@cloudbase/weda-ui 2.0.8 → 2.0.11
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/package.json +9 -2
- package/src/mp/components/button/index.js +1 -1
- package/src/mp/components/button/index.wxml +19 -19
- package/src/mp/components/calendar/index.js +64 -37
- package/src/mp/components/calendar/index.wxml +28 -8
- package/src/mp/components/carousel/index.wxml +30 -3
- package/src/mp/components/chart/bar/index.js +1 -2
- package/src/mp/components/chart/bar/index.wxml +7 -2
- package/src/mp/components/chart/common/config/bar.js +1 -1
- package/src/mp/components/chart/common/core/eChartBar.js +29 -34
- package/src/mp/components/chart/common/core/eChartBase.js +46 -32
- package/src/mp/components/chart/common/core/eChartLine.js +34 -40
- package/src/mp/components/chart/common/core/eChartPie.js +12 -9
- package/src/mp/components/chart/ec-canvas/ec-canvas.wxml +19 -2
- package/src/mp/components/chart/ec-canvas/wx-canvas.js +24 -22
- package/src/mp/components/chart/line/index.js +2 -2
- package/src/mp/components/chart/line/index.wxml +7 -2
- package/src/mp/components/chart/pie/index.js +1 -1
- package/src/mp/components/chart/pie/index.wxml +7 -3
- package/src/mp/components/chart/statisticsCard/index.wxml +5 -1
- package/src/mp/components/dataView/index.wxml +2 -2
- package/src/mp/components/form/checkbox/index.js +10 -6
- package/src/mp/components/form/checkbox/index.wxml +26 -23
- package/src/mp/components/form/form/index.wxml +3 -3
- package/src/mp/components/form/formcell/index.wxml +9 -9
- package/src/mp/components/form/formcell/index.wxss +1 -1
- package/src/mp/components/form/input/index.js +3 -3
- package/src/mp/components/form/input/index.wxml +36 -30
- package/src/mp/components/form/input/index.wxss +2 -2
- package/src/mp/components/form/location/components/mapChoose/index.wxml +59 -12
- package/src/mp/components/form/location/index.wxml +39 -7
- package/src/mp/components/form/radio/index.js +9 -5
- package/src/mp/components/form/radio/index.wxml +23 -23
- package/src/mp/components/form/select/index.js +156 -97
- package/src/mp/components/form/select/index.wxml +39 -37
- package/src/mp/components/form/select/index.wxss +5 -3
- package/src/mp/components/form/select/region/index.js +18 -12
- package/src/mp/components/form/switch/index.wxml +20 -16
- package/src/mp/components/form/textarea/index.wxml +12 -8
- package/src/mp/components/form/tips/index.wxml +1 -3
- package/src/mp/components/form/uploader/index.js +1 -1
- package/src/mp/components/form/uploader/index.wxml +19 -18
- package/src/mp/components/form/uploader/weui-uploader.js +210 -200
- package/src/mp/components/form/uploader/weui-uploader.wxml +81 -38
- package/src/mp/components/form/uploaderFile/index.js +5 -4
- package/src/mp/components/form/uploaderFile/index.wxml +97 -41
- package/src/mp/components/graphicCard/index.js +26 -24
- package/src/mp/components/graphicCard/index.wxml +30 -6
- package/src/mp/components/image/index.wxml +25 -18
- package/src/mp/components/image/index.wxss +3 -1
- package/src/mp/components/listView/index.wxml +34 -11
- package/src/mp/components/lottery/index.wxml +29 -7
- package/src/mp/components/lottery/index.wxss +31 -25
- package/src/mp/components/navLayout/index.wxml +29 -7
- package/src/mp/components/navigationBar/index.wxml +162 -53
- package/src/mp/components/swiper/index.wxml +12 -7
- package/src/mp/components/tabs/index.js +14 -10
- package/src/mp/components/tabs/index.wxml +2 -1
- package/src/mp/components/text/index.wxml +2 -1
- package/src/mp/components/text/index.wxss +1 -1
- package/src/mp/components/wxOpenApi/phone/index.wxml +11 -12
- package/src/mp/components/wxOpenApi/phoneCode/index.wxml +11 -12
- package/src/mp/components/wxOpenApi/share/index.wxml +11 -12
- package/src/mp/components/wxOpenApi/userInfo/index.wxml +10 -11
- package/src/mp/style/weda-ui.wxss +8 -3
- package/src/mp/utils/deepEqual.js +37 -37
- package/src/mp/utils/destr.js +41 -40
- package/src/mp/utils/dr_square_point.js +10 -6
- package/src/setupTests.js +13 -13
- package/src/web/components/button/index.tsx +44 -40
- package/src/web/components/carousel/index.tsx +1 -1
- package/src/web/components/chart/common/config/bar.js +1 -1
- package/src/web/components/chart/common/core/eChartBar.js +28 -34
- package/src/web/components/chart/common/core/eChartLine.js +34 -40
- package/src/web/components/chart/common/core/eChartPie.js +12 -9
- package/src/web/components/form/form/index.tsx +5 -5
- package/src/web/components/form/formcell/index.css +5 -1
- package/src/web/components/form/formcell/index.tsx +1 -1
- package/src/web/components/form/select/h5.tsx +154 -103
- package/src/web/components/form/select/index.css +3 -0
- package/src/web/components/form/textarea/index.tsx +1 -1
- package/src/web/components/form/uploader/uploader.h5.tsx +26 -20
- package/src/web/components/image/index.css +2 -2
- package/src/web/components/image/index.tsx +1 -1
- package/src/web/components/link/index.tsx +1 -1
- package/src/web/components/navLayout/index.tsx +1 -1
- package/src/web/components/navigationBar/index.tsx +2 -2
- package/src/web/components/picker/timePicker.tsx +1 -1
- package/src/web/components/text/index.tsx +13 -14
- package/src/web/utils/isObjectEqual.js +2 -1
- package/src/web/weda-ui.css +4 -0
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
<view
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
class="weda-ui weui-cells weui-cells_form {{className}}"
|
|
3
|
+
id="{{id}}"
|
|
4
|
+
style="{{style}}"
|
|
5
5
|
>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
<mp-uploader
|
|
7
|
+
max-size="{{maxSize * 1024 * 1024}}"
|
|
8
|
+
files="{{files}}"
|
|
9
|
+
title="{{title}}"
|
|
10
|
+
showDelete="{{true}}"
|
|
11
|
+
ext-class="{{layout}}"
|
|
12
|
+
bindfail="uploadError"
|
|
13
|
+
bindsuccess="uploadSuccess"
|
|
14
|
+
layout="{{layout}}"
|
|
15
|
+
select="{{selectFile}}"
|
|
16
|
+
upload="{{uploadFile}}"
|
|
17
|
+
maxCount="{{maxCount}}"
|
|
18
|
+
binddelete="onDelete"
|
|
19
|
+
>
|
|
20
|
+
</mp-uploader>
|
|
20
21
|
</view>
|
|
21
22
|
|
|
22
23
|
<!-- uploader delete 实际代码接受 showDelete
|
|
23
24
|
https://developers.weixin.qq.com/community/develop/doc/000a4e7b9cc158c110aa3961056400
|
|
24
25
|
-->
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
<!-- bind开头的是事件handler,wxml模版中不能带 `{{}}`
|
|
27
28
|
```
|
|
28
29
|
<mp-uploader files="{{files}}" showDelete="{{true}}" ext-class="{{layout}}" bindfail="uploadError" bindsuccess="uploadSuccess" select="{{selectFile}}" upload="{{uploadFile}}" maxCount="{{maxUploadCount}}" title="{{title}}" binddelete="onDelete"></mp-uploader>
|
|
29
30
|
```
|
|
@@ -1,209 +1,219 @@
|
|
|
1
1
|
Component({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
options: {
|
|
3
|
+
addGlobalClass: true,
|
|
4
|
+
virtualHost: true,
|
|
5
|
+
},
|
|
6
|
+
properties: {
|
|
7
|
+
title: {
|
|
8
|
+
type: String,
|
|
9
|
+
value: '图片上传',
|
|
5
10
|
},
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
value: '图片上传'
|
|
10
|
-
},
|
|
11
|
-
sizeType: {
|
|
12
|
-
type: Array,
|
|
13
|
-
value: ['original', 'compressed']
|
|
14
|
-
},
|
|
15
|
-
sourceType: {
|
|
16
|
-
type: Array,
|
|
17
|
-
value: ['album', 'camera']
|
|
18
|
-
},
|
|
19
|
-
maxSize: {
|
|
20
|
-
type: Number,
|
|
21
|
-
value: 5 * 1024 * 1024
|
|
22
|
-
},
|
|
23
|
-
maxCount: {
|
|
24
|
-
// 最多上传多少个文件
|
|
25
|
-
type: Number,
|
|
26
|
-
value: 1
|
|
27
|
-
},
|
|
28
|
-
files: {
|
|
29
|
-
// 当前的图片列表, {url, error, loading}
|
|
30
|
-
type: Array,
|
|
31
|
-
value: [],
|
|
32
|
-
observer(newVal) {
|
|
33
|
-
this.setData({
|
|
34
|
-
currentFiles: newVal
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
select: {
|
|
39
|
-
// 过滤某个文件
|
|
40
|
-
type: null,
|
|
41
|
-
value: () => { }
|
|
42
|
-
},
|
|
43
|
-
upload: {
|
|
44
|
-
// 返回Promise的一个文件上传的函数
|
|
45
|
-
type: null,
|
|
46
|
-
value: null
|
|
47
|
-
},
|
|
48
|
-
tips: {
|
|
49
|
-
type: String,
|
|
50
|
-
value: ''
|
|
51
|
-
},
|
|
52
|
-
layout: {
|
|
53
|
-
type: String,
|
|
54
|
-
value: 'horizontal'
|
|
55
|
-
},
|
|
56
|
-
extClass: {
|
|
57
|
-
type: String,
|
|
58
|
-
value: ''
|
|
59
|
-
},
|
|
60
|
-
showDelete: {
|
|
61
|
-
// 是否显示delete按钮
|
|
62
|
-
type: Boolean,
|
|
63
|
-
value: true
|
|
64
|
-
}
|
|
11
|
+
sizeType: {
|
|
12
|
+
type: Array,
|
|
13
|
+
value: ['original', 'compressed'],
|
|
65
14
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
previewImageUrls: []
|
|
15
|
+
sourceType: {
|
|
16
|
+
type: Array,
|
|
17
|
+
value: ['album', 'camera'],
|
|
70
18
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
19
|
+
maxSize: {
|
|
20
|
+
type: Number,
|
|
21
|
+
value: 5 * 1024 * 1024,
|
|
22
|
+
},
|
|
23
|
+
maxCount: {
|
|
24
|
+
// 最多上传多少个文件
|
|
25
|
+
type: Number,
|
|
26
|
+
value: 1,
|
|
27
|
+
},
|
|
28
|
+
files: {
|
|
29
|
+
// 当前的图片列表, {url, error, loading}
|
|
30
|
+
type: Array,
|
|
31
|
+
value: [],
|
|
32
|
+
observer(newVal) {
|
|
33
|
+
this.setData({
|
|
34
|
+
currentFiles: newVal,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
select: {
|
|
39
|
+
// 过滤某个文件
|
|
40
|
+
type: null,
|
|
41
|
+
value: () => {},
|
|
42
|
+
},
|
|
43
|
+
upload: {
|
|
44
|
+
// 返回Promise的一个文件上传的函数
|
|
45
|
+
type: null,
|
|
46
|
+
value: null,
|
|
47
|
+
},
|
|
48
|
+
tips: {
|
|
49
|
+
type: String,
|
|
50
|
+
value: '',
|
|
51
|
+
},
|
|
52
|
+
layout: {
|
|
53
|
+
type: String,
|
|
54
|
+
value: 'horizontal',
|
|
55
|
+
},
|
|
56
|
+
extClass: {
|
|
57
|
+
type: String,
|
|
58
|
+
value: '',
|
|
59
|
+
},
|
|
60
|
+
showDelete: {
|
|
61
|
+
// 是否显示delete按钮
|
|
62
|
+
type: Boolean,
|
|
63
|
+
value: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
data: {
|
|
67
|
+
currentFiles: [],
|
|
68
|
+
showPreview: false,
|
|
69
|
+
previewImageUrls: [],
|
|
70
|
+
},
|
|
71
|
+
ready() {},
|
|
72
|
+
methods: {
|
|
73
|
+
previewImage(e) {
|
|
74
|
+
const { index } = e.currentTarget.dataset;
|
|
75
|
+
const previewImageUrls = [];
|
|
76
|
+
this.data.files.forEach((item) => {
|
|
77
|
+
previewImageUrls.push(item.url);
|
|
78
|
+
});
|
|
79
|
+
this.setData({
|
|
80
|
+
previewImageUrls,
|
|
81
|
+
previewCurrent: index,
|
|
82
|
+
showPreview: true,
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
chooseImage() {
|
|
86
|
+
if (this.uploading) return;
|
|
87
|
+
wx.chooseImage({
|
|
88
|
+
count: this.data.maxCount - this.data.files.length,
|
|
89
|
+
sizeType: this.data.sizeType,
|
|
90
|
+
sourceType: this.data.sourceType,
|
|
91
|
+
success: (res) => {
|
|
92
|
+
// console.log('chooseImage resp', res)
|
|
93
|
+
// 首先检查文件大小
|
|
94
|
+
let invalidIndex = -1;
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
res.tempFiles.forEach((item, index) => {
|
|
97
|
+
if (item.size > this.data.maxSize) {
|
|
98
|
+
invalidIndex = index;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (typeof this.data.select === 'function') {
|
|
102
|
+
const ret = this.data.select(res);
|
|
103
|
+
if (ret === false) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (invalidIndex >= 0) {
|
|
108
|
+
this.triggerEvent(
|
|
109
|
+
'fail',
|
|
110
|
+
{
|
|
111
|
+
type: 1,
|
|
112
|
+
errMsg: `chooseImage:fail size exceed ${this.data.maxSize}`,
|
|
113
|
+
total: res.tempFilePaths.length,
|
|
114
|
+
index: invalidIndex,
|
|
115
|
+
},
|
|
116
|
+
{}
|
|
117
|
+
);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// 获取文件内容
|
|
121
|
+
const mgr = wx.getFileSystemManager();
|
|
122
|
+
const contents = res.tempFilePaths.map((item) => {
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
const fileContent = mgr.readFileSync(item);
|
|
125
|
+
return fileContent;
|
|
126
|
+
});
|
|
127
|
+
const obj = {
|
|
128
|
+
tempFilePaths: res.tempFilePaths,
|
|
129
|
+
tempFiles: res.tempFiles,
|
|
130
|
+
contents,
|
|
131
|
+
};
|
|
132
|
+
// 触发选中的事件,开发者根据内容来上传文件,上传了把上传的结果反馈到files属性里面
|
|
133
|
+
this.triggerEvent('select', obj, {});
|
|
134
|
+
const files = res.tempFilePaths.map((item, i) => ({
|
|
135
|
+
loading: true,
|
|
136
|
+
url:
|
|
137
|
+
res.tempFilePaths[i] ||
|
|
138
|
+
`data:image/jpg;base64,${wx.arrayBufferToBase64(contents[i])}`,
|
|
139
|
+
}));
|
|
140
|
+
if (!files || !files.length) return;
|
|
141
|
+
if (typeof this.data.upload === 'function') {
|
|
142
|
+
const len = this.data.files.length;
|
|
143
|
+
const newFiles = this.data.files.concat(files);
|
|
79
144
|
this.setData({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
showPreview: true
|
|
145
|
+
files: newFiles,
|
|
146
|
+
currentFiles: newFiles,
|
|
83
147
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.triggerEvent('fail', {
|
|
110
|
-
type: 1,
|
|
111
|
-
errMsg: `chooseImage:fail size exceed ${this.data.maxSize}`,
|
|
112
|
-
total: res.tempFilePaths.length,
|
|
113
|
-
index: invalidIndex
|
|
114
|
-
}, {});
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
// 获取文件内容
|
|
118
|
-
const mgr = wx.getFileSystemManager();
|
|
119
|
-
const contents = res.tempFilePaths.map((item) => {
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
const fileContent = mgr.readFileSync(item);
|
|
122
|
-
return fileContent;
|
|
123
|
-
});
|
|
124
|
-
const obj = {
|
|
125
|
-
tempFilePaths: res.tempFilePaths,
|
|
126
|
-
tempFiles: res.tempFiles,
|
|
127
|
-
contents
|
|
128
|
-
};
|
|
129
|
-
// 触发选中的事件,开发者根据内容来上传文件,上传了把上传的结果反馈到files属性里面
|
|
130
|
-
this.triggerEvent('select', obj, {});
|
|
131
|
-
const files = res.tempFilePaths.map((item, i) => ({
|
|
132
|
-
loading: true,
|
|
133
|
-
url: res.tempFilePaths[i] ||
|
|
134
|
-
`data:image/jpg;base64,${wx.arrayBufferToBase64(contents[i])}`
|
|
135
|
-
}));
|
|
136
|
-
if (!files || !files.length)
|
|
137
|
-
return;
|
|
138
|
-
if (typeof this.data.upload === 'function') {
|
|
139
|
-
const len = this.data.files.length;
|
|
140
|
-
const newFiles = this.data.files.concat(files);
|
|
141
|
-
this.setData({
|
|
142
|
-
files: newFiles,
|
|
143
|
-
currentFiles: newFiles
|
|
144
|
-
});
|
|
145
|
-
this.loading = true;
|
|
146
|
-
this.data
|
|
147
|
-
.upload(obj)
|
|
148
|
-
.then((json) => {
|
|
149
|
-
this.loading = false;
|
|
150
|
-
if (json.urls) {
|
|
151
|
-
const oldFiles = this.data.files;
|
|
152
|
-
json.urls.forEach((url, index) => {
|
|
153
|
-
oldFiles[len + index].url = url;
|
|
154
|
-
oldFiles[len + index].loading = false;
|
|
155
|
-
});
|
|
156
|
-
this.setData({
|
|
157
|
-
files: oldFiles,
|
|
158
|
-
currentFiles: newFiles
|
|
159
|
-
});
|
|
160
|
-
this.triggerEvent('success', json, {});
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
this.triggerEvent('fail', {
|
|
164
|
-
type: 3,
|
|
165
|
-
errMsg: 'upload file fail, urls not found'
|
|
166
|
-
}, {});
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
.catch((err) => {
|
|
170
|
-
this.loading = false;
|
|
171
|
-
const oldFiles = this.data.files;
|
|
172
|
-
res.tempFilePaths.forEach((item, index) => {
|
|
173
|
-
oldFiles[len + index].error = true;
|
|
174
|
-
oldFiles[len + index].loading = false;
|
|
175
|
-
});
|
|
176
|
-
this.setData({
|
|
177
|
-
files: oldFiles,
|
|
178
|
-
currentFiles: newFiles
|
|
179
|
-
});
|
|
180
|
-
this.triggerEvent('fail', {
|
|
181
|
-
type: 3,
|
|
182
|
-
errMsg: 'upload file fail',
|
|
183
|
-
error: err
|
|
184
|
-
}, {});
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
fail: (fail) => {
|
|
189
|
-
if (fail.errMsg.indexOf('chooseImage:fail cancel') >= 0) {
|
|
190
|
-
this.triggerEvent('cancel', {}, {});
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
fail.type = 2;
|
|
194
|
-
this.triggerEvent('fail', fail, {});
|
|
148
|
+
this.loading = true;
|
|
149
|
+
this.data
|
|
150
|
+
.upload(obj)
|
|
151
|
+
.then((json) => {
|
|
152
|
+
this.loading = false;
|
|
153
|
+
if (json.urls) {
|
|
154
|
+
const oldFiles = this.data.files;
|
|
155
|
+
json.urls.forEach((url, index) => {
|
|
156
|
+
oldFiles[len + index].url = url;
|
|
157
|
+
oldFiles[len + index].loading = false;
|
|
158
|
+
});
|
|
159
|
+
this.setData({
|
|
160
|
+
files: oldFiles,
|
|
161
|
+
currentFiles: newFiles,
|
|
162
|
+
});
|
|
163
|
+
this.triggerEvent('success', json, {});
|
|
164
|
+
} else {
|
|
165
|
+
this.triggerEvent(
|
|
166
|
+
'fail',
|
|
167
|
+
{
|
|
168
|
+
type: 3,
|
|
169
|
+
errMsg: 'upload file fail, urls not found',
|
|
170
|
+
},
|
|
171
|
+
{}
|
|
172
|
+
);
|
|
195
173
|
}
|
|
196
|
-
|
|
174
|
+
})
|
|
175
|
+
.catch((err) => {
|
|
176
|
+
this.loading = false;
|
|
177
|
+
const oldFiles = this.data.files;
|
|
178
|
+
res.tempFilePaths.forEach((item, index) => {
|
|
179
|
+
oldFiles[len + index].error = true;
|
|
180
|
+
oldFiles[len + index].loading = false;
|
|
181
|
+
});
|
|
182
|
+
this.setData({
|
|
183
|
+
files: oldFiles,
|
|
184
|
+
currentFiles: newFiles,
|
|
185
|
+
});
|
|
186
|
+
this.triggerEvent(
|
|
187
|
+
'fail',
|
|
188
|
+
{
|
|
189
|
+
type: 3,
|
|
190
|
+
errMsg: 'upload file fail',
|
|
191
|
+
error: err,
|
|
192
|
+
},
|
|
193
|
+
{}
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
197
|
},
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
198
|
+
fail: (fail) => {
|
|
199
|
+
if (fail.errMsg.indexOf('chooseImage:fail cancel') >= 0) {
|
|
200
|
+
this.triggerEvent('cancel', {}, {});
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
fail.type = 2;
|
|
204
|
+
this.triggerEvent('fail', fail, {});
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
deletePic(e) {
|
|
209
|
+
const index = e.detail.index;
|
|
210
|
+
const files = this.data.files;
|
|
211
|
+
const file = files.splice(index, 1);
|
|
212
|
+
this.setData({
|
|
213
|
+
files,
|
|
214
|
+
currentFiles: files,
|
|
215
|
+
});
|
|
216
|
+
this.triggerEvent('delete', { index, item: file[0] });
|
|
217
|
+
},
|
|
218
|
+
},
|
|
209
219
|
});
|
|
@@ -1,45 +1,88 @@
|
|
|
1
1
|
<view class="weui-uploader {{extClass}}">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
</block>
|
|
11
|
-
<block wx:if="{{layout === 'vertical'}}">
|
|
12
|
-
<view class="weui-uploader__label">
|
|
13
|
-
<view class="weui-uploader__title">{{title}}</view>
|
|
14
|
-
<label wx:if="{{true}}" class="weda-formcells__flag">*</label>
|
|
15
|
-
</view>
|
|
16
|
-
<view class="weui-uploader__info" wx:if="{{maxCount > 1}}">{{currentFiles.length}}/{{maxCount}}</view>
|
|
17
|
-
</block>
|
|
2
|
+
<view class="weui-uploader__hd {{layout}}">
|
|
3
|
+
<view class="weda-formcells__label weui-cell">
|
|
4
|
+
<block wx:if="{{layout === 'horizontal'}}">
|
|
5
|
+
<view class="">
|
|
6
|
+
<view class="weui-uploader__title">{{title}}</view>
|
|
7
|
+
<view class="weui-uploader__info" wx:if="{{maxCount > 1}}"
|
|
8
|
+
>{{currentFiles.length}}/{{maxCount}}</view
|
|
9
|
+
>
|
|
18
10
|
</view>
|
|
11
|
+
<label wx:if="{{true}}" class="weda-formcells__flag">*</label>
|
|
12
|
+
</block>
|
|
13
|
+
<block wx:if="{{layout === 'vertical'}}">
|
|
14
|
+
<view class="weui-uploader__label">
|
|
15
|
+
<view class="weui-uploader__title">{{title}}</view>
|
|
16
|
+
<label wx:if="{{true}}" class="weda-formcells__flag">*</label>
|
|
17
|
+
</view>
|
|
18
|
+
<view class="weui-uploader__info" wx:if="{{maxCount > 1}}"
|
|
19
|
+
>{{currentFiles.length}}/{{maxCount}}</view
|
|
20
|
+
>
|
|
21
|
+
</block>
|
|
19
22
|
</view>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
</view>
|
|
24
|
+
<view class="weui-uploader__bd">
|
|
25
|
+
<view class="weui-uploader__files">
|
|
26
|
+
<block wx:for="{{currentFiles}}" wx:key="*this">
|
|
27
|
+
<view
|
|
28
|
+
wx:if="{{item.error}}"
|
|
29
|
+
data-index="{{index}}"
|
|
30
|
+
bindtap="previewImage"
|
|
31
|
+
class="weui-uploader__file weui-uploader__file_status"
|
|
32
|
+
>
|
|
33
|
+
<image
|
|
34
|
+
class="weui-uploader__img"
|
|
35
|
+
src="{{item.url}}"
|
|
36
|
+
mode="aspectFill"
|
|
37
|
+
/>
|
|
38
|
+
<view class="weui-uploader__file-content">
|
|
39
|
+
<icon type="warn" size="23" color="#F43530"></icon>
|
|
40
|
+
</view>
|
|
41
|
+
</view>
|
|
42
|
+
<view
|
|
43
|
+
wx:elif="{{item.loading}}"
|
|
44
|
+
data-index="{{index}}"
|
|
45
|
+
bindtap="previewImage"
|
|
46
|
+
class="weui-uploader__file weui-uploader__file_status"
|
|
47
|
+
>
|
|
48
|
+
<image
|
|
49
|
+
class="weui-uploader__img"
|
|
50
|
+
src="{{item.url}}"
|
|
51
|
+
mode="aspectFill"
|
|
52
|
+
/>
|
|
53
|
+
<view class="weui-uploader__file-content">
|
|
54
|
+
<view class="weui-loading"></view>
|
|
55
|
+
</view>
|
|
39
56
|
</view>
|
|
40
|
-
<view
|
|
41
|
-
|
|
57
|
+
<view
|
|
58
|
+
wx:else
|
|
59
|
+
class="weui-uploader__file"
|
|
60
|
+
data-index="{{index}}"
|
|
61
|
+
bindtap="previewImage"
|
|
62
|
+
>
|
|
63
|
+
<image
|
|
64
|
+
class="weui-uploader__img"
|
|
65
|
+
src="{{item.url}}"
|
|
66
|
+
mode="aspectFill"
|
|
67
|
+
/>
|
|
42
68
|
</view>
|
|
69
|
+
</block>
|
|
70
|
+
</view>
|
|
71
|
+
<view
|
|
72
|
+
wx:if="{{currentFiles.length < maxCount}}"
|
|
73
|
+
class="weui-uploader__input-box"
|
|
74
|
+
hover-class="weui-active"
|
|
75
|
+
>
|
|
76
|
+
<view class="weui-uploader__input" bindtap="chooseImage"></view>
|
|
43
77
|
</view>
|
|
44
|
-
|
|
78
|
+
</view>
|
|
79
|
+
<mp-gallery
|
|
80
|
+
class="gallery"
|
|
81
|
+
hide-on-click="{{true}}"
|
|
82
|
+
show-delete="{{showDelete}}"
|
|
83
|
+
show="{{showPreview}}"
|
|
84
|
+
binddelete="deletePic"
|
|
85
|
+
img-urls="{{previewImageUrls}}"
|
|
86
|
+
current="{{previewCurrent}}"
|
|
87
|
+
></mp-gallery>
|
|
45
88
|
</view>
|
|
@@ -60,7 +60,7 @@ Component({
|
|
|
60
60
|
urls: [],
|
|
61
61
|
cloudFile: [],
|
|
62
62
|
strogeUrls: [],
|
|
63
|
-
singleFlag: false
|
|
63
|
+
singleFlag: false,
|
|
64
64
|
},
|
|
65
65
|
methods: {
|
|
66
66
|
// 批量上传文件前置事件
|
|
@@ -134,8 +134,9 @@ Component({
|
|
|
134
134
|
if (!this.handleBefore(files?.tempFiles)) return;
|
|
135
135
|
const uploadPath = 'weda-uploader';
|
|
136
136
|
const uploadPromise = files.tempFiles.map(async (tempFile) => {
|
|
137
|
-
const cloudPath = `${uploadPath}/${uuid().replaceAll('-', '')}-${
|
|
138
|
-
|
|
137
|
+
const cloudPath = `${uploadPath}/${uuid().replaceAll('-', '')}-${
|
|
138
|
+
tempFile.name
|
|
139
|
+
}`;
|
|
139
140
|
tempFile.percent = '0';
|
|
140
141
|
tempFile.cloudPath = null;
|
|
141
142
|
tempFile.filePath = tempFile?.path || null;
|
|
@@ -260,7 +261,7 @@ Component({
|
|
|
260
261
|
//当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
|
|
261
262
|
if (Array.isArray(value) && !this.data.singleFlag) {
|
|
262
263
|
this.setData({
|
|
263
|
-
urls: value
|
|
264
|
+
urls: value,
|
|
264
265
|
});
|
|
265
266
|
this.data.singleFlag = true;
|
|
266
267
|
}
|