@dt-frames/ui 1.0.2 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/README.md +1 -15
  2. package/es/assets/imgs/header/avatar.png +0 -0
  3. package/es/assets/style/reset.less +0 -3
  4. package/es/components/curd/src/components/dialog.d.ts +21 -58
  5. package/es/components/curd/src/types/curd.type.d.ts +2 -1
  6. package/es/components/dialog/index.d.ts +2 -0
  7. package/es/components/dialog/src/hooks/useDialog.d.ts +3 -0
  8. package/es/components/forms/index.d.ts +2 -2
  9. package/es/components/forms/src/components/formIcon.d.ts +4 -47
  10. package/es/components/forms/src/index.d.ts +2 -6
  11. package/es/components/iframe/index.d.ts +2 -2
  12. package/es/components/index.d.ts +3 -2
  13. package/es/components/modal/src/components/close-icon.d.ts +0 -43
  14. package/es/components/modal/src/index.d.ts +0 -43
  15. package/es/components/source/src/types/table.type.d.ts +1 -1
  16. package/es/components/table/index.d.ts +1 -1
  17. package/es/components/table/src/components/setting/Column.d.ts +6 -5
  18. package/es/components/table/src/hooks/useColumns.d.ts +1 -1
  19. package/es/components/table/src/hooks/useDataSource.d.ts +1 -3
  20. package/es/components/table/src/hooks/useHeaderCode.d.ts +2 -0
  21. package/es/components/table/src/hooks/useRowSelection.d.ts +2 -3
  22. package/es/components/table/src/index.d.ts +15 -3
  23. package/es/components/table/src/props.d.ts +7 -1
  24. package/es/index.js +284 -271
  25. package/es/style/assets/style/reset.less +0 -3
  26. package/es/style/components/forms/{src/index.less → index.less} +2 -0
  27. package/es/style/components/icons/index.less +1 -0
  28. package/es/style/components/iframe/index.less +3 -0
  29. package/es/style/components/modal/{src/index.less → index.less} +0 -0
  30. package/es/style/components/table/{src/index.less → index.less} +12 -1
  31. package/es/style/theme/header/index.less +8 -4
  32. package/es/style/theme/sider/index.less +25 -25
  33. package/es/style/theme/theme.less +2 -1
  34. package/es/theme/header/components/logo.d.ts +43 -0
  35. package/es/theme/header/components/notify.d.ts +0 -1
  36. package/package.json +50 -40
  37. package/src/assets/data/icons/actions.ts +427 -0
  38. package/src/assets/data/icons/code.ts +10 -0
  39. package/src/assets/data/icons/commuticate.ts +190 -0
  40. package/src/assets/data/icons/currency.ts +46 -0
  41. package/src/assets/data/icons/devices.ts +128 -0
  42. package/src/assets/data/icons/edit.ts +165 -0
  43. package/src/assets/data/icons/file.ts +104 -0
  44. package/src/assets/data/icons/math.ts +53 -0
  45. package/src/assets/data/icons/message.ts +75 -0
  46. package/src/assets/data/icons/navigate.ts +181 -0
  47. package/src/assets/data/icons/other.ts +333 -0
  48. package/src/assets/data/icons.ts +58 -0
  49. package/src/assets/imgs/header/avatar.png +0 -0
  50. package/src/assets/imgs/logo/logo.png +0 -0
  51. package/src/assets/locales/en_US.json +3 -0
  52. package/src/assets/locales/zh_CN.json +3 -0
  53. package/src/assets/style/index.less +10 -0
  54. package/src/assets/style/reset.less +17 -0
  55. package/src/components/container/index.less +85 -0
  56. package/src/components/container/index.ts +8 -0
  57. package/src/components/container/src/bar.ts +107 -0
  58. package/src/components/container/src/lazy-container.vue +9 -0
  59. package/src/components/container/src/scroll-bar.vue +117 -0
  60. package/src/components/container/src/scroll-container.vue +61 -0
  61. package/src/components/curd/index.ts +5 -0
  62. package/src/components/curd/src/components/dialog.vue +71 -0
  63. package/src/components/curd/src/components/props.ts +32 -0
  64. package/src/components/curd/src/hooks/useCurd.tsx +87 -0
  65. package/src/components/curd/src/types/curd.type.ts +31 -0
  66. package/src/components/dialog/index.ts +5 -0
  67. package/src/components/dialog/src/hooks/useDialog.ts +85 -0
  68. package/src/components/excel/index.ts +6 -0
  69. package/src/components/excel/src/export2Excel.ts +44 -0
  70. package/src/components/forms/index.less +84 -0
  71. package/src/components/forms/index.ts +11 -0
  72. package/src/components/forms/src/componentMap.ts +44 -0
  73. package/src/components/forms/src/components/formButton.vue +150 -0
  74. package/src/components/forms/src/components/formIcon.vue +50 -0
  75. package/src/components/forms/src/components/formItem.vue +407 -0
  76. package/src/components/forms/src/components/radioButton.vue +58 -0
  77. package/src/components/forms/src/const/form.const.ts +7 -0
  78. package/src/components/forms/src/hooks/helper.ts +70 -0
  79. package/src/components/forms/src/hooks/useForm.ts +130 -0
  80. package/src/components/forms/src/hooks/useFormActions.ts +63 -0
  81. package/src/components/forms/src/hooks/useFormEvents.ts +247 -0
  82. package/src/components/forms/src/hooks/useFormValue.ts +49 -0
  83. package/src/components/forms/src/hooks/useFormValues.ts +131 -0
  84. package/src/components/forms/src/hooks/useLabelWidth.ts +57 -0
  85. package/src/components/forms/src/index.vue +306 -0
  86. package/src/components/forms/src/prop.ts +80 -0
  87. package/src/components/forms/src/types/form.type.ts +269 -0
  88. package/{es/style/components/icons/src → src/components/icons}/index.less +1 -0
  89. package/src/components/icons/index.ts +7 -0
  90. package/src/components/icons/src/pick-icon.vue +117 -0
  91. package/src/components/icons/src/svg-icon.vue +117 -0
  92. package/src/components/iframe/index.less +3 -0
  93. package/src/components/iframe/index.ts +5 -0
  94. package/src/components/iframe/src/index.less +3 -0
  95. package/src/components/iframe/src/index.vue +38 -0
  96. package/src/components/index.ts +48 -0
  97. package/src/components/modal/index.less +60 -0
  98. package/src/components/modal/index.ts +8 -0
  99. package/src/components/modal/src/components/close-icon.vue +47 -0
  100. package/src/components/modal/src/components/modal-wrap.vue +118 -0
  101. package/src/components/modal/src/components/modal.tsx +30 -0
  102. package/src/components/modal/src/components/modalFooter.vue +38 -0
  103. package/src/components/modal/src/hooks/useDrag.ts +107 -0
  104. package/src/components/modal/src/hooks/useFullScreen.ts +27 -0
  105. package/src/components/modal/src/hooks/useModal.ts +176 -0
  106. package/src/components/modal/src/index.vue +173 -0
  107. package/src/components/modal/src/props.ts +43 -0
  108. package/src/components/modal/src/types/modal.type.ts +27 -0
  109. package/src/components/router/base-router.vue +11 -0
  110. package/src/components/router/index.ts +3 -0
  111. package/src/components/source/index.ts +1 -0
  112. package/src/components/source/src/hooks/useFetch.ts +69 -0
  113. package/src/components/source/src/hooks/usePage.ts +3 -0
  114. package/src/components/source/src/hooks/useSource.ts +179 -0
  115. package/src/components/source/src/index.ts +5 -0
  116. package/src/components/source/src/types/source.type.ts +68 -0
  117. package/src/components/source/src/types/table.type.ts +8 -0
  118. package/src/components/table/index.less +173 -0
  119. package/src/components/table/index.ts +7 -0
  120. package/src/components/table/src/components/TableActions.vue +108 -0
  121. package/src/components/table/src/components/TableHeader.vue +77 -0
  122. package/src/components/table/src/components/TableRender.vue +76 -0
  123. package/src/components/table/src/components/setting/Column.vue +354 -0
  124. package/src/components/table/src/components/setting/Download.vue +55 -0
  125. package/src/components/table/src/components/setting/Fullscreen.vue +43 -0
  126. package/src/components/table/src/components/setting/Size.vue +42 -0
  127. package/src/components/table/src/components/setting/index.vue +64 -0
  128. package/src/components/table/src/const.ts +13 -0
  129. package/src/components/table/src/hooks/useColumns.ts +319 -0
  130. package/{es/assets/app-antd-dark-theme-style.e3b0c442.css → src/components/table/src/hooks/useCustomRow.ts} +0 -0
  131. package/src/components/table/src/hooks/useDataSource.ts +99 -0
  132. package/src/components/table/src/hooks/useHeaderCode.ts +82 -0
  133. package/src/components/table/src/hooks/useLoading.ts +29 -0
  134. package/src/components/table/src/hooks/usePagination.ts +76 -0
  135. package/src/components/table/src/hooks/useRowSelection.ts +145 -0
  136. package/src/components/table/src/hooks/useRows.ts +30 -0
  137. package/src/components/table/src/hooks/useTable.ts +89 -0
  138. package/src/components/table/src/hooks/useTableHeader.ts +48 -0
  139. package/src/components/table/src/hooks/useTableInstance.ts +29 -0
  140. package/src/components/table/src/hooks/useTableScroll.ts +229 -0
  141. package/src/components/table/src/index.vue +197 -0
  142. package/src/components/table/src/props.ts +157 -0
  143. package/src/components/table/src/types/table.type.ts +133 -0
  144. package/src/components/table/src/types/tableHeader.type.ts +27 -0
  145. package/{es/assets/app-theme-style.e3b0c442.css → src/components/type.ts} +0 -0
  146. package/src/directives/icon.ts +36 -0
  147. package/src/directives/index.ts +26 -0
  148. package/src/directives/permission.ts +20 -0
  149. package/src/global.d.ts +8 -0
  150. package/src/index.ts +4 -0
  151. package/src/theme/content/index.vue +37 -0
  152. package/src/theme/feature/back-top.vue +11 -0
  153. package/src/theme/feature/index.vue +7 -0
  154. package/src/theme/footer/index.less +16 -0
  155. package/src/theme/footer/index.vue +24 -0
  156. package/src/theme/header/components/bread-crumb.vue +26 -0
  157. package/src/theme/header/components/fullscreen.vue +12 -0
  158. package/src/theme/header/components/handler.ts +81 -0
  159. package/src/theme/header/components/index.ts +21 -0
  160. package/src/theme/header/components/lang-picker.vue +36 -0
  161. package/src/theme/header/components/logo.vue +35 -0
  162. package/src/theme/header/components/menu-search.vue +62 -0
  163. package/src/theme/header/components/notify.vue +22 -0
  164. package/src/theme/header/components/setting-theme.vue +123 -0
  165. package/src/theme/header/components/theme-drawer/enum.ts +12 -0
  166. package/src/theme/header/components/theme-drawer/feature.vue +75 -0
  167. package/src/theme/header/components/theme-drawer/index.ts +7 -0
  168. package/src/theme/header/components/theme-drawer/menu-type.vue +40 -0
  169. package/src/theme/header/components/theme-drawer/select-item.vue +46 -0
  170. package/src/theme/header/components/theme-drawer/switch-item.vue +39 -0
  171. package/src/theme/header/components/theme-drawer/theme-color.vue +26 -0
  172. package/src/theme/header/components/trigger.vue +14 -0
  173. package/src/theme/header/components/user-info.vue +60 -0
  174. package/src/theme/header/const/index.ts +40 -0
  175. package/src/theme/header/helper/menu-tree.ts +64 -0
  176. package/src/theme/header/index.less +442 -0
  177. package/{es/theme/theme.d.ts → src/theme/header/index.ts} +0 -0
  178. package/src/theme/header/index.vue +96 -0
  179. package/src/theme/header/multiple-header.vue +67 -0
  180. package/src/theme/header/set-theme.less +68 -0
  181. package/src/theme/index.ts +3 -0
  182. package/src/theme/sider/components/basic-menu/basic-menu-item.vue +14 -0
  183. package/src/theme/sider/components/basic-menu/basic-menu.vue +122 -0
  184. package/src/theme/sider/components/basic-menu/basic-sub-menu-item.vue +46 -0
  185. package/src/theme/sider/components/basic-menu/menu-item-content.vue +13 -0
  186. package/src/theme/sider/components/drag-bar.vue +26 -0
  187. package/src/theme/sider/components/layout-menu.vue +132 -0
  188. package/src/theme/sider/components/props.ts +97 -0
  189. package/src/theme/sider/components/sider-trigger.vue +24 -0
  190. package/src/theme/sider/helper/sider.ts +52 -0
  191. package/src/theme/sider/helper/split-menu.ts +146 -0
  192. package/src/theme/sider/hooks/useDragLine.ts +86 -0
  193. package/src/theme/sider/hooks/useOpenKeys.ts +57 -0
  194. package/src/theme/sider/index.less +203 -0
  195. package/src/theme/sider/index.vue +88 -0
  196. package/src/theme/tabs/components/TabContent.vue +36 -0
  197. package/src/theme/tabs/components/TabRedo.vue +18 -0
  198. package/src/theme/tabs/hooks/useMultifyTabs.ts +96 -0
  199. package/src/theme/tabs/hooks/useTabDropdown.ts +89 -0
  200. package/src/theme/tabs/index.less +165 -0
  201. package/src/theme/tabs/index.vue +98 -0
  202. package/src/theme/tabs/types/tabs.type.ts +8 -0
  203. package/src/theme/theme.less +67 -0
  204. package/src/theme/theme.vue +90 -0
  205. package/src/theme/transition.less +99 -0
  206. package/es/assets/data/icon.d.ts +0 -4
  207. package/es/assets/data/icon.ts +0 -69
  208. package/es/assets/data/icon11.ts +0 -69
  209. package/es/assets/style/var.less +0 -42
  210. package/es/components/icons/pick-icon.d.ts +0 -529
  211. package/es/components/icons/svg-icon.d.ts +0 -44
  212. package/es/components/table/src/hooks/useFormat.d.ts +0 -2
  213. package/es/components/table/src/hooks/useVirtualScroll.d.ts +0 -5
  214. package/es/components/table/src/utils/format.d.ts +0 -1
  215. package/es/index.css +0 -1
  216. package/es/style/assets/style/var.less +0 -42
  217. package/es/theme/content/index.d.ts +0 -29
  218. package/es/theme/header/components/menu-search.d.ts +0 -528
  219. package/es/theme/header/components/setting-theme.d.ts +0 -2550
  220. package/es/theme/header/components/user-info.d.ts +0 -452
  221. package/es/theme/header/index.d.ts +0 -4369
  222. package/es/theme/header/multiple-header.d.ts +0 -2001
  223. package/es/theme/styles/hooks/changeTheme.d.ts +0 -1
  224. package/es/theme/styles/hooks/generate.d.ts +0 -13
  225. package/es/theme/styles/index.d.ts +0 -2
  226. package/es/theme/tabs/components/TabRedo.d.ts +0 -49
  227. package/es/theme/tabs/index.d.ts +0 -1399
  228. package/es/theme/theme/initTheme.d.ts +0 -3
  229. package/es/theme/theme/util.d.ts +0 -5
  230. package/es/themes/generate.ts +0 -74
  231. package/es/themes/index.ts +0 -10
  232. package/es/themes/modifyVars.ts +0 -33
  233. package/es/themes/themePlugiin.ts +0 -74
