Commit 748428f6 authored by leon's avatar leon

feat: horizontal bar cache images

parent 599bc27b
<script>
export default {
onLaunch: function() {
uni.removeStorageSync('cacheImages')
console.log('App Launch')
},
onShow: function() {
......
......@@ -130,10 +130,14 @@
chart.setOption(this.ec.option)
return chart
},
initChart() {
let { endVal } = this.elementData.dataList
this.ec.option.title[0].text = `${endVal}%`
this.ec.option.series[0].axisLine.lineStyle.color[0][0] = endVal / 100
initChart() {
let { endVal } = this.elementData.dataList
if(this.ec.option.title) {
this.ec.option.title[0].text = `${endVal}%`
}
if(this.ec.option.series) {
this.ec.option.series[0].axisLine.lineStyle.color[0][0] = endVal / 100
}
}
}
}
......
......@@ -50,17 +50,21 @@
}
chart.setOption(this.ec.option)
chart.on('click', event => {
const {
dataList: {
preview,
images
const { preview, images } = this.elementData.dataList
var urls = []
var caches = uni.getStorageSync('cacheImages')
images.forEach(url => {
if(caches.hasOwnProperty(url)) {
urls.push(caches[url])
} else {
urls.push(url)
}
} = this.elementData
})
// 特殊处理,如果preview为true,代表点击显示图片
if (preview) {
uni.previewImage({
current: event.dataIndex,
urls: images
urls: urls
})
} else {
this.handleEchartsClick(event)
......@@ -69,9 +73,12 @@
return chart
},
initChart() {
const { categories, series } = this.elementData.dataList
const { categories, series, preview, images } = this.elementData.dataList
this.$set(this.ec.option, 'yAxis.data', categories)
this.$set(this.ec.option, 'series', this.dealSeriesData(series))
this.$set(this.ec.option, 'series', this.dealSeriesData(series))
if(preview) {
this.cacheImages(images)
}
},
/**
* 处理数据
......@@ -97,7 +104,31 @@
}
})
return newData
}
},
/**
* 缓存图片数据
*/
cacheImages(images) {
var caches = uni.getStorageSync('cacheImages')
if(!caches) {
caches = {}
}
images.forEach(url => {
// 如果包含当前url,就不再下载
if(!caches.hasOwnProperty(url)) {
uni.downloadFile({
url: url,
success: (res) => {
if(res.statusCode === 200) {
caches[url] = res.tempFilePath
uni.setStorageSync('cacheImages', caches)
}
}
})
}
})
}
}
}
</script>
......
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