@aoao-y33/ui 0.0.2

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 (211) hide show
  1. package/README.md +811 -0
  2. package/dist/button/components/button/button.vue.d.ts +22 -0
  3. package/dist/button/components/button/button.vue.d.ts.map +1 -0
  4. package/dist/button/components/button/index.d.ts +3 -0
  5. package/dist/button/components/button/index.d.ts.map +1 -0
  6. package/dist/button/components/button/props.d.ts +21 -0
  7. package/dist/button/components/button/props.d.ts.map +1 -0
  8. package/dist/button/components/fields/index.d.ts +2 -0
  9. package/dist/button/components/fields/index.d.ts.map +1 -0
  10. package/dist/button/hoc/index.d.ts +2 -0
  11. package/dist/button/hoc/index.d.ts.map +1 -0
  12. package/dist/button/hoc/useButton.d.ts +19 -0
  13. package/dist/button/hoc/useButton.d.ts.map +1 -0
  14. package/dist/button/index.d.ts +5 -0
  15. package/dist/button/index.d.ts.map +1 -0
  16. package/dist/button/utils/index.d.ts +4 -0
  17. package/dist/button/utils/index.d.ts.map +1 -0
  18. package/dist/common/index.d.ts +2 -0
  19. package/dist/common/index.d.ts.map +1 -0
  20. package/dist/common/utils/iconUtils.d.ts +2 -0
  21. package/dist/common/utils/iconUtils.d.ts.map +1 -0
  22. package/dist/common/utils/index.d.ts +2 -0
  23. package/dist/common/utils/index.d.ts.map +1 -0
  24. package/dist/form/components/fields/index.d.ts +2 -0
  25. package/dist/form/components/fields/index.d.ts.map +1 -0
  26. package/dist/form/components/form/form.vue.d.ts +42 -0
  27. package/dist/form/components/form/form.vue.d.ts.map +1 -0
  28. package/dist/form/components/form/index.d.ts +90 -0
  29. package/dist/form/components/form/index.d.ts.map +1 -0
  30. package/dist/form/components/form/props.d.ts +21 -0
  31. package/dist/form/components/form/props.d.ts.map +1 -0
  32. package/dist/form/components/form-item/form-item.vue.d.ts +19 -0
  33. package/dist/form/components/form-item/form-item.vue.d.ts.map +1 -0
  34. package/dist/form/components/form-item/index.d.ts +31 -0
  35. package/dist/form/components/form-item/index.d.ts.map +1 -0
  36. package/dist/form/components/form-item/props.d.ts +14 -0
  37. package/dist/form/components/form-item/props.d.ts.map +1 -0
  38. package/dist/form/hoc/index.d.ts +4 -0
  39. package/dist/form/hoc/index.d.ts.map +1 -0
  40. package/dist/form/hoc/useForm.d.ts +13 -0
  41. package/dist/form/hoc/useForm.d.ts.map +1 -0
  42. package/dist/form/hoc/useFormExpose.d.ts +24 -0
  43. package/dist/form/hoc/useFormExpose.d.ts.map +1 -0
  44. package/dist/form/hoc/useFormFetch.d.ts +25 -0
  45. package/dist/form/hoc/useFormFetch.d.ts.map +1 -0
  46. package/dist/form/index.d.ts +6 -0
  47. package/dist/form/index.d.ts.map +1 -0
  48. package/dist/form/utils/index.d.ts +9 -0
  49. package/dist/form/utils/index.d.ts.map +1 -0
  50. package/dist/global.d.ts +33 -0
  51. package/dist/global.d.ts.map +1 -0
  52. package/dist/index.css +3 -0
  53. package/dist/index.d.ts +12 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +38948 -0
  56. package/dist/layout/components/fields/basic/basic.vue.d.ts +20 -0
  57. package/dist/layout/components/fields/basic/basic.vue.d.ts.map +1 -0
  58. package/dist/layout/components/fields/index.d.ts +2 -0
  59. package/dist/layout/components/fields/index.d.ts.map +1 -0
  60. package/dist/layout/components/fields/side/side.vue.d.ts +20 -0
  61. package/dist/layout/components/fields/side/side.vue.d.ts.map +1 -0
  62. package/dist/layout/components/fields/top/top.vue.d.ts +18 -0
  63. package/dist/layout/components/fields/top/top.vue.d.ts.map +1 -0
  64. package/dist/layout/components/layout/index.d.ts +22 -0
  65. package/dist/layout/components/layout/index.d.ts.map +1 -0
  66. package/dist/layout/components/layout/layout.vue.d.ts +15 -0
  67. package/dist/layout/components/layout/layout.vue.d.ts.map +1 -0
  68. package/dist/layout/components/layout/props.d.ts +4 -0
  69. package/dist/layout/components/layout/props.d.ts.map +1 -0
  70. package/dist/layout/hoc/index.d.ts +2 -0
  71. package/dist/layout/hoc/index.d.ts.map +1 -0
  72. package/dist/layout/hoc/useLayout.d.ts +12 -0
  73. package/dist/layout/hoc/useLayout.d.ts.map +1 -0
  74. package/dist/layout/index.d.ts +5 -0
  75. package/dist/layout/index.d.ts.map +1 -0
  76. package/dist/layout/utils/index.d.ts +4 -0
  77. package/dist/layout/utils/index.d.ts.map +1 -0
  78. package/dist/modal/components/form-modal/form-modal.vue.d.ts +46 -0
  79. package/dist/modal/components/form-modal/form-modal.vue.d.ts.map +1 -0
  80. package/dist/modal/components/form-modal/index.d.ts +101 -0
  81. package/dist/modal/components/form-modal/index.d.ts.map +1 -0
  82. package/dist/modal/components/form-modal/props.d.ts +19 -0
  83. package/dist/modal/components/form-modal/props.d.ts.map +1 -0
  84. package/dist/modal/components/modal/index.d.ts +53 -0
  85. package/dist/modal/components/modal/index.d.ts.map +1 -0
  86. package/dist/modal/components/modal/modal.vue.d.ts +29 -0
  87. package/dist/modal/components/modal/modal.vue.d.ts.map +1 -0
  88. package/dist/modal/components/modal/props.d.ts +24 -0
  89. package/dist/modal/components/modal/props.d.ts.map +1 -0
  90. package/dist/modal/hoc/index.d.ts +4 -0
  91. package/dist/modal/hoc/index.d.ts.map +1 -0
  92. package/dist/modal/hoc/useFormModal.d.ts +13 -0
  93. package/dist/modal/hoc/useFormModal.d.ts.map +1 -0
  94. package/dist/modal/hoc/useModal.d.ts +12 -0
  95. package/dist/modal/hoc/useModal.d.ts.map +1 -0
  96. package/dist/modal/hoc/useModalExpose.d.ts +8 -0
  97. package/dist/modal/hoc/useModalExpose.d.ts.map +1 -0
  98. package/dist/modal/index.d.ts +4 -0
  99. package/dist/modal/index.d.ts.map +1 -0
  100. package/dist/table/components/fields/action-column/action-column.vue.d.ts +6 -0
  101. package/dist/table/components/fields/action-column/action-column.vue.d.ts.map +1 -0
  102. package/dist/table/components/fields/action-column/props.d.ts +8 -0
  103. package/dist/table/components/fields/action-column/props.d.ts.map +1 -0
  104. package/dist/table/components/fields/index.d.ts +2 -0
  105. package/dist/table/components/fields/index.d.ts.map +1 -0
  106. package/dist/table/components/table/index.d.ts +58 -0
  107. package/dist/table/components/table/index.d.ts.map +1 -0
  108. package/dist/table/components/table/props.d.ts +43 -0
  109. package/dist/table/components/table/props.d.ts.map +1 -0
  110. package/dist/table/components/table/table.vue.d.ts +33 -0
  111. package/dist/table/components/table/table.vue.d.ts.map +1 -0
  112. package/dist/table/components/table-column/index.d.ts +6 -0
  113. package/dist/table/components/table-column/index.d.ts.map +1 -0
  114. package/dist/table/components/table-column/props.d.ts +6 -0
  115. package/dist/table/components/table-column/props.d.ts.map +1 -0
  116. package/dist/table/components/table-column/table-column.vue.d.ts +6 -0
  117. package/dist/table/components/table-column/table-column.vue.d.ts.map +1 -0
  118. package/dist/table/components/table-page/index.d.ts +12 -0
  119. package/dist/table/components/table-page/index.d.ts.map +1 -0
  120. package/dist/table/components/table-page/props.d.ts +13 -0
  121. package/dist/table/components/table-page/props.d.ts.map +1 -0
  122. package/dist/table/components/table-page/table-page.vue.d.ts +11 -0
  123. package/dist/table/components/table-page/table-page.vue.d.ts.map +1 -0
  124. package/dist/table/components/table-select/index.d.ts +73 -0
  125. package/dist/table/components/table-select/index.d.ts.map +1 -0
  126. package/dist/table/components/table-select/props.d.ts +21 -0
  127. package/dist/table/components/table-select/props.d.ts.map +1 -0
  128. package/dist/table/components/table-select/table-select.vue.d.ts +36 -0
  129. package/dist/table/components/table-select/table-select.vue.d.ts.map +1 -0
  130. package/dist/table/hoc/index.d.ts +3 -0
  131. package/dist/table/hoc/index.d.ts.map +1 -0
  132. package/dist/table/hoc/useTable.d.ts +33 -0
  133. package/dist/table/hoc/useTable.d.ts.map +1 -0
  134. package/dist/table/hoc/useTableExpose.d.ts +7 -0
  135. package/dist/table/hoc/useTableExpose.d.ts.map +1 -0
  136. package/dist/table/index.d.ts +8 -0
  137. package/dist/table/index.d.ts.map +1 -0
  138. package/dist/table/utils/index.d.ts +4 -0
  139. package/dist/table/utils/index.d.ts.map +1 -0
  140. package/package.json +42 -0
  141. package/src/button/components/button/button.vue +64 -0
  142. package/src/button/components/button/index.ts +2 -0
  143. package/src/button/components/button/props.ts +75 -0
  144. package/src/button/components/fields/index.ts +6 -0
  145. package/src/button/hoc/index.ts +1 -0
  146. package/src/button/hoc/useButton.ts +27 -0
  147. package/src/button/index.ts +4 -0
  148. package/src/button/utils/index.ts +32 -0
  149. package/src/common/index.ts +1 -0
  150. package/src/common/utils/iconUtils.ts +21 -0
  151. package/src/common/utils/index.ts +1 -0
  152. package/src/form/components/fields/index.ts +35 -0
  153. package/src/form/components/form/form.vue +130 -0
  154. package/src/form/components/form/index.ts +6 -0
  155. package/src/form/components/form/props.ts +73 -0
  156. package/src/form/components/form-item/form-item.vue +90 -0
  157. package/src/form/components/form-item/index.ts +6 -0
  158. package/src/form/components/form-item/props.ts +50 -0
  159. package/src/form/hoc/index.ts +3 -0
  160. package/src/form/hoc/useForm.ts +106 -0
  161. package/src/form/hoc/useFormExpose.ts +97 -0
  162. package/src/form/hoc/useFormFetch.ts +103 -0
  163. package/src/form/index.ts +5 -0
  164. package/src/form/utils/index.ts +149 -0
  165. package/src/global.ts +40 -0
  166. package/src/index.ts +37 -0
  167. package/src/layout/components/fields/basic/basic.vue +18 -0
  168. package/src/layout/components/fields/index.ts +10 -0
  169. package/src/layout/components/fields/side/side.vue +26 -0
  170. package/src/layout/components/fields/top/top.vue +13 -0
  171. package/src/layout/components/layout/index.ts +6 -0
  172. package/src/layout/components/layout/layout.vue +19 -0
  173. package/src/layout/components/layout/props.ts +3 -0
  174. package/src/layout/hoc/index.ts +1 -0
  175. package/src/layout/hoc/useLayout.ts +32 -0
  176. package/src/layout/index.ts +4 -0
  177. package/src/layout/utils/index.ts +31 -0
  178. package/src/modal/components/form-modal/form-modal.vue +158 -0
  179. package/src/modal/components/form-modal/index.ts +5 -0
  180. package/src/modal/components/form-modal/props.ts +61 -0
  181. package/src/modal/components/modal/index.ts +6 -0
  182. package/src/modal/components/modal/modal.vue +127 -0
  183. package/src/modal/components/modal/props.ts +78 -0
  184. package/src/modal/hoc/index.ts +3 -0
  185. package/src/modal/hoc/useFormModal.ts +140 -0
  186. package/src/modal/hoc/useModal.ts +151 -0
  187. package/src/modal/hoc/useModalExpose.ts +52 -0
  188. package/src/modal/index.ts +3 -0
  189. package/src/style/index.css +21 -0
  190. package/src/table/components/fields/action-column/action-column.vue +34 -0
  191. package/src/table/components/fields/action-column/props.ts +8 -0
  192. package/src/table/components/fields/index.ts +6 -0
  193. package/src/table/components/table/index.ts +6 -0
  194. package/src/table/components/table/props.ts +148 -0
  195. package/src/table/components/table/table.vue +77 -0
  196. package/src/table/components/table-column/index.ts +6 -0
  197. package/src/table/components/table-column/props.ts +26 -0
  198. package/src/table/components/table-column/table-column.vue +31 -0
  199. package/src/table/components/table-page/index.ts +6 -0
  200. package/src/table/components/table-page/props.ts +48 -0
  201. package/src/table/components/table-page/table-page.vue +51 -0
  202. package/src/table/components/table-select/index.ts +6 -0
  203. package/src/table/components/table-select/props.ts +79 -0
  204. package/src/table/components/table-select/table-select.vue +70 -0
  205. package/src/table/hoc/index.ts +2 -0
  206. package/src/table/hoc/useTable.ts +206 -0
  207. package/src/table/hoc/useTableExpose.ts +46 -0
  208. package/src/table/index.ts +7 -0
  209. package/src/table/utils/index.ts +37 -0
  210. package/tsconfig.json +30 -0
  211. package/vite.config.ts +49 -0