@@ -0,0 +1,63 @@
1
+ /** ==================================
2
+ * 处理查询条件中的按钮收缩
3
+ * ==================================*/
4
+
5
+ import { isBoolean, Recordable, useAppStore } from "@dt-frames/core"
6
+ import { ComputedRef, Ref, toRaw, unref } from "vue"
7
+ import { RESET_BTN_NAME, SEARCH_BTN_NAME } from "../const/form.const"
8
+ import { ButtonProps, FormProps, FormSchema } from "../types/form.type"
9
+
10
+ type FormOpt = {
11
+ updateSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>
12
+ getProps: ComputedRef<FormProps>
13
+ getSchema: ComputedRef<FormSchema[]>,
14
+ defaultValue: Ref<Recordable>,
15
+ getFormValues: () => Recordable,
16
+ setFormValues: (values: Recordable) => Promise<void>,
17
+ }
18
+
19
+ export function useFormActions(opt: FormOpt) {
20
+ const { getProps, getSchema, defaultValue, updateSchema, getFormValues, setFormValues } = opt
21
+ const { appConf } = useAppStore()
22
+
23
+ // 切换查询条件的展开 折叠
24
+ function handleAdvanced(isAdvanced: boolean) {
25
+ const { schemas, minShowColumn = appConf.ui.form?.minShowColumn || 2 } = unref(getProps)
26
+
27
+ let schema = schemas.reduce( ( t: FormSchema[], it: FormSchema, index ) => {
28
+ if( index > minShowColumn - 1)
29
+ it.isAdvanced = isAdvanced
30
+ t.push( it )
31
+
32
+ return t
33
+ }, [] )
34
+
35
+ updateSchema( schema )
36
+ }
37
+
38
+ function handleMethod(params: boolean | ButtonProps) {
39
+ const { onSearch, onReset } = unref(getProps)
40
+
41
+ if( isBoolean( params ) ) {
42
+
43
+ // 如果为boolean 则视为查询条件的切换按钮
44
+ handleAdvanced(params as boolean)
45
+
46
+ } else if(params.name === SEARCH_BTN_NAME) {
47
+
48
+ // 查询
49
+ onSearch(getFormValues())
50
+
51
+ } else if(params.name === RESET_BTN_NAME) {
52
+
53
+ // 重置
54
+ setFormValues(toRaw(defaultValue.value))
55
+ onReset(getFormValues())
56
+
57
+ } else {
58
+ (params as ButtonProps).onClick()
59
+ }
60
+ }
61
+
62
+ return [ handleMethod ]
63
+ }
@@ -0,0 +1,247 @@
1
+ import { dateFormat, deepMerge, isObject, isString, Recordable } from "@dt-frames/core"
2
+ import { ComputedRef, nextTick, Ref, toRaw, unref } from "vue"
3
+ import { uniqBy, cloneDeep } from 'lodash-es'
4
+ import { FormActionType, FormProps, FormSchema } from "../types/form.type"
5
+ import { handleInputNumberValue } from "./helper"
6
+
7
+ /** =================================
8
+ * 定义表单的事件
9
+ * =================================*/
10
+ type FormEventsType = {
11
+ emit: (event: string, ...args: any[]) => void
12
+ getProps: ComputedRef<FormProps>;
13
+ getSchema: ComputedRef<FormSchema[]>
14
+ formModel: Recordable,
15
+ defaultValue: Ref<Recordable>,
16
+ formElRef: Ref<FormActionType>,
17
+ schemaRef: Ref<FormSchema[]>,
18
+ handleFormValues: Function;
19
+ }
20
+
21
+ export function useFormEvents({
22
+ emit,
23
+ getSchema,
24
+ formModel,
25
+ defaultValue,
26
+ formElRef,
27
+ schemaRef,
28
+ handleFormValues
29
+ }: FormEventsType) {
30
+
31
+ /**
32
+ * 获取form表单的值
33
+ */
34
+ function getFormValues() {
35
+ const formEl = unref(formElRef);
36
+ if (!formEl) return {};
37
+
38
+ return handleFormValues(toRaw(unref(formModel)))
39
+ }
40
+
41
+ /**
42
+ * 更新表单的值
43
+ */
44
+ function updateSchema(data: Partial<FormSchema> | Partial<FormSchema>[]): Promise<void> {
45
+ let updateItems: Partial<FormSchema>[] = []
46
+
47
+ updateItems = isObject(data)
48
+ ? [ data as FormSchema ]
49
+ : [...data]
50
+
51
+ if( updateItems.every( it => it.component !== 'Divider' && !it.name ) ) {
52
+ console.error( '所有的元素都必须设置name属性' )
53
+ return
54
+ }
55
+
56
+ let schema: FormSchema[] = []
57
+ updateItems.forEach( it => {
58
+ unref(getSchema).forEach( val => {
59
+ if( val.name === it.name ) {
60
+ const newSchema = deepMerge(val, it)
61
+ schema.push(newSchema as FormSchema)
62
+ } else {
63
+ schema.push(val)
64
+ }
65
+ } )
66
+ } )
67
+
68
+ schemaRef.value = uniqBy(schema, 'name')
69
+ }
70
+
71
+
72
+ /**
73
+ * 重新设置schema
74
+ */
75
+ function resetSchema(data: Partial<FormSchema> | Partial<FormSchema>[]): Promise<void> {
76
+ let updateItems: Partial<FormSchema>[] = []
77
+
78
+ updateItems = isObject(data)
79
+ ? [ data as FormSchema ]
80
+ : [...data]
81
+
82
+ if( updateItems.every( it => it.component !== 'Divider' && !it.name ) ) {
83
+ console.error( '所有的元素都必须设置name属性' )
84
+ return
85
+ }
86
+
87
+ schemaRef.value = updateItems as FormSchema[]
88
+ }
89
+
90
+ /**
91
+ * 清除验证条件
92
+ */
93
+ async function clearValidate(name?: string | string[]) {
94
+ await unref(formElRef)?.clearValidate(name);
95
+ }
96
+
97
+ /**
98
+ * 重置form表单
99
+ */
100
+ function resetForms() {
101
+ if ( !unref(formElRef) ) return
102
+
103
+ Object.keys( formModel ).forEach( key => {
104
+ const schema = unref(getSchema).find((item) => item.name === key)
105
+ const isInput =
106
+ schema?.component &&
107
+ ['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(schema.component)
108
+
109
+ formModel[key] = isInput ? defaultValue.value[key] || '' : defaultValue.value[key]
110
+
111
+ } )
112
+
113
+ nextTick(() => clearValidate())
114
+
115
+ emit('reset', toRaw(formModel))
116
+ }
117
+
118
+ /**
119
+ * 根据属性名删除表单
120
+ */
121
+ function removeFormByName(names: string | string[]) {
122
+ if( !names ) return
123
+
124
+ const schemaList: FormSchema[] = cloneDeep(unref(getSchema))
125
+ const nameList: string[] = isString(names) ? [names] : names
126
+
127
+ for (const name of nameList) {
128
+ _removeSchemaByName(name, schemaList);
129
+ }
130
+ schemaRef.value = schemaList
131
+ }
132
+
133
+ function _removeSchemaByName(name: string, schemaList: FormSchema[]) {
134
+ const index = schemaList.findIndex((schema) => schema.name === name);
135
+ if (index !== -1) {
136
+ delete formModel[name];
137
+ schemaList.splice(index, 1);
138
+ }
139
+ }
140
+
141
+
142
+ /**
143
+ * 设置属性的值
144
+ */
145
+ function setFormValues(values: Recordable | null): Promise<void> {
146
+
147
+ if( !values || !Object.keys( values ).length ) {
148
+ for(let it in formModel) formModel[it] = Array.isArray(formModel[it]) ? [] : null
149
+ return
150
+ }
151
+
152
+ const names = unref(getSchema).map((item) => item.name).filter(Boolean)
153
+
154
+ const validKeys: string[] = []
155
+
156
+ Object.keys(values).forEach( key => {
157
+ const schema = unref(getSchema).find((item) => item.name === key)
158
+ let value = values[key]
159
+
160
+ const hasKey = Reflect.has(values, key)
161
+
162
+ value = handleInputNumberValue(schema?.component, value)
163
+
164
+ if (hasKey && names.includes(key)) {
165
+ if( itemIsDateType(key) ) {
166
+ if (Array.isArray(value)) {
167
+ const arr: any[] = [];
168
+ for (const ele of value) {
169
+ arr.push(ele ? dateFormat(ele) : null);
170
+ }
171
+ formModel[key] = arr;
172
+ } else {
173
+ const { props } = schema || {}
174
+
175
+ let _props = props as any
176
+
177
+ if (typeof props === 'function') {
178
+ _props = props({ formModel });
179
+ }
180
+ formModel[key] = value ? (_props?.valueFormat ? value : dateFormat(value)) : null
181
+ }
182
+ } else {
183
+ formModel[key] = value
184
+ }
185
+
186
+ validKeys.push(key)
187
+ }
188
+ } )
189
+
190
+ return validateFields(validKeys).catch((_) => {})
191
+ }
192
+
193
+ /**
194
+ * 动态添加一个表单
195
+ */
196
+ function appendFormItems(schema: FormSchema, prefixName?: string, first = false) {
197
+ const schemaList: FormSchema[] = cloneDeep(unref(getSchema))
198
+
199
+ const index = schemaList.findIndex((schema) => schema.name === prefixName)
200
+
201
+ if (!prefixName || index === -1 || first) {
202
+ first ? schemaList.unshift(schema) : schemaList.push(schema);
203
+ schemaRef.value = schemaList;
204
+ return;
205
+ }
206
+
207
+ if (index !== -1) {
208
+ schemaList.splice(index + 1, 0, schema);
209
+ }
210
+
211
+ schemaRef.value = schemaList;
212
+ }
213
+
214
+ /**
215
+ * 检验有效的属性值
216
+ */
217
+ async function validate(nameList: (string | number)[]) {
218
+ return await unref(formElRef)?.validate(nameList);
219
+ }
220
+
221
+ /**
222
+ * 返回有效的区域
223
+ */
224
+ async function validateFields(nameList: (string | number)[]) {
225
+ return unref(formElRef)?.validateFields(nameList);
226
+ }
227
+
228
+ function itemIsDateType(key: string) {
229
+ return unref(getSchema).some((item) => {
230
+ return item.name === key ? ['DatePicker', 'MonthPicker', 'WeekPicker', 'TimePicker', 'RangePicker'].includes(item.component) : false;
231
+ });
232
+ }
233
+
234
+
235
+ return {
236
+ updateSchema,
237
+ resetSchema,
238
+ clearValidate,
239
+ resetForms,
240
+ removeFormByName,
241
+ setFormValues,
242
+ appendFormItems,
243
+ getFormValues,
244
+ validate,
245
+ validateFields
246
+ }
247
+ }
@@ -0,0 +1,49 @@
1
+ import { Recordable } from "@dt-frames/core";
2
+ import { getCurrentInstance, Ref, reactive, readonly, watchEffect, computed, nextTick, toRaw, unref } from "vue";
3
+ import { isEqual } from 'lodash-es'
4
+
5
+ export function useFormValue<T extends Recordable>(
6
+ props: T,
7
+ key: keyof T = 'value',
8
+ changeEvent = 'change',
9
+ emitData?: Ref<any[]>
10
+ ) {
11
+ const instance = getCurrentInstance()
12
+ const emit = instance?.emit
13
+
14
+ const innerState = reactive({
15
+ value: props[key]
16
+ })
17
+
18
+ const defaultState = readonly(innerState)
19
+
20
+ const setState = ( val: any ) => {
21
+ innerState.value = val
22
+
23
+ nextTick(() => {
24
+ emit?.(changeEvent, val, ...(toRaw(unref(emitData)) || []))
25
+ })
26
+ }
27
+
28
+ watchEffect(() => {
29
+ innerState.value = props[key]
30
+ })
31
+
32
+ const state: any = computed({
33
+ get() {
34
+ return innerState.value
35
+ },
36
+ set(value) {
37
+ if( isEqual(value, defaultState.value) ) return
38
+
39
+ innerState.value = value as T[keyof T]
40
+
41
+ nextTick(() => {
42
+ emit?.(changeEvent, value, ...(toRaw(unref(emitData)) || []))
43
+ })
44
+
45
+ }
46
+ })
47
+
48
+ return [state, setState, defaultState]
49
+ }
@@ -0,0 +1,131 @@
1
+ /** =========================================================
2
+ * 处理表单的值
3
+ * ==========================================================*/
4
+ import { dateFormat, isFunction, isObject, isString, Recordable } from "@dt-frames/core";
5
+ import { isArray } from "@vue/shared";
6
+ import { set } from "lodash-es";
7
+ import dayjs from "dayjs";
8
+ import { ComputedRef, Ref, unref } from "vue";
9
+ import { FormProps, FormSchema } from "../types/form.type";
10
+ import { datePickerType } from "./helper";
11
+
12
+ type FormValueOptions = {
13
+ getProps: ComputedRef<FormProps>
14
+ defaultValue: Ref<any>
15
+ getSchema: ComputedRef<FormSchema[]>
16
+ formModel: Recordable
17
+ }
18
+
19
+ export function useFormValues({
20
+ defaultValue,
21
+ getSchema,
22
+ formModel,
23
+ getProps
24
+ }: FormValueOptions) {
25
+
26
+ /**
27
+ * 可以动态获取formModel的值
28
+ */
29
+ function handleFormValues(values: Recordable) {
30
+ if( !isObject(values) ) return { }
31
+
32
+ const res: Recordable = {}
33
+
34
+ for(let [key, value] of Object.entries(values)) {
35
+ if( !key || (Array.isArray(value) && value.length === 0) || isFunction(value) ) {
36
+ continue
37
+ }
38
+
39
+ /**
40
+ * TODO 这里需要对时间进行处理
41
+ */
42
+
43
+
44
+ if ( isString(value) ) {
45
+ value = value.trim();
46
+ }
47
+
48
+ set(res, key, value)
49
+ }
50
+
51
+ return res
52
+ }
53
+
54
+
55
+ /**
56
+ * 设置默认值
57
+ * 设置初始化的formModel值
58
+ */
59
+ function initDefault() {
60
+ const schema = unref( getSchema )
61
+ const obj: Recordable = {}
62
+
63
+ schema.forEach( item => {
64
+
65
+ const { props = {}, name, component } = item
66
+
67
+ let { defaultValue, mode, format, treeCheckable } = isFunction( props ) ? props() : props
68
+ const names: string[] = isString(name) ? [ name ] : name
69
+
70
+ if( defaultValue !== null && defaultValue !== undefined ) {
71
+
72
+ // 处理时间
73
+ if( datePickerType.includes(component) ) {
74
+ const modeType = {
75
+ time: 'YYYY-MM-DD HH:mm:ss',
76
+ date: 'YYYY-MM-DD',
77
+ month: 'YYYY-MM',
78
+ year: 'YYYY'
79
+ }
80
+
81
+ const _format = format || ( modeType[mode] ) || modeType.date
82
+
83
+ if ( !isArray(defaultValue) ) {
84
+ // 单个时间
85
+ obj[names[0]] = dayjs(defaultValue, _format)
86
+ formModel[names[0]] = dayjs(defaultValue, _format)
87
+ } else {
88
+
89
+ // 范围时间
90
+ let rangeTimes = defaultValue.reduce(( t, it ) => {
91
+ t.push( dayjs(it, _format) )
92
+ return t
93
+ }, [])
94
+
95
+ obj[names[0]] = rangeTimes
96
+ formModel[names[0]] = rangeTimes
97
+ }
98
+ } else {
99
+ // 如果names是数组 则代表有多个默认值 如 InputGroup
100
+ if( names.length > 1 ) {
101
+ names.forEach( ( key, index ) => {
102
+ obj[ key ] = defaultValue[ index ]
103
+ formModel[ key ] = defaultValue[ index ]
104
+ } )
105
+ } else {
106
+ obj[names[0]] = defaultValue
107
+ formModel[names[0]] = defaultValue
108
+ }
109
+ }
110
+ } else {
111
+ names.forEach( ( key, index ) => {
112
+ let defaultV = null
113
+ // 如果为树结构且为多选 或者复选框为多选状态
114
+ if( (component === 'TreeSelect' && (mode === 'multiple' || treeCheckable)) ||
115
+ (component === 'Select' && mode === 'multiple') ) {
116
+ defaultV = []
117
+ }
118
+
119
+ formModel[ key ] = obj[ key ] = defaultV
120
+ } )
121
+ }
122
+ } )
123
+
124
+ defaultValue.value = obj
125
+ }
126
+
127
+ return {
128
+ handleFormValues,
129
+ initDefault
130
+ }
131
+ }
@@ -0,0 +1,57 @@
1
+ /** =========================================================
2
+ * 处理表单的label宽度问题
3
+ * ==========================================================*/
4
+
5
+ import { isString, isNumber, useAppStore } from "@dt-frames/core";
6
+ import { computed, Ref, unref } from "vue";
7
+ import { FormProps, FormSchema } from "../types/form.type";
8
+
9
+ // 计算label的宽度
10
+ export function useLabelWidth(schemaItemRef: Ref<FormSchema>, propsRef: Ref<FormProps>) {
11
+ return computed(() => {
12
+ // 当前元素上关于label的设置
13
+ const { labelWidth, labelCol = { }, wrapperCol = { } } = unref( schemaItemRef )
14
+ // 获取全局配置
15
+ const { appConf } = useAppStore()
16
+
17
+ // 整个form关于label的设置
18
+ const {
19
+ labelWidth: gLabelWidth,
20
+ labelCol: glabelCol,
21
+ wrapperCol: gwrapperCol,
22
+ layout = appConf.ui.form.layout
23
+ } = unref( propsRef )
24
+
25
+ // 如果宽度设置为0
26
+ if( (isString(labelWidth) || isNumber(labelWidth)) && Number(labelWidth.toString()) === 0 ) {
27
+ return {
28
+ labelCol: {
29
+ ...labelCol,
30
+ ...{ style: { textAlign: 'left' } }
31
+ },
32
+ wrapperCol
33
+ }
34
+ }
35
+
36
+ let width = labelWidth || gLabelWidth
37
+ const labelcol = { ...glabelCol, ...labelCol }
38
+ const wrapcol = { ...gwrapperCol, ...wrapperCol }
39
+
40
+ if (width) {
41
+ width = isNumber(width) ? `${width}px` : width
42
+ }
43
+
44
+ return {
45
+ labelCol: {
46
+ style: { width },
47
+ ...labelcol
48
+ },
49
+ wrapperCol: {
50
+ style: { width: layout === 'vertical' ? '100%' : `calc(100% - ${width})` },
51
+ ...wrapcol
52
+ }
53
+ }
54
+
55
+ })
56
+ }
57
+