doway-coms 2.11.31 → 2.11.32

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 (92) hide show
  1. package/.browserslistrc +2 -2
  2. package/README.md +28 -28
  3. package/package.json +62 -62
  4. package/packages/AuditsList/index.js +7 -7
  5. package/packages/AuditsList/src/index.vue +314 -314
  6. package/packages/BaseButton/index.js +7 -7
  7. package/packages/BaseButton/src/index.vue +242 -242
  8. package/packages/BaseCheckbox/index.js +7 -7
  9. package/packages/BaseCheckbox/src/index.vue +134 -134
  10. package/packages/BaseDate/index.js +7 -7
  11. package/packages/BaseDate/src/index.vue +197 -197
  12. package/packages/BaseDateWeek/index.js +7 -7
  13. package/packages/BaseDateWeek/src/index.vue +163 -163
  14. package/packages/BaseDatetime/index.js +7 -7
  15. package/packages/BaseDatetime/src/index.vue +196 -196
  16. package/packages/BaseFileGroup/index.js +7 -7
  17. package/packages/BaseFileGroup/src/index.vue +724 -724
  18. package/packages/BaseForm/index.js +7 -7
  19. package/packages/BaseForm/src/index.vue +896 -896
  20. package/packages/BaseGantt/index.js +9 -9
  21. package/packages/BaseGantt/src/index.vue +617 -617
  22. package/packages/BaseGrid/index.js +9 -9
  23. package/packages/BaseGrid/src/exportCmp.vue +105 -105
  24. package/packages/BaseGrid/src/gridApi.js +32 -32
  25. package/packages/BaseGrid/src/index.vue +4271 -4268
  26. package/packages/BaseGridAdjust/index.js +9 -9
  27. package/packages/BaseGridAdjust/src/index.vue +482 -482
  28. package/packages/BaseInput/index.js +7 -7
  29. package/packages/BaseInput/src/index.vue +207 -207
  30. package/packages/BaseIntervalInput/index.js +7 -7
  31. package/packages/BaseIntervalInput/src/index.vue +310 -310
  32. package/packages/BaseKanbanEmpty/index.js +7 -7
  33. package/packages/BaseKanbanEmpty/src/index.vue +176 -176
  34. package/packages/BaseNumberInput/index.js +7 -7
  35. package/packages/BaseNumberInput/src/index.vue +291 -291
  36. package/packages/BasePagination/index.js +7 -7
  37. package/packages/BasePagination/src/index.vue +91 -91
  38. package/packages/BasePictureCard/index.js +7 -7
  39. package/packages/BasePictureCard/src/index.vue +671 -671
  40. package/packages/BasePrintPreview/index.js +7 -7
  41. package/packages/BasePrintPreview/src/index.vue +150 -150
  42. package/packages/BasePulldown/index.js +7 -7
  43. package/packages/BasePulldown/src/index.vue +1395 -1395
  44. package/packages/BaseSearch/index.js +7 -7
  45. package/packages/BaseSearch/src/index.vue +935 -935
  46. package/packages/BaseSelect/index.js +7 -7
  47. package/packages/BaseSelect/src/index.vue +155 -155
  48. package/packages/BaseSelectMulti/index.js +7 -7
  49. package/packages/BaseSelectMulti/src/index.vue +148 -148
  50. package/packages/BaseTextArea/index.js +7 -7
  51. package/packages/BaseTextArea/src/index.vue +197 -197
  52. package/packages/BaseTime/index.js +7 -7
  53. package/packages/BaseTime/src/index.vue +166 -166
  54. package/packages/BaseTool/index.js +7 -7
  55. package/packages/BaseTool/src/index.vue +353 -353
  56. package/packages/BaseToolStatus/index.js +7 -7
  57. package/packages/BaseToolStatus/src/ApprovalPersonsGroup.vue +41 -41
  58. package/packages/BaseToolStatus/src/index.vue +439 -439
  59. package/packages/BaseTreeSelect/index.js +8 -8
  60. package/packages/BaseTreeSelect/src/index.vue +437 -437
  61. package/packages/HistoryModal/index.js +8 -8
  62. package/packages/HistoryModal/src/index.vue +144 -144
  63. package/packages/LeaveAMessage/index.js +7 -7
  64. package/packages/LeaveAMessage/src/index.vue +601 -601
  65. package/packages/directive/clickoutside.js +44 -44
  66. package/packages/index.js +197 -197
  67. package/packages/styles/default.css +78 -78
  68. package/packages/styles/default.less +91 -91
  69. package/packages/styles/hps/default.less +25 -25
  70. package/packages/utils/api.js +122 -122
  71. package/packages/utils/auth.js +38 -38
  72. package/packages/utils/common.js +728 -728
  73. package/packages/utils/dom.js +181 -181
  74. package/packages/utils/enum.js +86 -86
  75. package/packages/utils/filters.js +495 -495
  76. package/packages/utils/gridFormat.js +66 -66
  77. package/packages/utils/msg.js +104 -104
  78. package/packages/utils/patchFiles.js +44 -44
  79. package/packages/utils/request.js +181 -181
  80. package/packages/utils/store.js +373 -373
  81. package/packages/utils/tscPrinter.js +101 -101
  82. package/sync.bash +6 -6
  83. package/vue.config.js +59 -59
  84. package/dist/css/chunk-vendors.7f83d8f9.css +0 -8
  85. package/dist/css/index.7946d50b.css +0 -1
  86. package/dist/favicon.ico +0 -0
  87. package/dist/js/chunk-vendors.28fda91d.js +0 -340
  88. package/dist/js/index.49bc6add.js +0 -2
  89. package/lib/doway-coms.common.js +0 -120397
  90. package/lib/doway-coms.css +0 -1
  91. package/lib/doway-coms.umd.js +0 -120407
  92. package/lib/doway-coms.umd.min.js +0 -328
