diff --git a/src/control/chart/chart.scss b/src/control/chart/chart.scss index 38a5c81f96a92f350a76fb52bf385ec72d19bcad..6dc0f9d7efacb38771a8a63bbed8204762e0cc6b 100644 --- a/src/control/chart/chart.scss +++ b/src/control/chart/chart.scss @@ -27,6 +27,7 @@ $control-chart: (); } } @include e('chart-grid-container') { + position: relative; flex: 1; height: 50%; @include when('bottom') { @@ -59,6 +60,35 @@ $control-chart: (); width: 100%; height: 100%; } + @include e('drill-down') { + position: absolute; + top: 0; + left: 0; + width: 150px; + padding: getCssVar('spacing', 'tight') 0; + background: getCssVar('color', 'bg', 1); + border: 1px solid getCssVar(color, border); + border-radius: getCssVar('border-radius', small); + box-shadow: getCssVar(color, elevated); + + @include m('item') { + display: flex; + gap: getCssVar('spacing', 'tight'); + align-items: center; + height: 40px; + padding: getCssVar('spacing', 'tight') getCssVar('spacing', 'base-loose'); + font-size: getCssVar('font-size', 'regular'); + cursor: pointer; + + &:hover { + background-color: getCssVar(color, fill, 1); + } + } + + @include m('item-text') { + margin-bottom: getCssVar('spacing', 'super-tight'); + } + } @include e('grid') { flex: 1; height: auto; diff --git a/src/control/chart/chart.tsx b/src/control/chart/chart.tsx index 359c45b96700564cf932fb01d5c430acc5943898..c3713044665d57a71bdae6139bf51592503216c8 100644 --- a/src/control/chart/chart.tsx +++ b/src/control/chart/chart.tsx @@ -1,4 +1,8 @@ -import { useControlController, useNamespace } from '@ibiz-template/vue3-util'; +import { + useControlController, + useNamespace, + useClickOutside, +} from '@ibiz-template/vue3-util'; import { defineComponent, nextTick, @@ -26,13 +30,20 @@ const ChartControl = defineComponent({ isSimple: { type: Boolean, required: false }, data: { type: Array, required: false }, }, - setup(props) { + emits: ['drillDown'], + setup(props, { emit }) { const c = useControlController((...args) => new ChartController(...args)); const ns = useNamespace(`control-${c.model.controlType!.toLowerCase()}`); const chartRef = ref(); const maxHeight = ref(0); // 图表表格的高度,后续会根据表格位置进行计算 const uuid = createUUID(); + const showCheck = ref(false); + const drillDownPos = ref({}); // 数据下钻框位置 + const drillDownRef = ref(); // 数据下钻框 + let func: { stop: () => void }; + let tempParams: IData; // 点击的图表回调事件参数 + // 本地数据模式 const initSimpleData = (): void => { if (!props.data) { @@ -83,6 +94,19 @@ const ChartControl = defineComponent({ return c.state.gridData || []; }; + const computedDrillDownPos = (params: IParams) => { + if (params.event) { + const event: PointerEvent = params.event.event; + event.stopPropagation(); + event.preventDefault(); + const { offsetX, offsetY } = params.event; + drillDownPos.value = { + top: `${offsetY}px`, + left: `${offsetX + 16}px`, + }; + } + }; + // 容器大小变化监听器 let resizeObserver: ResizeObserver; @@ -97,8 +121,34 @@ const ChartControl = defineComponent({ resizeObserver.observe(chartRef.value); } setHeight(); + if (props.modelData.controlParam?.ctrlParams?.ENABLEDRILLDOWN) { + // 开启数据钻取,重写chart的click事件 + chart.on('click', (params: IData) => { + tempParams = params; + chart.dispatchAction({ type: 'hideTip' }); + showCheck.value = true; + c.changeTooltipState(false); + func = useClickOutside(drillDownRef, () => { + showCheck.value = false; + c.changeTooltipState(true); + func.stop(); + }); + computedDrillDownPos(params); + }); + } }); + // 查看明细 + const openDrillDown = (_event: MouseEvent) => { + showCheck.value = false; + if (func) { + func.stop(); + } + c.changeTooltipState(true); + const param = c.computedDrillDownParam(tempParams); + emit('drillDown', param); + }; + // 表格显示时计算表格的高度 watch( () => c.state.showGrid, @@ -110,6 +160,17 @@ const ChartControl = defineComponent({ }, ); + watch( + () => c.state.items, + () => { + console.log(888, c.state.items); + }, + { + immediate: true, + deep: true, + }, + ); + // 绘制表格 const renderGrid = () => { return ( @@ -144,6 +205,10 @@ const ChartControl = defineComponent({ ns, chartRef, uuid, + showCheck, + drillDownPos, + drillDownRef, + openDrillDown, renderGrid, }; }, @@ -179,6 +244,41 @@ const ChartControl = defineComponent({
{ibiz.i18n.t('control.chart.chartPlaceholder')}
+ {this.showCheck ? ( +
+
+ + + + + +
+ {ibiz.i18n.t('control.chart.drillDown')} +
+
+
+ ) : null} {this.c.state.showGrid ? (
{this.renderGrid()}
diff --git a/src/locale/en/index.ts b/src/locale/en/index.ts index 9fef70698cf5721aa488691f4b8526931c392bc1..48380a1b4ad287c0bc232bd20357fe891e45f8d6 100644 --- a/src/locale/en/index.ts +++ b/src/locale/en/index.ts @@ -327,6 +327,7 @@ export default { }, chart: { chartPlaceholder: 'Chart', + drillDown: 'DrillDown', }, dashboard: { customDashboardContainer: { diff --git a/src/locale/zh-CN/index.ts b/src/locale/zh-CN/index.ts index c17c6225a5fdd425d81a01ac61c4b4d0e702030c..eed64bccc9247e8089c10e51c107c8297010fbe7 100644 --- a/src/locale/zh-CN/index.ts +++ b/src/locale/zh-CN/index.ts @@ -299,6 +299,7 @@ export default { }, chart: { chartPlaceholder: '图表', + drillDown: '检查明细', }, dashboard: { customDashboardContainer: {