jufubao-base 1.0.443 → 1.0.444-beta2

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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(node *)",
5
+ "Bash(git *)",
6
+ "Bash(echo \"---exit:$?\")",
7
+ "mcp__ide__getDiagnostics"
8
+ ]
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jufubao-base",
3
- "version": "1.0.443",
3
+ "version": "1.0.444-beta2",
4
4
  "private": false,
5
5
  "description": "聚福宝业务组件基础插件包",
6
6
  "main": "index.js",
@@ -64,7 +64,7 @@
64
64
  </view>
65
65
  </view>
66
66
  </view>
67
- <view class="tip">最多可上传6张图片,每张不超过5MB</view>
67
+ <view class="tip">最多可上传5张图片(上传文件格式:JPG/PNG/JPEG/GIF,不超过5MB)</view>
68
68
  </view>
69
69
 
70
70
  <!-- 联系方式 -->
@@ -146,6 +146,10 @@
146
146
  contactInfo: '',
147
147
  isAnonymous: false,
148
148
  contactPlaceholder: "",
149
+ // 图片上传限制:格式、大小(MB)、张数
150
+ imageExts: ["jpg", "png", "jpeg", "gif"],
151
+ imageMaxSize: 50,
152
+ imageMaxCount: 5,
149
153
  }
150
154
  },
151
155
  computed: {
@@ -216,8 +220,8 @@
216
220
  },
217
221
  // 选择图片
218
222
  chooseImage() {
219
- if (this.uploadImages.length >= 6) {
220
- uni.showToast({ title: '最多上传6张图片', icon: 'none' });
223
+ if (this.uploadImages.length >= this.imageMaxCount) {
224
+ uni.showToast({ title: `最多上传${this.imageMaxCount}张图片`, icon: 'none' });
221
225
  return;
222
226
  }
223
227
  uni.chooseImage({
@@ -231,6 +235,8 @@
231
235
  // #ifdef H5
232
236
  file = res.tempFiles[0];
233
237
  // #endif
238
+ // 校验图片格式与大小
239
+ if (!this.checkImageFile(this.getImageFileInfo(res))) return;
234
240
  this.$xdShowLoading({});
235
241
  try {
236
242
  let image = await this.uploadImage(file);
@@ -244,6 +250,43 @@
244
250
  }
245
251
  });
246
252
  },
253
+ /**
254
+ * @description 获取选中图片的信息(H5 与小程序返回值结构不同)
255
+ * @param res {object} chooseImage 成功回调参数
256
+ * @return {object} {name, size, type}
257
+ */
258
+ getImageFileInfo(res = {}) {
259
+ let info = {};
260
+ // #ifdef MP-WEIXIN
261
+ let tempFile = res.tempFiles[0] || {};
262
+ info = { name: tempFile.path || res.tempFilePaths[0], size: tempFile.size };
263
+ // #endif
264
+ // #ifdef H5
265
+ let file = res.tempFiles[0] || {};
266
+ info = { name: file.name, size: file.size, type: file.type };
267
+ // #endif
268
+ return info;
269
+ },
270
+ /**
271
+ * @description 校验图片格式(JPG/PNG/JPEG/GIF)与大小
272
+ * @param info {object} 图片信息 name/size/type
273
+ * @return {boolean} 是否通过校验
274
+ */
275
+ checkImageFile(info = {}) {
276
+ let name = info.name || "";
277
+ let index = name.lastIndexOf(".");
278
+ let ext = (index === -1 ? "" : name.slice(index + 1)).toLowerCase();
279
+ let type = (info.type || "").toLowerCase();
280
+ if (!this.imageExts.includes(ext) && !this.imageExts.some(item => type.endsWith(`/${item}`))) {
281
+ uni.showToast({ title: "图片格式仅支持JPG/PNG/JPEG/GIF", icon: 'none' });
282
+ return false;
283
+ }
284
+ if (info.size > this.imageMaxSize * 1024 * 1024) {
285
+ uni.showToast({ title: `图片大小不能超过${this.imageMaxSize}MB`, icon: 'none' });
286
+ return false;
287
+ }
288
+ return true;
289
+ },
247
290
  // 上传图片到 OSS
248
291
  uploadImage(file) {
249
292
  let fileName = file.name || 'image.png';
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * @description 第三方库
5
- * @param threePackagePath {String} 第三方库所在项目路径存放路径路
6
- * @param packname {String} 包名字
7
- * @returns {string|*}
8
- */
9
- const getPackagePath = (threePackagePath, packname = 'gxd-commands-bussiness')=>{
10
- if(packname === 'gxd-commands-bussiness') {
11
- return `/Users/shiyonggao/Desktop/code/BASE/UNIAPP/xd-commands-bussiness/${threePackagePath}`;
12
- }
13
-
14
- if (packname === 'gxd-uni-library-editx') {
15
- return `/Users/shiyonggao/Desktop/code/BASE/UNIAPP/xd-uni-library-editx/${threePackagePath}`;
16
- }
17
-
18
- };
19
-
20
- module.exports = {
21
- getPackagePath
22
- }