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