widget.qw 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +73 -0
  2. package/build/favicon.ico +0 -0
  3. package/build/style.css +763 -0
  4. package/build/widget.qw.es.js +20653 -0
  5. package/build/widget.qw.umd.js +20660 -0
  6. package/index.html +17 -0
  7. package/package.json +47 -0
  8. package/public/favicon.ico +0 -0
  9. package/src/App.vue +26 -0
  10. package/src/api/index.js +126 -0
  11. package/src/assets/avatar.png +0 -0
  12. package/src/assets/banner_handle.png +0 -0
  13. package/src/assets/bg_blue.png +0 -0
  14. package/src/assets/bg_white.png +0 -0
  15. package/src/assets/down.png +0 -0
  16. package/src/assets/home.jpg +0 -0
  17. package/src/assets/icon_box.png +0 -0
  18. package/src/assets/icon_dot.png +0 -0
  19. package/src/assets/icon_draw.png +0 -0
  20. package/src/assets/icon_file.png +0 -0
  21. package/src/assets/icon_fold.png +0 -0
  22. package/src/assets/icon_shield.png +0 -0
  23. package/src/assets/logo.png +0 -0
  24. package/src/components/AuditBar.vue +341 -0
  25. package/src/components/BillCard.vue +156 -0
  26. package/src/components/CheckGroup.vue +114 -0
  27. package/src/components/DatetimePicker/DatetimePop.vue +343 -0
  28. package/src/components/DatetimePicker/index.vue +113 -0
  29. package/src/components/DayDropdown.vue +57 -0
  30. package/src/components/FilePicker.vue +114 -0
  31. package/src/components/Input.vue +72 -0
  32. package/src/components/MonthDropdown.vue +52 -0
  33. package/src/components/MultiPicker.vue +124 -0
  34. package/src/components/ProjectDropdown.vue +62 -0
  35. package/src/components/ProjectPicker.vue +111 -0
  36. package/src/components/SecretNotify.js +6 -0
  37. package/src/components/Sheet.vue +93 -0
  38. package/src/components/SinglePicker.vue +103 -0
  39. package/src/components/SingleUserSelector.vue +425 -0
  40. package/src/components/Switch.vue +65 -0
  41. package/src/components/TreePicker.vue +113 -0
  42. package/src/components/UserPicker.vue +107 -0
  43. package/src/components/UserProfile.vue +128 -0
  44. package/src/components/UsersPicker.vue +118 -0
  45. package/src/components/YearDropdown.vue +60 -0
  46. package/src/components/data_selector.vue +281 -0
  47. package/src/components/image_picker.vue +115 -0
  48. package/src/components/images_picker.vue +140 -0
  49. package/src/components/index.js +157 -0
  50. package/src/components/mult_list_selector.vue +156 -0
  51. package/src/components/product_selector.vue +186 -0
  52. package/src/components/subdepartment_selector.vue +481 -0
  53. package/src/components/user_selector.vue +639 -0
  54. package/src/components/widget/DataPop.vue +96 -0
  55. package/src/components/widget/TreePop.vue +89 -0
  56. package/src/components/widget/UserPop.vue +347 -0
  57. package/src/env.d.ts +8 -0
  58. package/src/main.js +111 -0
  59. package/src/router/index.ts +165 -0
  60. package/src/util/array_util.js +32 -0
  61. package/src/util/auth_util.js +73 -0
  62. package/src/util/bool_util.js +6 -0
  63. package/src/util/bus.js +2 -0
  64. package/src/util/cache_util.js +19 -0
  65. package/src/util/errer_code.js +7 -0
  66. package/src/util/eval_util.js +20 -0
  67. package/src/util/icon_util.js +37 -0
  68. package/src/util/image_util.js +28 -0
  69. package/src/util/index.js +56 -0
  70. package/src/util/num_util.js +71 -0
  71. package/src/util/obj_util.js +29 -0
  72. package/src/util/request.js +74 -0
  73. package/src/util/request_json.js +72 -0
  74. package/src/util/request_json_mute.js +66 -0
  75. package/src/util/request_upload.js +79 -0
  76. package/src/util/route_util.js +32 -0
  77. package/src/util/str_util.js +144 -0
  78. package/src/util/time_util.js +407 -0
  79. package/src/util/toast_util.js +25 -0
  80. package/src/util/tree_util.js +120 -0
  81. package/src/util/validate.js +183 -0
  82. package/src/util/vue_filter.js +223 -0
  83. package/src/views/auditbar/index.vue +66 -0
  84. package/src/views/billcard/index.vue +46 -0
  85. package/src/views/checkgroup/index.vue +36 -0
  86. package/src/views/dataSelector/index.vue +49 -0
  87. package/src/views/datetimepicker/index.vue +35 -0
  88. package/src/views/daydropdown/index.vue +31 -0
  89. package/src/views/filepicker/index.vue +32 -0
  90. package/src/views/home/index.vue +64 -0
  91. package/src/views/imagepicker/index.vue +32 -0
  92. package/src/views/imagespicker/index.vue +32 -0
  93. package/src/views/input/index.vue +35 -0
  94. package/src/views/monthdropdown/index.vue +31 -0
  95. package/src/views/multListSelector/index.vue +61 -0
  96. package/src/views/multipicker/index.vue +37 -0
  97. package/src/views/productSelector/index.vue +35 -0
  98. package/src/views/projectdropdown/index.vue +31 -0
  99. package/src/views/projectpicker/index.vue +42 -0
  100. package/src/views/secretnotify/index.vue +28 -0
  101. package/src/views/sheet/index.vue +46 -0
  102. package/src/views/singlepicker/index.vue +36 -0
  103. package/src/views/subdepartmentSelector/index.vue +41 -0
  104. package/src/views/switch/index.vue +35 -0
  105. package/src/views/treepicker/index.vue +42 -0
  106. package/src/views/userSelector/index.vue +54 -0
  107. package/src/views/userSelectorNew/index.vue +45 -0
  108. package/src/views/userpicker/index.vue +43 -0
  109. package/src/views/userprofile/index.vue +30 -0
  110. package/src/views/userspicker/index.vue +43 -0
  111. package/src/views/yeardropdown/index.vue +32 -0
  112. package/src/vm/index.js +6 -0
  113. package/tsconfig.json +19 -0
  114. package/tsconfig.node.json +8 -0
  115. package/vite.config.ts +73 -0
