orion-design 0.1.31 → 0.1.32
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -5
- package/dist/Throne/index.js +14 -30
- package/dist/Throne/index.js.map +1 -1
- package/dist/components/Button/index.js +33 -40
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/Flex/index.js +89 -122
- package/dist/components/Flex/index.js.map +1 -1
- package/dist/components/Form/Form.js +2 -2
- package/dist/components/Form/Form.js.map +1 -1
- package/dist/components/Form/LovInput/LovInput.js +2 -2
- package/dist/components/Form/LovInput/LovInput.js.map +1 -1
- package/dist/components/Form/LovInput/hooks/useLov.js +5 -5
- package/dist/components/Form/LovInput/hooks/useLov.js.map +1 -1
- package/dist/components/Form/LovInput/index.js +4 -4
- package/dist/components/Form/hooks/FormItemValidateTrigger.js +2 -2
- package/dist/components/Form/hooks/FormItemValidateTrigger.js.map +1 -1
- package/dist/components/Form/hooks/index.js +68 -127
- package/dist/components/Form/hooks/index.js.map +1 -1
- package/dist/components/Form/index.js +656 -836
- package/dist/components/Form/index.js.map +1 -1
- package/dist/components/Form/utils/index.js +18 -30
- package/dist/components/Form/utils/index.js.map +1 -1
- package/dist/components/LovTable/LovPagetable.vue.d.ts +492 -0
- package/dist/components/LovTable/index.d.ts +246 -0
- package/dist/components/LovTable/index.js +106 -179
- package/dist/components/LovTable/index.js.map +1 -1
- package/dist/components/Modal/index.js +56 -111
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Modal/types.d.ts +1 -1
- package/dist/components/Modal/types.js +3 -4
- package/dist/components/Modal/types.js.map +1 -1
- package/dist/components/Modal/useModal.js +5 -5
- package/dist/components/Modal/useModal.js.map +1 -1
- package/dist/components/Pagetable/Pagetable.d.ts +92 -1
- package/dist/components/Pagetable/columns/PagetableColumnButtongroup.d.ts +13 -0
- package/dist/components/Pagetable/columns/PagetableColumnDate.d.ts +13 -0
- package/dist/components/Pagetable/columns/PagetableColumnLink.d.ts +13 -0
- package/dist/components/Pagetable/columns/PagetableColumnMultiselect.d.ts +13 -0
- package/dist/components/Pagetable/columns/PagetableColumnNumber.d.ts +13 -0
- package/dist/components/Pagetable/columns/PagetableColumnSingleselect.d.ts +13 -0
- package/dist/components/Pagetable/columns/PagetableColumnString.d.ts +13 -0
- package/dist/components/Pagetable/hooks/useColumns.js +85 -88
- package/dist/components/Pagetable/hooks/useColumns.js.map +1 -1
- package/dist/components/Pagetable/index.d.ts +155 -0
- package/dist/components/Pagetable/index.js +596 -683
- package/dist/components/Pagetable/index.js.map +1 -1
- package/dist/components/Pagetable/utils/index.js +54 -92
- package/dist/components/Pagetable/utils/index.js.map +1 -1
- package/dist/components/Querytable/hooks/useColumns.js +74 -82
- package/dist/components/Querytable/hooks/useColumns.js.map +1 -1
- package/dist/components/Querytable/index.js +469 -579
- package/dist/components/Querytable/index.js.map +1 -1
- package/dist/components/Querytable/utils/index.js +54 -92
- package/dist/components/Querytable/utils/index.js.map +1 -1
- package/dist/components/RichTextEditor/index.js +74 -100
- package/dist/components/RichTextEditor/index.js.map +1 -1
- package/dist/components/Tabs/constants.js +2 -2
- package/dist/components/Tabs/constants.js.map +1 -1
- package/dist/components/Tabs/index.js +358 -603
- package/dist/components/Tabs/index.js.map +1 -1
- package/dist/components/Tabs/tab-bar.js +6 -6
- package/dist/components/Tabs/tab-bar.js.map +1 -1
- package/dist/components/Tabs/tab-pane.js +3 -3
- package/dist/components/Tabs/tab-pane.js.map +1 -1
- package/dist/components/_constants/aria.js +2 -2
- package/dist/components/_constants/aria.js.map +1 -1
- package/dist/components/_constants/event.js +4 -6
- package/dist/components/_constants/event.js.map +1 -1
- package/dist/components/_constants/index.js +6 -6
- package/dist/components/_hooks/index.js +7 -7
- package/dist/components/_hooks/use-namespace/index.js +39 -74
- package/dist/components/_hooks/use-namespace/index.js.map +1 -1
- package/dist/components/_hooks/use-ordered-children/index.js +19 -29
- package/dist/components/_hooks/use-ordered-children/index.js.map +1 -1
- package/dist/components/_util/arrays.js +5 -9
- package/dist/components/_util/arrays.js.map +1 -1
- package/dist/components/_util/browser.js +6 -6
- package/dist/components/_util/browser.js.map +1 -1
- package/dist/components/_util/classNames.js +17 -22
- package/dist/components/_util/classNames.js.map +1 -1
- package/dist/components/_util/dom/aria.js +39 -74
- package/dist/components/_util/dom/aria.js.map +1 -1
- package/dist/components/_util/dom/element.js +8 -9
- package/dist/components/_util/dom/element.js.map +1 -1
- package/dist/components/_util/dom/event.js +7 -14
- package/dist/components/_util/dom/event.js.map +1 -1
- package/dist/components/_util/dom/index.js +36 -36
- package/dist/components/_util/dom/position.js +25 -49
- package/dist/components/_util/dom/position.js.map +1 -1
- package/dist/components/_util/dom/scroll.js +61 -103
- package/dist/components/_util/dom/scroll.js.map +1 -1
- package/dist/components/_util/dom/style.js +50 -65
- package/dist/components/_util/dom/style.js.map +1 -1
- package/dist/components/_util/easings.js +4 -8
- package/dist/components/_util/easings.js.map +1 -1
- package/dist/components/_util/error.js +11 -12
- package/dist/components/_util/error.js.map +1 -1
- package/dist/components/_util/functions.js +3 -3
- package/dist/components/_util/i18n.js +2 -2
- package/dist/components/_util/i18n.js.map +1 -1
- package/dist/components/_util/index.js +137 -137
- package/dist/components/_util/isValid.js +2 -4
- package/dist/components/_util/isValid.js.map +1 -1
- package/dist/components/_util/objects.js +14 -18
- package/dist/components/_util/objects.js.map +1 -1
- package/dist/components/_util/props-util/index.js +20 -46
- package/dist/components/_util/props-util/index.js.map +1 -1
- package/dist/components/_util/props-util/initDefaultProps.js +10 -18
- package/dist/components/_util/props-util/initDefaultProps.js.map +1 -1
- package/dist/components/_util/raf.js +4 -5
- package/dist/components/_util/raf.js.map +1 -1
- package/dist/components/_util/rand.js +3 -4
- package/dist/components/_util/rand.js.map +1 -1
- package/dist/components/_util/strings.js +8 -9
- package/dist/components/_util/strings.js.map +1 -1
- package/dist/components/_util/throttleByRaf.js +10 -16
- package/dist/components/_util/throttleByRaf.js.map +1 -1
- package/dist/components/_util/type.js +38 -41
- package/dist/components/_util/type.js.map +1 -1
- package/dist/components/_util/types.js +22 -41
- package/dist/components/_util/types.js.map +1 -1
- package/dist/components/_util/typescript.js +2 -2
- package/dist/components/_util/typescript.js.map +1 -1
- package/dist/components/_util/util.js +43 -85
- package/dist/components/_util/util.js.map +1 -1
- package/dist/components/_util/vue/global-node.js +15 -27
- package/dist/components/_util/vue/global-node.js.map +1 -1
- package/dist/components/_util/vue/icon.js +25 -29
- package/dist/components/_util/vue/icon.js.map +1 -1
- package/dist/components/_util/vue/index.js +41 -41
- package/dist/components/_util/vue/install.js +18 -35
- package/dist/components/_util/vue/install.js.map +1 -1
- package/dist/components/_util/vue/props/index.js +6 -6
- package/dist/components/_util/vue/props/runtime.js +30 -46
- package/dist/components/_util/vue/props/runtime.js.map +1 -1
- package/dist/components/_util/vue/refs.js +6 -12
- package/dist/components/_util/vue/refs.js.map +1 -1
- package/dist/components/_util/vue/size.js +3 -5
- package/dist/components/_util/vue/size.js.map +1 -1
- package/dist/components/_util/vue/validator.js +4 -5
- package/dist/components/_util/vue/validator.js.map +1 -1
- package/dist/components/_util/vue/vnode.js +54 -100
- package/dist/components/_util/vue/vnode.js.map +1 -1
- package/dist/components/_util/vue-types/index.js +220 -231
- package/dist/components/_util/vue-types/index.js.map +1 -1
- package/dist/components/components.js +20 -20
- package/dist/components/index.js +35 -38
- package/dist/components/index.js.map +1 -1
- package/dist/error/OrionError.js +4 -8
- package/dist/error/OrionError.js.map +1 -1
- package/dist/index.css +1 -797
- package/dist/index.js +36 -36
- package/dist/print/LodopFuncs.js +43 -101
- package/dist/print/LodopFuncs.js.map +1 -1
- package/dist/print/index.js +108 -200
- package/dist/print/index.js.map +1 -1
- package/dist/request/ErrorHandlerChain.js +14 -17
- package/dist/request/ErrorHandlerChain.js.map +1 -1
- package/dist/request/RequestFilterChain.js +13 -16
- package/dist/request/RequestFilterChain.js.map +1 -1
- package/dist/request/ResponseParserChain.js +14 -17
- package/dist/request/ResponseParserChain.js.map +1 -1
- package/dist/request/disivion/DateSerializer.js +22 -47
- package/dist/request/disivion/DateSerializer.js.map +1 -1
- package/dist/request/disivion/DivisionErrorHandler.js +25 -40
- package/dist/request/disivion/DivisionErrorHandler.js.map +1 -1
- package/dist/request/disivion/DivisionResponseParser.js +10 -16
- package/dist/request/disivion/DivisionResponseParser.js.map +1 -1
- package/dist/request/disivion/index.js +201 -305
- package/dist/request/disivion/index.js.map +1 -1
- package/dist/request/error/BizExceptionResponseError.js +5 -11
- package/dist/request/error/BizExceptionResponseError.js.map +1 -1
- package/dist/request/error/ExceptionResponseError.js +5 -11
- package/dist/request/error/ExceptionResponseError.js.map +1 -1
- package/dist/request/error/ResponseError.js +4 -9
- package/dist/request/error/ResponseError.js.map +1 -1
- package/dist/request/error/SessionExceptionResponseError.js +5 -11
- package/dist/request/error/SessionExceptionResponseError.js.map +1 -1
- package/dist/request/index.js +11 -11
- package/dist/utils/DateUtil.js +33 -48
- package/dist/utils/DateUtil.js.map +1 -1
- package/dist/utils/NumberUtil.js +6 -6
- package/dist/utils/NumberUtil.js.map +1 -1
- package/dist/utils/cloneDeep.js +2 -2
- package/dist/utils/delay.js +3 -3
- package/dist/utils/delay.js.map +1 -1
- package/dist/utils/functions.js +3 -3
- package/dist/utils/index.js +12 -12
- package/dist/utils/md5.js +93 -191
- package/dist/utils/md5.js.map +1 -1
- package/dist/utils/uuid.js +25 -35
- package/dist/utils/uuid.js.map +1 -1
- package/dist/version/index.js +2 -2
- package/dist/version/version.d.ts +1 -1
- package/dist/version/version.js +2 -2
- package/dist/version/version.js.map +1 -1
- package/package.json +1 -1
- package/dist/_commonjsHelpers-DWwsNxpa.js +0 -9
- package/dist/_commonjsHelpers-DWwsNxpa.js.map +0 -1
- package/dist/components-B3d9m_tn.js +0 -27
- package/dist/components-B3d9m_tn.js.map +0 -1
- package/dist/functions-BeMkokbY.js +0 -63
- package/dist/functions-BeMkokbY.js.map +0 -1
- package/dist/index-BOKLZnqH.js +0 -54
- package/dist/index-BOKLZnqH.js.map +0 -1
- package/dist/index-D1m0KTpK.js +0 -69
- package/dist/index-D1m0KTpK.js.map +0 -1
- package/dist/index-DR5ZP7mD.js +0 -160
- package/dist/index-DR5ZP7mD.js.map +0 -1
- package/dist/index-DkwIULcN.js +0 -200
- package/dist/index-DkwIULcN.js.map +0 -1
@@ -1,145 +1,86 @@
|
|
1
|
-
import { inject, getCurrentInstance, computed } from "vue";
|
2
|
-
import { formContextKey } from "../Form.js";
|
3
|
-
import
|
4
|
-
import { castArray, isString, isArray } from "lodash-es";
|
5
|
-
import
|
6
|
-
import
|
7
|
-
const
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
const
|
12
|
-
|
13
|
-
return
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
trigger = "change";
|
22
|
-
}
|
23
|
-
return computed(() => {
|
24
|
-
const rules = [];
|
25
|
-
let flag = true;
|
26
|
-
if (required) {
|
27
|
-
if (props.rules) {
|
28
|
-
rules.push(...castArray(props.rules));
|
29
|
-
flag = !rules.some((rule) => Object.keys(rule).includes("required"));
|
30
|
-
}
|
31
|
-
if (formContext.rules && formContext.rules[name]) {
|
32
|
-
const formRules = castArray(formContext.rules[name]);
|
33
|
-
flag = !formRules.some((rule) => Object.keys(rule).includes("required"));
|
34
|
-
}
|
35
|
-
}
|
36
|
-
if (flag) {
|
37
|
-
rules.push({
|
38
|
-
required: true,
|
39
|
-
message: `必填项[${label ? label : name}]不能为空`,
|
40
|
-
trigger
|
41
|
-
});
|
42
|
-
}
|
43
|
-
return rules;
|
1
|
+
import { inject as C, getCurrentInstance as s, computed as n } from "vue";
|
2
|
+
import { formContextKey as M } from "../Form.js";
|
3
|
+
import V from "../../../Throne/index.js";
|
4
|
+
import { castArray as p, isString as x, isArray as I } from "lodash-es";
|
5
|
+
import f from "../../../error/OrionError.js";
|
6
|
+
import F from "./FormItemValidateTrigger.js";
|
7
|
+
const u = () => C(M), S = () => {
|
8
|
+
const e = u(), { props: r } = s();
|
9
|
+
return n(() => r.span ? r.span : e.itemSpan);
|
10
|
+
}, O = () => {
|
11
|
+
const e = u(), { props: r, type: o } = s(), { name: t, label: l, required: m } = r;
|
12
|
+
let a = F[o.name];
|
13
|
+
return a || (a = "change"), n(() => {
|
14
|
+
const c = [];
|
15
|
+
let i = !0;
|
16
|
+
return m && (r.rules && (c.push(...p(r.rules)), i = !c.some((d) => Object.keys(d).includes("required"))), e.rules && e.rules[t] && (i = !p(e.rules[t]).some((g) => Object.keys(g).includes("required")))), i && c.push({
|
17
|
+
required: !0,
|
18
|
+
message: `必填项[${l || t}]不能为空`,
|
19
|
+
trigger: a
|
20
|
+
}), c;
|
44
21
|
});
|
45
|
-
}
|
46
|
-
const
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
} else {
|
63
|
-
throw new OrionError("code类型错误");
|
64
|
-
}
|
65
|
-
return codeData;
|
22
|
+
}, R = () => {
|
23
|
+
const e = u(), { props: r } = s();
|
24
|
+
return n(() => e.disabled || r.disabled);
|
25
|
+
}, k = () => {
|
26
|
+
const { props: e } = s();
|
27
|
+
return n(() => {
|
28
|
+
let r;
|
29
|
+
const { code: o } = e;
|
30
|
+
if (o)
|
31
|
+
if (x(o))
|
32
|
+
r = V.getCode(o).value;
|
33
|
+
else if (I(o))
|
34
|
+
r = o;
|
35
|
+
else
|
36
|
+
throw new f("code类型错误");
|
37
|
+
else throw new f("code为空");
|
38
|
+
return r;
|
66
39
|
});
|
67
|
-
}
|
68
|
-
const
|
69
|
-
|
70
|
-
const { props } = getCurrentInstance();
|
71
|
-
const { name } = props;
|
72
|
-
return computed({
|
40
|
+
}, w = () => {
|
41
|
+
const e = u(), { props: r } = s(), { name: o } = r;
|
42
|
+
return n({
|
73
43
|
get: () => {
|
74
|
-
const
|
75
|
-
|
76
|
-
return "";
|
77
|
-
}
|
78
|
-
return value;
|
44
|
+
const t = e.modelValue[o];
|
45
|
+
return t || "";
|
79
46
|
},
|
80
|
-
set: (
|
81
|
-
|
82
|
-
formContext.updateModelValue(name, "");
|
83
|
-
} else {
|
84
|
-
formContext.updateModelValue(name, newValue);
|
85
|
-
}
|
47
|
+
set: (t) => {
|
48
|
+
t ? e.updateModelValue(o, t) : e.updateModelValue(o, "");
|
86
49
|
}
|
87
50
|
});
|
88
|
-
}
|
89
|
-
const
|
90
|
-
|
91
|
-
const { props } = getCurrentInstance();
|
92
|
-
const { name } = props;
|
93
|
-
return computed({
|
51
|
+
}, A = () => {
|
52
|
+
const e = u(), { props: r } = s(), { name: o } = r;
|
53
|
+
return n({
|
94
54
|
get: () => {
|
95
|
-
const
|
96
|
-
if (
|
97
|
-
return
|
98
|
-
}
|
99
|
-
return value.split(",");
|
55
|
+
const t = e.modelValue[o];
|
56
|
+
if (t)
|
57
|
+
return t.split(",");
|
100
58
|
},
|
101
|
-
set: (
|
102
|
-
|
103
|
-
formContext.updateModelValue(name, "");
|
104
|
-
} else {
|
105
|
-
formContext.updateModelValue(name, newValue.join(","));
|
106
|
-
}
|
59
|
+
set: (t) => {
|
60
|
+
t ? e.updateModelValue(o, t.join(",")) : e.updateModelValue(o, "");
|
107
61
|
}
|
108
62
|
});
|
109
|
-
}
|
110
|
-
const
|
111
|
-
|
112
|
-
const { props } = getCurrentInstance();
|
113
|
-
const { name } = props;
|
114
|
-
return computed({
|
63
|
+
}, D = () => {
|
64
|
+
const e = u(), { props: r } = s(), { name: o } = r;
|
65
|
+
return n({
|
115
66
|
get: () => {
|
116
|
-
const
|
117
|
-
|
118
|
-
return false;
|
119
|
-
}
|
120
|
-
return value == "1";
|
67
|
+
const t = e.modelValue[o];
|
68
|
+
return t ? t == "1" : !1;
|
121
69
|
},
|
122
|
-
set: (
|
123
|
-
const
|
124
|
-
|
125
|
-
if (oldValue) {
|
126
|
-
formContext.updateModelValue(name, newValue);
|
127
|
-
} else {
|
128
|
-
if (_newValue) {
|
129
|
-
formContext.updateModelValue(name, newValue);
|
130
|
-
}
|
131
|
-
}
|
70
|
+
set: (t) => {
|
71
|
+
const l = e.modelValue[o], m = t ? "1" : "0";
|
72
|
+
(l || t) && e.updateModelValue(o, m);
|
132
73
|
}
|
133
74
|
});
|
134
75
|
};
|
135
76
|
export {
|
136
|
-
useFormContext,
|
137
|
-
useFormItemBooleanModel,
|
138
|
-
useFormItemCode,
|
139
|
-
useFormItemDisabled,
|
140
|
-
useFormItemMultiModel,
|
141
|
-
useFormItemRules,
|
142
|
-
useFormItemSpan,
|
143
|
-
useFormItemStringModel
|
77
|
+
u as useFormContext,
|
78
|
+
D as useFormItemBooleanModel,
|
79
|
+
k as useFormItemCode,
|
80
|
+
R as useFormItemDisabled,
|
81
|
+
A as useFormItemMultiModel,
|
82
|
+
O as useFormItemRules,
|
83
|
+
S as useFormItemSpan,
|
84
|
+
w as useFormItemStringModel
|
144
85
|
};
|
145
86
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/Form/hooks/index.ts"],"sourcesContent":["import { inject, getCurrentInstance, computed } from 'vue'\r\nimport { formContextKey, FormItemRule } from '../Form'\r\nimport Throne from '../../../Throne'\r\nimport { CodeItem } from '../../types'\r\nimport { castArray, isArray, isString } from 'lodash-es'\r\nimport OrionError from '../../../error/OrionError'\r\nimport formItemValidateTrigger from './FormItemValidateTrigger'\r\n\r\nconst useFormContext = () => {\r\n return inject(formContextKey)\r\n}\r\n\r\nconst useFormItemSpan = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n\r\n return computed(() => (props.span ? (props.span as number) : formContext.itemSpan))\r\n}\r\n\r\nconst useFormItemRules = () => {\r\n const formContext = useFormContext()!\r\n const { props, type } = getCurrentInstance()!\r\n const { name, label, required } = props\r\n let trigger = formItemValidateTrigger[type.name!]\r\n if (!trigger) {\r\n trigger = 'change'\r\n }\r\n\r\n return computed(() => {\r\n const rules: FormItemRule[] = []\r\n let flag = true\r\n\r\n if (required) {\r\n if (props.rules) {\r\n rules.push(...castArray(props.rules))\r\n flag = !rules.some((rule) => Object.keys(rule).includes('required'))\r\n }\r\n if (formContext.rules && formContext.rules[name as string]) {\r\n const formRules = castArray(formContext.rules[name as string])\r\n flag = !formRules.some((rule) => Object.keys(rule).includes('required'))\r\n }\r\n }\r\n\r\n if (flag) {\r\n rules.push({\r\n required: true,\r\n message: `必填项[${label ? label : name}]不能为空`,\r\n trigger: trigger,\r\n })\r\n }\r\n\r\n return rules\r\n })\r\n}\r\n\r\nconst useFormItemDisabled = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n return computed(() => formContext.disabled || (props.disabled as boolean))\r\n}\r\n\r\nconst useFormItemCode = () => {\r\n const { props } = getCurrentInstance()!\r\n\r\n return computed(() => {\r\n let codeData: Array<CodeItem>\r\n const { code } = props\r\n if (!code) {\r\n throw new OrionError('code为空')\r\n } else if (isString(code)) {\r\n codeData = Throne.getCode(code).value\r\n } else if (isArray<CodeItem>(code)) {\r\n codeData = code\r\n } else {\r\n throw new OrionError('code类型错误')\r\n }\r\n\r\n return codeData\r\n })\r\n}\r\n\r\nconst useFormItemStringModel = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n const { name } = props\r\n\r\n return computed<string>({\r\n get: () => {\r\n const value = formContext.modelValue[name as string]\r\n if (!value) {\r\n return ''\r\n }\r\n return value as string\r\n },\r\n set: (newValue) => {\r\n if (!newValue) {\r\n formContext.updateModelValue(name as string, '')\r\n } else {\r\n formContext.updateModelValue(name as string, newValue)\r\n }\r\n },\r\n })\r\n}\r\n\r\nconst useFormItemMultiModel = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n const { name } = props\r\n\r\n return computed<string[] | undefined>({\r\n get: () => {\r\n const value = formContext.modelValue[name as string]\r\n if (!value) {\r\n return undefined\r\n }\r\n return (value as string).split(',')\r\n },\r\n set: (newValue) => {\r\n if (!newValue) {\r\n formContext.updateModelValue(name as string, '')\r\n } else {\r\n formContext.updateModelValue(name as string, newValue.join(','))\r\n }\r\n },\r\n })\r\n}\r\n\r\nconst useFormItemBooleanModel = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n const { name } = props\r\n\r\n return computed<boolean>({\r\n get: () => {\r\n const value = formContext.modelValue[name as string]\r\n if (!value) {\r\n return false\r\n }\r\n return (value as string) == '1'\r\n },\r\n set: (_newValue) => {\r\n const oldValue = formContext.modelValue[name as string]\r\n const newValue = _newValue ? '1' : '0'\r\n if (oldValue) {\r\n formContext.updateModelValue(name as string, newValue)\r\n } else {\r\n if (_newValue) {\r\n formContext.updateModelValue(name as string, newValue)\r\n }\r\n }\r\n },\r\n })\r\n}\r\n\r\nexport {\r\n useFormContext,\r\n useFormItemSpan,\r\n useFormItemRules,\r\n useFormItemDisabled,\r\n useFormItemCode,\r\n useFormItemStringModel,\r\n useFormItemMultiModel,\r\n useFormItemBooleanModel,\r\n}\r\n"],"names":[],"mappings":";;;;;;AAQA,
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/Form/hooks/index.ts"],"sourcesContent":["import { inject, getCurrentInstance, computed } from 'vue'\r\nimport { formContextKey, FormItemRule } from '../Form'\r\nimport Throne from '../../../Throne'\r\nimport { CodeItem } from '../../types'\r\nimport { castArray, isArray, isString } from 'lodash-es'\r\nimport OrionError from '../../../error/OrionError'\r\nimport formItemValidateTrigger from './FormItemValidateTrigger'\r\n\r\nconst useFormContext = () => {\r\n return inject(formContextKey)\r\n}\r\n\r\nconst useFormItemSpan = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n\r\n return computed(() => (props.span ? (props.span as number) : formContext.itemSpan))\r\n}\r\n\r\nconst useFormItemRules = () => {\r\n const formContext = useFormContext()!\r\n const { props, type } = getCurrentInstance()!\r\n const { name, label, required } = props\r\n let trigger = formItemValidateTrigger[type.name!]\r\n if (!trigger) {\r\n trigger = 'change'\r\n }\r\n\r\n return computed(() => {\r\n const rules: FormItemRule[] = []\r\n let flag = true\r\n\r\n if (required) {\r\n if (props.rules) {\r\n rules.push(...castArray(props.rules))\r\n flag = !rules.some((rule) => Object.keys(rule).includes('required'))\r\n }\r\n if (formContext.rules && formContext.rules[name as string]) {\r\n const formRules = castArray(formContext.rules[name as string])\r\n flag = !formRules.some((rule) => Object.keys(rule).includes('required'))\r\n }\r\n }\r\n\r\n if (flag) {\r\n rules.push({\r\n required: true,\r\n message: `必填项[${label ? label : name}]不能为空`,\r\n trigger: trigger,\r\n })\r\n }\r\n\r\n return rules\r\n })\r\n}\r\n\r\nconst useFormItemDisabled = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n return computed(() => formContext.disabled || (props.disabled as boolean))\r\n}\r\n\r\nconst useFormItemCode = () => {\r\n const { props } = getCurrentInstance()!\r\n\r\n return computed(() => {\r\n let codeData: Array<CodeItem>\r\n const { code } = props\r\n if (!code) {\r\n throw new OrionError('code为空')\r\n } else if (isString(code)) {\r\n codeData = Throne.getCode(code).value\r\n } else if (isArray<CodeItem>(code)) {\r\n codeData = code\r\n } else {\r\n throw new OrionError('code类型错误')\r\n }\r\n\r\n return codeData\r\n })\r\n}\r\n\r\nconst useFormItemStringModel = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n const { name } = props\r\n\r\n return computed<string>({\r\n get: () => {\r\n const value = formContext.modelValue[name as string]\r\n if (!value) {\r\n return ''\r\n }\r\n return value as string\r\n },\r\n set: (newValue) => {\r\n if (!newValue) {\r\n formContext.updateModelValue(name as string, '')\r\n } else {\r\n formContext.updateModelValue(name as string, newValue)\r\n }\r\n },\r\n })\r\n}\r\n\r\nconst useFormItemMultiModel = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n const { name } = props\r\n\r\n return computed<string[] | undefined>({\r\n get: () => {\r\n const value = formContext.modelValue[name as string]\r\n if (!value) {\r\n return undefined\r\n }\r\n return (value as string).split(',')\r\n },\r\n set: (newValue) => {\r\n if (!newValue) {\r\n formContext.updateModelValue(name as string, '')\r\n } else {\r\n formContext.updateModelValue(name as string, newValue.join(','))\r\n }\r\n },\r\n })\r\n}\r\n\r\nconst useFormItemBooleanModel = () => {\r\n const formContext = useFormContext()!\r\n const { props } = getCurrentInstance()!\r\n const { name } = props\r\n\r\n return computed<boolean>({\r\n get: () => {\r\n const value = formContext.modelValue[name as string]\r\n if (!value) {\r\n return false\r\n }\r\n return (value as string) == '1'\r\n },\r\n set: (_newValue) => {\r\n const oldValue = formContext.modelValue[name as string]\r\n const newValue = _newValue ? '1' : '0'\r\n if (oldValue) {\r\n formContext.updateModelValue(name as string, newValue)\r\n } else {\r\n if (_newValue) {\r\n formContext.updateModelValue(name as string, newValue)\r\n }\r\n }\r\n },\r\n })\r\n}\r\n\r\nexport {\r\n useFormContext,\r\n useFormItemSpan,\r\n useFormItemRules,\r\n useFormItemDisabled,\r\n useFormItemCode,\r\n useFormItemStringModel,\r\n useFormItemMultiModel,\r\n useFormItemBooleanModel,\r\n}\r\n"],"names":["useFormContext","inject","formContextKey","useFormItemSpan","formContext","props","getCurrentInstance","computed","useFormItemRules","type","name","label","required","trigger","formItemValidateTrigger","rules","flag","castArray","rule","useFormItemDisabled","useFormItemCode","codeData","code","isString","Throne","isArray","OrionError","useFormItemStringModel","value","newValue","useFormItemMultiModel","useFormItemBooleanModel","_newValue","oldValue"],"mappings":";;;;;;AAQA,MAAMA,IAAiB,MACdC,EAAOC,CAAc,GAGxBC,IAAkB,MAAM;AAC5B,QAAMC,IAAcJ,KACd,EAAE,OAAAK,MAAUC;AAElB,SAAOC,EAAS,MAAOF,EAAM,OAAQA,EAAM,OAAkBD,EAAY,QAAS;AACpF,GAEMI,IAAmB,MAAM;AAC7B,QAAMJ,IAAcJ,KACd,EAAE,OAAAK,GAAO,MAAAI,EAAK,IAAIH,EAAmB,GACrC,EAAE,MAAAI,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