p-pc-ui 1.2.7 → 1.2.9

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((renderItem.type == 'uploadOss' || renderItem.type== 'upload') && renderItem.fieldType == 'string'){
96
- fieldType ='array'
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 renderItem.loadDataFunc()
141
+ const res = await renderItem.loadDataFunc();
139
142
  renderItem["optionList"] = res;
140
- clearInterval(interval);
141
- renderItem.placeholder = `请选择${renderItem.label}`;
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 == 'upload') {
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
- if(renderItem.loadDataFunc){
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];
@@ -280,13 +278,14 @@ const getFormData = async (options: { no_check?: Boolean } = {}) => {
280
278
  if (renderItem?.visibleHook && !renderItem.visibleHook(formData)) {
281
279
  continue;
282
280
  }
283
-
284
281
  // 上传到oss
285
- else if (renderItem.type == "uploadOss") {
282
+ else if (renderItem.type == "uploadOss" || renderItem.type == "uploadTos") {
286
283
  const fileData = toRaw(formData[key]);
287
- const keys = fileData.map((val)=>{return val?.response?.key || val.key});
284
+ const keys = fileData.map((val) => {
285
+ return val?.response?.key || val.key;
286
+ });
288
287
  returnFormData[key] = renderItem?.fieldType == "string" ? keys[0] : keys;
289
- }
288
+ }
290
289
  // 获取file对象
291
290
  else if (renderItem.type == "upload") {
292
291
  const formatData = formState[key].map((val) => ({ base64: val.thumbUrl, file: val.originFileObj }));
@@ -368,6 +367,25 @@ const uploadOss = async (file, config) => {
368
367
  return config.key;
369
368
  };
370
369
 
370
+ /**
371
+ * 上传到火山云TOS
372
+ */
373
+ const uploadTos = async (file, config) => {
374
+ const formData = new FormData();
375
+ formData.append("key", config["key"]);
376
+ formData.append("policy", config["policy"]);
377
+ formData.append("x-tos-algorithm", config["x-tos-algorithm"]);
378
+ formData.append("x-tos-credential", config["x-tos-credential"]);
379
+ formData.append("x-tos-date", config["x-tos-date"]);
380
+ formData.append("x-tos-signature", config["x-tos-signature"]);
381
+ formData.append("file", file, file.fileName || file.name);
382
+ await fetch(config.host, {
383
+ method: "POST",
384
+ body: formData,
385
+ });
386
+
387
+ return config["key"];
388
+ };
371
389
  /**
372
390
  * 自定义上传事件
373
391
  */
@@ -375,9 +393,11 @@ const uploadRequest = async (options, renderItem: FormDataItem) => {
375
393
  const file = options.file;
376
394
  if (renderItem.type == "uploadOss") {
377
395
  const config: any = await renderItem.getOssToken({ file_name: file.name });
378
-
379
396
  const key = await uploadOss(file, config);
380
-
397
+ options.onSuccess({ key }, file);
398
+ } else if (renderItem.type == "uploadTos") {
399
+ const config: any = await renderItem.getTosToken({ file_name: file.name });
400
+ const key = await uploadTos(file, config);
381
401
  options.onSuccess({ key }, file);
382
402
  } else {
383
403
  setTimeout(() => {
@@ -398,7 +418,6 @@ const editorUpload = async (renderItem, file, insertFn) => {
398
418
  insertFn(renderItem.baseOssUrl + key);
399
419
  };
400
420
 
401
-
402
421
  /**
403
422
  * 发送验证码
404
423
  */
@@ -571,7 +590,7 @@ defineExpose({
571
590
  ></a-tree-select>
572
591
 
573
592
  <a-upload
574
- v-if="renderItem.type == 'uploadOss' || renderItem.type == 'upload'"
593
+ v-if="renderItem.type == 'uploadOss' || renderItem.type == 'uploadTos' || renderItem.type == 'upload'"
575
594
  :file-list="formState[renderItem.key]"
576
595
  :multiple="true"
577
596
  :max-count="renderItem?.maxCount || 1"
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "p-pc-ui",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "type": "module",
5
- "module": "index.ts",
5
+ "module": "dist/index.ts",
6
6
  "main": "dist/index.ts",
7
7
  "files": [
8
8
  "dist"