Commit 748428f6 authored by leon's avatar leon

feat: horizontal bar cache images

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