baseMixin.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { getToken } from '@/api/token'
  2. import bus from '@/assets/js/event.js'
  3. export default {
  4. data () {
  5. return {
  6. token: null,
  7. verifyNotPassName: null,
  8. }
  9. },
  10. props: {
  11. enableFlow: {
  12. type: Boolean,
  13. default: false,
  14. },
  15. taskName: {
  16. type: String,
  17. default: ""
  18. }
  19. },
  20. mounted () {
  21. bus.$on('verifyNotPass', (name) => {
  22. if (!this.verifyNotPassName) {
  23. this.verifyNotPassName = name;
  24. }
  25. });
  26. },
  27. methods: {
  28. startVerify: function(name) {
  29. this.verifyNotPassName = null;
  30. bus.$emit('startVerify', name);
  31. setTimeout(() => {
  32. }, 5000);
  33. return !this.verifyNotPassName;
  34. },
  35. submitHandler: function (func, checkToken) {
  36. if (this.token == null || checkToken == false) {
  37. getToken().then((res) => {
  38. this.token = res.data;
  39. func(this.token);
  40. }).catch((error) => {
  41. if (error && error.status == 404) {
  42. return;
  43. }
  44. console.log(error)
  45. // msg('网络错误');
  46. this.resetToken();
  47. });
  48. }
  49. },
  50. resetToken: function () {
  51. this.token = null;
  52. },
  53. backListView: function(isDestoryListView, listViewName, params, func) {
  54. console.log(isDestoryListView + "-" + this.$route.name);
  55. var formViewName = this.$route.name;
  56. this.$parent.closeTabByName(formViewName);
  57. var _listViewName = formViewName;
  58. if (!listViewName) {
  59. if (formViewName.endWith('Form')) {
  60. _listViewName = _listViewName.substring(0, formViewName.length - 4) + "List";
  61. } else if (formViewName.endWith('Add')) {
  62. _listViewName = _listViewName.substring(0, formViewName.length - 3) + "List";
  63. }
  64. }
  65. if (_listViewName == "TransactionSubjectList" || _listViewName == "ProjectSubjectList") {
  66. _listViewName = "MeetingSubjectList";
  67. }
  68. console.log(_listViewName + " ----");
  69. this.$parent.refreshTabByName((listViewName || _listViewName), isDestoryListView, params);
  70. // setTimeout(() => {
  71. // }, 100);
  72. },
  73. reset: function(backUp) {
  74. if (backUp.titles) {
  75. this.titles = Object.assign([], JSON.parse(JSON.stringify(backUp.titles)));
  76. }
  77. if (backUp.paramNames) {
  78. this.paramNames = Object.assign([], backUp.paramNames);
  79. }
  80. if (backUp.otherParam) {
  81. this.otherParam = Object.assign({}, backUp.otherParam);
  82. }
  83. if (backUp.dicts) {
  84. this.dicts = Object.assign([], JSON.parse(JSON.stringify(backUp.dicts)));
  85. }
  86. },
  87. toClick: function (ref, func) {
  88. if (!func || func()) {
  89. this.$refs[ref].click();
  90. } else {
  91. if (this.verifyNotPassAfter) {
  92. this.verifyNotPassAfter(this.verifyNotPassName);
  93. }
  94. msg("必填项不能为空");
  95. }
  96. },
  97. }
  98. }