cnhis-design-vue 0.3.3-beta → 0.3.6-beta

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 (81) hide show
  1. package/env.d.ts +2 -0
  2. package/es/big-table/index.css +1 -0
  3. package/es/big-table/index.js +116 -74
  4. package/es/button-print/index.css +1 -0
  5. package/es/drag-layout/index.css +2 -1
  6. package/es/drag-layout/index.js +33 -58
  7. package/es/grid/index.css +2 -1
  8. package/es/grid/index.js +2 -3
  9. package/es/index.css +2 -1
  10. package/es/index.js +152 -135
  11. package/package.json +5 -2
  12. package/packages/big-table/index.ts +17 -0
  13. package/packages/big-table/src/BigTable.vue +2511 -0
  14. package/packages/big-table/src/assets/iconfont/iconfont.less +21 -0
  15. package/packages/big-table/src/assets/iconfont/iconfont.ttf +0 -0
  16. package/packages/big-table/src/assets/img/failure.png +0 -0
  17. package/packages/big-table/src/assets/img/icon-asc.png +0 -0
  18. package/packages/big-table/src/assets/img/icon-desc.png +0 -0
  19. package/packages/big-table/src/assets/img/no-permission.png +0 -0
  20. package/packages/big-table/src/assets/img/nodata.png +0 -0
  21. package/packages/big-table/src/assets/img/notfound.png +0 -0
  22. package/packages/big-table/src/assets/img/qr.png +0 -0
  23. package/packages/big-table/src/assets/img/video_default_cover.png +0 -0
  24. package/packages/big-table/src/assets/img/xb_big.png +0 -0
  25. package/packages/big-table/src/assets/img/xb_small.png +0 -0
  26. package/packages/big-table/src/assets/style/table-base.less +275 -0
  27. package/packages/big-table/src/assets/style/table-global.less +167 -0
  28. package/packages/big-table/src/bigTableEmits.ts +46 -0
  29. package/packages/big-table/src/bigTableProps.ts +125 -0
  30. package/packages/big-table/src/bigTableState.ts +62 -0
  31. package/packages/big-table/src/components/NoData.vue +90 -0
  32. package/packages/big-table/src/components/SvgIcon.vue +49 -0
  33. package/packages/big-table/src/components/TextOverTooltip.vue +110 -0
  34. package/packages/big-table/src/components/edit-form/EditForm.vue +426 -0
  35. package/packages/big-table/src/components/edit-form/edit-component/edit-date-picker/edit-date-picker.vue +66 -0
  36. package/packages/big-table/src/components/edit-form/edit-component/edit-digital/edit-digital.vue +60 -0
  37. package/packages/big-table/src/components/edit-form/edit-component/edit-input/edit-input.vue +38 -0
  38. package/packages/big-table/src/components/edit-form/edit-component/edit-input-password/edit-input-password.vue +89 -0
  39. package/packages/big-table/src/components/edit-form/edit-component/edit-month-picker/edit-month-picker.vue +38 -0
  40. package/packages/big-table/src/components/edit-form/edit-component/edit-search/edit-search.vue +63 -0
  41. package/packages/big-table/src/components/edit-form/edit-component/edit-search-more/edit-search-more.vue +69 -0
  42. package/packages/big-table/src/components/edit-form/edit-component/edit-select/edit-select.vue +51 -0
  43. package/packages/big-table/src/components/edit-form/edit-component/edit-select-multiple/edit-select-multiple.vue +60 -0
  44. package/packages/big-table/src/components/edit-form/edit-component/edit-textarea/edit-textarea.vue +34 -0
  45. package/packages/big-table/src/components/edit-form/edit-component/edit-time-picker/edit-time-picker.vue +42 -0
  46. package/packages/big-table/src/components/edit-form/edit-component/editFormProps.ts +91 -0
  47. package/packages/big-table/src/components/edit-form/edit-component/register-com.ts +18 -0
  48. package/packages/big-table/src/components/edit-form/hooks/useConfigData.ts +79 -0
  49. package/packages/big-table/src/components/edit-form/hooks/useDateType.ts +184 -0
  50. package/packages/big-table/src/components/edit-form/hooks/useFormCommon.ts +373 -0
  51. package/packages/big-table/src/components/edit-form/hooks/useItemDefault.ts +638 -0
  52. package/packages/big-table/src/components/edit-form/hooks/useSearch.ts +910 -0
  53. package/packages/big-table/src/components/edit-form/hooks/useValidateRules.ts +387 -0
  54. package/packages/big-table/src/components/edit-form/interface.ts +53 -0
  55. package/packages/big-table/src/components/edit-form/types.ts +3 -0
  56. package/packages/big-table/src/components/edit-form/utils.ts +247 -0
  57. package/packages/big-table/src/hooks/useBatchEditing.ts +574 -0
  58. package/packages/big-table/src/hooks/useFormat.ts +612 -0
  59. package/packages/big-table/src/hooks/useNestTable.ts +109 -0
  60. package/packages/big-table/src/hooks/useTableParse.ts +169 -0
  61. package/packages/big-table/src/utils.ts +705 -0
  62. package/packages/button-print/index.ts +15 -0
  63. package/packages/button-print/src/ButtonPrint.vue +697 -0
  64. package/packages/button-print/src/components/IdentityVerification.vue +149 -0
  65. package/packages/button-print/src/interfaces.ts +19 -0
  66. package/packages/button-print/src/utils/crypto.js +25 -0
  67. package/packages/button-print/src/utils/print.es.min.js +1 -0
  68. package/packages/drag-layout/index.ts +15 -0
  69. package/packages/drag-layout/src/DragFormLeftItem.vue +131 -0
  70. package/packages/drag-layout/src/DragFormRightItem.vue +277 -0
  71. package/packages/drag-layout/src/DragLayout.vue +712 -0
  72. package/packages/grid/index.ts +17 -0
  73. package/packages/grid/src/Grid.tsx +22 -0
  74. package/packages/grid/src/hooks.ts +168 -0
  75. package/packages/index.ts +36 -0
  76. package/src/component/svg/index.vue +49 -0
  77. package/src/core/create.ts +5 -0
  78. package/src/global/variable.ts +2 -0
  79. package/src/utils/clickoutside.ts +80 -0
  80. package/src/utils/crypto.js +25 -0
  81. package/src/utils/vexutils.ts +811 -0
