@cloudbase/weda-ui-mp 3.12.2 → 3.13.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/components/form/uploaderFile/index.js +37 -59
- package/components/form/uploaderFile/index.wxss +5 -13
- package/components/wd-store-home/index.js +17 -0
- package/components/wd-store-home/index.json +5 -0
- package/components/wd-store-home/index.wxml +1 -0
- package/components/wd-store-product/index.js +39 -0
- package/components/wd-store-product/index.json +5 -0
- package/components/wd-store-product/index.wxml +1 -0
- package/index.json +2 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
|
|
2
2
|
import { transSize, randomStr } from '../../../utils/platform';
|
|
3
|
+
import equal from '../../../utils/deepEqual';
|
|
3
4
|
|
|
4
5
|
Component({
|
|
5
6
|
options: {
|
|
@@ -24,6 +25,9 @@ Component({
|
|
|
24
25
|
defaultValue: {
|
|
25
26
|
type: null,
|
|
26
27
|
},
|
|
28
|
+
oldValue: {
|
|
29
|
+
type: null,
|
|
30
|
+
},
|
|
27
31
|
maxUploadCount: {
|
|
28
32
|
type: Number,
|
|
29
33
|
value: 9,
|
|
@@ -105,10 +109,7 @@ Component({
|
|
|
105
109
|
});
|
|
106
110
|
return false;
|
|
107
111
|
}
|
|
108
|
-
if (
|
|
109
|
-
this.properties.maxSize &&
|
|
110
|
-
files.some((f) => f.size > this.properties.maxSize * 1024 * 1024)
|
|
111
|
-
) {
|
|
112
|
+
if (this.properties.maxSize && files.some((f) => f.size > this.properties.maxSize * 1024 * 1024)) {
|
|
112
113
|
wx.showToast({
|
|
113
114
|
title: `上传文件大小不能超过${this.properties.maxSize}M`,
|
|
114
115
|
icon: 'none',
|
|
@@ -154,6 +155,13 @@ Component({
|
|
|
154
155
|
},
|
|
155
156
|
});
|
|
156
157
|
},
|
|
158
|
+
getName: function (hf) {
|
|
159
|
+
const uuidReg = /[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}-/;
|
|
160
|
+
const lastIndex = String(hf).lastIndexOf('/');
|
|
161
|
+
const name = String(hf).slice(lastIndex + 1);
|
|
162
|
+
const label = name.replace(uuidReg, '');
|
|
163
|
+
return label;
|
|
164
|
+
},
|
|
157
165
|
handleUpload: async function (files, reload = false) {
|
|
158
166
|
var _this = this;
|
|
159
167
|
if (!this.handleBefore(files)) return;
|
|
@@ -172,10 +180,7 @@ Component({
|
|
|
172
180
|
});
|
|
173
181
|
if (typeof ret === 'boolean') {
|
|
174
182
|
shouldUploadToCos = ret;
|
|
175
|
-
} else if (
|
|
176
|
-
Array.Array(ret) &&
|
|
177
|
-
ret.every((i) => typeof i === 'string')
|
|
178
|
-
) {
|
|
183
|
+
} else if (Array.Array(ret) && ret.every((i) => typeof i === 'string')) {
|
|
179
184
|
files = ret.map((path, idx) => {
|
|
180
185
|
files[idx].path = path;
|
|
181
186
|
});
|
|
@@ -193,14 +198,12 @@ Component({
|
|
|
193
198
|
...i,
|
|
194
199
|
percent: '0',
|
|
195
200
|
cloudPath: null,
|
|
196
|
-
name: i?.name || i?.tempFilePath
|
|
201
|
+
name: i?.name || this.getName(i?.tempFilePath),
|
|
197
202
|
filePath: i?.path || i?.tempFilePath || null,
|
|
198
203
|
size: transSize(i?.size),
|
|
199
204
|
status: 'pending',
|
|
200
205
|
}));
|
|
201
|
-
let filelsList = reload
|
|
202
|
-
? this.data.files
|
|
203
|
-
: [...this.data.files, ...initFiles];
|
|
206
|
+
let filelsList = reload ? this.data.files : [...this.data.files, ...initFiles];
|
|
204
207
|
this.setData({
|
|
205
208
|
files: filelsList,
|
|
206
209
|
});
|
|
@@ -210,9 +213,7 @@ Component({
|
|
|
210
213
|
_this.handleUploadFile({
|
|
211
214
|
_tempFile: tempFile,
|
|
212
215
|
onSuccess: (res) => {
|
|
213
|
-
filelsList = filelsList.map((i) =>
|
|
214
|
-
i.filePath === res.filePath ? res : i
|
|
215
|
-
);
|
|
216
|
+
filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
|
|
216
217
|
_this.triggerEvent('success', {
|
|
217
218
|
value: res.cloudPath,
|
|
218
219
|
file: res,
|
|
@@ -220,30 +221,22 @@ Component({
|
|
|
220
221
|
resolve(res);
|
|
221
222
|
},
|
|
222
223
|
onProgressUpdate: (res) => {
|
|
223
|
-
filelsList = filelsList.map((i) =>
|
|
224
|
-
i.filePath === res.filePath ? res : i
|
|
225
|
-
);
|
|
224
|
+
filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
|
|
226
225
|
_this.setData({
|
|
227
226
|
files: filelsList,
|
|
228
227
|
});
|
|
229
228
|
},
|
|
230
229
|
onFail: (res, error) => {
|
|
231
|
-
filelsList = filelsList.map((i) =>
|
|
232
|
-
i.filePath === res.filePath ? res : i
|
|
233
|
-
);
|
|
230
|
+
filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
|
|
234
231
|
_this.triggerEvent('error', error.detail);
|
|
235
232
|
resolve(res);
|
|
236
233
|
},
|
|
237
234
|
});
|
|
238
235
|
});
|
|
239
|
-
})
|
|
236
|
+
}),
|
|
240
237
|
).then((res) => {
|
|
241
|
-
const result = filelsList.map(
|
|
242
|
-
|
|
243
|
-
);
|
|
244
|
-
const cloudPathList = result
|
|
245
|
-
.filter((i) => i.cloudPath)
|
|
246
|
-
.map((j) => j.cloudPath);
|
|
238
|
+
const result = filelsList.map((i) => res.find((j) => j.filePath === i.filePath) || i);
|
|
239
|
+
const cloudPathList = result.filter((i) => i.cloudPath).map((j) => j.cloudPath);
|
|
247
240
|
this.setData({
|
|
248
241
|
files: result,
|
|
249
242
|
urls: cloudPathList,
|
|
@@ -252,12 +245,7 @@ Component({
|
|
|
252
245
|
_this.handleChange(cloudPathList);
|
|
253
246
|
});
|
|
254
247
|
},
|
|
255
|
-
handleUploadFile: async function ({
|
|
256
|
-
_tempFile,
|
|
257
|
-
onSuccess,
|
|
258
|
-
onProgressUpdate,
|
|
259
|
-
onFail,
|
|
260
|
-
}) {
|
|
248
|
+
handleUploadFile: async function ({ _tempFile, onSuccess, onProgressUpdate, onFail }) {
|
|
261
249
|
const tempFile = {
|
|
262
250
|
..._tempFile,
|
|
263
251
|
};
|
|
@@ -324,20 +312,15 @@ Component({
|
|
|
324
312
|
}
|
|
325
313
|
});
|
|
326
314
|
this.setData({
|
|
327
|
-
files: this.data.files.filter(
|
|
328
|
-
(v) => e.target.dataset.item.cloudPath !== v.cloudPath
|
|
329
|
-
),
|
|
315
|
+
files: this.data.files.filter((v) => e.target.dataset.item.cloudPath !== v.cloudPath),
|
|
330
316
|
urls: newUrls,
|
|
331
317
|
});
|
|
332
318
|
} else {
|
|
333
319
|
const filelist = this.data.files.filter(
|
|
334
320
|
(item) =>
|
|
335
|
-
e.target.dataset.item?.path != item?.path ||
|
|
336
|
-
e.target.dataset.item?.tempFilePath != item?.tempFilePath
|
|
337
|
-
);
|
|
338
|
-
newUrls = this.data.urls.filter(
|
|
339
|
-
(v) => e.target.dataset.item?.cloudPath != v
|
|
321
|
+
e.target.dataset.item?.path != item?.path || e.target.dataset.item?.tempFilePath != item?.tempFilePath,
|
|
340
322
|
);
|
|
323
|
+
newUrls = this.data.urls.filter((v) => e.target.dataset.item?.cloudPath != v);
|
|
341
324
|
this.setData({
|
|
342
325
|
files: filelist,
|
|
343
326
|
urls: newUrls,
|
|
@@ -352,6 +335,7 @@ Component({
|
|
|
352
335
|
if (this.properties.single) {
|
|
353
336
|
value = values[0] ?? '';
|
|
354
337
|
}
|
|
338
|
+
this.setData({ oldValue: value });
|
|
355
339
|
this.triggerEvent('change', { value });
|
|
356
340
|
},
|
|
357
341
|
|
|
@@ -428,6 +412,9 @@ Component({
|
|
|
428
412
|
},
|
|
429
413
|
observers: {
|
|
430
414
|
defaultValue: async function (value) {
|
|
415
|
+
if (equal(this.data.oldValue, value)) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
431
418
|
//当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
|
|
432
419
|
if (Array.isArray(value) && !this.data.singleFlag) {
|
|
433
420
|
this.setData({
|
|
@@ -441,10 +428,7 @@ Component({
|
|
|
441
428
|
for (let f of values) {
|
|
442
429
|
if (f.startsWith('cloud:')) {
|
|
443
430
|
const hf = await getTempFileURL(f);
|
|
444
|
-
const
|
|
445
|
-
const lastIndex = String(hf).lastIndexOf('/');
|
|
446
|
-
const name = String(hf).slice(lastIndex + 1);
|
|
447
|
-
const label = name.replace(uuidReg, '');
|
|
431
|
+
const label = this.getName(hf);
|
|
448
432
|
const httpFile = {
|
|
449
433
|
name: label,
|
|
450
434
|
cloudPath: f,
|
|
@@ -455,19 +439,14 @@ Component({
|
|
|
455
439
|
httpFiles.push(httpFile);
|
|
456
440
|
}
|
|
457
441
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
this.
|
|
462
|
-
|
|
463
|
-
cloudFile:
|
|
464
|
-
JSON.stringify(value) != JSON.stringify(this.data.cloudFile)
|
|
465
|
-
? [].concat(value)
|
|
466
|
-
: [],
|
|
467
|
-
});
|
|
468
|
-
}
|
|
442
|
+
this.setData({
|
|
443
|
+
oldValue: value,
|
|
444
|
+
files: httpFiles,
|
|
445
|
+
cloudFile: JSON.stringify(value) != JSON.stringify(this.data.cloudFile) ? [].concat(value) : [],
|
|
446
|
+
});
|
|
469
447
|
} else {
|
|
470
448
|
this.setData({
|
|
449
|
+
oldValue: value,
|
|
471
450
|
files: [],
|
|
472
451
|
cloudFile: [],
|
|
473
452
|
});
|
|
@@ -481,8 +460,7 @@ Component({
|
|
|
481
460
|
},
|
|
482
461
|
'layout,extClass': function (layout, extClass) {
|
|
483
462
|
const temp = `weda-formcells weui-cells weui-cells_forms ${extClass}`;
|
|
484
|
-
const layoutCls =
|
|
485
|
-
layout !== 'vertical' ? ` weui-flex ${temp}` : `${temp}`;
|
|
463
|
+
const layoutCls = layout !== 'vertical' ? ` weui-flex ${temp}` : `${temp}`;
|
|
486
464
|
this.setData({ layoutCls });
|
|
487
465
|
},
|
|
488
466
|
},
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
/* theme */
|
|
32
32
|
.weda-uploader-files__btn {
|
|
33
33
|
margin: 0;
|
|
34
|
-
width:
|
|
34
|
+
width: auto;
|
|
35
35
|
height: 32px;
|
|
36
36
|
padding: 0;
|
|
37
37
|
display: flex;
|
|
@@ -132,27 +132,19 @@
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/* 标准化样式适配 start */
|
|
135
|
-
.wd-form-item.wd-mp-upload-file-root
|
|
136
|
-
.weda-uploader-files
|
|
137
|
-
.weda-uploader-files__btn-contain {
|
|
135
|
+
.wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__btn-contain {
|
|
138
136
|
padding: 0;
|
|
139
137
|
}
|
|
140
138
|
|
|
141
|
-
.wd-form-item.wd-mp-upload-file-root
|
|
142
|
-
.weda-uploader-files
|
|
143
|
-
.weda-uploader-files__file-status {
|
|
139
|
+
.wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__file-status {
|
|
144
140
|
width: auto;
|
|
145
141
|
}
|
|
146
142
|
|
|
147
|
-
.wd-form-item.wd-mp-upload-file-root
|
|
148
|
-
.weda-uploader-files
|
|
149
|
-
.weda-uploader-files__file-foot {
|
|
143
|
+
.wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__file-foot {
|
|
150
144
|
margin: 0;
|
|
151
145
|
}
|
|
152
146
|
|
|
153
|
-
.wd-form-item.wd-mp-upload-file-root
|
|
154
|
-
.weda-uploader-files
|
|
155
|
-
.weda-uploader-files__item {
|
|
147
|
+
.wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__item {
|
|
156
148
|
padding: 0;
|
|
157
149
|
}
|
|
158
150
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<store-home id="{{id}}" appid="{{appid}}"></store-home>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import handleEvents from '../../utils/handleEvents';
|
|
2
|
+
|
|
3
|
+
Component({
|
|
4
|
+
options: {
|
|
5
|
+
virtualHost: true,
|
|
6
|
+
},
|
|
7
|
+
properties: {
|
|
8
|
+
id: {
|
|
9
|
+
type: String,
|
|
10
|
+
value: '',
|
|
11
|
+
},
|
|
12
|
+
appid: {
|
|
13
|
+
type: String,
|
|
14
|
+
value: '',
|
|
15
|
+
},
|
|
16
|
+
productId: {
|
|
17
|
+
type: String,
|
|
18
|
+
value: '',
|
|
19
|
+
},
|
|
20
|
+
productPromotionLink: {
|
|
21
|
+
type: String,
|
|
22
|
+
value: '',
|
|
23
|
+
},
|
|
24
|
+
mediaId: {
|
|
25
|
+
type: String,
|
|
26
|
+
value: '',
|
|
27
|
+
},
|
|
28
|
+
customStyle: {
|
|
29
|
+
type: Object,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
methods: {
|
|
33
|
+
...handleEvents([
|
|
34
|
+
{ title: '跳转小店成功', name: 'bindentererror' },
|
|
35
|
+
{ title: '跳转小店失败', name: 'bindentersuccess' },
|
|
36
|
+
]),
|
|
37
|
+
},
|
|
38
|
+
observers: {},
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<store-product id="{{id}}" appid="{{appid}}" product-id="{{productId}}" product-promotion-link="{{productPromotionLink}}" media-id="{{mediaId}}" custom-style="{{customStyle}}" bindentersuccess="bindentersuccess" bindentererror="bindentererror" />
|
package/index.json
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"components": {
|
|
3
|
+
"WdStoreProduct": "components/wd-store-product/index",
|
|
4
|
+
"WdStoreHome": "components/wd-store-home/index",
|
|
3
5
|
"WdMarkdown": "components/wd-markdown/index",
|
|
4
6
|
"WdUnifiedLink": "components/wd-unified-link/index",
|
|
5
7
|
"WdProgress": "components/wd-progress/index",
|