@archbiz/element-ui 0.0.0-stage → 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/dist/element-ui.cjs +12 -0
- package/dist/element-ui.js +5522 -0
- package/dist/style.css +1 -0
- package/package.json +49 -3
- package/src/components/ab-checkbox.vue +51 -0
- package/src/components/ab-color-picker.vue +39 -0
- package/src/components/ab-detail/ab-detail.vue +285 -0
- package/src/components/ab-detail/index.js +1 -0
- package/src/components/ab-drawer/ab-drawer.vue +50 -0
- package/src/components/ab-drawer/index.js +3 -0
- package/src/components/ab-icon/ab-icon.vue +90 -0
- package/src/components/ab-icon/index.js +1 -0
- package/src/components/ab-input-number.vue +49 -0
- package/src/components/ab-input-range.vue +90 -0
- package/src/components/ab-radio.vue +51 -0
- package/src/components/ab-router-link.vue +46 -0
- package/src/components/ab-search/ab-search.vue +168 -0
- package/src/components/ab-search/index.js +4 -0
- package/src/components/ab-select.vue +107 -0
- package/src/components/ab-table/ab-table-column.vue +131 -0
- package/src/components/ab-table/ab-table-columns.vue +62 -0
- package/src/components/ab-table/ab-table-operate.vue +160 -0
- package/src/components/ab-table/ab-table.vue +316 -0
- package/src/components/ab-table/columns.js +90 -0
- package/src/components/ab-table/footer.js +77 -0
- package/src/components/ab-table/formatter.js +2 -0
- package/src/components/ab-table/index.js +8 -0
- package/src/components/ab-table/utils.js +36 -0
- package/src/components/ab-time-period.vue +116 -0
- package/src/components/ab-time-picker.vue +38 -0
- package/src/components/ab-toolbar/ab-toolbar.vue +99 -0
- package/src/components/ab-toolbar/index.js +1 -0
- package/src/components/ab-tree-select.vue +456 -0
- package/src/components/ab-upload-file.vue +277 -0
- package/src/components/index.js +27 -0
- package/src/core/ab-form.js +25 -0
- package/src/core/alias.js +36 -0
- package/src/core/config.js +65 -0
- package/src/core/form-render.js +260 -0
- package/src/core/options.js +25 -0
- package/src/hooks/use-cache.js +75 -0
- package/src/index.js +39 -0
- package/src/makers/datePicker.js +8 -0
- package/src/makers/frame.js +23 -0
- package/src/makers/index.js +23 -0
- package/src/makers/input.js +12 -0
- package/src/makers/select.js +8 -0
- package/src/makers/slider.js +7 -0
- package/src/makers/timePicker.js +8 -0
- package/src/makers/tree.js +10 -0
- package/src/makers/upload.js +20 -0
- package/src/parsers/checkbox.js +5 -0
- package/src/parsers/colorPicker.js +29 -0
- package/src/parsers/datePicker.js +24 -0
- package/src/parsers/frame.js +17 -0
- package/src/parsers/hidden.js +11 -0
- package/src/parsers/index.js +36 -0
- package/src/parsers/input.js +15 -0
- package/src/parsers/number.js +29 -0
- package/src/parsers/radio.js +5 -0
- package/src/parsers/select.js +15 -0
- package/src/parsers/slider.js +21 -0
- package/src/parsers/switch.js +11 -0
- package/src/parsers/text.js +25 -0
- package/src/parsers/timePicker.js +12 -0
- package/src/parsers/tree.js +37 -0
- package/src/parsers/upload.js +35 -0
- package/src/plugins/ab-detail.js +7 -0
- package/src/plugins/ab-drawer.js +7 -0
- package/src/plugins/ab-form.js +14 -0
- package/src/plugins/ab-search.js +7 -0
- package/src/plugins/ab-table.js +15 -0
- package/src/plugins/ab-toolbar.js +7 -0
- package/src/rule/defaults.js +187 -0
- package/src/rule/formatter.js +218 -0
- package/src/style/index.css +356 -0
- package/src/utils/formatter.js +188 -0
- package/src/utils/router-link.js +59 -0
- package/README.md +0 -3
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ab-upload-file">
|
|
3
|
+
<el-upload
|
|
4
|
+
v-if="!currentDisabled"
|
|
5
|
+
action=""
|
|
6
|
+
:show-file-list="false"
|
|
7
|
+
:drag="drag"
|
|
8
|
+
:multiple="currentLimit > 1"
|
|
9
|
+
:accept="accept"
|
|
10
|
+
:before-upload="beforeUpload"
|
|
11
|
+
:http-request="uploadRequest"
|
|
12
|
+
>
|
|
13
|
+
<el-button type="primary" size="small">选择文件</el-button>
|
|
14
|
+
<div v-if="isShowTip" slot="tip" class="ab-upload-file__tip">
|
|
15
|
+
支持 {{ fileTypes.join("/") }},单个不超过 {{ fileSize }} MB
|
|
16
|
+
</div>
|
|
17
|
+
</el-upload>
|
|
18
|
+
|
|
19
|
+
<ul class="ab-upload-file__list">
|
|
20
|
+
<li v-for="file in files" :key="file.uid" class="ab-upload-file__item">
|
|
21
|
+
<span class="ab-upload-file__name">{{ file.name }}</span>
|
|
22
|
+
<span v-if="file.status === 'uploading'" class="ab-upload-file__tip">上传中...</span>
|
|
23
|
+
<span v-if="file.error" class="ab-upload-file__error">{{ file.error }}</span>
|
|
24
|
+
<el-button v-if="file.url && preEnabled" type="text" @click="preview(file)">预览</el-button>
|
|
25
|
+
<el-link v-if="file.url && dowEnabled" :href="file.url" target="_blank" download>下载</el-link>
|
|
26
|
+
<el-button
|
|
27
|
+
v-if="!currentDisabled && delEnabled && file.status !== 'uploading'"
|
|
28
|
+
type="text"
|
|
29
|
+
@click="removeFile(file)"
|
|
30
|
+
>
|
|
31
|
+
删除
|
|
32
|
+
</el-button>
|
|
33
|
+
</li>
|
|
34
|
+
</ul>
|
|
35
|
+
</div>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script>
|
|
39
|
+
const IMAGE_TYPES = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"];
|
|
40
|
+
const DEFAULT_TYPES = ["doc", "xls", "txt", "pdf"];
|
|
41
|
+
|
|
42
|
+
function fileNameFromUrl(url) {
|
|
43
|
+
const name = String(url).split(/[?#]/, 1)[0].split("/").pop() || url;
|
|
44
|
+
try {
|
|
45
|
+
return decodeURIComponent(name);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error instanceof URIError) return name;
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getBusinessId(value) {
|
|
53
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
54
|
+
if (typeof value === "string" && value.trim() && value !== "new") return value;
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default {
|
|
59
|
+
name: "AbUploadFile",
|
|
60
|
+
props: {
|
|
61
|
+
value: { type: Array, default: () => [] },
|
|
62
|
+
apis: { type: Object, default: undefined },
|
|
63
|
+
abFormInject: { type: Object, default: undefined },
|
|
64
|
+
idFieldTable: { type: String, default: undefined },
|
|
65
|
+
businessCode: { type: String, default: undefined },
|
|
66
|
+
uploadType: { type: String, default: undefined },
|
|
67
|
+
maxLength: { type: [Number, String], default: undefined },
|
|
68
|
+
fileType: { type: Array, default: undefined },
|
|
69
|
+
fileSize: { type: Number, default: 5 },
|
|
70
|
+
limit: { type: Number, default: undefined },
|
|
71
|
+
drag: Boolean,
|
|
72
|
+
isShowTip: { type: Boolean, default: true },
|
|
73
|
+
readonly: Boolean,
|
|
74
|
+
disabled: Boolean,
|
|
75
|
+
delEnabled: { type: Boolean, default: true },
|
|
76
|
+
preEnabled: { type: Boolean, default: true },
|
|
77
|
+
dowEnabled: { type: Boolean, default: true },
|
|
78
|
+
coverEnabled: Boolean,
|
|
79
|
+
autoCover: Boolean,
|
|
80
|
+
},
|
|
81
|
+
data() {
|
|
82
|
+
return {
|
|
83
|
+
uid: 0,
|
|
84
|
+
files: [],
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
computed: {
|
|
88
|
+
currentDisabled() {
|
|
89
|
+
return this.disabled || this.readonly || Boolean(this.abFormInject && this.abFormInject.readonly === true);
|
|
90
|
+
},
|
|
91
|
+
currentLimit() {
|
|
92
|
+
if (this.limit != null) return Number(this.limit);
|
|
93
|
+
if (this.maxLength != null) return Number(this.maxLength);
|
|
94
|
+
return 5;
|
|
95
|
+
},
|
|
96
|
+
fileTypes() {
|
|
97
|
+
if (Array.isArray(this.fileType) && this.fileType.length) return this.fileType;
|
|
98
|
+
return this.uploadType === "image" ? IMAGE_TYPES : DEFAULT_TYPES;
|
|
99
|
+
},
|
|
100
|
+
accept() {
|
|
101
|
+
return this.fileTypes.map((type) => `.${String(type).replace(/^\./, "")}`).join(",");
|
|
102
|
+
},
|
|
103
|
+
apisClient() {
|
|
104
|
+
return this.apis || this.$abUploadApis;
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
watch: {
|
|
108
|
+
value: {
|
|
109
|
+
handler(next) {
|
|
110
|
+
this.syncFromValue(next);
|
|
111
|
+
},
|
|
112
|
+
immediate: true,
|
|
113
|
+
deep: true,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
methods: {
|
|
117
|
+
syncFromValue(value) {
|
|
118
|
+
const urls = Array.isArray(value) ? value : [];
|
|
119
|
+
const available = [...this.files];
|
|
120
|
+
const next = urls.map((url) => {
|
|
121
|
+
const index = available.findIndex((file) => file.url === url);
|
|
122
|
+
if (index > -1) return available.splice(index, 1)[0];
|
|
123
|
+
return {
|
|
124
|
+
uid: ++this.uid,
|
|
125
|
+
name: fileNameFromUrl(url),
|
|
126
|
+
url,
|
|
127
|
+
id: undefined,
|
|
128
|
+
fileId: undefined,
|
|
129
|
+
size: undefined,
|
|
130
|
+
error: undefined,
|
|
131
|
+
status: "linked",
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
this.files = [
|
|
135
|
+
...next,
|
|
136
|
+
...this.files.filter((file) => file.status === "uploading" || file.status === "failed"),
|
|
137
|
+
];
|
|
138
|
+
},
|
|
139
|
+
publish() {
|
|
140
|
+
this.$emit(
|
|
141
|
+
"input",
|
|
142
|
+
this.files.filter((file) => file.url).map((file) => file.url)
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
beforeUpload(file) {
|
|
146
|
+
const uploading = this.files.filter((item) => item.status === "uploading" || item.status === "linked").length;
|
|
147
|
+
if (uploading >= this.currentLimit) {
|
|
148
|
+
this.$message.error(`最多上传 ${this.currentLimit} 个文件`);
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const name = file.name || "";
|
|
152
|
+
const extension = name.includes(".") ? name.slice(name.lastIndexOf(".") + 1).toLowerCase() : "";
|
|
153
|
+
if (
|
|
154
|
+
this.fileTypes.length &&
|
|
155
|
+
!this.fileTypes.some((type) => String(type).toLowerCase().replace(/^\./, "") === extension)
|
|
156
|
+
) {
|
|
157
|
+
this.$message.error(`仅支持 ${this.fileTypes.join("/")} 格式`);
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
if (file.size > this.fileSize * 1024 * 1024) {
|
|
161
|
+
this.$message.error(`文件大小不能超过 ${this.fileSize} MB`);
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
},
|
|
166
|
+
uploadRequest(options) {
|
|
167
|
+
const client = this.apisClient;
|
|
168
|
+
if (!client || typeof client.upload !== "function") {
|
|
169
|
+
const error = new Error("未配置上传接口");
|
|
170
|
+
this.$message.error(error.message);
|
|
171
|
+
this.$emit("error", error);
|
|
172
|
+
return Promise.reject(error);
|
|
173
|
+
}
|
|
174
|
+
const file = {
|
|
175
|
+
uid: ++this.uid,
|
|
176
|
+
name: options.file && options.file.name,
|
|
177
|
+
url: undefined,
|
|
178
|
+
id: undefined,
|
|
179
|
+
fileId: undefined,
|
|
180
|
+
size: undefined,
|
|
181
|
+
error: undefined,
|
|
182
|
+
status: "uploading",
|
|
183
|
+
};
|
|
184
|
+
this.files.push(file);
|
|
185
|
+
return Promise.resolve()
|
|
186
|
+
.then(() => client.upload({ file: options.file }))
|
|
187
|
+
.then((response) => {
|
|
188
|
+
const data = response && response.data ? response.data : response;
|
|
189
|
+
if (!data || data.id == null || typeof data.url !== "string" || !data.url) {
|
|
190
|
+
throw new TypeError("上传接口需返回 id、name、url");
|
|
191
|
+
}
|
|
192
|
+
this.$set(file, "id", data.id);
|
|
193
|
+
this.$set(file, "fileId", data.id);
|
|
194
|
+
this.$set(file, "url", data.url);
|
|
195
|
+
this.$set(file, "name", data.name || (options.file && options.file.name) || data.url);
|
|
196
|
+
this.$set(file, "size", data.size);
|
|
197
|
+
this.$set(file, "status", "linked");
|
|
198
|
+
this.publish();
|
|
199
|
+
return response;
|
|
200
|
+
})
|
|
201
|
+
.catch((error) => {
|
|
202
|
+
this.$set(file, "status", "failed");
|
|
203
|
+
this.$set(file, "error", this.errorMessage(error));
|
|
204
|
+
this.$emit("error", error);
|
|
205
|
+
throw error;
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
handleUploadError(error) {
|
|
209
|
+
this.$emit("error", error);
|
|
210
|
+
},
|
|
211
|
+
removeFile(file) { const client = this.apisClient;
|
|
212
|
+
const businessId = this.businessId();
|
|
213
|
+
const done = () => {
|
|
214
|
+
this.files = this.files.filter((item) => item.uid !== file.uid);
|
|
215
|
+
this.publish();
|
|
216
|
+
};
|
|
217
|
+
if (client && typeof client.remove === "function" && file.fileId != null && businessId !== undefined) {
|
|
218
|
+
Promise.resolve(
|
|
219
|
+
client.remove({
|
|
220
|
+
...this.businessParams(businessId),
|
|
221
|
+
fileId: file.fileId,
|
|
222
|
+
})
|
|
223
|
+
)
|
|
224
|
+
.then(done)
|
|
225
|
+
.catch((error) => {
|
|
226
|
+
this.$message.error(this.errorMessage(error));
|
|
227
|
+
this.$emit("error", error);
|
|
228
|
+
});
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
done();
|
|
232
|
+
},
|
|
233
|
+
preview(file) {
|
|
234
|
+
const name = file.name || "";
|
|
235
|
+
const extension = name.includes(".") ? name.slice(name.lastIndexOf(".") + 1).toLowerCase() : "";
|
|
236
|
+
this.$emit("preview", { url: file.url, name, extension, fileId: file.fileId });
|
|
237
|
+
},
|
|
238
|
+
businessId() {
|
|
239
|
+
const inject = this.abFormInject;
|
|
240
|
+
const value = inject && inject.formValue && inject.idField ? inject.formValue[inject.idField] : undefined;
|
|
241
|
+
return getBusinessId(value);
|
|
242
|
+
},
|
|
243
|
+
businessParams(id) {
|
|
244
|
+
return {
|
|
245
|
+
businessType: this.idFieldTable || (this.abFormInject && this.abFormInject.idFieldTable),
|
|
246
|
+
businessCode: this.businessCode,
|
|
247
|
+
businessId: id,
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
errorMessage(error) {
|
|
251
|
+
return error instanceof Error ? error.message : String(error);
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
</script>
|
|
256
|
+
|
|
257
|
+
<style scoped>
|
|
258
|
+
.ab-upload-file__list {
|
|
259
|
+
margin: 0;
|
|
260
|
+
padding: 0;
|
|
261
|
+
list-style: none;
|
|
262
|
+
}
|
|
263
|
+
.ab-upload-file__item {
|
|
264
|
+
display: flex;
|
|
265
|
+
align-items: center;
|
|
266
|
+
gap: 8px;
|
|
267
|
+
flex-wrap: wrap;
|
|
268
|
+
}
|
|
269
|
+
.ab-upload-file__tip {
|
|
270
|
+
font-size: 12px;
|
|
271
|
+
color: #909399;
|
|
272
|
+
}
|
|
273
|
+
.ab-upload-file__error {
|
|
274
|
+
font-size: 12px;
|
|
275
|
+
color: #f56c6c;
|
|
276
|
+
}
|
|
277
|
+
</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import abSelect from "./ab-select.vue";
|
|
2
|
+
import abRadio from "./ab-radio.vue";
|
|
3
|
+
import abCheckbox from "./ab-checkbox.vue";
|
|
4
|
+
import abIcon from "./ab-icon/ab-icon.vue";
|
|
5
|
+
import abTreeSelect from "./ab-tree-select.vue";
|
|
6
|
+
import abInputNumber from "./ab-input-number.vue";
|
|
7
|
+
import abInputRange from "./ab-input-range.vue";
|
|
8
|
+
import abTimePeriod from "./ab-time-period.vue";
|
|
9
|
+
import abTimePicker from "./ab-time-picker.vue";
|
|
10
|
+
import abColorPicker from "./ab-color-picker.vue";
|
|
11
|
+
import abUploadFile from "./ab-upload-file.vue";
|
|
12
|
+
import abRouterLink from "./ab-router-link.vue";
|
|
13
|
+
|
|
14
|
+
export default [
|
|
15
|
+
abSelect,
|
|
16
|
+
abRadio,
|
|
17
|
+
abCheckbox,
|
|
18
|
+
abIcon,
|
|
19
|
+
abTreeSelect,
|
|
20
|
+
abInputNumber,
|
|
21
|
+
abInputRange,
|
|
22
|
+
abTimePeriod,
|
|
23
|
+
abTimePicker,
|
|
24
|
+
abColorPicker,
|
|
25
|
+
abUploadFile,
|
|
26
|
+
abRouterLink,
|
|
27
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import createAbForm, { VNode } from "@archbiz/core-v2";
|
|
2
|
+
import components from "../components/index.js";
|
|
3
|
+
import parsers from "../parsers/index.js";
|
|
4
|
+
import getConfig from "./config.js";
|
|
5
|
+
import alias from "./alias.js";
|
|
6
|
+
import formRender from "./form-render.js";
|
|
7
|
+
import makers from "../makers/index.js";
|
|
8
|
+
import { applyRuleDefaults } from "../rule/defaults.js";
|
|
9
|
+
|
|
10
|
+
export default function abForm() {
|
|
11
|
+
VNode.use(alias);
|
|
12
|
+
|
|
13
|
+
const { AbForm } = createAbForm({
|
|
14
|
+
ui: process.env.UI,
|
|
15
|
+
version: `${process.env.VERSION}`,
|
|
16
|
+
formRender,
|
|
17
|
+
components,
|
|
18
|
+
parsers,
|
|
19
|
+
makers,
|
|
20
|
+
getConfig,
|
|
21
|
+
mergeRule: (rule) => applyRuleDefaults(rule),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return AbForm;
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const PRE = 'el';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
input: `${PRE}-input`,
|
|
5
|
+
password: `${PRE}-input`,
|
|
6
|
+
textarea: `${PRE}-input`,
|
|
7
|
+
text: 'span',
|
|
8
|
+
hidden: 'span',
|
|
9
|
+
divider: `${PRE}-divider`,
|
|
10
|
+
number: `${PRE}-input-number`,
|
|
11
|
+
inputNumber: `${PRE}-input-number`,
|
|
12
|
+
inputCurrency: 'ab-input-number',
|
|
13
|
+
inputPercent: 'ab-input-number',
|
|
14
|
+
select: 'ab-select',
|
|
15
|
+
radio: 'ab-radio',
|
|
16
|
+
checkbox: 'ab-checkbox',
|
|
17
|
+
switch: `${PRE}-switch`,
|
|
18
|
+
datePicker: `${PRE}-date-picker`,
|
|
19
|
+
timePicker: 'ab-time-picker',
|
|
20
|
+
slider: `${PRE}-slider`,
|
|
21
|
+
rate: `${PRE}-rate`,
|
|
22
|
+
colorPicker: 'ab-color-picker',
|
|
23
|
+
cascader: `${PRE}-cascader`,
|
|
24
|
+
treeSelect: 'ab-tree-select',
|
|
25
|
+
inputRange: 'ab-input-range',
|
|
26
|
+
timePeriod: 'ab-time-period',
|
|
27
|
+
uploadFile: 'ab-upload-file',
|
|
28
|
+
upload: 'ab-upload-file',
|
|
29
|
+
form: `${PRE}-form`,
|
|
30
|
+
formItem: `${PRE}-form-item`,
|
|
31
|
+
ElButton: `${PRE}-button`,
|
|
32
|
+
button: `${PRE}-button`,
|
|
33
|
+
icon: 'ab-icon',
|
|
34
|
+
row: `${PRE}-row`,
|
|
35
|
+
col: `${PRE}-col`
|
|
36
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export default function getConfig() {
|
|
2
|
+
return {
|
|
3
|
+
form: {
|
|
4
|
+
inline: true,
|
|
5
|
+
labelPosition: "right",
|
|
6
|
+
labelSuffix: undefined,
|
|
7
|
+
hideRequiredAsterisk: false,
|
|
8
|
+
labelWidth: "120px",
|
|
9
|
+
fieldWidth: "238px",
|
|
10
|
+
showMessage: true,
|
|
11
|
+
inlineMessage: false,
|
|
12
|
+
statusIcon: false,
|
|
13
|
+
validateOnRuleChange: true,
|
|
14
|
+
disabled: false,
|
|
15
|
+
size: undefined,
|
|
16
|
+
},
|
|
17
|
+
row: {
|
|
18
|
+
gutter: 0,
|
|
19
|
+
type: undefined,
|
|
20
|
+
align: undefined,
|
|
21
|
+
justify: undefined,
|
|
22
|
+
tag: "div",
|
|
23
|
+
},
|
|
24
|
+
info: {
|
|
25
|
+
type: "popover",
|
|
26
|
+
trigger: "hover",
|
|
27
|
+
placement: "top-start",
|
|
28
|
+
icon: "el-icon-warning",
|
|
29
|
+
},
|
|
30
|
+
submitBtn: {
|
|
31
|
+
type: "primary",
|
|
32
|
+
size: "medium",
|
|
33
|
+
plain: false,
|
|
34
|
+
round: false,
|
|
35
|
+
circle: false,
|
|
36
|
+
loading: false,
|
|
37
|
+
disabled: false,
|
|
38
|
+
icon: "el-icon-upload",
|
|
39
|
+
width: "100%",
|
|
40
|
+
autofocus: false,
|
|
41
|
+
nativeType: "button",
|
|
42
|
+
innerText: "提交",
|
|
43
|
+
show: false,
|
|
44
|
+
col: undefined,
|
|
45
|
+
click: undefined,
|
|
46
|
+
},
|
|
47
|
+
resetBtn: {
|
|
48
|
+
type: "default",
|
|
49
|
+
size: "medium",
|
|
50
|
+
plain: false,
|
|
51
|
+
round: false,
|
|
52
|
+
circle: false,
|
|
53
|
+
loading: false,
|
|
54
|
+
disabled: false,
|
|
55
|
+
icon: "el-icon-refresh",
|
|
56
|
+
width: "100%",
|
|
57
|
+
autofocus: false,
|
|
58
|
+
nativeType: "button",
|
|
59
|
+
innerText: "重置",
|
|
60
|
+
show: false,
|
|
61
|
+
col: undefined,
|
|
62
|
+
click: undefined,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { isFunction, preventDefault, toString, isString, isType } from "@archbiz/utils";
|
|
2
|
+
import { BaseForm } from "@archbiz/core-v2";
|
|
3
|
+
import style from "../style/index.css";
|
|
4
|
+
import { resolveRuleFormatter } from "../rule/formatter.js";
|
|
5
|
+
import { isRouterLinkConfig } from "../utils/router-link.js";
|
|
6
|
+
import AbRouterLink from "../components/ab-router-link.vue";
|
|
7
|
+
|
|
8
|
+
const styleClass = style || {};
|
|
9
|
+
const upperCaseReg = /[A-Z]/;
|
|
10
|
+
|
|
11
|
+
const injectTypes = new Set(["select", "treeselect", "radio", "checkbox", "inputrange", "timeperiod", "tree", "upload", "uploadfile", "frame"]);
|
|
12
|
+
|
|
13
|
+
const readonlyTextTypes = new Set([
|
|
14
|
+
"input",
|
|
15
|
+
"password",
|
|
16
|
+
"textarea",
|
|
17
|
+
"number",
|
|
18
|
+
"inputnumber",
|
|
19
|
+
"inputcurrency",
|
|
20
|
+
"inputpercent",
|
|
21
|
+
"select",
|
|
22
|
+
"radio",
|
|
23
|
+
"checkbox",
|
|
24
|
+
"switch",
|
|
25
|
+
"datepicker",
|
|
26
|
+
"timepicker",
|
|
27
|
+
"slider",
|
|
28
|
+
"rate",
|
|
29
|
+
"cascader",
|
|
30
|
+
"treeselect",
|
|
31
|
+
"text",
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export function isAttr(name, value) {
|
|
35
|
+
return !upperCaseReg.test(name) && (isString(value) || isType(value, "Number"));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isTooltip(info) {
|
|
39
|
+
return info.type === "tooltip";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default class Form extends BaseForm {
|
|
43
|
+
get injectTypes() {
|
|
44
|
+
return injectTypes;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
readonlyRender(parser) {
|
|
48
|
+
if (!this.$handle.vm || !this.$handle.vm.readonly) return;
|
|
49
|
+
if (!parser.isDef || parser.rule.component) return;
|
|
50
|
+
if (!readonlyTextTypes.has(parser.type)) return;
|
|
51
|
+
|
|
52
|
+
const rule = parser.rule;
|
|
53
|
+
const value = this.$handle.getFormData(parser);
|
|
54
|
+
const row = this.$handle.formData || {};
|
|
55
|
+
const formatter = resolveRuleFormatter({ ...rule, props: rule.props || {} }).formatter;
|
|
56
|
+
const displayValue = typeof formatter === "function" ? formatter({ cellValue: value, column: rule, row }) : value;
|
|
57
|
+
const content = String(displayValue ?? "");
|
|
58
|
+
const link = rule.link;
|
|
59
|
+
|
|
60
|
+
if (isRouterLinkConfig(link)) {
|
|
61
|
+
return this.vNode.make(AbRouterLink, { props: { link, value, row } }, [content]);
|
|
62
|
+
}
|
|
63
|
+
return this.vNode.make("span", { domProps: { textContent: content } });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
inputVData(parser) {
|
|
67
|
+
const props = parser.rule.props || {};
|
|
68
|
+
parser.vData.attrs({ ...props });
|
|
69
|
+
if (!props.size && this.options.form.size) parser.vData.props("size", this.options.form.size);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
validate(call) {
|
|
73
|
+
this.getFormRef().validate((valid) => {
|
|
74
|
+
call && call(valid);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
validateField(field, call) {
|
|
79
|
+
this.getFormRef().validateField(field, call);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
resetField(parser) {
|
|
83
|
+
this.vm.$refs[parser.formItemRefName].resetField();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
clearValidateState(parser) {
|
|
87
|
+
const fItem = this.vm.$refs[parser.formItemRefName];
|
|
88
|
+
if (fItem) {
|
|
89
|
+
fItem.validateMessage = "";
|
|
90
|
+
fItem.validateState = "";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
beforeRender() {
|
|
95
|
+
this.propsData = this.vData
|
|
96
|
+
.props(this.options.form)
|
|
97
|
+
.props({
|
|
98
|
+
model: this.$handle.formData,
|
|
99
|
+
rules: this.$handle.validate,
|
|
100
|
+
key: "form" + this.unique,
|
|
101
|
+
})
|
|
102
|
+
.ref(this.refName)
|
|
103
|
+
.nativeOn({ submit: preventDefault })
|
|
104
|
+
.class(this.options.form.className)
|
|
105
|
+
.class("form-create", true)
|
|
106
|
+
.class("ab-form", true)
|
|
107
|
+
.key(this.unique)
|
|
108
|
+
.get();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
render(vn) {
|
|
112
|
+
if (vn.length > 0) vn.push(this.makeFormBtn());
|
|
113
|
+
|
|
114
|
+
return this.vNode.form(this.propsData, [this.options.row === false ? vn : this.makeRow(vn)]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
makeRow(vn) {
|
|
118
|
+
const _class = {},
|
|
119
|
+
row = this.options.row || {};
|
|
120
|
+
|
|
121
|
+
if (row.class) _class[row.class] = true;
|
|
122
|
+
return this.vNode.row({ props: row || {}, key: "fr" + this.unique, class: _class }, vn);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
container(child, parser) {
|
|
126
|
+
return this.makeFormItem(parser, child);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
makeFormItem(parser, child) {
|
|
130
|
+
let fItemUnique = `fItem${parser.key}${this.unique}`,
|
|
131
|
+
{ rule, field, formItemRefName } = parser,
|
|
132
|
+
col = this.getGetCol(parser),
|
|
133
|
+
labelWidth = !col.labelWidth && !rule.title ? 0 : col.labelWidth,
|
|
134
|
+
fieldWidth = parser.isDef ? this.options.form && this.options.form.fieldWidth : "",
|
|
135
|
+
{ inline, col: _col } = this.propsData.props,
|
|
136
|
+
propsData = this.vData
|
|
137
|
+
.props({
|
|
138
|
+
prop: field,
|
|
139
|
+
// label: rule.title,
|
|
140
|
+
// labelFor: unique,
|
|
141
|
+
rules: rule.validate,
|
|
142
|
+
labelWidth: toString(labelWidth),
|
|
143
|
+
required: rule.props.required,
|
|
144
|
+
})
|
|
145
|
+
.key(fItemUnique)
|
|
146
|
+
.ref(formItemRefName)
|
|
147
|
+
.class(rule.className)
|
|
148
|
+
.style(fieldWidth ? { "--ab-field-width": toString(fieldWidth) } : undefined)
|
|
149
|
+
.get(),
|
|
150
|
+
node = this.vNode.formItem(propsData, [child, this.makeFormPop(parser, fItemUnique)]);
|
|
151
|
+
return inline === true || _col === false ? node : this.makeCol(col, parser, fItemUnique, [node]);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
makeFormPop({ rule }, unique) {
|
|
155
|
+
if (rule.title) {
|
|
156
|
+
const titleProp = isString(rule.title) ? { title: rule.title } : rule.title;
|
|
157
|
+
const info = this.options.info || {},
|
|
158
|
+
svn = [titleProp.title || ""];
|
|
159
|
+
if (rule.info) {
|
|
160
|
+
svn.push(
|
|
161
|
+
this.vNode.make(
|
|
162
|
+
isTooltip(info) ? "el-tooltip" : "el-popover",
|
|
163
|
+
{
|
|
164
|
+
props: { ...info, content: rule.info },
|
|
165
|
+
key: `pop${unique}`,
|
|
166
|
+
},
|
|
167
|
+
[
|
|
168
|
+
this.vNode.icon({
|
|
169
|
+
class: [info.icon || "el-icon-warning"],
|
|
170
|
+
slot: isTooltip(info) ? "default" : "reference",
|
|
171
|
+
}),
|
|
172
|
+
]
|
|
173
|
+
)
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return this.vNode.make("span", { ...titleProp, slot: "label" }, svn);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
makeCol(col, parser, fItemUnique, VNodeFn) {
|
|
181
|
+
if (col.span === undefined) col.span = 24;
|
|
182
|
+
const cls = {
|
|
183
|
+
[styleClass.__fc_h]: !!parser.rule.hidden,
|
|
184
|
+
[styleClass.__fc_v]: !!parser.rule.visibility,
|
|
185
|
+
};
|
|
186
|
+
if (col.class) cls[col.class] = true;
|
|
187
|
+
return this.vNode.col(
|
|
188
|
+
{
|
|
189
|
+
props: col,
|
|
190
|
+
class: cls,
|
|
191
|
+
key: `${fItemUnique}col1`,
|
|
192
|
+
},
|
|
193
|
+
VNodeFn
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
makeFormBtn() {
|
|
198
|
+
let btn = [],
|
|
199
|
+
submitBtnShow = false !== this.vm.buttonProps && false !== this.vm.buttonProps.show,
|
|
200
|
+
resetBtnShow = false !== this.vm.resetProps && false !== this.vm.resetProps.show;
|
|
201
|
+
if (submitBtnShow) btn.push(this.makeSubmitBtn(resetBtnShow ? 19 : 24));
|
|
202
|
+
if (resetBtnShow) btn.push(this.makeResetBtn(4));
|
|
203
|
+
|
|
204
|
+
return this.propsData.props.inline === true
|
|
205
|
+
? btn
|
|
206
|
+
: btn.length
|
|
207
|
+
? this.vNode.col(
|
|
208
|
+
{
|
|
209
|
+
props: { span: 24 },
|
|
210
|
+
key: `${this.unique}col2`,
|
|
211
|
+
},
|
|
212
|
+
btn
|
|
213
|
+
)
|
|
214
|
+
: [];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
makeResetBtn(span) {
|
|
218
|
+
const resetBtn = this.vm.resetProps,
|
|
219
|
+
props = resetBtn.col || { span: span, push: 1 };
|
|
220
|
+
|
|
221
|
+
return this.vNode.col({ props: props, key: `${this.unique}col3` }, [
|
|
222
|
+
this.vNode.button(
|
|
223
|
+
{
|
|
224
|
+
key: `frsbtn${this.unique}`,
|
|
225
|
+
props: resetBtn,
|
|
226
|
+
on: {
|
|
227
|
+
click: () => {
|
|
228
|
+
const fApi = this.$handle.fCreateApi;
|
|
229
|
+
isFunction(resetBtn.click) ? resetBtn.click(fApi) : fApi.resetFields();
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
style: { width: resetBtn.width },
|
|
233
|
+
},
|
|
234
|
+
[resetBtn.innerText]
|
|
235
|
+
),
|
|
236
|
+
]);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
makeSubmitBtn(span) {
|
|
240
|
+
const submitBtn = this.vm.buttonProps,
|
|
241
|
+
props = submitBtn.col || { span: span };
|
|
242
|
+
|
|
243
|
+
return this.vNode.col({ props: props, key: `${this.unique}col4` }, [
|
|
244
|
+
this.vNode.button(
|
|
245
|
+
{
|
|
246
|
+
key: `fbtn${this.unique}`,
|
|
247
|
+
props: submitBtn,
|
|
248
|
+
on: {
|
|
249
|
+
click: () => {
|
|
250
|
+
const fApi = this.$handle.fCreateApi;
|
|
251
|
+
isFunction(submitBtn.click) ? submitBtn.click(fApi) : fApi.submit();
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
style: { width: submitBtn.width },
|
|
255
|
+
},
|
|
256
|
+
[submitBtn.innerText]
|
|
257
|
+
),
|
|
258
|
+
]);
|
|
259
|
+
}
|
|
260
|
+
}
|