cloud-web-corejs 1.0.54-dev.555 → 1.0.54-dev.557

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 (54) hide show
  1. package/package.json +1 -3
  2. package/src/components/baseAlert/mixins.js +1 -61
  3. package/src/components/baseInputExport/mixins.js +1 -391
  4. package/src/components/errorMsg/mixins.js +1 -96
  5. package/src/components/excelImport/mixins.js +1 -774
  6. package/src/components/fileLibrary/index.vue +15 -17
  7. package/src/components/hiprint/view/design/index.vue +139 -47
  8. package/src/components/hiprint/view/design/preview.vue +75 -52
  9. package/src/components/hiprint/view/json-view.vue +31 -31
  10. package/src/components/luckysheet/dialog.vue +1 -12
  11. package/src/components/luckysheet/export.js +1 -591
  12. package/src/components/luckysheet/fileUtils.js +1 -147
  13. package/src/components/luckysheet/index.js +1 -72
  14. package/src/components/luckysheet/view.vue +0 -92
  15. package/src/components/oplogTable/mixins.js +1 -80
  16. package/src/components/table/index.js +1 -1044
  17. package/src/components/wf/wf.js +1 -2156
  18. package/src/components/wf/wfUtil.js +1 -279
  19. package/src/components/xform/form-designer/form-widget/components/gantt/index.vue +1 -1
  20. package/src/components/xform/form-designer/form-widget/dialog/importDialogMixin.js +1 -1752
  21. package/src/components/xform/form-designer/form-widget/field-widget/fieldMixin.js +1 -1630
  22. package/src/components/xform/form-designer/form-widget/field-widget/gantt-widget.vue +1 -1
  23. package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/exportItemColumns-dialog.vue +1 -1
  24. package/src/components/xform/form-render/container-item/data-table-mixin.js +1 -3043
  25. package/src/components/xform/form-render/container-item/table2-item.vue +12 -4
  26. package/src/components/xform/form-render/indexMixin.js +1 -3677
  27. package/src/mixins/tableTree/index.js +1 -196
  28. package/src/router/modules/customer.js +7 -7
  29. package/src/store/modules/permission.js +2 -2
  30. package/src/views/bd/setting/bd_attach_setting/mixins/list.js +1 -239
  31. package/src/views/bd/setting/form_script/mixins/dialog.js +1 -130
  32. package/src/views/bd/setting/form_script/mixins/edit.js +2 -199
  33. package/src/views/bd/setting/form_script/mixins/edit1.js +2 -193
  34. package/src/views/bd/setting/form_script/mixins/list.js +1 -236
  35. package/src/views/bd/setting/form_script/mixins/list1.js +1 -410
  36. package/src/views/bd/setting/form_template/mixins/batchWfObjConfigDialog.js +1 -278
  37. package/src/views/bd/setting/form_template/mixins/edit.js +1 -225
  38. package/src/views/bd/setting/form_template/mixins/list.js +1 -665
  39. package/src/views/bd/setting/form_template/mixins/otherAuthDialog.js +1 -187
  40. package/src/views/bd/setting/menu_kind/mixins/authDialog.js +1 -294
  41. package/src/views/bd/setting/menu_kind/mixins/list.js +1 -201
  42. package/src/views/bd/setting/table_model/mixins/edit.js +1 -1189
  43. package/src/views/bd/setting/table_model/mixins/list.js +1 -427
  44. package/src/views/bd/setting/table_model/mixins/otherAuthDialog.js +1 -195
  45. package/src/views/user/ledger_library/list.vue +12 -10
  46. package/src/views/user/position/list.vue +68 -124
  47. package/src/components/luckysheet/README.md +0 -329
  48. package/src/components/luckysheet/colorTest.js +0 -54
  49. package/src/components/luckysheet/exportExample.js +0 -182
  50. package/src/components/luckysheet/fileConversionExample.js +0 -127
  51. package/src/components/luckysheet/testExport.js +0 -57
  52. package/src/components/xform/form-designer/form-widget/dialog/importDialogMixin - /345/211/257/346/234/254.js" +0 -1639
  53. package/src/components/xform/utils/formula-util copy 2.js +0 -945
  54. package/src/components/xform/utils/formula-util copy.js +0 -856
