Commit 79c9852b authored by Damon's avatar Damon

perf: 日志封装、图片异步优化

parent 599f15ec
const VERSION = process.uniEnv.version
const canIUseLogManage = wx.canIUse("getLogManager");
const logger = canIUseLogManage ? wx.getLogManager({ level: 0 }) : null;
var realtimeLogger = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null;
/**
* @param {string} file 所在文件名
* @param {...any} arg 参数
*/
export function DEBUG (file, ...args) {
console.debug(file, " | ", ...args);
if (canIUseLogManage) {
logger.debug(`[${VERSION}]`, file, " | ", ...args);
}
realtimeLogger && realtimeLogger.info(`[${VERSION}]`, file, " | ", ...args);
}
/**
*
* @param {string} file 所在文件名
* @param {...any} arg 参数
*/
export function RUN (file, ...args) {
console.log(file, " | ", ...args);
if (canIUseLogManage) {
logger.log(`[${VERSION}]`, file, " | ", ...args);
}
realtimeLogger && realtimeLogger.info(`[${VERSION}]`, file, " | ", ...args);
}
/**
*
* @param {string} file 所在文件名
* @param {...any} arg 参数
*/
export function ERROR (file, ...args) {
console.error(file, " | ", ...args);
if (canIUseLogManage) {
logger.warn(`[${VERSION}]`, file, " | ", ...args);
}
if (realtimeLogger) {
realtimeLogger.error(`[${VERSION}]`, file, " | ", ...args);
// 判断是否支持设置模糊搜索
// 错误的信息可记录到 FilterMsg,方便搜索定位
if (realtimeLogger.addFilterMsg) {
try {
realtimeLogger.addFilterMsg(
`[${VERSION}] ${file} ${JSON.stringify(args)}`
);
} catch (e) {
realtimeLogger.addFilterMsg(`[${VERSION}] ${file}`);
}
}
}
}
// 方便将页面名字自动打印
export function getLogger (fileName) {
return {
DEBUG: function (...args) {
DEBUG(fileName, ...args);
},
RUN: function (...args) {
RUN(fileName, ...args);
},
ERROR: function (...args) {
ERROR(fileName, ...args);
}
};
}
\ No newline at end of file
...@@ -45,14 +45,15 @@ export default { ...@@ -45,14 +45,15 @@ export default {
* 存储图片到任务队列 * 存储图片到任务队列
* @param {Array} files 图片路径 * @param {Array} files 图片路径
*/ */
async saveToTask(files) { async saveToTask(files, order) {
// 生成key返回,然后把key放到异步上传的任务队列 // 生成key返回,然后把key放到异步上传的任务队列
let lists = files.map(v => { let lists = files.map(v => {
const key = randomChar(10) const key = randomChar(10)
return { return {
key: key, key: key,
path: v, path: v,
src: key src: key,
...order
} }
}) })
// for (let i = 0; i < files.length; i++) { // for (let i = 0; i < files.length; i++) {
...@@ -69,7 +70,7 @@ export default { ...@@ -69,7 +70,7 @@ export default {
* 选择图片 * 选择图片
* @param {Object} data option * @param {Object} data option
*/ */
async chooseImg(data){ async chooseImg(data, order){
const self = this const self = this
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.chooseImage({ uni.chooseImage({
...@@ -77,7 +78,7 @@ export default { ...@@ -77,7 +78,7 @@ export default {
sizeType: data.sizeType || ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 sizeType: data.sizeType || ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: data.sourceType || ['album', 'camera'], //从相册选择 sourceType: data.sourceType || ['album', 'camera'], //从相册选择
success: function(res) { success: function(res) {
const lists = self.saveToTask(res.tempFilePaths) const lists = self.saveToTask(res.tempFilePaths, order)
resolve(lists) resolve(lists)
}, },
fail: err => { fail: err => {
......
import uploader from '@/plugins/uploader/index.js' import uploader from '@/plugins/uploader/index.js'
import { RUN, ERROR } from "@/common/log.js"
export default { export default {
/** /**
* 执行任务队列 * 执行任务队列
...@@ -11,7 +10,6 @@ export default { ...@@ -11,7 +10,6 @@ export default {
const options = { const options = {
files: uploadTask, // 必填 临时文件路径 格式: [{path: "图片地址"}] files: uploadTask, // 必填 临时文件路径 格式: [{path: "图片地址"}]
load: false, //(默认 true 说明:本接口是否提示加载动画) load: false, //(默认 true 说明:本接口是否提示加载动画)
maxSize: 300000, //(默认 无 说明:上传的文件最大字节数限制,默认不限制)
onEachUpdate: res => { onEachUpdate: res => {
console.log("上传成功返回:",res); console.log("上传成功返回:",res);
}, },
...@@ -19,22 +17,31 @@ export default { ...@@ -19,22 +17,31 @@ export default {
console.log("上传进度返回:",res); console.log("上传进度返回:",res);
} }
} }
const result = await uploader.qnFileUpload(options)
if (result && !result.statusCode) { // 匹配已上传完成的图片,更新缓存数据 uploader.qnFileUpload(options).then(res => {
let newTask = [] this.refreshTask(that, res)
let delImg = [] }).catch(err => {
uploadTask.forEach(v => { console.log("err", err)
if (result.includes(`/${v.key}`)) { // 删除已上传的图片 ERROR('upload_photo', err)
delImg.push(v.path) if (err.errMsg && err.errMsg.indexOf('fail file not found') !== -1) { // 在任务中删除不存在的图片
} else { // 未上传的重新存储 this.refreshTask(that, ['failErr'])
newTask.push(v) }
} })
}) },
refreshTask(that, result) {
console.log("result", result)
const uploadTask = JSON.parse(JSON.stringify(that.uploadTask))
let newTask = []
let delImg = []
uploadTask.forEach(v => {
if (result.includes(`/${v.key}`) || result.includes('failErr')) { // 删除已上传的图片
delImg.push(v.path)
} else { // 未上传的重新存储
newTask.push(v)
}
})
// uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理 // uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理
that.$u.vuex('uploadTask', newTask) that.$u.vuex('uploadTask', newTask)
}
} }
} }
\ No newline at end of file
...@@ -325,7 +325,9 @@ export default { ...@@ -325,7 +325,9 @@ export default {
'&brandId=' + '&brandId=' +
item.lianbaoBrandId + item.lianbaoBrandId +
'&auditResults=' + '&auditResults=' +
(item.auditResults ? Object.keys(item.auditResults).join() : ''), (item.auditResults ? Object.keys(item.auditResults).join() : '') +
'&orderNumber=' +
item.orderNumber
}) })
}, },
handleClick(item, type, showCountTime) { handleClick(item, type, showCountTime) {
......
...@@ -521,6 +521,7 @@ export default { ...@@ -521,6 +521,7 @@ export default {
onLoad(option) { onLoad(option) {
getApp().trackPage('订单完工信息页') getApp().trackPage('订单完工信息页')
if (option) { if (option) {
this.orderNumber = option.orderNumber
this.maintainStep = option.maintainStep this.maintainStep = option.maintainStep
this.orderId = option.orderId this.orderId = option.orderId
this.categoryId = option.categoryId this.categoryId = option.categoryId
...@@ -1147,7 +1148,12 @@ export default { ...@@ -1147,7 +1148,12 @@ export default {
async closeTake(val) { async closeTake(val) {
if (val && val.length > 0) { if (val && val.length > 0) {
const files = val.map((v) => v.path) const files = val.map((v) => v.path)
const value = await this.saveToTask(files) const order = {
orderNumber: this.orderNumber,
fieldsName: this.photoItem.fieldsName,
fieldsTitle: this.photoItem.fieldsTitle
}
const value = await this.saveToTask(files, order)
this.$refs[ this.$refs[
`fileChild${this.photoItem.groupIndex}${this.photoItem.itemIndex}` `fileChild${this.photoItem.groupIndex}${this.photoItem.itemIndex}`
][0].setTmpValue(value) ][0].setTmpValue(value)
...@@ -1162,9 +1168,14 @@ export default { ...@@ -1162,9 +1168,14 @@ export default {
let options = { let options = {
sourceType: ['album'], //['album', 'camera'] sourceType: ['album'], //['album', 'camera']
count: 3, count: 3,
sizeType: ['original'], sizeType: ['original']
}
const order = {
orderNumber: this.orderNumber,
fieldsName: this.photoItem.fieldsName,
fieldsTitle: this.photoItem.fieldsTitle
} }
const value = await this.chooseImg(options) const value = await this.chooseImg(options, order)
self.$refs[ self.$refs[
`fileChild${self.photoItem.groupIndex}${self.photoItem.itemIndex}` `fileChild${self.photoItem.groupIndex}${self.photoItem.itemIndex}`
][0].setTmpValue(value) ][0].setTmpValue(value)
......
...@@ -515,7 +515,9 @@ export default { ...@@ -515,7 +515,9 @@ export default {
'&systemId=' + '&systemId=' +
this.order.partnerCompanyId + this.order.partnerCompanyId +
'&classifyId=' + '&classifyId=' +
this.order.categoryId, this.order.categoryId +
'&orderNumber=' +
this.order.orderNumber,
}) })
}, },
take() { take() {
...@@ -938,7 +940,9 @@ export default { ...@@ -938,7 +940,9 @@ export default {
'&orderStatus=' + '&orderStatus=' +
this.order.orderStatus + this.order.orderStatus +
'&brandId=' + '&brandId=' +
this.order.lianbaoBrandId, this.order.lianbaoBrandId +
'&orderNumber=' +
this.order.orderNumber
}) })
}, },
rejectOrder() { rejectOrder() {
......
...@@ -92,6 +92,7 @@ export default class fileUpload extends request { ...@@ -92,6 +92,7 @@ export default class fileUpload extends request {
} }
const parmas = JSON.parse(JSON.stringify(qnRes)) const parmas = JSON.parse(JSON.stringify(qnRes))
parmas.visitPrefix = '' parmas.visitPrefix = ''
let requestResult = await qiniuUpload(requestInfo, parmas); let requestResult = await qiniuUpload(requestInfo, parmas);
return Promise.resolve(requestResult); return Promise.resolve(requestResult);
} catch (err) { } catch (err) {
......
...@@ -115,7 +115,11 @@ export const qiniuUpload = function(requestInfo, qnRes) { ...@@ -115,7 +115,11 @@ export const qiniuUpload = function(requestInfo, qnRes) {
resolve(fileList); resolve(fileList);
} }
}, (error) => { }, (error) => {
reject(error); const rejectMsg = {
...error,
...item
}
reject(rejectMsg);
}, { }, {
region: qnRes.region || 'SCN', //地区 region: qnRes.region || 'SCN', //地区
domain: qnRes.visitPrefix, // bucket 域名,下载资源时用到。 domain: qnRes.visitPrefix, // bucket 域名,下载资源时用到。
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment