@iswangh/element-plus-kit-form 0.1.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/LICENSE +201 -0
- package/README.md +289 -0
- package/dist/FormAction.vue.d.ts +46 -0
- package/dist/FormAction.vue.d.ts.map +1 -0
- package/dist/FormItem.vue.d.ts +74 -0
- package/dist/FormItem.vue.d.ts.map +1 -0
- package/dist/config/index.d.ts +65 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +380 -0
- package/dist/style.css +1 -0
- package/dist/types/index.d.ts +126 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# @iswangh/element-plus-kit-form
|
|
2
|
+
|
|
3
|
+
Element Plus Kit Form 组件,基于 Element Plus 的动态表单组件,支持通过配置快速生成表单。
|
|
4
|
+
|
|
5
|
+
## 📦 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @iswangh/element-plus-kit-form
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**注意**:此包依赖 `@iswangh/element-plus-kit-core`,安装时会自动安装。
|
|
12
|
+
|
|
13
|
+
## 🚀 快速开始
|
|
14
|
+
|
|
15
|
+
### 基础用法
|
|
16
|
+
|
|
17
|
+
```vue
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { WForm } from '@iswangh/element-plus-kit-form'
|
|
20
|
+
import type { FormItems } from '@iswangh/element-plus-kit-form'
|
|
21
|
+
|
|
22
|
+
const formItems: FormItems = [
|
|
23
|
+
{
|
|
24
|
+
prop: 'username',
|
|
25
|
+
label: '用户名',
|
|
26
|
+
comp: 'input',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
prop: 'email',
|
|
30
|
+
label: '邮箱',
|
|
31
|
+
comp: 'input',
|
|
32
|
+
compAttrs: {
|
|
33
|
+
type: 'email',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
const form = ref({
|
|
39
|
+
username: '',
|
|
40
|
+
email: '',
|
|
41
|
+
})
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<WForm :model="form" :form-items="formItems" />
|
|
46
|
+
</template>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 引入样式
|
|
50
|
+
|
|
51
|
+
如果使用按需引入,需要手动引入样式:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import '@iswangh/element-plus-kit-form/style.css'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 📖 API 文档
|
|
58
|
+
|
|
59
|
+
### Props
|
|
60
|
+
|
|
61
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
62
|
+
| --- | --- | --- | --- |
|
|
63
|
+
| model | 表单数据对象 | `Record<string, any>` | `{}` |
|
|
64
|
+
| formItems | 表单项配置数组 | `FormItems` | `[]` |
|
|
65
|
+
| rowAttrs | 行布局属性(ElRow 属性) | `RowAttrs` | `{}` |
|
|
66
|
+
| actionConfig | 操作按钮配置 | `ActionConfig` | `{}` |
|
|
67
|
+
|
|
68
|
+
**继承 Element Plus Form 属性**:组件继承所有 `ElForm` 的属性,如 `rules`、`labelPosition`、`size` 等。
|
|
69
|
+
|
|
70
|
+
### Events
|
|
71
|
+
|
|
72
|
+
| 事件名 | 说明 | 参数 |
|
|
73
|
+
| --- | --- | --- |
|
|
74
|
+
| validate | 表单项验证事件 | `(prop: FormItemProp, isValid: boolean, message: string)` |
|
|
75
|
+
| change | 表单项值变化事件 | `(extendedParams: EventExtendedParams, value: any)` |
|
|
76
|
+
| action | 操作按钮点击事件 | `(eventName: string)` |
|
|
77
|
+
| search | 搜索按钮点击事件 | - |
|
|
78
|
+
| reset | 重置按钮点击事件 | - |
|
|
79
|
+
| submit | 提交按钮点击事件 | - |
|
|
80
|
+
| cancel | 取消按钮点击事件 | - |
|
|
81
|
+
|
|
82
|
+
### Slots
|
|
83
|
+
|
|
84
|
+
| 插槽名 | 说明 | 作用域参数 |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| `form-item-{prop}` | 表单项插槽,用于自定义表单项内容 | `FormItemSlotScope` |
|
|
87
|
+
| `{prop}-{slotName}` | 动态组件插槽,如 `username-prefix`、`email-suffix` | `FormItemSlotScope` |
|
|
88
|
+
|
|
89
|
+
### FormItem 配置
|
|
90
|
+
|
|
91
|
+
#### 基础配置
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
interface FormItem<C extends FormItemComp = FormItemComp> {
|
|
95
|
+
prop: string // 表单字段名(必填)
|
|
96
|
+
label: string // 标签文本
|
|
97
|
+
comp: FormItemComp // 组件类型(必填)
|
|
98
|
+
compAttrs?: FormItemCompAttrs<C> // 组件属性配置
|
|
99
|
+
vIf?: boolean | ((data?: any) => boolean) // 条件渲染(v-if)
|
|
100
|
+
vShow?: boolean | ((data?: any) => boolean) // 显示/隐藏(v-show)
|
|
101
|
+
colAttrs?: ColAttrs // 列布局属性(ElCol 属性)
|
|
102
|
+
// ... 其他 ElFormItem 属性
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### 支持的组件类型
|
|
107
|
+
|
|
108
|
+
组件支持所有 Element Plus 表单组件,包括:
|
|
109
|
+
|
|
110
|
+
- `input` - 输入框
|
|
111
|
+
- `input-number` - 数字输入框
|
|
112
|
+
- `select` - 选择器
|
|
113
|
+
- `date-picker` - 日期选择器
|
|
114
|
+
- `time-picker` - 时间选择器
|
|
115
|
+
- `switch` - 开关
|
|
116
|
+
- `radio` - 单选框
|
|
117
|
+
- `checkbox` - 复选框
|
|
118
|
+
- `textarea` - 文本域
|
|
119
|
+
- 等等...
|
|
120
|
+
|
|
121
|
+
#### 使用示例
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const formItems: FormItems = [
|
|
125
|
+
{
|
|
126
|
+
prop: 'username',
|
|
127
|
+
label: '用户名',
|
|
128
|
+
comp: 'input',
|
|
129
|
+
compAttrs: {
|
|
130
|
+
placeholder: '请输入用户名',
|
|
131
|
+
clearable: true,
|
|
132
|
+
},
|
|
133
|
+
rules: [
|
|
134
|
+
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
prop: 'age',
|
|
139
|
+
label: '年龄',
|
|
140
|
+
comp: 'input-number',
|
|
141
|
+
compAttrs: {
|
|
142
|
+
min: 0,
|
|
143
|
+
max: 120,
|
|
144
|
+
step: 1,
|
|
145
|
+
},
|
|
146
|
+
// 条件渲染:只有当 username 存在时才显示
|
|
147
|
+
vIf: (data) => !!data?.username,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
prop: 'gender',
|
|
151
|
+
label: '性别',
|
|
152
|
+
comp: 'select',
|
|
153
|
+
compAttrs: {
|
|
154
|
+
options: [
|
|
155
|
+
{ label: '男', value: 'male' },
|
|
156
|
+
{ label: '女', value: 'female' },
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
]
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### ActionConfig 配置
|
|
164
|
+
|
|
165
|
+
操作按钮配置用于自定义表单底部的操作按钮。
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
interface ActionConfig {
|
|
169
|
+
vIf?: boolean | ((data?: any) => boolean) // 是否显示操作区域
|
|
170
|
+
vShow?: boolean | ((data?: any) => boolean) // 显示/隐藏操作区域
|
|
171
|
+
buttons?: ActionConfigButtons[] // 按钮列表
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### 预设按钮
|
|
176
|
+
|
|
177
|
+
支持以下预设按钮:
|
|
178
|
+
|
|
179
|
+
- `'submit'` - 提交按钮
|
|
180
|
+
- `'reset'` - 重置按钮
|
|
181
|
+
- `'search'` - 搜索按钮
|
|
182
|
+
- `'cancel'` - 取消按钮
|
|
183
|
+
|
|
184
|
+
#### 自定义按钮
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
interface ActionConfigButtonItem extends Partial<ButtonProps> {
|
|
188
|
+
label?: string // 按钮文字
|
|
189
|
+
eventName: string // 事件名称(必填)
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### 使用示例
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const actionConfig: ActionConfig = {
|
|
197
|
+
buttons: [
|
|
198
|
+
'submit',
|
|
199
|
+
'reset',
|
|
200
|
+
{
|
|
201
|
+
label: '自定义按钮',
|
|
202
|
+
eventName: 'custom',
|
|
203
|
+
type: 'primary',
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## 💡 高级用法
|
|
210
|
+
|
|
211
|
+
### 条件渲染
|
|
212
|
+
|
|
213
|
+
使用 `vIf` 或 `vShow` 实现表单项的条件显示:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const formItems: FormItems = [
|
|
217
|
+
{
|
|
218
|
+
prop: 'username',
|
|
219
|
+
label: '用户名',
|
|
220
|
+
comp: 'input',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
prop: 'email',
|
|
224
|
+
label: '邮箱',
|
|
225
|
+
comp: 'input',
|
|
226
|
+
// 只有当用户名存在时才显示邮箱字段
|
|
227
|
+
vIf: (data) => !!data?.username,
|
|
228
|
+
},
|
|
229
|
+
]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 自定义插槽
|
|
233
|
+
|
|
234
|
+
使用插槽自定义表单项内容:
|
|
235
|
+
|
|
236
|
+
```vue
|
|
237
|
+
<template>
|
|
238
|
+
<WForm :model="form" :form-items="formItems">
|
|
239
|
+
<template #username-prefix="{ formItem }">
|
|
240
|
+
<el-icon><User /></el-icon>
|
|
241
|
+
</template>
|
|
242
|
+
</WForm>
|
|
243
|
+
</template>
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### 表单验证
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
const formItems: FormItems = [
|
|
250
|
+
{
|
|
251
|
+
prop: 'email',
|
|
252
|
+
label: '邮箱',
|
|
253
|
+
comp: 'input',
|
|
254
|
+
rules: [
|
|
255
|
+
{ required: true, message: '请输入邮箱', trigger: 'blur' },
|
|
256
|
+
{ type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' },
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
]
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### 监听事件
|
|
263
|
+
|
|
264
|
+
```vue
|
|
265
|
+
<template>
|
|
266
|
+
<WForm
|
|
267
|
+
:model="form"
|
|
268
|
+
:form-items="formItems"
|
|
269
|
+
@change="handleChange"
|
|
270
|
+
@submit="handleSubmit"
|
|
271
|
+
/>
|
|
272
|
+
</template>
|
|
273
|
+
|
|
274
|
+
<script setup lang="ts">
|
|
275
|
+
const handleChange = (extendedParams: EventExtendedParams, value: any) => {
|
|
276
|
+
console.log('字段变化:', extendedParams.prop, value)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const handleSubmit = () => {
|
|
280
|
+
console.log('提交表单:', form.value)
|
|
281
|
+
}
|
|
282
|
+
</script>
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## 🔗 相关链接
|
|
286
|
+
|
|
287
|
+
- [主包文档](../kit/README.md)
|
|
288
|
+
- [核心工具包文档](../core/README.md)
|
|
289
|
+
- [Element Plus 文档](https://element-plus.org/zh-CN/)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Slot } from 'vue';
|
|
2
|
+
import { ActionConfig } from './types';
|
|
3
|
+
interface Props {
|
|
4
|
+
inline?: boolean;
|
|
5
|
+
actionSlot?: Slot;
|
|
6
|
+
config?: ActionConfig;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
|
|
9
|
+
inline: boolean;
|
|
10
|
+
config: () => {};
|
|
11
|
+
}>>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
12
|
+
action: (payload: {
|
|
13
|
+
eventName: string;
|
|
14
|
+
data?: any;
|
|
15
|
+
}) => void;
|
|
16
|
+
}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
|
|
17
|
+
inline: boolean;
|
|
18
|
+
config: () => {};
|
|
19
|
+
}>>> & Readonly<{
|
|
20
|
+
onAction?: ((payload: {
|
|
21
|
+
eventName: string;
|
|
22
|
+
data?: any;
|
|
23
|
+
}) => any) | undefined;
|
|
24
|
+
}>, {
|
|
25
|
+
inline: boolean;
|
|
26
|
+
config: ActionConfig;
|
|
27
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
28
|
+
export default _default;
|
|
29
|
+
type __VLS_WithDefaults<P, D> = {
|
|
30
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
|
|
31
|
+
default: D[K];
|
|
32
|
+
}> : P[K];
|
|
33
|
+
};
|
|
34
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
35
|
+
type __VLS_TypePropsToOption<T> = {
|
|
36
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
37
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
38
|
+
} : {
|
|
39
|
+
type: import('vue').PropType<T[K]>;
|
|
40
|
+
required: true;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
type __VLS_PrettifyLocal<T> = {
|
|
44
|
+
[K in keyof T]: T[K];
|
|
45
|
+
} & {};
|
|
46
|
+
//# sourceMappingURL=FormAction.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormAction.vue.d.ts","sourceRoot":"","sources":["../src/FormAction.vue"],"names":[],"mappings":"AACA;AAiEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,KAAK,EAAE,YAAY,EAA0B,MAAM,SAAS,CAAA;AAInE,UAAU,KAAK;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,UAAU,CAAC,EAAE,IAAI,CAAA;IACjB,MAAM,CAAC,EAAE,YAAY,CAAA;CACtB;;;;;;mBAGqC,MAAM;eAAS,GAAG;;;;;;;mBAAlB,MAAM;eAAS,GAAG;;;YAN7C,OAAO;YAEP,YAAY;;AAyIvB,wBAOG;AAEH,KAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI;KAC9B,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAC7C,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;KAAC,CAAC,GAC5C,CAAC,CAAC,CAAC,CAAC;CACP,CAAC;AACF,KAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;AACjE,KAAK,uBAAuB,CAAC,CAAC,IAAI;KAChC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACpC;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KAAE,GAC9D;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAE;CACzD,CAAC;AACF,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Slot } from 'vue';
|
|
2
|
+
import { FormItem } from './types';
|
|
3
|
+
interface ProcessedSlot {
|
|
4
|
+
rawSlotName: string;
|
|
5
|
+
slotName: string;
|
|
6
|
+
slotFn: Slot;
|
|
7
|
+
}
|
|
8
|
+
interface FormSlots {
|
|
9
|
+
formItemSlots: ProcessedSlot[];
|
|
10
|
+
dynamicComponentSlots: Map<string, ProcessedSlot[]>;
|
|
11
|
+
}
|
|
12
|
+
interface Props {
|
|
13
|
+
formItem: FormItem;
|
|
14
|
+
index: number;
|
|
15
|
+
formData?: Record<string, any>;
|
|
16
|
+
dynamicCompEvents: Record<string, (...args: any[]) => any>;
|
|
17
|
+
formSlots?: FormSlots;
|
|
18
|
+
}
|
|
19
|
+
type __VLS_Props = Props;
|
|
20
|
+
type __VLS_PublicProps = {
|
|
21
|
+
modelValue?: any;
|
|
22
|
+
} & __VLS_Props;
|
|
23
|
+
declare function __VLS_template(): {
|
|
24
|
+
attrs: Partial<{}>;
|
|
25
|
+
slots: Partial<Record<string, (_: {
|
|
26
|
+
value: unknown;
|
|
27
|
+
form: Record<string, any>;
|
|
28
|
+
formItem: FormItem<import('./types').FormItemComp>;
|
|
29
|
+
}) => any>>;
|
|
30
|
+
refs: {};
|
|
31
|
+
rootEl: any;
|
|
32
|
+
};
|
|
33
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
34
|
+
declare const __VLS_component: import('vue').DefineComponent<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<__VLS_PublicProps>, {
|
|
35
|
+
formData: () => {};
|
|
36
|
+
formSlots: () => {
|
|
37
|
+
formItemSlots: never[];
|
|
38
|
+
dynamicComponentSlots: Map<any, any>;
|
|
39
|
+
};
|
|
40
|
+
}>>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<__VLS_PublicProps>, {
|
|
41
|
+
formData: () => {};
|
|
42
|
+
formSlots: () => {
|
|
43
|
+
formItemSlots: never[];
|
|
44
|
+
dynamicComponentSlots: Map<any, any>;
|
|
45
|
+
};
|
|
46
|
+
}>>> & Readonly<{}>, {
|
|
47
|
+
formData: Record<string, any>;
|
|
48
|
+
formSlots: FormSlots;
|
|
49
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
50
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
51
|
+
export default _default;
|
|
52
|
+
type __VLS_WithDefaults<P, D> = {
|
|
53
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
|
|
54
|
+
default: D[K];
|
|
55
|
+
}> : P[K];
|
|
56
|
+
};
|
|
57
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
58
|
+
type __VLS_TypePropsToOption<T> = {
|
|
59
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
60
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
61
|
+
} : {
|
|
62
|
+
type: import('vue').PropType<T[K]>;
|
|
63
|
+
required: true;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
67
|
+
new (): {
|
|
68
|
+
$slots: S;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
type __VLS_PrettifyLocal<T> = {
|
|
72
|
+
[K in keyof T]: T[K];
|
|
73
|
+
} & {};
|
|
74
|
+
//# sourceMappingURL=FormItem.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormItem.vue.d.ts","sourceRoot":"","sources":["../src/FormItem.vue"],"names":[],"mappings":"AACA;AA8HA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,KAAK,EAAuB,QAAQ,EAAE,MAAM,SAAS,CAAA;AAI5D,UAAU,aAAa;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,IAAI,CAAA;CACb;AAED,UAAU,SAAS;IACjB,aAAa,EAAE,aAAa,EAAE,CAAA;IAC9B,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC,CAAA;CACpD;AAED,UAAU,KAAK;IACb,QAAQ,EAAE,QAAQ,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAA;IAC1D,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB;AAQD,KAAK,WAAW,GAAG,KAAK,CAAC;AAyEzB,KAAK,iBAAiB,GAAG;IACzB,UAAU,CAAC,EAAE,GAAG,CAAC;CAChB,GAAG,WAAW,CAAC;AAKhB,iBAAS,cAAc;WA0GT,OAAO,IAA6B;;;;;UAXqC,GAAG;;;EAgBzF;AAmBD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe;;;;;;;;;;;;;cA9NR,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;eAElB,SAAS;4EAsOrB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAEpG,KAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI;KAC9B,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAC7C,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;KAAC,CAAC,GAC5C,CAAC,CAAC,CAAC,CAAC;CACP,CAAC;AACF,KAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;AACjE,KAAK,uBAAuB,CAAC,CAAC,IAAI;KAChC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACpC;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KAAE,GAC9D;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAE;CACzD,CAAC;AACF,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC;AACF,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { FormProps } from 'element-plus';
|
|
2
|
+
import { ActionConfig, ActionConfigButtonItem, FormItem } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* 表单组件配置常量
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 需要从 FormItem 中排除的自定义属性键名
|
|
8
|
+
* 这些属性不会传递给 el-form-item 组件
|
|
9
|
+
*/
|
|
10
|
+
export declare const FORM_ITEM_EXCLUDED_KEYS: readonly ["comp", "compAttrs", "vIf", "vShow"];
|
|
11
|
+
/**
|
|
12
|
+
* 表单组件类型映射配置
|
|
13
|
+
*
|
|
14
|
+
* 使用显式类型注解避免类型推断超出编译器序列化限制
|
|
15
|
+
* 类型提示通过 keyof 提取键名,不依赖完整的类型定义
|
|
16
|
+
*/
|
|
17
|
+
export declare const FORM_ITEM_COMP_MAP: Record<string, any>;
|
|
18
|
+
/**
|
|
19
|
+
* 动态组件默认配置
|
|
20
|
+
*/
|
|
21
|
+
export declare const COMPONENT_DEFAULT_CONFIG: {
|
|
22
|
+
/**
|
|
23
|
+
* 获取组件默认属性
|
|
24
|
+
*/
|
|
25
|
+
getDefaults(formItem: FormItem): {
|
|
26
|
+
[x: string]: any;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 判断组件类型
|
|
30
|
+
*/
|
|
31
|
+
getComponentType(comp: string): "input" | "select" | "picker" | "other";
|
|
32
|
+
/**
|
|
33
|
+
* 动态生成 placeholder
|
|
34
|
+
*/
|
|
35
|
+
generatePlaceholder(formItem: FormItem, type: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* 构建组件属性
|
|
38
|
+
*/
|
|
39
|
+
buildComponentAttrs(formItem: FormItem, type: string): Record<string, any>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* 表单属性默认配置
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_FORM_ATTRS: Partial<FormProps>;
|
|
45
|
+
/**
|
|
46
|
+
* 表单动作按钮默认配置
|
|
47
|
+
*/
|
|
48
|
+
export declare const DEFAULT_FORM_ACTION_BUTTONS: Record<string, Partial<Omit<ActionConfigButtonItem, 'eventName'>>>;
|
|
49
|
+
/**
|
|
50
|
+
* 表单动作默认配置
|
|
51
|
+
*/
|
|
52
|
+
export declare const ACTION_DEFAULT_CONFIG: {
|
|
53
|
+
getDefaults(inline?: boolean, actionConfig?: ActionConfig): {
|
|
54
|
+
vIf: boolean | ((data?: any) => boolean);
|
|
55
|
+
vShow: boolean | ((data?: any) => boolean);
|
|
56
|
+
buttons: string[] | import('../types').ActionConfigButtons[];
|
|
57
|
+
};
|
|
58
|
+
generateActionButtons(inline?: boolean): string[];
|
|
59
|
+
buildActionAttrs(inline?: boolean): {
|
|
60
|
+
buttons: string[];
|
|
61
|
+
vIf: boolean | undefined;
|
|
62
|
+
vShow: boolean;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAI9E;;GAEG;AAEH;;;GAGG;AACH,eAAO,MAAM,uBAAuB,gDAAiD,CAAA;AAsCrF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAGzC,CAAA;AAEV;;GAEG;AACH,eAAO,MAAM,wBAAwB;IACnC;;OAEG;0BACmB,QAAQ;;;IAe9B;;OAEG;2BACoB,MAAM;IAoB7B;;OAEG;kCAC2B,QAAQ,QAAQ,MAAM;IAkBpD;;OAEG;kCAC2B,QAAQ,QAAQ,MAAM;CAYrD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAQf,OAAO,CAAC,SAAS,CAAC,CAAA;AAElC;;GAEG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,WAAW,CAAC,CAAC,CAK1G,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB;yBACX,OAAO,iBAAiB,YAAY;6BAXgB,CAAC;+BACpE,CAAC;;;mCAkBwB,OAAO;8BAGZ,OAAO;;;;;CAOlC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default } from './Form.vue';
|
|
2
|
+
export { default as WForm } from './Form.vue';
|
|
3
|
+
export type { ActionConfig, ActionConfigButtonItem, Arrayable, ColAttrs, ElFormAttrs, EventExtendedParams, FormItem, FormItemComp, FormItemCompAttrs, FormItems, FormItemSlotScope, RowAttrs, } from './types';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,oBAAoB,CAAA;AAE3B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAA;AAE7C,YAAY,EACV,YAAY,EACZ,sBAAsB,EACtB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,QAAQ,GACT,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { defineComponent as _, createElementBlock as T, openBlock as m, createElementVNode as x, computed as s, resolveComponent as P, withDirectives as $, createCommentVNode as z, createBlock as E, withCtx as A, Fragment as R, renderList as M, mergeProps as w, createTextVNode as W, toDisplayString as G, resolveDynamicComponent as k, vShow as U, mergeModels as O, useModel as H, normalizeProps as j, guardReactiveProps as L, createSlots as V, renderSlot as K, useAttrs as X, useSlots as q, ref as Y, withModifiers as J, createVNode as B, unref as Q } from "vue";
|
|
2
|
+
import { checkCondition as N } from "@iswangh/element-plus-kit-core";
|
|
3
|
+
import { ElTreeSelect as Z, ElTransfer as ee, ElTimeSelect as te, ElTimePicker as oe, ElSwitch as ne, ElSlider as le, ElSelectV2 as re, ElSelect as ae, ElRate as se, ElRadioGroup as ie, ElMention as ce, ElInputTag as me, ElInputNumber as ue, ElInput as fe, ElDatePicker as de, ElDatePickerPanel as pe, ElColorPicker as ve, ElColorPickerPanel as he, ElCheckboxGroup as ge, ElCascader as Ee, ElAutocomplete as Ce, ElCol as be, ElRow as Ae } from "element-plus";
|
|
4
|
+
var ye = /* @__PURE__ */ _({
|
|
5
|
+
name: "Refresh",
|
|
6
|
+
__name: "refresh",
|
|
7
|
+
setup(e) {
|
|
8
|
+
return (o, l) => (m(), T("svg", {
|
|
9
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
10
|
+
viewBox: "0 0 1024 1024"
|
|
11
|
+
}, [
|
|
12
|
+
x("path", {
|
|
13
|
+
fill: "currentColor",
|
|
14
|
+
d: "M771.776 794.88A384 384 0 0 1 128 512h64a320 320 0 0 0 555.712 216.448H654.72a32 32 0 1 1 0-64h149.056a32 32 0 0 1 32 32v148.928a32 32 0 1 1-64 0v-50.56zM276.288 295.616h92.992a32 32 0 0 1 0 64H220.16a32 32 0 0 1-32-32V178.56a32 32 0 0 1 64 0v50.56A384 384 0 0 1 896.128 512h-64a320 320 0 0 0-555.776-216.384z"
|
|
15
|
+
})
|
|
16
|
+
]));
|
|
17
|
+
}
|
|
18
|
+
}), Ie = ye, Se = /* @__PURE__ */ _({
|
|
19
|
+
name: "Search",
|
|
20
|
+
__name: "search",
|
|
21
|
+
setup(e) {
|
|
22
|
+
return (o, l) => (m(), T("svg", {
|
|
23
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
24
|
+
viewBox: "0 0 1024 1024"
|
|
25
|
+
}, [
|
|
26
|
+
x("path", {
|
|
27
|
+
fill: "currentColor",
|
|
28
|
+
d: "m795.904 750.72 124.992 124.928a32 32 0 0 1-45.248 45.248L750.656 795.904a416 416 0 1 1 45.248-45.248zM480 832a352 352 0 1 0 0-704 352 352 0 0 0 0 704"
|
|
29
|
+
})
|
|
30
|
+
]));
|
|
31
|
+
}
|
|
32
|
+
}), we = Se;
|
|
33
|
+
const ke = ["comp", "compAttrs", "vIf", "vShow"], _e = {
|
|
34
|
+
custom: "div"
|
|
35
|
+
}, Fe = {
|
|
36
|
+
autocomplete: Ce,
|
|
37
|
+
cascader: Ee,
|
|
38
|
+
checkbox: ge,
|
|
39
|
+
"color-picker-panel": he,
|
|
40
|
+
"color-picker": ve,
|
|
41
|
+
"date-picker-panel": pe,
|
|
42
|
+
"date-picker": de,
|
|
43
|
+
input: fe,
|
|
44
|
+
"input-number": ue,
|
|
45
|
+
"input-tag": me,
|
|
46
|
+
mention: ce,
|
|
47
|
+
radio: ie,
|
|
48
|
+
rate: se,
|
|
49
|
+
select: ae,
|
|
50
|
+
"select-v2": re,
|
|
51
|
+
slider: le,
|
|
52
|
+
switch: ne,
|
|
53
|
+
"time-picker": oe,
|
|
54
|
+
"time-select": te,
|
|
55
|
+
transfer: ee,
|
|
56
|
+
"tree-select": Z
|
|
57
|
+
}, Pe = {
|
|
58
|
+
...Fe,
|
|
59
|
+
..._e
|
|
60
|
+
}, Me = {
|
|
61
|
+
/**
|
|
62
|
+
* 获取组件默认属性
|
|
63
|
+
*/
|
|
64
|
+
getDefaults(e) {
|
|
65
|
+
const { comp: o, compAttrs: l = {} } = e, r = this.getComponentType(o);
|
|
66
|
+
return {
|
|
67
|
+
...this.buildComponentAttrs(e, r),
|
|
68
|
+
...l
|
|
69
|
+
// 用户配置最后合并,优先级最高
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* 判断组件类型
|
|
74
|
+
*/
|
|
75
|
+
getComponentType(e) {
|
|
76
|
+
const o = ["autocomplete", "input", "input-number", "input-tag", "mention"], l = ["cascader", "select", "select-v2", "tree-select"], r = ["date-picker", "time-select", "time-picker"];
|
|
77
|
+
return o.includes(e) ? "input" : l.includes(e) ? "select" : r.includes(e) ? "picker" : "other";
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* 动态生成 placeholder
|
|
81
|
+
*/
|
|
82
|
+
generatePlaceholder(e, o) {
|
|
83
|
+
const { label: l, comp: r } = e, h = l ? `${l}` : "";
|
|
84
|
+
return o === "input" ? r === "input-number" ? "请输入" : `请输入${h}` : ["select", "picker"].includes(o) ? `请选择${h}` : "";
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* 构建组件属性
|
|
88
|
+
*/
|
|
89
|
+
buildComponentAttrs(e, o) {
|
|
90
|
+
const l = {};
|
|
91
|
+
return ["input", "select", "picker"].includes(o) && (l.placeholder = this.generatePlaceholder(e, o), l.clearable = !0), ["select"].includes(o) && (l.filterable = !0), l;
|
|
92
|
+
}
|
|
93
|
+
}, Te = {
|
|
94
|
+
showMessage: !0,
|
|
95
|
+
scrollToError: !0,
|
|
96
|
+
scrollIntoViewOptions: {
|
|
97
|
+
behavior: "smooth",
|
|
98
|
+
// 平滑滚动
|
|
99
|
+
block: "center",
|
|
100
|
+
// 垂直居中,让错误项在视窗中间
|
|
101
|
+
inline: "nearest"
|
|
102
|
+
// 水平方向保持最近位置
|
|
103
|
+
}
|
|
104
|
+
}, De = {
|
|
105
|
+
search: { label: "搜索", icon: we, type: "primary" },
|
|
106
|
+
reset: { label: "重置", icon: Ie },
|
|
107
|
+
submit: { label: "确认", type: "primary" },
|
|
108
|
+
cancel: { label: "取消" }
|
|
109
|
+
}, Oe = {
|
|
110
|
+
getDefaults(e, o) {
|
|
111
|
+
return {
|
|
112
|
+
...this.buildActionAttrs(e),
|
|
113
|
+
...o
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
generateActionButtons(e) {
|
|
117
|
+
return e ? ["search", "reset"] : ["submit", "cancel"];
|
|
118
|
+
},
|
|
119
|
+
buildActionAttrs(e) {
|
|
120
|
+
return {
|
|
121
|
+
buttons: this.generateActionButtons(e),
|
|
122
|
+
vIf: e,
|
|
123
|
+
vShow: !0
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}, Ve = /* @__PURE__ */ _({
|
|
127
|
+
name: "ElementPlusKitFormItemAction",
|
|
128
|
+
__name: "FormAction",
|
|
129
|
+
props: {
|
|
130
|
+
inline: { type: Boolean, default: !1 },
|
|
131
|
+
actionSlot: {},
|
|
132
|
+
config: { default: () => ({}) }
|
|
133
|
+
},
|
|
134
|
+
emits: ["action"],
|
|
135
|
+
setup(e) {
|
|
136
|
+
const o = e, l = s(() => ({ ...o, config: { ...Oe.getDefaults(o.inline, o.config) } })), r = s(() => {
|
|
137
|
+
const { buttons: g } = l.value.config;
|
|
138
|
+
return g.map((p) => {
|
|
139
|
+
if (typeof p == "string") {
|
|
140
|
+
const v = De[p];
|
|
141
|
+
return v ? { ...v, eventName: p } : { label: p.toUpperCase(), eventName: p };
|
|
142
|
+
}
|
|
143
|
+
return p;
|
|
144
|
+
});
|
|
145
|
+
}), h = s(() => (g) => {
|
|
146
|
+
const { label: p, eventName: v, ...b } = g;
|
|
147
|
+
return { ...b };
|
|
148
|
+
});
|
|
149
|
+
return (g, p) => {
|
|
150
|
+
const v = P("el-button"), b = P("el-form-item");
|
|
151
|
+
return l.value.config.vIf ? $((m(), E(b, {
|
|
152
|
+
key: 0,
|
|
153
|
+
prop: "action"
|
|
154
|
+
}, {
|
|
155
|
+
default: A(() => [
|
|
156
|
+
e.actionSlot ? (m(), E(k(e.actionSlot), {
|
|
157
|
+
key: 1,
|
|
158
|
+
prop: "action"
|
|
159
|
+
})) : (m(!0), T(R, { key: 0 }, M(r.value, (C, I) => (m(), E(v, w({
|
|
160
|
+
key: `${C.label}-${I}`
|
|
161
|
+
}, { ref_for: !0 }, h.value(C), {
|
|
162
|
+
onClick: (F) => g.$emit("action", { eventName: C.eventName })
|
|
163
|
+
}), {
|
|
164
|
+
default: A(() => [
|
|
165
|
+
W(G(C.label ?? ""), 1)
|
|
166
|
+
]),
|
|
167
|
+
_: 2
|
|
168
|
+
}, 1040, ["onClick"]))), 128))
|
|
169
|
+
]),
|
|
170
|
+
_: 1
|
|
171
|
+
}, 512)), [
|
|
172
|
+
[U, l.value.config.vShow]
|
|
173
|
+
]) : z("", !0);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}), Be = /* @__PURE__ */ _({
|
|
177
|
+
name: "ElementPlusKitFormItem",
|
|
178
|
+
__name: "FormItem",
|
|
179
|
+
props: /* @__PURE__ */ O({
|
|
180
|
+
formItem: {},
|
|
181
|
+
index: {},
|
|
182
|
+
formData: { default: () => ({}) },
|
|
183
|
+
dynamicCompEvents: {},
|
|
184
|
+
formSlots: { default: () => ({ formItemSlots: [], dynamicComponentSlots: /* @__PURE__ */ new Map() }) }
|
|
185
|
+
}, {
|
|
186
|
+
modelValue: {},
|
|
187
|
+
modelModifiers: {}
|
|
188
|
+
}),
|
|
189
|
+
emits: /* @__PURE__ */ O(["change"], ["update:modelValue"]),
|
|
190
|
+
setup(e) {
|
|
191
|
+
const o = e, l = H(e, "modelValue");
|
|
192
|
+
function r() {
|
|
193
|
+
const i = new Set(ke);
|
|
194
|
+
return Object.fromEntries(
|
|
195
|
+
Object.entries(o.formItem).filter(([u]) => !i.has(u))
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const h = s(() => r()), g = s(() => o.formSlots.formItemSlots), p = s(() => Pe[o.formItem.comp] || "div"), v = s(() => {
|
|
199
|
+
const { formItem: i, index: u } = o;
|
|
200
|
+
return { prop: i.prop, formItem: i, index: u };
|
|
201
|
+
});
|
|
202
|
+
function b() {
|
|
203
|
+
const i = {};
|
|
204
|
+
for (const [u, c] of Object.entries(o.dynamicCompEvents))
|
|
205
|
+
i[u] = (...f) => c(v.value, ...f);
|
|
206
|
+
return i;
|
|
207
|
+
}
|
|
208
|
+
const C = s(() => b()), I = s(() => ({ ...Me.getDefaults(o.formItem), ...C.value })), F = s(() => (i) => o.formSlots.dynamicComponentSlots.get(i));
|
|
209
|
+
return (i, u) => {
|
|
210
|
+
const c = P("el-form-item");
|
|
211
|
+
return m(), E(c, j(L(h.value)), V({
|
|
212
|
+
default: A(() => [
|
|
213
|
+
e.formItem.comp !== "custom" ? (m(), E(k(p.value), w({ key: 0 }, I.value, {
|
|
214
|
+
modelValue: l.value,
|
|
215
|
+
"onUpdate:modelValue": u[0] || (u[0] = (f) => l.value = f),
|
|
216
|
+
onChange: u[1] || (u[1] = (f) => i.$emit("change", v.value, f))
|
|
217
|
+
}), V({ _: 2 }, [
|
|
218
|
+
M(F.value(e.formItem.prop), (f, t) => ({
|
|
219
|
+
name: f.slotName,
|
|
220
|
+
fn: A((n) => [
|
|
221
|
+
(m(), E(k(f.slotFn), w({
|
|
222
|
+
value: l.value,
|
|
223
|
+
form: e.formData,
|
|
224
|
+
"form-item": e.formItem
|
|
225
|
+
}, n), null, 16, ["value", "form", "form-item"]))
|
|
226
|
+
])
|
|
227
|
+
}))
|
|
228
|
+
]), 1040, ["modelValue"])) : K(i.$slots, e.formItem.prop, {
|
|
229
|
+
key: 1,
|
|
230
|
+
value: l.value,
|
|
231
|
+
form: e.formData,
|
|
232
|
+
formItem: e.formItem
|
|
233
|
+
})
|
|
234
|
+
]),
|
|
235
|
+
_: 2
|
|
236
|
+
}, [
|
|
237
|
+
M(g.value, (f, t) => ({
|
|
238
|
+
name: f.slotName,
|
|
239
|
+
fn: A((n) => [
|
|
240
|
+
(m(), E(k(f.slotFn), w({
|
|
241
|
+
value: l.value,
|
|
242
|
+
form: e.formData,
|
|
243
|
+
"form-item": e.formItem
|
|
244
|
+
}, n), null, 16, ["value", "form", "form-item"]))
|
|
245
|
+
])
|
|
246
|
+
}))
|
|
247
|
+
]), 1040);
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}), Re = /* @__PURE__ */ _({
|
|
251
|
+
name: "WForm",
|
|
252
|
+
__name: "Form",
|
|
253
|
+
props: {
|
|
254
|
+
formItems: {},
|
|
255
|
+
rowAttrs: { default: () => ({}) },
|
|
256
|
+
actionConfig: { default: () => ({}) },
|
|
257
|
+
model: { default: () => ({}) },
|
|
258
|
+
rules: {},
|
|
259
|
+
inline: { type: Boolean },
|
|
260
|
+
labelPosition: {},
|
|
261
|
+
labelWidth: {},
|
|
262
|
+
labelSuffix: {},
|
|
263
|
+
size: {},
|
|
264
|
+
disabled: { type: Boolean },
|
|
265
|
+
hideRequiredAsterisk: { type: Boolean },
|
|
266
|
+
showMessage: { type: Boolean },
|
|
267
|
+
inlineMessage: { type: Boolean },
|
|
268
|
+
statusIcon: { type: Boolean },
|
|
269
|
+
validateOnRuleChange: { type: Boolean },
|
|
270
|
+
scrollToError: { type: Boolean },
|
|
271
|
+
scrollIntoViewOptions: {}
|
|
272
|
+
},
|
|
273
|
+
emits: ["validate", "change", "action", "search", "reset", "submit", "cancel"],
|
|
274
|
+
setup(e, { expose: o, emit: l }) {
|
|
275
|
+
const r = e, h = l, g = X(), p = s(() => Object.fromEntries(
|
|
276
|
+
Object.entries(g).filter(
|
|
277
|
+
([t, n]) => t.startsWith("on") && typeof n == "function"
|
|
278
|
+
)
|
|
279
|
+
)), v = s(() => {
|
|
280
|
+
const { formItems: t, actionConfig: n, rowAttrs: a, ...d } = r, S = Object.fromEntries(
|
|
281
|
+
Object.entries(g).filter(
|
|
282
|
+
([y, D]) => !(y.startsWith("on") && typeof D == "function")
|
|
283
|
+
)
|
|
284
|
+
);
|
|
285
|
+
return { ...d, ...Te, ...S };
|
|
286
|
+
}), b = s(() => {
|
|
287
|
+
const { span: t } = r?.rowAttrs ?? {};
|
|
288
|
+
return r.formItems.filter((n) => N({ condition: n.vIf, data: r.model, defaultValue: !0 })).map((n) => {
|
|
289
|
+
const { colAttrs: a = {} } = n ?? {};
|
|
290
|
+
return { ...n, colAttrs: { ...a, span: a.span ?? t } };
|
|
291
|
+
});
|
|
292
|
+
}), C = q();
|
|
293
|
+
function I(t) {
|
|
294
|
+
const n = [];
|
|
295
|
+
for (const a in C)
|
|
296
|
+
a.startsWith(t) && n.push({
|
|
297
|
+
rawSlotName: a,
|
|
298
|
+
slotName: a.replace(t, ""),
|
|
299
|
+
slotFn: C[a]
|
|
300
|
+
});
|
|
301
|
+
return n;
|
|
302
|
+
}
|
|
303
|
+
const F = s(() => {
|
|
304
|
+
const t = I("form-item-"), n = /* @__PURE__ */ new Map();
|
|
305
|
+
for (const a of b.value) {
|
|
306
|
+
const d = I(`${a.prop}-`);
|
|
307
|
+
d.length > 0 && n.set(a.prop, d);
|
|
308
|
+
}
|
|
309
|
+
return { formItemSlots: t, dynamicComponentSlots: n };
|
|
310
|
+
}), i = s(() => r.rowAttrs && Object.keys(r.rowAttrs).length > 0), u = s(() => ({
|
|
311
|
+
row: v.value.inline || i.value ? Ae : "div",
|
|
312
|
+
col: i.value ? be : "div"
|
|
313
|
+
})), c = Y();
|
|
314
|
+
async function f({ eventName: t }) {
|
|
315
|
+
const n = ["submit", "search"], a = ["cancel", "reset"];
|
|
316
|
+
[...n, ...a].includes(t) && (n.includes(t) && await c.value?.validate?.(), a.includes(t) && c.value?.resetFields?.(), h(t)), h("action", t);
|
|
317
|
+
}
|
|
318
|
+
return o({
|
|
319
|
+
// element-plus form exposes
|
|
320
|
+
get fields() {
|
|
321
|
+
return c.value?.fields;
|
|
322
|
+
},
|
|
323
|
+
getField: (t) => c.value?.getField?.(t),
|
|
324
|
+
validate: () => c.value?.validate?.(),
|
|
325
|
+
validateField: (t) => c.value?.validateField?.(t),
|
|
326
|
+
resetFields: (t) => c.value?.resetFields?.(t),
|
|
327
|
+
clearValidate: (t) => c.value?.clearValidate?.(t),
|
|
328
|
+
scrollToField: (t) => c.value?.scrollToField?.(t)
|
|
329
|
+
}), (t, n) => {
|
|
330
|
+
const a = P("el-form");
|
|
331
|
+
return m(), E(a, w({
|
|
332
|
+
ref_key: "formRef",
|
|
333
|
+
ref: c
|
|
334
|
+
}, v.value, {
|
|
335
|
+
model: e.model,
|
|
336
|
+
onValidate: n[1] || (n[1] = (d, S, y) => t.$emit("validate", d, S, y)),
|
|
337
|
+
onSubmit: n[2] || (n[2] = J(() => {
|
|
338
|
+
}, ["prevent"]))
|
|
339
|
+
}), {
|
|
340
|
+
default: A(() => [
|
|
341
|
+
(m(), E(k(u.value.row), j(L(e.rowAttrs)), {
|
|
342
|
+
default: A(() => [
|
|
343
|
+
(m(!0), T(R, null, M(b.value, (d, S) => $((m(), E(k(u.value.col), w({
|
|
344
|
+
key: `${d.prop}-${S}`
|
|
345
|
+
}, { ref_for: !0 }, d.colAttrs), {
|
|
346
|
+
default: A(() => [
|
|
347
|
+
B(Be, {
|
|
348
|
+
modelValue: e.model[d.prop],
|
|
349
|
+
"onUpdate:modelValue": (y) => e.model[d.prop] = y,
|
|
350
|
+
"form-item": d,
|
|
351
|
+
"form-data": e.model,
|
|
352
|
+
"dynamic-comp-events": p.value,
|
|
353
|
+
"form-slots": F.value,
|
|
354
|
+
index: S,
|
|
355
|
+
onChange: n[0] || (n[0] = (y, D) => t.$emit("change", y, D))
|
|
356
|
+
}, null, 8, ["modelValue", "onUpdate:modelValue", "form-item", "form-data", "dynamic-comp-events", "form-slots", "index"])
|
|
357
|
+
]),
|
|
358
|
+
_: 2
|
|
359
|
+
}, 1040)), [
|
|
360
|
+
[U, Q(N)({ condition: d.vShow, data: r.model, defaultValue: !0 })]
|
|
361
|
+
])), 128)),
|
|
362
|
+
B(Ve, {
|
|
363
|
+
inline: v.value.inline,
|
|
364
|
+
"action-slot": t.$slots.action,
|
|
365
|
+
config: e.actionConfig,
|
|
366
|
+
onAction: f
|
|
367
|
+
}, null, 8, ["inline", "action-slot", "config"])
|
|
368
|
+
]),
|
|
369
|
+
_: 1
|
|
370
|
+
}, 16))
|
|
371
|
+
]),
|
|
372
|
+
_: 1
|
|
373
|
+
}, 16, ["model"]);
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
export {
|
|
378
|
+
Re as WForm,
|
|
379
|
+
Re as default
|
|
380
|
+
};
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@charset "UTF-8";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ButtonProps, ElCol, ElRow, FormItemInstance, FormRules } from 'element-plus';
|
|
2
|
+
import { FORM_ITEM_COMP_MAP } from '../config';
|
|
3
|
+
/**
|
|
4
|
+
* Element Plus Form Attributes
|
|
5
|
+
*
|
|
6
|
+
* 由于 `FormInstance['$slots']` 类型定义存在问题,
|
|
7
|
+
* 暂时无法直接使用 `FormInstance['$props']`,
|
|
8
|
+
* 因此手动定义了部分常用属性以确保类型安全。
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://element-plus.org/zh-CN/component/form.html#form-attributes Element Plus Form Attributes}
|
|
11
|
+
*/
|
|
12
|
+
export interface ElFormAttrs {
|
|
13
|
+
model?: Record<string, any>;
|
|
14
|
+
rules?: FormRules;
|
|
15
|
+
inline?: boolean;
|
|
16
|
+
labelPosition?: 'left' | 'right' | 'top';
|
|
17
|
+
labelWidth?: string | number;
|
|
18
|
+
labelSuffix?: string;
|
|
19
|
+
size?: 'large' | 'default' | 'small';
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
hideRequiredAsterisk?: boolean;
|
|
22
|
+
showMessage?: boolean;
|
|
23
|
+
inlineMessage?: boolean;
|
|
24
|
+
statusIcon?: boolean;
|
|
25
|
+
validateOnRuleChange?: boolean;
|
|
26
|
+
scrollToError?: boolean;
|
|
27
|
+
scrollIntoViewOptions?: ScrollIntoViewOptions;
|
|
28
|
+
}
|
|
29
|
+
/** Element Plus FormItem 属性 */
|
|
30
|
+
type ElFormItemAttrs = FormItemInstance['$props'];
|
|
31
|
+
/**
|
|
32
|
+
* 支持的表单组件枚举
|
|
33
|
+
*
|
|
34
|
+
* 显式定义所有可用的组件键名,确保类型提示正常工作
|
|
35
|
+
* 注意:由于 FORM_ITEM_COMP_MAP 使用了 Record<string, any> 避免类型推断超出限制,
|
|
36
|
+
* 我们需要显式定义键名类型,而不是从 typeof FORM_ITEM_COMP_MAP 中提取
|
|
37
|
+
*/
|
|
38
|
+
export type FormItemComp = 'autocomplete' | 'cascader' | 'checkbox' | 'color-picker' | 'color-picker-panel' | 'date-picker' | 'date-picker-panel' | 'input' | 'input-number' | 'input-tag' | 'mention' | 'radio' | 'rate' | 'select' | 'select-v2' | 'slider' | 'switch' | 'time-picker' | 'time-select' | 'transfer' | 'tree-select' | 'custom';
|
|
39
|
+
/** 表单组件配置映射类型 */
|
|
40
|
+
type FormCompConfig = typeof FORM_ITEM_COMP_MAP;
|
|
41
|
+
/**
|
|
42
|
+
* 根据组件类型推断对应的属性类型(排除事件处理器)
|
|
43
|
+
* @template T - 组件类型
|
|
44
|
+
*/
|
|
45
|
+
export type FormItemCompAttrs<T extends FormItemComp = FormItemComp> = Omit<InstanceType<FormCompConfig[T]>['$props'], `on${string}`>;
|
|
46
|
+
export type RowAttrs = InstanceType<typeof ElRow>['$props'] & {
|
|
47
|
+
span?: number;
|
|
48
|
+
};
|
|
49
|
+
export type ColAttrs = InstanceType<typeof ElCol>['$props'];
|
|
50
|
+
/**
|
|
51
|
+
* FormItem 属性
|
|
52
|
+
*
|
|
53
|
+
* 扩展自 Element Plus 的 FormItem 组件属性,添加了自定义配置选项
|
|
54
|
+
*
|
|
55
|
+
* @template C - 组件类型
|
|
56
|
+
* @extends {ElFormItemAttrs} Element Plus FormItem 组件原始属性
|
|
57
|
+
* @property {C} comp 使用的组件类型
|
|
58
|
+
* @property {FormItemCompAttrs<C>} [compAttrs] 传递给组件的属性配置对象
|
|
59
|
+
* @property {boolean | ((data?: any) => boolean)} [vIf] 条件渲染控制,支持布尔值或接收表单数据的函数
|
|
60
|
+
* @property {boolean | ((data?: any) => boolean)} [vShow] 显示/隐藏控制,支持布尔值或接收表单数据的函数
|
|
61
|
+
*
|
|
62
|
+
* @see {@link https://element-plus.org/zh-CN/component/form.html#form-item-attributes Element Plus Form Item Attributes}
|
|
63
|
+
*/
|
|
64
|
+
export interface FormItem<C extends FormItemComp = FormItemComp> extends ElFormItemAttrs {
|
|
65
|
+
prop: string;
|
|
66
|
+
comp: C;
|
|
67
|
+
compAttrs?: FormItemCompAttrs<C>;
|
|
68
|
+
vIf?: boolean | ((data?: any) => boolean);
|
|
69
|
+
vShow?: boolean | ((data?: any) => boolean);
|
|
70
|
+
colAttrs?: ColAttrs;
|
|
71
|
+
}
|
|
72
|
+
/** formItems 配置类型 - 推断每一项的 comp 对应的组件类型 */
|
|
73
|
+
export type FormItems = {
|
|
74
|
+
[K in FormItemComp]: FormItem<K>;
|
|
75
|
+
}[FormItemComp][];
|
|
76
|
+
/**
|
|
77
|
+
* 表单项插槽作用域参数
|
|
78
|
+
*
|
|
79
|
+
* @property {any} value 当前表单项组件的值
|
|
80
|
+
* @property {Record<string, any>} form 表单数据
|
|
81
|
+
* @property {FormItem} formItem 表单项配置
|
|
82
|
+
*/
|
|
83
|
+
export interface FormItemSlotScope {
|
|
84
|
+
value: any;
|
|
85
|
+
form: Record<string, any>;
|
|
86
|
+
formItem: FormItem;
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
}
|
|
89
|
+
/** 允许数组类型 */
|
|
90
|
+
export type Arrayable<T> = T | T[];
|
|
91
|
+
/**
|
|
92
|
+
* 标准化的表单操作按钮配置项
|
|
93
|
+
*
|
|
94
|
+
* @extends {ButtonProps} el-button 的属性
|
|
95
|
+
* @property {string} label 按钮文字
|
|
96
|
+
* @property {string} eventName 事件名称
|
|
97
|
+
*/
|
|
98
|
+
export interface ActionConfigButtonItem extends Partial<ButtonProps> {
|
|
99
|
+
label?: string;
|
|
100
|
+
eventName: string;
|
|
101
|
+
}
|
|
102
|
+
/** 表单操作按钮配置项 */
|
|
103
|
+
export type ActionConfigButtons = ActionConfigButtonItem | 'submit' | 'cancel' | 'search' | 'reset';
|
|
104
|
+
/**
|
|
105
|
+
* 表单操作项配置
|
|
106
|
+
*
|
|
107
|
+
* @property {boolean | ((data?: any) => boolean)} vIf 是否显示
|
|
108
|
+
* @property {boolean | ((data?: any) => boolean)} vShow 是否显示
|
|
109
|
+
* @property {ActionConfigButtons[]} buttons 按钮列表
|
|
110
|
+
*/
|
|
111
|
+
export interface ActionConfig {
|
|
112
|
+
vIf?: boolean | ((data?: any) => boolean);
|
|
113
|
+
vShow?: boolean | ((data?: any) => boolean);
|
|
114
|
+
buttons?: ActionConfigButtons[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 事件拓展参数
|
|
118
|
+
* @template K 属性名类型
|
|
119
|
+
*/
|
|
120
|
+
export interface EventExtendedParams<K = string> {
|
|
121
|
+
prop: K;
|
|
122
|
+
index: number;
|
|
123
|
+
formItem: FormItem;
|
|
124
|
+
}
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iswangh/element-plus-kit-form",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Element Plus Kit Form component",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./style.css": "./dist/style.css"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"README.md",
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"element-plus": "^2.11.7",
|
|
23
|
+
"vue": "^3.5.23"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@iswangh/element-plus-kit-core": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@element-plus/icons-vue": "^2.3.2",
|
|
30
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
31
|
+
"element-plus": "^2.11.7",
|
|
32
|
+
"sass": "^1.93.3",
|
|
33
|
+
"typescript": "^5.9.2",
|
|
34
|
+
"vite": "^7.1.5",
|
|
35
|
+
"vite-plugin-dts": "^4.5.4",
|
|
36
|
+
"vue": "^3.5.23",
|
|
37
|
+
"vue-tsc": "^3.0.7"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "vite build",
|
|
44
|
+
"dev": "vite build --watch",
|
|
45
|
+
"type-check": "vue-tsc --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|