orion-design 0.1.30 → 0.1.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. package/README.md +5 -5
  2. package/dist/Throne/index.js +30 -14
  3. package/dist/Throne/index.js.map +1 -1
  4. package/dist/_commonjsHelpers-DWwsNxpa.js +9 -0
  5. package/dist/_commonjsHelpers-DWwsNxpa.js.map +1 -0
  6. package/dist/components/Button/index.js +40 -33
  7. package/dist/components/Button/index.js.map +1 -1
  8. package/dist/components/Flex/index.js +122 -89
  9. package/dist/components/Flex/index.js.map +1 -1
  10. package/dist/components/Form/Form.js +2 -2
  11. package/dist/components/Form/Form.js.map +1 -1
  12. package/dist/components/Form/LovInput/LovInput.js +2 -2
  13. package/dist/components/Form/LovInput/LovInput.js.map +1 -1
  14. package/dist/components/Form/LovInput/hooks/useLov.js +5 -5
  15. package/dist/components/Form/LovInput/hooks/useLov.js.map +1 -1
  16. package/dist/components/Form/LovInput/index.js +4 -4
  17. package/dist/components/Form/hooks/FormItemValidateTrigger.js +2 -2
  18. package/dist/components/Form/hooks/FormItemValidateTrigger.js.map +1 -1
  19. package/dist/components/Form/hooks/index.js +128 -66
  20. package/dist/components/Form/hooks/index.js.map +1 -1
  21. package/dist/components/Form/index.js +836 -656
  22. package/dist/components/Form/index.js.map +1 -1
  23. package/dist/components/Form/utils/index.js +30 -18
  24. package/dist/components/Form/utils/index.js.map +1 -1
  25. package/dist/components/LovTable/index.js +179 -105
  26. package/dist/components/LovTable/index.js.map +1 -1
  27. package/dist/components/Modal/index.js +111 -56
  28. package/dist/components/Modal/index.js.map +1 -1
  29. package/dist/components/Modal/types.js +4 -3
  30. package/dist/components/Modal/types.js.map +1 -1
  31. package/dist/components/Modal/useModal.js +5 -5
  32. package/dist/components/Modal/useModal.js.map +1 -1
  33. package/dist/components/Pagetable/hooks/useColumns.js +88 -80
  34. package/dist/components/Pagetable/hooks/useColumns.js.map +1 -1
  35. package/dist/components/Pagetable/index.js +687 -542
  36. package/dist/components/Pagetable/index.js.map +1 -1
  37. package/dist/components/Pagetable/utils/index.js +92 -54
  38. package/dist/components/Pagetable/utils/index.js.map +1 -1
  39. package/dist/components/Querytable/hooks/useColumns.js +82 -74
  40. package/dist/components/Querytable/hooks/useColumns.js.map +1 -1
  41. package/dist/components/Querytable/index.js +579 -469
  42. package/dist/components/Querytable/index.js.map +1 -1
  43. package/dist/components/Querytable/utils/index.js +92 -54
  44. package/dist/components/Querytable/utils/index.js.map +1 -1
  45. package/dist/components/RichTextEditor/index.js +100 -74
  46. package/dist/components/RichTextEditor/index.js.map +1 -1
  47. package/dist/components/Tabs/constants.js +2 -2
  48. package/dist/components/Tabs/constants.js.map +1 -1
  49. package/dist/components/Tabs/index.js +603 -358
  50. package/dist/components/Tabs/index.js.map +1 -1
  51. package/dist/components/Tabs/tab-bar.js +6 -6
  52. package/dist/components/Tabs/tab-bar.js.map +1 -1
  53. package/dist/components/Tabs/tab-pane.js +3 -3
  54. package/dist/components/Tabs/tab-pane.js.map +1 -1
  55. package/dist/components/_constants/aria.js +2 -2
  56. package/dist/components/_constants/aria.js.map +1 -1
  57. package/dist/components/_constants/event.js +6 -4
  58. package/dist/components/_constants/event.js.map +1 -1
  59. package/dist/components/_constants/index.js +6 -6
  60. package/dist/components/_hooks/index.js +7 -7
  61. package/dist/components/_hooks/use-namespace/index.js +74 -39
  62. package/dist/components/_hooks/use-namespace/index.js.map +1 -1
  63. package/dist/components/_hooks/use-ordered-children/index.js +29 -19
  64. package/dist/components/_hooks/use-ordered-children/index.js.map +1 -1
  65. package/dist/components/_util/arrays.js +9 -5
  66. package/dist/components/_util/arrays.js.map +1 -1
  67. package/dist/components/_util/browser.js +6 -6
  68. package/dist/components/_util/browser.js.map +1 -1
  69. package/dist/components/_util/classNames.js +22 -17
  70. package/dist/components/_util/classNames.js.map +1 -1
  71. package/dist/components/_util/dom/aria.js +74 -39
  72. package/dist/components/_util/dom/aria.js.map +1 -1
  73. package/dist/components/_util/dom/element.js +9 -8
  74. package/dist/components/_util/dom/element.js.map +1 -1
  75. package/dist/components/_util/dom/event.js +14 -7
  76. package/dist/components/_util/dom/event.js.map +1 -1
  77. package/dist/components/_util/dom/index.js +36 -36
  78. package/dist/components/_util/dom/position.js +49 -25
  79. package/dist/components/_util/dom/position.js.map +1 -1
  80. package/dist/components/_util/dom/scroll.js +103 -61
  81. package/dist/components/_util/dom/scroll.js.map +1 -1
  82. package/dist/components/_util/dom/style.js +65 -50
  83. package/dist/components/_util/dom/style.js.map +1 -1
  84. package/dist/components/_util/easings.js +8 -4
  85. package/dist/components/_util/easings.js.map +1 -1
  86. package/dist/components/_util/error.js +12 -11
  87. package/dist/components/_util/error.js.map +1 -1
  88. package/dist/components/_util/functions.js +3 -3
  89. package/dist/components/_util/i18n.js +2 -2
  90. package/dist/components/_util/i18n.js.map +1 -1
  91. package/dist/components/_util/index.js +137 -137
  92. package/dist/components/_util/isValid.js +4 -2
  93. package/dist/components/_util/isValid.js.map +1 -1
  94. package/dist/components/_util/objects.js +18 -14
  95. package/dist/components/_util/objects.js.map +1 -1
  96. package/dist/components/_util/props-util/index.js +46 -20
  97. package/dist/components/_util/props-util/index.js.map +1 -1
  98. package/dist/components/_util/props-util/initDefaultProps.js +18 -10
  99. package/dist/components/_util/props-util/initDefaultProps.js.map +1 -1
  100. package/dist/components/_util/raf.js +5 -4
  101. package/dist/components/_util/raf.js.map +1 -1
  102. package/dist/components/_util/rand.js +4 -3
  103. package/dist/components/_util/rand.js.map +1 -1
  104. package/dist/components/_util/strings.js +9 -8
  105. package/dist/components/_util/strings.js.map +1 -1
  106. package/dist/components/_util/throttleByRaf.js +16 -10
  107. package/dist/components/_util/throttleByRaf.js.map +1 -1
  108. package/dist/components/_util/type.js +41 -38
  109. package/dist/components/_util/type.js.map +1 -1
  110. package/dist/components/_util/types.js +41 -22
  111. package/dist/components/_util/types.js.map +1 -1
  112. package/dist/components/_util/typescript.js +2 -2
  113. package/dist/components/_util/typescript.js.map +1 -1
  114. package/dist/components/_util/util.js +85 -43
  115. package/dist/components/_util/util.js.map +1 -1
  116. package/dist/components/_util/vue/global-node.js +27 -15
  117. package/dist/components/_util/vue/global-node.js.map +1 -1
  118. package/dist/components/_util/vue/icon.js +29 -25
  119. package/dist/components/_util/vue/icon.js.map +1 -1
  120. package/dist/components/_util/vue/index.js +41 -41
  121. package/dist/components/_util/vue/install.js +35 -18
  122. package/dist/components/_util/vue/install.js.map +1 -1
  123. package/dist/components/_util/vue/props/index.js +6 -6
  124. package/dist/components/_util/vue/props/runtime.js +46 -30
  125. package/dist/components/_util/vue/props/runtime.js.map +1 -1
  126. package/dist/components/_util/vue/refs.js +12 -6
  127. package/dist/components/_util/vue/refs.js.map +1 -1
  128. package/dist/components/_util/vue/size.js +5 -3
  129. package/dist/components/_util/vue/size.js.map +1 -1
  130. package/dist/components/_util/vue/validator.js +5 -4
  131. package/dist/components/_util/vue/validator.js.map +1 -1
  132. package/dist/components/_util/vue/vnode.js +100 -54
  133. package/dist/components/_util/vue/vnode.js.map +1 -1
  134. package/dist/components/_util/vue-types/index.js +231 -220
  135. package/dist/components/_util/vue-types/index.js.map +1 -1
  136. package/dist/components/components.js +20 -20
  137. package/dist/components/index.js +38 -35
  138. package/dist/components/index.js.map +1 -1
  139. package/dist/components-B3d9m_tn.js +27 -0
  140. package/dist/components-B3d9m_tn.js.map +1 -0
  141. package/dist/error/OrionError.js +8 -4
  142. package/dist/error/OrionError.js.map +1 -1
  143. package/dist/functions-BeMkokbY.js +63 -0
  144. package/dist/functions-BeMkokbY.js.map +1 -0
  145. package/dist/index-BOKLZnqH.js +54 -0
  146. package/dist/index-BOKLZnqH.js.map +1 -0
  147. package/dist/index-D1m0KTpK.js +69 -0
  148. package/dist/index-D1m0KTpK.js.map +1 -0
  149. package/dist/index-DR5ZP7mD.js +160 -0
  150. package/dist/index-DR5ZP7mD.js.map +1 -0
  151. package/dist/index-DkwIULcN.js +200 -0
  152. package/dist/index-DkwIULcN.js.map +1 -0
  153. package/dist/index.css +797 -1
  154. package/dist/index.js +36 -36
  155. package/dist/print/LodopFuncs.js +101 -43
  156. package/dist/print/LodopFuncs.js.map +1 -1
  157. package/dist/print/index.js +200 -108
  158. package/dist/print/index.js.map +1 -1
  159. package/dist/request/ErrorHandlerChain.js +17 -14
  160. package/dist/request/ErrorHandlerChain.js.map +1 -1
  161. package/dist/request/RequestFilterChain.js +16 -13
  162. package/dist/request/RequestFilterChain.js.map +1 -1
  163. package/dist/request/ResponseParserChain.js +17 -14
  164. package/dist/request/ResponseParserChain.js.map +1 -1
  165. package/dist/request/disivion/DateSerializer.js +47 -22
  166. package/dist/request/disivion/DateSerializer.js.map +1 -1
  167. package/dist/request/disivion/DivisionErrorHandler.js +40 -25
  168. package/dist/request/disivion/DivisionErrorHandler.js.map +1 -1
  169. package/dist/request/disivion/DivisionResponseParser.js +16 -10
  170. package/dist/request/disivion/DivisionResponseParser.js.map +1 -1
  171. package/dist/request/disivion/index.js +305 -201
  172. package/dist/request/disivion/index.js.map +1 -1
  173. package/dist/request/error/BizExceptionResponseError.js +11 -5
  174. package/dist/request/error/BizExceptionResponseError.js.map +1 -1
  175. package/dist/request/error/ExceptionResponseError.js +11 -5
  176. package/dist/request/error/ExceptionResponseError.js.map +1 -1
  177. package/dist/request/error/ResponseError.js +9 -4
  178. package/dist/request/error/ResponseError.js.map +1 -1
  179. package/dist/request/error/SessionExceptionResponseError.js +11 -5
  180. package/dist/request/error/SessionExceptionResponseError.js.map +1 -1
  181. package/dist/request/index.js +11 -11
  182. package/dist/utils/DateUtil.js +48 -33
  183. package/dist/utils/DateUtil.js.map +1 -1
  184. package/dist/utils/NumberUtil.js +6 -6
  185. package/dist/utils/NumberUtil.js.map +1 -1
  186. package/dist/utils/cloneDeep.js +2 -2
  187. package/dist/utils/delay.js +3 -3
  188. package/dist/utils/delay.js.map +1 -1
  189. package/dist/utils/functions.js +3 -3
  190. package/dist/utils/index.js +12 -12
  191. package/dist/utils/md5.js +191 -93
  192. package/dist/utils/md5.js.map +1 -1
  193. package/dist/utils/uuid.js +35 -25
  194. package/dist/utils/uuid.js.map +1 -1
  195. package/dist/version/index.js +2 -2
  196. package/dist/version/version.d.ts +1 -1
  197. package/dist/version/version.js +2 -2
  198. package/dist/version/version.js.map +1 -1
  199. package/package.json +1 -1
