From 945d19583510b6161f414fd23a34742fb6acd6e6 Mon Sep 17 00:00:00 2001 From: wisonic Date: Thu, 15 Aug 2024 19:08:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=9B=BE=E8=A1=A8):=20=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E8=A1=A8=E5=9B=BE=E7=89=87=E7=82=B9=E5=87=BB=E6=94=BE?= =?UTF-8?q?=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/visualization/ViewTrackBar.vue | 3 +- .../js/panel/charts/table/table-info.ts | 24 +++++++++--- .../views/components/ChartComponentS2.vue | 37 ++++++++++++++++++- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/core/core-frontend/src/components/visualization/ViewTrackBar.vue b/core/core-frontend/src/components/visualization/ViewTrackBar.vue index 60c1e5df54..cafa0ace5d 100644 --- a/core/core-frontend/src/components/visualization/ViewTrackBar.vue +++ b/core/core-frontend/src/components/visualization/ViewTrackBar.vue @@ -35,7 +35,8 @@ const state = reactive({ drill: t('visualization.drill'), linkage: t('visualization.linkage'), linkageAndDrill: t('visualization.linkage_and_drill'), - jump: t('visualization.jump') + jump: t('visualization.jump'), + enlarge: t('visualization.enlarge') } }) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts index 73d4e2e8af..4c5f567976 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts @@ -13,14 +13,19 @@ class ImageCell extends TableDataCell { const img = new Image() const { x, y, width, height, fieldValue } = this.meta img.src = fieldValue as string + img.setAttribute('crossOrigin', 'anonymous') img.onload = () => { !this.cfg.children && (this.cfg.children = []) + const { width: imgWidth, height: imgHeight } = img + const ratio = Math.max(imgWidth / width, imgHeight / height) + const imgShowWidth = imgWidth / ratio + const imgShowHeight = imgHeight / ratio this.textShape = this.addShape('image', { attrs: { - x, - y, - width, - height, + x: x + (imgShowWidth < width ? (width - imgShowWidth) / 2 : 0), + y: y + (imgShowHeight < height ? (height - imgShowHeight) / 2 : 0), + width: imgShowWidth, + height: imgShowHeight, img } }) @@ -118,12 +123,21 @@ export class TableInfo extends S2ChartView { } const customAttr = parseJson(chart.customAttr) + const style = this.configStyle(chart) + // 自适应列宽模式下,URL 字段的宽度固定为 120 + if (customAttr.basicStyle.tableColumnMode === 'adapt') { + const urlFields = fields.filter(field => axisMap[field.dataeaseName]?.deType === 7) + style.colCfg.widthByFieldValue = urlFields?.reduce((p, n) => { + p[n.chartShowName ?? n.name] = 120 + return p + }, {}) + } // options const s2Options: S2Options = { width: containerDom.offsetWidth, height: containerDom.offsetHeight, showSeriesNumber: customAttr.tableHeader.showIndex, - style: this.configStyle(chart), + style, conditions: this.configConditions(chart), tooltip: { getContainer: () => containerDom, diff --git a/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue b/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue index 8aba579c51..061cd2e5ac 100644 --- a/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue +++ b/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue @@ -107,7 +107,9 @@ const state = reactive({ totalItems: 0, showPage: false, pageStyle: 'simple', - currentPageSize: 0 + currentPageSize: 0, + imgEnlarge: false, + imgSrc: '' }) // 图表数据不用全响应式 let chartData = shallowRef>({ @@ -408,6 +410,16 @@ const trackClick = trackAction => { if (mobileInPc.value && !inMobile.value) return emit('onJumpClick', jumpParam) break + case 'enlarge': + if (view.value.type === 'table-info') { + param.data.dimensionList?.forEach(d => { + if (d.id === state.curActionId) { + state.imgSrc = d.value + state.imgEnlarge = true + } + }) + } + break default: break } @@ -491,6 +503,14 @@ const trackMenuCalc = itemId => { ) { trackMenuInfo = ['linkageAndDrill'] } + // 明细表 URL 字段图片放大 + if (view.value.type === 'table-info') { + view.value.xAxis?.forEach(axis => { + if (axis.id === itemId) { + trackMenuInfo.push('enlarge') + } + }) + } return trackMenuInfo } @@ -651,6 +671,11 @@ const tablePageClass = computed(() => { + +
+ +
+
+