@@ -0,0 +1,97 @@
1
+ import type {Ref} from "vue";
2
+ import type {AxFormInstance} from "@/form";
3
+
4
+ /**
5
+ * 表单暴露钩子函数,提供统一的表单操作接口
6
+ *
7
+ * 该函数封装了表单的各种操作方法,包括获取值、设置值、重置等,
8
+ * 并通过泛型提供类型安全的访问方式
9
+ *
10
+ * @template T - 表单数据类型,必须是一个记录类型的对象
11
+ * @param form - 表单实例的Ref引用,指向AxFormInstance类型
12
+ * @returns 返回包含各种表单操作方法的对象
13
+ */
14
+ export type FormApi<T extends Record<string, any>> = ReturnType<typeof useFormExpose<T>>;
15
+
16
+ export function useFormExpose<T extends Record<string, any>>(form:Ref<AxFormInstance>){
17
+
18
+ /**
19
+ * 获取底层的Element UI表单实例
20
+ *
21
+ * @returns Element UI表单实例
22
+ */
23
+ const getElForm = () => {
24
+ return form.value.getElForm();
25
+ }
26
+
27
+ /**
28
+ * 获取表单的所有字段值
29
+ *
30
+ * @returns 表单所有字段的值对象,类型为T
31
+ */
32
+ const getValues = ():T => {
33
+ return form.value.getValues() as T;
34
+ }
35
+
36
+ /**
37
+ * 获取表单指定字段的值
38
+ *
39
+ * @param field - 要获取值的字段名称
40
+ * @returns 指定字段的值,类型为该字段在T中的对应类型
41
+ */
42
+ const getValue = (field:keyof T):T[keyof T] => {
43
+ return form.value.getValue(field as string) as T[keyof T];
44
+ }
45
+
46
+ /**
47
+ * 获取表单的所有字段名称列表
48
+ *
49
+ * @returns 表单字段名称数组,每个元素都是T的键类型
50
+ */
51
+ const getFields = ():(keyof T)[] => {
52
+ return form.value.getFields() as (keyof T)[];
53
+ }
54
+
55
+ /**
56
+ * 获取表单字段的默认值
57
+ *
58
+ * @returns 包含默认值的对象,可能只包含部分字段,类型为Partial<T>
59
+ */
60
+ const getDefaultValues = ():Partial<T> => {
61
+ return form.value.getDefaultValues() as Partial<T>;
62
+ }
63
+
64
+
65
+ /**
66
+ * 批量设置表单字段的值
67
+ *
68
+ * @param values - 要设置的值对象,可以只包含部分字段,类型为Partial<T>
69
+ */
70
+ const setValues = (values:Partial<T>) => {
71
+ form.value.setValues(values);
72
+ }
73
+
74
+ /**
75
+ * 重置表单所有字段的值到默认状态
76
+ */
77
+ const resetValues = () => {
78
+ form.value.resetValues();
79
+ }
80
+
81
+ /**
82
+ * 清空表单所有字段的值
83
+ */
84
+ const clearValues = () => {
85
+ form.value.clearValues();
86
+ }
87
+ return {
88
+ getElForm,
89
+ getValues,
90
+ getValue,
91
+ getFields,
92
+ getDefaultValues,
93
+ setValues,
94
+ resetValues,
95
+ clearValues
96
+ }
97
+ }
@@ -0,0 +1,103 @@
1
+ import type {Ref} from "vue";
2
+ import type {AxFormInstance} from "@/form";
3
+ import type {FetchOptions, RequestFetch} from "@aoao-y33/hooks";
4
+
5
+ export type FormFetchApi<T extends Record<string, any>> = ReturnType<typeof useFormFetch<T>>
6
+ /**
7
+ * 表单数据获取钩子函数,提供表单相关的API请求和数据加载功能
8
+ *
9
+ * 该函数封装了表单的配置设置、API绑定、数据加载等操作,
10
+ * 用于处理表单与服务端的数据交互
11
+ *
12
+ * @template T - 表单数据类型,必须是一个记录类型的对象
13
+ * @param formRef - 表单实例的Ref引用,指向AxFormInstance类型
14
+ * @returns 返回包含各种表单数据操作方法的对象
15
+ */
16
+ export function useFormFetch<T extends Record<string, any>,R=any>(formRef: Ref<AxFormInstance>) {
17
+
18
+ /**
19
+ * 设置表单的配置信息
20
+ *
21
+ * @param config - 表单配置选项,包含请求配置等信息
22
+ */
23
+ const setConfig = (config: FetchOptions<T, R>) => {
24
+ formRef.value.setConfig(config)
25
+ }
26
+
27
+ /**
28
+ * 设置表单的请求API方法
29
+ *
30
+ * @param api - 请求方法,用于从服务端获取或提交数据
31
+ */
32
+ const setApi = (api: RequestFetch<T, R>) => {
33
+ formRef.value.setApi(api)
34
+ }
35
+
36
+ /**
37
+ * 加载表单数据,可选择传入参数
38
+ *
39
+ * @param params - 可选的查询参数,用于过滤或指定要加载的数据
40
+ * @returns 返回Promise,解析为加载的数据结果
41
+ */
42
+ const load = (params?: T) => {
43
+ return formRef.value.load(params)
44
+ }
45
+
46
+ /**
47
+ * 获取当前表单的配置信息
48
+ *
49
+ * @returns 表单配置对象
50
+ */
51
+ const getConfig = () => {
52
+ return formRef.value.getConfig()
53
+ }
54
+
55
+ /**
56
+ * 获取表单实例
57
+ *
58
+ * @returns 表单实例对象
59
+ */
60
+ const get = () => {
61
+ return formRef.value.get()
62
+ }
63
+
64
+ /**
65
+ * 检查表单是否已准备好使用
66
+ *
67
+ * @returns 表单准备状态
68
+ */
69
+ const getReady = () => {
70
+ return formRef.value.getReady()
71
+ }
72
+
73
+ /**
74
+ * 设置表单参数,并可选择是否立即加载数据
75
+ *
76
+ * @param data - 要设置的参数数据
77
+ * @param load - 可选标志,指示设置参数后是否立即执行加载操作
78
+ * @returns 返回操作结果
79
+ */
80
+ const setParams = (data: T, load?: boolean) => {
81
+ return formRef.value.setParams(data, load)
82
+ }
83
+
84
+ /**
85
+ * 重新加载表单数据
86
+ *
87
+ * @returns 返回Promise,解析为重新加载的数据结果
88
+ */
89
+ const reload = () => {
90
+ return formRef.value.reload()
91
+ }
92
+
93
+ return{
94
+ setConfig,
95
+ setApi,
96
+ load,
97
+ getConfig,
98
+ get,
99
+ getReady,
100
+ setParams,
101
+ reload
102
+ }
103
+ }
@@ -0,0 +1,5 @@
1
+ export * from './components/form';
2
+ export * from './components/form-item';
3
+ export * from './components/fields';
4
+ export * from './utils';
5
+ export * from './hoc';
@@ -0,0 +1,149 @@
1
+ import type {Component} from "vue";
2
+ import type {FormItemRule} from "element-plus";
3
+
4
+ /**
5
+ * 表单项验证规则类型
6
+ * 支持三种形式的规则定义:
7
+ * - 直接的 FormItemRule 对象
8
+ * - 返回 FormItemRule 的函数(无参数)
9
+ * - 返回 FormItemRule 的函数(接收类型和标签参数)
10
+ */
11
+ export type VFormItemRule =
12
+ FormItemRule
13
+ | (() => FormItemRule)
14
+ | ((type: string,label?: string) => FormItemRule)
15
+
16
+ /**
17
+ * 表单字段组件注册表
18
+ * 存储字段类型与对应 Vue 组件的映射关系
19
+ * @example
20
+ * // 注册自定义输入组件
21
+ * formFields['custom-input'] = CustomInputComponent
22
+ */
23
+ export const formFields: Record<string, Component> = {};
24
+
25
+ /**
26
+ * 表单验证规则注册表
27
+ * 预定义了常用的表单验证规则
28
+ *
29
+ * 内置规则包括:
30
+ * - required: 必填验证,根据字段类型自动显示"请输入"或"请选择"
31
+ * - required2: 自定义验证器实现的必填验证
32
+ * - phone: 手机号格式验证(11位数字,以1开头,第二位3-9)
33
+ * - tel: 电话号码格式验证(带可选区号)
34
+ * - mail: 邮箱地址格式验证
35
+ */
36
+ export const formRules:Record<string, VFormItemRule> = {
37
+ /**
38
+ * 必填验证规则
39
+ * @param type - 字段类型,用于判断提示文本
40
+ * @param label - 字段标签名称
41
+ * @returns 验证规则对象
42
+ */
43
+ "required":(type:string,label:string="")=>
44
+ ({'required':true,message:isTip(type)+label}),
45
+
46
+ /**
47
+ * 基于自定义验证器的必填验证
48
+ * 使用 validator 函数实现更灵活的验证逻辑
49
+ */
50
+ "required2":()=>
51
+ ({
52
+ validator:(_:any,value:any,cb:any)=>{
53
+ if(!value){
54
+ cb(new Error())
55
+ }else {
56
+ cb();
57
+ }
58
+ }
59
+ }),
60
+
61
+ /**
62
+ * 手机号验证规则
63
+ * 匹配规则:^1[3-9]\d{9}$
64
+ * @param _ - 占位参数
65
+ * @param label - 字段标签名称,用于错误提示
66
+ */
67
+ "phone": (_,label="") =>
68
+ ({pattern: /^1[3-9]\d{9}$/, message: `${label}格式错误`}),
69
+
70
+ /**
71
+ * 固定电话号码验证规则
72
+ * 匹配规则:支持带区号或不带区号的格式,如 010-12345678 或 12345678
73
+ * @param _ - 占位参数
74
+ * @param label - 字段标签名称,用于错误提示
75
+ */
76
+ "tel":(_,label="")=>
77
+ ({pattern: /^(\d{3,4}-?)?\d{7,8}$/, message: `${label}格式错误`}),
78
+
79
+ /**
80
+ * 电子邮箱验证规则
81
+ * 匹配规则:标准邮箱格式(用户名@域名.后缀)
82
+ * @param _ - 占位参数
83
+ * @param label - 字段标签名称,用于错误提示
84
+ */
85
+ "mail":(_,label="")=>
86
+ ({pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, message: `${label}格式错误`}),
87
+ }
88
+
89
+ /**
90
+ * 注册新的表单字段组件
91
+ * 将自定义组件添加到表单字段注册表中
92
+ *
93
+ * @param type - 字段类型标识符(唯一)
94
+ * @param component - 对应的 Vue 组件
95
+ *
96
+ * @warning 如果类型已存在,会输出警告信息并阻止重复注册
97
+ *
98
+ * @example
99
+ * import CustomInput from './CustomInput.vue'
100
+ * addFormField('custom-input', CustomInput)
101
+ */
102
+ export const addFormField = (type: string, component: Component) => {
103
+ if (type in formFields) {
104
+ console.warn(`${type} has in formFields`);
105
+ return;
106
+ }
107
+ formFields[type] = component;
108
+ }
109
+
110
+ /**
111
+ * 注册新的表单验证规则
112
+ * 将自定义验证规则添加到规则注册表中
113
+ *
114
+ * @param type - 规则类型标识符(唯一)
115
+ * @param rule - 验证规则对象或函数
116
+ *
117
+ * @throws 如果规则类型已存在,抛出错误信息
118
+ *
119
+ * @example
120
+ * addFormRules('idCard', (type, label) => ({
121
+ * pattern: /^\d{17}[\dXx]$/,
122
+ * message: `${label}身份证号格式错误`
123
+ * }))
124
+ */
125
+ export const addFormRules=(type:string,rule:any)=>{
126
+ if(type in formRules){
127
+ throw `${type}类形的规则已存在`
128
+ }
129
+ formRules[type] = rule;
130
+ }
131
+
132
+ /**
133
+ * 根据字段类型获取验证提示前缀
134
+ * 对于选择类组件返回"请选择",其他类型返回"请输入"
135
+ *
136
+ * @param type - 字段类型
137
+ * @returns 提示文本前缀
138
+ *
139
+ * @example
140
+ * isTip('input') // "请输入"
141
+ * isTip('select') // "请选择"
142
+ * isTip('checkbox') // "请选择"
143
+ */
144
+ export const isTip=(type:string)=>{
145
+ if(["select","checkbox","cascade"].includes(type)){
146
+ return "请选择";
147
+ }
148
+ return "请输入";
149
+ }
package/src/global.ts ADDED
@@ -0,0 +1,40 @@
1
+ // global.ts
2
+ // @ts-ignore
3
+
4
+ import type { AxButton } from './button'
5
+ import type { AxForm } from './form'
6
+ import type { AxFormItem } from './form'
7
+ import type { AxLayout } from './layout'
8
+ import type { AxModal } from './modal'
9
+ import type { AxTable, AxTablePage, AxTableSelect, AxTableColumn } from './table'
10
+
11
+ declare module 'vue' {
12
+ export interface GlobalComponents {
13
+ AxButton: typeof AxButton
14
+ AxForm: typeof AxForm
15
+ AxFormItem: typeof AxFormItem
16
+ AxLayout: typeof AxLayout
17
+ AxModal: typeof AxModal
18
+ AxTable: typeof AxTable
19
+ AxTablePage: typeof AxTablePage
20
+ AxTableSelect: typeof AxTableSelect
21
+ AxTableColumn: typeof AxTableColumn
22
+ }
23
+ }
24
+
25
+ // 添加组件名称的 kebab-case 版本支持
26
+ declare module 'vue' {
27
+ export interface GlobalComponents {
28
+ 'ax-button': typeof AxButton
29
+ 'ax-form': typeof AxForm
30
+ 'ax-form-item': typeof AxFormItem
31
+ 'ax-layout': typeof AxLayout
32
+ 'ax-modal': typeof AxModal
33
+ 'ax-table': typeof AxTable
34
+ 'ax-table-page': typeof AxTablePage
35
+ 'ax-table-select': typeof AxTableSelect
36
+ 'ax-table-column': typeof AxTableColumn
37
+ }
38
+ }
39
+
40
+ export {}
package/src/index.ts ADDED
@@ -0,0 +1,37 @@
1
+ import './style/index.css';
2
+ import type {App} from "vue";
3
+ import './global';
4
+ import {AxButton, initButtonFields} from "@/button";
5
+ import {AxForm, AxFormItem, initFormFields} from "@/form";
6
+ import {AxLayout, initLayoutFields} from "@/layout";
7
+ import {AxTable, AxTableColumn, AxTablePage, AxTableSelect, initTableColumns} from "@/table";
8
+ import {AxModal} from "@/modal";
9
+
10
+ export * from './modal';
11
+ export * from './button';
12
+ export * from './form';
13
+ export * from './layout';
14
+ export * from './table';
15
+ export * from './common';
16
+ initButtonFields();
17
+ initFormFields();
18
+ initLayoutFields();
19
+ initTableColumns();
20
+
21
+ export default {
22
+ install(app: App) {
23
+ initFormFields();
24
+ initLayoutFields();
25
+ initTableColumns();
26
+ initButtonFields();
27
+ app.component("ax-button", AxButton);
28
+ app.component("ax-form", AxForm);
29
+ app.component("ax-form-item", AxFormItem);
30
+ app.component("ax-layout", AxLayout);
31
+ app.component("ax-modal", AxModal);
32
+ app.component("ax-table", AxTable);
33
+ app.component("ax-table-page", AxTablePage);
34
+ app.component("ax-table-select", AxTableSelect);
35
+ app.component("ax-table-column", AxTableColumn);
36
+ }
37
+ }
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <div class="w-full h-full flex flex-col overflow-hidden">
3
+ <header class="w-full">
4
+ <slot name="header"></slot>
5
+ </header>
6
+ <main class="flex flex-1 overflow-hidden h-full">
7
+ <aside class="h-full overflow-hidden">
8
+ <slot name="aside"></slot>
9
+ </aside>
10
+ <main class="flex-1 flex overflow-hidden h-full">
11
+ <slot name="main"></slot>
12
+ </main>
13
+ </main>
14
+ <footer class="w-full">
15
+ <slot name="footer"></slot>
16
+ </footer>
17
+ </div>
18
+ </template>
@@ -0,0 +1,10 @@
1
+ import basic from './basic/basic.vue';
2
+ import side from './side/side.vue';
3
+ import top from './top/top.vue';
4
+ import {addLayoutField} from "@/layout";
5
+
6
+ export const initLayoutFields = () => {
7
+ addLayoutField('basic', basic);
8
+ addLayoutField('side', side);
9
+ addLayoutField('top', top);
10
+ }
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <div class="w-full h-full flex overflow-hidden">
3
+ <aside class="h-full overflow-hidden">
4
+ <slot name="aside"></slot>
5
+ </aside>
6
+ <main class="h-full flex-1 flex flex-col overflow-hidden">
7
+ <header class="w-full">
8
+ <slot name="header"></slot>
9
+ </header>
10
+ <main class="flex-1 w-full overflow-hidden">
11
+ <slot name="main"></slot>
12
+ </main>
13
+ <footer class="w-full">
14
+ <slot name="footer"></slot>
15
+ </footer>
16
+ </main>
17
+ </div>
18
+ </template>
19
+
20
+ <script setup lang="ts">
21
+
22
+ </script>
23
+
24
+ <style scoped>
25
+
26
+ </style>
@@ -0,0 +1,13 @@
1
+ <template>
2
+ <div class="flex flex-col w-full h-full">
3
+ <header class="w-full">
4
+ <slot name="header"></slot>
5
+ </header>
6
+ <main class="flex-1 w-full flex overflow-hidden">
7
+ <slot name="main"></slot>
8
+ </main>
9
+ <footer class="w-full">
10
+ <slot name="footer"></slot>
11
+ </footer>
12
+ </div>
13
+ </template>
@@ -0,0 +1,6 @@
1
+ import layout from './layout.vue';
2
+
3
+ export * from './props';
4
+ export const AxLayout = layout;
5
+ export type AxLayoutInstance = InstanceType<typeof layout>;
6
+ export default AxLayout;
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <Layout>
3
+ <template v-for="slot in Object.keys(slots)" #[slot]>
4
+ <slot :name="slot"></slot>
5
+ </template>
6
+ </Layout>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import {type AxLayoutProps} from "./props";
11
+ import {computed, useSlots} from "vue";
12
+ import {layoutFields} from "@/layout";
13
+
14
+ const {type = 'basic'} = defineProps<AxLayoutProps>();
15
+ const slots = useSlots();
16
+ const Layout = computed(()=>{
17
+ return layoutFields[type]
18
+ })
19
+ </script>
@@ -0,0 +1,3 @@
1
+ export interface AxLayoutProps {
2
+ type?: string;
3
+ }
@@ -0,0 +1 @@
1
+ export * from './useLayout';
@@ -0,0 +1,32 @@
1
+ import {type Component, defineComponent, h, shallowRef} from "vue";
2
+ import {AxLayout} from "@/layout";
3
+ import {mergeDeep} from "@aoao-y33/utils";
4
+
5
+ export interface AxLayoutOptions {
6
+ type?: string;
7
+ header?:Component;
8
+ footer?:Component ;
9
+ main?:Component ;
10
+ aside?:Component ;
11
+ }
12
+ export function useLayout(options:AxLayoutOptions={}){
13
+ const props = shallowRef(options);
14
+ const setLayout=(options:AxLayoutOptions)=>{
15
+ props.value = mergeDeep(props.value,options);
16
+ }
17
+ const Layout = defineComponent({
18
+ setup(){
19
+ const slots:Record<string, Component> = {};
20
+ const keys = ['header','footer','main','aside'];
21
+
22
+ keys.forEach(key=>{
23
+ if(props.value?.[key as keyof typeof props.value]){
24
+ slots[key] = ()=>h(props.value[key as keyof typeof props.value] as Component)
25
+ }
26
+ })
27
+ return ()=>h(AxLayout as any,{type:props.value?.type},slots);
28
+ }
29
+ })
30
+
31
+ return [Layout,setLayout] as const;
32
+ }
@@ -0,0 +1,4 @@
1
+ export * from './components/layout';
2
+ export * from './components/fields';
3
+ export * from './hoc';
4
+ export * from './utils';
@@ -0,0 +1,31 @@
1
+ import type {Component} from "vue";
2
+
3
+ /**
4
+ * 布局组件注册表
5
+ * 存储布局类型与对应 Vue 组件的映射关系
6
+ * @example
7
+ * // 注册自定义布局组件
8
+ * addLayoutField('sidebar', SidebarLayoutComponent)
9
+ */
10
+ export const layoutFields:Record<string, Component> = {};
11
+
12
+ /**
13
+ * 注册新的布局类型组件
14
+ * 将自定义布局组件添加到布局类型注册表中
15
+ *
16
+ * @param type - 布局类型标识符(唯一)
17
+ * @param component - 对应的 Vue 组件
18
+ *
19
+ * @warning 如果类型已存在,会输出警告信息并阻止重复注册
20
+ *
21
+ * @example
22
+ * import CustomLayout from './CustomLayout.vue'
23
+ * addLayoutField('custom-layout', CustomLayout)
24
+ */
25
+ export const addLayoutField = (type: string, component: Component) => {
26
+ if (type in layoutFields) {
27
+ console.warn(`[AxLayout] Layout type ${type} already exists`)
28
+ return;
29
+ }
30
+ layoutFields[type] = component;
31
+ }