Skip to content

Commit

Permalink
chore: 修复 s2-vue 类型
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Nov 17, 2023
1 parent 2bdae50 commit 378ab50
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 57 deletions.
80 changes: 42 additions & 38 deletions packages/s2-vue/playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ const fieldMap = {
channel: ['物美', '华联'],
sex: ['', ''],
};
const partDrillDown: PartDrillDown = {
drillConfig: {
dataSet: [
Expand All @@ -545,11 +546,12 @@ const partDrillDown: PartDrillDown = {
const field = drillFields[0];
const rowData = (
dataSet.getCellMultiData({
query: meta?.query,
query: meta?.query!,
drillDownFields: [preDrillDownfield],
}) as Data[]
).filter(
(item) => item!.sub_type && item!.type && item![preDrillDownfield],
(item) =>
item!['sub_type'] && item!['type'] && item![preDrillDownfield],
);
console.log(rowData);
Expand Down Expand Up @@ -609,47 +611,49 @@ export default defineComponent({
operation: {
hiddenColumns: true,
sort: true,
onClick: (...args: any[]) => {
console.log('menuClick', ...args);
},
menus: [
{
key: 'trend',
text: '趋势',
icon: 'Trend',
enable: (cell) => cell.cellType === CellType.DATA_CELL,
onClick(cell) {
// eslint-disable-next-line no-console
console.log('趋势图 icon 点击: ', cell);
},
menu: {
onClick: (info, cell) => {
console.log('menuClick', info, cell);
},
{
key: '1',
icon: 'Trend',
text: '菜单1',
onClick(cell: any) {
console.log('cell-1: ', cell);
items: [
{
key: 'trend',
icon: 'Trend',
label: '趋势',
visible: (cell) => cell.cellType === CellType.DATA_CELL,
onClick(info, cell) {
// eslint-disable-next-line no-console
console.log('趋势图 icon 点击: ', info, cell);
},
},
children: [
{
key: '1-1',
icon: 'Trend',
text: '菜单1-1',
onClick(cell: any) {
console.log('cell-1-1: ', cell);
{
key: '1',
icon: 'Trend',
label: '菜单1',
onClick(info, cell) {
console.log('cell-1: ', cell);
},
children: [
{
key: '1-1',
icon: 'Trend',
label: '菜单1-1',
onClick(info, cell) {
console.log('cell-1-1: ', cell);
},
},
],
},
{
key: '2',
icon: 'Trend',
label: '菜单2',
onClick(info, cell) {
console.log('cell-2: ', cell);
},
],
},
{
key: '2',
icon: 'Trend',
text: '菜单2',
onClick(cell: any) {
console.log('cell-2: ', cell);
},
},
],
],
},
},
},
}) as unknown as S2Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<script lang="ts">
import { TOOLTIP_PREFIX_CLS } from '@antv/s2';
import {
type TooltipOperatorMenuInfo,
type TooltipBaseOperatorMenuItem,
TOOLTIP_PREFIX_CLS,
} from '@antv/s2';
import type { TooltipOperatorProps as BaseTooltipOperatorProps } from '@antv/s2-shared';
import { Menu, Dropdown, type MenuProps } from 'ant-design-vue';
import { defineComponent } from 'vue';
Expand All @@ -15,19 +19,25 @@ interface TooltipOperatorProps extends BaseTooltipOperatorProps {
export default defineComponent({
name: 'TooltipOperator',
props: [
'menus',
'menu',
'onlyShowOperator',
'onClick',
'cell',
] as unknown as GetInitProps<TooltipOperatorProps>,
setup(_, { emit }) {
setup(props) {
const { menu, cell } = props;
const onMenuClick: MenuClickEventHandler = (menuInfo) => {
emit('click', menuInfo);
menu?.onClick?.(menuInfo as unknown as TooltipOperatorMenuInfo, cell);
};
const onMenuTitleClick = (subMenu: TooltipBaseOperatorMenuItem) => () => {
subMenu?.onClick(subMenu as TooltipOperatorMenuInfo, cell);
};
return {
TOOLTIP_PREFIX_CLS,
onMenuClick,
onMenuTitleClick,
menus: menu?.items,
};
},
components: {
Expand All @@ -54,7 +64,7 @@ export default defineComponent({
<template v-else>
<template v-for="menu in menus" :key="menu.key">
<Dropdown :class="`${TOOLTIP_PREFIX_CLS}-operator-dropdown`">
<TooltipOperatorTitle :menu="menu" @click="menu.onClick?.(cell)" />
<TooltipOperatorTitle :menu="menu" @click="onMenuTitleClick(menu)" />
<template #overlay>
<Menu
:class="`${TOOLTIP_PREFIX_CLS}-operator-menus`"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script lang="ts">
import {
type TooltipOperatorMenu,
type S2CellType,
TOOLTIP_PREFIX_CLS,
type TooltipOperatorMenuInfo,
type S2CellType,
type TooltipBaseOperatorMenuItem,
} from '@antv/s2';
import { Menu } from 'ant-design-vue';
import { isEmpty } from 'lodash';
Expand All @@ -11,16 +12,17 @@ import type { GetInitProps } from '../../../../interface';
import TooltipOperatorTitle from './title.vue';
interface TooltipOperatorMenuProps {
menu: TooltipOperatorMenu;
menu: TooltipBaseOperatorMenuItem;
cell: S2CellType;
}
export default defineComponent({
name: 'TooltipOperatorMenu',
props: ['menu', 'cell'] as unknown as GetInitProps<TooltipOperatorMenuProps>,
setup(props) {
const { menu, cell } = props;
const onMenuTitleClick = () => {
props.menu.onClick?.(props.cell);
props.menu.onClick?.(menu as TooltipOperatorMenuInfo, cell);
};
return {
Expand Down Expand Up @@ -52,14 +54,14 @@ export default defineComponent({
<TooltipOperatorMenu :menu="subMenu" :cell="cell" />
</template>
<template v-else>
<MenuItem :title="subMenu.text" :key="subMenu.key">
<MenuItem :title="subMenu.label" :key="subMenu.key">
<TooltipOperatorTitle :menu="subMenu" @click="onMenuTitleClick" />
</MenuItem>
</template>
</template>
</SubMenu>
<!-- v-if/else branches must use unique keys. -->
<MenuItem v-if="isEmpty(menu.children)" :title="menu.text" :key="menu.key">
<MenuItem v-if="isEmpty(menu.children)" :title="menu.label" :key="menu.key">
<TooltipOperatorTitle :menu="menu" @click="onMenuTitleClick" />
</MenuItem>
</template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
import {
type TooltipOperatorMenu,
type TooltipBaseOperatorMenuItem,
TOOLTIP_PREFIX_CLS,
getIcon,
} from '@antv/s2';
import { computed, defineComponent } from 'vue';
import type { GetInitProps } from '../../../../interface';
interface TooltipOperatorTitleProps {
menu: TooltipOperatorMenu;
menu: TooltipBaseOperatorMenuItem;
}
export default defineComponent({
Expand All @@ -32,7 +32,7 @@ export default defineComponent({
v-html="icon"
:class="`${TOOLTIP_PREFIX_CLS}-operator-icon`"
/>
<span :class="`${TOOLTIP_PREFIX_CLS}-operator-text`">{{ menu.text }}</span>
<span :class="`${TOOLTIP_PREFIX_CLS}-operator-text`">{{ menu.label }}</span>
</span>
</template>

Expand Down
6 changes: 2 additions & 4 deletions packages/s2-vue/src/components/tooltip/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ export default defineComponent({
<template>
<template v-if="onlyShowOperator">
<TooltipOperator
:menus="operator?.menus || []"
:menu="operator?.menu"
:onlyShowOperator="true"
:cell="cell"
@click="operator?.onClick"
/>
</template>
<template v-else>
<TooltipOperator
:menus="operator?.menus || []"
:menu="operator?.menu"
:onlyShowOperator="false"
:cell="cell"
@click="operator?.onClick"
/>

<template v-if="content">
Expand Down

0 comments on commit 378ab50

Please sign in to comment.