general-basic-form 1.0.25 → 1.0.27

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 CHANGED
@@ -1,191 +1,356 @@
1
- # GeneralBasicForm
2
-
3
- 一个兼容 Vue2 和 Vue3 的表单组件 <br/>
4
- 示例:
5
-
6
- <GeneralBasicForm
7
- :showSearch="showSearch"
8
- :getList="getList"
9
- :formItem="formItem"
10
- :size="size"
11
- ref="generalBasicForm"
12
- labelWidth="90px"
13
- >
14
- ...一些传入插槽的内容
15
- </GeneralBasicForm>
16
-
17
- ![image-20210903165502942](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202109031655830.png)
18
-
19
- 在单纯作为表单的时候可以这样使用:
20
-
21
- <GeneralBasicForm
22
- formOnly
23
- :formItem="formItem"
24
- size="small"
25
- ref="generalBasicForm"
26
- :labelWidth="formLabelWidth"
27
- :formData: {
28
- // 外部传入的表单数据,用于回填
29
- }
30
- noUrlParameters
31
- />
32
-
33
- <style lang="scss" scoped>
34
- :deep {
35
- .el-form-item {
36
- margin-bottom: 22px;
37
- }
38
- }
39
- </style>
40
-
41
- 表单数据校验需要拿到内部表单的ref
42
-
43
- this.$refs["generalBasicForm"].$refs["queryFormRef"]
44
- .validate(
45
- async (valid) => {
46
- if (valid) {
47
- console.log(this.$refs["generalBasicForm"]["queryParams"]);
48
- }
49
- }
50
- );
51
-
52
- ![image-20211014191532067](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202110141915657.png)
53
-
54
- 数据示例:
55
-
56
- showSearch: true, // 显示搜索条件
57
- getList(); // 请求数据的函数
58
- formOnly:true // 只展示表单不展示按钮
59
- noUrlParameters:true // 不接受和不改变url的参数
60
- formItem: [
61
- { label: "款式名称",
62
- prop: "bsName",
63
- type: "input",
64
- placeholder: "请输入图片名称/分类名称/图片标签",
65
- rules: [
66
- {
67
- message: "请输入信息"
68
- },
69
- {
70
- pattern: /^\w+[\,\,\-\w' '#]+$/,
71
- message: "请输入正确的Invoice单号"
72
- }
73
- ],
74
- template: {
75
- suffix: () => {
76
- return <svg-icon icon-class="baifenbi" />;
77
- },
78
- },
79
- maxlength: "3000"},
80
- {
81
- label: "二次工艺",
82
- prop: "spName",
83
- type: "select",
84
- multiple:true, //多选
85
- option: [
86
- { value: "3", desc: "满印" },
87
- { value: "1", desc: "区域印花" },
88
- { value: "2", desc: "绣花" },
89
- ],
90
- },
91
- {
92
- label: "创建时间",
93
- prop: "create_time",
94
- type: "date-picker",
95
- "value-format": "yyyyMMdd"
96
- },
97
- {
98
- label: "二次工艺成本价格(人民币分)",
99
- prop: "spCost",
100
- type: "input-number",
101
- "controls-position": "right",
102
- min: 0,
103
- rules: [
104
- {
105
- required: true,
106
- message: "请输入二次工艺成本价格",
107
- trigger: "blur",
108
- },
109
- ],
110
- },
111
- {
112
- label: "分类",
113
- prop: "分类",
114
- type: "cascader",
115
- options: [
116
- {
117
- value: "zhinan",
118
- label: "指南",
119
- children: [
120
- {
121
- value: "shejiyuanze",
122
- label: "设计原则",
123
- children: [
124
- {
125
- value: "yizhi",
126
- label: "一致",
127
- },
128
- {
129
- value: "fankui",
130
- label: "反馈",
131
- },
132
- {
133
- value: "xiaolv",
134
- label: "效率",
135
- },
136
- {
137
- value: "kekong",
138
- label: "可控",
139
- },
140
- ],
141
- },
142
- {
143
- value: "daohang",
144
- label: "导航",
145
- children: [
146
- {
147
- value: "cexiangdaohang",
148
- label: "侧向导航",
149
- },
150
- {
151
- value: "dingbudaohang",
152
- label: "顶部导航",
153
- },
154
- ],
155
- },
156
- ],
157
- },
158
- {
159
- value: "ziyuan",
160
- label: "资源",
161
- children: [
162
- {
163
- value: "axure",
164
- label: "Axure Components",
165
- },
166
- {
167
- value: "sketch",
168
- label: "Sketch Templates",
169
- },
170
- {
171
- value: "jiaohu",
172
- label: "组件交互文档",
173
- },
174
- ],
175
- },
176
- ],
177
- },
178
- ],
179
- //分别支持input输入框,select单选框,date-picker日期选择器,cascader层级选择器 四种组件
180
-
181
- //date-picker可以传入'start-placeholder'和'end-placeholder',其他组件支持placeholder传入
182
-
183
- //rules为表单校验规则,每个组件都可以传入
184
-
185
- //input支持template,支持以下几个属性:
186
- //prefix 输入框头部内容,只对 type="text"(默认) 有效
187
- //suffix 输入框尾部内容,只对 type="text" 有效
188
- //prepend 输入框前置内容,只对 type="text" 有效
189
- //append 输入框后置内容,只对 type="text" 有效
190
- 安装:npm i general-basic-form<br/>
191
- install: npm i general-basic-form
1
+ # GeneralBasicForm
2
+
3
+ 一个兼容 Vue2 和 Vue3 的表单组件,支持typescript,vue2请使用@1版本,Vue3请使用@2版本 <br/>
4
+
5
+ 示例:
6
+
7
+ 因为兼容性问题,目前只能使用完整引入
8
+
9
+ ```
10
+ import ElementPlus from 'element-plus'
11
+ import 'element-plus/dist/index.css'
12
+ app.use(ElementPlus)
13
+ ```
14
+
15
+ ```
16
+ import { VGeneralBasicForm } from "general-basic-form";
17
+ ```
18
+
19
+ <VGeneralBasicForm
20
+ :showSearch="showSearch"
21
+ :getList="getList"
22
+ :formItem="formItem"
23
+ :size="size"
24
+ ref="VGeneralBasicFormRef"
25
+ labelWidth="90px"
26
+ >
27
+ ...一些传入插槽的内容
28
+ </VGeneralBasicForm>
29
+
30
+ ![image-20210903165502942](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202109031655830.png)
31
+
32
+ 在单纯作为表单的时候可以这样使用:
33
+
34
+ <VGeneralBasicForm
35
+ formOnly
36
+ :formItem="formItem"
37
+ size="small"
38
+ ref="VGeneralBasicFormRef"
39
+ :labelWidth="formLabelWidth"
40
+ :formData: {
41
+ // 外部传入的表单数据,用于回填
42
+ }
43
+ noUrlParameters
44
+ :afterReset="afterReset"
45
+ />
46
+
47
+ <style lang="scss" scoped>
48
+ :deep {
49
+ .el-form-item {
50
+ margin-bottom: 22px;
51
+ }
52
+ }
53
+ </style>
54
+
55
+ getList会传出默认的参数,首次请求时会有页数和分页大小,重置后会传出默认页数1
56
+
57
+ async getList(
58
+ params = {
59
+ page: Number(this.$route.query.page) || 1,
60
+ limit: Number(this.$route.query.limit) || 10,
61
+ }
62
+ ) {}
63
+
64
+ 表单数据校验需要拿到内部表单的ref
65
+
66
+ const VGeneralBasicFormRef = this.$refs["VGeneralBasicFormRef"];
67
+ VGeneralBasicFormRef.$refs["queryFormRef"].validate(async (boolean, object) => {
68
+ if (boolean) {
69
+ console.log(this.$refs["VGeneralBasicFormRef"]["queryParams"]);
70
+ }
71
+ });
72
+
73
+ 校验单个字段
74
+ const VGeneralBasicFormRef = this.$refs["VGeneralBasicFormRef"];
75
+ const state = await new Promise((resolve, reject) => {
76
+ VGeneralBasicFormRef.$refs["queryFormRef"]?.validateField(
77
+ "accNum",
78
+ (errorMessage) => {
79
+ if (!errorMessage) {
80
+ const { accNum } = VGeneralBasicFormRef["queryParams"];
81
+ http
82
+ .getMobileByAccNum({ accNum })
83
+ .then((res) => {
84
+ if (res) {
85
+ if (res.data) {
86
+ }
87
+ resolve(true);
88
+ }else {
89
+ resolve(false);
90
+ }
91
+ })
92
+ .catch((error) => {
93
+ resolve(false);
94
+ });
95
+ } else {
96
+ resolve(false);
97
+ }
98
+ }
99
+ );
100
+ });
101
+
102
+
103
+ ![image-20211014191532067](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202110141915657.png)
104
+
105
+ 数据示例:
106
+
107
+ showSearch: true, // 显示搜索条件
108
+ getList(); // 请求数据的函数
109
+ afterReset(); // 在重置按钮点击完后但还没重新请求时触发的的函数
110
+ formOnly:true // 只展示表单不展示按钮
111
+ noUrlParameters:true // 不接受和不改变url的参数
112
+ loading:false // 加载动画
113
+ formData:{} // 注意,因为可能出现的性能问题在组件watch formData的变化时没有使用deep,所以有时候深度的修改会不生效,导致表单数据不完整
114
+ noInputBlank: true //校验input框不能仅输入空格
115
+ //例子:formData.value.x=y ✘ | formData.value={...formData.value,x:y}
116
+ formItem: [
117
+ { // vue2未实现
118
+ label: '',
119
+ prop: 'bsName35',
120
+ type: 'divider',
121
+ dividerSetting: {
122
+ },
123
+ template: {
124
+ default: () => {
125
+ return "123123123";
126
+ },
127
+ },
128
+ },
129
+ { label: "款式名称",
130
+ prop: "bsName",
131
+ type: "input",
132
+ inputSetting: {
133
+ placeholder: '请输入手机验证码',
134
+ style: 'width: 100%'
135
+ },
136
+ rules: [
137
+ {
138
+ message: "请输入信息"
139
+ },
140
+ {
141
+ pattern: /^\w+[\,\,\-\w' '#]+$/,
142
+ message: "请输入正确的Invoice单号"
143
+ }
144
+ ],
145
+ verificationSetting: {
146
+ defaultText: "查询",
147
+ restTime: 5,
148
+ },
149
+ template: {
150
+ suffix: () => {
151
+ return <svg-icon icon-class="baifenbi" />;
152
+ },
153
+ },
154
+ },
155
+ {
156
+ label: "二次工艺",
157
+ prop: "spName",
158
+ type: "select",
159
+ multiple:true, //多选
160
+ selectSetting:{},
161
+ option: [
162
+ { value: "3", label: "满印" },
163
+ { value: "1", label: "区域印花" },
164
+ { value: "2", label: "绣花" },
165
+ ],
166
+ },
167
+ {
168
+ label: "创建时间",
169
+ prop: "create_time",
170
+ type: "date-picker",
171
+ datePackerSetting: {
172
+ "range-separator": "",
173
+ }
174
+ },
175
+ {
176
+ label: "二次工艺成本价格(人民币分)",
177
+ prop: "spCost",
178
+ type: "input-number",
179
+ "controls-position": "right",
180
+ min: 0,
181
+ rules: [
182
+ {
183
+ required: true,
184
+ message: "请输入二次工艺成本价格",
185
+ trigger: "blur",
186
+ },
187
+ ],
188
+ },
189
+ {
190
+ // vue2未实现
191
+ label: '',
192
+ prop: 'bsName2',
193
+ type: 'input-graphic-verification',
194
+ inputSetting: {
195
+ placeholder: '请输入图形验证码',
196
+ style: 'width: 100%'
197
+ },
198
+ rules: [
199
+ {
200
+ message: '请输入图形验证码',
201
+ trigger: 'blur'
202
+ }
203
+ ],
204
+ graphicSrc, // 请求图像的URL
205
+ getGraphic, // 重新请求图像的函数
206
+ key:Math.random(), // 必传,图像更新后必须更新。如果URL会变化也可以用URL代替
207
+ },
208
+ {
209
+ label: '',
210
+ prop: 'bsName3',
211
+ type: 'input-mobile-verification',
212
+ inputSetting: {
213
+ placeholder: '请输入手机验证码',
214
+ style: 'width: 100%'
215
+ },
216
+ rules: [
217
+ {
218
+ message: '请输入手机验证码',
219
+ trigger: 'blur'
220
+ }
221
+ ],
222
+ getSmscode,// 获取验证码的回调函数,获取失败必须返回false,否则计时器不会重新计算
223
+ },
224
+ {
225
+ // vue2未实现
226
+ label: '是否必填',
227
+ prop: 'is_optional',
228
+ type: 'radio',
229
+ radioGroupSetting: {
230
+ disabled: true
231
+ },
232
+ option: [
233
+ { value: '是', label: 'true',border: true },
234
+ { value: '否', label: 'false' }
235
+ ],
236
+ rules: [
237
+ {
238
+ required: true,
239
+ message: '请输入标签项名称',
240
+ trigger: 'blur'
241
+ }
242
+ ]
243
+ },
244
+ {
245
+ // vue2未实现
246
+ label: '多选',
247
+ prop: 'is_multi',
248
+ type: 'checkbox',
249
+ checkboxGroupSetting: {
250
+ },
251
+ option: [
252
+ { value: '是', label: 'true' },
253
+ { value: '否', label: 'false' }
254
+ ],
255
+ rules: []
256
+ },
257
+ {
258
+ // vue2未实现
259
+ label: '受访人',
260
+ prop: 'contactors',
261
+ type: 'form-item-slot',
262
+ name: "contactors"
263
+ // 插槽组件使用:
264
+ // <VGeneralBasicForm ...>
265
+ // <template #contactors>
266
+ // <div>一些组件
267
+ // 一些组件
268
+ // <el-form-item prop="contactors">...</el-form-item>
269
+ // </div>
270
+ // </template>
271
+ // </VGeneralBasicForm>
272
+ },
273
+ {
274
+ label: "分类",
275
+ prop: "分类",
276
+ type: "cascader",
277
+ selectSetting:{},
278
+ options: [
279
+ {
280
+ value: "zhinan",
281
+ label: "指南",
282
+ children: [
283
+ {
284
+ value: "shejiyuanze",
285
+ label: "设计原则",
286
+ children: [
287
+ {
288
+ value: "yizhi",
289
+ label: "一致",
290
+ },
291
+ {
292
+ value: "fankui",
293
+ label: "反馈",
294
+ },
295
+ {
296
+ value: "xiaolv",
297
+ label: "效率",
298
+ },
299
+ {
300
+ value: "kekong",
301
+ label: "可控",
302
+ },
303
+ ],
304
+ },
305
+ {
306
+ value: "daohang",
307
+ label: "导航",
308
+ children: [
309
+ {
310
+ value: "cexiangdaohang",
311
+ label: "侧向导航",
312
+ },
313
+ {
314
+ value: "dingbudaohang",
315
+ label: "顶部导航",
316
+ },
317
+ ],
318
+ },
319
+ ],
320
+ },
321
+ {
322
+ value: "ziyuan",
323
+ label: "资源",
324
+ children: [
325
+ {
326
+ value: "axure",
327
+ label: "Axure Components",
328
+ },
329
+ {
330
+ value: "sketch",
331
+ label: "Sketch Templates",
332
+ },
333
+ {
334
+ value: "jiaohu",
335
+ label: "组件交互文档",
336
+ },
337
+ ],
338
+ },
339
+ ],
340
+ },
341
+ ],
342
+
343
+ //rules为表单校验规则,每个组件都可以传入
344
+
345
+ //input支持template,支持以下几个属性:
346
+ //prefix 输入框头部内容,只对 type="text"(默认) 有效
347
+ //suffix 输入框尾部内容,只对 type="text" 有效
348
+ //prepend 输入框前置内容,只对 type="text" 有效
349
+ //append 输入框后置内容,只对 type="text" 有效
350
+
351
+ //divider支持template:
352
+ //default
353
+
354
+
355
+ 安装:npm i general-basic-form<br/>
356
+ install: npm i general-basic-form
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @Author: 陈德立*******419287484@qq.com
3
+ * @Date: 2023-11-07 17:55:59
4
+ * @LastEditTime: 2023-11-08 10:24:14
5
+ * @LastEditors: 陈德立*******419287484@qq.com
6
+ * @Github: https://github.com/Alan1034
7
+ * @Description:
8
+ * @FilePath: \GeneralBasicForm\public\index.d.ts
9
+ *
10
+ */
11
+ /// <reference types="vite/client" />
12
+ declare module "*.vue" {
13
+ import { DefineComponent } from "vue"
14
+ const component: DefineComponent<{}, {}, any>
15
+ export default component
16
+ }
17
+ declare module "general-basic-form";