Commit 5114719f authored by Damon's avatar Damon

perf: 日志增加图片大小、网络类型

parent 9429d5eb
......@@ -185,6 +185,7 @@
// 拍照项张数目增加 等于10张
photo.allImages.unshift(
{
size: photo.tempPath.size,
path: photo.tempPath.mixWater,
src: photo.tempPath.mixWater,
key: this.fileMaps[0] ? this.fileMaps[0].key : '',
......
......@@ -44,6 +44,15 @@
</template>
<script>
const formatSize = function(size, pointLength, units) {
var unit;
units = units || [ 'B', 'K', 'M', 'G' ];
while ( (unit = units.shift()) && size > 1024 ) {
size = size / 1024;
}
return (unit === 'B' ? size : size.toFixed( pointLength === undefined ? 2 : pointLength)) + unit;
}
let r = require("@/libs/bmap-wx.min.js");
let h = new r.BMapWX({
// ak: "rpVq5d3yxaRCoKzVwmFMo0o4iC524CAG",
......@@ -382,7 +391,7 @@
})
},
// 第二步:绘制画布
drawCanvas: function(tempPath) {
drawCanvas: async function(tempPath) {
uni.showLoading({
title: '数据处理中...',
icon: 'loading'
......@@ -449,9 +458,11 @@
width: canvasWidth,
height: canvasHeight,
canvasId: 'canvas',
success: (res) => {
success: async (res) => {
const size = await this.getImageSize(res.tempFilePath)
this.tempImgs.mixWater = res.tempFilePath
globalTempPath.origin = this.tempImgs.origin
globalTempPath.size = formatSize(size) || ''
globalTempPath.mixWater = res.tempFilePath
let timer = setTimeout(()=>{
//this.goPage('/pages/photo/preview')
......@@ -483,7 +494,19 @@
fail() {}
})
},
getImageSize(path) {
return new Promise((resolve, reject) => {
wx.getFileInfo({
filePath: path,
success (res) {
resolve(res.size)
},
fail() {
resolve(0)
}
})
})
},
showPreviewFn(img) {
uni.previewImage({
current: 0,
......
import uploader from '@/plugins/uploader/index.js'
const globalUrl = process.uniEnv || {}
const randomChar = function(l, url = "") {
const x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
let tmp = "";
......@@ -14,6 +15,16 @@ const randomChar = function(l, url = "") {
tmp
);
}
const formatSize = function(size, pointLength, units) {
var unit;
units = units || [ 'B', 'K', 'M', 'G' ];
while ( (unit = units.shift()) && size > 1024 ) {
size = size / 1024;
}
return (unit === 'B' ? size : size.toFixed( pointLength === undefined ? 2 : pointLength)) + unit;
}
export default {
name: 'upload',
components: {},
......@@ -52,7 +63,8 @@ export default {
return {
time: this.$u.timeFormat(new Date().getTime(), 'yyyy-mm-dd hh:MM:ss'),
key: key,
path: v,
path: v.path,
size: formatSize(v.size) || '',
src: key,
...order
}
......@@ -79,7 +91,7 @@ export default {
sizeType: data.sizeType || ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: data.sourceType || ['album', 'camera'], //从相册选择
success: function(res) {
const lists = self.saveToTask(res.tempFilePaths, order)
const lists = self.saveToTask(res.tempFiles, order)
resolve(lists)
},
fail: err => {
......
import uploader from '@/plugins/uploader/index.js'
import { RUN, ERROR } from "@/common/log.js"
const getNetworkType = function() {
return new Promise((resolve, reject) => {
uni.getNetworkType({
success (res) {
resolve(res.networkType)
},
fail (res) {
resolve('获取失败')
}
})
})
}
export default {
/**
* 执行任务队列
*/
async uploadImageTask(that) {
const uploadTask = JSON.parse(JSON.stringify(that.uploadTask))
const networkType = await getNetworkType()
const options = {
files: uploadTask, // 必填 临时文件路径 格式: [{path: "图片地址"}]
load: false, //(默认 true 说明:本接口是否提示加载动画)
......@@ -15,7 +29,8 @@ export default {
const log = {
...res,
mobile: that.vuex_user.mobile
mobile: that.vuex_user.mobile,
networkType: networkType
}
delete log.files
RUN('upload_photo_success', log)
......@@ -33,6 +48,7 @@ export default {
err.mobile = that.vuex_user.mobile
if(!err.key) err.files = uploadTask
if(!err.orderNumber) err.orderNumber = uploadTask[0].orderNumber
if(!err.networkType) err.networkType = networkType
ERROR('upload_photo_error', err)
if (err.errMsg && (err.errMsg.indexOf('fail file not found') !== -1 || err.errMsg.indexOf('file doesn') !== -1)) { // 在任务中删除不存在的图片
......
......@@ -1147,14 +1147,13 @@ export default {
// 拍照回调
async closeTake(val) {
if (val && val.length > 0) {
const files = val.map((v) => v.path)
const order = {
orderNumber: this.orderNumber,
fieldsName: this.photoItem.fieldsName,
fieldsTitle: this.photoItem.fieldsTitle,
uploadType: 'camera'
}
const value = await this.saveToTask(files, order)
const value = await this.saveToTask(val, order)
this.$refs[
`fileChild${this.photoItem.groupIndex}${this.photoItem.itemIndex}`
][0].setTmpValue(value)
......
......@@ -534,8 +534,7 @@ export default {
// 获取返回的图片 ,如果返回的图片存在则直接异常签约,成功后跳转到去完工页面,
if (img) {
// 拍照完成
const files = img.map((v) => v.path)
const value = await this.saveToTask(files)
const value = await this.saveToTask(img)
this.isErrorSign = true
this.errorSignUrl = value[0].key
this.handleBtn()
......
......@@ -257,14 +257,13 @@
if (!this.currentItemDate.orderImages) this.currentItemDate.orderImages = []
// 真实地址key
let saveList = this.currentItemDate.key
const files = img.map(v => v.path)
const order = {
orderNumber: this.orderNumber,
fieldsName: this.currentItemDate.fieldsName,
fieldsTitle: this.currentItemDate.fieldsTitle,
uploadType: 'camera'
}
const value = await this.saveToTask(files, order)
const value = await this.saveToTask(img, order)
value.forEach(item =>{
// 文件key添加保存数组中
saveList.push(item.key)
......
const qiniuUploader = require("./qiniuUploader");
//七牛云上传文件命名
export const randomChar = function(l, url = "") {
const x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
......@@ -69,7 +70,7 @@ export const chooseVideo = function(data) {
}
// 七牛云上传
export const qiniuUpload = function(requestInfo, qnRes) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
if (Array.isArray(requestInfo.files)) {
let len = requestInfo.files.length;
let fileList = new Array;
......@@ -87,7 +88,6 @@ export const qiniuUpload = function(requestInfo, qnRes) {
qnRes.visitPrefix = qnRes.visitPrefix.substring(0, prefixLen - 1)
}
uploadFile(0);
function uploadFile(i) {
let item = requestInfo.files[i];
let updateUrl = item.key //randomChar(10, qnRes.folderPath);
......@@ -114,10 +114,10 @@ export const qiniuUpload = function(requestInfo, qnRes) {
} else {
resolve(fileList);
}
}, (error) => {
}, async (error) => {
const rejectMsg = {
...error,
...item
...item,
}
reject(rejectMsg);
}, {
......
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