Commit 4eebb2fa by 前端

失败记录缓存本地

1 parent e60e1645
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
<script> <script>
import checkUpdate from "@/uni_modules/uni-upgrade-center-app/utils/check-update-nvue.js"; import checkUpdate from "@/uni_modules/uni-upgrade-center-app/utils/check-update-nvue.js";
import { mapState } from "vuex"; import { mapState } from "vuex";
import storge from "@/mixin/storge";
export default { export default {
mixins: [storge],
computed: { computed: {
...mapState("audio", ["isEnd", "isStart"]), ...mapState("audio", ["isEnd", "isStart"]),
}, },
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
ref="formRef" ref="formRef"
@cancel="cancel" @cancel="cancel"
@confirm="submit" @confirm="submit"
:cancelBtnText="`${step == 1? '取消' : '上一步'}`" :cancelBtnText="`${step == 1 ? '取消' : '上一步'}`"
:confirmBtnText="`${sceneType == 0 ?step == 1? '下一步' : '完成接待': '完成接待'}`" :confirmBtnText="`${
:title="`${step == 1? '客户信息完善' : '结果反馈'}`" sceneType == 0 ? (step == 1 ? '下一步' : '完成接待') : '完成接待'
}`"
:title="`${step == 1 ? '客户信息完善' : '结果反馈'}`"
:popupW="820" :popupW="820"
:maxHeight="820" :maxHeight="820"
:isAutoClose="false" :isAutoClose="false"
...@@ -14,23 +16,24 @@ ...@@ -14,23 +16,24 @@
<view name="content"> <view name="content">
<template v-if="step == 1"> <template v-if="step == 1">
<template v-if="!check(true)"> <template v-if="!check(true)">
<view <view class="error-tip" v-if="errorTip"
class="error-tip" >以下信息不能为空,请完善信息后保存</view
v-if="errorTip" >
>以下信息不能为空,请完善信息后保存</view> <view class="pop-tips" v-else>{{ tips }}</view>
<view
class="pop-tips"
v-else
>{{tips}}</view>
</template> </template>
<view class="form"> <view class="form">
<template v-for="(i, index) in formObject"> <template v-for="(i, index) in formObject">
<view <view class="form-item" :key="index">
class="form-item" <view :class="['label', { required: i.required }]">{{
:key="index" i.label
> }}</view>
<view :class="['label',{required:i.required}]">{{ i.label }}</view> <view
<view :class="['value', { error: showError(i.key) && i.required },{disabled:customerType == 0}]"> :class="[
'value',
{ error: showError(i.key) && i.required },
{ disabled: customerType == 0 },
]"
>
<template v-if="i.type == 'input'"> <template v-if="i.type == 'input'">
<input <input
:type="i.inputType" :type="i.inputType"
...@@ -44,7 +47,10 @@ ...@@ -44,7 +47,10 @@
</template> </template>
<template v-else> <template v-else>
<view <view
:class="['select', `${formData[i.key]? '' : 'placeholder'}`]" :class="[
'select',
`${formData[i.key] ? '' : 'placeholder'}`,
]"
@click="showPopup(i.popKey)" @click="showPopup(i.popKey)"
> >
{{ formData[i.key] || i.placeholder }} {{ formData[i.key] || i.placeholder }}
...@@ -63,14 +69,30 @@ ...@@ -63,14 +69,30 @@
<template v-else> <template v-else>
<view class="pop-tips">请完善本次接待结果</view> <view class="pop-tips">请完善本次接待结果</view>
<view class="choose-box"> <view class="choose-box">
<template v-for="(i,index) in resultList"> <template v-for="(i, index) in resultList">
<view <view
:class="['choose-item', `${i.status == receptionStatus ? i.status == 1 ? 'success' : 'error' : ''}`]" :class="[
'choose-item',
`${
i.status == receptionStatus
? i.status == 1
? 'success'
: 'error'
: ''
}`,
]"
:key="index" :key="index"
@click="chooseResult(i.status)" @click="chooseResult(i.status)"
> >
<view :class="['sprite-icon' , `icon-face-${i.status == receptionStatus ? `${i.icon}-active` : i.icon }`]"></view> <view
{{ i.text}} :class="[
'sprite-icon',
`icon-face-${
i.status == receptionStatus ? `${i.icon}-active` : i.icon
}`,
]"
></view>
{{ i.text }}
</view> </view>
</template> </template>
</view> </view>
...@@ -79,26 +101,23 @@ ...@@ -79,26 +101,23 @@
</MessageBox> </MessageBox>
<car-brands <car-brands
ref="carBrandListVisible" ref="carBrandListVisible"
@select="handleSelect($event,'carBrandListVisible')" @select="handleSelect($event, 'carBrandListVisible')"
/> />
<employee <employee
ref="employeeBoxVisible" ref="employeeBoxVisible"
@select="handleSelect($event,'employeeBoxVisible')" @select="handleSelect($event, 'employeeBoxVisible')"
/> />
<uni-popup <uni-popup ref="successRef" type="message">
ref="successRef"
type="message"
>
<uni-popup-message <uni-popup-message
type="success" type="success"
message="保存成功" message="数据保存成功"
:duration="1500" :duration="1500"
></uni-popup-message> ></uni-popup-message>
</uni-popup> </uni-popup>
</view> </view>
</template> </template>
<script type='text/ecmascript-6'> <script type="text/ecmascript-6">
import Employee from '@/components/Employee.vue' import Employee from '@/components/Employee.vue'
import CarBrands from '@/components/CarBrands.vue' import CarBrands from '@/components/CarBrands.vue'
import { mapMutations } from "vuex"; import { mapMutations } from "vuex";
...@@ -342,7 +361,7 @@ export default { ...@@ -342,7 +361,7 @@ export default {
} }
</script> </script>
<style scoped lang='scss'> <style scoped lang="scss">
.pop-tips { .pop-tips {
background: rgba(44, 102, 247, 0.1); background: rgba(44, 102, 247, 0.1);
color: #2c66f7; color: #2c66f7;
...@@ -461,4 +480,4 @@ export default { ...@@ -461,4 +480,4 @@ export default {
border-color: #f247241a; border-color: #f247241a;
} }
} }
</style>
\ No newline at end of file \ No newline at end of file
</style>
...@@ -14,6 +14,7 @@ const UPLOAD_STATUS = { ...@@ -14,6 +14,7 @@ const UPLOAD_STATUS = {
fail: 2, fail: 2,
}; };
import upload from "@/utils/ossUploadFile/uploadFile.js"; import upload from "@/utils/ossUploadFile/uploadFile.js";
import fileManager from "@/utils/file/FileManager.js";
import { mapMutations, mapState } from "vuex"; import { mapMutations, mapState } from "vuex";
import utils from "@/utils/utils.js"; import utils from "@/utils/utils.js";
export default { export default {
...@@ -27,6 +28,13 @@ export default { ...@@ -27,6 +28,13 @@ export default {
}; };
}, },
mounted() { mounted() {
// this.checkRecord();
// fileManager.writeFile("123.txt", 555);
// fileManager.readFile("file://123.txt").then((res) => {
// // res 读取的文件内容
// console.log(res);
// });
// 获取当前页面栈数组 // 获取当前页面栈数组
const pages = getCurrentPages(); const pages = getCurrentPages();
const currentPage = pages[pages.length - 1]; const currentPage = pages[pages.length - 1];
...@@ -124,43 +132,10 @@ export default { ...@@ -124,43 +132,10 @@ export default {
//保存录音记录及其他信息 //保存录音记录及其他信息
async uploadVoice(tempFilePath) { async uploadVoice(tempFilePath) {
try { try {
const { shopMerchantId, phone, sceneType } = const params = Object.assign(this.getParams(), {
uni.$storage.get("userInfo"), recordUrlList: tempFilePath,
{ customerName, phoneNumber, salesUuid, carModel, staffName } = });
this.$store.state.user.customerInfo, if (params.customerName && params.phoneNumber && params.salesUuid) {
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) => { uni.$api.commonApi.saveRecCustomer(params).then((res) => {
console.log(res, params); console.log(res, params);
}); });
...@@ -195,6 +170,10 @@ export default { ...@@ -195,6 +170,10 @@ export default {
}); });
} }
if (this.audioInfo.audioStatus == "no") { if (this.audioInfo.audioStatus == "no") {
setTimeout(() => {
uni.hideLoading();
}, 2000);
uni.removeSavedFile({ uni.removeSavedFile({
filePath: res.tempFilePath, filePath: res.tempFilePath,
complete: function (res) { complete: function (res) {
...@@ -203,15 +182,14 @@ export default { ...@@ -203,15 +182,14 @@ export default {
}); });
return; return;
} }
// const isContinue = this.hasErrorFile(); const isContinue = this.hasErrorFile();
// if (isContinue) { if (isContinue) {
// this.handleErrorFile(res.tempFilePath); this.handleErrorFile(res.tempFilePath, UPLOAD_STATUS.fail);
// if (this.audioInfo.audioStatus == 'end') { return;
// this.saveRecord(); }
// } //模拟上传失败
// return; const x = Math.random() * 10 > 5 ? "" : "x";
// } const result = await this.checkUploadFile(res.tempFilePath + x);
const result = await this.checkUploadFile(res.tempFilePath);
if (result instanceof Error) { if (result instanceof Error) {
console.error("上传失败:", result); console.error("上传失败:", result);
const { customerName, phoneNumber, salesUuid, carModel, staffName } = const { customerName, phoneNumber, salesUuid, carModel, staffName } =
...@@ -220,11 +198,13 @@ export default { ...@@ -220,11 +198,13 @@ export default {
this.$sendSentry( this.$sendSentry(
`重试多次失败:手机号-${phoneNumber} 姓名-${customerName} 销售-${staffName} 车型-${carModel} 员工-${name},失败原因-${result}` `重试多次失败:手机号-${phoneNumber} 姓名-${customerName} 销售-${staffName} 车型-${carModel} 员工-${name},失败原因-${result}`
); );
const saveResult = await uni.saveFile({
// this.handleErrorFile(res.tempFilePath, UPLOAD_STATUS.fail); tempFilePath: res.tempFilePath,
// return; }); // 保存文件到本地
this.handleErrorFile(saveResult[1].savedFilePath, UPLOAD_STATUS.fail);
return;
} else { } else {
// this.handleErrorFile(result, UPLOAD_STATUS.success); this.handleErrorFile(result, UPLOAD_STATUS.success);
} }
const storageFile = [...this.audioInfo.audioList, result]; const storageFile = [...this.audioInfo.audioList, result];
uni.$storage.set("storageFile", storageFile); uni.$storage.set("storageFile", storageFile);
...@@ -237,16 +217,20 @@ export default { ...@@ -237,16 +217,20 @@ export default {
}, },
/**保存记录*/ /**保存记录*/
saveRecord() { saveRecord() {
console.log("保存记录");
const recordUrlList = JSON.parse(uni.$storage.get("errorFile") || "[]"); const recordUrlList = JSON.parse(uni.$storage.get("errorFile") || "[]");
let recordList = JSON.parse(uni.$storage.get("recordList") || "[]"); let recordList = JSON.parse(uni.$storage.get("recordList") || "[]");
recordList = [ recordList = [
...recordList,
{ {
...this.getParams(), ...this.getParams(),
recordUrlList, recordUrlList,
}, },
...recordList,
]; ];
uni.$storage.set("recordList", JSON.stringify(recordList)); uni.$storage.set("recordList", JSON.stringify(recordList));
uni.hideLoading();
uni.$storage.set("errorFile", "");
console.log(recordList, "recordList");
}, },
/**是否存在错误文件*/ /**是否存在错误文件*/
hasErrorFile() { hasErrorFile() {
...@@ -261,42 +245,36 @@ export default { ...@@ -261,42 +245,36 @@ export default {
const errorFileList = JSON.parse(uni.$storage.get("errorFile") || "[]"); const errorFileList = JSON.parse(uni.$storage.get("errorFile") || "[]");
const errorFile = [...errorFileList, { file, status }]; const errorFile = [...errorFileList, { file, status }];
uni.$storage.set("errorFile", JSON.stringify(errorFile)); uni.$storage.set("errorFile", JSON.stringify(errorFile));
}, console.log(this.audioInfo.audioStatus, errorFile, "errorFile");
/**上传记录*/ if (
async handleRerord(val) { this.audioInfo.audioStatus == "end" &&
let recordList = JSON.parse(uni.$storage.get("recordList") || "[]"); errorFile.find((i) => i.status == UPLOAD_STATUS.fail)
let idx = recordList.findIndex( ) {
(item) => item.receptionStartTime == val.receptionStartTime this.saveRecord();
);
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 (
if (recordUrlList.every((i) => i.status == UPLOAD_STATUS.success)) { this.audioInfo.audioStatus == "end" &&
recordList.splice(idx, 1); errorFile.every((i) => i.status == UPLOAD_STATUS.success)
val.recordUrlList = val.recordUrlList.map((i) => i.file); ) {
this.uploadVoice(val); uni.$storage.set("errorFile", "");
uni.$storage.set("recordList", JSON.stringify(recordList));
} }
}, },
async checkUploadFile(tempFilePath) { async checkUploadFile(tempFilePath) {
console.log(tempFilePath);
let attempt = 0; let attempt = 0;
let errorMsg = ""; let errorMsg = "";
while (attempt < 5) { while (attempt < 2) {
try { try {
const result = await upload(tempFilePath); const result = await upload(tempFilePath);
// 上传成功 // 上传成功
return result; return result;
} catch (error) { } catch (error) {
if (attempt == 0) { if (attempt == 0) {
this.$sendSentry(`第一次上传失败:文件${tempFilePath}`); const { customerName, phoneNumber } =
this.$store.state.user.customerInfo;
this.$sendSentry(
`第一次上传失败:姓名-${customerName},手机号-${phoneNumber},文件${tempFilePath}`
);
} }
errorMsg = error; errorMsg = error;
attempt++; attempt++;
...@@ -311,16 +289,16 @@ export default { ...@@ -311,16 +289,16 @@ export default {
}, },
//结束接待 //结束接待
stopAudio: utils.throttle(async function (status) { stopAudio: utils.throttle(async function (status) {
// const result = await this.$permision.requestAndroidPermission( // const result = await this.$permision.requestAndroidPermission(
// "android.permission.RECORD_AUDIO" // "android.permission.RECORD_AUDIO"
// ); // );
// if (result !== 1) { // if (result !== 1) {
// uni.showToast({ // uni.showToast({
// title: "为了记录语音通话,请打开录音权限", // title: "为了记录语音通话,请打开录音权限",
// icon: "none", // icon: "none",
// }); // });
// return; // return;
// } // }
if (this.audioInfo.audioStatus != "start") { if (this.audioInfo.audioStatus != "start") {
return; return;
} }
...@@ -328,16 +306,10 @@ export default { ...@@ -328,16 +306,10 @@ export default {
let finish_timer = null; let finish_timer = null;
this.setAudioInfo({ audioStatus: "end" }); this.setAudioInfo({ audioStatus: "end" });
//直接退出 //直接退出
if (!status) { uni.showLoading({
uni.showLoading({ mask: true,
mask: true, title: status ? "" : "处理中请稍后...",
title: "处理中请稍后...", });
});
// setTimeout(() => {
// uni.hideLoading();
// clearInterval(finish_timer);
// }, 1000 * 60);
}
this.times = 0; this.times = 0;
clearInterval(this.timer); clearInterval(this.timer);
this.timer = null; this.timer = null;
...@@ -352,7 +324,7 @@ export default { ...@@ -352,7 +324,7 @@ export default {
clearInterval(finish_timer); clearInterval(finish_timer);
} }
}, 300); }, 300);
}, 1500), }, 500),
//监听点击事件 //监听点击事件
initTime() { initTime() {
if (this.audioInfo.audioStatus != "start") return; if (this.audioInfo.audioStatus != "start") return;
......
/*
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 11:28:48
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-04-26 10:04:31
* @FilePath: \gl_tape\mixin\click.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
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);
},
},
};
...@@ -845,4 +845,9 @@ export default { ...@@ -845,4 +845,9 @@ export default {
background-position-x: -100%; background-position-x: -100%;
} }
} }
.webview-container {
width: 100rpx;
height: 100rpx;
opacity: 0;
}
</style> </style>
...@@ -16,6 +16,8 @@ export const STORAGE_OBJECTkEY = { ...@@ -16,6 +16,8 @@ export const STORAGE_OBJECTkEY = {
noSignInUuid: "noSignInUuid", noSignInUuid: "noSignInUuid",
noviceGuideStatus: "noviceGuideStatus", noviceGuideStatus: "noviceGuideStatus",
accountLength: "accountLength", accountLength: "accountLength",
errorFile: "errorFile",
recordList: "recordList",
}; };
// export const IMG_VERSION = async () => { // export const IMG_VERSION = async () => {
......
class FileManager {
writeFile(addr, data) {
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS, // 程序公用文档目录常量
(fs) => {
// 创建或打开文件, fs.root是根目录操作对象,直接fs表示当前操作对象
fs.root.getFile(
addr,
{
create: true, // 文件不存在则创建
},
(fileEntry) => {
// 文件在手机中的路径
console.log(fileEntry.fullPath);
fileEntry.createWriter((writer) => {
// 写入文件成功完成的回调函数
writer.onwrite = (e) => {
console.log("写入成功");
};
// 向文件中写入数据
writer.write(JSON.stringify(data));
});
},
(e) => {
console.log("getFile failed: " + e.message);
}
);
},
(e) => {
console.log(e.message);
}
);
}
readFile(addr) {
let that = this;
return new Promise((resolve, reject) => {
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
(fs) => {
fs.root.getFile(
addr,
{
create: true,
},
(fileEntry) => {
fileEntry.file(function (file) {
console.log("文件大小:" + file.size + "-- 文件名:" + file.name);
//创建读取文件对象
let fileReader = new plus.io.FileReader();
//以文本格式读取文件数据内容
fileReader.readAsText(file, "utf-8");
//文件读取操作完成时的回调函数
fileReader.onloadend = function (evt) {
resolve(evt.target.result);
//console.log("提取的服务器地址:", sURL);
};
});
},
(e) => {
reject(e);
console.log(e);
}
);
},
(e) => {
reject(e);
console.log(e.message);
}
);
});
}
}
export default new FileManager();
...@@ -35,54 +35,57 @@ const uploadFile = function (filePath) { ...@@ -35,54 +35,57 @@ const uploadFile = function (filePath) {
const aliyunServerURL = config.uploadUrl; // OSS地址 const aliyunServerURL = config.uploadUrl; // OSS地址
const accessid = config.OSSAccessKeyId; const accessid = config.OSSAccessKeyId;
const policyBase64 = getPolicyBase64(); const policyBase64 = getPolicyBase64();
const { signature, securityToken, lsaccessKeyId } = await getSignature( try {
policyBase64 const { signature, securityToken, lsaccessKeyId } = await getSignature(
); // 获取签名 policyBase64
); // 获取签名
uni.uploadFile({ uni.uploadFile({
url: aliyunServerURL, // 开发者服务器url url: aliyunServerURL, // 开发者服务器url
filePath: filePath, // 要上传文件资源的路径 filePath: filePath, // 要上传文件资源的路径
name: "file", // 必须填file name: "file", // 必须填file
formData: { formData: {
key: aliyunFileKey, key: aliyunFileKey,
policy: policyBase64, policy: policyBase64,
OSSAccessKeyId: lsaccessKeyId, OSSAccessKeyId: lsaccessKeyId,
success_action_status: "200", // 让服务端返回200, 不然默认会返回204 success_action_status: "200", // 让服务端返回200, 不然默认会返回204
signature: signature, signature: signature,
"x-oss-security-token": securityToken, // 使用STS签名时必传。 "x-oss-security-token": securityToken, // 使用STS签名时必传。
}, },
success: function (res) { success: function (res) {
console.log(res, 444); console.log(res, 444);
if (res.statusCode != 200) { if (res.statusCode != 200) {
reject( reject(
new Error( new Error(
"上传错误:" + "上传错误:" +
JSON.stringify({ JSON.stringify({
statusCode: res.statusCode, statusCode: res.statusCode,
filePath, filePath,
key: aliyunFileKey, key: aliyunFileKey,
policy: policyBase64, policy: policyBase64,
OSSAccessKeyId: lsaccessKeyId, OSSAccessKeyId: lsaccessKeyId,
signature: signature, signature: signature,
"x-oss-security-token": securityToken, "x-oss-security-token": securityToken,
}) })
) )
); );
} else { } else {
uni.removeSavedFile({ uni.removeSavedFile({
filePath, filePath,
complete: function (res) { complete: function (res) {
console.log(res); console.log(res);
}, },
}); });
} }
resolve(aliyunServerURL + aliyunFileKey); resolve(aliyunServerURL + aliyunFileKey);
}, },
fail: function (err) { fail: function (err) {
err.domainName = aliyunServerURL; err.domainName = aliyunServerURL;
reject(err); reject(err);
}, },
}); });
} catch {
reject("获取签名失败");
}
}); });
}; };
...@@ -103,17 +106,22 @@ const getPolicyBase64 = function () { ...@@ -103,17 +106,22 @@ const getPolicyBase64 = function () {
// 生成签名 // 生成签名
const getSignature = function (policyBase64) { const getSignature = function (policyBase64) {
return new Promise(async (reslove) => { return new Promise(async (reslove, reject) => {
const result = uni.$api.commonApi.getToken({}).then((res) => { const result = uni.$api.commonApi
const { lsaccessKeySecret, securityToken, lsaccessKeyId } = res; .getToken({})
const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret); .then((res) => {
const signature = Crypto.enc.Base64.stringify(bytes); const { lsaccessKeySecret, securityToken, lsaccessKeyId } = res;
reslove({ const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret);
signature, const signature = Crypto.enc.Base64.stringify(bytes);
securityToken, reslove({
lsaccessKeyId, signature,
securityToken,
lsaccessKeyId,
});
})
.catch((error) => {
reject(error);
}); });
});
// const result = await uni.request({ // const result = await uni.request({
// url: 'https://dj.test.glsx.com.cn/rop-dj-smartcarlife/router', // url: 'https://dj.test.glsx.com.cn/rop-dj-smartcarlife/router',
// data: { // data: {
......
...@@ -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!