p-pc-ui 1.2.7 → 1.2.8
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.
|
@@ -79,6 +79,13 @@ export interface UploadOss<K extends string = string> extends UploadBase<K> {
|
|
|
79
79
|
baseOssUrl: string,
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
export interface UploadTos<K extends string = string> extends UploadBase<K> {
|
|
83
|
+
type: 'uploadTos',
|
|
84
|
+
getTosToken: ({file_name}) => Promise<any>,
|
|
85
|
+
baseTosUrl: string,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
82
89
|
|
|
83
90
|
export interface Upload<K extends string = string> extends UploadBase<K> {
|
|
84
91
|
type: 'upload',
|
|
@@ -113,6 +120,7 @@ export type FormDataItem<K extends string = string> =
|
|
|
113
120
|
| Select<K>
|
|
114
121
|
| Upload<K>
|
|
115
122
|
| UploadOss<K>
|
|
123
|
+
| UploadTos<K>
|
|
116
124
|
| Textarea<K>
|
|
117
125
|
| DatePicker<K>
|
|
118
126
|
| Component<K>
|
|
@@ -65,8 +65,8 @@ const emits = defineEmits(["confirm"]);
|
|
|
65
65
|
*/
|
|
66
66
|
const editorRef = shallowRef();
|
|
67
67
|
|
|
68
|
-
onBeforeMount(async() => {
|
|
69
|
-
renderData.value =await disposeRenderData(props.renderData);
|
|
68
|
+
onBeforeMount(async () => {
|
|
69
|
+
renderData.value = await disposeRenderData(props.renderData);
|
|
70
70
|
const _formState = initFormState(renderData.value, props.initForm);
|
|
71
71
|
for (const key in _formState) {
|
|
72
72
|
formState[key] = _formState[key];
|
|
@@ -76,11 +76,11 @@ onBeforeMount(async() => {
|
|
|
76
76
|
/**
|
|
77
77
|
* 处理渲染表单
|
|
78
78
|
*/
|
|
79
|
-
const disposeRenderData = async(renderData: FormDataItem[]) => {
|
|
79
|
+
const disposeRenderData = async (renderData: FormDataItem[]) => {
|
|
80
80
|
const _renderData = _.cloneDeep(renderData).map((val) => ({
|
|
81
81
|
...val,
|
|
82
82
|
rules: [] as any,
|
|
83
|
-
})) as (FormDataItem & {rules:[]})[];
|
|
83
|
+
})) as (FormDataItem & { rules: [] })[];
|
|
84
84
|
|
|
85
85
|
for (const renderItem of _renderData) {
|
|
86
86
|
let { fieldType, fieldRules, label } = renderItem;
|
|
@@ -89,16 +89,19 @@ const disposeRenderData = async(renderData: FormDataItem[]) => {
|
|
|
89
89
|
const operateType = ["select", "treeSeect", "date", "datePicker"].includes(renderItem.type) ? "选择" : "输入";
|
|
90
90
|
for (const fieldRule of fieldRules || []) {
|
|
91
91
|
const { msg, required, min, max } = fieldRule;
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
// 图片需要额外处理
|
|
94
94
|
|
|
95
|
-
if(
|
|
96
|
-
|
|
95
|
+
if (
|
|
96
|
+
(renderItem.type == "uploadOss" || renderItem.type == "uploadTos" || renderItem.type == "upload") &&
|
|
97
|
+
renderItem.fieldType == "string"
|
|
98
|
+
) {
|
|
99
|
+
fieldType = "array";
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
if (required) {
|
|
100
103
|
rules.push({
|
|
101
|
-
type: renderItem.type == "uploadOss" ? "array" : renderItem.fieldType,
|
|
104
|
+
type: renderItem.type == "uploadOss" || renderItem.type == "uploadTos" ? "array" : renderItem.fieldType,
|
|
102
105
|
required: true,
|
|
103
106
|
message: msg || `请${operateType}${label}`,
|
|
104
107
|
trigger: "blur",
|
|
@@ -135,10 +138,10 @@ const disposeRenderData = async(renderData: FormDataItem[]) => {
|
|
|
135
138
|
renderItem.placeholder = "加载中" + point.join("");
|
|
136
139
|
}, 500);
|
|
137
140
|
|
|
138
|
-
const res = await
|
|
141
|
+
const res = await renderItem.loadDataFunc();
|
|
139
142
|
renderItem["optionList"] = res;
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
clearInterval(interval);
|
|
144
|
+
renderItem.placeholder = `请选择${renderItem.label}`;
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
// 渲染搜索框下拉框
|
|
@@ -188,7 +191,7 @@ const initFormState = (renderData: FormDataItem[], initFromData = {}) => {
|
|
|
188
191
|
break;
|
|
189
192
|
case "string":
|
|
190
193
|
// 如果是图片类型, 并且是string类型,代表用户只需要1张图片,并且已文本的形式存放
|
|
191
|
-
if (renderItem.type == "uploadOss" || renderItem.type ==
|
|
194
|
+
if (renderItem.type == "uploadOss" || renderItem.type == "uploadTos" || renderItem.type == "upload") {
|
|
192
195
|
initValue = [];
|
|
193
196
|
} else {
|
|
194
197
|
initValue = "";
|
|
@@ -214,18 +217,13 @@ const initFormState = (renderData: FormDataItem[], initFromData = {}) => {
|
|
|
214
217
|
renderItem.optionList = [];
|
|
215
218
|
}
|
|
216
219
|
|
|
217
|
-
|
|
218
|
-
if (!initValue && renderItem.optionList ) {
|
|
220
|
+
if (!initValue && renderItem.optionList) {
|
|
219
221
|
initValue = renderItem["optionList"][0]?.id;
|
|
220
222
|
}
|
|
221
223
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
initValue =undefined
|
|
224
|
+
if (renderItem.loadDataFunc) {
|
|
225
|
+
initValue = undefined;
|
|
225
226
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
227
|
} else if (renderItem.type == "uploadOss") {
|
|
230
228
|
if (!_.isArray(initValue)) {
|
|
231
229
|
initValue = [initValue];
|
|
@@ -284,9 +282,11 @@ const getFormData = async (options: { no_check?: Boolean } = {}) => {
|
|
|
284
282
|
// 上传到oss
|
|
285
283
|
else if (renderItem.type == "uploadOss") {
|
|
286
284
|
const fileData = toRaw(formData[key]);
|
|
287
|
-
const keys = fileData.map((val)=>{
|
|
285
|
+
const keys = fileData.map((val) => {
|
|
286
|
+
return val?.response?.key || val.key;
|
|
287
|
+
});
|
|
288
288
|
returnFormData[key] = renderItem?.fieldType == "string" ? keys[0] : keys;
|
|
289
|
-
}
|
|
289
|
+
}
|
|
290
290
|
// 获取file对象
|
|
291
291
|
else if (renderItem.type == "upload") {
|
|
292
292
|
const formatData = formState[key].map((val) => ({ base64: val.thumbUrl, file: val.originFileObj }));
|
|
@@ -368,6 +368,25 @@ const uploadOss = async (file, config) => {
|
|
|
368
368
|
return config.key;
|
|
369
369
|
};
|
|
370
370
|
|
|
371
|
+
/**
|
|
372
|
+
* 上传到火山云TOS
|
|
373
|
+
*/
|
|
374
|
+
const uploadTos = async (file, config) => {
|
|
375
|
+
const formData = new FormData();
|
|
376
|
+
formData.append("key", config["key"]);
|
|
377
|
+
formData.append("policy", config["policy"]);
|
|
378
|
+
formData.append("x-tos-algorithm", config["x-tos-algorithm"]);
|
|
379
|
+
formData.append("x-tos-credential", config["x-tos-credential"]);
|
|
380
|
+
formData.append("x-tos-date", config["x-tos-date"]);
|
|
381
|
+
formData.append("x-tos-signature", config["x-tos-signature"]);
|
|
382
|
+
formData.append("file", file, file.fileName || file.name);
|
|
383
|
+
await fetch(config.host, {
|
|
384
|
+
method: "POST",
|
|
385
|
+
body: formData,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
return config["key"];
|
|
389
|
+
};
|
|
371
390
|
/**
|
|
372
391
|
* 自定义上传事件
|
|
373
392
|
*/
|
|
@@ -375,9 +394,11 @@ const uploadRequest = async (options, renderItem: FormDataItem) => {
|
|
|
375
394
|
const file = options.file;
|
|
376
395
|
if (renderItem.type == "uploadOss") {
|
|
377
396
|
const config: any = await renderItem.getOssToken({ file_name: file.name });
|
|
378
|
-
|
|
379
397
|
const key = await uploadOss(file, config);
|
|
380
|
-
|
|
398
|
+
options.onSuccess({ key }, file);
|
|
399
|
+
} else if (renderItem.type == "uploadTos") {
|
|
400
|
+
const config: any = await renderItem.getTosToken({ file_name: file.name });
|
|
401
|
+
const key = await uploadTos(file, config);
|
|
381
402
|
options.onSuccess({ key }, file);
|
|
382
403
|
} else {
|
|
383
404
|
setTimeout(() => {
|
|
@@ -398,7 +419,6 @@ const editorUpload = async (renderItem, file, insertFn) => {
|
|
|
398
419
|
insertFn(renderItem.baseOssUrl + key);
|
|
399
420
|
};
|
|
400
421
|
|
|
401
|
-
|
|
402
422
|
/**
|
|
403
423
|
* 发送验证码
|
|
404
424
|
*/
|
|
@@ -571,7 +591,7 @@ defineExpose({
|
|
|
571
591
|
></a-tree-select>
|
|
572
592
|
|
|
573
593
|
<a-upload
|
|
574
|
-
v-if="renderItem.type == 'uploadOss' || renderItem.type == 'upload'"
|
|
594
|
+
v-if="renderItem.type == 'uploadOss' || renderItem.type == 'uploadTos' || renderItem.type == 'upload'"
|
|
575
595
|
:file-list="formState[renderItem.key]"
|
|
576
596
|
:multiple="true"
|
|
577
597
|
:max-count="renderItem?.maxCount || 1"
|