@@ -0,0 +1,165 @@
1
+ import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
2
+
3
+ const routes: Array<RouteRecordRaw> = [
4
+ {
5
+ path: "/",
6
+ redirect: "/home",
7
+ },
8
+ {
9
+ path: "/home",
10
+ name: "Home",
11
+ component: () => import("../views/home/index.vue"),
12
+ },
13
+ {
14
+ path: "/auditbar",
15
+ name: "Auditbar",
16
+ component: () => import("../views/auditbar/index.vue"),
17
+ },
18
+ {
19
+ path: "/input",
20
+ name: "input",
21
+ component: () => import("../views/input/index.vue"),
22
+ },
23
+ {
24
+ path: "/singlepicker",
25
+ name: "singlepicker",
26
+ component: () => import("../views/singlepicker/index.vue"),
27
+ },
28
+ {
29
+ path: "/multipicker",
30
+ name: "multipicker",
31
+ component: () => import("../views/multipicker/index.vue"),
32
+ },
33
+ {
34
+ path: "/checkgroup",
35
+ name: "checkgroup",
36
+ component: () => import("../views/checkgroup/index.vue"),
37
+ },
38
+ {
39
+ path: "/datetimepicker",
40
+ name: "datetimepicker",
41
+ component: () => import("../views/datetimepicker/index.vue"),
42
+ },
43
+ {
44
+ path: "/secretnotify",
45
+ name: "secretnotify",
46
+ component: () => import("../views/secretnotify/index.vue"),
47
+ },
48
+ {
49
+ path: "/productSelector",
50
+ name: "productSelector",
51
+ component: () => import("../views/productSelector/index.vue"),
52
+ },
53
+ {
54
+ path: "/dataSelector",
55
+ name: "dataSelector",
56
+ component: () => import("../views/dataSelector/index.vue"),
57
+ },
58
+ {
59
+ path: "/multListSelector",
60
+ name: "multListSelector",
61
+ component: () => import("../views/multListSelector/index.vue"),
62
+ },
63
+ {
64
+ path: "/subdepartmentSelector",
65
+ name: "subdepartmentSelector",
66
+ component: () => import("../views/subdepartmentSelector/index.vue"),
67
+ },
68
+ {
69
+ path: "/userSelector",
70
+ name: "userSelector",
71
+ component: () => import("../views/userSelector/index.vue"),
72
+ },
73
+ {
74
+ path: "/userSelectorNew",
75
+ name: "userSelectorNew",
76
+ component: () => import("../views/userSelectorNew/index.vue"),
77
+ },
78
+ {
79
+ path: "/imagepicker",
80
+ name: "imagepicker",
81
+ component: () => import("../views/imagepicker/index.vue"),
82
+ },
83
+ {
84
+ path: "/imagespicker",
85
+ name: "imagespicker",
86
+ component: () => import("../views/imagespicker/index.vue"),
87
+ },
88
+ {
89
+ path: "/filepicker",
90
+ name: "filepicker",
91
+ component: () => import("../views/filepicker/index.vue"),
92
+ },
93
+ {
94
+ path: "/billcard",
95
+ name: "billcard",
96
+ component: () => import("../views/billcard/index.vue"),
97
+ },
98
+ {
99
+ path: "/userspicker",
100
+ name: "userspicker",
101
+ component: () => import("../views/userspicker/index.vue"),
102
+ },
103
+ {
104
+ path: "/userpicker",
105
+ name: "userpicker",
106
+ component: () => import("../views/userpicker/index.vue"),
107
+ },
108
+ {
109
+ path: "/projectpicker",
110
+ name: "projectpicker",
111
+ component: () => import("../views/projectpicker/index.vue"),
112
+ },
113
+ {
114
+ path: "/userprofile",
115
+ name: "userprofile",
116
+ component: () => import("../views/userprofile/index.vue"),
117
+ },
118
+ {
119
+ path: "/yeardropdown",
120
+ name: "yeardropdown",
121
+ component: () => import("../views/yeardropdown/index.vue"),
122
+ },
123
+ {
124
+ path: "/monthdropdown",
125
+ name: "monthdropdown",
126
+ component: () => import("../views/monthdropdown/index.vue"),
127
+ },
128
+ {
129
+ path: "/daydropdown",
130
+ name: "daydropdown",
131
+ component: () => import("../views/daydropdown/index.vue"),
132
+ },
133
+ {
134
+ path: "/projectdropdown",
135
+ name: "projectdropdown",
136
+ component: () => import("../views/projectdropdown/index.vue"),
137
+ },
138
+ {
139
+ path: "/switch",
140
+ name: "switch",
141
+ component: () => import("../views/switch/index.vue"),
142
+ },
143
+ {
144
+ path: "/sheet",
145
+ name: "sheet",
146
+ component: () => import("../views/sheet/index.vue"),
147
+ },
148
+ {
149
+ path: "/treepicker",
150
+ name: "treepicker",
151
+ component: () => import("../views/treepicker/index.vue"),
152
+ }
153
+ ];
154
+
155
+ const router = createRouter({
156
+ history: createWebHashHistory(process.env.BASE_URL),
157
+ routes,
158
+ });
159
+
160
+ router.beforeEach((to, from, next) => {
161
+ console.log("+++路由回调++++++++++++++++++++++");
162
+ next();
163
+ });
164
+
165
+ export default router;
@@ -0,0 +1,32 @@
1
+ export function arySwapPrev(arr, index) {
2
+ if (index > 0 && index < arr.length) {
3
+ [arr[index - 1], arr[index]] = [arr[index], arr[index - 1]];
4
+ }
5
+ return arr;
6
+ }
7
+
8
+ export function arySwapNext(arr, index) {
9
+ if (index >= 0 && index < arr.length - 1) {
10
+ [arr[index], arr[index + 1]] = [arr[index + 1], arr[index]];
11
+ }
12
+ return arr;
13
+ }
14
+
15
+ export function uniq(ary){
16
+ // 去重
17
+ let newAry = [...new Set(ary)]
18
+ return newAry
19
+ }
20
+
21
+ export function uniqCode(arr) {
22
+ const uniqueMap = new Map();
23
+ for (const item of arr) {
24
+ const key = item.code
25
+ if (!uniqueMap.has(key)) {
26
+ uniqueMap.set(key, item);
27
+ }
28
+ }
29
+ return Array.from(uniqueMap.values());
30
+ }
31
+
32
+
@@ -0,0 +1,73 @@
1
+ import { setCacheValueByKey, getCacheValueByKey, removeCacheByKey } from "./cache_util.js";
2
+ import { computed } from 'vue'
3
+ import vm from '../vm'
4
+
5
+ //登陆token的键名
6
+ export const TOKEN_KEY = process.env.VUE_APP_TOKEN_KEY;
7
+ export const TOKEN_PREFIX = process.env.VUE_APP_TOKEN_PREFIX;
8
+
9
+ export function getToken() {
10
+ if (process.env.VUE_APP_IS_DEBUG)
11
+ return TOKEN_PREFIX + process.env.VUE_APP_DEBUG_TOKEN
12
+ else if(vm.tokenCallback)
13
+ return vm.tokenCallback()
14
+ }
15
+
16
+ export function setToken(token) {
17
+ setCacheValueByKey(TOKEN_KEY, token)
18
+ }
19
+
20
+ export function removeToken() {
21
+ removeCacheByKey(TOKEN_KEY)
22
+ }
23
+
24
+ export const props2auth = (props) => {
25
+ return {
26
+ isRequired: computed(() => {
27
+ if (props.auth) {
28
+ return props.auth == 'require'
29
+ }
30
+
31
+ return props.required
32
+ }),
33
+ isGone: computed(() => {
34
+ if (props.auth)
35
+ return props.auth == 'gone'
36
+
37
+ return false
38
+ }),
39
+ isDisabled: computed(()=>{
40
+ if (props.auth)
41
+ return props.auth == 'readonly'
42
+
43
+ if(props.required)
44
+ return false
45
+
46
+ if(props.disabled)
47
+ return true
48
+
49
+ if(props.readonly)
50
+ return true
51
+
52
+ return false
53
+ }),
54
+ isReadonly: computed(()=>{
55
+ if (props.auth)
56
+ return props.auth == 'readonly'
57
+
58
+ if(props.required)
59
+ return false
60
+
61
+ if(props.disabled)
62
+ return true
63
+
64
+ if(props.readonly)
65
+ return true
66
+
67
+ return false
68
+ }),
69
+ rules: computed(()=>{
70
+ return props.rules
71
+ })
72
+ }
73
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * bool转中文
3
+ */
4
+ export function bool2chinese(value) {
5
+ return value ? '是' : '否'
6
+ }
@@ -0,0 +1,2 @@
1
+ import mitt from 'mitt';
2
+ export default mitt();
@@ -0,0 +1,19 @@
1
+ // 读
2
+ export function getCacheValueByKey(key) {
3
+ return localStorage.getItem(key);
4
+ }
5
+
6
+ // 写
7
+ export function setCacheValueByKey(key, val) {
8
+ localStorage.setItem(key, val);
9
+ }
10
+
11
+ //删除
12
+ export function removeCacheByKey(key) {
13
+ localStorage.removeItem(key);
14
+ }
15
+
16
+ // 清除所有缓存
17
+ export function clearCache() {
18
+ localStorage.clear()
19
+ }
@@ -0,0 +1,7 @@
1
+ // 返回这些错误码都要清除cookie及local storage
2
+ //未登录 错误码
3
+ const NEED_LOGIN = process.env.VUE_APP_NEED_LOGIN_CODE;
4
+
5
+ export const NEED_LOGIN_CODES = [
6
+ NEED_LOGIN,
7
+ ]
@@ -0,0 +1,20 @@
1
+ import * as ToastUtil from './toast_util'
2
+
3
+ function evaluateWithParams(express, obj) {
4
+ const objStr = JSON.stringify(obj);
5
+ const newExpress = `(function() { const form = ${objStr}; return ${express}; })()`;
6
+ console.log('表达式:'+newExpress)
7
+ return eval(newExpress);
8
+ }
9
+
10
+ export const executeExpress = (express, params) => {
11
+ try {
12
+ const result = evaluateWithParams(express, params);
13
+ console.log(result);
14
+ return result
15
+ } catch (e) {
16
+ console.log('解析表达式失败', e)
17
+ ToastUtil.warnToast('解析表达式失败 '+ e)
18
+ return false
19
+ }
20
+ }
@@ -0,0 +1,37 @@
1
+ import { reactive } from 'vue'
2
+ // 引入全部图标
3
+ import * as Icons from "@element-plus/icons-vue"
4
+
5
+ // 按需引入图标
6
+ // import {
7
+ // CloseBold,
8
+ // Close,
9
+ // Plus,
10
+ // Star,
11
+ // UserFilled,
12
+ // Loading,
13
+ // Connection,
14
+ // Edit,
15
+ // FolderOpened
16
+ // } from '@element-plus/icons'
17
+
18
+ // const dictIcon = reactive({
19
+ // 'CloseBold': CloseBold,
20
+ // 'Close': Close,
21
+ // 'Plus': Plus,
22
+ // 'Star': Star,
23
+ // 'UserFilled': UserFilled,
24
+ // 'Loading': Loading,
25
+ // 'Connection': Connection,
26
+ // 'Edit': Edit,
27
+ // 'FolderOpened': FolderOpened
28
+ // })
29
+
30
+ const installIcon = (app) => {
31
+ // 便于模板获取
32
+ //app.config.globalProperties.$icon = dictIcon
33
+ // 使用全部图标
34
+ app.config.globalProperties.$icon = Icons
35
+ }
36
+
37
+ export default installIcon
@@ -0,0 +1,28 @@
1
+ import Compressor from 'compressorjs'
2
+
3
+ // 图片压缩
4
+ export const compress_image = async (file) => {
5
+ return new Promise((resolve, reject) => {
6
+ new Compressor(file, {
7
+ quality: 0.7,
8
+ maxWidth: 1400,
9
+ maxHeight: 1400,
10
+ success(result) {
11
+ console.log('压缩后的图片', result);
12
+ let compress_file = blob2file(result, result.name)
13
+ return resolve(compress_file)
14
+ },
15
+ error(err) {
16
+ console.error(err);
17
+ return reject(err)
18
+ }
19
+ })
20
+ })
21
+ }
22
+
23
+ function blob2file(blob, fileName, fileType = blob.type) {
24
+ return new File([blob], fileName, {
25
+ type: fileType,
26
+ lastModified: new Date().getTime()
27
+ });
28
+ }
@@ -0,0 +1,56 @@
1
+ import * as ApiUtil from '@/api'
2
+ import { successToast, warnToast } from './toast_util'
3
+ import * as AuthUtil from './auth_util'
4
+ import * as ArrayUtil from './array_util'
5
+ import * as StrUtil from './str_util'
6
+ import * as BoolUtil from './bool_util'
7
+ import * as RouteUtil from './route_util'
8
+ import * as TimeUtil from './time_util'
9
+ import * as ToastUtil from './toast_util'
10
+ import * as EvalUtil from './eval_util'
11
+ import * as ImageUtil from './image_util'
12
+ import * as TreeUtil from './tree_util'
13
+
14
+ export default {
15
+ ...AuthUtil,
16
+ ...ArrayUtil,
17
+ ...StrUtil,
18
+ ...BoolUtil,
19
+ ...RouteUtil,
20
+ ...TimeUtil,
21
+ ...ApiUtil,
22
+ ...ToastUtil,
23
+ ...EvalUtil,
24
+ ...ImageUtil,
25
+ ...TreeUtil,
26
+
27
+ href(url) {
28
+ window.location.href = url
29
+ },
30
+ hrefByNew(url) {
31
+ window.open(url, '_blank')
32
+ },
33
+ gotoLogin() {
34
+ let baseUrl = RouteUtil.getBaseUrl()
35
+ window.location.href = baseUrl + '#/login'
36
+ },
37
+ gotoByNew(path, params) {
38
+ const routeData = router.resolve({ path: path, query: params });
39
+ window.open(routeData.href, '_blank')
40
+ },
41
+ warnToast(msg) {
42
+ warnToast(msg)
43
+ },
44
+ successToast(msg) {
45
+ successToast(msg)
46
+ },
47
+ isEmail(email) {
48
+ return validateEmail(email)
49
+ },
50
+ isPhone(phone) {
51
+ return validatePhone(phone)
52
+ },
53
+ scrollToTop() {
54
+ document.documentElement.scrollTop = 0
55
+ }
56
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * 分钱转元,保留小数点后2位
3
+ * @param value 调用过滤器时,调用的文本
4
+ */
5
+ export function cent2yuanByDot(value) {
6
+ // 如果文本不存在,返回空字符
7
+ // value === 0 ; !0 === true.
8
+ if (!value) {
9
+ return '0.00'
10
+ }
11
+
12
+ // 文本转化为 float
13
+ const result = parseFloat(value) / 100;
14
+
15
+ // 如果文本为 integer 类型的文本,表示当前文本没有小数
16
+ // if (Number.isInteger(result)) {
17
+ // return result
18
+ // }
19
+
20
+ // 文本包含小数,保留小数点后2位
21
+ return result.toFixed(2);
22
+ }
23
+
24
+ /**
25
+ * 分钱转元,不保留角、分
26
+ * @param value 调用过滤器时,调用的文本
27
+ */
28
+ export function cent2yuan(value) {
29
+ // 如果文本不存在,返回空字符
30
+ // value === 0 ; !0 === true.
31
+ if (!value) {
32
+ return '0.00'
33
+ }
34
+
35
+ // 文本转化为 float
36
+ const result = parseFloat(value) / 100;
37
+
38
+ // 如果文本为 integer 类型的文本,表示当前文本没有小数
39
+ // if (Number.isInteger(result)) {
40
+ // return result
41
+ // }
42
+
43
+ // 文本包含小数,保留小数点后2位
44
+ return result.toFixed(0);
45
+ }
46
+
47
+ export function num2boolean(value) {
48
+ if (value > 0)
49
+ return true
50
+ else
51
+ return false
52
+ }
53
+
54
+ export function percent(value) {
55
+ // 如果文本不存在,返回空字符
56
+ // value === 0 ; !0 === true.
57
+ if (!value) {
58
+ return '0.00'
59
+ }
60
+
61
+ // 文本转化为 float
62
+ const result = parseFloat(value) * 100;
63
+
64
+ // 如果文本为 integer 类型的文本,表示当前文本没有小数
65
+ // if (Number.isInteger(result)) {
66
+ // return result
67
+ // }
68
+
69
+ // 文本包含小数,保留小数点后2位
70
+ return result.toFixed(2);
71
+ }
@@ -0,0 +1,29 @@
1
+ export function objSwapPrev(obj, targetProp) {
2
+ const keys = Object.keys(obj);
3
+ const targetIndex = keys.indexOf(targetProp);
4
+ if (targetIndex > 0) {
5
+ const prevIndex = targetIndex - 1;
6
+ // 交换属性位置
7
+ [keys[targetIndex], keys[prevIndex]] = [keys[prevIndex], keys[targetIndex]];
8
+ }
9
+ const newObj = {};
10
+ keys.forEach(key => {
11
+ newObj[key] = obj[key];
12
+ });
13
+ return newObj;
14
+ }
15
+
16
+ export function objSwapNext(obj, targetProp) {
17
+ const keys = Object.keys(obj);
18
+ const targetIndex = keys.indexOf(targetProp);
19
+ if (targetIndex < keys.length - 1) {
20
+ const nextIndex = targetIndex + 1;
21
+ // 交换属性位置
22
+ [keys[targetIndex], keys[nextIndex]] = [keys[nextIndex], keys[targetIndex]];
23
+ }
24
+ const newObj = {};
25
+ keys.forEach(key => {
26
+ newObj[key] = obj[key];
27
+ });
28
+ return newObj;
29
+ }
@@ -0,0 +1,74 @@
1
+ import vm from '../vm'
2
+ import axios from "axios"
3
+ import qs from "qs"
4
+ import { NEED_LOGIN_CODES } from './errer_code.js'
5
+ import { getToken,TOKEN_KEY } from './auth_util.js'
6
+ import util from './index.js'
7
+
8
+
9
+ // create an axios instance
10
+ const service = axios.create({
11
+ baseURL: '', // url = domain + request url
12
+ withCredentials: true, // send cookies when cross-domain requests
13
+ timeout: 1000 * 60 * 10, // request timeout
14
+ })
15
+
16
+ //请求拦截器
17
+ service.interceptors.request.use(
18
+ config => {
19
+ util.showLoading()
20
+
21
+ //请求头加token
22
+ config.headers[TOKEN_KEY] = getToken()
23
+
24
+ if (config.method.toLowerCase() == 'post') {
25
+ config.data = qs.stringify(config.data)
26
+ }
27
+ return config
28
+ },
29
+ error => {
30
+ // do something with request error
31
+ console.log(error) // for debug
32
+ util.hideLoading()
33
+ util.warnToast(error)
34
+ return Promise.reject(error)
35
+ }
36
+ )
37
+
38
+ //响应拦截器
39
+ service.interceptors.response.use(
40
+ response => {
41
+ util.hideLoading()
42
+
43
+ const res = response.data
44
+ console.log(res)
45
+
46
+ if (res.code !== 200) {
47
+ util.warnToast(res.msg || "Error")
48
+
49
+ console.log(NEED_LOGIN_CODES)
50
+
51
+ if (NEED_LOGIN_CODES.indexOf(res.code) >= 0) {
52
+ util.warnToast('请登录')
53
+ setTimeout(() => {
54
+ if (vm.needLoginCallback) {
55
+ vm.needLoginCallback()
56
+ }
57
+ return
58
+ }, 1500)
59
+ }
60
+
61
+ return res
62
+ }
63
+
64
+ return res
65
+ },
66
+ error => {
67
+ util.hideLoading()
68
+ console.log("err" + error) // for debug
69
+ util.warnToast(error.message)
70
+ return Promise.reject(error)
71
+ }
72
+ )
73
+
74
+ export default service