@aoao-y33/ui 0.0.3 → 0.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 (78) hide show
  1. package/README.md +0 -11
  2. package/dist/index.d.ts +0 -5
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -5
  5. package/package.json +9 -3
  6. package/dist/global.d.ts +0 -33
  7. package/dist/global.d.ts.map +0 -1
  8. package/src/button/components/button/button.vue +0 -64
  9. package/src/button/components/button/index.ts +0 -2
  10. package/src/button/components/button/props.ts +0 -75
  11. package/src/button/components/fields/index.ts +0 -6
  12. package/src/button/hoc/index.ts +0 -1
  13. package/src/button/hoc/useButton.ts +0 -27
  14. package/src/button/index.ts +0 -4
  15. package/src/button/utils/index.ts +0 -32
  16. package/src/common/index.ts +0 -1
  17. package/src/common/utils/iconUtils.ts +0 -21
  18. package/src/common/utils/index.ts +0 -1
  19. package/src/form/components/fields/index.ts +0 -35
  20. package/src/form/components/form/form.vue +0 -130
  21. package/src/form/components/form/index.ts +0 -6
  22. package/src/form/components/form/props.ts +0 -73
  23. package/src/form/components/form-item/form-item.vue +0 -90
  24. package/src/form/components/form-item/index.ts +0 -6
  25. package/src/form/components/form-item/props.ts +0 -50
  26. package/src/form/hoc/index.ts +0 -3
  27. package/src/form/hoc/useForm.ts +0 -106
  28. package/src/form/hoc/useFormExpose.ts +0 -97
  29. package/src/form/hoc/useFormFetch.ts +0 -103
  30. package/src/form/index.ts +0 -5
  31. package/src/form/utils/index.ts +0 -149
  32. package/src/global.ts +0 -40
  33. package/src/index.ts +0 -37
  34. package/src/layout/components/fields/basic/basic.vue +0 -18
  35. package/src/layout/components/fields/index.ts +0 -10
  36. package/src/layout/components/fields/side/side.vue +0 -26
  37. package/src/layout/components/fields/top/top.vue +0 -13
  38. package/src/layout/components/layout/index.ts +0 -6
  39. package/src/layout/components/layout/layout.vue +0 -19
  40. package/src/layout/components/layout/props.ts +0 -3
  41. package/src/layout/hoc/index.ts +0 -1
  42. package/src/layout/hoc/useLayout.ts +0 -32
  43. package/src/layout/index.ts +0 -4
  44. package/src/layout/utils/index.ts +0 -31
  45. package/src/modal/components/form-modal/form-modal.vue +0 -158
  46. package/src/modal/components/form-modal/index.ts +0 -5
  47. package/src/modal/components/form-modal/props.ts +0 -61
  48. package/src/modal/components/modal/index.ts +0 -6
  49. package/src/modal/components/modal/modal.vue +0 -127
  50. package/src/modal/components/modal/props.ts +0 -78
  51. package/src/modal/hoc/index.ts +0 -3
  52. package/src/modal/hoc/useFormModal.ts +0 -140
  53. package/src/modal/hoc/useModal.ts +0 -151
  54. package/src/modal/hoc/useModalExpose.ts +0 -52
  55. package/src/modal/index.ts +0 -3
  56. package/src/style/index.css +0 -21
  57. package/src/table/components/fields/action-column/action-column.vue +0 -34
  58. package/src/table/components/fields/action-column/props.ts +0 -8
  59. package/src/table/components/fields/index.ts +0 -6
  60. package/src/table/components/table/index.ts +0 -6
  61. package/src/table/components/table/props.ts +0 -148
  62. package/src/table/components/table/table.vue +0 -77
  63. package/src/table/components/table-column/index.ts +0 -6
  64. package/src/table/components/table-column/props.ts +0 -26
  65. package/src/table/components/table-column/table-column.vue +0 -31
  66. package/src/table/components/table-page/index.ts +0 -6
  67. package/src/table/components/table-page/props.ts +0 -48
  68. package/src/table/components/table-page/table-page.vue +0 -51
  69. package/src/table/components/table-select/index.ts +0 -6
  70. package/src/table/components/table-select/props.ts +0 -79
  71. package/src/table/components/table-select/table-select.vue +0 -70
  72. package/src/table/hoc/index.ts +0 -2
  73. package/src/table/hoc/useTable.ts +0 -206
  74. package/src/table/hoc/useTableExpose.ts +0 -46
  75. package/src/table/index.ts +0 -7
  76. package/src/table/utils/index.ts +0 -37
  77. package/tsconfig.json +0 -30
  78. package/vite.config.ts +0 -49
