cnhis-design-vue 3.1.16-beta.1 → 3.1.16-beta.4
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/es/packages/big-table/index.d.ts +651 -1
- package/es/packages/big-table/src/BigTable.vue.d.ts +674 -23
- package/es/packages/big-table/src/BigTable.vue_vue_type_script_setup_true_lang.js +46 -18
- package/es/packages/big-table/src/bigTableProps.d.ts +4 -0
- package/es/packages/big-table/src/bigTableProps.js +2 -1
- package/es/packages/big-table/src/bigTableState.d.ts +2 -0
- package/es/packages/big-table/src/bigTableState.js +3 -1
- package/es/packages/big-table/src/components/edit-form/edit-time.js +1 -1
- package/es/packages/big-table/src/hooks/index.d.ts +9 -0
- package/es/packages/big-table/src/hooks/index.js +9 -0
- package/es/packages/big-table/src/hooks/useAnchor.d.ts +7 -0
- package/es/packages/big-table/src/hooks/useAnchor.js +41 -0
- package/es/packages/big-table/src/hooks/useColumnConfigAdaptor.js +24 -8
- package/es/packages/big-table/src/hooks/useEdit.js +1 -1
- package/es/packages/big-table/src/hooks/useEvent.d.ts +1 -1
- package/es/packages/big-table/src/hooks/useEvent.js +3 -2
- package/es/packages/button-print/index.d.ts +2 -2
- package/es/packages/button-print/src/ButtonPrint.vue.d.ts +2 -2
- package/es/packages/button-print/src/components/IdentityVerification.vue.d.ts +2 -2
- package/es/packages/drag-layout/index.d.ts +2 -2
- package/es/packages/drag-layout/src/DragLayout.vue.d.ts +2 -2
- package/es/packages/fabric-chart/src/FabricChart.js +2 -1
- package/es/packages/field-set/index.d.ts +1 -1
- package/es/packages/field-set/src/FieldSet.vue.d.ts +1 -1
- package/es/packages/form-config/index.d.ts +17 -35
- package/es/packages/form-config/src/FormConfig.vue.d.ts +17 -35
- package/es/packages/form-config/src/components/FormConfigCreator.vue.d.ts +6 -15
- package/es/packages/form-config/src/components/FormConfigEdit.js +1 -1
- package/es/packages/form-config/src/components/FormConfigEdit.vue.d.ts +8 -17
- package/es/packages/form-config/src/constants/index.d.ts +47 -13
- package/es/packages/form-config/src/constants/index.js +52 -14
- package/es/packages/form-config/src/hooks/index.d.ts +1 -0
- package/es/packages/form-config/src/hooks/index.js +1 -0
- package/es/packages/form-config/src/hooks/useConfigurationField.js +6 -43
- package/es/packages/form-config/src/hooks/usePresetRenderer.js +1 -1
- package/es/packages/form-config/src/hooks/useSortable.d.ts +0 -1
- package/es/packages/form-render/index.d.ts +6 -15
- package/es/packages/form-render/src/FormRender.js +3 -4
- package/es/packages/form-render/src/FormRender.vue.d.ts +7 -16
- package/es/packages/form-render/src/components/renderer/cascader.js +1 -1
- package/es/packages/form-render/src/components/renderer/checkbox.js +1 -1
- package/es/packages/form-render/src/components/renderer/combination/index.js +2 -1
- package/es/packages/form-render/src/components/renderer/complex.js +1 -1
- package/es/packages/form-render/src/components/renderer/input.js +2 -1
- package/es/packages/form-render/src/components/renderer/inputNumber.js +2 -1
- package/es/packages/form-render/src/components/renderer/radio.js +1 -1
- package/es/packages/form-render/src/components/renderer/select.js +1 -1
- package/es/packages/form-render/src/components/renderer/slider.js +1 -1
- package/es/packages/form-render/src/components/renderer/switch.js +1 -1
- package/es/packages/form-render/src/components/renderer/textarea.js +1 -1
- package/es/packages/form-render/src/hooks/useBusinessBinding.d.ts +12 -9
- package/es/packages/form-render/src/hooks/useBusinessBinding.js +58 -58
- package/es/packages/form-render/src/hooks/useFieldListAdaptor.js +9 -2
- package/es/packages/form-render/src/hooks/useFormContext.d.ts +2 -1
- package/es/packages/form-render/src/hooks/useFormContext.js +2 -2
- package/es/packages/form-render/src/hooks/useTypeNormalize.js +1 -1
- package/es/packages/form-render/src/types/index.d.ts +0 -8
- package/es/packages/form-render/src/utils/business.d.ts +12 -0
- package/es/packages/form-render/src/utils/business.js +65 -0
- package/es/packages/form-render/src/utils/dom.d.ts +6 -0
- package/es/packages/form-render/src/utils/dom.js +14 -0
- package/es/packages/form-render/src/utils/index.d.ts +5 -25
- package/es/packages/form-render/src/utils/index.js +5 -137
- package/es/packages/form-render/src/utils/schema.d.ts +15 -0
- package/es/packages/form-render/src/utils/schema.js +83 -0
- package/es/packages/scale-view/src/hooks/use-component.d.ts +7 -7
- package/es/packages/select-label/index.d.ts +10 -10
- package/es/packages/select-label/src/LabelFormContent.vue.d.ts +3 -3
- package/es/packages/select-label/src/SelectLabel.vue.d.ts +7 -7
- package/es/packages/shortcut-setter/index.d.ts +6 -15
- package/es/packages/shortcut-setter/src/ShortcutSetter.vue.d.ts +6 -15
- package/es/packages/time-line/index.d.ts +2 -2
- package/es/packages/time-line/src/TimeLine.vue.d.ts +2 -2
- package/global.d.ts +8 -8
- package/package.json +1 -1
|
@@ -1,87 +1,87 @@
|
|
|
1
|
+
import { isField } from '@formily/core';
|
|
1
2
|
import { isString } from '@vueuse/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { isNumber } from 'lodash-es';
|
|
4
|
+
import { FIELD_BUSINESS_TYPE } from '../constants/index.js';
|
|
5
|
+
import { isIdCard, parseIdCard, parseAge2FromContext, parseBirthday, parseAge2Birthday } from '../utils/business.js';
|
|
4
6
|
|
|
5
7
|
class BusinessCollector {
|
|
6
|
-
constructor(
|
|
8
|
+
constructor(formModel) {
|
|
9
|
+
this.formModel = formModel;
|
|
7
10
|
this.typeCollector = /* @__PURE__ */ new Map();
|
|
8
11
|
this.fieldNameCollector = /* @__PURE__ */ new Map();
|
|
9
|
-
this.
|
|
12
|
+
this.handlerChangeMap = /* @__PURE__ */ new Map([
|
|
10
13
|
[FIELD_BUSINESS_TYPE.ID_CARD, this.handlerIdCardType.bind(this)],
|
|
11
|
-
[FIELD_BUSINESS_TYPE.
|
|
14
|
+
[FIELD_BUSINESS_TYPE.AGE_UNIT, this.handlerAgeType.bind(this)]
|
|
15
|
+
]);
|
|
16
|
+
this.blurHandlerMap = /* @__PURE__ */ new Map([
|
|
17
|
+
[FIELD_BUSINESS_TYPE.BIRTHDAY, this.handlerBirthdayType.bind(this)],
|
|
18
|
+
[FIELD_BUSINESS_TYPE.AGE, this.handlerAgeType.bind(this)]
|
|
12
19
|
]);
|
|
13
|
-
this.valueFilter = valueFilter;
|
|
14
20
|
}
|
|
15
21
|
collect(type, fieldName) {
|
|
16
|
-
|
|
17
|
-
set.add(fieldName);
|
|
18
|
-
this.typeCollector.set(type, set);
|
|
22
|
+
this.typeCollector.set(type, fieldName);
|
|
19
23
|
this.fieldNameCollector.set(fieldName, type);
|
|
20
24
|
}
|
|
21
25
|
getField(type) {
|
|
22
|
-
return
|
|
26
|
+
return this.typeCollector.get(type);
|
|
23
27
|
}
|
|
24
28
|
getType(fieldName) {
|
|
25
29
|
return this.fieldNameCollector.get(fieldName);
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
ageFields.forEach((field) => {
|
|
42
|
-
formModel.setFieldState(field, (state) => {
|
|
43
|
-
state.value = this.valueFilter({
|
|
44
|
-
fieldKey: field,
|
|
45
|
-
value: ageUnitFields.length ? value.age : context.year,
|
|
46
|
-
context,
|
|
47
|
-
type: FIELD_BUSINESS_TYPE.AGE
|
|
48
|
-
});
|
|
49
|
-
});
|
|
31
|
+
getValueByField(fieldName) {
|
|
32
|
+
const _field = this.formModel.query(fieldName).take();
|
|
33
|
+
return isField(_field) ? _field.value : null;
|
|
34
|
+
}
|
|
35
|
+
getValueByType(type) {
|
|
36
|
+
const field = this.getField(type);
|
|
37
|
+
return field ? this.getValueByField(field) : null;
|
|
38
|
+
}
|
|
39
|
+
setValueByType(type, value, force = true) {
|
|
40
|
+
const field = this.getField(type);
|
|
41
|
+
field && this.formModel.setFieldState(field, (state) => {
|
|
42
|
+
if (!force && state.value)
|
|
43
|
+
return;
|
|
44
|
+
state.value = value;
|
|
50
45
|
});
|
|
51
46
|
}
|
|
52
|
-
handlerIdCardType(
|
|
53
|
-
|
|
47
|
+
handlerIdCardType() {
|
|
48
|
+
const idCard = this.getValueByType(FIELD_BUSINESS_TYPE.ID_CARD);
|
|
49
|
+
if (!idCard || !isString(idCard) || !isIdCard(idCard))
|
|
54
50
|
return;
|
|
55
|
-
const info = parseIdCard(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
const birthdayFields = this.getField(FIELD_BUSINESS_TYPE.BIRTHDAY);
|
|
64
|
-
birthdayFields.forEach((field) => {
|
|
65
|
-
formModel.setFieldState(field, (state) => {
|
|
66
|
-
state.value = this.valueFilter({ fieldKey: field, value: info.birthday, type: FIELD_BUSINESS_TYPE.BIRTHDAY });
|
|
67
|
-
});
|
|
68
|
-
});
|
|
51
|
+
const info = parseIdCard(idCard);
|
|
52
|
+
const { age, ageUnit } = parseAge2FromContext(info);
|
|
53
|
+
this.setValueByType(FIELD_BUSINESS_TYPE.AGE_UNIT, ageUnit);
|
|
54
|
+
this.setValueByType(FIELD_BUSINESS_TYPE.AGE, age);
|
|
55
|
+
this.setValueByType(FIELD_BUSINESS_TYPE.SEX, info.sex);
|
|
56
|
+
this.setValueByType(FIELD_BUSINESS_TYPE.BIRTHDAY, info.birthday);
|
|
69
57
|
}
|
|
70
|
-
handlerBirthdayType(
|
|
71
|
-
|
|
58
|
+
handlerBirthdayType() {
|
|
59
|
+
const birthday = this.getValueByType(FIELD_BUSINESS_TYPE.BIRTHDAY);
|
|
60
|
+
if (!isString(birthday))
|
|
72
61
|
return;
|
|
73
|
-
|
|
62
|
+
const { age, ageUnit } = parseAge2FromContext(parseBirthday(birthday));
|
|
63
|
+
this.setValueByType(FIELD_BUSINESS_TYPE.AGE_UNIT, ageUnit);
|
|
64
|
+
this.setValueByType(FIELD_BUSINESS_TYPE.AGE, age);
|
|
74
65
|
}
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
66
|
+
handlerAgeType() {
|
|
67
|
+
const age = this.getValueByType(FIELD_BUSINESS_TYPE.AGE);
|
|
68
|
+
const ageUnit = this.getValueByType(FIELD_BUSINESS_TYPE.AGE_UNIT);
|
|
69
|
+
if (!isString(age) && !isNumber(age) || age === "")
|
|
70
|
+
return;
|
|
71
|
+
if (!isString(ageUnit) || ageUnit === "")
|
|
78
72
|
return;
|
|
79
|
-
this.
|
|
73
|
+
this.setValueByType(FIELD_BUSINESS_TYPE.BIRTHDAY, parseAge2Birthday(+age, ageUnit), false);
|
|
74
|
+
}
|
|
75
|
+
trigger(fieldName, triggerType = "change") {
|
|
76
|
+
var _a;
|
|
77
|
+
const type = this.getType(fieldName);
|
|
78
|
+
const handler = triggerType === "change" ? this.handlerChangeMap : triggerType === "blur" ? this.blurHandlerMap : null;
|
|
79
|
+
type && ((_a = handler == null ? void 0 : handler.get(type)) == null ? void 0 : _a());
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
function useBusinessBinding() {
|
|
83
|
-
function create(
|
|
84
|
-
return new BusinessCollector(
|
|
83
|
+
function create(formModel) {
|
|
84
|
+
return new BusinessCollector(formModel);
|
|
85
85
|
}
|
|
86
86
|
return { create };
|
|
87
87
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { isObject } from '@vueuse/core';
|
|
2
2
|
import { pick } from 'lodash-es';
|
|
3
3
|
import { useFormValidator, useTypeNormalize } from '../../../../packages/form-render';
|
|
4
|
-
import {
|
|
4
|
+
import { arrayed, parseNumberFromMaybeString } from '../utils/index.js';
|
|
5
|
+
import { fieldKeyEscape, createLinebarId, elementIdEscape } from '../utils/schema.js';
|
|
6
|
+
import { transformDateFormat } from '../utils/business.js';
|
|
5
7
|
|
|
6
8
|
function useFieldListAdaptor(collector, uuid) {
|
|
7
9
|
const { createValidatorSchema } = useFormValidator();
|
|
@@ -15,7 +17,12 @@ function useFieldListAdaptor(collector, uuid) {
|
|
|
15
17
|
"x-component-props": {
|
|
16
18
|
placeholder: item.placeholder,
|
|
17
19
|
clearable: item.is_empty === "0",
|
|
18
|
-
...item.componentProps || {}
|
|
20
|
+
...item.componentProps || {},
|
|
21
|
+
onBlur(...args) {
|
|
22
|
+
var _a2;
|
|
23
|
+
collector.trigger(item.val_key, "blur");
|
|
24
|
+
(_a2 = item.componentProps) == null ? void 0 : _a2.onBlur(...args);
|
|
25
|
+
}
|
|
19
26
|
},
|
|
20
27
|
"x-display": item.is_show === "0" ? "hidden" : "visible",
|
|
21
28
|
"x-pattern": item.is_edit === "0" ? "disabled" : "editable"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Form } from '@formily/core';
|
|
1
2
|
import { ShallowReactive } from 'vue';
|
|
2
3
|
import { FormRenderProps } from '../../../../../es/packages/form-render';
|
|
3
|
-
export declare function useFormContext(props: ShallowReactive<FormRenderProps
|
|
4
|
+
export declare function useFormContext(props: ShallowReactive<FormRenderProps>, formModel: Form): {
|
|
4
5
|
asyncQueue: import("../../../../../es/packages/form-render").FormAsyncQueue;
|
|
5
6
|
SchemaField: import("vue").Component<any, any, any, import("vue").ComputedOptions, import("vue").MethodOptions>;
|
|
6
7
|
businessCollector: import("../../../../../es/packages/form-render").BusinessCollector;
|
|
@@ -9,7 +9,7 @@ import { usePresetScope } from '../../../../packages/form-render/src/hooks/usePr
|
|
|
9
9
|
import { injectOrProvide, uuidGenerator } from '../../../../packages/form-render/src/utils';
|
|
10
10
|
import { InjectAsyncQueue, InjectionSchemaField, InjectionBusinessCollector, InjectionChangeContextCollector, InjectionFormItemDepsCollector, InjectionFormUUID, InjectionAnnotation } from '../../../../packages/form-render/src/constants';
|
|
11
11
|
|
|
12
|
-
function useFormContext(props) {
|
|
12
|
+
function useFormContext(props, formModel) {
|
|
13
13
|
const { callLifeCycle } = useFormRenderLifeCycle(props);
|
|
14
14
|
const asyncQueue = injectOrProvide(InjectAsyncQueue, () => useAsyncQueue().create(props.parallelism, {
|
|
15
15
|
beforeRequest(...args) {
|
|
@@ -34,7 +34,7 @@ function useFormContext(props) {
|
|
|
34
34
|
},
|
|
35
35
|
scope: Object.assign({}, usePresetScope(), props.scope)
|
|
36
36
|
}).SchemaField);
|
|
37
|
-
const businessCollector = useBusinessBinding().create(
|
|
37
|
+
const businessCollector = useBusinessBinding().create(formModel);
|
|
38
38
|
provide(InjectionBusinessCollector, businessCollector);
|
|
39
39
|
const changeContextCollector = useChangeContext().create();
|
|
40
40
|
provide(InjectionChangeContextCollector, changeContextCollector);
|
|
@@ -24,7 +24,7 @@ function useTypeNormalize() {
|
|
|
24
24
|
];
|
|
25
25
|
function normalize(item) {
|
|
26
26
|
const type = item.html_type;
|
|
27
|
-
if (["
|
|
27
|
+
if (["CHECKBOX_BLOCK", "RADIO_BLOCK"].includes(type)) {
|
|
28
28
|
item.__vertical = true;
|
|
29
29
|
}
|
|
30
30
|
if (["LINE_BREAKS"].includes(type)) {
|
|
@@ -2,7 +2,6 @@ import { AnyObject, WithUndefined } from '../../../../../es/src/types';
|
|
|
2
2
|
import { DataField, Field } from '@formily/core';
|
|
3
3
|
import { ISchema } from '@formily/json-schema/esm/types';
|
|
4
4
|
import { Component, FunctionalComponent } from 'vue';
|
|
5
|
-
import { FIELD_BUSINESS_TYPE } from '../../../../../es/packages/form-render/src/constants';
|
|
6
5
|
import { FieldItem } from '../types';
|
|
7
6
|
import { AsyncQueue } from '../hooks';
|
|
8
7
|
export * from './fieldItem';
|
|
@@ -45,12 +44,6 @@ export declare type FormChangePayload = {
|
|
|
45
44
|
fieldInstance: DataField;
|
|
46
45
|
context: FormChangeContext;
|
|
47
46
|
};
|
|
48
|
-
export declare type FormBusinessFilter = (payload: {
|
|
49
|
-
fieldKey: string;
|
|
50
|
-
value: unknown;
|
|
51
|
-
type: FIELD_BUSINESS_TYPE;
|
|
52
|
-
context?: any;
|
|
53
|
-
}) => unknown;
|
|
54
47
|
export declare type DependKeyType = string | Record<string, string> | Array<{
|
|
55
48
|
paramName: string;
|
|
56
49
|
paramValue?: string;
|
|
@@ -71,7 +64,6 @@ export declare type FormRenderProps = Partial<{
|
|
|
71
64
|
parallelism: number;
|
|
72
65
|
schema: ISchema;
|
|
73
66
|
components: Record<string, Component | FunctionalComponent>;
|
|
74
|
-
businessFilter: FormBusinessFilter;
|
|
75
67
|
scope: AnyObject;
|
|
76
68
|
annotation: AnyObject;
|
|
77
69
|
consumer: boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AgeContext, IdCardParseInfo } from '../../../../../es/packages/form-render';
|
|
2
|
+
import { FIELD_AGE_UNIT } from '../../../../../es/packages/form-render/src/constants';
|
|
3
|
+
export declare function parseIdCard(idCardNo: string): IdCardParseInfo;
|
|
4
|
+
export declare function transformDateFormat(format?: string): "date" | "datetime" | "month";
|
|
5
|
+
export declare function isIdCard(idCardNo: string): boolean;
|
|
6
|
+
export declare function isMobile(mobile: string): boolean;
|
|
7
|
+
export declare function parseBirthday(birthday: string): AgeContext;
|
|
8
|
+
export declare function parseAge2Birthday(age: number, ageUnit: string, formatter?: string): string;
|
|
9
|
+
export declare function parseAge2FromContext(context: AgeContext): {
|
|
10
|
+
ageUnit: FIELD_AGE_UNIT;
|
|
11
|
+
age: number;
|
|
12
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { differenceInDays, differenceInMonths, differenceInYears, format } from 'date-fns';
|
|
2
|
+
import { FIELD_AGE_UNIT, FIELD_SEX_VALUE } from '../../../../packages/form-render/src/constants';
|
|
3
|
+
|
|
4
|
+
function parseIdCard(idCardNo) {
|
|
5
|
+
const parseInner = (certificateNo, idxSexStart, birthYearSpan) => {
|
|
6
|
+
const res = {};
|
|
7
|
+
const idxSex = 1 - certificateNo.substr(idxSexStart, 1) % 2;
|
|
8
|
+
res.sex = idxSex === 1 ? FIELD_SEX_VALUE.FEMALE : FIELD_SEX_VALUE.MALE;
|
|
9
|
+
const year = (birthYearSpan == 2 ? "19" : "") + certificateNo.substr(6, birthYearSpan);
|
|
10
|
+
const month = certificateNo.substr(6 + birthYearSpan, 2);
|
|
11
|
+
const day = certificateNo.substr(8 + birthYearSpan, 2);
|
|
12
|
+
res.birthday = year + "-" + month + "-" + day;
|
|
13
|
+
const d = new Date();
|
|
14
|
+
const monthFloor = d.getMonth() + 1 < parseInt(month, 10) || d.getMonth() + 1 == parseInt(month, 10) && d.getDate() < parseInt(day, 10) ? 1 : 0;
|
|
15
|
+
Object.assign(res, parseBirthday(res.birthday));
|
|
16
|
+
res.age = res.year = d.getFullYear() - parseInt(year, 10) - monthFloor;
|
|
17
|
+
return res;
|
|
18
|
+
};
|
|
19
|
+
return parseInner(idCardNo, idCardNo.length == 15 ? 14 : 16, idCardNo.length == 15 ? 2 : 4);
|
|
20
|
+
}
|
|
21
|
+
function isMonthType(format2) {
|
|
22
|
+
return format2 && format2.replace(/yyyy-MM/gi, "YYYY-MM") === "YYYY-MM";
|
|
23
|
+
}
|
|
24
|
+
function transformDateFormat(format2 = "") {
|
|
25
|
+
if (isMonthType(format2))
|
|
26
|
+
return "month";
|
|
27
|
+
return format2.includes("HH") ? "datetime" : "date";
|
|
28
|
+
}
|
|
29
|
+
function isIdCard(idCardNo) {
|
|
30
|
+
return /^\d{6}(((19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[0-1])\d{3}(\d|x|X))|(\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[0-1])\d{3}))$/.test(idCardNo);
|
|
31
|
+
}
|
|
32
|
+
function isMobile(mobile) {
|
|
33
|
+
return /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/.test(mobile);
|
|
34
|
+
}
|
|
35
|
+
function parseBirthday(birthday) {
|
|
36
|
+
const result = {};
|
|
37
|
+
const d = new Date();
|
|
38
|
+
const birthDate = new Date(birthday);
|
|
39
|
+
result.day = differenceInDays(d, birthDate);
|
|
40
|
+
result.month = differenceInMonths(d, birthDate);
|
|
41
|
+
result.age = result.year = differenceInYears(d, birthDate);
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
function parseAge2Birthday(age, ageUnit, formatter = "yyyy-MM-dd") {
|
|
45
|
+
var _a;
|
|
46
|
+
const result = new Date();
|
|
47
|
+
const handlerMap = {
|
|
48
|
+
[FIELD_AGE_UNIT.MINUTE]: () => decreaseDate(result, "Minute", age),
|
|
49
|
+
[FIELD_AGE_UNIT.HOUR]: () => decreaseDate(result, "Hour", age),
|
|
50
|
+
[FIELD_AGE_UNIT.DAY]: () => decreaseDate(result, "Date", age),
|
|
51
|
+
[FIELD_AGE_UNIT.WEEK]: () => decreaseDate(result, "Date", age * 7),
|
|
52
|
+
[FIELD_AGE_UNIT.MONTH]: () => decreaseDate(result, "Month", age),
|
|
53
|
+
[FIELD_AGE_UNIT.YEAR]: () => decreaseDate(result, "FullYear", age)
|
|
54
|
+
};
|
|
55
|
+
(_a = handlerMap[ageUnit]) == null ? void 0 : _a.call(handlerMap);
|
|
56
|
+
return format(result, formatter);
|
|
57
|
+
function decreaseDate(date, type, num) {
|
|
58
|
+
date[`set${type}`](date[`get${type}`]() - num);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function parseAge2FromContext(context) {
|
|
62
|
+
return context.day < 30 ? { ageUnit: FIELD_AGE_UNIT.DAY, age: context.day } : context.day < 365 ? { ageUnit: FIELD_AGE_UNIT.MONTH, age: context.month } : { ageUnit: FIELD_AGE_UNIT.YEAR, age: context.year };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { isIdCard, isMobile, parseAge2Birthday, parseAge2FromContext, parseBirthday, parseIdCard, transformDateFormat };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WithNull } from '../../../../../es/src/types';
|
|
2
|
+
export declare function queryDecorator(key: string, wrapperElement: HTMLElement, formUUID: string): HTMLElement | null;
|
|
3
|
+
export declare function queryInput(decoratorElement?: WithNull<HTMLElement>): {
|
|
4
|
+
widgetElement: HTMLInputElement | null | undefined;
|
|
5
|
+
widgetElementList: HTMLInputElement[];
|
|
6
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { elementIdEscape } from '../../../../packages/form-render/src/utils/schema';
|
|
2
|
+
|
|
3
|
+
function queryDecorator(key, wrapperElement, formUUID) {
|
|
4
|
+
return wrapperElement.querySelector(elementIdEscape(`#${formUUID}-${key}`));
|
|
5
|
+
}
|
|
6
|
+
function queryInput(decoratorElement) {
|
|
7
|
+
var _a;
|
|
8
|
+
return {
|
|
9
|
+
widgetElement: decoratorElement == null ? void 0 : decoratorElement.querySelector("input"),
|
|
10
|
+
widgetElementList: Array.from((_a = decoratorElement == null ? void 0 : decoratorElement.querySelectorAll("input")) != null ? _a : [])
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { queryDecorator, queryInput };
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
-
import { AnyObject, ArrayAble
|
|
2
|
-
import { ISchema } from '@formily/json-schema/esm/types';
|
|
3
|
-
import { GeneralField } from '@formily/core';
|
|
1
|
+
import { AnyObject, ArrayAble } from '../../../../../es/src/types';
|
|
4
2
|
import { FunctionalComponent, InjectionKey, VNode } from 'vue';
|
|
5
|
-
import {
|
|
3
|
+
import { FieldItem } from '../types';
|
|
4
|
+
export * from './business';
|
|
5
|
+
export * from './dom';
|
|
6
|
+
export * from './schema';
|
|
6
7
|
export declare function formRenderLog(message: string, type?: keyof Console): void;
|
|
7
8
|
export declare function arrayed<T>(maybeArray: T): T extends Array<any> ? T : [T];
|
|
8
|
-
export declare function assignUpdateValue(props: AnyObject, field: GeneralField): {
|
|
9
|
-
[x: string]: any;
|
|
10
|
-
};
|
|
11
|
-
export declare function transformDateFormat(format?: string): "date" | "datetime" | "month";
|
|
12
|
-
export declare function isIdCard(idCardNo: string): boolean;
|
|
13
|
-
export declare function isMobile(mobile: string): boolean;
|
|
14
|
-
export declare function parseBirthday(birthday: string): AgeContext;
|
|
15
9
|
export declare function mergeDeepProperties(target: AnyObject, fieldList: FieldItem[], traverseProperties?: string[], property?: string, targetProperty?: string): AnyObject;
|
|
16
|
-
export declare function parseIdCard(idCardNo: string): IdCardParseInfo;
|
|
17
10
|
export declare function injectOrProvide<T>(key: InjectionKey<T>, creator: () => T): T;
|
|
18
11
|
export declare function parseNumberFromMaybeString(value: unknown): unknown;
|
|
19
|
-
export declare function traverseDependKey(dependKeys: DependKeyType, handler: {
|
|
20
|
-
(dependKey: string, valueKey: string, required?: boolean): void;
|
|
21
|
-
}): void;
|
|
22
|
-
export declare function traverseSchema(schema: ISchema, handler: (_s: ISchema) => void): void;
|
|
23
12
|
export declare function uuidGenerator(): string;
|
|
24
13
|
export declare function createSlot(renderer: unknown, props: AnyObject): Record<string, () => ArrayAble<VNode>> | {
|
|
25
14
|
default(): any;
|
|
26
15
|
};
|
|
27
|
-
export declare function queryDecorator(key: string, wrapperElement: HTMLElement, formUUID: string): HTMLElement | null;
|
|
28
|
-
export declare function queryInput(decoratorElement?: WithNull<HTMLElement>): {
|
|
29
|
-
widgetElement: HTMLInputElement | null | undefined;
|
|
30
|
-
widgetElementList: HTMLInputElement[];
|
|
31
|
-
};
|
|
32
|
-
export declare function getParentLinebar(key: string, fieldList: FieldItem[]): WithNull<string>;
|
|
33
|
-
export declare function elementIdEscape(id: string): string;
|
|
34
|
-
export declare function createLinebarId(id: string): string;
|
|
35
|
-
export declare function fieldKeyEscape(fieldList: FieldItem[]): string;
|
|
36
16
|
export declare function createInputSlot(props: AnyObject): import("vue").ComputedRef<Record<string, FunctionalComponent<{}, {}>>>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { inject, provide, computed, createVNode, Fragment } from 'vue';
|
|
2
2
|
import { isObject } from '@vue/shared';
|
|
3
|
-
import { isNumber, isString,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { isNumber, isString, isFunction } from 'lodash-es';
|
|
4
|
+
export { isIdCard, isMobile, parseAge2Birthday, parseAge2FromContext, parseBirthday, parseIdCard, transformDateFormat } from './business.js';
|
|
5
|
+
export { queryDecorator, queryInput } from './dom.js';
|
|
6
|
+
export { assignUpdateValue, createLinebarId, elementIdEscape, fieldKeyEscape, getParentLinebar, traverseDependKey, traverseSchema } from './schema.js';
|
|
7
7
|
|
|
8
8
|
function formRenderLog(message, type = "log") {
|
|
9
9
|
console[type](`[FormRender]: ${message}`);
|
|
@@ -13,42 +13,6 @@ function arrayed(maybeArray) {
|
|
|
13
13
|
return maybeArray;
|
|
14
14
|
return [maybeArray];
|
|
15
15
|
}
|
|
16
|
-
function assignUpdateValue(props, field) {
|
|
17
|
-
const _props = {
|
|
18
|
-
...props
|
|
19
|
-
};
|
|
20
|
-
if (isField(field)) {
|
|
21
|
-
Object.assign(_props, {
|
|
22
|
-
"onUpdate:value"(value) {
|
|
23
|
-
field.setValue(value);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return _props;
|
|
28
|
-
}
|
|
29
|
-
function isMonthType(format) {
|
|
30
|
-
return format && format.replace(/yyyy-MM/gi, "YYYY-MM") === "YYYY-MM";
|
|
31
|
-
}
|
|
32
|
-
function transformDateFormat(format = "") {
|
|
33
|
-
if (isMonthType(format))
|
|
34
|
-
return "month";
|
|
35
|
-
return format.includes("HH") ? "datetime" : "date";
|
|
36
|
-
}
|
|
37
|
-
function isIdCard(idCardNo) {
|
|
38
|
-
return /^\d{6}(((19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[0-1])\d{3}(\d|x|X))|(\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[0-1])\d{3}))$/.test(idCardNo);
|
|
39
|
-
}
|
|
40
|
-
function isMobile(mobile) {
|
|
41
|
-
return /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/.test(mobile);
|
|
42
|
-
}
|
|
43
|
-
function parseBirthday(birthday) {
|
|
44
|
-
const result = {};
|
|
45
|
-
const d = new Date();
|
|
46
|
-
const birthDate = new Date(birthday);
|
|
47
|
-
result.day = differenceInDays(d, birthDate);
|
|
48
|
-
result.month = differenceInMonths(d, birthDate);
|
|
49
|
-
result.age = result.year = differenceInYears(d, birthDate);
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
16
|
function mergeDeepProperties(target, fieldList, traverseProperties = ["children", "properties", "suffixConfig"], property = "val_key", targetProperty = "default_val") {
|
|
53
17
|
function traverse(_target, _fieldList) {
|
|
54
18
|
_fieldList.forEach((field) => {
|
|
@@ -76,23 +40,6 @@ function mergeDeepProperties(target, fieldList, traverseProperties = ["children"
|
|
|
76
40
|
return field[targetProperty];
|
|
77
41
|
}
|
|
78
42
|
}
|
|
79
|
-
function parseIdCard(idCardNo) {
|
|
80
|
-
const parseInner = (certificateNo, idxSexStart, birthYearSpan) => {
|
|
81
|
-
const res = {};
|
|
82
|
-
const idxSex = 1 - certificateNo.substr(idxSexStart, 1) % 2;
|
|
83
|
-
res.sex = idxSex === 1 ? FIELD_SEX_VALUE.FEMALE : FIELD_SEX_VALUE.MALE;
|
|
84
|
-
const year = (birthYearSpan == 2 ? "19" : "") + certificateNo.substr(6, birthYearSpan);
|
|
85
|
-
const month = certificateNo.substr(6 + birthYearSpan, 2);
|
|
86
|
-
const day = certificateNo.substr(8 + birthYearSpan, 2);
|
|
87
|
-
res.birthday = year + "-" + month + "-" + day;
|
|
88
|
-
const d = new Date();
|
|
89
|
-
const monthFloor = d.getMonth() + 1 < parseInt(month, 10) || d.getMonth() + 1 == parseInt(month, 10) && d.getDate() < parseInt(day, 10) ? 1 : 0;
|
|
90
|
-
Object.assign(res, parseBirthday(res.birthday));
|
|
91
|
-
res.age = res.year = d.getFullYear() - parseInt(year, 10) - monthFloor;
|
|
92
|
-
return res;
|
|
93
|
-
};
|
|
94
|
-
return parseInner(idCardNo, idCardNo.length == 15 ? 14 : 16, idCardNo.length == 15 ? 2 : 4);
|
|
95
|
-
}
|
|
96
43
|
function injectOrProvide(key, creator) {
|
|
97
44
|
let injected = inject(key, null);
|
|
98
45
|
if (!injected) {
|
|
@@ -108,49 +55,6 @@ function parseNumberFromMaybeString(value) {
|
|
|
108
55
|
return +value;
|
|
109
56
|
return value;
|
|
110
57
|
}
|
|
111
|
-
function traverseDependKey(dependKeys, handler) {
|
|
112
|
-
if (!dependKeys)
|
|
113
|
-
return;
|
|
114
|
-
createDependKeyMap().forEach((valueKey, dependKey) => {
|
|
115
|
-
if (isString(valueKey))
|
|
116
|
-
return handler(dependKey, valueKey);
|
|
117
|
-
handler(dependKey, valueKey.key, valueKey.required);
|
|
118
|
-
});
|
|
119
|
-
Object.entries(createDependKeyMap()).forEach(([dependKey, valueKey]) => {
|
|
120
|
-
handler(dependKey, valueKey);
|
|
121
|
-
});
|
|
122
|
-
function createDependKeyMap() {
|
|
123
|
-
const result = /* @__PURE__ */ new Map();
|
|
124
|
-
if (isArray(dependKeys)) {
|
|
125
|
-
dependKeys.forEach((k) => {
|
|
126
|
-
var _a;
|
|
127
|
-
if (isObject(k)) {
|
|
128
|
-
result.set(k.paramName, {
|
|
129
|
-
key: (_a = k.paramName) != null ? _a : k.paramValue,
|
|
130
|
-
required: k.required
|
|
131
|
-
});
|
|
132
|
-
} else {
|
|
133
|
-
result.set(k, k);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
} else if (isObject(dependKeys)) {
|
|
137
|
-
Object.entries(dependKeys).forEach(([k, v]) => {
|
|
138
|
-
result.set(k, v);
|
|
139
|
-
});
|
|
140
|
-
} else if (isString(dependKeys)) {
|
|
141
|
-
result.set(dependKeys, dependKeys);
|
|
142
|
-
}
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function traverseSchema(schema, handler) {
|
|
147
|
-
handler(schema);
|
|
148
|
-
if (isObject(schema.properties)) {
|
|
149
|
-
Object.values(schema.properties).forEach((_s) => {
|
|
150
|
-
traverseSchema(_s, handler);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
58
|
function uuidGenerator() {
|
|
155
59
|
return "key" + "xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
156
60
|
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
@@ -171,42 +75,6 @@ function createSlot(renderer, props) {
|
|
|
171
75
|
}
|
|
172
76
|
};
|
|
173
77
|
}
|
|
174
|
-
function queryDecorator(key, wrapperElement, formUUID) {
|
|
175
|
-
return wrapperElement.querySelector(elementIdEscape(`#${formUUID}-${key}`));
|
|
176
|
-
}
|
|
177
|
-
function queryInput(decoratorElement) {
|
|
178
|
-
var _a;
|
|
179
|
-
return {
|
|
180
|
-
widgetElement: decoratorElement == null ? void 0 : decoratorElement.querySelector("input"),
|
|
181
|
-
widgetElementList: Array.from((_a = decoratorElement == null ? void 0 : decoratorElement.querySelectorAll("input")) != null ? _a : [])
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function getParentLinebar(key, fieldList) {
|
|
185
|
-
let result = null;
|
|
186
|
-
for (const fieldItem of fieldList) {
|
|
187
|
-
if (fieldItem.val_key === key) {
|
|
188
|
-
if (isLinebar(fieldItem))
|
|
189
|
-
result = null;
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
if (isLinebar(fieldItem)) {
|
|
193
|
-
result = fieldItem.val_key;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return result;
|
|
197
|
-
function isLinebar(field) {
|
|
198
|
-
return field.html_type === "LINEBAR";
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function elementIdEscape(id) {
|
|
202
|
-
return id.replace(".", "-");
|
|
203
|
-
}
|
|
204
|
-
function createLinebarId(id) {
|
|
205
|
-
return elementIdEscape(`id-${id}`);
|
|
206
|
-
}
|
|
207
|
-
function fieldKeyEscape(fieldList) {
|
|
208
|
-
return fieldList.map((f) => f.val_key).join("-").replace(/[.]/g, "_");
|
|
209
|
-
}
|
|
210
78
|
function createInputSlot(props) {
|
|
211
79
|
return computed(() => {
|
|
212
80
|
const res = {};
|
|
@@ -220,4 +88,4 @@ function createInputSlot(props) {
|
|
|
220
88
|
});
|
|
221
89
|
}
|
|
222
90
|
|
|
223
|
-
export { arrayed,
|
|
91
|
+
export { arrayed, createInputSlot, createSlot, formRenderLog, injectOrProvide, mergeDeepProperties, parseNumberFromMaybeString, uuidGenerator };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AnyObject, WithNull } from '../../../../../es/src/types';
|
|
2
|
+
import { GeneralField } from '@formily/core';
|
|
3
|
+
import { ISchema } from '@formily/json-schema/esm/types';
|
|
4
|
+
import { DependKeyType, FieldItem } from '../../../../../es/packages/form-render';
|
|
5
|
+
export declare function traverseSchema(schema: ISchema, handler: (_s: ISchema) => void): void;
|
|
6
|
+
export declare function fieldKeyEscape(fieldList: FieldItem[]): string;
|
|
7
|
+
export declare function elementIdEscape(id: string): string;
|
|
8
|
+
export declare function createLinebarId(id: string): string;
|
|
9
|
+
export declare function traverseDependKey(dependKeys: DependKeyType, handler: {
|
|
10
|
+
(dependKey: string, valueKey: string, required?: boolean): void;
|
|
11
|
+
}): void;
|
|
12
|
+
export declare function getParentLinebar(key: string, fieldList: FieldItem[]): WithNull<string>;
|
|
13
|
+
export declare function assignUpdateValue(props: AnyObject, field: GeneralField): {
|
|
14
|
+
[x: string]: any;
|
|
15
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { isField } from '@formily/core';
|
|
2
|
+
import { isObject } from '@vue/shared';
|
|
3
|
+
import { isString, isArray } from 'lodash-es';
|
|
4
|
+
|
|
5
|
+
function traverseSchema(schema, handler) {
|
|
6
|
+
handler(schema);
|
|
7
|
+
if (isObject(schema.properties)) {
|
|
8
|
+
Object.values(schema.properties).forEach((_s) => {
|
|
9
|
+
traverseSchema(_s, handler);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function fieldKeyEscape(fieldList) {
|
|
14
|
+
return fieldList.map((f) => f.val_key).join("-").replace(/[.]/g, "_");
|
|
15
|
+
}
|
|
16
|
+
function elementIdEscape(id) {
|
|
17
|
+
return id.replace(".", "-");
|
|
18
|
+
}
|
|
19
|
+
function createLinebarId(id) {
|
|
20
|
+
return elementIdEscape(`id-${id}`);
|
|
21
|
+
}
|
|
22
|
+
function traverseDependKey(dependKeys, handler) {
|
|
23
|
+
if (!dependKeys)
|
|
24
|
+
return;
|
|
25
|
+
createDependKeyMap().forEach((valueKey, dependKey) => {
|
|
26
|
+
if (isString(valueKey))
|
|
27
|
+
return handler(dependKey, valueKey);
|
|
28
|
+
handler(dependKey, valueKey.key, valueKey.required);
|
|
29
|
+
});
|
|
30
|
+
Object.entries(createDependKeyMap()).forEach(([dependKey, valueKey]) => {
|
|
31
|
+
handler(dependKey, valueKey);
|
|
32
|
+
});
|
|
33
|
+
function createDependKeyMap() {
|
|
34
|
+
const result = /* @__PURE__ */ new Map();
|
|
35
|
+
if (isArray(dependKeys)) {
|
|
36
|
+
dependKeys.forEach((k) => {
|
|
37
|
+
var _a;
|
|
38
|
+
if (isObject(k)) {
|
|
39
|
+
result.set(k.paramName, { key: (_a = k.paramName) != null ? _a : k.paramValue, required: k.required });
|
|
40
|
+
} else {
|
|
41
|
+
result.set(k, k);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
} else if (isObject(dependKeys)) {
|
|
45
|
+
Object.entries(dependKeys).forEach(([k, v]) => {
|
|
46
|
+
result.set(k, v);
|
|
47
|
+
});
|
|
48
|
+
} else if (isString(dependKeys)) {
|
|
49
|
+
result.set(dependKeys, dependKeys);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function getParentLinebar(key, fieldList) {
|
|
55
|
+
let result = null;
|
|
56
|
+
for (const fieldItem of fieldList) {
|
|
57
|
+
if (fieldItem.val_key === key) {
|
|
58
|
+
if (isLinebar(fieldItem))
|
|
59
|
+
result = null;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
if (isLinebar(fieldItem)) {
|
|
63
|
+
result = fieldItem.val_key;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
function isLinebar(field) {
|
|
68
|
+
return field.html_type === "LINEBAR";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function assignUpdateValue(props, field) {
|
|
72
|
+
const _props = { ...props };
|
|
73
|
+
if (isField(field)) {
|
|
74
|
+
Object.assign(_props, {
|
|
75
|
+
"onUpdate:value"(value) {
|
|
76
|
+
field.setValue(value);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return _props;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { assignUpdateValue, createLinebarId, elementIdEscape, fieldKeyEscape, getParentLinebar, traverseDependKey, traverseSchema };
|