hookehuyr

检测图片格式

1 <!-- 1 <!--
2 * @Date: 2022-09-26 14:36:57 2 * @Date: 2022-09-26 14:36:57
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-28 17:56:57 4 + * @LastEditTime: 2022-10-28 18:02:43
5 * @FilePath: /swx/src/pages/activityDetail/index.vue 5 * @FilePath: /swx/src/pages/activityDetail/index.vue
6 * @Description: 活动详情页 6 * @Description: 活动详情页
7 --> 7 -->
...@@ -206,6 +206,7 @@ const start = async () => { ...@@ -206,6 +206,7 @@ const start = async () => {
206 const qrcode = await qrCodeActivityAPI({ i: getCurrentPageParam().id }); 206 const qrcode = await qrCodeActivityAPI({ i: getCurrentPageParam().id });
207 if (qrcode.code) { 207 if (qrcode.code) {
208 qrcode_url = qrcode.data.qrcode_url; 208 qrcode_url = qrcode.data.qrcode_url;
209 + // 图片格式不对可能导致渲染失败
209 base = { 210 base = {
210 width: 1024, 211 width: 1024,
211 height: 1334, 212 height: 1334,
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-28 16:30:35 4 + * @LastEditTime: 2022-10-28 18:07:32
5 * @FilePath: /swx/src/pages/apxUserInfo/index.vue 5 * @FilePath: /swx/src/pages/apxUserInfo/index.vue
6 * @Description: 补充资料 6 * @Description: 补充资料
7 --> 7 -->
...@@ -54,32 +54,42 @@ const afterRead = (event) => { ...@@ -54,32 +54,42 @@ const afterRead = (event) => {
54 mask: true 54 mask: true
55 }); 55 });
56 const { file } = event.detail; 56 const { file } = event.detail;
57 - // 获取上传URL 57 + const fileName = file.url;
58 - wx.uploadFile({ 58 + const ext = fileName.substring(fileName.lastIndexOf('.') + 1);
59 - url: BASE_URL + '/admin/?m=srv&a=upload', 59 + if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "png" || ext == "PNG"){
60 - filePath: file.url, 60 + // 获取上传URL
61 - name: 'file', 61 + wx.uploadFile({
62 - header: { 62 + url: BASE_URL + '/admin/?m=srv&a=upload',
63 - 'content-type': 'multipart/form-data', 63 + filePath: file.url,
64 - }, 64 + name: 'file',
65 - success: function (res) { 65 + header: {
66 - let upload_data = JSON.parse(res.data); 66 + 'content-type': 'multipart/form-data',
67 - wx.hideLoading({ 67 + },
68 - success: () => { 68 + success: function (res) {
69 - if (res.statusCode === 200) { 69 + let upload_data = JSON.parse(res.data);
70 - has_image.value = true; 70 + wx.hideLoading({
71 - uploader_image.value = upload_data.data.src; 71 + success: () => {
72 - } else { 72 + if (res.statusCode === 200) {
73 - wx.showToast({ 73 + has_image.value = true;
74 - icon: 'error', 74 + uploader_image.value = upload_data.data.src;
75 - title: '服务器错误,稍后重试!', 75 + } else {
76 - mask: true 76 + wx.showToast({
77 - }) 77 + icon: 'error',
78 - } 78 + title: '服务器错误,稍后重试!',
79 - }, 79 + mask: true
80 - }); 80 + })
81 - } 81 + }
82 - }); 82 + },
83 + });
84 + }
85 + });
86 + } else {
87 + wx.showToast({
88 + icon: 'error',
89 + title: '请检查图片格式!',
90 + mask: true
91 + })
92 + }
83 } 93 }
84 const removeUploadImage = () => { 94 const removeUploadImage = () => {
85 has_image.value = false; 95 has_image.value = false;
......