@@ -1,90 +0,0 @@
1
- <script setup lang="ts">
2
- import {ElFormItem, type FormItemInstance} from "element-plus";
3
- import type {AxFormItemProps} from "./props";
4
- import {computed, inject, onUnmounted, ref, useAttrs, useSlots} from "vue";
5
- import {formFields, formRules, isTip} from "@/form";
6
- import {useDefineProps} from "@aoao-y33/hooks";
7
-
8
- defineOptions({name: 'ax-form-item'});
9
- const {
10
- type = 'text',
11
- fieldName,
12
- label = "",
13
- componentProps = {},
14
- placeholder,
15
- vtypes = [],
16
- rules = [],
17
- defaultValue,
18
- ...props
19
- } = defineProps<AxFormItemProps>()
20
- const attrs = useAttrs();
21
- const slots = useSlots();
22
- const itemProps = useDefineProps(props);
23
- const formData = inject('formData', null) as Record<string, any> | null;
24
- const defaultData = inject('defaultData', {}) as Record<string, any>;
25
- if (formData) {
26
- defaultData[fieldName] = defaultValue;
27
- formData[fieldName] = defaultData[fieldName];
28
- }
29
- const FormField = computed(() => {
30
- return formFields[type];
31
- })
32
- const _placeholder = computed(() => {
33
- if (placeholder) {
34
- return placeholder;
35
- }
36
- return isTip(type) + (label || '');
37
- })
38
- const _rules = computed(() => {
39
- const validates = vtypes.map(item => {
40
- if (typeof formRules[item] === 'function') {
41
- return formRules[item](type, label);
42
- }
43
- return formRules[item];
44
- });
45
- return validates.concat(rules) as any;
46
- })
47
-
48
- onUnmounted(() => {
49
- if (formData) {
50
- delete formData[fieldName as string];
51
- }
52
- })
53
-
54
- const formItemRef = ref<FormItemInstance>();
55
-
56
- const instanceRef = ref<typeof FormField.value>();
57
-
58
- const getElFormItem=()=>{
59
- return formItemRef.value as FormItemInstance;
60
- }
61
- const getFormField=()=>{
62
- return instanceRef.value as any
63
- }
64
-
65
- defineExpose({
66
- getElFormItem,
67
- getFormField
68
- })
69
- </script>
70
- <template>
71
- <ElFormItem
72
- v-if="formData"
73
- v-bind="itemProps"
74
- :label="label"
75
- :prop="fieldName"
76
- :rules="_rules"
77
- ref="formItemRef"
78
- >
79
- <FormField
80
- ref="instanceRef"
81
- v-bind="{...componentProps,...attrs}"
82
- v-model="formData[fieldName]"
83
- :placeholder="_placeholder"
84
- >
85
- <template v-for="slot in Object.keys(slots)" #[slot]>
86
- <slot :name="slot"></slot>
87
- </template>
88
- </FormField>
89
- </ElFormItem>
90
- </template>
@@ -1,6 +0,0 @@
1
- import FormItem from './form-item.vue';
2
-
3
- export * from './props';
4
- export const AxFormItem = FormItem;
5
- export type AxFormItemInstance = InstanceType<typeof FormItem>;
6
- export default AxFormItem;
@@ -1,50 +0,0 @@
1
- import type {FormItemProps} from "element-plus";
2
-
3
- /**
4
- * AxFormItem 表单项组件属性接口
5
- * 继承自 Element Plus FormItemProps,扩展了自定义字段配置功能
6
- */
7
- export interface AxFormItemProps extends FormItemProps{
8
- /** 字段名称,用于表单数据绑定和验证的唯一标识 */
9
- fieldName:string;
10
-
11
- /** 表单项的标签文本,显示在输入框左侧或上方 */
12
- label?: string;
13
-
14
- /**
15
- * 表单项类型,决定渲染的输入组件类型
16
- * @example 'input' | 'select' | 'textarea' | 'date-picker' 等
17
- */
18
- type?: string;
19
-
20
- /**
21
- * 验证规则类型数组,用于表单字段验证
22
- * @example ['required', 'email', 'phone'] 等预定义验证规则
23
- */
24
- vtypes?: string[];
25
-
26
- /** 字段的默认值,当表单初始化时自动填充 */
27
- defaultValue?: any;
28
-
29
- /**
30
- * 底层组件的额外属性配置
31
- * 透传给实际渲染的输入组件(如 Input、Select 等)
32
- */
33
- componentProps?:Record<string, any>
34
-
35
- /** 输入框的占位符文本,提示用户输入内容 */
36
- placeholder?:string
37
- }
38
-
39
- /**
40
- * AxFormItem 表单项配置选项接口
41
- * 继承自 AxFormItemProps,增加了插槽配置能力
42
- */
43
- export interface AxFormItemOptions extends AxFormItemProps{
44
- /**
45
- * 自定义插槽配置,用于覆盖表单项的默认渲染内容
46
- * key 为插槽名称,value 为插槽内容或渲染函数
47
- * @example { default: () => h('div', '自定义内容') }
48
- */
49
- slots?:Record<string, any>
50
- }
@@ -1,3 +0,0 @@
1
- export * from './useForm';
2
- export * from './useFormExpose';
3
- export * from './useFormFetch';
@@ -1,106 +0,0 @@
1
- import {AxForm, AxFormItem, type AxFormItemOptions, useFormExpose, useFormFetch} from "@/form";
2
- import {AxButton} from '@/button';
3
- import { type AxButtonOptions} from "@/button";
4
- import {type FieldsApi, useComponentPool, useState} from "@aoao-y33/hooks";
5
- import {omit} from "lodash";
6
- import type {AxFormInstance, AxFormOptions, FormApi, FormFetchApi} from '@/form';
7
- import type { StateApi} from "@aoao-y33/hooks";
8
- import {type Component, defineComponent, h, type Ref, ref} from "vue";
9
-
10
- /**
11
- * UseForm 返回值中的 API 接口
12
- * 扩展了基础表单 API,提供完整的表单控制能力
13
- * @template T - 表单数据类型
14
- */
15
- export interface UseFormApi<T extends Record<string, any>> extends FormApi<T> {
16
- /**
17
- * 表单属性状态管理器
18
- * 用于动态更新表单配置(不包含 buttonConfig 和 fieldConfig)
19
- */
20
- setForm: StateApi<Omit<AxFormOptions, 'buttonConfig'|'fieldConfig'>>
21
-
22
- /** 表单请求 API,用于执行表单提交等异步操作 */
23
- requestApi: FormFetchApi<T>
24
-
25
- /** 按钮组件池 API,用于管理表单中的按钮配置 */
26
- buttonsApi: FieldsApi<AxButtonOptions>
27
-
28
- /** 表单项组件池 API,用于管理表单字段的配置 */
29
- fieldsApi: FieldsApi<AxFormItemOptions>
30
- }
31
-
32
- /**
33
- * UseForm Hook 的返回类型
34
- * 包含渲染组件和 API 接口的元组
35
- * @template T - 表单数据类型
36
- */
37
- export type UseFormReturn<T extends Record<string, any>> = [Component, UseFormApi<T>];
38
-
39
- /**
40
- * 表单 Hook,用于创建可配置的表单组件
41
- *
42
- * 该 Hook 封装了表单的核心逻辑,包括:
43
- * - 表单状态管理
44
- * - 按钮和表单项的动态配置
45
- * - 表单验证和提交
46
- * - 组件渲染
47
- *
48
- * @param options - 表单初始配置选项
49
- * @returns [Form 组件, Form API] 元组
50
- *
51
- * @example
52
- * const [Form, formApi] = useForm({
53
- * api: submitData,
54
- * fieldConfig: { /* 字段配置 *\/ },
55
- * buttonConfig: { /* 按钮配置 *\/ }
56
- * })
57
- *
58
- * // 在模板中使用
59
- * <Form />
60
- *
61
- * // 通过 API 操作表单
62
- * formApi.fieldsApi.addField('username', { label: '用户名', type: 'input' })
63
- * formApi.requestApi.submit()
64
- */
65
- export function useForm<T extends Record<string, any>>(options: AxFormOptions<T> = {}): UseFormReturn<T> {
66
- // 创建表单属性状态,排除 buttonConfig 和 fieldConfig(它们由独立的组件池管理)
67
- const [props, setForm] = useState(omit(options, ['buttonConfig','fieldConfig']));
68
-
69
- // 创建按钮组件池,用于管理和渲染表单按钮
70
- const [Buttons, buttonsApi] = useComponentPool<AxButtonOptions>(AxButton,options.buttonConfig);
71
-
72
- // 创建表单项组件池,用于管理和渲染表单字段
73
- const [Fields, fieldsApi] = useComponentPool<AxFormItemOptions>(AxFormItem, options.fieldConfig);
74
-
75
- // 创建表单引用,用于访问表单实例的方法
76
- const formRef = ref() as Ref<AxFormInstance>;
77
-
78
- // 获取表单暴露的 API(验证、重置等方法)
79
- const formApi = useFormExpose<T>(formRef);
80
-
81
- // 获取表单请求 API(提交、数据获取等异步操作)
82
- const requestApi = useFormFetch<T>(formRef);
83
-
84
- // 定义表单渲染组件
85
- const Form = defineComponent({
86
- setup() {
87
- const slots: Record<string, Component> = {};
88
-
89
- // 如果存在按钮配置,创建按钮插槽
90
- if (buttonsApi.getList().length) {
91
- slots['button'] = () => h(Buttons);
92
- }
93
-
94
- // 如果存在字段配置,创建默认插槽(表单项列表)
95
- if(fieldsApi.getList().length){
96
- slots['default'] = () => h(Fields);
97
- }
98
-
99
- // 渲染 AxForm 组件,传入 ref、属性和插槽
100
- return () => h(AxForm as any, {ref:formRef,...props.value}, slots);
101
- }
102
- })
103
-
104
- // 返回表单组件和完整的 API 集合
105
- return [Form, {setForm, ...formApi,fieldsApi, requestApi, buttonsApi}] as const;
106
- }
@@ -1,97 +0,0 @@
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
- }
@@ -1,103 +0,0 @@
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
- }
package/src/form/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './components/form';
2
- export * from './components/form-item';
3
- export * from './components/fields';
4
- export * from './utils';
5
- export * from './hoc';
@@ -1,149 +0,0 @@
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 DELETED
@@ -1,40 +0,0 @@
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 DELETED
@@ -1,37 +0,0 @@
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
- }