@xtdev/xt-miniprogram-ui 1.0.13 → 1.0.14

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.
@@ -66,14 +66,14 @@ Component({
66
66
  */
67
67
  data: {
68
68
  iconSizeObj: {
69
- small: { main: 40, secondary: 32 },
70
- normal: { main: 48, secondary: 40 },
71
- large: { main: 48, secondary: 48 },
69
+ small: 32,
70
+ normal: 40,
71
+ large: 48,
72
72
  },
73
73
  iconRightObj: {
74
- small: { main: 8, secondary: 4 },
75
- normal: { main: 16, secondary: 8 },
76
- large: { main: 16, secondary: 16 },
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][type]}}" style="margin-right: {{iconRightObj[size][type]}}rpx"></xt-icon>
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>
@@ -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:inputConfirm="onInputConfirm" bind:cancel="onInputCancel"></xt-dialog>
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:chooseConfirm="onChooseConfirm" bind:cancel="onChooseCancel"></xt-dialog>
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
 
@@ -103,7 +103,7 @@ Component({
103
103
  }
104
104
  // 输入样式
105
105
  if(confirmtype == 'inputDialog'){
106
- this.triggerEvent('inputConfirm', this.data.inpVal)
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('chooseConfirm', this.data.curChoosedItemVal)
118
+ this.triggerEvent('confirm', this.data.curChoosedItemVal)
119
119
  }
120
120
  },
121
121
  // 点击取消按钮
@@ -26,15 +26,16 @@
26
26
 
27
27
  ####xt-uploader props
28
28
 
29
- | 参数 | 说明 | 类型 |
30
- | ----------- | ----------- | ---------- |
31
- | fileList | 图片列表,必传,受控组件 | `Array<String>` |
32
- | title | 表单标题 | `String` |
33
- | max | 上传最大值,默认为9 | `Number` |
29
+ | 参数 | 说明 | 类型 | 默认值
30
+ | ----------- | ----------- | ---------- | -------- |
31
+ | fileList | 图片列表,必传,受控组件 | Array<String> | `[]`
32
+ | title | 表单标题 | string |
33
+ | max | 上传最大值,每次可选照片数,默认为9 | number | 9
34
34
  | upload-desc | 上传文案说明 | `String` |
35
- | custom-upload | 是否自定义上传,true 点击盒子触发upload | `Boolean` |
36
- | disabled | 是否禁用,禁用时不能删除和上传,可预览 | `Boolean` |
37
- | sourceType | 照片来源 | ["album", "camera"] |
35
+ | custom-upload | 是否自定义上传,true 点击盒子触发upload | boolean | `false`
36
+ | disabled | 是否禁用,禁用时不能删除和上传,可预览 | boolean | `false`
37
+ | sourceType | 照片来源 | `Array<String>` | ["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: 失败原因 |
@@ -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,
@@ -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
  /**
@@ -66,85 +70,129 @@ Component({
66
70
  });
67
71
  },
68
72
  // 上传成功
69
- onUploadSuccess(url) {
70
- this.triggerEvent("upload", { fileList: this.properties.fileList, url });
73
+ onUploadSuccess(files, url) {
74
+ this.triggerEvent("upload", { fileList: files, url });
75
+ },
76
+ // 上传失败
77
+ onUploadError(errMsg) {
78
+ this.triggerEvent("error", { errMsg });
71
79
  },
72
80
  // 点击上传
73
81
  startTakePhoto() {
74
82
  const _this = this;
75
- if (this.properties.customUpload) {
83
+ const { customUpload, uploadApi, max, sourceType, fileList } =
84
+ this.properties;
85
+ if (customUpload) {
76
86
  this.triggerEvent("upload", {});
77
87
  return;
78
88
  }
89
+ if (!uploadApi || !uploadApi.url) {
90
+ wx.showToast({
91
+ title: "请传入上传接口",
92
+ icon: "error",
93
+ });
94
+ return;
95
+ }
79
96
  wx.chooseMedia({
80
- count: 1,
97
+ count: max - fileList.length,
81
98
  mediaType: ["image"],
82
99
  sizeType: ["compressed"],
83
- sourceType: this.properties.sourceType,
100
+ sourceType,
84
101
  success(res) {
85
102
  console.log(res, "0000");
86
103
  // tempFilePath可以作为img标签的src属性显示图片
87
- const tempFilePaths = res.tempFiles[0].tempFilePath;
88
- _this.uploadImage_v(tempFilePaths);
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
+ }
89
130
  },
90
131
  fail(error) {
91
- wx.showToast({
92
- title: error && error.errMsg,
93
- icon: "none",
94
- });
132
+ _this.onUploadError(error && error.errMsg);
133
+ console.log("-----选取失败", error && error.errMsg);
95
134
  },
96
135
  });
97
136
  },
98
137
  // 上传文件
99
138
  uploadImage_v(filePaths) {
100
- let _this = this;
101
- const { fileList } = _this.properties;
102
- wx.showLoading("图片上传中");
103
- utils.newHttp(
104
- "/core/file/oss/miniProgramPolicy",
105
- "GET",
106
- {
107
- dir: "microComponents",
108
- },
109
- (res) => {
110
- const { host, signature, accessKeyId, policy, dir } = res.data;
111
- let path = filePaths;
112
- let name = utils.random_string(32) + utils.get_suffix(path);
113
- wx.uploadFile({
114
- url: host,
115
- filePath: filePaths,
116
- name: "file",
117
- formData: {
118
- key: dir + "/" + name,
119
- policy,
120
- success_action_status: "200",
121
- OSSAccessKeyId: accessKeyId,
122
- signature,
123
- },
124
- header: {
125
- "Content-Type": "multipart/form-data",
126
- "wow-token": "c9fbecb5fdeecb78e8745db9225d88e1",
127
- },
128
- success: (res) => {
129
- if (res.statusCode == 200) {
130
- let url = host + dir + "/" + name;
131
- fileList.push(url);
132
- _this.onUploadSuccess(url);
133
- wx.showToast({
134
- icon: "success",
135
- title: "上传成功",
136
- });
137
- }
138
- },
139
- fail: (err) => {
140
- wx.showToast({
141
- icon: "error",
142
- title: err.errMsg || "网络错误,请重试",
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) {
152
+ let path = filePaths;
153
+ let name = utils.random_string(32) + utils.get_suffix(path);
154
+ wx.uploadFile({
155
+ url: host,
156
+ filePath: filePaths,
157
+ name: "file",
158
+ formData: {
159
+ key: dir + "/" + name,
160
+ policy,
161
+ success_action_status: "200",
162
+ OSSAccessKeyId: accessKeyId,
163
+ signature,
164
+ },
165
+ header: {
166
+ "Content-Type": "multipart/form-data",
167
+ },
168
+ success: (res) => {
169
+ if (res.statusCode == 200) {
170
+ let url = host + dir + "/" + name;
171
+ resolve(url);
172
+ // fileList.push(url);
173
+ // _this.onUploadSuccess(url);
174
+ // wx.showToast({
175
+ // icon: "success",
176
+ // title: "上传成功",
177
+ // });
178
+ }
179
+ },
180
+ fail: (err) => {
181
+ reject(err.errMsg || "网络错误,请重试");
182
+ // _this.onUploadError(err.errMsg || "网络错误,请重试");
183
+ // wx.showToast({
184
+ // icon: "error",
185
+ // title: err.errMsg || "网络错误,请重试",
186
+ // });
187
+ },
143
188
  });
144
- },
145
- });
146
- }
147
- );
189
+ } else {
190
+ reject(res.message);
191
+ // _this.onUploadError(res.message);
192
+ }
193
+ }
194
+ );
195
+ });
148
196
  },
149
197
  },
150
198
  });
@@ -31,11 +31,12 @@
31
31
  justify-content : center;
32
32
  align-items : center;
33
33
  background-color: #F5F5F5;
34
- margin-bottom : 32rpx;
34
+ margin-bottom : 16rpx;
35
+ flex-shrink: 0;
35
36
  }
36
37
 
37
38
  .file_item:not(:last-child) {
38
- margin-right: 32rpx;
39
+ margin-right: 16rpx;
39
40
  }
40
41
 
41
42
  .camera_icon {
@@ -1,17 +1,13 @@
1
1
  // import md5 from "md5";
2
2
 
3
- function newhttpRequest(url, method, params, callBack, header) {
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: full_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: esult.message || "请检查网络是否通畅,稍后重试!",
34
+ title: result.message || "请检查网络是否通畅,稍后重试!",
39
35
  icon: "none",
40
36
  });
41
37
  console.log("err = ", err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtdev/xt-miniprogram-ui",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "miniprogram": "libs",
6
6
  "publishConfig": {