@@ -1,856 +0,0 @@
1
- // 计算公式相关工具方法
2
- import {evalFn, getFieldWidgetById, traverseFieldWidgetsOfContainer} from "@base/components/xform/utils/util";
3
- import * as formulajs from '@formulajs/formulajs'
4
- import {EditorView} from "codemirror"
5
- import {MatchDecorator, Decoration, ViewPlugin, WidgetType} from "@codemirror/view"
6
- import {translate} from "@base/components/xform/utils/i18n";
7
-
8
- class PlaceholderWidget extends WidgetType {
9
- field;
10
- text;
11
- type;
12
-
13
- constructor(text) {
14
- super();
15
- if (text) {
16
- //type 仅用于区分颜色
17
- const [field, mText, type] = text.split(".");
18
- this.text = mText;
19
- this.type = type;
20
- this.field = field;
21
- }
22
- }
23
-
24
- eq(other) {
25
- return this.text === other.text;
26
- }
27
-
28
- // 此处是我们的渲染方法
29
- toDOM() {
30
- let elt = document.createElement('span');
31
- if (!this.text) return elt;
32
- elt.className = this.type === "func" ? "cm-function" : "cm-field";
33
- elt.textContent = this.text;
34
- return elt;
35
- }
36
-
37
- ignoreEvent() {
38
- return true;
39
- }
40
- }
41
-
42
- export const FORMULA_REG_EXP = /\{\{(\w+\.[^.]+\.\w+)}}/g
43
-
44
- const placeholderMatcher = new MatchDecorator({
45
- regexp: /\{\{(.+?)}}/g,
46
- decoration: (match) =>
47
- Decoration.replace({
48
- widget: new PlaceholderWidget(match[1])
49
- })
50
- });
51
-
52
-
53
- export const placeholders = ViewPlugin.fromClass(class {
54
- placeholders
55
-
56
- constructor(view) {
57
- this.placeholders = placeholderMatcher.createDeco(view)
58
- }
59
-
60
- update(update) {
61
- this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders)
62
- }
63
- }, {
64
- decorations: instance => instance.placeholders,
65
- provide: plugin => EditorView.atomicRanges.of(view => {
66
- return view.plugin(plugin)?.placeholders || Decoration.none
67
- })
68
- })
69
-
70
- // 背景样式
71
- export const baseTheme = EditorView.baseTheme({
72
- ".cm-function": {
73
- paddingLeft: "6px",
74
- paddingRight: "6px",
75
- paddingTop: "3px",
76
- paddingBottom: "3px",
77
- marginLeft: "3px",
78
- marginRight: "3px",
79
- backgroundColor: "#ffcdcc",
80
- borderRadius: "4px",
81
- },
82
- ".cm-field": {
83
- paddingLeft: "6px",
84
- paddingRight: "6px",
85
- paddingTop: "3px",
86
- paddingBottom: "3px",
87
- marginLeft: "3px",
88
- marginRight: "3px",
89
- backgroundColor: "#f8e7a0",
90
- borderRadius: "4px",
91
- }
92
-
93
- });
94
-
95
- export function calculateFormula(VFR, DSV, formulaJs, formulaFieldRef, changedFieldRef) {
96
- if (formulaFieldRef.tableParam) {
97
- } else if (!!formulaFieldRef.subFormItemFlag && !!changedFieldRef.subFormItemFlag) {
98
- /* 子表单字段变化,只能触发子表单同一行字段的计算公式重新计算!! */
99
- if (changedFieldRef.subFormRowId !== formulaFieldRef.subFormRowId) {
100
- return
101
- }
102
- }
103
-
104
- let formula = formulaFieldRef.field.options.formula
105
- formula = replaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef, changedFieldRef) //替换字段值
106
- if (!formula) {
107
- return
108
- }
109
-
110
- //替换formula-js函数
111
- const matchResult = formula.match(/[A-Za-z]*/g)
112
- let matchedList = []
113
- if (!!matchResult) {
114
- matchResult.forEach(mi => {
115
- if (!!mi && (findCalFunStartIndex(mi) !== -1) && !matchedList.includes(mi)) {
116
- const funcName = mi.toUpperCase()
117
- formula = formula.replaceAll(mi, 'formulaJs.' + funcName)
118
- matchedList.push(mi)
119
- }
120
- })
121
- }
122
-
123
- const formulaValue = evalFn(formula, DSV, VFR, formulaJs)
124
- if(formulaFieldRef)formulaFieldRef.setValue(formulaValue)
125
- return formulaValue
126
- }
127
-
128
- export function baseCalculateFormula(that,formulaStr, row /* VFR, DSV, formulaJs, formulaFieldRef, changedFieldRef */) {
129
- if(!formulaStr)return
130
- let formula = formulaStr;
131
- let VFR = that.getFormRef();
132
- let DSV = that.getGlobalDsv()
133
- let formulaJs = formulajs
134
- let formulaFieldRef = that;
135
- if (formulaFieldRef.tableParam) {
136
- } else if (!!formulaFieldRef.subFormItemFlag && !!changedFieldRef.subFormItemFlag) {
137
- /* 子表单字段变化,只能触发子表单同一行字段的计算公式重新计算!! */
138
- /* if (changedFieldRef.subFormRowId !== formulaFieldRef.subFormRowId) {
139
- return
140
- } */
141
- }
142
-
143
- formula = baseReplaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef,formula,row) //替换字段值
144
- if (!formula) {
145
- return
146
- }
147
-
148
- //替换formula-js函数
149
- const matchResult = formula.match(/[A-Za-z]*/g)
150
- let matchedList = []
151
- if (!!matchResult) {
152
- matchResult.forEach(mi => {
153
- if (!!mi && (findCalFunStartIndex(mi) !== -1) && !matchedList.includes(mi)) {
154
- const funcName = mi.toUpperCase()
155
- formula = formula.replaceAll(mi, 'formulaJs.' + funcName)
156
- matchedList.push(mi)
157
- }
158
- })
159
- }
160
-
161
- const formulaValue = evalFn(formula, DSV, VFR, formulaJs)
162
- return formulaValue
163
- }
164
-
165
-
166
- function getFieldKeyName(widget) {
167
- let o = widget.options.name;
168
- return (widget.options.keyNameEnabled && widget.options.keyName) || o;
169
- }
170
-
171
- function funOtherHanlde(){
172
-
173
- }
174
- /**
175
- * 替换计算公式中的字段值
176
- * @param VFR
177
- * @param formulaFieldRef
178
- * @returns {*}
179
- */
180
- export function baseReplaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef, formula, row) {
181
- // let formula = formulaFieldRef.field.options.formula
182
- const matchResult = formula.match(FORMULA_REG_EXP)
183
- if (!matchResult) {
184
- return formula
185
- }
186
-
187
- let resultFormula = formula
188
- let quitFlag = false
189
- matchResult.forEach(mi => {
190
- const thirdPart = mi.split('.')[2]
191
- const nodeType = thirdPart.substring(0, thirdPart.length - 2)
192
- if (nodeType === 'func') {
193
- const funcName = mi.split('.')[1]
194
- resultFormula = resultFormula.replace(mi, funcName)
195
- return
196
- }
197
-
198
- const firstPart = mi.split('.')[0]
199
- const fieldId = firstPart.substring(2, firstPart.length)
200
- const fieldSchema = getFieldWidgetById(VFR.formJsonObj.widgetList, fieldId, false)
201
- if (!!fieldSchema) {
202
- let fieldRef = VFR.getWidgetRef(fieldSchema.options.name)
203
- if (!!fieldRef) {
204
- //是否要考虑字符串值的替换??
205
- // resultFormula = resultFormula.replace(mi, fieldRef.currentValue)
206
- let fieldKeyName = getFieldKeyName(fieldSchema)
207
- let value = fieldRef.formModel[fieldKeyName]??null;
208
- resultFormula = resultFormula.replace(mi, value)
209
- } else { //getWidgetRef找不到,则可能是子表单字段
210
- const subFormNameOfField = VFR.getSubFormNameOfWidget(fieldSchema.options.name)
211
- if (!!formulaFieldRef.subFormItemFlag || formulaFieldRef.tableParam || row) {
212
- /* 如果当前计算字段是子表单字段,要判断公式中的子表单字段是否和当前计算字段是否属于同一子表单!! */
213
- if(row){
214
- let fieldKeyName = getFieldKeyName(fieldSchema)
215
- let value = row[fieldKeyName]??null;
216
- resultFormula = resultFormula.replaceAll(mi, value)
217
- /*
218
- let subFormRowId = row._X_ROW_KEY
219
- fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '_' + subFormRowId)
220
- if (!!fieldRef) {
221
- let value = fieldRef.currentValue;
222
- resultFormula = resultFormula.replaceAll(mi, value)
223
- } else {
224
- de
225
- quitFlag = true
226
- console.error('Field not found: ' + fieldSchema.options.label)
227
- } */
228
- }else if (subFormNameOfField === formulaFieldRef?.parentWidget?.options?.name) {
229
- let subFormRowId = formulaFieldRef.tableParam.row._X_ROW_KEY
230
- fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '_' + subFormRowId)
231
- if (!!fieldRef) {
232
- let value = fieldRef.currentValue??null;
233
- resultFormula = resultFormula.replaceAll(mi, value)
234
- } else {
235
- quitFlag = true
236
- console.error('Field not found: ' + fieldSchema.options.label)
237
- }
238
- } else if (subFormNameOfField === formulaFieldRef.subFormName) {
239
- fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '@row' + formulaFieldRef.subFormRowId)
240
- if (!!fieldRef) {
241
- resultFormula = resultFormula.replaceAll(mi, fieldRef.currentValue)
242
- } else {
243
- quitFlag = true
244
- console.error('Field not found: ' + fieldSchema.options.label)
245
- }
246
- }else {
247
- console.error('Invalid formula!')
248
- }
249
- } else {
250
- /* 在主表单字段的计算公式中使用子表单字段,应将子表单所有记录同字段的值代入!! */
251
- // const subFormValue = VFR.formDataModel[subFormNameOfField]
252
- let dataTableRef = VFR.getWidgetRef(subFormNameOfField)
253
- const subFormValue = VFR.formDataModel[fieldKeyName(dataTableRef.widget)]
254
- let allSubFieldValues = ''
255
- // const subFieldName = fieldSchema.options.name
256
- const subFieldName = fieldKeyName(fieldSchema)
257
- subFormValue.forEach((vi, idx) => {
258
- let val = vi[subFieldName]??null
259
- allSubFieldValues = (idx === 0) ? val : allSubFieldValues + ', ' + val
260
- })
261
- resultFormula = resultFormula.replaceAll(mi, allSubFieldValues)
262
- }
263
- }
264
- }
265
- })
266
-
267
- return quitFlag ? null : resultFormula
268
- }
269
-
270
- export function calculateFormula2(formulaStr, data, that) {
271
- if(!formulaStr)return
272
- let formula = formulaStr;
273
- let VFR = that.getFormRef();
274
- let DSV = that.getGlobalDsv()
275
- let formulaJs = formulajs
276
-
277
- if(data){
278
- for(let key in data){
279
- formula = formula.replaceAll(`[${key}]`,(data[key] || 0))
280
- }
281
- }
282
-
283
- //替换formula-js函数
284
- const matchResult = formula.match(/[A-Za-z]*/g)
285
- let matchedList = []
286
- if (!!matchResult) {
287
- matchResult.forEach(mi => {
288
- if (!!mi && (findCalFunStartIndex(mi) !== -1) && !matchedList.includes(mi)) {
289
- const funcName = mi.toUpperCase()
290
- formula = formula.replaceAll(mi, 'formulaJs.' + funcName)
291
- matchedList.push(mi)
292
- }
293
- })
294
- }
295
-
296
- const formulaValue = evalFn(formula, DSV, VFR, formulaJs)
297
- return formulaValue
298
- }
299
-
300
- /**
301
- * 判断字段是否用在计算公式中
302
- * @param fieldName
303
- * @param formula
304
- * @param VFR
305
- */
306
- export function fieldIsUsedInFormula(fieldName, formula, VFR, fieldTarget) {
307
- const matchResult = formula.match(FORMULA_REG_EXP)
308
- if (!matchResult) {
309
- return false
310
- }
311
-
312
- let foundResult = false
313
- matchResult.forEach(mi => {
314
- const thirdPart = mi.split('.')[2]
315
- const nodeType = thirdPart.substring(0, thirdPart.length - 2)
316
- if (nodeType === 'func') {
317
- return
318
- }
319
-
320
- const firstPart = mi.split('.')[0]
321
- const fieldId = firstPart.substring(2, firstPart.length)
322
- let fieldSchema = getFieldWidgetById(VFR.formJsonObj.widgetList, fieldId, false)
323
- if (!fieldSchema) {
324
- console.error('The field used by formula not found: ', fieldId)
325
- console.error('The formula is: ', formula)
326
- }
327
- if (fieldSchema && (fieldSchema.options.name === fieldName)) {
328
- foundResult = true
329
- }
330
- })
331
-
332
- return foundResult
333
- }
334
-
335
-
336
- /**
337
- * 替换计算公式中的字段值
338
- * @param VFR
339
- * @param formulaFieldRef
340
- * @returns {*}
341
- */
342
- export function replaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef) {
343
- let formula = formulaFieldRef.field.options.formula
344
- const matchResult = formula.match(FORMULA_REG_EXP)
345
- if (!matchResult) {
346
- return formula
347
- }
348
-
349
- let resultFormula = formula
350
- let quitFlag = false
351
- matchResult.forEach(mi => {
352
- const thirdPart = mi.split('.')[2]
353
- const nodeType = thirdPart.substring(0, thirdPart.length - 2)
354
- if (nodeType === 'func') {
355
- const funcName = mi.split('.')[1]
356
- resultFormula = resultFormula.replace(mi, funcName)
357
- return
358
- }
359
-
360
- const firstPart = mi.split('.')[0]
361
- const fieldId = firstPart.substring(2, firstPart.length)
362
- const fieldSchema = getFieldWidgetById(VFR.formJsonObj.widgetList, fieldId, false)
363
- if (!!fieldSchema) {
364
- let fieldRef = VFR.getWidgetRef(fieldSchema.options.name)
365
- if (!!fieldRef) {
366
- //是否要考虑字符串值的替换??
367
- resultFormula = resultFormula.replace(mi, fieldRef.currentValue)
368
- } else { //getWidgetRef找不到,则可能是子表单字段
369
- const subFormNameOfField = VFR.getSubFormNameOfWidget(fieldSchema.options.name)
370
- if (!!formulaFieldRef.subFormItemFlag || formulaFieldRef.tableParam) {
371
- /* 如果当前计算字段是子表单字段,要判断公式中的子表单字段是否和当前计算字段是否属于同一子表单!! */
372
-
373
-
374
- if (subFormNameOfField === formulaFieldRef?.parentWidget?.options?.name) {
375
- let subFormRowId = formulaFieldRef.tableParam.row._X_ROW_KEY
376
- fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '_' + subFormRowId)
377
- if (!!fieldRef) {
378
- resultFormula = resultFormula.replaceAll(mi, fieldRef.currentValue)
379
- } else {
380
- quitFlag = true
381
- console.error('Field not found: ' + fieldSchema.options.label)
382
- }
383
- } else if (subFormNameOfField === formulaFieldRef.subFormName) {
384
- fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '@row' + formulaFieldRef.subFormRowId)
385
- if (!!fieldRef) {
386
- resultFormula = resultFormula.replaceAll(mi, fieldRef.currentValue)
387
- } else {
388
- quitFlag = true
389
- console.error('Field not found: ' + fieldSchema.options.label)
390
- }
391
- } else {
392
- console.error('Invalid formula!')
393
- }
394
- } else {
395
- /* 在主表单字段的计算公式中使用子表单字段,应将子表单所有记录同字段的值代入!! */
396
- // const subFormValue = VFR.formDataModel[subFormNameOfField]
397
- let dataTableRef = VFR.getWidgetRef(subFormNameOfField)
398
- const subFormValue = VFR.formDataModel[fieldKeyName(dataTableRef.widget)]
399
-
400
- let allSubFieldValues = ''
401
- // const subFieldName = fieldSchema.options.name
402
- const subFieldName = fieldKeyName(fieldSchema)
403
- subFormValue.forEach((vi, idx) => {
404
- allSubFieldValues = (idx === 0) ? vi[subFieldName] : allSubFieldValues + ', ' + vi[subFieldName]
405
- })
406
- resultFormula = resultFormula.replaceAll(mi, allSubFieldValues)
407
- }
408
- }
409
- }
410
- })
411
-
412
- return quitFlag ? null : resultFormula
413
- }
414
-
415
- function fieldKeyName(widget) {
416
- let o = widget.options.name;
417
- return (
418
- (widget.options.keyNameEnabled && widget.options.keyName) || o
419
- );
420
- }
421
-
422
- /**
423
- * 获取字段值
424
- */
425
- function getWidgetValue(VFR, formula, widgetName) {
426
- const sIndex = formula.indexOf("(");
427
- const func = formula.substring(0, sIndex);
428
-
429
- const funcType = formulas.find(item => {
430
- if (item.flist.some(fItem => {
431
- return fItem.fName === func
432
- })) {
433
- return item;
434
- }
435
- });
436
- if (translate(funcType.fClass) === "数学类型") {
437
- return Number(VFR.getWidgetRef(widgetName).getValue());
438
- } else {
439
- return VFR.getWidgetRef(widgetName).getValue() + '';
440
- }
441
- }
442
-
443
- // 查找公式中的函数是否在枚举中
444
- export function hasFun(funName) {
445
- for (let i = 0; i < FORMULA_JS_FUNCTIONS.length; i++) {
446
- if (funName === FORMULA_JS_FUNCTIONS[i]) {
447
- return true
448
- }
449
- }
450
- return false
451
- }
452
-
453
- export function findCalFunStartIndex(formula) {
454
- let startIndex = -1
455
- for (let i = 0; i < FORMULA_JS_FUNCTIONS.length; i++) {
456
- let index = formula.indexOf(FORMULA_JS_FUNCTIONS[i])
457
- if (index !== -1) {
458
- return index
459
- }
460
- }
461
- return startIndex
462
- }
463
-
464
- /**
465
- * 当删除子表单行时,重新计算相关联的计算字段
466
- */
467
- export function recalculateFormulaOnSubFormRowDelete(VFR, DSV, formulaJs, formulaFieldRef) {
468
- if (!!formulaFieldRef.subFormItemFlag) {
469
- return
470
- }
471
-
472
- let formula = formulaFieldRef.field.options.formula
473
- formula = replaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef) //替换字段值
474
- if (!formula) {
475
- return
476
- }
477
-
478
- //替换formula-js函数
479
- const matchResult = formula.match(/[A-Za-z]*/g)
480
- let matchedList = []
481
- if (!!matchResult) {
482
- matchResult.forEach(mi => {
483
- if (!!mi && (findCalFunStartIndex(mi) !== -1) && !matchedList.includes(mi)) {
484
- const funcName = mi.toUpperCase()
485
- formula = formula.replaceAll(mi, 'formulaJs.' + funcName)
486
- matchedList.push(mi)
487
- }
488
- })
489
- }
490
-
491
- console.log('formula: ', formula)
492
- const formulaValue = evalFn(formula, DSV, VFR, formulaJs)
493
- formulaFieldRef.setValue(formulaValue)
494
- }
495
-
496
- export function broadcastFormulaRecalculateEvent(subFormRef) {
497
- let fieldNames = []
498
- let getFieldNamesFn = (fw) => {
499
- fieldNames.push(fw.options.name)
500
- }
501
- traverseFieldWidgetsOfContainer(subFormRef.widget, getFieldNamesFn)
502
- fieldNames.map(fieldName => {
503
- subFormRef.getFormRef().broadcast('FieldWidget', 'calculate-formula-sfRowDeleted', [null, fieldName])
504
- })
505
- }
506
-
507
- //--------------------- 以下为公式计算的API方法 start ------------------//
508
- // 日期格式化
509
- export function dateFormat(date, fmt) {
510
- date = new Date(date)
511
- let a = ['日', '一', '二', '三', '四', '五', '六']
512
- let o = {
513
- 'M+': date.getMonth() + 1, // 月份
514
- 'd+': date.getDate(), // 日
515
- 'h+': date.getHours(), // 小时
516
- 'm+': date.getMinutes(), // 分
517
- 's+': date.getSeconds(), // 秒
518
- 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
519
- 'S': date.getMilliseconds(), // 毫秒
520
- 'w': date.getDay(), // 周
521
- 'W': a[date.getDay()], // 大写周
522
- 'T': 'T'
523
- }
524
- if (/(y+)/.test(fmt)) {
525
- fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
526
- }
527
- for (let k in o) {
528
- if (new RegExp('(' + k + ')').test(fmt)) {
529
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
530
- }
531
- }
532
- return fmt
533
- }
534
-
535
- //月份加减
536
- export function addMonths(yearMonthDay, monthNum) {
537
- let arr = yearMonthDay.split('-'); //2020-08-19或2020-08
538
- let year = parseInt(arr[0]);
539
- let month = parseInt(arr[1]);
540
- month = month + monthNum;
541
- if (month > 12) { //月份加
542
- let yearNum = parseInt((month - 1) / 12);
543
- month = month % 12 === 0 ? 12 : month % 12;
544
- year += yearNum;
545
- } else if (month <= 0) { //月份减
546
- month = Math.abs(month);
547
- let yearNum = parseInt((month + 12) / 12);
548
- year -= yearNum;
549
- }
550
- month = month < 10 ? "0" + month : month;
551
- return year + "-" + month;
552
- }
553
-
554
- // 获取当前日期 yyyy-MM-dd
555
- export function TODAY() {
556
- // return this.FUNAPI.DODAY().toLocaleDateString().replaceAll("/","-")
557
- return dateFormat(new Date(), "yyyy-MM-dd")
558
- }
559
-
560
- // 获取当前时间 yyyy-MM-dd hh:mm:ss
561
- export function NOW() {
562
- // return this.FUNAPI.NOW().toLocaleDateString().replaceAll("/","-")
563
- return dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
564
- }
565
-
566
- /** 加减日期年
567
- * @param {Object} date 日期
568
- * @param {Object} month 加减的年
569
- */
570
- export function EYEAR(date, year) {
571
- try {
572
- let myDate = new Date(date)
573
- let newDate = myDate.setYear(myDate.getFullYear() + year)
574
- return dateFormat(new Date(newDate), "yyyy-MM-dd")
575
- } catch (e) {
576
- //TODO handle the exception
577
- //console.log(this.i18nt('designer.hint.formulaDateError'), date)
578
- //console.error(this.i18nt('designer.hint.formulaDateErrorMsg'), e);
579
- }
580
- }
581
-
582
- /** 加减日期月份
583
- * @param {Object} date 日期
584
- * @param {Object} month 加减的月份
585
- */
586
- export function EMONTH(date, month) {
587
- try {
588
- let myDate = new Date(date)
589
- let newDate = myDate.setMonth(myDate.getMonth() + month)
590
- return dateFormat(new Date(newDate), "yyyy-MM-dd")
591
- } catch (e) {
592
- //TODO handle the exception
593
- // console.log(this.i18nt('designer.hint.formulaDateError'), date)
594
- // console.error(this.i18nt('designer.hint.formulaDateErrorMsg'), e);
595
- }
596
- }
597
-
598
- /** 加减日期天数
599
- * @param {Object} date
600
- * @param {Object} day 加减天数
601
- */
602
- export function EDAY(date, day) {
603
- try {
604
- let myDate = new Date(date)
605
- let newDate = myDate.setDate(myDate.getDate() + day)
606
- return dateFormat(new Date(newDate), "yyyy-MM-dd")
607
- } catch (e) {
608
- //TODO handle the exception
609
- }
610
- }
611
-
612
- const FORMULA_JS_FUNCTIONS = [
613
- "INT",
614
- "SUM",
615
- "AVERAGE",
616
- "MAX",
617
- "MIN",
618
- "ABS",
619
- "ROUND",
620
- "CEILING",
621
- "LOG",
622
- "MOD",
623
- "POWER",
624
- "AND",
625
- "IF",
626
- "IFS",
627
- "IFERROR",
628
- "IFNA",
629
- "NOT",
630
- "OR",
631
- "SWITCH",
632
- "XOR",
633
- "YEAR",
634
- "MONTH",
635
- "DAY",
636
- "TODAY",
637
- "NOW",
638
- "EMONTH",
639
- "EDAY",
640
- "FIND",
641
- "LEFT",
642
- "RIGHT",
643
- "LEN",
644
- "LOWER",
645
- "UPPER",
646
- "MID",
647
- "TRIM",
648
- ];
649
-
650
- export const formulas = [
651
- {
652
- fClass: "designer.hint.formulaFunctionMaths",
653
- flist: [
654
- {
655
- fName: "INT",
656
- fType: "designer.hint.formulaNumber",
657
- fIntro: "designer.hint.formulaINT",
658
- },
659
- {
660
- fName: "SUM",
661
- fType: "designer.hint.formulaNumber",
662
- fIntro: "designer.hint.formulaSUM",
663
- },
664
- {
665
- fName: "SUMIF",
666
- fType: "designer.hint.formulaNumber",
667
- fIntro: "designer.hint.formulaSUMIF",
668
- },
669
- {
670
- fName: "SUMIFS",
671
- fType: "designer.hint.formulaNumber",
672
- fIntro: "designer.hint.formulaSUMIFS",
673
- },
674
- {
675
- fName: "AVERAGE",
676
- fType: "designer.hint.formulaNumber",
677
- fIntro: "designer.hint.formulaAVERAGE",
678
- },
679
- {
680
- fName: "MAX",
681
- fType: "designer.hint.formulaNumber",
682
- fIntro: "designer.hint.formulaMAX",
683
- },
684
- {
685
- fName: "MIN",
686
- fType: "designer.hint.formulaNumber",
687
- fIntro: "designer.hint.formulaMIN",
688
- },
689
- {
690
- fName: "ABS",
691
- fType: "designer.hint.formulaNumber",
692
- fIntro: "designer.hint.formulaABS",
693
- },
694
- {
695
- fName: "ROUND",
696
- fType: "designer.hint.formulaNumber",
697
- fIntro: "designer.hint.formulaROUND",
698
- },
699
- {
700
- fName: "CEILING",
701
- fType: "designer.hint.formulaNumber",
702
- fIntro: "designer.hint.formulaCEILING",
703
- },
704
- {
705
- fName: "LOG",
706
- fType: "designer.hint.formulaNumber",
707
- fIntro: "designer.hint.formulaLOG",
708
- },
709
- {
710
- fName: "MOD",
711
- fType: "designer.hint.formulaNumber",
712
- fIntro: "designer.hint.formulaMOD",
713
- },
714
- {
715
- fName: "POWER",
716
- fType: "designer.hint.formulaNumber",
717
- fIntro: "designer.hint.formulaPOWER",
718
- },
719
- ],
720
- },
721
- {
722
- fClass: "designer.hint.formulaFunctionLogic",
723
- flist: [
724
- {
725
- fName: "AND",
726
- fType: "designer.hint.formulaObject",
727
- fIntro: "designer.hint.formulaAND",
728
- },
729
- {
730
- fName: "IF",
731
- fType: "designer.hint.formulaObject",
732
- fIntro: "designer.hint.formulaIF",
733
- },
734
- {
735
- fName: "IFS",
736
- fType: "designer.hint.formulaObject",
737
- fIntro: "designer.hint.formulaIFS",
738
- },
739
- {
740
- fName: "IFERROR",
741
- fType: "designer.hint.formulaObject",
742
- fIntro: "designer.hint.formulaIFERROR",
743
- },
744
- {
745
- fName: "IFNA",
746
- fType: "designer.hint.formulaObject",
747
- fIntro: "designer.hint.formulaIFNA",
748
- },
749
- {
750
- fName: "NOT",
751
- fType: "designer.hint.formulaObject",
752
- fIntro: "designer.hint.formulaNOT",
753
- },
754
- {
755
- fName: "OR",
756
- fType: "designer.hint.formulaObject",
757
- fIntro: "designer.hint.formulaOR",
758
- },
759
- {
760
- fName: "SWITCH",
761
- fType: "designer.hint.formulaObject",
762
- fIntro: "designer.hint.formulaSWITCH",
763
- },
764
- {
765
- fName: "XOR",
766
- fType: "designer.hint.formulaObject",
767
- fIntro: "designer.hint.formulaXOR",
768
- },
769
- ],
770
- },
771
- {
772
- fClass: "designer.hint.formulaFunctionTime",
773
- flist: [
774
- {
775
- fName: "YEAR",
776
- fType: "designer.hint.formulaDate",
777
- fIntro: "designer.hint.formulaYEAR",
778
- },
779
- {
780
- fName: "MONTH",
781
- fType: "designer.hint.formulaDate",
782
- fIntro: "designer.hint.formulaMONTH",
783
- },
784
- {
785
- fName: "DAY",
786
- fType: "designer.hint.formulaDate",
787
- fIntro: "designer.hint.formulaDAY",
788
- },
789
- {
790
- fName: "TODAY",
791
- fType: "designer.hint.formulaDate",
792
- fIntro: "designer.hint.formulaTODAY",
793
- },
794
- {
795
- fName: "NOW",
796
- fType: "designer.hint.formulaDate",
797
- fIntro: "designer.hint.formulaNOW",
798
- },
799
- {
800
- fName: "EMONTH",
801
- fType: "designer.hint.formulaDate",
802
- fIntro: "designer.hint.formulaEMONTH",
803
- },
804
- {
805
- fName: "EDAY",
806
- fType: "designer.hint.formulaDate",
807
- fIntro: "designer.hint.formulaEDAY",
808
- },
809
- ],
810
- },
811
- {
812
- fClass: "designer.hint.formulaFunctionString",
813
- flist: [
814
- {
815
- fName: "FIND",
816
- fType: "designer.hint.formulaChar",
817
- fIntro: "designer.hint.formulaFIND",
818
- },
819
- {
820
- fName: "LEFT",
821
- fType: "designer.hint.formulaChar",
822
- fIntro: "designer.hint.formulaLEFT",
823
- },
824
- {
825
- fName: "RIGHT",
826
- fType: "designer.hint.formulaChar",
827
- fIntro: "designer.hint.formulaRIGHT",
828
- },
829
- {
830
- fName: "LEN",
831
- fType: "designer.hint.formulaChar",
832
- fIntro: "designer.hint.formulaLEN",
833
- },
834
- {
835
- fName: "LOWER",
836
- fType: "designer.hint.formulaChar",
837
- fIntro: "designer.hint.formulaLOWER",
838
- },
839
- {
840
- fName: "UPPER",
841
- fType: "designer.hint.formulaChar",
842
- fIntro: "designer.hint.formulaUPPER",
843
- },
844
- {
845
- fName: "MID",
846
- fType: "designer.hint.formulaChar",
847
- fIntro: "designer.hint.formulaMID",
848
- },
849
- {
850
- fName: "TRIM",
851
- fType: "designer.hint.formulaChar",
852
- fIntro: "designer.hint.formulaTRIM",
853
- },
854
- ],
855
- },
856
- ];