sinosoft-common-form 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 +29 -0
- package/common-form.es.js +247 -0
- package/common-form.umd.js +1 -0
- package/package.json +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
参数介绍
|
|
2
|
+
|
|
3
|
+
Form 属性
|
|
4
|
+
|
|
5
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
6
|
+
|-------------|------------------------------------------------|--------|--------|
|
|
7
|
+
| v-model | 表单数据,双向绑定(字段需与 prop 属性一样) | Object | - |
|
|
8
|
+
| form-column | 表单配置项,详情见下方 Column 属性 | Array | - |
|
|
9
|
+
| rules | 表单规则验证,校验规则请参考elementplus官方文档 | Array | - |
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
Column 配置项
|
|
14
|
+
|
|
15
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
16
|
+
|---------|----------------------------------------------|--------|--------|
|
|
17
|
+
| type | 表单类型,elementplus的组件以及自己定义的组件 | String | - |
|
|
18
|
+
| label | el-form-item label 属性 | String | - |
|
|
19
|
+
| prop | el-form-item prop 属性 | String | - |
|
|
20
|
+
| field | el-form-item prop 属性 | String | - |
|
|
21
|
+
| options | elementplus的组件自定义的组件的props | Object | - |
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Form 方法
|
|
26
|
+
|
|
27
|
+
| 事件名 | 说明 | 回调参数 |
|
|
28
|
+
|--------|--------------------------|----------|
|
|
29
|
+
| submit | 点击确认按钮拿到表单数据 | model |
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { defineComponent as A, ref as $, computed as G, resolveComponent as s, openBlock as o, createBlock as r, mergeProps as J, withModifiers as Q, unref as k, withCtx as a, createElementBlock as x, Fragment as w, renderList as B, createVNode as i, createTextVNode as V, toDisplayString as m, withKeys as W, renderSlot as X, createCommentVNode as L } from "vue";
|
|
2
|
+
const R = /* @__PURE__ */ A({
|
|
3
|
+
__name: "Index",
|
|
4
|
+
props: {
|
|
5
|
+
fieldList: null,
|
|
6
|
+
model: null,
|
|
7
|
+
options: null
|
|
8
|
+
},
|
|
9
|
+
emits: ["submit", "reset", "cancel"],
|
|
10
|
+
setup(h, { expose: K, emit: C }) {
|
|
11
|
+
const _ = h, n = $({}), y = $(), v = G(() => Object.assign({
|
|
12
|
+
labelPosition: "right",
|
|
13
|
+
disabled: !1,
|
|
14
|
+
submitButtonText: "提交",
|
|
15
|
+
resetButtonText: "重置",
|
|
16
|
+
cancelButtonText: "取消"
|
|
17
|
+
}, _ == null ? void 0 : _.options));
|
|
18
|
+
K({
|
|
19
|
+
formRef: y
|
|
20
|
+
}), _.fieldList.map((t) => {
|
|
21
|
+
const u = t.type === "checkbox" ? [] : "";
|
|
22
|
+
_.model ? n.value = _.model : n.value[t.field] = t.value || u;
|
|
23
|
+
});
|
|
24
|
+
const T = (t) => {
|
|
25
|
+
t && t.validate((u) => {
|
|
26
|
+
if (u)
|
|
27
|
+
C("submit", n.value);
|
|
28
|
+
else
|
|
29
|
+
return !1;
|
|
30
|
+
});
|
|
31
|
+
}, S = (t) => {
|
|
32
|
+
t && T(y.value);
|
|
33
|
+
}, Y = (t) => {
|
|
34
|
+
t && t.resetFields();
|
|
35
|
+
};
|
|
36
|
+
return (t, u) => {
|
|
37
|
+
const D = s("el-radio"), F = s("el-radio-group"), b = s("el-form-item"), M = s("el-checkbox"), N = s("el-checkbox-group"), H = s("el-option"), j = s("el-select"), z = s("el-date-picker"), I = s("el-input"), U = s("el-button"), O = s("el-form");
|
|
38
|
+
return o(), r(O, J({
|
|
39
|
+
onSubmit: u[3] || (u[3] = Q(() => {
|
|
40
|
+
}, ["prevent"])),
|
|
41
|
+
model: n.value
|
|
42
|
+
}, k(v), {
|
|
43
|
+
ref_key: "formRef",
|
|
44
|
+
ref: y
|
|
45
|
+
}), {
|
|
46
|
+
default: a(() => [
|
|
47
|
+
(o(!0), x(w, null, B(h.fieldList, (e, q) => (o(), r(b, { key: q }, {
|
|
48
|
+
default: a(() => [
|
|
49
|
+
e.type === "radio" ? (o(), r(b, {
|
|
50
|
+
key: 0,
|
|
51
|
+
label: e.label,
|
|
52
|
+
rules: e.rules,
|
|
53
|
+
prop: [e.field]
|
|
54
|
+
}, {
|
|
55
|
+
default: a(() => [
|
|
56
|
+
i(F, {
|
|
57
|
+
modelValue: n.value[e.field],
|
|
58
|
+
"onUpdate:modelValue": (l) => n.value[e.field] = l,
|
|
59
|
+
disabled: e.disabled
|
|
60
|
+
}, {
|
|
61
|
+
default: a(() => {
|
|
62
|
+
var l;
|
|
63
|
+
return [
|
|
64
|
+
(o(!0), x(w, null, B((l = e.options) == null ? void 0 : l.data, (d) => {
|
|
65
|
+
var p, c;
|
|
66
|
+
return o(), r(D, {
|
|
67
|
+
label: d[((p = e.options) == null ? void 0 : p.valueKey) || "value"],
|
|
68
|
+
size: "large",
|
|
69
|
+
key: d[((c = e.options) == null ? void 0 : c.valueKey) || "value"]
|
|
70
|
+
}, {
|
|
71
|
+
default: a(() => {
|
|
72
|
+
var f;
|
|
73
|
+
return [
|
|
74
|
+
V(m(d[((f = e.options) == null ? void 0 : f.labelkey) || "label"]), 1)
|
|
75
|
+
];
|
|
76
|
+
}),
|
|
77
|
+
_: 2
|
|
78
|
+
}, 1032, ["label"]);
|
|
79
|
+
}), 128))
|
|
80
|
+
];
|
|
81
|
+
}),
|
|
82
|
+
_: 2
|
|
83
|
+
}, 1032, ["modelValue", "onUpdate:modelValue", "disabled"])
|
|
84
|
+
]),
|
|
85
|
+
_: 2
|
|
86
|
+
}, 1032, ["label", "rules", "prop"])) : e.type === "checkbox" ? (o(), r(b, {
|
|
87
|
+
key: 1,
|
|
88
|
+
label: e.label,
|
|
89
|
+
rules: e.rules,
|
|
90
|
+
prop: [e.field]
|
|
91
|
+
}, {
|
|
92
|
+
default: a(() => [
|
|
93
|
+
i(N, {
|
|
94
|
+
modelValue: n.value[e.field],
|
|
95
|
+
"onUpdate:modelValue": (l) => n.value[e.field] = l,
|
|
96
|
+
disabled: e.disabled
|
|
97
|
+
}, {
|
|
98
|
+
default: a(() => {
|
|
99
|
+
var l;
|
|
100
|
+
return [
|
|
101
|
+
(o(!0), x(w, null, B((l = e.options) == null ? void 0 : l.data, (d) => {
|
|
102
|
+
var p, c;
|
|
103
|
+
return o(), r(M, {
|
|
104
|
+
key: d[((p = e.options) == null ? void 0 : p.valueKey) || "value"],
|
|
105
|
+
label: d[((c = e.options) == null ? void 0 : c.valueKey) || "value"]
|
|
106
|
+
}, {
|
|
107
|
+
default: a(() => {
|
|
108
|
+
var f;
|
|
109
|
+
return [
|
|
110
|
+
V(m(d[((f = e.options) == null ? void 0 : f.labelkey) || "label"]), 1)
|
|
111
|
+
];
|
|
112
|
+
}),
|
|
113
|
+
_: 2
|
|
114
|
+
}, 1032, ["label"]);
|
|
115
|
+
}), 128))
|
|
116
|
+
];
|
|
117
|
+
}),
|
|
118
|
+
_: 2
|
|
119
|
+
}, 1032, ["modelValue", "onUpdate:modelValue", "disabled"])
|
|
120
|
+
]),
|
|
121
|
+
_: 2
|
|
122
|
+
}, 1032, ["label", "rules", "prop"])) : e.type === "select" ? (o(), r(b, {
|
|
123
|
+
key: 2,
|
|
124
|
+
label: e.label,
|
|
125
|
+
rules: e.rules,
|
|
126
|
+
prop: [e.field]
|
|
127
|
+
}, {
|
|
128
|
+
default: a(() => {
|
|
129
|
+
var l;
|
|
130
|
+
return [
|
|
131
|
+
i(j, {
|
|
132
|
+
modelValue: n.value[e.field],
|
|
133
|
+
"onUpdate:modelValue": (d) => n.value[e.field] = d,
|
|
134
|
+
placeholder: ((l = e.options) == null ? void 0 : l.placeholder) || "请选择",
|
|
135
|
+
clearable: e.clearable
|
|
136
|
+
}, {
|
|
137
|
+
default: a(() => {
|
|
138
|
+
var d;
|
|
139
|
+
return [
|
|
140
|
+
(o(!0), x(w, null, B((d = e.options) == null ? void 0 : d.data, (p) => {
|
|
141
|
+
var c, f, P;
|
|
142
|
+
return o(), r(H, {
|
|
143
|
+
key: p[((c = e.options) == null ? void 0 : c.valueKey) || "value"],
|
|
144
|
+
label: p[((f = e.options) == null ? void 0 : f.labelkey) || "label"],
|
|
145
|
+
value: p[((P = e.options) == null ? void 0 : P.valueKey) || "value"]
|
|
146
|
+
}, null, 8, ["label", "value"]);
|
|
147
|
+
}), 128))
|
|
148
|
+
];
|
|
149
|
+
}),
|
|
150
|
+
_: 2
|
|
151
|
+
}, 1032, ["modelValue", "onUpdate:modelValue", "placeholder", "clearable"])
|
|
152
|
+
];
|
|
153
|
+
}),
|
|
154
|
+
_: 2
|
|
155
|
+
}, 1032, ["label", "rules", "prop"])) : e.type === "datetime" ? (o(), r(b, {
|
|
156
|
+
key: 3,
|
|
157
|
+
label: e.label,
|
|
158
|
+
rules: e.rules,
|
|
159
|
+
prop: [e.field]
|
|
160
|
+
}, {
|
|
161
|
+
default: a(() => [
|
|
162
|
+
i(z, {
|
|
163
|
+
modelValue: n.value[e.field],
|
|
164
|
+
"onUpdate:modelValue": (l) => n.value[e.field] = l,
|
|
165
|
+
readonly: e.readonly,
|
|
166
|
+
type: "datetime",
|
|
167
|
+
placeholder: e.placeholder || e.label,
|
|
168
|
+
"default-time": t.defaultTime,
|
|
169
|
+
"value-format": e.format || "YYYY-MM-DD HH:mm:ss"
|
|
170
|
+
}, null, 8, ["modelValue", "onUpdate:modelValue", "readonly", "placeholder", "default-time", "value-format"])
|
|
171
|
+
]),
|
|
172
|
+
_: 2
|
|
173
|
+
}, 1032, ["label", "rules", "prop"])) : (o(), r(b, {
|
|
174
|
+
key: 4,
|
|
175
|
+
label: e.label,
|
|
176
|
+
rules: e.rules,
|
|
177
|
+
prop: [e.field]
|
|
178
|
+
}, {
|
|
179
|
+
default: a(() => [
|
|
180
|
+
i(I, {
|
|
181
|
+
modelValue: n.value[e.field],
|
|
182
|
+
"onUpdate:modelValue": (l) => n.value[e.field] = l,
|
|
183
|
+
readonly: e.readonly,
|
|
184
|
+
type: e.type ?? "text",
|
|
185
|
+
placeholder: e.placeholder || e.label,
|
|
186
|
+
disabled: e.disabled,
|
|
187
|
+
showPassword: e.showPassword,
|
|
188
|
+
clearable: e.clearable,
|
|
189
|
+
onKeyup: W((l) => S(e.enterable), ["enter"])
|
|
190
|
+
}, null, 8, ["modelValue", "onUpdate:modelValue", "readonly", "type", "placeholder", "disabled", "showPassword", "clearable", "onKeyup"])
|
|
191
|
+
]),
|
|
192
|
+
_: 2
|
|
193
|
+
}, 1032, ["label", "rules", "prop"]))
|
|
194
|
+
]),
|
|
195
|
+
_: 2
|
|
196
|
+
}, 1024))), 128)),
|
|
197
|
+
i(b, null, {
|
|
198
|
+
default: a(() => [
|
|
199
|
+
X(t.$slots, "buttons", {
|
|
200
|
+
model: n.value,
|
|
201
|
+
formRef: y.value
|
|
202
|
+
}, () => [
|
|
203
|
+
i(U, {
|
|
204
|
+
type: "primary",
|
|
205
|
+
onClick: u[0] || (u[0] = (e) => T(y.value))
|
|
206
|
+
}, {
|
|
207
|
+
default: a(() => [
|
|
208
|
+
V(m(k(v).submitButtonText), 1)
|
|
209
|
+
]),
|
|
210
|
+
_: 1
|
|
211
|
+
}),
|
|
212
|
+
k(v).showResetButton ? (o(), r(U, {
|
|
213
|
+
key: 0,
|
|
214
|
+
type: "info",
|
|
215
|
+
onClick: u[1] || (u[1] = (e) => Y(y.value))
|
|
216
|
+
}, {
|
|
217
|
+
default: a(() => [
|
|
218
|
+
V(m(k(v).resetButtonText), 1)
|
|
219
|
+
]),
|
|
220
|
+
_: 1
|
|
221
|
+
})) : L("", !0),
|
|
222
|
+
k(v).showCancelButton ? (o(), r(U, {
|
|
223
|
+
key: 1,
|
|
224
|
+
onClick: u[2] || (u[2] = (e) => C("cancel"))
|
|
225
|
+
}, {
|
|
226
|
+
default: a(() => [
|
|
227
|
+
V(m(k(v).cancelButtonText), 1)
|
|
228
|
+
]),
|
|
229
|
+
_: 1
|
|
230
|
+
})) : L("", !0)
|
|
231
|
+
])
|
|
232
|
+
]),
|
|
233
|
+
_: 3
|
|
234
|
+
})
|
|
235
|
+
]),
|
|
236
|
+
_: 3
|
|
237
|
+
}, 16, ["model"]);
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
function g(h, K = {}) {
|
|
242
|
+
g.installed || (g.installed = !0, h.component("common-el-form", R));
|
|
243
|
+
}
|
|
244
|
+
R.install = g;
|
|
245
|
+
export {
|
|
246
|
+
R as default
|
|
247
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("vue")):typeof define=="function"&&define.amd?define(["vue"],c):(e=typeof globalThis<"u"?globalThis:e||self,e.Form=c(e.Vue))})(this,function(e){"use strict";const c=e.defineComponent({__name:"Index",props:{fieldList:null,model:null,options:null},emits:["submit","reset","cancel"],setup(k,{expose:m,emit:B}){const f=k,t=e.ref({}),u=e.ref(),b=e.computed(()=>Object.assign({labelPosition:"right",disabled:!1,submitButtonText:"提交",resetButtonText:"重置",cancelButtonText:"取消"},f==null?void 0:f.options));m({formRef:u}),f.fieldList.map(n=>{const a=n.type==="checkbox"?[]:"";f.model?t.value=f.model:t.value[n.field]=n.value||a});const h=n=>{n&&n.validate(a=>{if(a)B("submit",t.value);else return!1})},V=n=>{n&&h(u.value)},C=n=>{n&&n.resetFields()};return(n,a)=>{const w=e.resolveComponent("el-radio"),g=e.resolveComponent("el-radio-group"),i=e.resolveComponent("el-form-item"),N=e.resolveComponent("el-checkbox"),T=e.resolveComponent("el-checkbox-group"),U=e.resolveComponent("el-option"),K=e.resolveComponent("el-select"),S=e.resolveComponent("el-date-picker"),D=e.resolveComponent("el-input"),_=e.resolveComponent("el-button"),F=e.resolveComponent("el-form");return e.openBlock(),e.createBlock(F,e.mergeProps({onSubmit:a[3]||(a[3]=e.withModifiers(()=>{},["prevent"])),model:t.value},e.unref(b),{ref_key:"formRef",ref:u}),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(k.fieldList,(l,L)=>(e.openBlock(),e.createBlock(i,{key:L},{default:e.withCtx(()=>[l.type==="radio"?(e.openBlock(),e.createBlock(i,{key:0,label:l.label,rules:l.rules,prop:[l.field]},{default:e.withCtx(()=>[e.createVNode(g,{modelValue:t.value[l.field],"onUpdate:modelValue":o=>t.value[l.field]=o,disabled:l.disabled},{default:e.withCtx(()=>{var o;return[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList((o=l.options)==null?void 0:o.data,r=>{var d,s;return e.openBlock(),e.createBlock(w,{label:r[((d=l.options)==null?void 0:d.valueKey)||"value"],size:"large",key:r[((s=l.options)==null?void 0:s.valueKey)||"value"]},{default:e.withCtx(()=>{var p;return[e.createTextVNode(e.toDisplayString(r[((p=l.options)==null?void 0:p.labelkey)||"label"]),1)]}),_:2},1032,["label"])}),128))]}),_:2},1032,["modelValue","onUpdate:modelValue","disabled"])]),_:2},1032,["label","rules","prop"])):l.type==="checkbox"?(e.openBlock(),e.createBlock(i,{key:1,label:l.label,rules:l.rules,prop:[l.field]},{default:e.withCtx(()=>[e.createVNode(T,{modelValue:t.value[l.field],"onUpdate:modelValue":o=>t.value[l.field]=o,disabled:l.disabled},{default:e.withCtx(()=>{var o;return[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList((o=l.options)==null?void 0:o.data,r=>{var d,s;return e.openBlock(),e.createBlock(N,{key:r[((d=l.options)==null?void 0:d.valueKey)||"value"],label:r[((s=l.options)==null?void 0:s.valueKey)||"value"]},{default:e.withCtx(()=>{var p;return[e.createTextVNode(e.toDisplayString(r[((p=l.options)==null?void 0:p.labelkey)||"label"]),1)]}),_:2},1032,["label"])}),128))]}),_:2},1032,["modelValue","onUpdate:modelValue","disabled"])]),_:2},1032,["label","rules","prop"])):l.type==="select"?(e.openBlock(),e.createBlock(i,{key:2,label:l.label,rules:l.rules,prop:[l.field]},{default:e.withCtx(()=>{var o;return[e.createVNode(K,{modelValue:t.value[l.field],"onUpdate:modelValue":r=>t.value[l.field]=r,placeholder:((o=l.options)==null?void 0:o.placeholder)||"请选择",clearable:l.clearable},{default:e.withCtx(()=>{var r;return[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList((r=l.options)==null?void 0:r.data,d=>{var s,p,x;return e.openBlock(),e.createBlock(U,{key:d[((s=l.options)==null?void 0:s.valueKey)||"value"],label:d[((p=l.options)==null?void 0:p.labelkey)||"label"],value:d[((x=l.options)==null?void 0:x.valueKey)||"value"]},null,8,["label","value"])}),128))]}),_:2},1032,["modelValue","onUpdate:modelValue","placeholder","clearable"])]}),_:2},1032,["label","rules","prop"])):l.type==="datetime"?(e.openBlock(),e.createBlock(i,{key:3,label:l.label,rules:l.rules,prop:[l.field]},{default:e.withCtx(()=>[e.createVNode(S,{modelValue:t.value[l.field],"onUpdate:modelValue":o=>t.value[l.field]=o,readonly:l.readonly,type:"datetime",placeholder:l.placeholder||l.label,"default-time":n.defaultTime,"value-format":l.format||"YYYY-MM-DD HH:mm:ss"},null,8,["modelValue","onUpdate:modelValue","readonly","placeholder","default-time","value-format"])]),_:2},1032,["label","rules","prop"])):(e.openBlock(),e.createBlock(i,{key:4,label:l.label,rules:l.rules,prop:[l.field]},{default:e.withCtx(()=>[e.createVNode(D,{modelValue:t.value[l.field],"onUpdate:modelValue":o=>t.value[l.field]=o,readonly:l.readonly,type:l.type??"text",placeholder:l.placeholder||l.label,disabled:l.disabled,showPassword:l.showPassword,clearable:l.clearable,onKeyup:e.withKeys(o=>V(l.enterable),["enter"])},null,8,["modelValue","onUpdate:modelValue","readonly","type","placeholder","disabled","showPassword","clearable","onKeyup"])]),_:2},1032,["label","rules","prop"]))]),_:2},1024))),128)),e.createVNode(i,null,{default:e.withCtx(()=>[e.renderSlot(n.$slots,"buttons",{model:t.value,formRef:u.value},()=>[e.createVNode(_,{type:"primary",onClick:a[0]||(a[0]=l=>h(u.value))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(b).submitButtonText),1)]),_:1}),e.unref(b).showResetButton?(e.openBlock(),e.createBlock(_,{key:0,type:"info",onClick:a[1]||(a[1]=l=>C(u.value))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(b).resetButtonText),1)]),_:1})):e.createCommentVNode("",!0),e.unref(b).showCancelButton?(e.openBlock(),e.createBlock(_,{key:1,onClick:a[2]||(a[2]=l=>B("cancel"))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(b).cancelButtonText),1)]),_:1})):e.createCommentVNode("",!0)])]),_:3})]),_:3},16,["model"])}}});function y(k,m={}){y.installed||(y.installed=!0,k.component("common-el-form",c))}return c.install=y,c});
|
package/package.json
ADDED