cloud-web-corejs 1.0.171 → 1.0.173

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.
@@ -0,0 +1,860 @@
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
+
196
+ /* if(funcName === "SUMIF" || funcName === "SUMIFS"){
197
+ debugger
198
+ } */
199
+ return
200
+ }
201
+
202
+ const firstPart = mi.split('.')[0]
203
+ const fieldId = firstPart.substring(2, firstPart.length)
204
+ const fieldSchema = getFieldWidgetById(VFR.formJsonObj.widgetList, fieldId, false)
205
+ if (!!fieldSchema) {
206
+ let fieldRef = VFR.getWidgetRef(fieldSchema.options.name)
207
+ if (!!fieldRef) {
208
+ //是否要考虑字符串值的替换??
209
+ // resultFormula = resultFormula.replace(mi, fieldRef.currentValue)
210
+ let fieldKeyName = getFieldKeyName(fieldSchema)
211
+ let value = fieldRef.formModel[fieldKeyName]??null;
212
+ resultFormula = resultFormula.replace(mi, value)
213
+ } else { //getWidgetRef找不到,则可能是子表单字段
214
+ const subFormNameOfField = VFR.getSubFormNameOfWidget(fieldSchema.options.name)
215
+ if (!!formulaFieldRef.subFormItemFlag || formulaFieldRef.tableParam || row) {
216
+ /* 如果当前计算字段是子表单字段,要判断公式中的子表单字段是否和当前计算字段是否属于同一子表单!! */
217
+ if(row){
218
+ let fieldKeyName = getFieldKeyName(fieldSchema)
219
+ let value = row[fieldKeyName]??null;
220
+ resultFormula = resultFormula.replaceAll(mi, value)
221
+ /*
222
+ let subFormRowId = row._X_ROW_KEY
223
+ fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '_' + subFormRowId)
224
+ if (!!fieldRef) {
225
+ let value = fieldRef.currentValue;
226
+ resultFormula = resultFormula.replaceAll(mi, value)
227
+ } else {
228
+ de
229
+ quitFlag = true
230
+ console.error('Field not found: ' + fieldSchema.options.label)
231
+ } */
232
+ }else if (subFormNameOfField === formulaFieldRef?.parentWidget?.options?.name) {
233
+ let subFormRowId = formulaFieldRef.tableParam.row._X_ROW_KEY
234
+ fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '_' + subFormRowId)
235
+ if (!!fieldRef) {
236
+ let value = fieldRef.currentValue??null;
237
+ resultFormula = resultFormula.replaceAll(mi, value)
238
+ } else {
239
+ quitFlag = true
240
+ console.error('Field not found: ' + fieldSchema.options.label)
241
+ }
242
+ } else if (subFormNameOfField === formulaFieldRef.subFormName) {
243
+ fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '@row' + formulaFieldRef.subFormRowId)
244
+ if (!!fieldRef) {
245
+ resultFormula = resultFormula.replaceAll(mi, fieldRef.currentValue)
246
+ } else {
247
+ quitFlag = true
248
+ console.error('Field not found: ' + fieldSchema.options.label)
249
+ }
250
+ }else {
251
+ console.error('Invalid formula!')
252
+ }
253
+ } else {
254
+ /* 在主表单字段的计算公式中使用子表单字段,应将子表单所有记录同字段的值代入!! */
255
+ // const subFormValue = VFR.formDataModel[subFormNameOfField]
256
+ let dataTableRef = VFR.getWidgetRef(subFormNameOfField)
257
+ const subFormValue = VFR.formDataModel[fieldKeyName(dataTableRef.widget)]
258
+ let allSubFieldValues = ''
259
+ // const subFieldName = fieldSchema.options.name
260
+ const subFieldName = fieldKeyName(fieldSchema)
261
+ subFormValue.forEach((vi, idx) => {
262
+ let val = vi[subFieldName]??null
263
+ allSubFieldValues = (idx === 0) ? val : allSubFieldValues + ', ' + val
264
+ })
265
+ resultFormula = resultFormula.replaceAll(mi, allSubFieldValues)
266
+ }
267
+ }
268
+ }
269
+ })
270
+
271
+ return quitFlag ? null : resultFormula
272
+ }
273
+
274
+ export function calculateFormula2(formulaStr, data, that) {
275
+ if(!formulaStr)return
276
+ let formula = formulaStr;
277
+ let VFR = that.getFormRef();
278
+ let DSV = that.getGlobalDsv()
279
+ let formulaJs = formulajs
280
+
281
+ if(data){
282
+ for(let key in data){
283
+ formula = formula.replaceAll(`[${key}]`,(data[key] || 0))
284
+ }
285
+ }
286
+
287
+ //替换formula-js函数
288
+ const matchResult = formula.match(/[A-Za-z]*/g)
289
+ let matchedList = []
290
+ if (!!matchResult) {
291
+ matchResult.forEach(mi => {
292
+ if (!!mi && (findCalFunStartIndex(mi) !== -1) && !matchedList.includes(mi)) {
293
+ const funcName = mi.toUpperCase()
294
+ formula = formula.replaceAll(mi, 'formulaJs.' + funcName)
295
+ matchedList.push(mi)
296
+ }
297
+ })
298
+ }
299
+
300
+ const formulaValue = evalFn(formula, DSV, VFR, formulaJs)
301
+ return formulaValue
302
+ }
303
+
304
+ /**
305
+ * 判断字段是否用在计算公式中
306
+ * @param fieldName
307
+ * @param formula
308
+ * @param VFR
309
+ */
310
+ export function fieldIsUsedInFormula(fieldName, formula, VFR, fieldTarget) {
311
+ const matchResult = formula.match(FORMULA_REG_EXP)
312
+ if (!matchResult) {
313
+ return false
314
+ }
315
+
316
+ let foundResult = false
317
+ matchResult.forEach(mi => {
318
+ const thirdPart = mi.split('.')[2]
319
+ const nodeType = thirdPart.substring(0, thirdPart.length - 2)
320
+ if (nodeType === 'func') {
321
+ return
322
+ }
323
+
324
+ const firstPart = mi.split('.')[0]
325
+ const fieldId = firstPart.substring(2, firstPart.length)
326
+ let fieldSchema = getFieldWidgetById(VFR.formJsonObj.widgetList, fieldId, false)
327
+ if (!fieldSchema) {
328
+ console.error('The field used by formula not found: ', fieldId)
329
+ console.error('The formula is: ', formula)
330
+ }
331
+ if (fieldSchema && (fieldSchema.options.name === fieldName)) {
332
+ foundResult = true
333
+ }
334
+ })
335
+
336
+ return foundResult
337
+ }
338
+
339
+
340
+ /**
341
+ * 替换计算公式中的字段值
342
+ * @param VFR
343
+ * @param formulaFieldRef
344
+ * @returns {*}
345
+ */
346
+ export function replaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef) {
347
+ let formula = formulaFieldRef.field.options.formula
348
+ const matchResult = formula.match(FORMULA_REG_EXP)
349
+ if (!matchResult) {
350
+ return formula
351
+ }
352
+
353
+ let resultFormula = formula
354
+ let quitFlag = false
355
+ matchResult.forEach(mi => {
356
+ const thirdPart = mi.split('.')[2]
357
+ const nodeType = thirdPart.substring(0, thirdPart.length - 2)
358
+ if (nodeType === 'func') {
359
+ const funcName = mi.split('.')[1]
360
+ resultFormula = resultFormula.replace(mi, funcName)
361
+ return
362
+ }
363
+
364
+ const firstPart = mi.split('.')[0]
365
+ const fieldId = firstPart.substring(2, firstPart.length)
366
+ const fieldSchema = getFieldWidgetById(VFR.formJsonObj.widgetList, fieldId, false)
367
+ if (!!fieldSchema) {
368
+ let fieldRef = VFR.getWidgetRef(fieldSchema.options.name)
369
+ if (!!fieldRef) {
370
+ //是否要考虑字符串值的替换??
371
+ resultFormula = resultFormula.replace(mi, fieldRef.currentValue)
372
+ } else { //getWidgetRef找不到,则可能是子表单字段
373
+ const subFormNameOfField = VFR.getSubFormNameOfWidget(fieldSchema.options.name)
374
+ if (!!formulaFieldRef.subFormItemFlag || formulaFieldRef.tableParam) {
375
+ /* 如果当前计算字段是子表单字段,要判断公式中的子表单字段是否和当前计算字段是否属于同一子表单!! */
376
+
377
+
378
+ if (subFormNameOfField === formulaFieldRef?.parentWidget?.options?.name) {
379
+ let subFormRowId = formulaFieldRef.tableParam.row._X_ROW_KEY
380
+ fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '_' + subFormRowId)
381
+ if (!!fieldRef) {
382
+ resultFormula = resultFormula.replaceAll(mi, fieldRef.currentValue)
383
+ } else {
384
+ quitFlag = true
385
+ console.error('Field not found: ' + fieldSchema.options.label)
386
+ }
387
+ } else if (subFormNameOfField === formulaFieldRef.subFormName) {
388
+ fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '@row' + formulaFieldRef.subFormRowId)
389
+ if (!!fieldRef) {
390
+ resultFormula = resultFormula.replaceAll(mi, fieldRef.currentValue)
391
+ } else {
392
+ quitFlag = true
393
+ console.error('Field not found: ' + fieldSchema.options.label)
394
+ }
395
+ } else {
396
+ console.error('Invalid formula!')
397
+ }
398
+ } else {
399
+ /* 在主表单字段的计算公式中使用子表单字段,应将子表单所有记录同字段的值代入!! */
400
+ // const subFormValue = VFR.formDataModel[subFormNameOfField]
401
+ let dataTableRef = VFR.getWidgetRef(subFormNameOfField)
402
+ const subFormValue = VFR.formDataModel[fieldKeyName(dataTableRef.widget)]
403
+
404
+ let allSubFieldValues = ''
405
+ // const subFieldName = fieldSchema.options.name
406
+ const subFieldName = fieldKeyName(fieldSchema)
407
+ subFormValue.forEach((vi, idx) => {
408
+ allSubFieldValues = (idx === 0) ? vi[subFieldName] : allSubFieldValues + ', ' + vi[subFieldName]
409
+ })
410
+ resultFormula = resultFormula.replaceAll(mi, allSubFieldValues)
411
+ }
412
+ }
413
+ }
414
+ })
415
+
416
+ return quitFlag ? null : resultFormula
417
+ }
418
+
419
+ function fieldKeyName(widget) {
420
+ let o = widget.options.name;
421
+ return (
422
+ (widget.options.keyNameEnabled && widget.options.keyName) || o
423
+ );
424
+ }
425
+
426
+ /**
427
+ * 获取字段值
428
+ */
429
+ function getWidgetValue(VFR, formula, widgetName) {
430
+ const sIndex = formula.indexOf("(");
431
+ const func = formula.substring(0, sIndex);
432
+
433
+ const funcType = formulas.find(item => {
434
+ if (item.flist.some(fItem => {
435
+ return fItem.fName === func
436
+ })) {
437
+ return item;
438
+ }
439
+ });
440
+ if (translate(funcType.fClass) === "数学类型") {
441
+ return Number(VFR.getWidgetRef(widgetName).getValue());
442
+ } else {
443
+ return VFR.getWidgetRef(widgetName).getValue() + '';
444
+ }
445
+ }
446
+
447
+ // 查找公式中的函数是否在枚举中
448
+ export function hasFun(funName) {
449
+ for (let i = 0; i < FORMULA_JS_FUNCTIONS.length; i++) {
450
+ if (funName === FORMULA_JS_FUNCTIONS[i]) {
451
+ return true
452
+ }
453
+ }
454
+ return false
455
+ }
456
+
457
+ export function findCalFunStartIndex(formula) {
458
+ let startIndex = -1
459
+ for (let i = 0; i < FORMULA_JS_FUNCTIONS.length; i++) {
460
+ let index = formula.indexOf(FORMULA_JS_FUNCTIONS[i])
461
+ if (index !== -1) {
462
+ return index
463
+ }
464
+ }
465
+ return startIndex
466
+ }
467
+
468
+ /**
469
+ * 当删除子表单行时,重新计算相关联的计算字段
470
+ */
471
+ export function recalculateFormulaOnSubFormRowDelete(VFR, DSV, formulaJs, formulaFieldRef) {
472
+ if (!!formulaFieldRef.subFormItemFlag) {
473
+ return
474
+ }
475
+
476
+ let formula = formulaFieldRef.field.options.formula
477
+ formula = replaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef) //替换字段值
478
+ if (!formula) {
479
+ return
480
+ }
481
+
482
+ //替换formula-js函数
483
+ const matchResult = formula.match(/[A-Za-z]*/g)
484
+ let matchedList = []
485
+ if (!!matchResult) {
486
+ matchResult.forEach(mi => {
487
+ if (!!mi && (findCalFunStartIndex(mi) !== -1) && !matchedList.includes(mi)) {
488
+ const funcName = mi.toUpperCase()
489
+ formula = formula.replaceAll(mi, 'formulaJs.' + funcName)
490
+ matchedList.push(mi)
491
+ }
492
+ })
493
+ }
494
+
495
+ console.log('formula: ', formula)
496
+ const formulaValue = evalFn(formula, DSV, VFR, formulaJs)
497
+ formulaFieldRef.setValue(formulaValue)
498
+ }
499
+
500
+ export function broadcastFormulaRecalculateEvent(subFormRef) {
501
+ let fieldNames = []
502
+ let getFieldNamesFn = (fw) => {
503
+ fieldNames.push(fw.options.name)
504
+ }
505
+ traverseFieldWidgetsOfContainer(subFormRef.widget, getFieldNamesFn)
506
+ fieldNames.map(fieldName => {
507
+ subFormRef.getFormRef().broadcast('FieldWidget', 'calculate-formula-sfRowDeleted', [null, fieldName])
508
+ })
509
+ }
510
+
511
+ //--------------------- 以下为公式计算的API方法 start ------------------//
512
+ // 日期格式化
513
+ export function dateFormat(date, fmt) {
514
+ date = new Date(date)
515
+ let a = ['日', '一', '二', '三', '四', '五', '六']
516
+ let o = {
517
+ 'M+': date.getMonth() + 1, // 月份
518
+ 'd+': date.getDate(), // 日
519
+ 'h+': date.getHours(), // 小时
520
+ 'm+': date.getMinutes(), // 分
521
+ 's+': date.getSeconds(), // 秒
522
+ 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
523
+ 'S': date.getMilliseconds(), // 毫秒
524
+ 'w': date.getDay(), // 周
525
+ 'W': a[date.getDay()], // 大写周
526
+ 'T': 'T'
527
+ }
528
+ if (/(y+)/.test(fmt)) {
529
+ fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
530
+ }
531
+ for (let k in o) {
532
+ if (new RegExp('(' + k + ')').test(fmt)) {
533
+ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
534
+ }
535
+ }
536
+ return fmt
537
+ }
538
+
539
+ //月份加减
540
+ export function addMonths(yearMonthDay, monthNum) {
541
+ let arr = yearMonthDay.split('-'); //2020-08-19或2020-08
542
+ let year = parseInt(arr[0]);
543
+ let month = parseInt(arr[1]);
544
+ month = month + monthNum;
545
+ if (month > 12) { //月份加
546
+ let yearNum = parseInt((month - 1) / 12);
547
+ month = month % 12 === 0 ? 12 : month % 12;
548
+ year += yearNum;
549
+ } else if (month <= 0) { //月份减
550
+ month = Math.abs(month);
551
+ let yearNum = parseInt((month + 12) / 12);
552
+ year -= yearNum;
553
+ }
554
+ month = month < 10 ? "0" + month : month;
555
+ return year + "-" + month;
556
+ }
557
+
558
+ // 获取当前日期 yyyy-MM-dd
559
+ export function TODAY() {
560
+ // return this.FUNAPI.DODAY().toLocaleDateString().replaceAll("/","-")
561
+ return dateFormat(new Date(), "yyyy-MM-dd")
562
+ }
563
+
564
+ // 获取当前时间 yyyy-MM-dd hh:mm:ss
565
+ export function NOW() {
566
+ // return this.FUNAPI.NOW().toLocaleDateString().replaceAll("/","-")
567
+ return dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
568
+ }
569
+
570
+ /** 加减日期年
571
+ * @param {Object} date 日期
572
+ * @param {Object} month 加减的年
573
+ */
574
+ export function EYEAR(date, year) {
575
+ try {
576
+ let myDate = new Date(date)
577
+ let newDate = myDate.setYear(myDate.getFullYear() + year)
578
+ return dateFormat(new Date(newDate), "yyyy-MM-dd")
579
+ } catch (e) {
580
+ //TODO handle the exception
581
+ //console.log(this.i18nt('designer.hint.formulaDateError'), date)
582
+ //console.error(this.i18nt('designer.hint.formulaDateErrorMsg'), e);
583
+ }
584
+ }
585
+
586
+ /** 加减日期月份
587
+ * @param {Object} date 日期
588
+ * @param {Object} month 加减的月份
589
+ */
590
+ export function EMONTH(date, month) {
591
+ try {
592
+ let myDate = new Date(date)
593
+ let newDate = myDate.setMonth(myDate.getMonth() + month)
594
+ return dateFormat(new Date(newDate), "yyyy-MM-dd")
595
+ } catch (e) {
596
+ //TODO handle the exception
597
+ // console.log(this.i18nt('designer.hint.formulaDateError'), date)
598
+ // console.error(this.i18nt('designer.hint.formulaDateErrorMsg'), e);
599
+ }
600
+ }
601
+
602
+ /** 加减日期天数
603
+ * @param {Object} date
604
+ * @param {Object} day 加减天数
605
+ */
606
+ export function EDAY(date, day) {
607
+ try {
608
+ let myDate = new Date(date)
609
+ let newDate = myDate.setDate(myDate.getDate() + day)
610
+ return dateFormat(new Date(newDate), "yyyy-MM-dd")
611
+ } catch (e) {
612
+ //TODO handle the exception
613
+ }
614
+ }
615
+
616
+ const FORMULA_JS_FUNCTIONS = [
617
+ "INT",
618
+ "SUM",
619
+ "AVERAGE",
620
+ "MAX",
621
+ "MIN",
622
+ "ABS",
623
+ "ROUND",
624
+ "CEILING",
625
+ "LOG",
626
+ "MOD",
627
+ "POWER",
628
+ "AND",
629
+ "IF",
630
+ "IFS",
631
+ "IFERROR",
632
+ "IFNA",
633
+ "NOT",
634
+ "OR",
635
+ "SWITCH",
636
+ "XOR",
637
+ "YEAR",
638
+ "MONTH",
639
+ "DAY",
640
+ "TODAY",
641
+ "NOW",
642
+ "EMONTH",
643
+ "EDAY",
644
+ "FIND",
645
+ "LEFT",
646
+ "RIGHT",
647
+ "LEN",
648
+ "LOWER",
649
+ "UPPER",
650
+ "MID",
651
+ "TRIM",
652
+ ];
653
+
654
+ export const formulas = [
655
+ {
656
+ fClass: "designer.hint.formulaFunctionMaths",
657
+ flist: [
658
+ {
659
+ fName: "INT",
660
+ fType: "designer.hint.formulaNumber",
661
+ fIntro: "designer.hint.formulaINT",
662
+ },
663
+ {
664
+ fName: "SUM",
665
+ fType: "designer.hint.formulaNumber",
666
+ fIntro: "designer.hint.formulaSUM",
667
+ },
668
+ {
669
+ fName: "SUMIF",
670
+ fType: "designer.hint.formulaNumber",
671
+ fIntro: "designer.hint.formulaSUMIF",
672
+ },
673
+ {
674
+ fName: "SUMIFS",
675
+ fType: "designer.hint.formulaNumber",
676
+ fIntro: "designer.hint.formulaSUMIFS",
677
+ },
678
+ {
679
+ fName: "AVERAGE",
680
+ fType: "designer.hint.formulaNumber",
681
+ fIntro: "designer.hint.formulaAVERAGE",
682
+ },
683
+ {
684
+ fName: "MAX",
685
+ fType: "designer.hint.formulaNumber",
686
+ fIntro: "designer.hint.formulaMAX",
687
+ },
688
+ {
689
+ fName: "MIN",
690
+ fType: "designer.hint.formulaNumber",
691
+ fIntro: "designer.hint.formulaMIN",
692
+ },
693
+ {
694
+ fName: "ABS",
695
+ fType: "designer.hint.formulaNumber",
696
+ fIntro: "designer.hint.formulaABS",
697
+ },
698
+ {
699
+ fName: "ROUND",
700
+ fType: "designer.hint.formulaNumber",
701
+ fIntro: "designer.hint.formulaROUND",
702
+ },
703
+ {
704
+ fName: "CEILING",
705
+ fType: "designer.hint.formulaNumber",
706
+ fIntro: "designer.hint.formulaCEILING",
707
+ },
708
+ {
709
+ fName: "LOG",
710
+ fType: "designer.hint.formulaNumber",
711
+ fIntro: "designer.hint.formulaLOG",
712
+ },
713
+ {
714
+ fName: "MOD",
715
+ fType: "designer.hint.formulaNumber",
716
+ fIntro: "designer.hint.formulaMOD",
717
+ },
718
+ {
719
+ fName: "POWER",
720
+ fType: "designer.hint.formulaNumber",
721
+ fIntro: "designer.hint.formulaPOWER",
722
+ },
723
+ ],
724
+ },
725
+ {
726
+ fClass: "designer.hint.formulaFunctionLogic",
727
+ flist: [
728
+ {
729
+ fName: "AND",
730
+ fType: "designer.hint.formulaObject",
731
+ fIntro: "designer.hint.formulaAND",
732
+ },
733
+ {
734
+ fName: "IF",
735
+ fType: "designer.hint.formulaObject",
736
+ fIntro: "designer.hint.formulaIF",
737
+ },
738
+ {
739
+ fName: "IFS",
740
+ fType: "designer.hint.formulaObject",
741
+ fIntro: "designer.hint.formulaIFS",
742
+ },
743
+ {
744
+ fName: "IFERROR",
745
+ fType: "designer.hint.formulaObject",
746
+ fIntro: "designer.hint.formulaIFERROR",
747
+ },
748
+ {
749
+ fName: "IFNA",
750
+ fType: "designer.hint.formulaObject",
751
+ fIntro: "designer.hint.formulaIFNA",
752
+ },
753
+ {
754
+ fName: "NOT",
755
+ fType: "designer.hint.formulaObject",
756
+ fIntro: "designer.hint.formulaNOT",
757
+ },
758
+ {
759
+ fName: "OR",
760
+ fType: "designer.hint.formulaObject",
761
+ fIntro: "designer.hint.formulaOR",
762
+ },
763
+ {
764
+ fName: "SWITCH",
765
+ fType: "designer.hint.formulaObject",
766
+ fIntro: "designer.hint.formulaSWITCH",
767
+ },
768
+ {
769
+ fName: "XOR",
770
+ fType: "designer.hint.formulaObject",
771
+ fIntro: "designer.hint.formulaXOR",
772
+ },
773
+ ],
774
+ },
775
+ {
776
+ fClass: "designer.hint.formulaFunctionTime",
777
+ flist: [
778
+ {
779
+ fName: "YEAR",
780
+ fType: "designer.hint.formulaDate",
781
+ fIntro: "designer.hint.formulaYEAR",
782
+ },
783
+ {
784
+ fName: "MONTH",
785
+ fType: "designer.hint.formulaDate",
786
+ fIntro: "designer.hint.formulaMONTH",
787
+ },
788
+ {
789
+ fName: "DAY",
790
+ fType: "designer.hint.formulaDate",
791
+ fIntro: "designer.hint.formulaDAY",
792
+ },
793
+ {
794
+ fName: "TODAY",
795
+ fType: "designer.hint.formulaDate",
796
+ fIntro: "designer.hint.formulaTODAY",
797
+ },
798
+ {
799
+ fName: "NOW",
800
+ fType: "designer.hint.formulaDate",
801
+ fIntro: "designer.hint.formulaNOW",
802
+ },
803
+ {
804
+ fName: "EMONTH",
805
+ fType: "designer.hint.formulaDate",
806
+ fIntro: "designer.hint.formulaEMONTH",
807
+ },
808
+ {
809
+ fName: "EDAY",
810
+ fType: "designer.hint.formulaDate",
811
+ fIntro: "designer.hint.formulaEDAY",
812
+ },
813
+ ],
814
+ },
815
+ {
816
+ fClass: "designer.hint.formulaFunctionString",
817
+ flist: [
818
+ {
819
+ fName: "FIND",
820
+ fType: "designer.hint.formulaChar",
821
+ fIntro: "designer.hint.formulaFIND",
822
+ },
823
+ {
824
+ fName: "LEFT",
825
+ fType: "designer.hint.formulaChar",
826
+ fIntro: "designer.hint.formulaLEFT",
827
+ },
828
+ {
829
+ fName: "RIGHT",
830
+ fType: "designer.hint.formulaChar",
831
+ fIntro: "designer.hint.formulaRIGHT",
832
+ },
833
+ {
834
+ fName: "LEN",
835
+ fType: "designer.hint.formulaChar",
836
+ fIntro: "designer.hint.formulaLEN",
837
+ },
838
+ {
839
+ fName: "LOWER",
840
+ fType: "designer.hint.formulaChar",
841
+ fIntro: "designer.hint.formulaLOWER",
842
+ },
843
+ {
844
+ fName: "UPPER",
845
+ fType: "designer.hint.formulaChar",
846
+ fIntro: "designer.hint.formulaUPPER",
847
+ },
848
+ {
849
+ fName: "MID",
850
+ fType: "designer.hint.formulaChar",
851
+ fIntro: "designer.hint.formulaMID",
852
+ },
853
+ {
854
+ fName: "TRIM",
855
+ fType: "designer.hint.formulaChar",
856
+ fIntro: "designer.hint.formulaTRIM",
857
+ },
858
+ ],
859
+ },
860
+ ];