common-utils-kit 1.1.33 → 1.1.35
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.
- package/README.md +714 -422
- package/lib/element/index.common.127.js +169 -0
- package/lib/element/index.common.172.js +238 -0
- package/lib/element/index.common.212.js +274 -0
- package/lib/element/index.common.214.js +167 -0
- package/lib/element/index.common.290.js +167 -0
- package/lib/element/index.common.315.js +159 -0
- package/lib/element/index.common.373.js +159 -0
- package/lib/element/index.common.406.js +150 -0
- package/lib/element/index.common.50.js +191 -0
- package/lib/element/index.common.507.js +138 -0
- package/lib/element/index.common.719.js +164 -0
- package/lib/element/index.common.766.js +157 -0
- package/lib/element/index.common.873.js +159 -0
- package/lib/element/index.common.884.js +172 -0
- package/lib/element/index.common.js +7598 -2927
- package/lib/element/index.umd.323.js +164 -0
- package/lib/element/index.umd.348.js +169 -0
- package/lib/element/index.umd.404.js +150 -0
- package/lib/element/index.umd.41.js +238 -0
- package/lib/element/index.umd.466.js +138 -0
- package/lib/element/index.umd.503.js +167 -0
- package/lib/element/index.umd.638.js +274 -0
- package/lib/element/index.umd.813.js +159 -0
- package/lib/element/index.umd.836.js +157 -0
- package/lib/element/index.umd.850.js +191 -0
- package/lib/element/index.umd.858.js +159 -0
- package/lib/element/index.umd.876.js +172 -0
- package/lib/element/index.umd.954.js +159 -0
- package/lib/element/index.umd.964.js +167 -0
- package/lib/element/index.umd.js +7598 -2927
- package/lib/element/index.umd.min.200.js +1 -0
- package/lib/element/index.umd.min.3.js +1 -0
- package/lib/element/index.umd.min.308.js +1 -0
- package/lib/element/index.umd.min.326.js +1 -0
- package/lib/element/index.umd.min.466.js +1 -0
- package/lib/element/index.umd.min.474.js +1 -0
- package/lib/element/index.umd.min.5.js +1 -0
- package/lib/element/index.umd.min.550.js +1 -0
- package/lib/element/index.umd.min.593.js +1 -0
- package/lib/element/index.umd.min.615.js +1 -0
- package/lib/element/index.umd.min.688.js +1 -0
- package/lib/element/index.umd.min.878.js +1 -0
- package/lib/element/index.umd.min.898.js +1 -0
- package/lib/element/index.umd.min.931.js +1 -0
- package/lib/element/index.umd.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,422 +1,714 @@
|
|
|
1
|
-
# Common Utils Kit
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
- `
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
```js
|
|
163
|
-
import {
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
import {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
- `
|
|
324
|
-
- `
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
>
|
|
338
|
-
<
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
-
|
|
363
|
-
-
|
|
364
|
-
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
<
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
-
|
|
409
|
-
-
|
|
410
|
-
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
1
|
+
# Common Utils Kit
|
|
2
|
+
|
|
3
|
+
`common-utils-kit` 是一个基于 Vue 2 和 Element UI 的公共能力包,当前同时提供:
|
|
4
|
+
|
|
5
|
+
- 通用工具方法
|
|
6
|
+
- 自定义指令
|
|
7
|
+
- 请求封装
|
|
8
|
+
- WebSocket 封装
|
|
9
|
+
- Element UI 业务组件
|
|
10
|
+
|
|
11
|
+
当前版本:`1.1.34`
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install common-utils-kit
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
依赖要求:
|
|
20
|
+
|
|
21
|
+
- `vue` 2.x
|
|
22
|
+
- `element-ui` `>=2.13.2`
|
|
23
|
+
|
|
24
|
+
## 目录能力
|
|
25
|
+
|
|
26
|
+
### 主入口
|
|
27
|
+
|
|
28
|
+
主入口 `common-utils-kit` 当前导出:
|
|
29
|
+
|
|
30
|
+
- `test`
|
|
31
|
+
- `format`
|
|
32
|
+
- `tool`
|
|
33
|
+
- `file`
|
|
34
|
+
- `confirm`
|
|
35
|
+
- `request`
|
|
36
|
+
- `websocket`
|
|
37
|
+
- `table`
|
|
38
|
+
- `directive`
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import {
|
|
42
|
+
test,
|
|
43
|
+
format,
|
|
44
|
+
tool,
|
|
45
|
+
file,
|
|
46
|
+
confirm,
|
|
47
|
+
request,
|
|
48
|
+
websocket,
|
|
49
|
+
table,
|
|
50
|
+
directive,
|
|
51
|
+
} from 'common-utils-kit';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Element 组件入口
|
|
55
|
+
|
|
56
|
+
`common-utils-kit/element` 当前导出:
|
|
57
|
+
|
|
58
|
+
- `View3D`
|
|
59
|
+
- `ScreenScale`
|
|
60
|
+
- `ConfirmDialog`
|
|
61
|
+
- `ElementForm`
|
|
62
|
+
- `ElementTable`
|
|
63
|
+
- `ScrollTable`
|
|
64
|
+
- `ResetDrawer`
|
|
65
|
+
- `ResetDialog`
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import {
|
|
69
|
+
View3D,
|
|
70
|
+
ScreenScale,
|
|
71
|
+
ConfirmDialog,
|
|
72
|
+
ElementForm,
|
|
73
|
+
ElementTable,
|
|
74
|
+
ScrollTable,
|
|
75
|
+
ResetDrawer,
|
|
76
|
+
ResetDialog,
|
|
77
|
+
} from 'common-utils-kit/element';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 样式
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import 'common-utils-kit/lib/utils-kit.css';
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 快速开始
|
|
87
|
+
|
|
88
|
+
### 1. 全局挂载常用能力
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
import Vue from 'vue';
|
|
92
|
+
import {
|
|
93
|
+
test,
|
|
94
|
+
format,
|
|
95
|
+
tool,
|
|
96
|
+
file,
|
|
97
|
+
confirm,
|
|
98
|
+
table,
|
|
99
|
+
directive,
|
|
100
|
+
} from 'common-utils-kit';
|
|
101
|
+
|
|
102
|
+
Vue.prototype.$test = test;
|
|
103
|
+
Vue.prototype.$format = format;
|
|
104
|
+
Vue.prototype.$tool = tool;
|
|
105
|
+
Vue.prototype.$fileKit = file;
|
|
106
|
+
Vue.prototype.$confirmKit = confirm;
|
|
107
|
+
Vue.prototype.$tableKit = table;
|
|
108
|
+
|
|
109
|
+
Vue.use(directive);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 2. 局部使用
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import { confirm, table } from 'common-utils-kit';
|
|
116
|
+
|
|
117
|
+
confirm.customConfirm({ title: '提示', toolTips: '确认执行当前操作?' });
|
|
118
|
+
|
|
119
|
+
const sorted = table.sortMergeData(list, 'region');
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## 工具能力
|
|
123
|
+
|
|
124
|
+
### test
|
|
125
|
+
|
|
126
|
+
常用校验能力:
|
|
127
|
+
|
|
128
|
+
- `hasValue`
|
|
129
|
+
- `valueType`
|
|
130
|
+
- `email`
|
|
131
|
+
- `mobile`
|
|
132
|
+
- `url`
|
|
133
|
+
- `idCard`
|
|
134
|
+
- `carNo`
|
|
135
|
+
- `amount`
|
|
136
|
+
- `chinese`
|
|
137
|
+
- `letter`
|
|
138
|
+
- `landline`
|
|
139
|
+
- `code`
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
import { test } from 'common-utils-kit';
|
|
143
|
+
|
|
144
|
+
test.email('demo@test.com');
|
|
145
|
+
test.mobile('13800138000');
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### format
|
|
149
|
+
|
|
150
|
+
常用数据处理能力:
|
|
151
|
+
|
|
152
|
+
- `getProperty`
|
|
153
|
+
- `unrepeated`
|
|
154
|
+
- `treeToFlat`
|
|
155
|
+
- `flatToTree`
|
|
156
|
+
- `recursionFunction`
|
|
157
|
+
- `filterData`
|
|
158
|
+
- `dateDiff`
|
|
159
|
+
- `getNowDate`
|
|
160
|
+
- `setFormColumnsData`
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
import { format } from 'common-utils-kit';
|
|
164
|
+
|
|
165
|
+
const flatList = format.treeToFlat(treeData);
|
|
166
|
+
const treeData = format.flatToTree(list);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### tool
|
|
170
|
+
|
|
171
|
+
提供:
|
|
172
|
+
|
|
173
|
+
- `debounce`
|
|
174
|
+
- `throttle`
|
|
175
|
+
- `sleep`
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
import { tool } from 'common-utils-kit';
|
|
179
|
+
|
|
180
|
+
const submit = tool.debounce(() => {
|
|
181
|
+
console.log('submit');
|
|
182
|
+
}, 500);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### file
|
|
186
|
+
|
|
187
|
+
提供:
|
|
188
|
+
|
|
189
|
+
- `downloadBase64File`
|
|
190
|
+
- `downloadFiles`
|
|
191
|
+
- `fileToBase64`
|
|
192
|
+
- `base64ToFile`
|
|
193
|
+
- `base64ToFileBlob`
|
|
194
|
+
- `uploadCompress`
|
|
195
|
+
|
|
196
|
+
```js
|
|
197
|
+
import { file } from 'common-utils-kit';
|
|
198
|
+
|
|
199
|
+
file.downloadFiles('https://example.com/demo.pdf', 'demo.pdf');
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### confirm
|
|
203
|
+
|
|
204
|
+
当前主用方法是 `customConfirm`,统一从主入口使用,不再从 `element-ui` 目录单独引用。
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
import { confirm } from 'common-utils-kit';
|
|
208
|
+
|
|
209
|
+
const res = await confirm.customConfirm({
|
|
210
|
+
title: '操作确认',
|
|
211
|
+
toolTips: '确认执行当前操作?',
|
|
212
|
+
titleIcon: 'el-icon-warning-outline',
|
|
213
|
+
tipIcon: 'el-icon-warning',
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
console.log(res.flag);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
输入弹窗示例:
|
|
220
|
+
|
|
221
|
+
```js
|
|
222
|
+
const res = await confirm.customConfirm({
|
|
223
|
+
title: '填写原因',
|
|
224
|
+
dialogType: 'input',
|
|
225
|
+
toolTips: '请输入本次操作原因',
|
|
226
|
+
inputPlaceholder: '请输入原因',
|
|
227
|
+
inputValue: '',
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
console.log(res.flag, res.inputValue);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
常用参数:
|
|
234
|
+
|
|
235
|
+
- `title`
|
|
236
|
+
- `dialogType`
|
|
237
|
+
- `toolTips`
|
|
238
|
+
- `inputValue`
|
|
239
|
+
- `inputPlaceholder`
|
|
240
|
+
- `btnParam`
|
|
241
|
+
- `closeOnClickModal`
|
|
242
|
+
- `closeOnPressEscape`
|
|
243
|
+
- `customClass`
|
|
244
|
+
- `titleIcon`
|
|
245
|
+
- `tipIcon`
|
|
246
|
+
|
|
247
|
+
### request
|
|
248
|
+
|
|
249
|
+
请求封装从 `request` 模块获取。
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
import { request } from 'common-utils-kit';
|
|
253
|
+
|
|
254
|
+
const http = new request.RequestHttp({
|
|
255
|
+
baseURL: '/api',
|
|
256
|
+
timeout: 60000,
|
|
257
|
+
withCredentials: true,
|
|
258
|
+
}, {
|
|
259
|
+
getToken: () => localStorage.getItem('token'),
|
|
260
|
+
tokenHeader: 'token',
|
|
261
|
+
showLoading: () => {},
|
|
262
|
+
hideLoading: () => {},
|
|
263
|
+
message: Message,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
http.get('/user/info', { id: 1 }, { cancel: true, loading: false });
|
|
267
|
+
http.post('/user/save', { name: '张三' });
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
请求取消能力:
|
|
271
|
+
|
|
272
|
+
```js
|
|
273
|
+
import { request } from 'common-utils-kit';
|
|
274
|
+
|
|
275
|
+
const canceler = new request.AxiosCanceler({ type: 'abort' });
|
|
276
|
+
|
|
277
|
+
const config = {
|
|
278
|
+
method: 'get',
|
|
279
|
+
url: '/api/list',
|
|
280
|
+
params: { pageNum: 1 },
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
canceler.addPending(config);
|
|
284
|
+
canceler.removePending(config);
|
|
285
|
+
canceler.removeAllPending();
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### websocket
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
import { websocket } from 'common-utils-kit';
|
|
292
|
+
|
|
293
|
+
const client = websocket.createSocketClient({
|
|
294
|
+
url: 'ws://example.com/socket',
|
|
295
|
+
heartMessage: 'ping',
|
|
296
|
+
heartTime: 60000,
|
|
297
|
+
reconnectTime: 5000,
|
|
298
|
+
onMessage: event => console.log(event.data),
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
client.connect();
|
|
302
|
+
client.send({ type: 'hello' });
|
|
303
|
+
client.close();
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### table
|
|
307
|
+
|
|
308
|
+
当前主用场景是 Element 表格合并行辅助。
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
import { table } from 'common-utils-kit';
|
|
312
|
+
|
|
313
|
+
const sorted = table.sortMergeData(sourceData, 'region');
|
|
314
|
+
const spanList = table.getMergeSpanList(sorted, 'region');
|
|
315
|
+
const spanMethod = table.createMergeSpanMethod(spanList, 0);
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## 指令
|
|
319
|
+
|
|
320
|
+
通过 `Vue.use(directive)` 安装后,当前可用指令包括:
|
|
321
|
+
|
|
322
|
+
- `v-debounce`
|
|
323
|
+
- `v-input-debounce`
|
|
324
|
+
- `v-btn-debounce`
|
|
325
|
+
- `v-btn-throttle`
|
|
326
|
+
- `v-click-lock`
|
|
327
|
+
- `v-relative-time`
|
|
328
|
+
- `v-input-rule`
|
|
329
|
+
- `v-local-loading`
|
|
330
|
+
- `v-full-loading`
|
|
331
|
+
- `v-el-drag-dialog`
|
|
332
|
+
|
|
333
|
+
示例:
|
|
334
|
+
|
|
335
|
+
```vue
|
|
336
|
+
<template>
|
|
337
|
+
<div>
|
|
338
|
+
<el-input
|
|
339
|
+
v-model="keyword"
|
|
340
|
+
v-input-debounce:1000="handleSearch"
|
|
341
|
+
placeholder="输入后防抖搜索"
|
|
342
|
+
/>
|
|
343
|
+
|
|
344
|
+
<el-button v-btn-throttle="500" @click="handleSubmit">
|
|
345
|
+
节流提交
|
|
346
|
+
</el-button>
|
|
347
|
+
</div>
|
|
348
|
+
</template>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Element 组件
|
|
352
|
+
|
|
353
|
+
## ConfirmDialog
|
|
354
|
+
|
|
355
|
+
`ConfirmDialog` 是一个基于 `el-dialog` 的业务确认弹窗组件。
|
|
356
|
+
|
|
357
|
+
```vue
|
|
358
|
+
<template>
|
|
359
|
+
<confirm-dialog
|
|
360
|
+
v-model="dialogVisible"
|
|
361
|
+
title="删除提示"
|
|
362
|
+
dialog-type="tips"
|
|
363
|
+
tool-tips="删除后数据不可恢复,是否继续?"
|
|
364
|
+
:btn-param="componentBtns"
|
|
365
|
+
title-icon="el-icon-warning-outline"
|
|
366
|
+
tip-icon="el-icon-warning"
|
|
367
|
+
@affirm="handleConfirm"
|
|
368
|
+
/>
|
|
369
|
+
</template>
|
|
370
|
+
|
|
371
|
+
<script>
|
|
372
|
+
import { ConfirmDialog } from 'common-utils-kit/element';
|
|
373
|
+
|
|
374
|
+
export default {
|
|
375
|
+
components: {
|
|
376
|
+
ConfirmDialog,
|
|
377
|
+
},
|
|
378
|
+
data() {
|
|
379
|
+
return {
|
|
380
|
+
dialogVisible: false,
|
|
381
|
+
componentBtns: [
|
|
382
|
+
{ btnlable: '取消', type: '', flag: 'cancel' },
|
|
383
|
+
{ btnlable: '确认删除', type: 'danger', flag: 'confirm' },
|
|
384
|
+
],
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
methods: {
|
|
388
|
+
handleConfirm(flag, value) {
|
|
389
|
+
console.log(flag, value);
|
|
390
|
+
this.dialogVisible = false;
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
</script>
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
## ElementForm
|
|
398
|
+
|
|
399
|
+
`ElementForm` 是配置型表单/展示组件。
|
|
400
|
+
|
|
401
|
+
### 基础用法
|
|
402
|
+
|
|
403
|
+
```vue
|
|
404
|
+
<template>
|
|
405
|
+
<element-form
|
|
406
|
+
ref="formExample"
|
|
407
|
+
:columns="formColumns"
|
|
408
|
+
:form-data="formData"
|
|
409
|
+
:label-width="110"
|
|
410
|
+
:value-width="90"
|
|
411
|
+
@itemChange="itemChange"
|
|
412
|
+
@handleSearch="handleSearch"
|
|
413
|
+
@handleClear="handleClear"
|
|
414
|
+
/>
|
|
415
|
+
</template>
|
|
416
|
+
|
|
417
|
+
<script>
|
|
418
|
+
import { ElementForm } from 'common-utils-kit/element';
|
|
419
|
+
|
|
420
|
+
export default {
|
|
421
|
+
components: {
|
|
422
|
+
ElementForm,
|
|
423
|
+
},
|
|
424
|
+
data() {
|
|
425
|
+
return {
|
|
426
|
+
formData: {
|
|
427
|
+
customerName: '',
|
|
428
|
+
customerType: '',
|
|
429
|
+
},
|
|
430
|
+
formColumns: [
|
|
431
|
+
{
|
|
432
|
+
param: 'customerName',
|
|
433
|
+
label: '客户名称',
|
|
434
|
+
effect: 'form',
|
|
435
|
+
type: 'search',
|
|
436
|
+
rules: { required: true },
|
|
437
|
+
proport: 8,
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
param: 'customerType',
|
|
441
|
+
label: '客户类型',
|
|
442
|
+
effect: 'form',
|
|
443
|
+
type: 'select',
|
|
444
|
+
props: { label: 'label', value: 'value' },
|
|
445
|
+
data: [],
|
|
446
|
+
rules: { select: true },
|
|
447
|
+
proport: 8,
|
|
448
|
+
},
|
|
449
|
+
],
|
|
450
|
+
};
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
</script>
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### 通过 ref 批量填充列配置
|
|
457
|
+
|
|
458
|
+
`batchSetColumnData` 现在通过组件实例方法提供,不需要再从内部 `utils/common.js` 直接引用。
|
|
459
|
+
|
|
460
|
+
```js
|
|
461
|
+
created() {
|
|
462
|
+
this.formColumns = this.createFormColumns();
|
|
463
|
+
},
|
|
464
|
+
mounted() {
|
|
465
|
+
this.formColumns = this.$refs.formExample.batchSetColumnData({
|
|
466
|
+
客户类型: [
|
|
467
|
+
{ label: '企业客户', value: 'company' },
|
|
468
|
+
{ label: '个人客户', value: 'personal' },
|
|
469
|
+
],
|
|
470
|
+
客户标签: [
|
|
471
|
+
{ label: '重点客户', value: 'important' },
|
|
472
|
+
{ label: '已签约', value: 'contract' },
|
|
473
|
+
{ label: '待跟进', value: 'follow' },
|
|
474
|
+
],
|
|
475
|
+
}, { unique: 'label', data: 'data' });
|
|
476
|
+
}
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### 组件实例方法
|
|
480
|
+
|
|
481
|
+
- `submitForm()`:执行表单校验,返回 `Boolean`
|
|
482
|
+
- `clearValidate(param)`:清空校验
|
|
483
|
+
- `batchSetColumnData(config, props)`:基于当前 `columns` 返回新的列配置
|
|
484
|
+
- `setFormDisabled(disabled, params)`:批量设置表单项禁用状态
|
|
485
|
+
|
|
486
|
+
### 常见字段
|
|
487
|
+
|
|
488
|
+
- `param`
|
|
489
|
+
- `label`
|
|
490
|
+
- `effect`
|
|
491
|
+
- `type`
|
|
492
|
+
- `rules`
|
|
493
|
+
- `proport`
|
|
494
|
+
- `props`
|
|
495
|
+
- `data`
|
|
496
|
+
- `clearable`
|
|
497
|
+
- `filterable`
|
|
498
|
+
- `multiple`
|
|
499
|
+
- `disabled`
|
|
500
|
+
|
|
501
|
+
### 支持的常见类型
|
|
502
|
+
|
|
503
|
+
- `input`
|
|
504
|
+
- `select`
|
|
505
|
+
- `cascader`
|
|
506
|
+
- `date`
|
|
507
|
+
- `checkbox`
|
|
508
|
+
- `radio`
|
|
509
|
+
- `textarea`
|
|
510
|
+
- `search`
|
|
511
|
+
|
|
512
|
+
## ElementTable
|
|
513
|
+
|
|
514
|
+
`ElementTable` 是配置型表格组件,支持:
|
|
515
|
+
|
|
516
|
+
- 复选列
|
|
517
|
+
- 单选列
|
|
518
|
+
- 序号列
|
|
519
|
+
- 详情跳转列
|
|
520
|
+
- 开关列
|
|
521
|
+
- 图片列
|
|
522
|
+
- 按钮列
|
|
523
|
+
- 分隔展示
|
|
524
|
+
- 拼接展示
|
|
525
|
+
- 气泡提示
|
|
526
|
+
- 气泡表格
|
|
527
|
+
- 表头插槽
|
|
528
|
+
- 单元格插槽
|
|
529
|
+
|
|
530
|
+
```vue
|
|
531
|
+
<template>
|
|
532
|
+
<element-table
|
|
533
|
+
:columns="columns"
|
|
534
|
+
:main-data="tableData"
|
|
535
|
+
:show-checkbox="true"
|
|
536
|
+
:show-radio="true"
|
|
537
|
+
:select-radio.sync="selectRadio"
|
|
538
|
+
:show-index="true"
|
|
539
|
+
:page="page"
|
|
540
|
+
row-key="id"
|
|
541
|
+
@handleButton="handleButton"
|
|
542
|
+
@setStatus="setStatus"
|
|
543
|
+
@openDetail="openDetail"
|
|
544
|
+
/>
|
|
545
|
+
</template>
|
|
546
|
+
|
|
547
|
+
<script>
|
|
548
|
+
import { ElementTable } from 'common-utils-kit/element';
|
|
549
|
+
|
|
550
|
+
export default {
|
|
551
|
+
components: {
|
|
552
|
+
ElementTable,
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
</script>
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
## ScrollTable
|
|
559
|
+
|
|
560
|
+
滚动加载表格组件:
|
|
561
|
+
|
|
562
|
+
```vue
|
|
563
|
+
<template>
|
|
564
|
+
<scroll-table
|
|
565
|
+
:columns="columns"
|
|
566
|
+
:main-data="tableData"
|
|
567
|
+
:loading="loading"
|
|
568
|
+
:finished="finished"
|
|
569
|
+
height="460"
|
|
570
|
+
@load="loadMore"
|
|
571
|
+
/>
|
|
572
|
+
</template>
|
|
573
|
+
|
|
574
|
+
<script>
|
|
575
|
+
import { ScrollTable } from 'common-utils-kit/element';
|
|
576
|
+
|
|
577
|
+
export default {
|
|
578
|
+
components: {
|
|
579
|
+
ScrollTable,
|
|
580
|
+
},
|
|
581
|
+
};
|
|
582
|
+
</script>
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
常用参数:
|
|
586
|
+
|
|
587
|
+
- `columns`
|
|
588
|
+
- `mainData`
|
|
589
|
+
- `loading`
|
|
590
|
+
- `finished`
|
|
591
|
+
- `loadDistance`
|
|
592
|
+
- `height`
|
|
593
|
+
|
|
594
|
+
## ScreenScale
|
|
595
|
+
|
|
596
|
+
大屏缩放容器:
|
|
597
|
+
|
|
598
|
+
```vue
|
|
599
|
+
<template>
|
|
600
|
+
<screen-scale :width="1920" :height="1080">
|
|
601
|
+
<div style="width: 1920px; height: 1080px;">
|
|
602
|
+
大屏内容
|
|
603
|
+
</div>
|
|
604
|
+
</screen-scale>
|
|
605
|
+
</template>
|
|
606
|
+
|
|
607
|
+
<script>
|
|
608
|
+
import { ScreenScale } from 'common-utils-kit/element';
|
|
609
|
+
|
|
610
|
+
export default {
|
|
611
|
+
components: {
|
|
612
|
+
ScreenScale,
|
|
613
|
+
},
|
|
614
|
+
};
|
|
615
|
+
</script>
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
## ResetDrawer
|
|
619
|
+
|
|
620
|
+
用于解决业务抽屉外层直接 `v-if` 销毁时,`append-to-body` 挂载异常的问题。
|
|
621
|
+
|
|
622
|
+
```vue
|
|
623
|
+
<template>
|
|
624
|
+
<reset-drawer
|
|
625
|
+
v-model="drawerVisible"
|
|
626
|
+
title="业务抽屉"
|
|
627
|
+
size="480px"
|
|
628
|
+
:wrapper-closable="false"
|
|
629
|
+
>
|
|
630
|
+
<business-drawer-content :id="currentId" />
|
|
631
|
+
</reset-drawer>
|
|
632
|
+
</template>
|
|
633
|
+
|
|
634
|
+
<script>
|
|
635
|
+
import { ResetDrawer } from 'common-utils-kit/element';
|
|
636
|
+
|
|
637
|
+
export default {
|
|
638
|
+
components: {
|
|
639
|
+
ResetDrawer,
|
|
640
|
+
},
|
|
641
|
+
};
|
|
642
|
+
</script>
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
## ResetDialog
|
|
646
|
+
|
|
647
|
+
用于解决业务弹窗外层直接 `v-if` 销毁时,`append-to-body` 挂载异常的问题。
|
|
648
|
+
|
|
649
|
+
```vue
|
|
650
|
+
<template>
|
|
651
|
+
<reset-dialog
|
|
652
|
+
v-model="dialogVisible"
|
|
653
|
+
title="业务弹窗"
|
|
654
|
+
width="560px"
|
|
655
|
+
:close-on-click-modal="false"
|
|
656
|
+
>
|
|
657
|
+
<business-dialog-content :id="currentId" />
|
|
658
|
+
<template slot="footer">
|
|
659
|
+
<el-button @click="dialogVisible = false">取消</el-button>
|
|
660
|
+
<el-button type="primary" @click="dialogVisible = false">确定</el-button>
|
|
661
|
+
</template>
|
|
662
|
+
</reset-dialog>
|
|
663
|
+
</template>
|
|
664
|
+
|
|
665
|
+
<script>
|
|
666
|
+
import { ResetDialog } from 'common-utils-kit/element';
|
|
667
|
+
|
|
668
|
+
export default {
|
|
669
|
+
components: {
|
|
670
|
+
ResetDialog,
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
</script>
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
## View3D
|
|
677
|
+
|
|
678
|
+
`View3D` 为三维展示组件,当前通过 `common-utils-kit/element` 兼容导出:
|
|
679
|
+
|
|
680
|
+
```js
|
|
681
|
+
import { View3D } from 'common-utils-kit/element';
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
具体业务参数请结合实际页面或示例工程使用。
|
|
685
|
+
|
|
686
|
+
## 本地开发
|
|
687
|
+
|
|
688
|
+
```bash
|
|
689
|
+
npm run dev
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
## 构建
|
|
693
|
+
|
|
694
|
+
```bash
|
|
695
|
+
npm run build
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
## 构建 npm 主入口
|
|
699
|
+
|
|
700
|
+
```bash
|
|
701
|
+
npm run lib
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
## 构建 Element 子入口
|
|
705
|
+
|
|
706
|
+
```bash
|
|
707
|
+
npm run lib:module
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
## 检查
|
|
711
|
+
|
|
712
|
+
```bash
|
|
713
|
+
npm run lint
|
|
714
|
+
```
|