Ver código fonte

修改图片校验问题

ymz 4 meses atrás
pai
commit
fee8c1c3d5

+ 2 - 1
env/.env.development

@@ -2,11 +2,12 @@ NODE_ENV=development
 
 # pre环境
 # VITE_APP_URL=https://mic.freerr.cn
+VITE_APP_URL=http://10.144.62.235:9999
 # 生产
 # VITE_APP_URL=https://cnbg.yaoyi.net
 # VITE_APP_URL=https://mic.cnbg.com.cn
 # 中生测试
-VITE_APP_URL=https://mic-t.cnbg.com.cn
+# VITE_APP_URL=https://mic-t.cnbg.com.cn
 
 
 

+ 18 - 1
src/components/uploadImg/index.vue

@@ -46,7 +46,9 @@ const beforeUploadImg = () => {
       }
       uploadImg()
     },
-    fail: function (res) {}
+    fail: function (res) {
+      console.log('res', res)
+    }
   })
 }
 
@@ -83,6 +85,8 @@ const uploadImg = async () => {
     sizeType: ['original', 'compressed'],
     sourceType: sourceType.value,
     async success(res: any) {
+      console.log('res', res)
+
       let tempFiles = res.tempFiles
       // 当前相片来源为拍照
       if (sourceType.value[0] === 'camera') {
@@ -92,6 +96,19 @@ const uploadImg = async () => {
           tempFiles[0].path = path
         }
       }
+
+      let flag = res.tempFilePaths.every((item: string) => {
+        return item.includes('.jpg') || item.includes('.jpeg') || item.includes('.png')
+      })
+      if (!flag) {
+        uni.showToast({
+          title: '暂不支持该格式照片,请更换为png或jpg格式',
+          icon: 'none',
+          duration: 3000
+        })
+        return
+      }
+
       // 保存上传成功的数据
       const imageValue: imgType[] = []
       // 使用map而不是forEach,因为map会返回一个Promise数组

+ 2 - 2
src/pages-sub-task/task/components/imgCom.vue

@@ -31,7 +31,7 @@
 </template>
 
 <script setup lang="ts">
-import { ref, unref, onMounted, watch } from 'vue'
+import { ref, unref, watch } from 'vue'
 import uploadImgCom from '@/components/uploadImg/index.vue'
 
 const emmits = defineEmits(['update:imgValue'])
@@ -51,7 +51,7 @@ const imgList = ref<imgType[]>([])
 
 watch(
   () => props.imgValue,
-  (newVal, oldVal) => {
+  () => {
     if (props?.imgValue) {
       let str = props?.imgValue.split(',')
       imgList.value = str.map((item) => {