@cloudbase/weda-ui-mp 3.20.2 → 3.20.3

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.
@@ -2,6 +2,7 @@ import { getCloudInstance, getTempFileURL, getDefaultUploadPath } from '../../..
2
2
  import { randomStr } from '../../../utils/platform';
3
3
  import { compressImage } from './compress';
4
4
  import { isNil } from '../../../utils/lodash';
5
+ import { storageTypeIsHttps } from '../uploaderFile/upload';
5
6
 
6
7
  Component({
7
8
  options: {
@@ -99,6 +100,10 @@ Component({
99
100
  type: Object,
100
101
  value: null,
101
102
  },
103
+ storageType: {
104
+ type: String,
105
+ value: 'cloudID',
106
+ },
102
107
  },
103
108
  data: {
104
109
  maxCount: 0,
@@ -172,6 +177,17 @@ Component({
172
177
  cloudPath,
173
178
  filePath,
174
179
  });
180
+ let result = uploadRes.fileID;
181
+ let file = files?.tempFiles[0];
182
+ // 小程序自带tempURL 不需要调用 tcb.getTempFileURL 获取
183
+ if (storageTypeIsHttps(this.data.storageType)) {
184
+ result = await getTempFileURL(uploadRes.fileID);
185
+ file = { ...file, url: result };
186
+ }
187
+ this.triggerEvent('success', {
188
+ value: result,
189
+ file: file,
190
+ });
175
191
  return { fileID: uploadRes.fileID };
176
192
  });
177
193
  const uploadFileList = await Promise.all(uploadPromise);
@@ -195,11 +211,7 @@ Component({
195
211
  },
196
212
  uploadSuccess: async function (e) {
197
213
  const urls = e.detail.cloudUrls; // uploadFile 获取返回值
198
- // 小程序自带tempURL 不需要调用 tcb.getTempFileURL 获取
199
- this.triggerEvent('success', {
200
- value: this.properties.single ? urls[0] : urls,
201
- file: e.detail.file,
202
- });
214
+
203
215
  const newUrls = [...this.data.cloudFile, ...urls];
204
216
  this.setData({
205
217
  files: this.data.files.concat(e.detail.urls.map((url) => ({ url }))),
@@ -228,8 +240,11 @@ Component({
228
240
  }
229
241
  this.handleChange(newUrls, true);
230
242
  },
231
- handleChange: function (values, isDelete = false) {
243
+ handleChange: async function (values, isDelete = false) {
232
244
  let value = values;
245
+ if (storageTypeIsHttps(this.data.storageType)) {
246
+ value = await Promise.all(values.map((i) => getTempFileURL(i)));
247
+ }
233
248
  if (this.properties.single) {
234
249
  value = values[0] ?? '';
235
250
  }
@@ -80,6 +80,10 @@ Component({
80
80
  type: String,
81
81
  value: '点击上传',
82
82
  },
83
+ storageType: {
84
+ type: String,
85
+ value: 'cloudID',
86
+ },
83
87
  },
84
88
  data: {
85
89
  maxCount: 0,
@@ -1,5 +1,7 @@
1
1
  import { transSize, randomStr } from '../../../utils/platform';
2
- import { getCloudInstance, getDefaultUploadPath } from '../../../utils/tcb';
2
+ import { getCloudInstance, getDefaultUploadPath, getTempFileURL } from '../../../utils/tcb';
3
+
4
+ export const storageTypeIsHttps = (storageType) => storageType === 'https';
3
5
 
4
6
  const ACTION = { CHOOSE_MEDIA: 'chooseMedia', CHOOSE_MESSAGE_FILE: 'chooseMessageFile' };
5
7
 
@@ -226,15 +228,16 @@ const handleUploadFile = async ({
226
228
  };
227
229
 
228
230
  export const upload = (uploadInstance) => {
229
- const { config, onSuccess, onFail } = uploadInstance;
231
+ const { config, onFail } = uploadInstance;
230
232
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
231
233
  const { action, disabled, maxSize, ..._config } = config;
232
234
  if (disabled) return;
233
235
  const success = (res) => {
234
- const result = handleUpload(res.tempFiles, uploadInstance);
235
- onSuccess(result);
236
+ // 文件选择成功
237
+ handleUpload(res.tempFiles, uploadInstance);
236
238
  };
237
239
  const fail = (e) => {
240
+ // 文件选择失败
238
241
  onFail(e);
239
242
  };
240
243
 
@@ -260,17 +263,35 @@ export const initUploadInstance = ({ action, config, previewFile }, _this) => {
260
263
  urls: cloudPathList,
261
264
  cloudFile: cloudPathList,
262
265
  });
266
+ const { single, storageType } = _this.data;
263
267
  let _value = cloudPathList;
264
- if (_this.data.single) {
265
- _value = cloudPathList[0] ?? '';
268
+ if (storageTypeIsHttps(storageType)) {
269
+ Promise.all(_value.map((i) => getTempFileURL(i))).then((res) => {
270
+ _value = single ? cloudPathList[0] ?? '' : res;
271
+ _this.handleChange(_value);
272
+ });
273
+ } else {
274
+ if (single) {
275
+ _value = cloudPathList[0] ?? '';
276
+ }
277
+ _this.handleChange(_value);
266
278
  }
267
- _this.handleChange(_value);
268
279
  },
269
280
  onSuccess(res) {
270
- _this.triggerEvent('success', {
271
- value: res.cloudPath,
272
- file: res,
273
- });
281
+ const { storageType } = _this.data;
282
+ if (storageTypeIsHttps(storageType)) {
283
+ getTempFileURL(res.cloudPath).then((url) => {
284
+ _this.triggerEvent('success', {
285
+ value: url,
286
+ file: { ...res, url },
287
+ });
288
+ });
289
+ } else {
290
+ _this.triggerEvent('success', {
291
+ value: res.cloudPath,
292
+ file: res,
293
+ });
294
+ }
274
295
  },
275
296
  onFail(e) {
276
297
  _this.triggerEvent('error', e);
@@ -68,3 +68,7 @@
68
68
  .weda-RichTextView ._img {
69
69
  vertical-align: middle;
70
70
  }
71
+
72
+ .weda-RichTextView .p {
73
+ min-height: 1em;
74
+ }
@@ -30,6 +30,10 @@ Component({
30
30
  type: String,
31
31
  value: '点击上传',
32
32
  },
33
+ storageType: {
34
+ type: String,
35
+ value: 'cloudID',
36
+ },
33
37
  },
34
38
  methods: {
35
39
  initValue: function () {
@@ -36,6 +36,7 @@
36
36
  callbacks="{{callbacks}}"
37
37
  uploadButtonText="{{uploadButtonText}}"
38
38
  uploadTipText="{{uploadTipText}}"
39
+ storageType="{{storageType}}"
39
40
  />
40
41
  </wd-form-item>
41
42
  </block>
@@ -3,7 +3,8 @@ import formFieldBehavior from '../form-field-behavior/form-field-behavior';
3
3
  import itemBehavior from '../form-field-behavior/item-behavior';
4
4
  import isEqual from '../../utils/deepEqual';
5
5
  import { convertSingleValue } from '../../utils/platform';
6
- import { upload } from '../form/uploaderFile/upload';
6
+ import { upload, storageTypeIsHttps } from '../form/uploaderFile/upload';
7
+ import { getTempFileURL } from '../../utils/tcb';
7
8
 
8
9
  Component({
9
10
  options: {
@@ -44,6 +45,10 @@ Component({
44
45
  type: String,
45
46
  value: 'normal',
46
47
  },
48
+ storageType: {
49
+ type: String,
50
+ value: 'cloudID',
51
+ },
47
52
  },
48
53
  data: {
49
54
  files: [],
@@ -87,17 +92,35 @@ Component({
87
92
  files,
88
93
  });
89
94
  const cloudPathList = files.map((i) => i.cloudId).filter((j) => !!j);
95
+ const { single, storageType } = _this.data;
90
96
  let _value = cloudPathList;
91
- if (_this.data.single) {
92
- _value = cloudPathList[0] ?? '';
97
+ if (storageTypeIsHttps(storageType)) {
98
+ Promise.all(_value.map((i) => getTempFileURL(i))).then((res) => {
99
+ _value = single ? cloudPathList[0] ?? '' : res;
100
+ _this.handleChange({ detail: { value: _value } });
101
+ });
102
+ } else {
103
+ if (single) {
104
+ _value = cloudPathList[0] ?? '';
105
+ }
106
+ _this.handleChange({ detail: { value: _value } });
93
107
  }
94
- _this.handleChange({ detail: { value: _value } });
95
108
  },
96
109
  onSuccess(res) {
97
- _this.triggerEvent('success', {
98
- value: res.cloudPath,
99
- file: res,
100
- });
110
+ const { storageType } = _this.data;
111
+ if (storageTypeIsHttps(storageType)) {
112
+ getTempFileURL(res.cloudPath).then((url) => {
113
+ _this.triggerEvent('success', {
114
+ value: url,
115
+ file: { ...res, url },
116
+ });
117
+ });
118
+ } else {
119
+ _this.triggerEvent('success', {
120
+ value: res.cloudPath,
121
+ file: res,
122
+ });
123
+ }
101
124
  },
102
125
  onFail(e) {
103
126
  _this.triggerEvent('error', e);
@@ -163,13 +186,14 @@ Component({
163
186
  'name, value, label, required, visible, disabled, readOnly, sourceType': function () {
164
187
  this.updateWidgetAPI();
165
188
  },
166
- 'disabled,sourceType,maxUploadCount,sizeType,maxSize,single': function (
189
+ 'disabled,sourceType,maxUploadCount,sizeType,maxSize,single,storageType': function (
167
190
  disabled,
168
191
  sourceType,
169
192
  maxUploadCount,
170
193
  sizeType,
171
194
  maxSize,
172
195
  single,
196
+ storageType,
173
197
  ) {
174
198
  const config = {
175
199
  disabled,
@@ -178,6 +202,7 @@ Component({
178
202
  sizeType,
179
203
  maxSize,
180
204
  single,
205
+ storageType,
181
206
  };
182
207
  this.setConfig(config);
183
208
  },
@@ -39,6 +39,7 @@
39
39
  compressQuality="{{compressQuality}}"
40
40
  compressedHeight="{{compressedHeight}}"
41
41
  compressedWidth="{{compressedWidth}}"
42
+ storageType="{{storageType}}"
42
43
  callbacks="{{callbacks}}"
43
44
  bind:change="handleChange"
44
45
  sourceType="{{sourceType}}"
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.20.2",
6
+ "version": "3.20.3",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"