Commit fb87ef72 by 胡悦

Merge branch 'v1.0.7' of http://192.168.3.233:8090/glsx/gl_tape into v1.0.7

2 parents 182ccda0 f0896682
...@@ -24,6 +24,7 @@ Vue.component("UpdateBox", UpdateBox); ...@@ -24,6 +24,7 @@ Vue.component("UpdateBox", UpdateBox);
uni.$api = api; uni.$api = api;
uni.$storage = new Storage(); uni.$storage = new Storage();
uni.$throttle = utils.throttle; uni.$throttle = utils.throttle;
uni.$isNetWork = utils.isNetWork;
Vue.config.productionTip = false; Vue.config.productionTip = false;
App.mpType = "app"; App.mpType = "app";
Vue.prototype.$ossDomain = config.OSS_DOMAIN; Vue.prototype.$ossDomain = config.OSS_DOMAIN;
......
...@@ -77,11 +77,6 @@ export default { ...@@ -77,11 +77,6 @@ export default {
this.times = 0; this.times = 0;
this.$refs.tipBox?.close(); this.$refs.tipBox?.close();
}, },
//检查缓存录音
checkVoice() {
const file = uni.$storage.get("storageFile");
if (file) this.uploadVoice(file);
},
getParams() { getParams() {
const { shopMerchantId, phone, sceneType } = uni.$storage.get("userInfo"), const { shopMerchantId, phone, sceneType } = uni.$storage.get("userInfo"),
{ customerName, phoneNumber, salesUuid, carModel, staffName } = { customerName, phoneNumber, salesUuid, carModel, staffName } =
...@@ -112,60 +107,6 @@ export default { ...@@ -112,60 +107,6 @@ export default {
}; };
return params; return params;
}, },
//保存录音记录及其他信息
async uploadVoice(tempFilePath) {
try {
const { shopMerchantId, phone, sceneType } =
uni.$storage.get("userInfo"),
{ customerName, phoneNumber, salesUuid, carModel, staffName } =
this.$store.state.user.customerInfo,
receptionCustomerPaySourceList = this.booksList.map((item) => {
return {
id: item.id,
sourceType: item.id,
sourceUrl: item.imgUrl,
};
}),
{ receptionStartTime, receptionEndTime, endReasonType } =
this.audioInfo,
params = {
carModel,
endReasonType, //原因 1.异常 0.正常
customerName,
phoneNumber,
loginPhone: phone,
salesName: staffName,
salesUuid,
receptionStatus: this.receptionStatus, //接待结果 1.成交 0.战败
recordUrlList: tempFilePath,
receptionStartTime,
receptionEndTime,
receptionCustomerPaySourceList, //1.付款凭证文件路径 2.客户购车发票文件路径 3.客户延保合同文件路径
merchantId: shopMerchantId,
bussinessType: sceneType == 0 ? 1 : 2, // sceneType 0延保 1精品。 bussinessType 1.延保 2.轻改
};
console.log(
customerName,
phoneNumber,
salesUuid,
carModel,
tempFilePath
);
if (customerName && phoneNumber && salesUuid) {
uni.$api.commonApi.saveRecCustomer(params).then((res) => {
console.log(res, params);
});
}
this.setBooks([]);
this.$store.dispatch("clearCustomerInfo");
this.setReceptionStatus(1);
this.setAudioInfo({ endReasonType: 0, audioStatus: "finish" });
uni.$storage.set("storageFile", "");
} catch (error) {
this.$store.dispatch("clearCustomerInfo");
console.log(error);
}
},
//开始录音 //开始录音
async startAudio() { async startAudio() {
if (this.audioInfo.audioStatus == "start") return; if (this.audioInfo.audioStatus == "start") return;
...@@ -194,41 +135,34 @@ export default { ...@@ -194,41 +135,34 @@ export default {
}); });
return; return;
} }
// const isContinue = this.hasErrorFile(); const saveResult = await uni.saveFile({
// if (isContinue) { tempFilePath: res.tempFilePath,
// this.handleErrorFile(res.tempFilePath); }); // 保存文件到本地
// if (this.audioInfo.audioStatus == 'end') { //删除默认文件
// this.saveRecord(); uni.removeSavedFile({
// } filePath: res.tempFilePath,
// return; complete: function (res) {
// } console.log(res);
const result = await this.checkUploadFile(res.tempFilePath); },
if (result instanceof Error) { });
console.error("上传失败:", result); this.handleSave(saveResult);
const { customerName, phoneNumber, salesUuid, carModel, staffName } =
this.$store.state.user.customerInfo;
const { name } = uni.$storage.get("userInfo");
this.$sendSentry(
`重试多次失败:手机号-${phoneNumber} 姓名-${customerName} 销售-${staffName} 车型-${carModel} 员工-${name},失败原因-${result}`
);
// this.handleErrorFile(res.tempFilePath, UPLOAD_STATUS.fail);
// return;
} else {
// this.handleErrorFile(result, UPLOAD_STATUS.success);
}
const storageFile = [...this.audioInfo.audioList, result];
uni.$storage.set("storageFile", storageFile);
this.setAudioInfo({ audioList: storageFile });
if (this.audioInfo.audioStatus == "start") {
return;
}
this.uploadVoice(storageFile);
}); });
}, },
handleSave(file) {
if (this.audioInfo.audioStatus == "end") {
this.saveRecord();
this.setBooks([]);
this.$store.dispatch("clearCustomerInfo");
this.setReceptionStatus(1);
this.setAudioInfo({ endReasonType: 0, audioStatus: "finish" });
} else {
const audioList = [...this.audioInfo.audioList, file];
this.setAudioInfo({ audioList });
}
},
/**保存记录*/ /**保存记录*/
saveRecord() { saveRecord() {
const recordUrlList = JSON.parse(uni.$storage.get("errorFile") || "[]"); const recordUrlList = this.audioInfo.audioList;
let recordList = JSON.parse(uni.$storage.get("recordList") || "[]"); let recordList = JSON.parse(uni.$storage.get("recordList") || "[]");
recordList = [ recordList = [
...recordList, ...recordList,
...@@ -239,67 +173,6 @@ export default { ...@@ -239,67 +173,6 @@ export default {
]; ];
uni.$storage.set("recordList", JSON.stringify(recordList)); uni.$storage.set("recordList", JSON.stringify(recordList));
}, },
/**是否存在错误文件*/
hasErrorFile() {
const fileList = JSON.parse(uni.$storage.get("errorFile") || "[]");
const errorFileList = fileList.filter(
(item) => item.status == UPLOAD_STATUS.fail
);
return errorFileList.length > 0;
},
/**处理失败的文件*/
handleErrorFile(file, status) {
const errorFileList = JSON.parse(uni.$storage.get("errorFile") || "[]");
const errorFile = [...errorFileList, { file, status }];
uni.$storage.set("errorFile", JSON.stringify(errorFile));
},
/**上传记录*/
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) {
if (i.status == UPLOAD_STATUS.fail) {
const result = await this.checkUploadFile(i.file);
if (!(result instanceof Error)) {
i.status = UPLOAD_STATUS.success;
}
}
}
// 判断是否全部上传成功
if (recordUrlList.every((i) => i.status == UPLOAD_STATUS.success)) {
recordList.splice(idx, 1);
val.recordUrlList = val.recordUrlList.map((i) => i.file);
this.uploadVoice(val);
uni.$storage.set("recordList", JSON.stringify(recordList));
}
},
async checkUploadFile(tempFilePath) {
let attempt = 0;
let errorMsg = "";
while (attempt < 5) {
try {
const result = await upload(tempFilePath);
// 上传成功
return result;
} catch (error) {
if (attempt == 0) {
this.$sendSentry(`第一次上传失败:文件${tempFilePath}`);
}
errorMsg = error;
attempt++;
// 等待一段时间后重试
await new Promise((resolve) => setTimeout(resolve, 3000)); // 3秒后重试
}
}
// 达到最大尝试次数后,如果上传仍然失败,可以进行相应的处理
console.error("上传失败,达到最大尝试次数");
// 返回一个错误或者进行其他操作
return new Error(errorMsg);
},
//结束接待 //结束接待
stopAudio: utils.throttle(async function (status) { stopAudio: utils.throttle(async function (status) {
// const result = await this.$permision.requestAndroidPermission( // const result = await this.$permision.requestAndroidPermission(
...@@ -322,12 +195,7 @@ export default { ...@@ -322,12 +195,7 @@ export default {
if (!status) { if (!status) {
uni.showLoading({ uni.showLoading({
mask: true, mask: true,
title: "处理中请稍后...",
}); });
// setTimeout(() => {
// uni.hideLoading();
// clearInterval(finish_timer);
// }, 1000 * 60);
} }
this.times = 0; this.times = 0;
clearInterval(this.timer); clearInterval(this.timer);
......
const UPLOAD_STATUS = {
// 上传状态
success: 1,
fail: 2,
};
import upload from "@/utils/ossUploadFile/uploadFile.js";
import utils from "@/utils/utils.js";
export default {
mounted() {
// this.checkRecord();
// setInterval(() => {
// this.checkRecord();
// }, 1000 * 60 * 10);
},
methods: {
checkRecord() {
utils.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]);
}
});
},
/**上传记录*/
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) {
if (i.status == UPLOAD_STATUS.fail) {
const filePath = i.file;
console.log(filePath, "filePath");
const result = await this.checkFileUpload(filePath);
if (!(result instanceof Error)) {
i.status = UPLOAD_STATUS.success;
i.file = result;
}
}
}
// 判断是否全部上传成功
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);
recordList.splice(idx, 1);
uni.$storage.set("recordList", JSON.stringify(recordList));
} catch (err) {
Promise.reject(error);
}
}
},
async checkFileUpload(tempFilePath) {
console.log(tempFilePath);
let attempt = 0;
let errorMsg = "";
while (attempt < 2) {
try {
const result = await upload(tempFilePath);
// 上传成功
return result;
} catch (error) {
errorMsg = error;
attempt++;
// 等待一段时间后重试
await new Promise((resolve) => setTimeout(resolve, 3000)); // 3秒后重试
}
}
// 达到最大尝试次数后,如果上传仍然失败,可以进行相应的处理
console.error("上传失败,达到最大尝试次数");
// 返回一个错误或者进行其他操作
return new Error(errorMsg);
},
},
};
...@@ -16,8 +16,9 @@ export const STORAGE_OBJECTkEY = { ...@@ -16,8 +16,9 @@ export const STORAGE_OBJECTkEY = {
noSignInUuid: "noSignInUuid", noSignInUuid: "noSignInUuid",
noviceGuideStatus: "noviceGuideStatus", noviceGuideStatus: "noviceGuideStatus",
accountLength: "accountLength", accountLength: "accountLength",
carBrandList:'carBrandList', carBrandList: "carBrandList",
employeeList:'employeeList' employeeList: "employeeList",
recordList: "recordList",
}; };
// export const IMG_VERSION = async () => { // export const IMG_VERSION = async () => {
......
...@@ -76,10 +76,25 @@ var throttle = function (fn, delay) { ...@@ -76,10 +76,25 @@ var throttle = function (fn, delay) {
}, delay); }, delay);
}; };
}; };
//检查是否有网络
var isNetWork = function () {
return new Promise((resolve, reject) => {
uni.getNetworkType({
complete: function (res) {
if (res.networkType == "none") {
reject();
} else {
resolve();
}
},
});
});
};
export default { export default {
convertDateTimeFormat, convertDateTimeFormat,
deepClone, deepClone,
accDiv, accDiv,
debounce, debounce,
throttle, throttle,
isNetWork,
}; };
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!