@cloudbase/weda-ui-mp 3.20.2 → 3.20.4
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/components/form/uploader/index.js +21 -6
- package/components/form/uploader/weui-uploader.js +1 -0
- package/components/form/uploaderFile/index.js +4 -0
- package/components/form/uploaderFile/upload.js +32 -11
- package/components/richText/index.wxss +4 -0
- package/components/wd-upload-file/index.js +4 -0
- package/components/wd-upload-file/index.wxml +1 -0
- package/components/wd-upload-image/index.js +35 -10
- package/components/wd-upload-image/index.wxml +1 -0
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -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,
|
|
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
|
-
|
|
235
|
-
|
|
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 (
|
|
265
|
-
_value
|
|
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.
|
|
271
|
-
|
|
272
|
-
|
|
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);
|
|
@@ -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,11 +45,15 @@ 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: [],
|
|
50
55
|
uploadInstance: {},
|
|
51
|
-
config: { count: 9, maxDuration: 60 },
|
|
56
|
+
config: { count: 9, maxDuration: 60, mediaType: 'image' },
|
|
52
57
|
},
|
|
53
58
|
methods: {
|
|
54
59
|
initValue: function () {
|
|
@@ -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 (
|
|
92
|
-
_value
|
|
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.
|
|
98
|
-
|
|
99
|
-
|
|
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
|
},
|