Просмотр исходного кода

上传文件处添加package随机参数

wzz 1 месяц назад
Родитель
Сommit
ccbb65b2bb
1 измененных файлов с 8 добавлено и 6 удалено
  1. 8 6
      src/pages/selfCenter/upload.vue

+ 8 - 6
src/pages/selfCenter/upload.vue

@@ -31,6 +31,7 @@
 
 <script>
 import { request, uploadImage, currentOpenId } from '@/utils/request.js'
+import md5 from '@/common/md5.js'
 
 const MAX_COUNT = 9
 
@@ -73,10 +74,13 @@ export default {
       if (this.uploading || !this.images.length) return
       this.uploading = true
       uni.showLoading({ title: '上传中...', mask: true })
+      // package_sign:这一批(点一次"上传"按钮)的所有图片共用同一个值,用当前时间戳做 md5,
+      // 每次点击上传都会生成一个新的值,只在 report&action=add 登记这一步带上
+      const packageSign = md5(Date.now().toString())
       const failedPaths = []
       let successCount = 0
       for (const filePath of this.images) {
-        const ok = await this.uploadOne(filePath)
+        const ok = await this.uploadOne(filePath, packageSign)
         if (ok) {
           successCount++
         } else {
@@ -89,11 +93,9 @@ export default {
       this.images = failedPaths
       this.showResult(successCount, failedPaths.length)
     },
-    // 两步:1) uni.uploadFile 传图换 attach_id  2) 带着 openId + attach_id 调 report&action=add 登记
-    async uploadOne(filePath) {
+    // 两步:1) uni.uploadFile 传图换 attach_id  2) 带着 openId + attach_id + package_sign 调 report&action=add 登记
+    async uploadOne(filePath, packageSign) {
       const uploadRes = await uploadImage(filePath)
-      // TODO-DIAG: 确认第一步返回结构(attach_id 在哪个字段)的临时日志,确认后删除
-      console.log('UPLOAD_DEBUG step1 result=', JSON.stringify(uploadRes))
       if (uploadRes.notJson || uploadRes.code !== 200) return false
       const data = uploadRes.data
       const attachId = data && (data.id || data.attach_id)
@@ -101,8 +103,8 @@ export default {
       const addRes = await request('report', 'add', {
         openId: currentOpenId(),
         attach_id: attachId,
+        package_sign: packageSign,
       })
-      console.log('UPLOAD_DEBUG step2 result=', JSON.stringify(addRes))
       return addRes.code === 200
     },
     showResult(successCount, failCount) {