@xtdev/xt-miniprogram-ui 1.0.15 → 1.0.16
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/libs/xt-dialog/README.md
CHANGED
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
<img src="https://img.tanjiu.cn/home/X2bAjz2FQc6mNewfhbNBQfHm6zTmfYzd.png" alt="输入样式" style="zoom:50%;" />
|
|
74
74
|
|
|
75
75
|
```html
|
|
76
|
-
<xt-dialog type="inputText" show="{{showInputDialog}}" title="标题标题标题" message="" placeholder="请输入内容" confirmButtonText="确定" showCancelButton="{{true}}" cancelButtonText="取消" bind:
|
|
76
|
+
<xt-dialog type="inputText" show="{{showInputDialog}}" title="标题标题标题" message="" placeholder="请输入内容" confirmButtonText="确定" showCancelButton="{{true}}" cancelButtonText="取消" bind:confirm="onInputConfirm" bind:cancel="onInputCancel"></xt-dialog>
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
### 5 选择器样式
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
<img src="https://img.tanjiu.cn/home/yKrCY5MnGFS3FcjJ6pJRz5fXmJEHrSay.png" alt="选择器样式" style="zoom:50%;" />
|
|
82
82
|
|
|
83
83
|
```html
|
|
84
|
-
<xt-dialog type="choose" show="{{true}}" title="标题标题标题" chooiceItems="{{chooiceItems}}" confirmButtonText="确定" showCancelButton="{{true}}" cancelButtonText="取消" bind:
|
|
84
|
+
<xt-dialog type="choose" show="{{true}}" title="标题标题标题" chooiceItems="{{chooiceItems}}" confirmButtonText="确定" showCancelButton="{{true}}" cancelButtonText="取消" bind:confirm="onChooseConfirm" bind:cancel="onChooseCancel"></xt-dialog>
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
#### 1)常规情况下的 chooiceItems 参数
|
|
@@ -142,7 +142,12 @@ chooiceItems:[
|
|
|
142
142
|
| label | 选项的文本描述 | String |
|
|
143
143
|
| remark | 选项的辅助信息 | String |
|
|
144
144
|
|
|
145
|
+
### Events
|
|
145
146
|
|
|
147
|
+
| 事件 | 说明 | 回调参数 |
|
|
148
|
+
| ------------ | ------------------ | ------------ |
|
|
149
|
+
| bind:confirm | 点击确认按钮时触发 | event.detail |
|
|
150
|
+
| bind:ccancel | 点击取消按钮时触发 | - |
|
|
146
151
|
|
|
147
152
|
|
|
148
153
|
|
package/libs/xt-dialog/index.js
CHANGED
|
@@ -103,7 +103,7 @@ Component({
|
|
|
103
103
|
}
|
|
104
104
|
// 输入样式
|
|
105
105
|
if(confirmtype == 'inputDialog'){
|
|
106
|
-
this.triggerEvent('
|
|
106
|
+
this.triggerEvent('confirm', this.data.inpVal)
|
|
107
107
|
}
|
|
108
108
|
// 选择样式
|
|
109
109
|
if(confirmtype == 'chooseDialog'){
|
|
@@ -115,7 +115,7 @@ Component({
|
|
|
115
115
|
})
|
|
116
116
|
return
|
|
117
117
|
}
|
|
118
|
-
this.triggerEvent('
|
|
118
|
+
this.triggerEvent('confirm', this.data.curChoosedItemVal)
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
121
|
// 点击取消按钮
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
|
|
27
27
|
####xt-uploader props
|
|
28
28
|
|
|
29
|
-
| 参数
|
|
30
|
-
| ----------- | ----------- | ---------- |
|
|
31
|
-
| fileList | 图片列表,必传,受控组件 |
|
|
32
|
-
| title | 表单标题 |
|
|
33
|
-
| max |
|
|
29
|
+
| 参数 | 说明 | 类型 | 默认值
|
|
30
|
+
| ----------- | ----------- | ---------- | -------- |
|
|
31
|
+
| fileList | 图片列表,必传,受控组件 | Array<String> | `[]`
|
|
32
|
+
| title | 表单标题 | string |
|
|
33
|
+
| max | 上传最大值,每次可选照片数,默认为9 | number | 9
|
|
34
34
|
| upload-desc | 上传文案说明 | `String` |
|
|
35
|
-
| custom-upload | 是否自定义上传,true 点击盒子触发upload | `
|
|
36
|
-
| disabled | 是否禁用,禁用时不能删除和上传,可预览 | `
|
|
37
|
-
| sourceType | 照片来源 | ["album", "camera"]
|
|
35
|
+
| custom-upload | 是否自定义上传,true 点击盒子触发upload | boolean | `false`
|
|
36
|
+
| disabled | 是否禁用,禁用时不能删除和上传,可预览 | boolean | `false`
|
|
37
|
+
| sourceType | 照片来源 | `Array<String>` | ["album", "camera"]
|
|
38
38
|
| upload-api | 组件库放公网,上传接口api,必传 | {url: 'https://...',fileDir: 'microComponents'} |
|
|
39
39
|
|
|
40
40
|
####Events
|
|
@@ -24,7 +24,7 @@ Component({
|
|
|
24
24
|
// ["album", "camera"]
|
|
25
25
|
sourceType: {
|
|
26
26
|
type: Array,
|
|
27
|
-
value: ["camera"],
|
|
27
|
+
value: ["album", "camera"],
|
|
28
28
|
},
|
|
29
29
|
customUpload: {
|
|
30
30
|
type: Boolean,
|
|
@@ -70,8 +70,8 @@ Component({
|
|
|
70
70
|
});
|
|
71
71
|
},
|
|
72
72
|
// 上传成功
|
|
73
|
-
onUploadSuccess(url) {
|
|
74
|
-
this.triggerEvent("upload", { fileList:
|
|
73
|
+
onUploadSuccess(files, url) {
|
|
74
|
+
this.triggerEvent("upload", { fileList: files, url });
|
|
75
75
|
},
|
|
76
76
|
// 上传失败
|
|
77
77
|
onUploadError(errMsg) {
|
|
@@ -80,11 +80,12 @@ Component({
|
|
|
80
80
|
// 点击上传
|
|
81
81
|
startTakePhoto() {
|
|
82
82
|
const _this = this;
|
|
83
|
-
|
|
83
|
+
const { customUpload, uploadApi, max, sourceType, fileList } =
|
|
84
|
+
this.properties;
|
|
85
|
+
if (customUpload) {
|
|
84
86
|
this.triggerEvent("upload", {});
|
|
85
87
|
return;
|
|
86
88
|
}
|
|
87
|
-
const uploadApi = this.properties.uploadApi;
|
|
88
89
|
if (!uploadApi || !uploadApi.url) {
|
|
89
90
|
wx.showToast({
|
|
90
91
|
title: "请传入上传接口",
|
|
@@ -93,15 +94,39 @@ Component({
|
|
|
93
94
|
return;
|
|
94
95
|
}
|
|
95
96
|
wx.chooseMedia({
|
|
96
|
-
count:
|
|
97
|
+
count: max - fileList.length,
|
|
97
98
|
mediaType: ["image"],
|
|
98
99
|
sizeType: ["compressed"],
|
|
99
|
-
sourceType
|
|
100
|
+
sourceType,
|
|
100
101
|
success(res) {
|
|
101
102
|
console.log(res, "0000");
|
|
102
103
|
// tempFilePath可以作为img标签的src属性显示图片
|
|
103
|
-
const tempFilePaths = res.tempFiles
|
|
104
|
-
|
|
104
|
+
const tempFilePaths = res.tempFiles;
|
|
105
|
+
if (Array.isArray(tempFilePaths) && tempFilePaths.length) {
|
|
106
|
+
Promise.allSettled(
|
|
107
|
+
tempFilePaths.map((temp) =>
|
|
108
|
+
_this.uploadImage_v(temp.tempFilePath)
|
|
109
|
+
)
|
|
110
|
+
).then((uploadRes) => {
|
|
111
|
+
wx.hideLoading();
|
|
112
|
+
console.log("----uploadRes", uploadRes);
|
|
113
|
+
// 上传成功
|
|
114
|
+
const successUrls = uploadRes
|
|
115
|
+
.filter((result) => result.status == "fulfilled")
|
|
116
|
+
.map((result) => result.value);
|
|
117
|
+
if (successUrls.length) {
|
|
118
|
+
const files = fileList.concat(successUrls);
|
|
119
|
+
_this.onUploadSuccess(files, successUrls);
|
|
120
|
+
}
|
|
121
|
+
// 上传失败
|
|
122
|
+
const errorList = uploadRes.filter(
|
|
123
|
+
(result) => result.status == "rejected"
|
|
124
|
+
);
|
|
125
|
+
if (errorList.length) {
|
|
126
|
+
_this.onUploadError(errorList[0].value);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
105
130
|
},
|
|
106
131
|
fail(error) {
|
|
107
132
|
_this.onUploadError(error && error.errMsg);
|
|
@@ -111,20 +136,19 @@ Component({
|
|
|
111
136
|
},
|
|
112
137
|
// 上传文件
|
|
113
138
|
uploadImage_v(filePaths) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (host) {
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
const { url, fileDir, ...header } = this.properties.uploadApi;
|
|
141
|
+
wx.showLoading("上传中");
|
|
142
|
+
utils.newHttp(
|
|
143
|
+
url,
|
|
144
|
+
"GET",
|
|
145
|
+
{
|
|
146
|
+
dir: fileDir || "microComponents",
|
|
147
|
+
},
|
|
148
|
+
header,
|
|
149
|
+
(res) => {
|
|
150
|
+
const { host, signature, accessKeyId, policy, dir } = res.data;
|
|
151
|
+
if (host) {
|
|
128
152
|
let path = filePaths;
|
|
129
153
|
let name = utils.random_string(32) + utils.get_suffix(path);
|
|
130
154
|
wx.uploadFile({
|
|
@@ -144,27 +168,31 @@ Component({
|
|
|
144
168
|
success: (res) => {
|
|
145
169
|
if (res.statusCode == 200) {
|
|
146
170
|
let url = host + dir + "/" + name;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
171
|
+
resolve(url);
|
|
172
|
+
// fileList.push(url);
|
|
173
|
+
// _this.onUploadSuccess(url);
|
|
174
|
+
// wx.showToast({
|
|
175
|
+
// icon: "success",
|
|
176
|
+
// title: "上传成功",
|
|
177
|
+
// });
|
|
153
178
|
}
|
|
154
179
|
},
|
|
155
180
|
fail: (err) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
181
|
+
reject(err.errMsg || "网络错误,请重试");
|
|
182
|
+
// _this.onUploadError(err.errMsg || "网络错误,请重试");
|
|
183
|
+
// wx.showToast({
|
|
184
|
+
// icon: "error",
|
|
185
|
+
// title: err.errMsg || "网络错误,请重试",
|
|
186
|
+
// });
|
|
161
187
|
},
|
|
162
188
|
});
|
|
163
|
-
|
|
164
|
-
|
|
189
|
+
} else {
|
|
190
|
+
reject(res.message);
|
|
191
|
+
// _this.onUploadError(res.message);
|
|
192
|
+
}
|
|
165
193
|
}
|
|
166
|
-
|
|
167
|
-
);
|
|
194
|
+
);
|
|
195
|
+
});
|
|
168
196
|
},
|
|
169
197
|
},
|
|
170
198
|
});
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
justify-content : center;
|
|
32
32
|
align-items : center;
|
|
33
33
|
background-color: #F5F5F5;
|
|
34
|
-
margin-bottom :
|
|
34
|
+
margin-bottom : 16rpx;
|
|
35
|
+
flex-shrink: 0;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
.file_item:not(:last-child) {
|
|
38
|
-
margin-right:
|
|
39
|
+
margin-right: 16rpx;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
.camera_icon {
|