@@ -1,83 +1,145 @@
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;
1
+ import { inject, getCurrentInstance, computed } from "vue";
2
+ import { formContextKey } from "../Form.js";
3
+ import Throne from "../../../Throne/index.js";
4
+ import { castArray, isString, isArray } from "lodash-es";
5
+ import OrionError from "../../../error/OrionError.js";
6
+ import formItemValidateTrigger from "./FormItemValidateTrigger.js";
7
+ const useFormContext = () => {
8
+ return inject(formContextKey);
9
+ };
10
+ const useFormItemSpan = () => {
11
+ const formContext = useFormContext();
12
+ const { props } = getCurrentInstance();
13
+ return computed(() => props.span ? props.span : formContext.itemSpan);
14
+ };
15
+ const useFormItemRules = () => {
16
+ const formContext = useFormContext();
17
+ const { props, type } = getCurrentInstance();
18
+ const { name, label, required } = props;
19
+ let trigger = formItemValidateTrigger[type.name];
20
+ if (!trigger) {
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;
21
44
  });
22
- }, R = () => {
23
- const e = u(), { props: r } = s();
24
- return n(() => e.disabled || r.disabled);
25
- }, k = () => {
26
- let e;
27
- const { props: r } = s(), { code: o } = r;
28
- if (o)
29
- if (x(o))
30
- e = V.getCode(o).value;
31
- else if (I(o))
32
- e = o;
33
- else
34
- throw new f("code类型错误");
35
- else throw new f("code为空");
36
- return n(() => e);
37
- }, w = () => {
38
- const e = u(), { props: r } = s(), { name: o } = r;
39
- return n({
45
+ };
46
+ const useFormItemDisabled = () => {
47
+ const formContext = useFormContext();
48
+ const { props } = getCurrentInstance();
49
+ return computed(() => formContext.disabled || props.disabled);
50
+ };
51
+ const useFormItemCode = () => {
52
+ const { props } = getCurrentInstance();
53
+ return computed(() => {
54
+ let codeData;
55
+ const { code } = props;
56
+ if (!code) {
57
+ throw new OrionError("code为空");
58
+ } else if (isString(code)) {
59
+ codeData = Throne.getCode(code).value;
60
+ } else if (isArray(code)) {
61
+ codeData = code;
62
+ } else {
63
+ throw new OrionError("code类型错误");
64
+ }
65
+ return codeData;
66
+ });
67
+ };
68
+ const useFormItemStringModel = () => {
69
+ const formContext = useFormContext();
70
+ const { props } = getCurrentInstance();
71
+ const { name } = props;
72
+ return computed({
40
73
  get: () => {
41
- const t = e.modelValue[o];
42
- return t || "";
74
+ const value = formContext.modelValue[name];
75
+ if (!value) {
76
+ return "";
77
+ }
78
+ return value;
43
79
  },
44
- set: (t) => {
45
- t ? e.updateModelValue(o, t) : e.updateModelValue(o, "");
80
+ set: (newValue) => {
81
+ if (!newValue) {
82
+ formContext.updateModelValue(name, "");
83
+ } else {
84
+ formContext.updateModelValue(name, newValue);
85
+ }
46
86
  }
47
87
  });
48
- }, A = () => {
49
- const e = u(), { props: r } = s(), { name: o } = r;
50
- return n({
88
+ };
89
+ const useFormItemMultiModel = () => {
90
+ const formContext = useFormContext();
91
+ const { props } = getCurrentInstance();
92
+ const { name } = props;
93
+ return computed({
51
94
  get: () => {
52
- const t = e.modelValue[o];
53
- if (t)
54
- return t.split(",");
95
+ const value = formContext.modelValue[name];
96
+ if (!value) {
97
+ return void 0;
98
+ }
99
+ return value.split(",");
55
100
  },
56
- set: (t) => {
57
- t ? e.updateModelValue(o, t.join(",")) : e.updateModelValue(o, "");
101
+ set: (newValue) => {
102
+ if (!newValue) {
103
+ formContext.updateModelValue(name, "");
104
+ } else {
105
+ formContext.updateModelValue(name, newValue.join(","));
106
+ }
58
107
  }
59
108
  });
60
- }, D = () => {
61
- const e = u(), { props: r } = s(), { name: o } = r;
62
- return n({
109
+ };
110
+ const useFormItemBooleanModel = () => {
111
+ const formContext = useFormContext();
112
+ const { props } = getCurrentInstance();
113
+ const { name } = props;
114
+ return computed({
63
115
  get: () => {
64
- const t = e.modelValue[o];
65
- return t ? t == "1" : !1;
116
+ const value = formContext.modelValue[name];
117
+ if (!value) {
118
+ return false;
119
+ }
120
+ return value == "1";
66
121
  },
67
- set: (t) => {
68
- const l = e.modelValue[o], m = t ? "1" : "0";
69
- (l || t) && e.updateModelValue(o, m);
122
+ set: (_newValue) => {
123
+ const oldValue = formContext.modelValue[name];
124
+ const newValue = _newValue ? "1" : "0";
125
+ if (oldValue) {
126
+ formContext.updateModelValue(name, newValue);
127
+ } else {
128
+ if (_newValue) {
129
+ formContext.updateModelValue(name, newValue);
130
+ }
131
+ }
70
132
  }
71
133
  });
72
134
  };
73
135
  export {
74
- u as useFormContext,
75
- D as useFormItemBooleanModel,
76
- k as useFormItemCode,
77
- R as useFormItemDisabled,
78
- A as useFormItemMultiModel,
79
- O as useFormItemRules,
80
- S as useFormItemSpan,
81
- w as useFormItemStringModel
136
+ useFormContext,
137
+ useFormItemBooleanModel,
138
+ useFormItemCode,
139
+ useFormItemDisabled,
140
+ useFormItemMultiModel,
141
+ useFormItemRules,
142
+ useFormItemSpan,
143
+ useFormItemStringModel
82
144
  };
83
145
  //# 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 let codeData: Array<CodeItem>\r\n const { props } = getCurrentInstance()!\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 return computed(() => codeData)\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,GAAM,OAAAC,GAAO,UAAAC,EAAA,IAAaP;AAC9B,MAAAQ,IAAUC,EAAwBL,EAAK,IAAK;AAChD,SAAKI,MACOA,IAAA,WAGLN,EAAS,MAAM;AACpB,UAAMQ,IAAwB,CAAA;AAC9B,QAAIC,IAAO;AAEX,WAAIJ,MACEP,EAAM,UACRU,EAAM,KAAK,GAAGE,EAAUZ,EAAM,KAAK,CAAC,GAC7BW,IAAA,CAACD,EAAM,KAAK,CAACG,MAAS,OAAO,KAAKA,CAAI,EAAE,SAAS,UAAU,CAAC,IAEjEd,EAAY,SAASA,EAAY,MAAMM,CAAc,MAEhDM,IAAA,CADWC,EAAUb,EAAY,MAAMM,CAAc,C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qB,IAAQxB,EAAY,WAAWM,CAAc;AACnD,UAAKkB;AAGG,eAAAA,EAAiB,MAAM,GAAG;AAAA,IACpC;AAAA,IACA,KAAK,CAACC,MAAa;AACjB,MAAKA,IAGHzB,EAAY,iBAAiBM,GAAgBmB,EAAS,KAAK,GAAG,CAAC,IAFnDzB,EAAA,iBAAiBM,GAAgB,EAAE;AAAA,IAInD;AAAA,EAAA,CACD;AACH,GAEMqB,IAA0B,MAAM;AACpC,QAAM3B,IAAcJ,KACd,EAAE,OAAAK,MAAUC,KACZ,EAAE,MAAAI,EAAS,IAAAL;AAEjB,SAAOE,EAAkB;AAAA,IACvB,KAAK,MAAM;AACH,YAAAqB,IAAQxB,EAAY,WAAWM,CAAc;AACnD,aAAKkB,IAGGA,KAAoB,MAFnB;AAAA,IAGX;AAAA,IACA,KAAK,CAACI,MAAc;AACZ,YAAAC,IAAW7B,EAAY,WAAWM,CAAc,GAChDmB,IAAWG,IAAY,MAAM;AACnC,OAAIC,KAGED,MACU5B,EAAA,iBAAiBM,GAAgBmB,CAAQ;AAAA,IAG3D;AAAA,EAAA,CACD;AACH;"}
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,MAAM,iBAAiB,MAAM;AAC3B,SAAO,OAAO,cAAc;AAC9B;AAEA,MAAM,kBAAkB,MAAM;AAC5B,QAAM,cAAc;AACd,QAAA,EAAE,UAAU;AAElB,SAAO,SAAS,MAAO,MAAM,OAAQ,MAAM,OAAkB,YAAY,QAAS;AACpF;AAEA,MAAM,mBAAmB,MAAM;AAC7B,QAAM,cAAc;AACpB,QAAM,EAAE,OAAO,KAAK,IAAI,mBAAmB;AAC3C,QAAM,EAAE,MAAM,OAAO,SAAA,IAAa;AAC9B,MAAA,UAAU,wBAAwB,KAAK,IAAK;AAChD,MAAI,CAAC,SAAS;AACF,cAAA;AAAA,EACZ;AAEA,SAAO,SAAS,MAAM;AACpB,UAAM,QAAwB,CAAA;AAC9B,QAAI,OAAO;AAEX,QAAI,U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