uu
This commit is contained in:
parent
24ace56576
commit
6f58c5ca0d
@ -1,4 +1,4 @@
|
|||||||
import { goto } from "./untool";
|
import { goto, getImageTempFilePath } from "./untool";
|
||||||
import { showToast, showLoading, hideLoading, downloadFile } from "./untool"
|
import { showToast, showLoading, hideLoading, downloadFile } from "./untool"
|
||||||
import { setSessionXToken, getSessionXToken } from "@/session"
|
import { setSessionXToken, getSessionXToken } from "@/session"
|
||||||
import { textEncoder, textDecoder } from "./util"
|
import { textEncoder, textDecoder } from "./util"
|
||||||
@ -77,7 +77,8 @@ async function handleResponse({
|
|||||||
// 图片类型数据特殊处理
|
// 图片类型数据特殊处理
|
||||||
if((header['content-type'] || header['Content-Type'])?.indexOf?.("image/") > -1) {
|
if((header['content-type'] || header['Content-Type'])?.indexOf?.("image/") > -1) {
|
||||||
const base64 = "data:image/png;base64," + uni.arrayBufferToBase64(data)
|
const base64 = "data:image/png;base64," + uni.arrayBufferToBase64(data)
|
||||||
resolve({ data: { fileUrl: base64 } })
|
let fileUrl = await getImageTempFilePath(base64)
|
||||||
|
resolve({ data: { fileUrl } })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data = data || {}
|
data = data || {}
|
||||||
|
|||||||
@ -142,6 +142,68 @@ const saveFile = ({ tempFilePath })=> {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getImageInfo = (src)=> {
|
||||||
|
return new Promise(async (resolve, reject)=> {
|
||||||
|
uni.getImageInfo({
|
||||||
|
src,
|
||||||
|
success(res) {
|
||||||
|
resolve(res)
|
||||||
|
},
|
||||||
|
fail(e) {
|
||||||
|
console.log("获取图片信息失败=======", e)
|
||||||
|
reject(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 微信小程序 有该api
|
||||||
|
const writeFile = (params = {}, fileEndFix = '.png')=> {
|
||||||
|
return new Promise((resolve, reject)=> {
|
||||||
|
//声明文件系统
|
||||||
|
const fs = wx.getFileSystemManager();
|
||||||
|
var times = new Date().getTime();
|
||||||
|
var filePath = wx.env.USER_DATA_PATH + '/' + times + fileEndFix;
|
||||||
|
//将base64图片写入
|
||||||
|
var that = this;
|
||||||
|
fs.writeFile({
|
||||||
|
filePath: filePath,
|
||||||
|
...params,
|
||||||
|
success: (res) => {
|
||||||
|
resolve({ filePath })
|
||||||
|
},
|
||||||
|
fail: (err)=> {
|
||||||
|
console.log("writeFile:错误==", err)
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const getImageTempFilePath = (base64File) => {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
let tempFile = base64File
|
||||||
|
|
||||||
|
// // #ifdef MP-WEIXIN
|
||||||
|
// let wxRes = await writeFile({ data: base64File, encoding: 'base64' })
|
||||||
|
// tempFile = wxRes.filePath
|
||||||
|
// // #endif
|
||||||
|
|
||||||
|
// // #ifdef H5
|
||||||
|
// let webRes = await downloadFile(base64File)
|
||||||
|
// tempFile = webRes.tempFilePath
|
||||||
|
// // #endif
|
||||||
|
|
||||||
|
// // #ifdef APP-PLUS
|
||||||
|
// let appRes = await downloadFile(tempFile)
|
||||||
|
// console.log("===appRes===", appRes)
|
||||||
|
// // #endif
|
||||||
|
|
||||||
|
resolve(tempFile)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -158,4 +220,5 @@ export {
|
|||||||
downloadFile,
|
downloadFile,
|
||||||
saveNetFile,
|
saveNetFile,
|
||||||
saveFile,
|
saveFile,
|
||||||
|
getImageTempFilePath,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -132,6 +132,10 @@ export default {
|
|||||||
showToast('获取图片信息异常:getImageZip')
|
showToast('获取图片信息异常:getImageZip')
|
||||||
reject('获取图片信息异常:getImageZip')
|
reject('获取图片信息异常:getImageZip')
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
fail(err){
|
||||||
|
showToast('获取图片信息异常:getImageZip')
|
||||||
|
console.log("canvasGetImageData:失败====", err);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -146,14 +150,17 @@ export default {
|
|||||||
uni.getImageInfo({
|
uni.getImageInfo({
|
||||||
src: filePath,
|
src: filePath,
|
||||||
success(res) {
|
success(res) {
|
||||||
|
console.log("获取图片信息成功=====", res)
|
||||||
// 按原图比例算出 新的画图高度
|
// 按原图比例算出 新的画图高度
|
||||||
let height = that.canvasHeight
|
let height = that.canvasHeight
|
||||||
if(!height) {
|
if(!height) {
|
||||||
height = parseInt(that.canvasWidth * (res.height / res.width))
|
height = parseInt(that.canvasWidth * (res.height / res.width))
|
||||||
that.$emit("update:canvasHeight", height)
|
that.$emit("update:canvasHeight", height)
|
||||||
}
|
}
|
||||||
cxt.drawImage(filePath, 0, 0, that.canvasWidth, that.canvasHeight);
|
cxt.drawImage(res.path, 0, 0, that.canvasWidth, that.canvasHeight);
|
||||||
|
console.log("开始绘制图片===")
|
||||||
cxt.draw(true, ()=> {
|
cxt.draw(true, ()=> {
|
||||||
|
console.log("绘制图片结束===")
|
||||||
setTimeout( async ()=> {
|
setTimeout( async ()=> {
|
||||||
let data = await that.getImageZip({ canvasId: that.canvasId, width: that.canvasWidth, height, })
|
let data = await that.getImageZip({ canvasId: that.canvasId, width: that.canvasWidth, height, })
|
||||||
resolve(data)
|
resolve(data)
|
||||||
@ -161,8 +168,8 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail(e) {
|
fail(e) {
|
||||||
|
console.log("获取图片信息失败=====", e)
|
||||||
reject(e)
|
reject(e)
|
||||||
console.log(e)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user