Commit 1dfe4c25 authored by chris.yang's avatar chris.yang

fix:table组件适配

parent d61c184d
<template> <template>
<view class="normal-table"> <view class="normal-table" :style="{ transform: `scale(${scale}) translate(${elementInfo.width * (scale - 1) /2}px, ${elementInfo.height * (scale - 1) /2}px)`}">
<NormalTitle :elementInfo="elementInfo"></NormalTitle> <NormalTitle :elementInfo="elementInfo"></NormalTitle>
<scroll-view scroll-x="true" class="scroll-view_H"> <scroll-view scroll-x="true" class="scroll-view_H" >
<view <view
class="table" class="table"
:style="[tableStyle]" :style="[tableStyle]"
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
mode="aspectFit" mode="aspectFit"
:src="`${cell[item.dataIndex]}?${new Date().getTime()}`" :src="`${cell[item.dataIndex]}?${new Date().getTime()}`"
crossOrigin="anonymous" crossOrigin="anonymous"
style="width:100%"
@click="imageClick(cellIndex, item.dataIndex)" @click="imageClick(cellIndex, item.dataIndex)"
></u-image> ></u-image>
</template> </template>
...@@ -46,7 +47,8 @@ ...@@ -46,7 +47,8 @@
left: 'start', left: 'start',
center: 'center', center: 'center',
right: 'end' right: 'end'
} },
scale: 1
}; };
}, },
computed: { computed: {
...@@ -91,7 +93,13 @@ ...@@ -91,7 +93,13 @@
initChart() { initChart() {
const that = this const that = this
that.$nextTick(() => { that.$nextTick(() => {
that.calculateScale()
that.chartTables = that.elementData.dataList.chartTables that.chartTables = that.elementData.dataList.chartTables
that.elementInfo.table.column.forEach(item => {
if(item.slots.customRender === 'picture') {
// that.cacheImages(item.dataIndex)
}
})
}) })
}, },
cellClick(e) { cellClick(e) {
...@@ -101,18 +109,59 @@ ...@@ -101,18 +109,59 @@
uni.$emit('handleLinkParams', { index, paramName, value: value }) uni.$emit('handleLinkParams', { index, paramName, value: value })
}, },
calculateScale() {
var query = wx.createSelectorQuery().in(this);
query.select(".normal-table").boundingClientRect(res => {
const w = res.width
const { width, height } = this.elementInfo
const scale = w / width
this.scale = scale
}).exec();
},
// 图片增加点击事件,查看全部图片 // 图片增加点击事件,查看全部图片
imageClick(index, key) { imageClick(index, key) {
const images = [] const images = []
var caches = uni.getStorageSync('cacheImages')
for(var i = 0; i < this.chartTables.length; i++) { for(var i = 0; i < this.chartTables.length; i++) {
const imageUrl = this.chartTables[i][key] const imageUrl = this.chartTables[i][key]
if(caches.hasOwnProperty(imageUrl)) {
images.push(caches[imageUrl])
} else {
images.push(imageUrl) images.push(imageUrl)
} }
}
uni.previewImage({ uni.previewImage({
current: index, current: index,
urls: images urls: images
}) })
},
/**
* 缓存图片数据
*/
cacheImages(key) {
var caches = uni.getStorageSync('cacheImages')
if(!caches) {
caches = {}
}
this.chartTables.forEach(item => {
// 如果包含当前url,就不再下载
const url = item[key]
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