@@ -0,0 +1,387 @@
1
+ import type { FormItemRule } from 'naive-ui'
2
+ import type { CmpElement, OptionListObj, EditFormProps } from '../interface'
3
+ import vexutils from '@/utils/vexutils';
4
+
5
+ export const useValidateRules = () => {
6
+ const checkLenght = (rule: FormItemRule, value: any, item: any): boolean | Error => {
7
+ try {
8
+ const { validate = {}, is_null, html_type } = item || {};
9
+ let { min_length, max_length } = validate || {};
10
+ let curval = value + "";
11
+
12
+ if (html_type === "INPUT") {
13
+ max_length = max_length ? +max_length : 300;
14
+ } else if (html_type === "TEXTAREA") {
15
+ max_length = max_length ? +max_length : 500;
16
+ } else if (html_type === "RICH_TEXT") {
17
+ const div = document.createElement("div");
18
+ div.innerHTML = value;
19
+ curval = div.innerText;
20
+ }
21
+ const strlen = curval.length;
22
+ // max_value min_value 请输入X-X个字符
23
+ let max = strlen > max_length,
24
+ min = min_length > strlen;
25
+ if (is_null == 0 && !value && value != 0) {
26
+ return new Error(`请输入${min_length || 0}-${max_length}个字符`)
27
+ }
28
+ // 非必填,没有值
29
+ if (is_null == 1 && !value) {
30
+ return true
31
+ }
32
+ if ((min_length || String(min_length) === "0") && max_length && (max || min)) {
33
+ return new Error(`请输入${min_length || 0}-${max_length}个字符`)
34
+ } else if (min_length && min) {
35
+ return new Error(`至少输入${min_length}个字符`)
36
+ } else if (max_length && max) {
37
+ return new Error(`最多只能输入${max_length}个字符`)
38
+ }
39
+ return true
40
+ } catch (error) {
41
+ console.log(error, "------checkLenght");
42
+ return true
43
+ }
44
+ }
45
+ const getInputCheck = (validate = undefined) => {
46
+ if (!validate) return false;
47
+ const isInteger = validate == "integer";
48
+ return {
49
+ pattern: isInteger ? /^-?[0-9]+$/ : /^(-?[0-9]+)(\\.[0-9]+)?$/,
50
+ message: isInteger ? "只能输入数字" : "只能输入数字和小数"
51
+ };
52
+ }
53
+ const handlerSetIdCarInfoValidate = (rule: FormItemRule, value: any, item: any) => {
54
+ try {
55
+ const { validate = {} } = item || {};
56
+ if (validate.vali_obj == "id_card") {
57
+ const pat = /^\d{6}(((19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{3}([0-9]|x|X))|(\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{3}))$/;
58
+ if (!pat.test(value)) {
59
+ return new Error(`请输入正确的身份证号码`)
60
+ }
61
+ }
62
+ return true
63
+ } catch (error) {
64
+ console.log(error, "------handlerSetIdCarInfoValidate");
65
+ return true
66
+ }
67
+ }
68
+ const checkinputBlank = (rule: FormItemRule, value: any, item: any) => {
69
+ try {
70
+ const { is_null, delete_before_after_spaces } = item;
71
+ if (typeof value === "string" && delete_before_after_spaces == 1) {
72
+ let val = value.trim();
73
+ if (!val && is_null == 0) {
74
+ return new Error(`不可为空`)
75
+ }
76
+ }
77
+ return true
78
+ } catch (error) {
79
+ console.log(error, "------checkinputBlank");
80
+ return true
81
+ }
82
+ }
83
+ const checkDigital = (rule: FormItemRule, value: any, item: any) => {
84
+ try {
85
+ const { validate, is_null, decimal_length, alias, name } = item;
86
+ const { min_value, max_value } = validate || {};
87
+ let showName = alias || name;
88
+ // max_value min_value
89
+ if (isNaN(+value)) {
90
+ return new Error(`只能输入数字`)
91
+ }
92
+ if (is_null == 0 && !value && value != 0) {
93
+ return new Error(`请输入${showName}有效范围`)
94
+ }
95
+ if (!value && value !== 0) {
96
+ if (is_null == 0) {
97
+ return new Error(`请输入${showName}有效范围`)
98
+ }
99
+ return true
100
+ }
101
+
102
+ const decimalLen = decimal_length || validate.decimal_length;
103
+ const valList = (value + "").trim().split(".");
104
+ if (decimalLen && decimalLen != 0) {
105
+ if (valList[1] && valList[1].length > decimalLen) {
106
+ return new Error(`小数最多${decimalLen}位`)
107
+ }
108
+ } else {
109
+ const flag = /^-?[0-9]+$/.test(value);
110
+ if (!flag) {
111
+ return new Error(`请输入整数`)
112
+ }
113
+ }
114
+ let max = +value > +max_value,
115
+ min = +min_value > +value;
116
+ if ((min_value || max_value) && (value || value == 0)) {
117
+ if ((min_value || String(min_value) === "0") && max_value && (max || min)) {
118
+ return new Error(`请输入${min_value}~${max_value}`)
119
+ } else if ((min_value && min) || (max_value && max)) {
120
+ return new Error(`请输入${showName}有效范围`)
121
+ }
122
+ return true
123
+ }
124
+ return true
125
+ } catch (error) {
126
+ console.log(error, "------checkDigital");
127
+ return true
128
+ }
129
+ }
130
+ const checkAgeJson = (rule: FormItemRule, value: any, item: any) => {
131
+ try {
132
+ const { is_null, alias, name } = item;
133
+ const { year, month, day, days } = value;
134
+ const c = (val: number) => String(val) === "0" || val > 0;
135
+ const checkval = () => !(c(year) || c(month) || c(day));
136
+ if (is_null == 0) {
137
+ if (checkval()) {
138
+ return new Error(`请输入${alias || name}`)
139
+ } else if (days > 73000) {
140
+ return new Error(`超出年龄范围0~200岁`)
141
+ }
142
+ }
143
+ return true
144
+ } catch (error) {
145
+ console.log(error, "------checkAgeJson");
146
+ return true
147
+ }
148
+ }
149
+ const checkAge = (rule: FormItemRule, value: any, item: any) => {
150
+ try {
151
+ let { is_null, name, alias } = item;
152
+ if (!value && is_null == 0) {
153
+ return new Error(`${alias || name}不能为空`)
154
+ }
155
+ if (!item.val_key_unit) {
156
+ return true
157
+ }
158
+ const curVal = item?.useFormValue
159
+ let k = typeof curVal === "string" && curVal.toLowerCase();
160
+ const o = {
161
+ year: 200,
162
+ month: 2400,
163
+ day: 73000
164
+ };
165
+ if (k) {
166
+ if (value > o[k]) {
167
+ return new Error(`超出年龄范围0~200岁`)
168
+ }
169
+ }
170
+ return true
171
+ } catch (error) {
172
+ console.log(error, "------checkAge");
173
+ return true
174
+ }
175
+ }
176
+ const handleUploadValidator = (rule: FormItemRule, value: any, item: any) => {
177
+ try {
178
+ let curval = value;
179
+ const { is_null, name, validate, html_type } = item;
180
+ let { min_length, max_length } = validate || {};
181
+ let unit = html_type === "UPPICTURE" ? "张" : "个";
182
+ if (html_type === "UPPICTURE") {
183
+ curval = curval.split(",").filter(Boolean);
184
+ } else if (vexutils.isJSON(value || "")) {
185
+ curval = JSON.parse(curval);
186
+ }
187
+ let len = curval?.length || 0;
188
+ if (is_null == 1 && len === 0) {
189
+ return true
190
+ } else if (is_null == 0 && (!curval || len === 0)) {
191
+ return new Error(`请上传${name}`)
192
+ } else if (len > 0) {
193
+ if (len < min_length) {
194
+ return new Error(`最少上传${min_length}${unit}`)
195
+ } else if (len > max_length) {
196
+ return new Error(`最多只能上传${max_length}${unit}`)
197
+ }
198
+ }
199
+ return true
200
+ } catch (error) {
201
+ console.log(error, "------handleUploadValidator");
202
+ return true
203
+ }
204
+ }
205
+ const checkMultipleChoice = (rule: FormItemRule, value: any, item: any) => {
206
+ try {
207
+ const { multi_select, multi_select_value, is_null, alias, name } = item;
208
+ if (Array.isArray(value)) {
209
+ if (is_null == 0) {
210
+ if (value.length === 0) {
211
+ return new Error(`请选择${alias || name}`)
212
+ }
213
+ }
214
+ if (is_null == 1 && value.length === 0) {
215
+ return true
216
+ }
217
+ if (multi_select_value) {
218
+ if (value.length > multi_select_value) {
219
+ return new Error(`最多只能选择${multi_select_value}项`)
220
+ }
221
+ }
222
+ }
223
+ return true
224
+ } catch (error) {
225
+ console.log(error, "------checkMultipleChoice");
226
+ return true
227
+ }
228
+ }
229
+ const checkcandidate = (rule: FormItemRule, value: any, item: any) => {
230
+ try {
231
+ let curval = value;
232
+ const { is_null, name, validate, check_max_val, check_min_val } = item;
233
+
234
+ // let { min_length, max_length } = validate;
235
+ if (is_null == 0 && !curval) {
236
+ return new Error(`请选${name}`)
237
+ }
238
+ if (vexutils.isJSON(value || "")) {
239
+ curval = JSON.parse(curval);
240
+ }
241
+ if (is_null != 0 && !Array.isArray(curval)) {
242
+ return true
243
+ }
244
+ let len = curval?.length || 0;
245
+ if (is_null == 1 && len === 0) {
246
+ return true
247
+ } else if (is_null == 0 && (!curval || len === 0)) {
248
+ return new Error(`请选${name}`)
249
+ } else if (len > 0) {
250
+ if (len < check_min_val) {
251
+ return new Error(`至少要选${check_min_val}项`)
252
+ } else if (len > check_max_val) {
253
+ return new Error(`最多可选${check_max_val}项`)
254
+ }
255
+ }
256
+ return true
257
+ } catch (error) {
258
+ console.log(error, "------checkcandidate");
259
+ return true
260
+ }
261
+ }
262
+ // 表单验证
263
+ const handleGetRules = (item: any) => {
264
+ const initRules: FormItemRule[] = [];
265
+ const { validate = {}, is_null } = item;
266
+ let { vali_obj } = validate;
267
+ // intercept 即使不显示 也需要校验
268
+ if (item.is_show == 0 && item.useType != "intercept") {
269
+ return initRules;
270
+ }
271
+ if (item.lineBarCheck || item.is_hide_field) {
272
+ return [];
273
+ }
274
+ switch (item.html_type) {
275
+ case "INPUT":
276
+ case "TEXTAREA":
277
+ case "RICH_TEXT":
278
+ initRules.push({
279
+ required: item.is_null == 0,
280
+ message: `请输入${item.name}`,
281
+ trigger: "change"
282
+ });
283
+ if (vali_obj != "mobile") {
284
+ initRules.push({
285
+ validator: (rule, value): boolean | Error => checkLenght(rule, value, item),
286
+ trigger: "change"
287
+ });
288
+ }
289
+ if (["integer", "number"].includes(vali_obj)) {
290
+ const rule = getInputCheck(vali_obj);
291
+ rule && initRules.push(rule);
292
+ }
293
+ if (vali_obj == "id_card") {
294
+ initRules.push({
295
+ validator: (rule, value) =>
296
+ handlerSetIdCarInfoValidate(rule, value, item),
297
+ trigger: "change"
298
+ });
299
+ }
300
+ initRules.push({
301
+ validator: (rule, value) => checkinputBlank(rule, value, item),
302
+ trigger: "change"
303
+ });
304
+ break;
305
+ case "DIGITAL":
306
+ initRules.push({
307
+ validator: (rule, value) => checkDigital(rule, value, item)
308
+ });
309
+ break;
310
+
311
+ case "AGE_JSON":
312
+ initRules.push({
313
+ validator: (rule, value) => checkAgeJson(rule, value, item),
314
+ trigger: "change"
315
+ });
316
+
317
+ break;
318
+ case "AGE":
319
+ initRules.push(
320
+ {
321
+ validator: (rule, value) => checkAge(rule, value, item),
322
+ trigger: "change"
323
+ },
324
+ {
325
+ required: item.is_null == 0,
326
+ message: `请输入${item.name}`
327
+ }
328
+ );
329
+ break;
330
+
331
+ case "UPPICTURE":
332
+ case "UPFILE":
333
+ case "VEDIO":
334
+ initRules.push({
335
+ validator: (rule, value) =>
336
+ handleUploadValidator(rule, value, item),
337
+ trigger: "change"
338
+ });
339
+
340
+ break;
341
+ case "CHECKBOX_BLOCK":
342
+ case "CHECKBOX":
343
+ case "SEARCH_MORE":
344
+ initRules.push(
345
+ {
346
+ required: item.is_null == 0,
347
+ message: `请选择${item.name}`,
348
+ trigger: "change"
349
+ },
350
+ {
351
+ validator: (rule, value) =>
352
+ checkMultipleChoice(rule, value, item),
353
+ trigger: "change"
354
+ }
355
+ );
356
+ break;
357
+ case "CANDIDATE_COMPONENTS":
358
+ initRules.push({
359
+ validator: (rule, value) => checkcandidate(rule, value, item),
360
+ trigger: "change"
361
+ });
362
+ break;
363
+ default:
364
+ initRules.push({
365
+ required: item.is_null == 0,
366
+ message: `请选择${item.name}`,
367
+ trigger: "change"
368
+ });
369
+ break;
370
+ }
371
+ if (validate && vali_obj == "mobile" && !validate.phone_idcard_type && is_null == 0) {
372
+ initRules.push({
373
+ pattern: /(^[0-9]{11,11}$)/,
374
+ message: '请输入正确的电话号码',
375
+ trigger: "change"
376
+ });
377
+ }
378
+ if(initRules.length) {
379
+ initRules[0].key = item.val_key
380
+ }
381
+ return initRules;
382
+ }
383
+
384
+ return {
385
+ handleGetRules
386
+ }
387
+ }
@@ -0,0 +1,53 @@
1
+ import { CmpName } from './types'
2
+
3
+ interface Validate {
4
+ obj_type?: string
5
+ }
6
+
7
+ export interface OptionListObj {
8
+ text?: string
9
+ value?: string
10
+ }
11
+
12
+ export interface CmpElement {
13
+ html_type: CmpName
14
+ date_format?: string
15
+ validate?: Validate
16
+ name: string
17
+ default_val: string
18
+ option: OptionListObj[]
19
+ data_value?: string
20
+ condition: string
21
+ attr: string
22
+ unit: string
23
+ is_multi: string | number
24
+ }
25
+
26
+ export interface FieldListProp {
27
+ isPure: boolean
28
+ }
29
+
30
+ export interface defaultFormProp {
31
+ defaultCombinationForm?: any
32
+ fieldList?: FieldListProp[]
33
+ }
34
+
35
+ export interface EditFormProps {
36
+ defaultForm: defaultFormProp
37
+ isPure: boolean
38
+ cacheUniqueKey?: any
39
+ banRequest?: boolean
40
+ propsDelSetting?: boolean
41
+ propsFormBtn?: boolean
42
+ parentConfig?: any
43
+ configuration?: any
44
+ isOpenShortcut?: boolean
45
+ formPrimaryKey: number | string
46
+ styleSetting?: any
47
+ }
48
+
49
+ export interface DateProp {
50
+ year?: number | string
51
+ month?: number | string
52
+ day?: number | string
53
+ }
@@ -0,0 +1,3 @@
1
+ export type CmpName = 'INPUT' | 'DIGITAL' | 'TEXTAREA' | 'RADIO' | 'RADIO_BLOCK' | 'CHECKBOX_BLOCK' | 'CHECKBOX' | 'SEARCH' | 'SEARCH_MORE' | 'DATE' | 'DATE-INPUT' | 'DATETIME-INPUT' | 'SELECT' | 'PHONE_TYPE' | 'IDCARD_TYPE' | 'editMonthPicker' | 'editTimePicker' | 'editDatePicker' | 'editSelect' | 'editInputPassword' | 'editSelectMultiple' | 'MAP' | 'ICON' | 'TIME-INPUT' | 'UPPICTURE' | 'LEVEL_SEARCH_CASCADE2' | 'LABEL' | 'GUAGE' | 'SLIDER_COMPONENT' | 'SWITCH_COMPONENT' | 'AGE_JSON' | 'AGE'
2
+
3
+ export type CmpNameValue = 'editInput' | 'editDigital' | 'editTextarea' | 'editSelect' | 'editSelectMultiple' | 'editSearch' | 'editSearchMore' | 'editDatePicker' | 'editMonthPicker' | 'editTimePicker' | 'editInputPassword'
@@ -0,0 +1,247 @@
1
+ /**
2
+ * 表单常用函数
3
+ */
4
+ import vexutils from '@/utils/vexutils';
5
+ import moment from 'moment';
6
+ import type { DateProp, CmpElement } from './interface'
7
+ interface ParamsProp {
8
+ defaultValue: any
9
+ userInfo: any
10
+ dbParams: any
11
+ }
12
+
13
+ /**
14
+ * deprecated: 生日 获取年龄 信息
15
+ * param {string} str 'YYYY-MM-DD' 时间格式
16
+ * returns {Object} {year, month, day}
17
+ */
18
+ export const getAgeInfo = (str: string): DateProp => {
19
+ let r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/);
20
+ if (r == null) return {};
21
+ let Y, M, D;
22
+ let d = new Date(+r[1], +r[3] - 1, +r[4]);
23
+ let returnStr = "输入的日期格式错误!";
24
+
25
+ if (d.getFullYear() == +r[1] && d.getMonth() + 1 == +r[3] && d.getDate() == +r[4]) {
26
+ let date = new Date();
27
+ let yearNow = date.getFullYear();
28
+ let monthNow = date.getMonth() + 1;
29
+ let dayNow = date.getDate();
30
+
31
+ let largeMonths = [1, 3, 5, 7, 8, 10, 12], // 大月, 用于计算天,只在年月都为零时,天数有效
32
+ lastMonth = monthNow - 1 > 0 ? monthNow - 1 : 12, // 上一个月的月份
33
+ isLeapYear = false, // 是否是闰年
34
+ daysOFMonth = 0; // 当前日期的上一个月多少天
35
+
36
+ if ((yearNow % 4 === 0 && yearNow % 100 !== 0) || yearNow % 400 === 0) {
37
+ // 是否闰年, 用于计算天,只在年月都为零时,天数有效
38
+ isLeapYear = true;
39
+ }
40
+
41
+ if (largeMonths.indexOf(lastMonth) > -1) {
42
+ daysOFMonth = 31;
43
+ } else if (lastMonth === 2) {
44
+ if (isLeapYear) {
45
+ daysOFMonth = 29;
46
+ } else {
47
+ daysOFMonth = 28;
48
+ }
49
+ } else {
50
+ daysOFMonth = 30;
51
+ }
52
+
53
+ Y = yearNow - parseInt(r[1]);
54
+ M = monthNow - parseInt(r[3]);
55
+ D = dayNow - parseInt(r[4]);
56
+ if (D < 0) {
57
+ D = D + daysOFMonth; // 借一个月
58
+ M--;
59
+ }
60
+ if (M < 0) {
61
+ // 借一年 12个月
62
+ Y--;
63
+ M = M + 12; //
64
+ }
65
+
66
+ if (Y < 0) {
67
+ returnStr = "出生日期有误!";
68
+ console.log(returnStr);
69
+ return { year: 0, month: 0, day: 0 };
70
+ } else if (Y === 0) {
71
+ if (M === 0) {
72
+ returnStr = D + "D";
73
+ } else {
74
+ returnStr = M + "M";
75
+ }
76
+ } else {
77
+ if (M === 0) {
78
+ returnStr = Y + "Y";
79
+ } else {
80
+ returnStr = Y + "Y" + M + "M";
81
+ }
82
+ }
83
+
84
+ // console.log(Y, M, D);
85
+ }
86
+
87
+ // return returnStr;
88
+ return { year: Y, month: M, day: D };
89
+ }
90
+
91
+ /**
92
+ * 兼容map
93
+ */
94
+ export const handleCompatibilityMap = (map: any = {}) => {
95
+ /**
96
+ * c_key_list
97
+ * 兼容处理,
98
+ * 兼容用户 输入 map.xx, sql.xx, result.xx 都可以解析到值
99
+ * 只要找个一个key有值,其他key 都附上同样的值
100
+ */
101
+ if (typeof map !== "object") return map;
102
+ let c_key_list = ["map", "sql", "result"];
103
+ let key_list = Object.keys(map || {});
104
+ let curKey = key_list.find(k => c_key_list.includes(k));
105
+ if (curKey) {
106
+ c_key_list.forEach(c => {
107
+ map[c] = map[curKey!];
108
+ });
109
+ }
110
+ return map;
111
+ }
112
+
113
+ export const randomId = (len: number) => {
114
+ return Math.random()
115
+ .toString(36)
116
+ .slice(3, len);
117
+ }
118
+ // 变量解析
119
+ export const handleSysParams = (str: string | number, obj: ParamsProp) => {
120
+ // let sysData = this.userInfo.map.sysParams;
121
+ let p: any = {
122
+ form: { ...obj.defaultValue },
123
+ sys: obj.userInfo?.map?.sysParams || {},
124
+ db: { ...(obj.dbParams || {}) }
125
+ };
126
+ // let isEmpty = v => Object.keys(v || {}).length;
127
+ const that = this;
128
+ const getVal = (t: string, r: RegExp, k: string) => {
129
+ return t.replace(r, function() {
130
+ let pKey = arguments[1];
131
+ let pls = pKey.split('!');
132
+ let plsList = pls.slice(1);
133
+ let l: string[] = [];
134
+ plsList.forEach((v: string) => {
135
+ let c = v;
136
+ if (v.includes('.')) {
137
+ let [_k, _v] = v.split('.');
138
+ c = typeof p[_k] === 'object' ? p[_k][_v] : '';
139
+ }
140
+ if (c || +c == 0) {
141
+ l.push(c);
142
+ }
143
+ });
144
+ let f = l.find(v => v || +v == 0);
145
+ let res = p[k][pls[0]];
146
+ res = vexutils.notEmpty(res) ? res : '';
147
+ if (pls.length > 1) {
148
+ return res || f;
149
+ }
150
+ return res;
151
+ });
152
+ };
153
+ if (typeof str === 'string') {
154
+ if (str.includes('form')) {
155
+ str = getVal(str, /\${form.(.*?)\}/g, 'form');
156
+ }
157
+ if (str.includes('sys')) {
158
+ str = getVal(str, /\${sys.(.*?)\}/g, 'sys');
159
+ }
160
+ if (str.includes('db')) {
161
+ str = getVal(str, /\${db.(.*?)\}/g, 'db');
162
+ }
163
+ }
164
+ if ((!str && +str != 0) || ['undefined', 'null'].includes(String(str))) {
165
+ str = '';
166
+ }
167
+ return str;
168
+ }
169
+
170
+ // 获取分组
171
+ export const hanldeGetTargetList = (t: any = {}, defaultFieldList: any[]) => {
172
+ if (t.group) {
173
+ return defaultFieldList.filter((v: any) => v.group == t.group);
174
+ }
175
+ return defaultFieldList || [];
176
+ }
177
+
178
+ // 获取身份证上的信息
179
+ export const handlerGetIdcatInfo = (idNo: string) => {
180
+ let parseInner = (certificateNo: string, idxSexStart: number, birthYearSpan: number) => {
181
+ let res: any = {};
182
+ let idxSex = 1 - (+certificateNo.slice(idxSexStart, 1) % 2);
183
+ // 女: "2" 男: "1"
184
+ res.sex = idxSex == 1 ? '2' : '1';
185
+
186
+ let year = (birthYearSpan == 2 ? '19' : '') + certificateNo.slice(6, birthYearSpan);
187
+ let month = certificateNo.slice(6 + birthYearSpan, 2);
188
+ let day = certificateNo.slice(8 + birthYearSpan, 2);
189
+ res.birthday = year + '-' + month + '-' + day;
190
+
191
+ let d = new Date();
192
+ let monthFloor = d.getMonth() + 1 < parseInt(month, 10) || (d.getMonth() + 1 == parseInt(month, 10) && d.getDate() < parseInt(day, 10)) ? 1 : 0;
193
+ // res.age = d.getFullYear() - parseInt(year, 10) - monthFloor;
194
+ res.year = d.getFullYear() - parseInt(year, 10) - monthFloor;
195
+ res.day = moment(d).diff(moment(new Date(res.birthday)), 'days');
196
+ res.month = moment(d).diff(moment(new Date(res.birthday)), 'months');
197
+ return res;
198
+ };
199
+ return parseInner(idNo, idNo.length == 15 ? 14 : 16, idNo.length == 15 ? 2 : 4);
200
+ }
201
+
202
+ // 获取日期格式
203
+ export const handlerGetDateType = (data: any): string => {
204
+ let dateType;
205
+ switch (data.html_type) {
206
+ case 'DATETIME-INPUT':
207
+ dateType = 'yyyy-MM-dd HH:mm:ss';
208
+ break;
209
+ case 'DATE-INPUT':
210
+ dateType = 'yyyy-MM-dd';
211
+ break;
212
+ case 'TIME-INPUT':
213
+ dateType = 'HH:mm:ss';
214
+ break;
215
+ case 'DATE':
216
+ data.date_format = data.date_format && data.date_format.replace(/yyyy/gi, 'yyyy');
217
+ dateType = (data.date_format || 'yyyy-MM-dd')
218
+ .replace(/yyyy-MM-dd/gi, 'yyyy-MM-dd')
219
+ .replace(/hh:mm:ss/gi, 'HH:mm:ss')
220
+ .replace(/hh:mm/gi, 'HH:mm');
221
+ break;
222
+ default:
223
+ dateType = data.date_format || 'yyyy-MM-dd';
224
+ break;
225
+ }
226
+ return dateType;
227
+ }
228
+
229
+ export const handleGetJsonStr = (str: any) => {
230
+ // {objs:[],objstr:''}, {type: 'jsonb', value: "{objs:[],objstr:''}"}
231
+ let resObj: any = {};
232
+ if (vexutils.isJSON(str)) {
233
+ resObj = JSON.parse(str);
234
+ } else {
235
+ resObj = typeof str === 'string' ? {} : str;
236
+ }
237
+ if (resObj && !resObj.objs && resObj.value) {
238
+ if (vexutils.isJSON(resObj.value)) {
239
+ resObj = JSON.parse(resObj.value);
240
+ // loop
241
+ if (resObj.type === 'jsonb') {
242
+ resObj = handleGetJsonStr(resObj);
243
+ }
244
+ }
245
+ }
246
+ return resObj;
247
+ }