Commit 1579c641 by 李伟康

commit 图片转base64

1 parent e35a899c
...@@ -47,18 +47,20 @@ const getMockData = async (immediate = false) => { ...@@ -47,18 +47,20 @@ const getMockData = async (immediate = false) => {
}; };
const imgToBase64 = (list, urlKey) => { const imgToBase64 = (list, urlKey) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let arr = [] let arr = [],
list.map(e => { newList = JSON.parse(JSON.stringify(list))
list.map((e, index) => {
if(!(urlKey ? e[urlKey] : e).startsWith('https')) return resolve(list)
uni.request({ uni.request({
url: urlKey ? e[urlKey] : e, url: urlKey ? e[urlKey] : e,
method: 'GET', method: 'GET',
responseType: 'arraybuffer', responseType: 'arraybuffer',
success: (res) => { success: (res) => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data)}` const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data)}`
if (urlKey) e[urlKey] = base64 if (urlKey) newList[index][urlKey] = base64
else e = base64 else newList[index] = base64
arr.push(e) arr.push(e)
if (arr.length === list.length) resolve(list) if (arr.length === list.length) resolve(newList)
}, },
fail: (err) => { fail: (err) => {
reject(err) reject(err)
...@@ -70,9 +72,9 @@ const imgToBase64 = (list, urlKey) => { ...@@ -70,9 +72,9 @@ const imgToBase64 = (list, urlKey) => {
const updateMockData = (data, key) => { const updateMockData = (data, key) => {
const mockData = uni.$storage.get('mock_data') const mockData = uni.$storage.get('mock_data')
mockData[key] = data mockData[key] = data
setTimeout(()=>{ setTimeout(() => {
uni.$storage.set("mock_data", mockData) uni.$storage.set("mock_data", mockData)
},1e3) }, 1e3)
} }
// 图片版本号 // 图片版本号
const getImageVersion = async () => { const getImageVersion = async () => {
......
...@@ -121,13 +121,13 @@ export default { ...@@ -121,13 +121,13 @@ export default {
// 查询素材 // 查询素材
async getSoure () { async getSoure () {
let { moduleList, toolList } = await uni.$api.systemApi.getMockData(); let { moduleList, toolList } = await uni.$api.systemApi.getMockData();
moduleList.map(async e => { await moduleList.map(async e => {
if (e.receptionSourceDetailList) e.receptionSourceDetailList = await uni.$api.systemApi.imgToBase64(e.receptionSourceDetailList, 'detailUrl') if (e.receptionSourceDetailList) e.receptionSourceDetailList = await uni.$api.systemApi.imgToBase64(e.receptionSourceDetailList, 'detailUrl')
if (e.carTypeList) e.carTypeList = await uni.$api.systemApi.imgToBase64(e.carTypeList) if (e.carTypeList) e.carTypeList = await uni.$api.systemApi.imgToBase64(e.carTypeList)
}) })
this.moduleList = moduleList this.moduleList = moduleList
this.toolList = toolList this.toolList = toolList
uni.$api.systemApi.updateMockData(moduleList, 'moduleList') uni.$api.systemApi.updateMockData(moduleList, 'moduleList')
}, },
errorImg (index) { errorImg (index) {
this.moduleList[index].showAlt = true this.moduleList[index].showAlt = true
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!