@xtdev/xt-miniprogram-ui 1.0.13 → 1.0.15
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-button/index.js
CHANGED
|
@@ -66,14 +66,14 @@ Component({
|
|
|
66
66
|
*/
|
|
67
67
|
data: {
|
|
68
68
|
iconSizeObj: {
|
|
69
|
-
small:
|
|
70
|
-
normal:
|
|
71
|
-
large:
|
|
69
|
+
small: 32,
|
|
70
|
+
normal: 40,
|
|
71
|
+
large: 48,
|
|
72
72
|
},
|
|
73
73
|
iconRightObj: {
|
|
74
|
-
small:
|
|
75
|
-
normal:
|
|
76
|
-
large:
|
|
74
|
+
small: 4,
|
|
75
|
+
normal: 8,
|
|
76
|
+
large: 16,
|
|
77
77
|
},
|
|
78
78
|
},
|
|
79
79
|
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
bindopensetting="onOpenSetting"
|
|
24
24
|
bindchooseavatar="onChooseAvatar"
|
|
25
25
|
>
|
|
26
|
-
<xt-icon wx:if="{{icon}}" icon="{{icon}}" size="{{iconSizeObj[size]
|
|
26
|
+
<xt-icon wx:if="{{icon}}" icon="{{icon}}" size="{{iconSizeObj[size]}}" style="margin-right: {{iconRightObj[size]}}rpx"></xt-icon>
|
|
27
27
|
<view>
|
|
28
28
|
<slot />
|
|
29
29
|
</view>
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
| custom-upload | 是否自定义上传,true 点击盒子触发upload | `Boolean` |
|
|
36
36
|
| disabled | 是否禁用,禁用时不能删除和上传,可预览 | `Boolean` |
|
|
37
37
|
| sourceType | 照片来源 | ["album", "camera"] |
|
|
38
|
+
| upload-api | 组件库放公网,上传接口api,必传 | {url: 'https://...',fileDir: 'microComponents'} |
|
|
38
39
|
|
|
39
40
|
####Events
|
|
40
41
|
|
|
@@ -42,3 +43,4 @@
|
|
|
42
43
|
| ---------------- | ------------- | ---------------------- |
|
|
43
44
|
| bind:upload | 上传成功后触发,如果customUpload为true则点击上传及触发 | fileList:图片列表, url:当前上传图片地址 |
|
|
44
45
|
| bind:delete | 删除成功后触发 | fileList:图片列表, url:当前删除图片地址,index:当前删除图片索引 |
|
|
46
|
+
| bind:error | 上传失败后触发 | errMsg: 失败原因 |
|
|
@@ -34,6 +34,10 @@ Component({
|
|
|
34
34
|
type: Boolean,
|
|
35
35
|
value: false,
|
|
36
36
|
},
|
|
37
|
+
uploadApi: {
|
|
38
|
+
type: Object,
|
|
39
|
+
value: {},
|
|
40
|
+
},
|
|
37
41
|
},
|
|
38
42
|
|
|
39
43
|
/**
|
|
@@ -69,6 +73,10 @@ Component({
|
|
|
69
73
|
onUploadSuccess(url) {
|
|
70
74
|
this.triggerEvent("upload", { fileList: this.properties.fileList, url });
|
|
71
75
|
},
|
|
76
|
+
// 上传失败
|
|
77
|
+
onUploadError(errMsg) {
|
|
78
|
+
this.triggerEvent("error", { errMsg });
|
|
79
|
+
},
|
|
72
80
|
// 点击上传
|
|
73
81
|
startTakePhoto() {
|
|
74
82
|
const _this = this;
|
|
@@ -76,6 +84,14 @@ Component({
|
|
|
76
84
|
this.triggerEvent("upload", {});
|
|
77
85
|
return;
|
|
78
86
|
}
|
|
87
|
+
const uploadApi = this.properties.uploadApi;
|
|
88
|
+
if (!uploadApi || !uploadApi.url) {
|
|
89
|
+
wx.showToast({
|
|
90
|
+
title: "请传入上传接口",
|
|
91
|
+
icon: "error",
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
79
95
|
wx.chooseMedia({
|
|
80
96
|
count: 1,
|
|
81
97
|
mediaType: ["image"],
|
|
@@ -88,61 +104,65 @@ Component({
|
|
|
88
104
|
_this.uploadImage_v(tempFilePaths);
|
|
89
105
|
},
|
|
90
106
|
fail(error) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
icon: "none",
|
|
94
|
-
});
|
|
107
|
+
_this.onUploadError(error && error.errMsg);
|
|
108
|
+
console.log("-----选取失败", error && error.errMsg);
|
|
95
109
|
},
|
|
96
110
|
});
|
|
97
111
|
},
|
|
98
112
|
// 上传文件
|
|
99
113
|
uploadImage_v(filePaths) {
|
|
114
|
+
const { url, fileDir, ...header } = this.properties.uploadApi;
|
|
100
115
|
let _this = this;
|
|
101
116
|
const { fileList } = _this.properties;
|
|
102
117
|
wx.showLoading("图片上传中");
|
|
103
118
|
utils.newHttp(
|
|
104
|
-
|
|
119
|
+
url,
|
|
105
120
|
"GET",
|
|
106
121
|
{
|
|
107
|
-
dir: "microComponents",
|
|
122
|
+
dir: fileDir || "microComponents",
|
|
108
123
|
},
|
|
124
|
+
header,
|
|
109
125
|
(res) => {
|
|
110
126
|
const { host, signature, accessKeyId, policy, dir } = res.data;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
127
|
+
if (host) {
|
|
128
|
+
let path = filePaths;
|
|
129
|
+
let name = utils.random_string(32) + utils.get_suffix(path);
|
|
130
|
+
wx.uploadFile({
|
|
131
|
+
url: host,
|
|
132
|
+
filePath: filePaths,
|
|
133
|
+
name: "file",
|
|
134
|
+
formData: {
|
|
135
|
+
key: dir + "/" + name,
|
|
136
|
+
policy,
|
|
137
|
+
success_action_status: "200",
|
|
138
|
+
OSSAccessKeyId: accessKeyId,
|
|
139
|
+
signature,
|
|
140
|
+
},
|
|
141
|
+
header: {
|
|
142
|
+
"Content-Type": "multipart/form-data",
|
|
143
|
+
},
|
|
144
|
+
success: (res) => {
|
|
145
|
+
if (res.statusCode == 200) {
|
|
146
|
+
let url = host + dir + "/" + name;
|
|
147
|
+
fileList.push(url);
|
|
148
|
+
_this.onUploadSuccess(url);
|
|
149
|
+
wx.showToast({
|
|
150
|
+
icon: "success",
|
|
151
|
+
title: "上传成功",
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
fail: (err) => {
|
|
156
|
+
_this.onUploadError(err.errMsg || "网络错误,请重试");
|
|
157
|
+
wx.showToast({
|
|
158
|
+
icon: "error",
|
|
159
|
+
title: err.errMsg || "网络错误,请重试",
|
|
160
|
+
});
|
|
161
|
+
},
|
|
143
162
|
});
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
} else {
|
|
164
|
+
_this.onUploadError(res.message);
|
|
165
|
+
}
|
|
146
166
|
}
|
|
147
167
|
);
|
|
148
168
|
},
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
// import md5 from "md5";
|
|
2
2
|
|
|
3
|
-
function newhttpRequest(url, method, params,
|
|
4
|
-
//change - gml 接口url拼接
|
|
5
|
-
var full_url = "https://gateway.tanjiu.cn" + url;
|
|
3
|
+
function newhttpRequest(url, method, params, header, callBack) {
|
|
6
4
|
wx.request({
|
|
7
|
-
url
|
|
5
|
+
url,
|
|
8
6
|
method: method,
|
|
9
7
|
header: {
|
|
10
8
|
"content-type": "application/json",
|
|
11
9
|
// Authorization: md5(pass),
|
|
12
|
-
"ls-client-id": "TANJIUCLOUD_BUSINESS",
|
|
13
10
|
token: "openApi",
|
|
14
|
-
"x-login-session": JSON.stringify({ userId: "2022199" }),
|
|
15
11
|
...header,
|
|
16
12
|
},
|
|
17
13
|
data: params,
|
|
@@ -35,7 +31,7 @@ function newhttpRequest(url, method, params, callBack, header) {
|
|
|
35
31
|
message: err.errMsg || err.msg,
|
|
36
32
|
};
|
|
37
33
|
wx.showToast({
|
|
38
|
-
title:
|
|
34
|
+
title: result.message || "请检查网络是否通畅,稍后重试!",
|
|
39
35
|
icon: "none",
|
|
40
36
|
});
|
|
41
37
|
console.log("err = ", err);
|