Commit 1ecbbddb by 前端

加锁

1 parent e87507e2
......@@ -24,6 +24,7 @@ Vue.component("MessageBox", MessageBox);
Vue.component("wnCanvas", wnCanvas);
Vue.component("UpdateBox", UpdateBox);
uni.$api = api;
uni.$lock = false;
uni.$storage = new Storage();
uni.$throttle = utils.throttle;
uni.$isNetWork = utils.isNetWork;
......
......@@ -170,6 +170,7 @@ export default {
},
/**保存记录*/
saveRecord() {
uni.$lock = true;
const recordUrlList = this.audioInfo.audioList.map((i) => {
return {
status: UPLOAD_STATUS.fail,
......@@ -178,14 +179,15 @@ export default {
});
let recordList = JSON.parse(uni.$storage.get("recordList") || "[]");
recordList = [
...recordList,
{
...this.getParams(),
recordUrlList,
},
...recordList,
];
console.log(recordList, "recordList");
uni.$storage.set("recordList", JSON.stringify(recordList));
uni.$lock = false;
},
//结束接待
stopAudio: utils.throttle(async function (status) {
......
......@@ -7,21 +7,7 @@ let wv, getResult;
import { uploadFile, getOssToken } from "@/utils/ossUploadFile/uploadFile.js";
import config from "@/config.js";
export default {
onLoad() {
// #ifdef APP-PLUS
// wv = plus.webview.create("", "custom-webview", {
// plusrequire: "none", //禁止远程网页使用plus的API,有些使用mui制作的网页可能会监听plus.key,造成关闭页面混乱,可以通过这种方式禁止
// "uni-app": "none", //不加载uni-app渲染层框架,避免样式冲突
// top: uni.getSystemInfoSync().statusBarHeight + 44, //放置在titleNView下方。如果还想在webview上方加个地址栏的什么的,可以继续降低TOP值
// });
// wv.loadURL("/hybrid/html/index.html");
// var currentWebview = this.$scope.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
// currentWebview.append(wv); //一定要append到当前的页面里!!!才能跟随当前页面一起做动画,一起关闭
// setTimeout(function () {
// wv.setStyle({ top: "100%", height: 300 });
// }, 1000); //如果是首页的onload调用时需要延时一下,二级页面无需延时,可直接获取
// // #endif
},
onLoad() {},
mounted() {
var currentWebview = this.$scope.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
setTimeout(function () {
......@@ -42,9 +28,12 @@ export default {
checkRecord() {
uni.$isNetWork().then(async (res) => {
let recordList = JSON.parse(uni.$storage.get("recordList") || "[]");
console.log(recordList, "recordList");
for (let i = 0; i < recordList.length; i++) {
await this.handleRerord(recordList[i]);
try {
await this.handleRerord(recordList[i]);
} catch (error) {
continue;
}
}
});
},
......@@ -64,10 +53,6 @@ export default {
},
/**上传记录*/
async handleRerord(val) {
let recordList = JSON.parse(uni.$storage.get("recordList") || "[]");
let idx = recordList.findIndex(
(item) => item.receptionStartTime == val.receptionStartTime
);
let recordUrlList = val.recordUrlList;
// 上传失败的记录
for (let i of recordUrlList) {
......@@ -93,6 +78,9 @@ export default {
});
i.status = UPLOAD_STATUS.success;
i.file = config.OSS_DOMAIN + "/" + config.FOLDER + filePath;
} else {
this.sendSentry(result.detail.data[0].error);
throw "上传失败";
}
getResult = "";
break;
......@@ -105,12 +93,21 @@ export default {
// }
}
}
//目前处于保存中
if (uni.$lock) {
return;
}
// 判断是否全部上传成功
if (recordUrlList.every((i) => i.status == UPLOAD_STATUS.success)) {
val.recordUrlList = val.recordUrlList.map((i) => i.file);
try {
const res = await uni.$api.commonApi.saveRecCustomer(val);
console.log(res, val);
await uni.$api.commonApi.saveRecCustomer(val).then((res) => {
console.log(res);
});
let recordList = JSON.parse(uni.$storage.get("recordList") || "[]");
let idx = recordList.findIndex(
(item) => item.receptionStartTime == val.receptionStartTime
);
recordList.splice(idx, 1);
uni.$storage.set("recordList", JSON.stringify(recordList));
} catch (err) {
......@@ -118,6 +115,14 @@ export default {
}
}
},
sendSentry(msg) {
const { customerName, phoneNumber, carModel, staffName } =
this.$store.state.user.customerInfo;
const { name } = uni.$storage.get("userInfo");
this.$sendSentry(
`上传失败:手机号-${phoneNumber} 姓名-${customerName} 销售-${staffName} 车型-${carModel} 员工-${name},失败原因-${msg}`
);
},
async checkFileUpload(tempFilePath) {
console.log(tempFilePath);
let attempt = 0;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!