@@ -1,496 +1,496 @@
1
- import moment from 'moment'
2
- import { controlType } from './enum'
3
- import XEUtils from 'xe-utils'
4
- import store from './store'
5
- // import { isNumber } from 'util'
6
- // import camelCase from 'lodash/camelCase'
7
- function pluralize(time, label) {
8
- if (time === 1) {
9
- return time + label
10
- }
11
- return time + label + 's'
12
- }
13
-
14
- export function timeAgo(time) {
15
- const between = Date.now() / 1000 - Number(time)
16
- if (between < 3600) {
17
- return pluralize(~~(between / 60), ' minute')
18
- } else if (between < 86400) {
19
- return pluralize(~~(between / 3600), ' hour')
20
- } else {
21
- return pluralize(~~(between / 86400), ' day')
22
- }
23
- }
24
-
25
- export function parseTime(time, cFormat) {
26
- if (arguments.length === 0) {
27
- return null
28
- }
29
-
30
- if ((time + '').length === 10) {
31
- time = +time * 1000
32
- }
33
-
34
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
35
- let date
36
- if (typeof time === 'object') {
37
- date = time
38
- } else {
39
- date = new Date(parseInt(time))
40
- }
41
- const formatObj = {
42
- y: date.getFullYear(),
43
- m: date.getMonth() + 1,
44
- d: date.getDate(),
45
- h: date.getHours(),
46
- i: date.getMinutes(),
47
- s: date.getSeconds(),
48
- a: date.getDay()
49
- }
50
- const timeStr = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
51
- let value = formatObj[key]
52
- if (key === 'a')
53
- return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
54
- if (result.length > 0 && value < 10) {
55
- value = '0' + value
56
- }
57
- return value || 0
58
- })
59
- return timeStr
60
- }
61
-
62
- export function formatTime(time, option) {
63
- time = +time * 1000
64
- const d = new Date(time)
65
- const now = Date.now()
66
-
67
- const diff = (now - d) / 1000
68
-
69
- if (diff < 30) {
70
- return '刚刚'
71
- } else if (diff < 3600) {
72
- // less 1 hour
73
- return Math.ceil(diff / 60) + '分钟前'
74
- } else if (diff < 3600 * 24) {
75
- return Math.ceil(diff / 3600) + '小时前'
76
- } else if (diff < 3600 * 24 * 2) {
77
- return '1天前'
78
- }
79
- if (option) {
80
- return parseTime(time, option)
81
- } else {
82
- return (
83
- d.getMonth() +
84
- 1 +
85
- '月' +
86
- d.getDate() +
87
- '日' +
88
- d.getHours() +
89
- '时' +
90
- d.getMinutes() +
91
- '分'
92
- )
93
- }
94
- }
95
-
96
- export function momentTime(time, cFormat) {
97
- return moment(time).format(cFormat)
98
- }
99
- /* 数字 格式化 */
100
- export function nFormatter(num, digits) {
101
- const si = [
102
- { value: 1e18, symbol: 'E' },
103
- { value: 1e15, symbol: 'P' },
104
- { value: 1e12, symbol: 'T' },
105
- { value: 1e9, symbol: 'G' },
106
- { value: 1e6, symbol: 'M' },
107
- { value: 1e3, symbol: 'k' }
108
- ]
109
- for (let i = 0; i < si.length; i++) {
110
- if (num >= si[i].value) {
111
- return (
112
- (num / si[i].value + 0.1)
113
- .toFixed(digits)
114
- .replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
115
- )
116
- }
117
- }
118
- return num.toString()
119
- }
120
-
121
- export function html2Text(val) {
122
- const div = document.createElement('div')
123
- div.innerHTML = val
124
- return div.textContent || div.innerText
125
- }
126
-
127
- export function toThousandslsFilter(num) {
128
- return (+num || 0)
129
- .toString()
130
- .replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
131
- }
132
-
133
- export function popupDisplayFilter(value, colInfo) {
134
- let linkField = colInfo.popupCaptionField.split('.')
135
- let returnValue = value
136
- for (let i = 0; i < linkField.length; i++) {
137
- if (
138
- returnValue[linkField[i]] === undefined ||
139
- returnValue[linkField[i]] === null
140
- ) {
141
- return null
142
- }
143
- returnValue = returnValue[linkField[i]]
144
- }
145
- return returnValue
146
- }
147
- export function displayFieldValueFilter(value, field) {
148
- if (value === null) {
149
- return value
150
- }
151
- let linkField = field.split('.')
152
- let returnValue = value
153
- for (let i = 0; i < linkField.length; i++) {
154
- if (
155
- returnValue[linkField[i]] === undefined ||
156
- returnValue[linkField[i]] === null
157
- ) {
158
- return null
159
- }
160
- returnValue = returnValue[linkField[i]]
161
- }
162
- return returnValue
163
- }
164
-
165
- export function displaySelectCaption(value, dataSource) {
166
- let tempItems = dataSource.filter(filterItem => {
167
- return filterItem.value === value
168
- })
169
- if (tempItems.length > 0) {
170
- return tempItems[0].caption
171
- } else {
172
- return value
173
- }
174
- }
175
- export function displaySelectMultiCaption(value, dataSource) {
176
- if (value && value.length > 0) {
177
- let tempValue = ''
178
- for (let i = 0; i < value.length; i++) {
179
- let tempCurrentValue = value[i]
180
- let tempItems = dataSource.filter(filterItem => {
181
- return filterItem.value === tempCurrentValue
182
- })
183
- if (tempItems.length > 0) {
184
- tempCurrentValue = tempItems[0].caption
185
- }
186
- tempValue = tempValue + tempCurrentValue
187
- if (i < value.length - 1) {
188
- tempValue = tempValue + ','
189
- }
190
- }
191
- return tempValue
192
- }
193
- return null
194
- }
195
-
196
- export function displayCaptionFilter(value, colInfo) {
197
- let linkField = colInfo.field.split('.')
198
- let fieldValue = value
199
- for (let i = 0; i < linkField.length; i++) {
200
- if (
201
- fieldValue[linkField[i]] === undefined ||
202
- fieldValue[linkField[i]] === null
203
- ) {
204
- return null
205
- }
206
- fieldValue = fieldValue[linkField[i]]
207
- }
208
- if (colInfo.controlType === controlType.drop) {
209
- let displayValue = colInfo.linkModuleData.dataSource.filter(item => {
210
- return item[colInfo.linkValueField] === fieldValue
211
- })
212
- if (displayValue.length > 0) {
213
- return displayValue[0][colInfo.linkCaptionField]
214
- }
215
- }
216
- if (colInfo.controlType === controlType.checkbox) {
217
- if (fieldValue === true || fieldValue === 'true') {
218
- fieldValue = '是'
219
- } else {
220
- fieldValue = '否'
221
- }
222
- }
223
- if (colInfo.controlType === controlType.date) {
224
- let dateTimeFormat = colInfo.format ? colInfo.format : 'YYYY-MM-DD'
225
- fieldValue = moment(fieldValue).format(dateTimeFormat)
226
- }
227
- if (colInfo.controlType === controlType.datetime) {
228
- let dateTimeFormat = colInfo.format
229
- ? colInfo.format
230
- : 'YYYY-MM-DD HH:mm:ss'
231
- fieldValue = moment(fieldValue).format(dateTimeFormat)
232
- }
233
- if (colInfo.controlType === controlType.time) {
234
- let timeFormat = colInfo.format ? colInfo.format : 'HH:mm:ss'
235
- fieldValue = moment('1970-01-01 ' + fieldValue).format(timeFormat)
236
- }
237
- if (colInfo.controlType === controlType.longtime) {
238
- let tempFieldValue = ''
239
- let tempDays = 0
240
- if (fieldValue.indexOf('.') > 0) {
241
- let arr = fieldValue.split('.')
242
- tempDays = arr[0]
243
- }
244
- //-------------------------
245
- // let tempYears = moment.duration(fieldValue).years()
246
- // if (tempYears > 0) {
247
- // tempFieldValue = tempYears + '年'
248
- // }
249
- // let tempMonths = moment.duration(fieldValue).months()
250
- // if (tempMonths > 0) {
251
- // tempFieldValue += tempMonths + '月'
252
- // }
253
- // let tempDays = moment.duration(fieldValue).days()
254
- //------------------------------
255
- if (tempDays > 0) {
256
- tempFieldValue += tempDays + '天'
257
- }
258
- tempFieldValue =
259
- tempFieldValue +
260
- moment.duration(fieldValue).hours() +
261
- '小时' +
262
- moment.duration(fieldValue).minutes() +
263
- '分钟' +
264
- moment.duration(fieldValue).seconds() +
265
- '秒'
266
- fieldValue = tempFieldValue
267
- }
268
-
269
- if (colInfo.controlType === controlType.dropmulti) {
270
- let returnValue = ''
271
- for (let x = 0; x < colInfo.linkModuleData.dataSource.length; x++) {
272
- if (
273
- fieldValue.indexOf(
274
- colInfo.linkModuleData.dataSource[x][colInfo.linkValueField]
275
- ) >= 0
276
- ) {
277
- returnValue =
278
- returnValue +
279
- colInfo.linkModuleData.dataSource[x][colInfo.linkCaptionField] +
280
- ','
281
- }
282
- }
283
- if (returnValue.length > 0) {
284
- returnValue = returnValue.substr(0, returnValue.length - 1)
285
- }
286
- return returnValue
287
- }
288
-
289
- if (colInfo.controlType === controlType.popup) {
290
- let tempField = colInfo.field
291
- if (colInfo.linkAttrField) {
292
- tempField = colInfo.linkAttrField + '.' + colInfo.linkCaptionField
293
- }
294
- let linkField = tempField.split('.')
295
- let returnValue = value
296
- for (let i = 0; i < linkField.length; i++) {
297
- if (
298
- returnValue[linkField[i]] === undefined ||
299
- returnValue[linkField[i]] === null
300
- ) {
301
- return null
302
- }
303
- returnValue = returnValue[linkField[i]]
304
- }
305
- return returnValue
306
- }
307
-
308
- if (colInfo.displayFormat) {
309
- if (colInfo.displayFormat.indexOf('p') === 0) {
310
- // 百分比显示
311
- let percentNumber = colInfo.displayFormat.substr(1)
312
- return (fieldValue * 100).toFixed(parseInt(percentNumber)) + '%'
313
- }
314
- }
315
-
316
- return fieldValue
317
- }
318
-
319
- export function splitFieldValueFilter(value, field) {
320
- let linkField = field.split('.')
321
- let tempValue = value
322
- for (let i = 0; i < linkField.length; i++) {
323
- tempValue = tempValue[linkField[i]]
324
- if (tempValue === undefined || tempValue === null) {
325
- return null
326
- }
327
- }
328
- return tempValue
329
- }
330
-
331
- export function dropdownDisplayFilter(value, colInfo) {
332
- let linkField = colInfo.field.split('.')
333
- let fieldValue = value
334
- for (let i = 0; i < linkField.length; i++) {
335
- if (
336
- fieldValue[linkField[i]] === undefined ||
337
- fieldValue[linkField[i]] === null
338
- ) {
339
- return null
340
- }
341
- fieldValue = fieldValue[linkField[i]]
342
- }
343
- if (colInfo.controlType === 'Drop') {
344
- let displayValue = colInfo.source.filter(item => {
345
- return item[colInfo.sourceValueField] === fieldValue
346
- })
347
- if (displayValue.length > 0) {
348
- return displayValue[0][colInfo.sourceCaptionField]
349
- }
350
- }
351
- if (colInfo.controlType === 'CheckBox') {
352
- if (fieldValue === true || fieldValue === 'true') {
353
- fieldValue = '是'
354
- } else {
355
- fieldValue = '否'
356
- }
357
- }
358
- if (colInfo.controlType === 'DateTime') {
359
- let dateTimeFormat = colInfo.format ? colInfo.format : 'YYYY-MM-DD'
360
- fieldValue = moment(fieldValue).format(dateTimeFormat)
361
- }
362
- if (colInfo.controlType === 'Time') {
363
- let timeFormat = colInfo.format ? colInfo.format : 'HH:mm:ss'
364
- fieldValue = moment('1970-01-01 ' + fieldValue).format(timeFormat)
365
- }
366
-
367
- if (colInfo.controlType === 'Popup') {
368
- let linkField = colInfo.popupCaptionField.split('.')
369
- let returnValue = value
370
- for (let i = 0; i < linkField.length; i++) {
371
- if (
372
- returnValue[linkField[i]] === undefined ||
373
- returnValue[linkField[i]] === null
374
- ) {
375
- return null
376
- }
377
- returnValue = returnValue[linkField[i]]
378
- }
379
-
380
- return returnValue
381
- }
382
- if (colInfo.controlType === 'PopupLink') {
383
- let linkField = colInfo.popupCaptionField.split('.')
384
- let returnValue = value
385
- for (let i = 0; i < linkField.length; i++) {
386
- if (
387
- returnValue[linkField[i]] === undefined ||
388
- returnValue[linkField[i]] === null
389
- ) {
390
- return null
391
- }
392
- returnValue = returnValue[linkField[i]]
393
- }
394
-
395
- return returnValue
396
- }
397
- return fieldValue
398
- }
399
-
400
- export function dateformat(time, cFormat) {
401
- return moment(time).format(cFormat)
402
- }
403
-
404
- export function secondDisplayTime(value) {
405
- let second = XEUtils.toInteger(value)
406
- let dayValue = XEUtils.floor(XEUtils.divide(second, 24 * 3600))
407
- let hourValue = 0
408
- let minuteValue = 0
409
- let secondValue = 0
410
- second = XEUtils.subtract(second, dayValue * 3600 * 24)
411
- if (second >= 0) {
412
- //设置小时数
413
- hourValue = XEUtils.floor(XEUtils.divide(second, 3600))
414
- //小时之后的剩余秒数
415
- second = XEUtils.subtract(second, hourValue * 3600)
416
- }
417
- if (second >= 0) {
418
- //设置分钟
419
- minuteValue = XEUtils.floor(XEUtils.divide(second, 60))
420
- //小时之后的剩余秒数
421
- second = XEUtils.subtract(second, minuteValue * 60)
422
- }
423
- if (second >= 0) {
424
- //设置秒数
425
- secondValue = second
426
- }
427
-
428
- return (
429
- dayValue +
430
- '天' +
431
- hourValue +
432
- '小时' +
433
- minuteValue +
434
- '分钟' +
435
- secondValue +
436
- '秒'
437
- )
438
- }
439
- /**
440
- * 网格非编辑状态格式化显示值
441
- * @param {*} rowInfo
442
- * @param {*} colInfo
443
- */
444
- export function gridDefaultValueDisplay(rowInfo,colInfo){
445
- let colControlType = colInfo.params.controlType
446
- let displayValue = rowInfo[colInfo.field]
447
- if(displayValue===null){
448
- return ''
449
- }
450
- switch(colControlType){
451
- case controlType.checkbox:
452
- displayValue = displayValue===true?'是':'否'
453
- break
454
- case controlType.select:
455
- const item = colInfo.params.dataSource.find(
456
- item => item.value === displayValue
457
- )
458
- displayValue = item ? item.caption :displayValue
459
- break
460
- case controlType.multiSelect:
461
- displayValue = XEUtils.map(displayValue, item => {
462
- return XEUtils.find(colInfo.params.dataSource, loop => loop.value === item).caption
463
- })
464
- displayValue = displayValue.join(',')
465
- break
466
- case controlType.number:
467
- if(colInfo.params&&colInfo.params.formatMethod){
468
- displayValue = colInfo.params.formatMethod(displayValue)
469
- }else{
470
- if(colInfo.params.doRound){
471
- displayValue=XEUtils.round(displayValue,colInfo.params.precision)
472
- }
473
- if(colInfo.params.percent){
474
- displayValue=XEUtils.round(displayValue*100,colInfo.params.precision)
475
- if(colInfo.params.thousandDigit===true){
476
- displayValue = displayValue.toLocaleString('en-US',{ maximumFractionDigits: 10 })
477
- }
478
- displayValue = displayValue+'%'
479
- }else{
480
- if(colInfo.params.thousandDigit===true){
481
- displayValue = displayValue.toLocaleString('en-US',{ maximumFractionDigits: 10 })
482
- }
483
- }
484
- }
485
-
486
- break
487
- case controlType.date:
488
- if(colInfo.params&&colInfo.params.formatMethod){
489
- displayValue=colInfo.params.formatMethod(displayValue)
490
- }else{
491
- displayValue=moment(displayValue).format(colInfo.params.format?colInfo.params.format:'YYYY-MM-DD')
492
- }
493
- break
494
- }
495
- return displayValue
1
+ import moment from 'moment'
2
+ import { controlType } from './enum'
3
+ import XEUtils from 'xe-utils'
4
+ import store from './store'
5
+ // import { isNumber } from 'util'
6
+ // import camelCase from 'lodash/camelCase'
7
+ function pluralize(time, label) {
8
+ if (time === 1) {
9
+ return time + label
10
+ }
11
+ return time + label + 's'
12
+ }
13
+
14
+ export function timeAgo(time) {
15
+ const between = Date.now() / 1000 - Number(time)
16
+ if (between < 3600) {
17
+ return pluralize(~~(between / 60), ' minute')
18
+ } else if (between < 86400) {
19
+ return pluralize(~~(between / 3600), ' hour')
20
+ } else {
21
+ return pluralize(~~(between / 86400), ' day')
22
+ }
23
+ }
24
+
25
+ export function parseTime(time, cFormat) {
26
+ if (arguments.length === 0) {
27
+ return null
28
+ }
29
+
30
+ if ((time + '').length === 10) {
31
+ time = +time * 1000
32
+ }
33
+
34
+ const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
35
+ let date
36
+ if (typeof time === 'object') {
37
+ date = time
38
+ } else {
39
+ date = new Date(parseInt(time))
40
+ }
41
+ const formatObj = {
42
+ y: date.getFullYear(),
43
+ m: date.getMonth() + 1,
44
+ d: date.getDate(),
45
+ h: date.getHours(),
46
+ i: date.getMinutes(),
47
+ s: date.getSeconds(),
48
+ a: date.getDay()
49
+ }
50
+ const timeStr = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
51
+ let value = formatObj[key]
52
+ if (key === 'a')
53
+ return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
54
+ if (result.length > 0 && value < 10) {
55
+ value = '0' + value
56
+ }
57
+ return value || 0
58
+ })
59
+ return timeStr
60
+ }
61
+
62
+ export function formatTime(time, option) {
63
+ time = +time * 1000
64
+ const d = new Date(time)
65
+ const now = Date.now()
66
+
67
+ const diff = (now - d) / 1000
68
+
69
+ if (diff < 30) {
70
+ return '刚刚'
71
+ } else if (diff < 3600) {
72
+ // less 1 hour
73
+ return Math.ceil(diff / 60) + '分钟前'
74
+ } else if (diff < 3600 * 24) {
75
+ return Math.ceil(diff / 3600) + '小时前'
76
+ } else if (diff < 3600 * 24 * 2) {
77
+ return '1天前'
78
+ }
79
+ if (option) {
80
+ return parseTime(time, option)
81
+ } else {
82
+ return (
83
+ d.getMonth() +
84
+ 1 +
85
+ '月' +
86
+ d.getDate() +
87
+ '日' +
88
+ d.getHours() +
89
+ '时' +
90
+ d.getMinutes() +
91
+ '分'
92
+ )
93
+ }
94
+ }
95
+
96
+ export function momentTime(time, cFormat) {
97
+ return moment(time).format(cFormat)
98
+ }
99
+ /* 数字 格式化 */
100
+ export function nFormatter(num, digits) {
101
+ const si = [
102
+ { value: 1e18, symbol: 'E' },
103
+ { value: 1e15, symbol: 'P' },
104
+ { value: 1e12, symbol: 'T' },
105
+ { value: 1e9, symbol: 'G' },
106
+ { value: 1e6, symbol: 'M' },
107
+ { value: 1e3, symbol: 'k' }
108
+ ]
109
+ for (let i = 0; i < si.length; i++) {
110
+ if (num >= si[i].value) {
111
+ return (
112
+ (num / si[i].value + 0.1)
113
+ .toFixed(digits)
114
+ .replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
115
+ )
116
+ }
117
+ }
118
+ return num.toString()
119
+ }
120
+
121
+ export function html2Text(val) {
122
+ const div = document.createElement('div')
123
+ div.innerHTML = val
124
+ return div.textContent || div.innerText
125
+ }
126
+
127
+ export function toThousandslsFilter(num) {
128
+ return (+num || 0)
129
+ .toString()
130
+ .replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
131
+ }
132
+
133
+ export function popupDisplayFilter(value, colInfo) {
134
+ let linkField = colInfo.popupCaptionField.split('.')
135
+ let returnValue = value
136
+ for (let i = 0; i < linkField.length; i++) {
137
+ if (
138
+ returnValue[linkField[i]] === undefined ||
139
+ returnValue[linkField[i]] === null
140
+ ) {
141
+ return null
142
+ }
143
+ returnValue = returnValue[linkField[i]]
144
+ }
145
+ return returnValue
146
+ }
147
+ export function displayFieldValueFilter(value, field) {
148
+ if (value === null) {
149
+ return value
150
+ }
151
+ let linkField = field.split('.')
152
+ let returnValue = value
153
+ for (let i = 0; i < linkField.length; i++) {
154
+ if (
155
+ returnValue[linkField[i]] === undefined ||
156
+ returnValue[linkField[i]] === null
157
+ ) {
158
+ return null
159
+ }
160
+ returnValue = returnValue[linkField[i]]
161
+ }
162
+ return returnValue
163
+ }
164
+
165
+ export function displaySelectCaption(value, dataSource) {
166
+ let tempItems = dataSource.filter(filterItem => {
167
+ return filterItem.value === value
168
+ })
169
+ if (tempItems.length > 0) {
170
+ return tempItems[0].caption
171
+ } else {
172
+ return value
173
+ }
174
+ }
175
+ export function displaySelectMultiCaption(value, dataSource) {
176
+ if (value && value.length > 0) {
177
+ let tempValue = ''
178
+ for (let i = 0; i < value.length; i++) {
179
+ let tempCurrentValue = value[i]
180
+ let tempItems = dataSource.filter(filterItem => {
181
+ return filterItem.value === tempCurrentValue
182
+ })
183
+ if (tempItems.length > 0) {
184
+ tempCurrentValue = tempItems[0].caption
185
+ }
186
+ tempValue = tempValue + tempCurrentValue
187
+ if (i < value.length - 1) {
188
+ tempValue = tempValue + ','
189
+ }
190
+ }
191
+ return tempValue
192
+ }
193
+ return null
194
+ }
195
+
196
+ export function displayCaptionFilter(value, colInfo) {
197
+ let linkField = colInfo.field.split('.')
198
+ let fieldValue = value
199
+ for (let i = 0; i < linkField.length; i++) {
200
+ if (
201
+ fieldValue[linkField[i]] === undefined ||
202
+ fieldValue[linkField[i]] === null
203
+ ) {
204
+ return null
205
+ }
206
+ fieldValue = fieldValue[linkField[i]]
207
+ }
208
+ if (colInfo.controlType === controlType.drop) {
209
+ let displayValue = colInfo.linkModuleData.dataSource.filter(item => {
210
+ return item[colInfo.linkValueField] === fieldValue
211
+ })
212
+ if (displayValue.length > 0) {
213
+ return displayValue[0][colInfo.linkCaptionField]
214
+ }
215
+ }
216
+ if (colInfo.controlType === controlType.checkbox) {
217
+ if (fieldValue === true || fieldValue === 'true') {
218
+ fieldValue = '是'
219
+ } else {
220
+ fieldValue = '否'
221
+ }
222
+ }
223
+ if (colInfo.controlType === controlType.date) {
224
+ let dateTimeFormat = colInfo.format ? colInfo.format : 'YYYY-MM-DD'
225
+ fieldValue = moment(fieldValue).format(dateTimeFormat)
226
+ }
227
+ if (colInfo.controlType === controlType.datetime) {
228
+ let dateTimeFormat = colInfo.format
229
+ ? colInfo.format
230
+ : 'YYYY-MM-DD HH:mm:ss'
231
+ fieldValue = moment(fieldValue).format(dateTimeFormat)
232
+ }
233
+ if (colInfo.controlType === controlType.time) {
234
+ let timeFormat = colInfo.format ? colInfo.format : 'HH:mm:ss'
235
+ fieldValue = moment('1970-01-01 ' + fieldValue).format(timeFormat)
236
+ }
237
+ if (colInfo.controlType === controlType.longtime) {
238
+ let tempFieldValue = ''
239
+ let tempDays = 0
240
+ if (fieldValue.indexOf('.') > 0) {
241
+ let arr = fieldValue.split('.')
242
+ tempDays = arr[0]
243
+ }
244
+ //-------------------------
245
+ // let tempYears = moment.duration(fieldValue).years()
246
+ // if (tempYears > 0) {
247
+ // tempFieldValue = tempYears + '年'
248
+ // }
249
+ // let tempMonths = moment.duration(fieldValue).months()
250
+ // if (tempMonths > 0) {
251
+ // tempFieldValue += tempMonths + '月'
252
+ // }
253
+ // let tempDays = moment.duration(fieldValue).days()
254
+ //------------------------------
255
+ if (tempDays > 0) {
256
+ tempFieldValue += tempDays + '天'
257
+ }
258
+ tempFieldValue =
259
+ tempFieldValue +
260
+ moment.duration(fieldValue).hours() +
261
+ '小时' +
262
+ moment.duration(fieldValue).minutes() +
263
+ '分钟' +
264
+ moment.duration(fieldValue).seconds() +
265
+ '秒'
266
+ fieldValue = tempFieldValue
267
+ }
268
+
269
+ if (colInfo.controlType === controlType.dropmulti) {
270
+ let returnValue = ''
271
+ for (let x = 0; x < colInfo.linkModuleData.dataSource.length; x++) {
272
+ if (
273
+ fieldValue.indexOf(
274
+ colInfo.linkModuleData.dataSource[x][colInfo.linkValueField]
275
+ ) >= 0
276
+ ) {
277
+ returnValue =
278
+ returnValue +
279
+ colInfo.linkModuleData.dataSource[x][colInfo.linkCaptionField] +
280
+ ','
281
+ }
282
+ }
283
+ if (returnValue.length > 0) {
284
+ returnValue = returnValue.substr(0, returnValue.length - 1)
285
+ }
286
+ return returnValue
287
+ }
288
+
289
+ if (colInfo.controlType === controlType.popup) {
290
+ let tempField = colInfo.field
291
+ if (colInfo.linkAttrField) {
292
+ tempField = colInfo.linkAttrField + '.' + colInfo.linkCaptionField
293
+ }
294
+ let linkField = tempField.split('.')
295
+ let returnValue = value
296
+ for (let i = 0; i < linkField.length; i++) {
297
+ if (
298
+ returnValue[linkField[i]] === undefined ||
299
+ returnValue[linkField[i]] === null
300
+ ) {
301
+ return null
302
+ }
303
+ returnValue = returnValue[linkField[i]]
304
+ }
305
+ return returnValue
306
+ }
307
+
308
+ if (colInfo.displayFormat) {
309
+ if (colInfo.displayFormat.indexOf('p') === 0) {
310
+ // 百分比显示
311
+ let percentNumber = colInfo.displayFormat.substr(1)
312
+ return (fieldValue * 100).toFixed(parseInt(percentNumber)) + '%'
313
+ }
314
+ }
315
+
316
+ return fieldValue
317
+ }
318
+
319
+ export function splitFieldValueFilter(value, field) {
320
+ let linkField = field.split('.')
321
+ let tempValue = value
322
+ for (let i = 0; i < linkField.length; i++) {
323
+ tempValue = tempValue[linkField[i]]
324
+ if (tempValue === undefined || tempValue === null) {
325
+ return null
326
+ }
327
+ }
328
+ return tempValue
329
+ }
330
+
331
+ export function dropdownDisplayFilter(value, colInfo) {
332
+ let linkField = colInfo.field.split('.')
333
+ let fieldValue = value
334
+ for (let i = 0; i < linkField.length; i++) {
335
+ if (
336
+ fieldValue[linkField[i]] === undefined ||
337
+ fieldValue[linkField[i]] === null
338
+ ) {
339
+ return null
340
+ }
341
+ fieldValue = fieldValue[linkField[i]]
342
+ }
343
+ if (colInfo.controlType === 'Drop') {
344
+ let displayValue = colInfo.source.filter(item => {
345
+ return item[colInfo.sourceValueField] === fieldValue
346
+ })
347
+ if (displayValue.length > 0) {
348
+ return displayValue[0][colInfo.sourceCaptionField]
349
+ }
350
+ }
351
+ if (colInfo.controlType === 'CheckBox') {
352
+ if (fieldValue === true || fieldValue === 'true') {
353
+ fieldValue = '是'
354
+ } else {
355
+ fieldValue = '否'
356
+ }
357
+ }
358
+ if (colInfo.controlType === 'DateTime') {
359
+ let dateTimeFormat = colInfo.format ? colInfo.format : 'YYYY-MM-DD'
360
+ fieldValue = moment(fieldValue).format(dateTimeFormat)
361
+ }
362
+ if (colInfo.controlType === 'Time') {
363
+ let timeFormat = colInfo.format ? colInfo.format : 'HH:mm:ss'
364
+ fieldValue = moment('1970-01-01 ' + fieldValue).format(timeFormat)
365
+ }
366
+
367
+ if (colInfo.controlType === 'Popup') {
368
+ let linkField = colInfo.popupCaptionField.split('.')
369
+ let returnValue = value
370
+ for (let i = 0; i < linkField.length; i++) {
371
+ if (
372
+ returnValue[linkField[i]] === undefined ||
373
+ returnValue[linkField[i]] === null
374
+ ) {
375
+ return null
376
+ }
377
+ returnValue = returnValue[linkField[i]]
378
+ }
379
+
380
+ return returnValue
381
+ }
382
+ if (colInfo.controlType === 'PopupLink') {
383
+ let linkField = colInfo.popupCaptionField.split('.')
384
+ let returnValue = value
385
+ for (let i = 0; i < linkField.length; i++) {
386
+ if (
387
+ returnValue[linkField[i]] === undefined ||
388
+ returnValue[linkField[i]] === null
389
+ ) {
390
+ return null
391
+ }
392
+ returnValue = returnValue[linkField[i]]
393
+ }
394
+
395
+ return returnValue
396
+ }
397
+ return fieldValue
398
+ }
399
+
400
+ export function dateformat(time, cFormat) {
401
+ return moment(time).format(cFormat)
402
+ }
403
+
404
+ export function secondDisplayTime(value) {
405
+ let second = XEUtils.toInteger(value)
406
+ let dayValue = XEUtils.floor(XEUtils.divide(second, 24 * 3600))
407
+ let hourValue = 0
408
+ let minuteValue = 0
409
+ let secondValue = 0
410
+ second = XEUtils.subtract(second, dayValue * 3600 * 24)
411
+ if (second >= 0) {
412
+ //设置小时数
413
+ hourValue = XEUtils.floor(XEUtils.divide(second, 3600))
414
+ //小时之后的剩余秒数
415
+ second = XEUtils.subtract(second, hourValue * 3600)
416
+ }
417
+ if (second >= 0) {
418
+ //设置分钟
419
+ minuteValue = XEUtils.floor(XEUtils.divide(second, 60))
420
+ //小时之后的剩余秒数
421
+ second = XEUtils.subtract(second, minuteValue * 60)
422
+ }
423
+ if (second >= 0) {
424
+ //设置秒数
425
+ secondValue = second
426
+ }
427
+
428
+ return (
429
+ dayValue +
430
+ '天' +
431
+ hourValue +
432
+ '小时' +
433
+ minuteValue +
434
+ '分钟' +
435
+ secondValue +
436
+ '秒'
437
+ )
438
+ }
439
+ /**
440
+ * 网格非编辑状态格式化显示值
441
+ * @param {*} rowInfo
442
+ * @param {*} colInfo
443
+ */
444
+ export function gridDefaultValueDisplay(rowInfo,colInfo){
445
+ let colControlType = colInfo.params.controlType
446
+ let displayValue = rowInfo[colInfo.field]
447
+ if(displayValue===null){
448
+ return ''
449
+ }
450
+ switch(colControlType){
451
+ case controlType.checkbox:
452
+ displayValue = displayValue===true?'是':'否'
453
+ break
454
+ case controlType.select:
455
+ const item = colInfo.params.dataSource.find(
456
+ item => item.value === displayValue
457
+ )
458
+ displayValue = item ? item.caption :displayValue
459
+ break
460
+ case controlType.multiSelect:
461
+ displayValue = XEUtils.map(displayValue, item => {
462
+ return XEUtils.find(colInfo.params.dataSource, loop => loop.value === item).caption
463
+ })
464
+ displayValue = displayValue.join(',')
465
+ break
466
+ case controlType.number:
467
+ if(colInfo.params&&colInfo.params.formatMethod){
468
+ displayValue = colInfo.params.formatMethod(displayValue)
469
+ }else{
470
+ if(colInfo.params.doRound){
471
+ displayValue=XEUtils.round(displayValue,colInfo.params.precision)
472
+ }
473
+ if(colInfo.params.percent){
474
+ displayValue=XEUtils.round(displayValue*100,colInfo.params.precision)
475
+ if(colInfo.params.thousandDigit===true){
476
+ displayValue = displayValue.toLocaleString('en-US',{ maximumFractionDigits: 10 })
477
+ }
478
+ displayValue = displayValue+'%'
479
+ }else{
480
+ if(colInfo.params.thousandDigit===true){
481
+ displayValue = displayValue.toLocaleString('en-US',{ maximumFractionDigits: 10 })
482
+ }
483
+ }
484
+ }
485
+
486
+ break
487
+ case controlType.date:
488
+ if(colInfo.params&&colInfo.params.formatMethod){
489
+ displayValue=colInfo.params.formatMethod(displayValue)
490
+ }else{
491
+ displayValue=moment(displayValue).format(colInfo.params.format?colInfo.params.format:'YYYY-MM-DD')
492
+ }
493
+ break
494
+ }
495
+ return displayValue
496
496
  }