mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
feat(table): 新增支持配置组件
This commit is contained in:
parent
644fa4f7c0
commit
bd6fae9aed
40
packages/table/src/ComponentColumn.vue
Normal file
40
packages/table/src/ComponentColumn.vue
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<template>
|
||||||
|
<TMagicTableColumn
|
||||||
|
show-overflow-tooltip
|
||||||
|
:label="config.label"
|
||||||
|
:width="config.width"
|
||||||
|
:fixed="config.fixed"
|
||||||
|
:sortable="config.sortable"
|
||||||
|
:prop="config.prop"
|
||||||
|
>
|
||||||
|
<template v-slot="scope">
|
||||||
|
<component :is="config.component" v-bind="componentProps(scope.row)"></component>
|
||||||
|
</template>
|
||||||
|
</TMagicTableColumn>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { TMagicTableColumn } from '@tmagic/design';
|
||||||
|
|
||||||
|
import { ColumnConfig } from './schema';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'MTableColumn',
|
||||||
|
});
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
config: ColumnConfig;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
config: () => ({}),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const componentProps = (row: any) => {
|
||||||
|
if (typeof props.config.props === 'function') {
|
||||||
|
return props.config.props(row) || {};
|
||||||
|
}
|
||||||
|
return props.config.props || {};
|
||||||
|
};
|
||||||
|
</script>
|
@ -25,6 +25,10 @@
|
|||||||
<ExpandColumn :config="item" :key="columnIndex"></ExpandColumn>
|
<ExpandColumn :config="item" :key="columnIndex"></ExpandColumn>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template v-else-if="item.type === 'component'">
|
||||||
|
<ComponentColumn :config="item" :key="columnIndex"></ComponentColumn>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template v-else-if="item.selection">
|
<template v-else-if="item.selection">
|
||||||
<component
|
<component
|
||||||
width="40"
|
width="40"
|
||||||
@ -64,6 +68,7 @@ import { cloneDeep } from 'lodash-es';
|
|||||||
import { getConfig, TMagicTable } from '@tmagic/design';
|
import { getConfig, TMagicTable } from '@tmagic/design';
|
||||||
|
|
||||||
import ActionsColumn from './ActionsColumn.vue';
|
import ActionsColumn from './ActionsColumn.vue';
|
||||||
|
import ComponentColumn from './ComponentColumn.vue';
|
||||||
import ExpandColumn from './ExpandColumn.vue';
|
import ExpandColumn from './ExpandColumn.vue';
|
||||||
import PopoverColumn from './PopoverColumn.vue';
|
import PopoverColumn from './PopoverColumn.vue';
|
||||||
import TextColumn from './TextColumn.vue';
|
import TextColumn from './TextColumn.vue';
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<template #content>
|
<template #content>
|
||||||
<div>{{ formatter(config, scope.row) }}</div>
|
<div>{{ formatter(config, scope.row) }}</div>
|
||||||
</template>
|
</template>
|
||||||
<TMagicButton text type="primary">扩展配置</TMagicButton>
|
<TMagicButton text type="primary">{{ config.buttonText || '扩展配置' }}</TMagicButton>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
|
|
||||||
<TMagicTag
|
<TMagicTag
|
||||||
|
@ -41,7 +41,7 @@ export type ColumnConfig = {
|
|||||||
fixed?: 'left' | 'right' | boolean;
|
fixed?: 'left' | 'right' | boolean;
|
||||||
width?: number | string;
|
width?: number | string;
|
||||||
actions?: ColumnActionConfig[];
|
actions?: ColumnActionConfig[];
|
||||||
type?: 'popover' | 'expand' | string | ((value: any, row: any) => string);
|
type?: 'popover' | 'expand' | 'component' | string | ((value: any, row: any) => string);
|
||||||
text?: string;
|
text?: string;
|
||||||
prop?: string;
|
prop?: string;
|
||||||
showHeader?: boolean;
|
showHeader?: boolean;
|
||||||
@ -58,8 +58,10 @@ export type ColumnConfig = {
|
|||||||
handler?: (row: any) => void;
|
handler?: (row: any) => void;
|
||||||
/** 当type为expand时有效,展开为html */
|
/** 当type为expand时有效,展开为html */
|
||||||
expandContent?: (row: any, prop?: string) => string;
|
expandContent?: (row: any, prop?: string) => string;
|
||||||
/** 当type为expand时有效,展开为vue组件 */
|
/** 当type为expand时,展开为vue组件;当type为component时显示的组件 */
|
||||||
component?: any;
|
component?: any;
|
||||||
/** 当type为expand时有效,展开的vue组件props */
|
/** 当type为expand时有效,展开的vue组件props */
|
||||||
props?: any;
|
props?: any;
|
||||||
|
/** 当type为tip时有效,显示文案 */
|
||||||
|
buttonText?: string;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user