knt-shared 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,259 @@
1
+ # knt-shared
2
+
3
+ KNT共享组件库和工具函数(基于 Vue3 + @arco-design/web-vue)
4
+
5
+ 参考 [Vben Admin](https://doc.vvbin.cn/components/introduction.html) 的设计思路实现
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install knt-shared
11
+ ```
12
+
13
+ ## 使用
14
+
15
+ ### Description 详情组件
16
+
17
+ ```vue
18
+ <template>
19
+ <Description
20
+ title="用户信息"
21
+ :items="descriptionItems"
22
+ :column="3"
23
+ bordered
24
+ />
25
+ </template>
26
+
27
+ <script setup lang="ts">
28
+ import { Description } from 'knt-shared';
29
+ import type { DescriptionItem } from 'knt-shared';
30
+
31
+ const descriptionItems: DescriptionItem[] = [
32
+ { label: '姓名', value: '张三' },
33
+ { label: '年龄', value: 28 },
34
+ { label: '邮箱', value: 'zhangsan@example.com' },
35
+ { label: '地址', value: '北京市朝阳区', span: 2 },
36
+ ];
37
+ </script>
38
+ ```
39
+
40
+ ### Form 表单组件
41
+
42
+ ```vue
43
+ <template>
44
+ <Form
45
+ ref="formRef"
46
+ :model="formData"
47
+ :rules="rules"
48
+ @submit="handleSubmit"
49
+ >
50
+ <a-form-item field="name" label="姓名">
51
+ <a-input v-model="formData.name" placeholder="请输入姓名" />
52
+ </a-form-item>
53
+ <a-form-item field="email" label="邮箱">
54
+ <a-input v-model="formData.email" placeholder="请输入邮箱" />
55
+ </a-form-item>
56
+ <a-form-item>
57
+ <a-button type="primary" html-type="submit">提交</a-button>
58
+ <a-button @click="handleReset">重置</a-button>
59
+ </a-form-item>
60
+ </Form>
61
+ </template>
62
+
63
+ <script setup lang="ts">
64
+ import { ref } from 'vue';
65
+ import { Form } from 'knt-shared';
66
+
67
+ const formRef = ref();
68
+ const formData = ref({
69
+ name: '',
70
+ email: '',
71
+ });
72
+
73
+ const rules = {
74
+ name: [{ required: true, message: '请输入姓名' }],
75
+ email: [
76
+ { required: true, message: '请输入邮箱' },
77
+ { type: 'email', message: '邮箱格式不正确' },
78
+ ],
79
+ };
80
+
81
+ const handleSubmit = (values: Record<string, any>) => {
82
+ console.log('提交数据:', values);
83
+ };
84
+
85
+ const handleReset = () => {
86
+ formRef.value?.resetFields();
87
+ };
88
+ </script>
89
+ ```
90
+
91
+ ### Table 表格组件
92
+
93
+ ```vue
94
+ <template>
95
+ <Table
96
+ ref="tableRef"
97
+ :columns="columns"
98
+ :data="tableData"
99
+ :loading="loading"
100
+ :pagination="{ pageSize: 10 }"
101
+ @page-change="handlePageChange"
102
+ />
103
+ </template>
104
+
105
+ <script setup lang="ts">
106
+ import { ref } from 'vue';
107
+ import { Table } from 'knt-shared';
108
+ import type { TableColumnData } from '@arco-design/web-vue';
109
+
110
+ const tableRef = ref();
111
+ const loading = ref(false);
112
+ const tableData = ref([
113
+ { id: 1, name: '张三', age: 25, email: 'zhangsan@example.com' },
114
+ { id: 2, name: '李四', age: 30, email: 'lisi@example.com' },
115
+ ]);
116
+
117
+ const columns: TableColumnData[] = [
118
+ { title: '姓名', dataIndex: 'name' },
119
+ { title: '年龄', dataIndex: 'age' },
120
+ { title: '邮箱', dataIndex: 'email' },
121
+ ];
122
+
123
+ const handlePageChange = (page: number) => {
124
+ console.log('页码变化:', page);
125
+ // 加载数据
126
+ };
127
+
128
+ // 使用 request 属性自动加载数据
129
+ const tableWithRequest = {
130
+ columns,
131
+ request: async (params: Record<string, any>) => {
132
+ // 调用 API
133
+ const response = await fetchData(params);
134
+ return {
135
+ data: response.list,
136
+ total: response.total,
137
+ };
138
+ },
139
+ };
140
+ </script>
141
+ ```
142
+
143
+ ### Modal 模态框组件
144
+
145
+ ```vue
146
+ <template>
147
+ <div>
148
+ <a-button @click="openModal">打开模态框</a-button>
149
+ <Modal
150
+ v-model:visible="visible"
151
+ title="编辑信息"
152
+ @ok="handleOk"
153
+ @cancel="handleCancel"
154
+ >
155
+ <a-form :model="formData">
156
+ <a-form-item label="姓名">
157
+ <a-input v-model="formData.name" />
158
+ </a-form-item>
159
+ </a-form>
160
+ </Modal>
161
+ </div>
162
+ </template>
163
+
164
+ <script setup lang="ts">
165
+ import { ref } from 'vue';
166
+ import { Modal } from 'knt-shared';
167
+
168
+ const visible = ref(false);
169
+ const formData = ref({ name: '' });
170
+
171
+ const openModal = () => {
172
+ visible.value = true;
173
+ };
174
+
175
+ const handleOk = () => {
176
+ console.log('确定', formData.value);
177
+ visible.value = false;
178
+ };
179
+
180
+ const handleCancel = () => {
181
+ console.log('取消');
182
+ };
183
+
184
+ // 使用 ref 控制模态框
185
+ const modalRef = ref();
186
+ modalRef.value?.open(); // 打开
187
+ modalRef.value?.close(); // 关闭
188
+ </script>
189
+ ```
190
+
191
+ ### 工具函数
192
+
193
+ ```ts
194
+ import { formatDate, formatNumber, isValidEmail } from 'knt-shared';
195
+
196
+ // 格式化日期
197
+ const dateStr = formatDate(new Date(), 'YYYY-MM-DD');
198
+
199
+ // 格式化数字
200
+ const numStr = formatNumber(1234567); // "1,234,567"
201
+
202
+ // 验证邮箱
203
+ const isValid = isValidEmail('test@example.com');
204
+ ```
205
+
206
+ ### Hooks (Composition API)
207
+
208
+ ```vue
209
+ <template>
210
+ <div>
211
+ <input v-model="inputValue" />
212
+ <p>防抖值: {{ debouncedValue }}</p>
213
+ </div>
214
+ </template>
215
+
216
+ <script setup lang="ts">
217
+ import { ref } from 'vue';
218
+ import { useDebounce, useLocalStorage, useToggle } from 'knt-shared';
219
+
220
+ const inputValue = ref('');
221
+ const debouncedValue = useDebounce(inputValue, 500);
222
+
223
+ const [stored, setStored] = useLocalStorage('key', 'default');
224
+
225
+ const [isOpen, toggle, open, close] = useToggle(false);
226
+ </script>
227
+ ```
228
+
229
+ ## 开发
230
+
231
+ ```bash
232
+ # 安装依赖
233
+ npm install
234
+
235
+ # 构建
236
+ npm run build
237
+
238
+ # 开发模式(监听文件变化)
239
+ npm run dev
240
+ ```
241
+
242
+ ## Playground 测试环境
243
+
244
+ 项目包含一个 playground 目录,用于测试和演示组件:
245
+
246
+ ```bash
247
+ cd playground
248
+ npm install
249
+ npm run dev
250
+ ```
251
+
252
+ 访问 http://localhost:3000 查看所有组件的测试和演示。
253
+
254
+ ## 发布
255
+
256
+ ```bash
257
+ npm publish
258
+ ```
259
+
@@ -0,0 +1,117 @@
1
+ import { FormSchema, BasicFormProps } from './types';
2
+
3
+ declare function __VLS_template(): {
4
+ actions?(_: {}): any;
5
+ };
6
+ declare const __VLS_component: import('vue').DefineComponent<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<BasicFormProps>, {
7
+ schemas: () => never[];
8
+ layout: string;
9
+ labelAlign: string;
10
+ autoSetPlaceHolder: boolean;
11
+ showSubmitButton: boolean;
12
+ showResetButton: boolean;
13
+ submitButtonText: string;
14
+ resetButtonText: string;
15
+ showActionButtons: boolean;
16
+ disabled: boolean;
17
+ baseColProps: () => {
18
+ span: number;
19
+ };
20
+ actionColOptions: () => {
21
+ span: number;
22
+ };
23
+ }>>, {
24
+ formRef: import('vue').Ref<any, any>;
25
+ formModel: Record<string, any>;
26
+ handleSubmit: (values: Record<string, any>) => Promise<void>;
27
+ getVisibleSchemas: () => FormSchema[];
28
+ getColProps: (schema: FormSchema) => Record<string, any>;
29
+ getFormItemBindValue: (schema: FormSchema) => {
30
+ field: string;
31
+ label: string;
32
+ labelColProps: Record<string, any> | undefined;
33
+ wrapperColProps: Record<string, any> | undefined;
34
+ rules: any[] | undefined;
35
+ disabled: boolean | undefined;
36
+ help: string | undefined;
37
+ extra: string | undefined;
38
+ required: boolean | undefined;
39
+ };
40
+ getPlaceholderText: (schema: FormSchema) => any;
41
+ getFieldsValue: () => Record<string, any>;
42
+ setFieldsValue: (values: Record<string, any>) => void;
43
+ resetFields: () => void;
44
+ validate: () => Promise<any>;
45
+ clearValidate: (field?: string | string[]) => void;
46
+ updateSchema: (schema: Partial<FormSchema> | Partial<FormSchema>[]) => void;
47
+ removeSchema: (field: string | string[]) => void;
48
+ getSchema: (field?: string) => FormSchema | FormSchema[] | undefined;
49
+ resetSchema: (schemas: FormSchema[]) => void;
50
+ setProps: (formProps: Partial<BasicFormProps>) => void;
51
+ scrollToField: (name: string, options?: ScrollIntoViewOptions) => void;
52
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
53
+ register: (formInstance: any) => void;
54
+ submit: (values: Record<string, any>) => void;
55
+ reset: () => void;
56
+ validate: (field: string, valid: boolean, message: string) => void;
57
+ }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<BasicFormProps>, {
58
+ schemas: () => never[];
59
+ layout: string;
60
+ labelAlign: string;
61
+ autoSetPlaceHolder: boolean;
62
+ showSubmitButton: boolean;
63
+ showResetButton: boolean;
64
+ submitButtonText: string;
65
+ resetButtonText: string;
66
+ showActionButtons: boolean;
67
+ disabled: boolean;
68
+ baseColProps: () => {
69
+ span: number;
70
+ };
71
+ actionColOptions: () => {
72
+ span: number;
73
+ };
74
+ }>>> & Readonly<{
75
+ onRegister?: ((formInstance: any) => any) | undefined;
76
+ onSubmit?: ((values: Record<string, any>) => any) | undefined;
77
+ onReset?: (() => any) | undefined;
78
+ onValidate?: ((field: string, valid: boolean, message: string) => any) | undefined;
79
+ }>, {
80
+ disabled: boolean;
81
+ schemas: FormSchema[];
82
+ layout: "horizontal" | "vertical" | "inline";
83
+ labelAlign: "left" | "right";
84
+ baseColProps: Record<string, any>;
85
+ actionColOptions: Record<string, any>;
86
+ autoSetPlaceHolder: boolean;
87
+ showSubmitButton: boolean;
88
+ showResetButton: boolean;
89
+ submitButtonText: string;
90
+ resetButtonText: string;
91
+ showActionButtons: boolean;
92
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
93
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
94
+ export default _default;
95
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
96
+ type __VLS_TypePropsToRuntimeProps<T> = {
97
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
98
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
99
+ } : {
100
+ type: import('vue').PropType<T[K]>;
101
+ required: true;
102
+ };
103
+ };
104
+ type __VLS_WithDefaults<P, D> = {
105
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
106
+ default: D[K];
107
+ }> : P[K];
108
+ };
109
+ type __VLS_Prettify<T> = {
110
+ [K in keyof T]: T[K];
111
+ } & {};
112
+ type __VLS_WithTemplateSlots<T, S> = T & {
113
+ new (): {
114
+ $slots: S;
115
+ };
116
+ };
117
+ //# sourceMappingURL=BasicForm.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BasicForm.vue.d.ts","sourceRoot":"","sources":["../../../src/components/Form/BasicForm.vue"],"names":[],"mappings":"AAyDA;AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAC;AAuW1E,iBAAS,cAAc;qBA+MO,GAAG;EAGhC;AAsBD,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;2BA7be,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;0BApD1B,UAAU;mCAMD,UAAU;;;;;;;;;;;iCA2BZ,UAAU;0BAsCnB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;6BAKd,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;4BAmBpB,MAAM,GAAG,MAAM,EAAE;2BAKlB,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,EAAE;0BAW5C,MAAM,GAAG,MAAM,EAAE;wBAYnB,MAAM,KAAG,UAAU,GAAG,UAAU,EAAE,GAAG,SAAS;2BAO3C,UAAU,EAAE;0BAMb,OAAO,CAA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0 +1,39 @@
1
+ import { Component } from 'vue';
2
+
3
+ /**
4
+ * 组件类型映射
5
+ */
6
+ export type ComponentType = 'Input' | 'InputNumber' | 'InputPassword' | 'Textarea' | 'Select' | 'Radio' | 'RadioGroup' | 'Checkbox' | 'CheckboxGroup' | 'Switch' | 'Slider' | 'Rate' | 'DatePicker' | 'TimePicker' | 'RangePicker' | 'Upload' | 'Cascader' | 'TreeSelect' | 'AutoComplete' | 'Mention' | 'Transfer';
7
+ /**
8
+ * 组件映射表
9
+ * 将字符串类型映射到实际的 Arco Design Vue 组件
10
+ */
11
+ export declare const componentMap: Map<string, Component>;
12
+ /**
13
+ * 注册自定义组件
14
+ * @param name 组件名称
15
+ * @param component 组件实例
16
+ */
17
+ export declare function registerComponent(name: string, component: Component): void;
18
+ /**
19
+ * 获取组件
20
+ * @param name 组件名称或组件实例
21
+ * @returns 组件实例
22
+ */
23
+ export declare function getComponent(name: string | Component): Component | undefined;
24
+ /**
25
+ * 需要自动设置 placeholder 的组件类型
26
+ */
27
+ export declare const componentsNeedPlaceholder: Set<string>;
28
+ /**
29
+ * 需要使用 "请选择" placeholder 的组件类型
30
+ */
31
+ export declare const componentsNeedSelectPlaceholder: Set<string>;
32
+ /**
33
+ * 根据组件类型生成默认 placeholder
34
+ * @param component 组件类型
35
+ * @param label 标签文本
36
+ * @returns placeholder 文本
37
+ */
38
+ export declare function getPlaceholder(component: string, label: string): string;
39
+ //# sourceMappingURL=componentMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"componentMap.d.ts","sourceRoot":"","sources":["../../../src/components/Form/componentMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAyBhC;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,aAAa,GACb,eAAe,GACf,UAAU,GACV,QAAQ,GACR,OAAO,GACP,YAAY,GACZ,UAAU,GACV,eAAe,GACf,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,cAAc,GACd,SAAS,GACT,UAAU,CAAC;AAEf;;;GAGG;AACH,eAAO,MAAM,YAAY,wBAA+B,CAAC;AA+BzD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,QAEnE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAK5E;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,aAKpC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,+BAA+B,aAO1C,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQvE"}
@@ -0,0 +1,8 @@
1
+ import { default as BasicForm } from './BasicForm.vue';
2
+ import { useForm, createFormSchema, mergeFormSchemas } from './useForm';
3
+ import { componentMap, registerComponent, getComponent, ComponentType } from './componentMap';
4
+ import { FormSchema, UseFormOptions, UseFormReturn, BasicFormProps, BasicFormEmits } from './types';
5
+
6
+ export { BasicForm, useForm, componentMap, registerComponent, getComponent, createFormSchema, mergeFormSchemas };
7
+ export type { FormSchema, UseFormOptions, UseFormReturn, ComponentType, BasicFormProps, BasicFormEmits };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Form/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzG,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;AAEjH,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,146 @@
1
+ import { Component } from 'vue';
2
+
3
+ /**
4
+ * 表单字段 Schema 定义
5
+ */
6
+ export interface FormSchema {
7
+ /** 字段名 */
8
+ field: string;
9
+ /** 组件类型(字符串或组件) */
10
+ component: string | Component;
11
+ /** 标签文本 */
12
+ label: string;
13
+ /** 标签宽度 */
14
+ labelWidth?: number | string;
15
+ /** 标签列属性 */
16
+ labelColProps?: Record<string, any>;
17
+ /** 输入框列属性 */
18
+ wrapperColProps?: Record<string, any>;
19
+ /** 栅格列属性 */
20
+ colProps?: Record<string, any>;
21
+ /** 验证规则 */
22
+ rules?: any[];
23
+ /** 组件属性 */
24
+ componentProps?: Record<string, any>;
25
+ /** 默认值 */
26
+ defaultValue?: any;
27
+ /** 自定义渲染函数 */
28
+ render?: (schema: FormSchema, formModel: Record<string, any>) => any;
29
+ /** 自定义组件内容渲染函数 */
30
+ renderComponentContent?: (schema: FormSchema, formModel: Record<string, any>) => any;
31
+ /** 栅格跨度 */
32
+ span?: number;
33
+ /** 唯一标识 */
34
+ key?: string | number;
35
+ /** 是否显示(支持函数动态判断) */
36
+ show?: boolean | ((formModel: Record<string, any>) => boolean);
37
+ /** 是否禁用 */
38
+ disabled?: boolean | ((formModel: Record<string, any>) => boolean);
39
+ /** 是否必填(用于自动添加星号) */
40
+ required?: boolean;
41
+ /** 帮助文本 */
42
+ help?: string;
43
+ /** 额外提示信息 */
44
+ extra?: string;
45
+ /** FormItem 的其他属性 */
46
+ formItemProps?: Record<string, any>;
47
+ }
48
+ /**
49
+ * BasicForm 组件属性
50
+ */
51
+ export interface BasicFormProps {
52
+ /** 表单字段 schemas */
53
+ schemas?: FormSchema[];
54
+ /** 表单布局 */
55
+ layout?: 'horizontal' | 'vertical' | 'inline';
56
+ /** 表单尺寸 */
57
+ size?: 'mini' | 'small' | 'medium' | 'large';
58
+ /** 是否禁用整个表单 */
59
+ disabled?: boolean;
60
+ /** 标签对齐方式 */
61
+ labelAlign?: 'left' | 'right';
62
+ /** 是否自动计算标签宽度 */
63
+ autoLabelWidth?: boolean;
64
+ /** 标签宽度 */
65
+ labelWidth?: number | string;
66
+ /** 标签列属性 */
67
+ labelColProps?: Record<string, any>;
68
+ /** 输入框列属性 */
69
+ wrapperColProps?: Record<string, any>;
70
+ /** 基础栅格列属性 */
71
+ baseColProps?: Record<string, any>;
72
+ /** 基础 FormItem 属性 */
73
+ baseFormItemProps?: Record<string, any>;
74
+ /** 操作按钮列配置 */
75
+ actionColOptions?: Record<string, any>;
76
+ /** 是否自动设置占位符 */
77
+ autoSetPlaceHolder?: boolean;
78
+ /** 是否显示提交按钮 */
79
+ showSubmitButton?: boolean;
80
+ /** 是否显示重置按钮 */
81
+ showResetButton?: boolean;
82
+ /** 提交按钮文本 */
83
+ submitButtonText?: string;
84
+ /** 重置按钮文本 */
85
+ resetButtonText?: string;
86
+ /** 是否显示操作按钮区域 */
87
+ showActionButtons?: boolean;
88
+ }
89
+ /**
90
+ * useForm 配置选项(与 BasicFormProps 一致)
91
+ */
92
+ export interface UseFormOptions extends BasicFormProps {
93
+ /** 其他扩展属性 */
94
+ [key: string]: any;
95
+ }
96
+ /**
97
+ * useForm 返回值
98
+ */
99
+ export interface UseFormReturn {
100
+ /** 注册表单实例 */
101
+ register: (formInstance: any) => void;
102
+ /** 获取所有字段值 */
103
+ getFieldsValue: () => Record<string, any>;
104
+ /** 设置字段值 */
105
+ setFieldsValue: (values: Record<string, any>) => Promise<void>;
106
+ /** 重置表单 */
107
+ resetFields: () => Promise<void>;
108
+ /** 验证表单 */
109
+ validate: (nameList?: string[]) => Promise<any>;
110
+ /** 验证指定字段 */
111
+ validateFields: (nameList?: string[]) => Promise<any>;
112
+ /** 清除验证 */
113
+ clearValidate: (field?: string | string[]) => Promise<void>;
114
+ /** 提交表单 */
115
+ submit: () => Promise<any>;
116
+ /** 更新 schema */
117
+ updateSchema: (schema: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>;
118
+ /** 重置 schema */
119
+ resetSchema: (schemas: FormSchema[]) => Promise<void>;
120
+ /** 根据字段名移除 schema */
121
+ removeSchemaByField: (field: string | string[]) => Promise<void>;
122
+ /** 添加 schema */
123
+ appendSchemaByField: (schema: FormSchema | FormSchema[], prefixField?: string, first?: boolean) => Promise<void>;
124
+ /** 获取 schema */
125
+ getSchema: (field?: string) => FormSchema | FormSchema[] | undefined;
126
+ /** 设置表单 Props */
127
+ setProps: (formProps: Partial<BasicFormProps>) => Promise<void>;
128
+ /** 滚动到指定字段 */
129
+ scrollToField: (name: string, options?: ScrollIntoViewOptions) => Promise<void>;
130
+ /** 表单数据模型 */
131
+ formModel: Record<string, any>;
132
+ /** 表单实例引用 */
133
+ formRef: any;
134
+ /** 获取表单实例 */
135
+ getForm: () => any;
136
+ }
137
+ /**
138
+ * BasicForm 组件事件
139
+ */
140
+ export interface BasicFormEmits {
141
+ (e: 'register', formInstance: any): void;
142
+ (e: 'submit', values: Record<string, any>): void;
143
+ (e: 'reset'): void;
144
+ (e: 'validate', field: string, valid: boolean, message: string): void;
145
+ }
146
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/Form/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEhC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,UAAU;IACV,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB;IACnB,SAAS,EAAE,MAAM,GAAG,SA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
2
+
3
+ /**
4
+ * useForm Hook
5
+ * 用于创建和管理表单实例(参考 Vben Admin 设计)
6
+ * @param options 表单配置选项
7
+ * @returns [register, formMethods]
8
+ */
9
+ export declare function useForm(options?: UseFormOptions): [
10
+ (formInstance: any) => void,
11
+ Omit<UseFormReturn, 'register'>
12
+ ];
13
+ /**
14
+ * 创建表单配置
15
+ * 用于快速创建表单 schema
16
+ */
17
+ export declare function createFormSchema(schemas: FormSchema[]): FormSchema[];
18
+ /**
19
+ * 合并表单配置
20
+ * 用于合并多个表单配置
21
+ */
22
+ export declare function mergeFormSchemas(...schemas: FormSchema[][]): FormSchema[];
23
+ //# sourceMappingURL=useForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../src/components/Form/useForm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAC;AAEzF;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG;IACrD,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI;IAC3B,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;CAChC,CAmSA;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,EAAE,GAAG,UAAU,EAAE,CAEzE"}
@@ -0,0 +1,2 @@
1
+ export * from './Form';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AACA,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { default as useDebounce } from './useDebounce';
2
+ export { default as useLocalStorage } from './useLocalStorage';
3
+ export { default as useToggle } from './useToggle';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Ref } from 'vue';
2
+
3
+ /**
4
+ * 防抖Hook
5
+ * @param value 需要防抖的值
6
+ * @param delay 延迟时间(毫秒)
7
+ * @returns 防抖后的值
8
+ */
9
+ declare function useDebounce<T>(value: Ref<T>, delay?: number): Ref<T>;
10
+ export default useDebounce;
11
+ //# sourceMappingURL=useDebounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.d.ts","sourceRoot":"","sources":["../../src/hooks/useDebounce.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAE5D;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,GAAE,MAAY,GAAG,GAAG,CAAC,CAAC,CAAC,CA4BlE;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Ref } from 'vue';
2
+
3
+ /**
4
+ * 本地存储Hook
5
+ * @param key 存储的key
6
+ * @param initialValue 初始值
7
+ * @returns [存储的值, 设置值的函数]
8
+ */
9
+ declare function useLocalStorage<T>(key: string, initialValue: T): readonly [Ref<T, T>, (value: T | ((val: T) => T)) => void];
10
+ export default useLocalStorage;
11
+ //# sourceMappingURL=useLocalStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocalStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useLocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAE3C;;;;;GAKG;AACH,iBAAS,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,gCAa7B,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,WAwB7C;AAED,eAAe,eAAe,CAAC"}