cloud-web-corejs 1.0.93 → 1.0.95
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/package.json +39 -30
- package/src/components/wf/content.vue +2 -0
- package/src/components/wf/setCandidateDialog.vue +1 -0
- package/src/components/wf/wf.js +3 -1
- package/src/components/xform/form-designer/designer.js +1 -1
- package/src/components/xform/form-designer/form-widget/container-widget/data-table-mixin.js +2 -1
- package/src/components/xform/form-designer/form-widget/dialog/searchFormDialog.vue +3 -0
- package/src/components/xform/form-designer/form-widget/field-widget/checkbox-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/dropdown-item-widget.vue +77 -0
- package/src/components/xform/form-designer/form-widget/field-widget/dropdown-menu-widget.vue +106 -0
- package/src/components/xform/form-designer/form-widget/field-widget/fieldMixin.js +7 -2
- package/src/components/xform/form-designer/form-widget/field-widget/mixins/vabsearch-mixin.js +176 -0
- package/src/components/xform/form-designer/form-widget/field-widget/multiSearch-widget.vue +53 -0
- package/src/components/xform/form-designer/form-widget/field-widget/number-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/project-tag-widget.vue +5 -2
- package/src/components/xform/form-designer/form-widget/field-widget/radio-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/search_button-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/select-widget.vue +2 -1
- package/src/components/xform/form-designer/form-widget/field-widget/singerSearch-widget.vue +53 -0
- package/src/components/xform/form-designer/form-widget/field-widget/status-widget.vue +3 -2
- package/src/components/xform/form-designer/form-widget/field-widget/vabSearch-widget.vue +2 -170
- package/src/components/xform/form-designer/indexMixin.js +1 -1
- package/src/components/xform/form-designer/setting-panel/form-setting.vue +263 -38
- package/src/components/xform/form-designer/setting-panel/index.vue +4 -0
- package/src/components/xform/form-designer/setting-panel/indexMixin.js +1 -1
- package/src/components/xform/form-designer/setting-panel/option-items-setting.vue +8 -3
- package/src/components/xform/form-designer/setting-panel/property-editor/a-link-editor.vue +1 -1
- package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/columnRenderDialog.vue +3 -2
- package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/data-table-editor.vue +0 -8
- package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/table-column-dialog.vue +111 -12
- package/src/components/xform/form-designer/setting-panel/property-editor/container-list-h5/list-h5-editor.vue +0 -8
- package/src/components/xform/form-designer/setting-panel/property-editor/field-button/search-dialog-event-editor.vue +26 -8
- package/src/components/xform/form-designer/setting-panel/property-editor/field-dropdown-menu/dropdown-item-editor.vue +21 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/field-dropdown-menu/dropdown-menu-editor.vue +59 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/field-import-button/import-button-editor.vue +7 -2
- package/src/components/xform/form-designer/setting-panel/property-editor/field-import-button/import2-button-editor.vue +8 -2
- package/src/components/xform/form-designer/setting-panel/property-editor/field-status/field-status-editor.vue +47 -28
- package/src/components/xform/form-designer/setting-panel/property-editor/field-vabSearch/vabSearchName-editor.vue +13 -1
- package/src/components/xform/form-designer/setting-panel/property-editor/formula-editor.vue +722 -467
- package/src/components/xform/form-designer/setting-panel/property-editor/formulaEnabled-editor.vue +1 -1
- package/src/components/xform/form-designer/setting-panel/property-editor/multiple-editor.vue +19 -14
- package/src/components/xform/form-designer/setting-panel/property-editor/project-tag-editor.vue +159 -18
- package/src/components/xform/form-designer/setting-panel/property-editor/textFlag-editor.vue +51 -2
- package/src/components/xform/form-designer/setting-panel/property-editor/wfFlag-editor.vue +2 -30
- package/src/components/xform/form-designer/setting-panel/property-editor/widgetShowRuleFlag-editor.vue +220 -0
- package/src/components/xform/form-designer/setting-panel/propertyRegister.js +5 -0
- package/src/components/xform/form-designer/toolbar-panel/index.vue +8 -4
- package/src/components/xform/form-designer/widget-panel/index.vue +21 -1
- package/src/components/xform/form-designer/widget-panel/indexMixin.js +3 -2
- package/src/components/xform/form-designer/widget-panel/widgetsConfig.js +489 -132
- package/src/components/xform/form-render/container-item/data-table-item.vue +7 -4
- package/src/components/xform/form-render/container-item/data-table-mixin.js +4 -1
- package/src/components/xform/form-render/container-item/data-table-mixin2.js +2169 -0
- package/src/components/xform/form-render/container-item/list-h5-item.vue +1 -9
- package/src/components/xform/form-render/container-item/list-h5-item2.vue +1 -8
- package/src/components/xform/form-render/indexMixin.js +7 -3
- package/src/components/xform/lang/zh-CN.js +13 -3
- package/src/components/xform/mixins/defaultHandle.js +1 -1
- package/src/components/xform/mixins/scriptHttp.js +1 -1
- package/src/components/xform/utils/format.js +21 -30
- package/src/components/xform/utils/formula-util.js +669 -0
- package/src/components/xform/utils/util.js +1 -1
- package/src/mixins/selectDialog/index.js +1 -1
- package/src/store/modules/permission.js +1 -1
- package/src/store/modules/settings.js +1 -1
@@ -0,0 +1,669 @@
|
|
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
|
+
formulaFieldRef.setValue(formulaValue)
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* 判断字段是否用在计算公式中
|
129
|
+
* @param fieldName
|
130
|
+
* @param formula
|
131
|
+
* @param VFR
|
132
|
+
*/
|
133
|
+
export function fieldIsUsedInFormula(fieldName, formula, VFR, fieldTarget) {
|
134
|
+
const matchResult = formula.match(FORMULA_REG_EXP)
|
135
|
+
if (!matchResult) {
|
136
|
+
return false
|
137
|
+
}
|
138
|
+
|
139
|
+
let foundResult = false
|
140
|
+
matchResult.forEach(mi => {
|
141
|
+
const thirdPart = mi.split('.')[2]
|
142
|
+
const nodeType = thirdPart.substring(0, thirdPart.length - 2)
|
143
|
+
if (nodeType === 'func') {
|
144
|
+
return
|
145
|
+
}
|
146
|
+
|
147
|
+
const firstPart = mi.split('.')[0]
|
148
|
+
const fieldId = firstPart.substring(2, firstPart.length)
|
149
|
+
let fieldSchema = getFieldWidgetById(VFR.formJsonObj.widgetList, fieldId, false)
|
150
|
+
if (!fieldSchema) {
|
151
|
+
console.error('The field used by formula not found: ', fieldId)
|
152
|
+
console.error('The formula is: ', formula)
|
153
|
+
}
|
154
|
+
if (fieldSchema && (fieldSchema.options.name === fieldName)) {
|
155
|
+
foundResult = true
|
156
|
+
}
|
157
|
+
})
|
158
|
+
|
159
|
+
return foundResult
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* 替换计算公式中的字段值
|
164
|
+
* @param VFR
|
165
|
+
* @param formulaFieldRef
|
166
|
+
* @returns {*}
|
167
|
+
*/
|
168
|
+
export function replaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef) {
|
169
|
+
let formula = formulaFieldRef.field.options.formula
|
170
|
+
const matchResult = formula.match(FORMULA_REG_EXP)
|
171
|
+
if (!matchResult) {
|
172
|
+
return formula
|
173
|
+
}
|
174
|
+
|
175
|
+
let resultFormula = formula
|
176
|
+
let quitFlag = false
|
177
|
+
matchResult.forEach(mi => {
|
178
|
+
const thirdPart = mi.split('.')[2]
|
179
|
+
const nodeType = thirdPart.substring(0, thirdPart.length - 2)
|
180
|
+
if (nodeType === 'func') {
|
181
|
+
const funcName = mi.split('.')[1]
|
182
|
+
resultFormula = resultFormula.replace(mi, funcName)
|
183
|
+
return
|
184
|
+
}
|
185
|
+
|
186
|
+
const firstPart = mi.split('.')[0]
|
187
|
+
const fieldId = firstPart.substring(2, firstPart.length)
|
188
|
+
const fieldSchema = getFieldWidgetById(VFR.formJsonObj.widgetList, fieldId, false)
|
189
|
+
if (!!fieldSchema) {
|
190
|
+
let fieldRef = VFR.getWidgetRef(fieldSchema.options.name)
|
191
|
+
if (!!fieldRef) {
|
192
|
+
//是否要考虑字符串值的替换??
|
193
|
+
resultFormula = resultFormula.replace(mi, fieldRef.getValue())
|
194
|
+
} else { //getWidgetRef找不到,则可能是子表单字段
|
195
|
+
const subFormNameOfField = VFR.getSubFormNameOfWidget(fieldSchema.options.name)
|
196
|
+
if (!!formulaFieldRef.subFormItemFlag || formulaFieldRef.tableParam) {
|
197
|
+
/* 如果当前计算字段是子表单字段,要判断公式中的子表单字段是否和当前计算字段是否属于同一子表单!! */
|
198
|
+
|
199
|
+
|
200
|
+
if (subFormNameOfField === formulaFieldRef?.parentWidget?.options?.name) {
|
201
|
+
let subFormRowId = formulaFieldRef.tableParam.row._X_ROW_KEY
|
202
|
+
fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '_' + subFormRowId)
|
203
|
+
if (!!fieldRef) {
|
204
|
+
resultFormula = resultFormula.replaceAll(mi, fieldRef.getValue())
|
205
|
+
} else {
|
206
|
+
quitFlag = true
|
207
|
+
console.error('Field not found: ' + fieldSchema.options.label)
|
208
|
+
}
|
209
|
+
} else if (subFormNameOfField === formulaFieldRef.subFormName) {
|
210
|
+
fieldRef = VFR.getWidgetRef(fieldSchema.options.name + '@row' + formulaFieldRef.subFormRowId)
|
211
|
+
if (!!fieldRef) {
|
212
|
+
resultFormula = resultFormula.replaceAll(mi, fieldRef.getValue())
|
213
|
+
} else {
|
214
|
+
quitFlag = true
|
215
|
+
console.error('Field not found: ' + fieldSchema.options.label)
|
216
|
+
}
|
217
|
+
} else {
|
218
|
+
console.error('Invalid formula!')
|
219
|
+
}
|
220
|
+
} else {
|
221
|
+
/* 在主表单字段的计算公式中使用子表单字段,应将子表单所有记录同字段的值代入!! */
|
222
|
+
const subFormValue = VFR.formDataModel[subFormNameOfField]
|
223
|
+
let allSubFieldValues = ''
|
224
|
+
// const subFieldName = fieldSchema.options.name
|
225
|
+
const subFieldName = fieldKeyName(fieldSchema)
|
226
|
+
subFormValue.forEach((vi, idx) => {
|
227
|
+
allSubFieldValues = (idx === 0) ? vi[subFieldName] : allSubFieldValues + ', ' + vi[subFieldName]
|
228
|
+
})
|
229
|
+
resultFormula = resultFormula.replaceAll(mi, allSubFieldValues)
|
230
|
+
}
|
231
|
+
}
|
232
|
+
}
|
233
|
+
})
|
234
|
+
|
235
|
+
return quitFlag ? null : resultFormula
|
236
|
+
}
|
237
|
+
|
238
|
+
function fieldKeyName(widget) {
|
239
|
+
let o = widget.options.name;
|
240
|
+
return (
|
241
|
+
(widget.options.keyNameEnabled && widget.options.keyName) || o
|
242
|
+
);
|
243
|
+
}
|
244
|
+
|
245
|
+
/**
|
246
|
+
* 获取字段值
|
247
|
+
*/
|
248
|
+
function getWidgetValue(VFR, formula, widgetName) {
|
249
|
+
const sIndex = formula.indexOf("(");
|
250
|
+
const func = formula.substring(0, sIndex);
|
251
|
+
|
252
|
+
const funcType = formulas.find(item => {
|
253
|
+
if (item.flist.some(fItem => {
|
254
|
+
return fItem.fName === func
|
255
|
+
})) {
|
256
|
+
return item;
|
257
|
+
}
|
258
|
+
});
|
259
|
+
if (translate(funcType.fClass) === "数学类型") {
|
260
|
+
return Number(VFR.getWidgetRef(widgetName).getValue());
|
261
|
+
} else {
|
262
|
+
return VFR.getWidgetRef(widgetName).getValue() + '';
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
// 查找公式中的函数是否在枚举中
|
267
|
+
export function hasFun(funName) {
|
268
|
+
for (let i = 0; i < FORMULA_JS_FUNCTIONS.length; i++) {
|
269
|
+
if (funName === FORMULA_JS_FUNCTIONS[i]) {
|
270
|
+
return true
|
271
|
+
}
|
272
|
+
}
|
273
|
+
return false
|
274
|
+
}
|
275
|
+
|
276
|
+
export function findCalFunStartIndex(formula) {
|
277
|
+
let startIndex = -1
|
278
|
+
for (let i = 0; i < FORMULA_JS_FUNCTIONS.length; i++) {
|
279
|
+
let index = formula.indexOf(FORMULA_JS_FUNCTIONS[i])
|
280
|
+
if (index !== -1) {
|
281
|
+
return index
|
282
|
+
}
|
283
|
+
}
|
284
|
+
return startIndex
|
285
|
+
}
|
286
|
+
|
287
|
+
/**
|
288
|
+
* 当删除子表单行时,重新计算相关联的计算字段
|
289
|
+
*/
|
290
|
+
export function recalculateFormulaOnSubFormRowDelete(VFR, DSV, formulaJs, formulaFieldRef) {
|
291
|
+
if (!!formulaFieldRef.subFormItemFlag) {
|
292
|
+
return
|
293
|
+
}
|
294
|
+
|
295
|
+
let formula = formulaFieldRef.field.options.formula
|
296
|
+
formula = replaceFieldsAndFunctionsOfFormula(VFR, formulaFieldRef) //替换字段值
|
297
|
+
if (!formula) {
|
298
|
+
return
|
299
|
+
}
|
300
|
+
|
301
|
+
//替换formula-js函数
|
302
|
+
const matchResult = formula.match(/[A-Za-z]*/g)
|
303
|
+
let matchedList = []
|
304
|
+
if (!!matchResult) {
|
305
|
+
matchResult.forEach(mi => {
|
306
|
+
if (!!mi && (findCalFunStartIndex(mi) !== -1) && !matchedList.includes(mi)) {
|
307
|
+
const funcName = mi.toUpperCase()
|
308
|
+
formula = formula.replaceAll(mi, 'formulaJs.' + funcName)
|
309
|
+
matchedList.push(mi)
|
310
|
+
}
|
311
|
+
})
|
312
|
+
}
|
313
|
+
|
314
|
+
console.log('formula: ', formula)
|
315
|
+
const formulaValue = evalFn(formula, DSV, VFR, formulaJs)
|
316
|
+
formulaFieldRef.setValue(formulaValue)
|
317
|
+
}
|
318
|
+
|
319
|
+
export function broadcastFormulaRecalculateEvent(subFormRef) {
|
320
|
+
let fieldNames = []
|
321
|
+
let getFieldNamesFn = (fw) => {
|
322
|
+
fieldNames.push(fw.options.name)
|
323
|
+
}
|
324
|
+
traverseFieldWidgetsOfContainer(subFormRef.widget, getFieldNamesFn)
|
325
|
+
fieldNames.map(fieldName => {
|
326
|
+
subFormRef.getFormRef().broadcast('FieldWidget', 'calculate-formula-sfRowDeleted', [null, fieldName])
|
327
|
+
})
|
328
|
+
}
|
329
|
+
|
330
|
+
//--------------------- 以下为公式计算的API方法 start ------------------//
|
331
|
+
// 日期格式化
|
332
|
+
export function dateFormat(date, fmt) {
|
333
|
+
date = new Date(date)
|
334
|
+
let a = ['日', '一', '二', '三', '四', '五', '六']
|
335
|
+
let o = {
|
336
|
+
'M+': date.getMonth() + 1, // 月份
|
337
|
+
'd+': date.getDate(), // 日
|
338
|
+
'h+': date.getHours(), // 小时
|
339
|
+
'm+': date.getMinutes(), // 分
|
340
|
+
's+': date.getSeconds(), // 秒
|
341
|
+
'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
|
342
|
+
'S': date.getMilliseconds(), // 毫秒
|
343
|
+
'w': date.getDay(), // 周
|
344
|
+
'W': a[date.getDay()], // 大写周
|
345
|
+
'T': 'T'
|
346
|
+
}
|
347
|
+
if (/(y+)/.test(fmt)) {
|
348
|
+
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
|
349
|
+
}
|
350
|
+
for (let k in o) {
|
351
|
+
if (new RegExp('(' + k + ')').test(fmt)) {
|
352
|
+
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
|
353
|
+
}
|
354
|
+
}
|
355
|
+
return fmt
|
356
|
+
}
|
357
|
+
|
358
|
+
//月份加减
|
359
|
+
export function addMonths(yearMonthDay, monthNum) {
|
360
|
+
let arr = yearMonthDay.split('-'); //2020-08-19或2020-08
|
361
|
+
let year = parseInt(arr[0]);
|
362
|
+
let month = parseInt(arr[1]);
|
363
|
+
month = month + monthNum;
|
364
|
+
if (month > 12) { //月份加
|
365
|
+
let yearNum = parseInt((month - 1) / 12);
|
366
|
+
month = month % 12 === 0 ? 12 : month % 12;
|
367
|
+
year += yearNum;
|
368
|
+
} else if (month <= 0) { //月份减
|
369
|
+
month = Math.abs(month);
|
370
|
+
let yearNum = parseInt((month + 12) / 12);
|
371
|
+
year -= yearNum;
|
372
|
+
}
|
373
|
+
month = month < 10 ? "0" + month : month;
|
374
|
+
return year + "-" + month;
|
375
|
+
}
|
376
|
+
|
377
|
+
// 获取当前日期 yyyy-MM-dd
|
378
|
+
export function TODAY() {
|
379
|
+
// return this.FUNAPI.DODAY().toLocaleDateString().replaceAll("/","-")
|
380
|
+
return dateFormat(new Date(), "yyyy-MM-dd")
|
381
|
+
}
|
382
|
+
|
383
|
+
// 获取当前时间 yyyy-MM-dd hh:mm:ss
|
384
|
+
export function NOW() {
|
385
|
+
// return this.FUNAPI.NOW().toLocaleDateString().replaceAll("/","-")
|
386
|
+
return dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
|
387
|
+
}
|
388
|
+
|
389
|
+
/** 加减日期年
|
390
|
+
* @param {Object} date 日期
|
391
|
+
* @param {Object} month 加减的年
|
392
|
+
*/
|
393
|
+
export function EYEAR(date, year) {
|
394
|
+
try {
|
395
|
+
let myDate = new Date(date)
|
396
|
+
let newDate = myDate.setYear(myDate.getFullYear() + year)
|
397
|
+
return dateFormat(new Date(newDate), "yyyy-MM-dd")
|
398
|
+
} catch (e) {
|
399
|
+
//TODO handle the exception
|
400
|
+
//console.log(this.i18nt('designer.hint.formulaDateError'), date)
|
401
|
+
//console.error(this.i18nt('designer.hint.formulaDateErrorMsg'), e);
|
402
|
+
}
|
403
|
+
}
|
404
|
+
|
405
|
+
/** 加减日期月份
|
406
|
+
* @param {Object} date 日期
|
407
|
+
* @param {Object} month 加减的月份
|
408
|
+
*/
|
409
|
+
export function EMONTH(date, month) {
|
410
|
+
try {
|
411
|
+
let myDate = new Date(date)
|
412
|
+
let newDate = myDate.setMonth(myDate.getMonth() + month)
|
413
|
+
return dateFormat(new Date(newDate), "yyyy-MM-dd")
|
414
|
+
} catch (e) {
|
415
|
+
//TODO handle the exception
|
416
|
+
// console.log(this.i18nt('designer.hint.formulaDateError'), date)
|
417
|
+
// console.error(this.i18nt('designer.hint.formulaDateErrorMsg'), e);
|
418
|
+
}
|
419
|
+
}
|
420
|
+
|
421
|
+
/** 加减日期天数
|
422
|
+
* @param {Object} date
|
423
|
+
* @param {Object} day 加减天数
|
424
|
+
*/
|
425
|
+
export function EDAY(date, day) {
|
426
|
+
try {
|
427
|
+
let myDate = new Date(date)
|
428
|
+
let newDate = myDate.setDate(myDate.getDate() + day)
|
429
|
+
return dateFormat(new Date(newDate), "yyyy-MM-dd")
|
430
|
+
} catch (e) {
|
431
|
+
//TODO handle the exception
|
432
|
+
}
|
433
|
+
}
|
434
|
+
|
435
|
+
const FORMULA_JS_FUNCTIONS = [
|
436
|
+
"INT",
|
437
|
+
"SUM",
|
438
|
+
"AVERAGE",
|
439
|
+
"MAX",
|
440
|
+
"MIN",
|
441
|
+
"ABS",
|
442
|
+
"ROUND",
|
443
|
+
"CEILING",
|
444
|
+
"LOG",
|
445
|
+
"MOD",
|
446
|
+
"POWER",
|
447
|
+
"AND",
|
448
|
+
"IF",
|
449
|
+
"IFS",
|
450
|
+
"IFERROR",
|
451
|
+
"IFNA",
|
452
|
+
"NOT",
|
453
|
+
"OR",
|
454
|
+
"SWITCH",
|
455
|
+
"XOR",
|
456
|
+
"YEAR",
|
457
|
+
"MONTH",
|
458
|
+
"DAY",
|
459
|
+
"TODAY",
|
460
|
+
"NOW",
|
461
|
+
"EMONTH",
|
462
|
+
"EDAY",
|
463
|
+
"FIND",
|
464
|
+
"LEFT",
|
465
|
+
"RIGHT",
|
466
|
+
"LEN",
|
467
|
+
"LOWER",
|
468
|
+
"UPPER",
|
469
|
+
"MID",
|
470
|
+
"TRIM",
|
471
|
+
];
|
472
|
+
|
473
|
+
export const formulas = [
|
474
|
+
{
|
475
|
+
fClass: "designer.hint.formulaFunctionMaths",
|
476
|
+
flist: [
|
477
|
+
{
|
478
|
+
fName: "INT",
|
479
|
+
fType: "designer.hint.formulaNumber",
|
480
|
+
fIntro: "designer.hint.formulaINT",
|
481
|
+
},
|
482
|
+
{
|
483
|
+
fName: "SUM",
|
484
|
+
fType: "designer.hint.formulaNumber",
|
485
|
+
fIntro: "designer.hint.formulaSUM",
|
486
|
+
},
|
487
|
+
{
|
488
|
+
fName: "AVERAGE",
|
489
|
+
fType: "designer.hint.formulaNumber",
|
490
|
+
fIntro: "designer.hint.formulaAVERAGE",
|
491
|
+
},
|
492
|
+
{
|
493
|
+
fName: "MAX",
|
494
|
+
fType: "designer.hint.formulaNumber",
|
495
|
+
fIntro: "designer.hint.formulaMAX",
|
496
|
+
},
|
497
|
+
{
|
498
|
+
fName: "MIN",
|
499
|
+
fType: "designer.hint.formulaNumber",
|
500
|
+
fIntro: "designer.hint.formulaMIN",
|
501
|
+
},
|
502
|
+
{
|
503
|
+
fName: "ABS",
|
504
|
+
fType: "designer.hint.formulaNumber",
|
505
|
+
fIntro: "designer.hint.formulaABS",
|
506
|
+
},
|
507
|
+
{
|
508
|
+
fName: "ROUND",
|
509
|
+
fType: "designer.hint.formulaNumber",
|
510
|
+
fIntro: "designer.hint.formulaROUND",
|
511
|
+
},
|
512
|
+
{
|
513
|
+
fName: "CEILING",
|
514
|
+
fType: "designer.hint.formulaNumber",
|
515
|
+
fIntro: "designer.hint.formulaCEILING",
|
516
|
+
},
|
517
|
+
{
|
518
|
+
fName: "LOG",
|
519
|
+
fType: "designer.hint.formulaNumber",
|
520
|
+
fIntro: "designer.hint.formulaLOG",
|
521
|
+
},
|
522
|
+
{
|
523
|
+
fName: "MOD",
|
524
|
+
fType: "designer.hint.formulaNumber",
|
525
|
+
fIntro: "designer.hint.formulaMOD",
|
526
|
+
},
|
527
|
+
{
|
528
|
+
fName: "POWER",
|
529
|
+
fType: "designer.hint.formulaNumber",
|
530
|
+
fIntro: "designer.hint.formulaPOWER",
|
531
|
+
},
|
532
|
+
],
|
533
|
+
},
|
534
|
+
{
|
535
|
+
fClass: "designer.hint.formulaFunctionLogic",
|
536
|
+
flist: [
|
537
|
+
{
|
538
|
+
fName: "AND",
|
539
|
+
fType: "designer.hint.formulaObject",
|
540
|
+
fIntro: "designer.hint.formulaAND",
|
541
|
+
},
|
542
|
+
{
|
543
|
+
fName: "IF",
|
544
|
+
fType: "designer.hint.formulaObject",
|
545
|
+
fIntro: "designer.hint.formulaIF",
|
546
|
+
},
|
547
|
+
{
|
548
|
+
fName: "IFS",
|
549
|
+
fType: "designer.hint.formulaObject",
|
550
|
+
fIntro: "designer.hint.formulaIFS",
|
551
|
+
},
|
552
|
+
{
|
553
|
+
fName: "IFERROR",
|
554
|
+
fType: "designer.hint.formulaObject",
|
555
|
+
fIntro: "designer.hint.formulaIFERROR",
|
556
|
+
},
|
557
|
+
{
|
558
|
+
fName: "IFNA",
|
559
|
+
fType: "designer.hint.formulaObject",
|
560
|
+
fIntro: "designer.hint.formulaIFNA",
|
561
|
+
},
|
562
|
+
{
|
563
|
+
fName: "NOT",
|
564
|
+
fType: "designer.hint.formulaObject",
|
565
|
+
fIntro: "designer.hint.formulaNOT",
|
566
|
+
},
|
567
|
+
{
|
568
|
+
fName: "OR",
|
569
|
+
fType: "designer.hint.formulaObject",
|
570
|
+
fIntro: "designer.hint.formulaOR",
|
571
|
+
},
|
572
|
+
{
|
573
|
+
fName: "SWITCH",
|
574
|
+
fType: "designer.hint.formulaObject",
|
575
|
+
fIntro: "designer.hint.formulaSWITCH",
|
576
|
+
},
|
577
|
+
{
|
578
|
+
fName: "XOR",
|
579
|
+
fType: "designer.hint.formulaObject",
|
580
|
+
fIntro: "designer.hint.formulaXOR",
|
581
|
+
},
|
582
|
+
],
|
583
|
+
},
|
584
|
+
{
|
585
|
+
fClass: "designer.hint.formulaFunctionTime",
|
586
|
+
flist: [
|
587
|
+
{
|
588
|
+
fName: "YEAR",
|
589
|
+
fType: "designer.hint.formulaDate",
|
590
|
+
fIntro: "designer.hint.formulaYEAR",
|
591
|
+
},
|
592
|
+
{
|
593
|
+
fName: "MONTH",
|
594
|
+
fType: "designer.hint.formulaDate",
|
595
|
+
fIntro: "designer.hint.formulaMONTH",
|
596
|
+
},
|
597
|
+
{
|
598
|
+
fName: "DAY",
|
599
|
+
fType: "designer.hint.formulaDate",
|
600
|
+
fIntro: "designer.hint.formulaDAY",
|
601
|
+
},
|
602
|
+
{
|
603
|
+
fName: "TODAY",
|
604
|
+
fType: "designer.hint.formulaDate",
|
605
|
+
fIntro: "designer.hint.formulaTODAY",
|
606
|
+
},
|
607
|
+
{
|
608
|
+
fName: "NOW",
|
609
|
+
fType: "designer.hint.formulaDate",
|
610
|
+
fIntro: "designer.hint.formulaNOW",
|
611
|
+
},
|
612
|
+
{
|
613
|
+
fName: "EMONTH",
|
614
|
+
fType: "designer.hint.formulaDate",
|
615
|
+
fIntro: "designer.hint.formulaEMONTH",
|
616
|
+
},
|
617
|
+
{
|
618
|
+
fName: "EDAY",
|
619
|
+
fType: "designer.hint.formulaDate",
|
620
|
+
fIntro: "designer.hint.formulaEDAY",
|
621
|
+
},
|
622
|
+
],
|
623
|
+
},
|
624
|
+
{
|
625
|
+
fClass: "designer.hint.formulaFunctionString",
|
626
|
+
flist: [
|
627
|
+
{
|
628
|
+
fName: "FIND",
|
629
|
+
fType: "designer.hint.formulaChar",
|
630
|
+
fIntro: "designer.hint.formulaFIND",
|
631
|
+
},
|
632
|
+
{
|
633
|
+
fName: "LEFT",
|
634
|
+
fType: "designer.hint.formulaChar",
|
635
|
+
fIntro: "designer.hint.formulaLEFT",
|
636
|
+
},
|
637
|
+
{
|
638
|
+
fName: "RIGHT",
|
639
|
+
fType: "designer.hint.formulaChar",
|
640
|
+
fIntro: "designer.hint.formulaRIGHT",
|
641
|
+
},
|
642
|
+
{
|
643
|
+
fName: "LEN",
|
644
|
+
fType: "designer.hint.formulaChar",
|
645
|
+
fIntro: "designer.hint.formulaLEN",
|
646
|
+
},
|
647
|
+
{
|
648
|
+
fName: "LOWER",
|
649
|
+
fType: "designer.hint.formulaChar",
|
650
|
+
fIntro: "designer.hint.formulaLOWER",
|
651
|
+
},
|
652
|
+
{
|
653
|
+
fName: "UPPER",
|
654
|
+
fType: "designer.hint.formulaChar",
|
655
|
+
fIntro: "designer.hint.formulaUPPER",
|
656
|
+
},
|
657
|
+
{
|
658
|
+
fName: "MID",
|
659
|
+
fType: "designer.hint.formulaChar",
|
660
|
+
fIntro: "designer.hint.formulaMID",
|
661
|
+
},
|
662
|
+
{
|
663
|
+
fName: "TRIM",
|
664
|
+
fType: "designer.hint.formulaChar",
|
665
|
+
fIntro: "designer.hint.formulaTRIM",
|
666
|
+
},
|
667
|
+
],
|
668
|
+
},
|
669
|
+
];
|