fix: 规范 TSX 渲染函数写法

This commit is contained in:
sunlei 2026-06-03 07:29:32 +08:00
parent c30d7d04a6
commit aec8444121
7 changed files with 167 additions and 139 deletions

View File

@ -630,7 +630,7 @@ export default defineComponent({
/**
*
*/
function renderSearchArea() {
const renderSearchArea = () => {
const hasSearch = (formOptions.value.schema?.length || 0) > 0;
const hasFormButtons = formButtons.value.length > 0;
const hasCollapse =
@ -677,50 +677,56 @@ export default defineComponent({
}}
</KtTableSearch>
);
}
};
/**
*
*
* @param record
*/
function renderActionCell(record: KtTableRecord) {
const renderActionCell = (record: KtTableRecord) => {
const { inlineActions, overflowActions } = splitRowActions(
rowActions.value,
);
return (
<ASpace class="kt-table__row-actions" size={0}>
{inlineActions.map((action) => renderRowAction(action, record))}
{overflowActions.length > 0 ? (
<APopover
overlayClassName="kt-table__row-action-popover"
placement="bottomRight"
trigger="click"
>
{{
content: () => (
<div class="kt-table__row-action-popover-content">
{overflowActions.map((action) =>
renderRowAction(action, record),
)}
</div>
),
default: () => (
<AButton
aria-label="更多操作"
class="kt-table__row-action-more"
type="link"
{{
default: () => (
<>
{inlineActions.map((action) => renderRowAction(action, record))}
{overflowActions.length > 0 ? (
<APopover
overlayClassName="kt-table__row-action-popover"
placement="bottomRight"
trigger="click"
>
<EllipsisOutlined class="kt-table__row-action-more-icon" />
</AButton>
),
}}
</APopover>
) : null}
{{
content: () => (
<div class="kt-table__row-action-popover-content">
{overflowActions.map((action) =>
renderRowAction(action, record),
)}
</div>
),
default: () => (
<AButton
aria-label="更多操作"
class="kt-table__row-action-more"
type="link"
>
<EllipsisOutlined class="kt-table__row-action-more-icon" />
</AButton>
),
}}
</APopover>
) : null}
</>
),
}}
</ASpace>
);
}
};
/**
*
@ -759,7 +765,7 @@ export default defineComponent({
/**
* toolbar
*/
function renderHeaderButtons() {
const renderHeaderButtons = () => {
const toolbar = slots.toolbar?.(context);
const buttons = headerButtons.value.map((button) => renderButton(button));
@ -767,16 +773,22 @@ export default defineComponent({
return (
<ASpace wrap>
{buttons}
{toolbar}
{{
default: () => (
<>
{buttons}
{toolbar}
</>
),
}}
</ASpace>
);
}
};
/**
*
*/
function renderHeaderSettings() {
const renderHeaderSettings = () => {
if (!props.showTableSetting) return null;
return (
@ -807,7 +819,7 @@ export default defineComponent({
visibleColumnKeys={visibleColumnKeys.value}
/>
);
}
};
/**
*

View File

@ -249,12 +249,12 @@ export default defineComponent({
* @param icon
* @param onClick
*/
function renderIconButton(
const renderIconButton = (
key: string,
title: string,
icon: VNodeChild,
onClick: () => void,
) {
) => {
return (
<ATooltip title={title}>
<AButton
@ -269,12 +269,12 @@ export default defineComponent({
</AButton>
</ATooltip>
);
}
};
/**
*
*/
function renderColumnSetting() {
const renderColumnSetting = () => {
if (!props.setting.column) return null;
return (
@ -353,51 +353,55 @@ export default defineComponent({
}}
</APopover>
);
}
};
return () => (
<ASpace size={4}>
{props.setting.reload
? renderIconButton(
'reload',
'刷新',
<RotateCw class="kt-table__toolbar-icon" />,
() => emit('reload'),
)
: null}
{props.setting.showSearch
? renderIconButton(
'showSearch',
props.searchVisible ? '隐藏搜索' : '显示搜索',
props.searchVisible ? (
<EyeOff class="kt-table__toolbar-icon" />
) : (
<Eye class="kt-table__toolbar-icon" />
),
() => emit('searchVisibleChange', !props.searchVisible),
)
: null}
{props.setting.density
? renderIconButton(
'density',
`密度:${SIZE_LABEL[props.size]}`,
<Menu class="kt-table__toolbar-icon" />,
cycleSize,
)
: null}
{renderColumnSetting()}
{props.setting.fullscreen
? renderIconButton(
'fullscreen',
props.fullscreen ? '退出全屏' : '全屏',
props.fullscreen ? (
<Minimize2 class="kt-table__toolbar-icon" />
) : (
<Fullscreen class="kt-table__toolbar-icon" />
),
() => emit('fullscreenChange', !props.fullscreen),
)
: null}
{{
default: () => [
props.setting.reload
? renderIconButton(
'reload',
'刷新',
<RotateCw class="kt-table__toolbar-icon" />,
() => emit('reload'),
)
: null,
props.setting.showSearch
? renderIconButton(
'showSearch',
props.searchVisible ? '隐藏搜索' : '显示搜索',
props.searchVisible ? (
<EyeOff class="kt-table__toolbar-icon" />
) : (
<Eye class="kt-table__toolbar-icon" />
),
() => emit('searchVisibleChange', !props.searchVisible),
)
: null,
props.setting.density
? renderIconButton(
'density',
`密度:${SIZE_LABEL[props.size]}`,
<Menu class="kt-table__toolbar-icon" />,
cycleSize,
)
: null,
renderColumnSetting(),
props.setting.fullscreen
? renderIconButton(
'fullscreen',
props.fullscreen ? '退出全屏' : '全屏',
props.fullscreen ? (
<Minimize2 class="kt-table__toolbar-icon" />
) : (
<Fullscreen class="kt-table__toolbar-icon" />
),
() => emit('fullscreenChange', !props.fullscreen),
)
: null,
],
}}
</ASpace>
);
},

View File

@ -30,7 +30,10 @@ type RenderKtTableSummaryOptions = {
* @param item
* @param context KtTable
*/
function renderStatisticValue(item: KtTableStatistic, context: KtTableContext) {
const renderStatisticValue = (
item: KtTableStatistic,
context: KtTableContext,
) => {
const value =
item.render?.(context) ??
(typeof item.value === 'function' ? item.value(context) : item.value);
@ -43,7 +46,7 @@ function renderStatisticValue(item: KtTableStatistic, context: KtTableContext) {
<span>{value}</span>
</span>
);
}
};
/**
* summary
@ -52,18 +55,18 @@ function renderStatisticValue(item: KtTableStatistic, context: KtTableContext) {
* @param statistic
* @param showDefaultLabel
*/
function renderCellContent(
const renderCellContent = (
context: KtTableContext,
statistic: KtTableStatistic | undefined,
showDefaultLabel: boolean,
): VNodeChild {
): VNodeChild => {
if (statistic) return renderStatisticValue(statistic, context);
if (showDefaultLabel) {
return <span class="kt-table__summary-title"></span>;
}
return null;
}
};
/**
* KtTable summary
@ -75,7 +78,7 @@ function renderCellContent(
* @param options.showSelection
* @param options.statistics
*/
export function renderKtTableSummary(options: RenderKtTableSummaryOptions) {
export const renderKtTableSummary = (options: RenderKtTableSummaryOptions) => {
const { columns, context, customSummary, showSelection, statistics } =
options;
if (statistics.length === 0) return customSummary;
@ -118,4 +121,4 @@ export function renderKtTableSummary(options: RenderKtTableSummaryOptions) {
</ATableSummaryRow>
</ATableSummary>
);
}
};

View File

@ -79,7 +79,7 @@ export function useKtTableActions(options: UseKtTableActionsOptions) {
/**
* KtTable
*/
function getDefaultButtons(): KtTableButton[] {
const getDefaultButtons = (): KtTableButton[] => {
if (!props.showDefaultButtons) return [];
return [
@ -99,7 +99,7 @@ export function useKtTableActions(options: UseKtTableActionsOptions) {
placement: 'form',
},
];
}
};
/**
*
@ -107,13 +107,13 @@ export function useKtTableActions(options: UseKtTableActionsOptions) {
* @param icon
* @param targetContext 使
*/
function renderIcon(
const renderIcon = (
icon: KtTableButton['icon'],
targetContext: KtTableContext = context,
) {
) => {
if (!icon) return null;
return typeof icon === 'function' ? icon(targetContext) : icon;
}
};
/**
*
@ -195,7 +195,7 @@ export function useKtTableActions(options: UseKtTableActionsOptions) {
*
* @param button
*/
function renderButton(button: KtTableButton) {
const renderButton = (button: KtTableButton) => {
return (
<AButton
danger={button.danger}
@ -209,7 +209,7 @@ export function useKtTableActions(options: UseKtTableActionsOptions) {
{button.label}
</AButton>
);
}
};
/**
*
@ -217,7 +217,7 @@ export function useKtTableActions(options: UseKtTableActionsOptions) {
* @param action
* @param row
*/
function renderRowAction(action: KtTableRowAction, row: KtTableRecord) {
const renderRowAction = (action: KtTableRowAction, row: KtTableRecord) => {
const disabled =
typeof action.disabled === 'function'
? action.disabled(row, context)
@ -235,7 +235,7 @@ export function useKtTableActions(options: UseKtTableActionsOptions) {
{action.label}
</AButton>
);
}
};
return {
formButtons,

View File

@ -282,12 +282,12 @@ export default defineComponent({
return [...map.values()];
}
function renderBindAction(options: {
const renderBindAction = (options: {
bound: boolean;
name: string;
onBind: () => Promise<void>;
onUnbind: () => Promise<void>;
}) {
}) => {
if (!options.bound) {
return (
<AButton onClick={options.onBind} type="link">
@ -306,25 +306,25 @@ export default defineComponent({
</AButton>
</APopconfirm>
);
}
};
function renderBoundTag(bound: boolean) {
const renderBoundTag = (bound: boolean) => {
return (
<Tag color={bound ? 'success' : 'default'}>
{bound ? '已绑定' : '未绑定'}
</Tag>
);
}
};
function renderEnabledTag(enabled: boolean) {
const renderEnabledTag = (enabled: boolean) => {
return (
<Tag color={enabled ? 'success' : 'default'}>
{enabled ? '启用' : '停用'}
</Tag>
);
}
};
function renderCommandTable() {
const renderCommandTable = () => {
return (
<ATable
columns={commandColumns}
@ -353,12 +353,15 @@ export default defineComponent({
if (column.key === 'action') {
return (
<ASpace>
{renderBindAction({
bound,
name: row.name || row.code,
onBind: () => handleCommandBind(row),
onUnbind: () => handleCommandUnbind(row),
})}
{{
default: () =>
renderBindAction({
bound,
name: row.name || row.code,
onBind: () => handleCommandBind(row),
onUnbind: () => handleCommandUnbind(row),
}),
}}
</ASpace>
);
}
@ -367,9 +370,9 @@ export default defineComponent({
}}
/>
);
}
};
function renderEventTable() {
const renderEventTable = () => {
return (
<ATable
columns={eventColumns}
@ -395,12 +398,15 @@ export default defineComponent({
if (column.key === 'action') {
return (
<ASpace>
{renderBindAction({
bound: row.bound,
name: row.name,
onBind: () => handleEventBind(row),
onUnbind: () => handleEventUnbind(row),
})}
{{
default: () =>
renderBindAction({
bound: row.bound,
name: row.name,
onBind: () => handleEventBind(row),
onUnbind: () => handleEventUnbind(row),
}),
}}
</ASpace>
);
}
@ -409,9 +415,9 @@ export default defineComponent({
}}
/>
);
}
};
function renderRuleTable() {
const renderRuleTable = () => {
return (
<ATable
columns={ruleColumns}
@ -447,12 +453,15 @@ export default defineComponent({
if (column.key === 'action') {
return (
<ASpace>
{renderBindAction({
bound,
name: row.name || row.keyword,
onBind: () => handleRuleBind(row),
onUnbind: () => handleRuleUnbind(row),
})}
{{
default: () =>
renderBindAction({
bound,
name: row.name || row.keyword,
onBind: () => handleRuleBind(row),
onUnbind: () => handleRuleUnbind(row),
}),
}}
</ASpace>
);
}
@ -461,7 +470,7 @@ export default defineComponent({
}}
/>
);
}
};
return () => (
<div class="qqbot-account-config-panel">

View File

@ -414,7 +414,7 @@ export default defineComponent({
/**
* KtTable
*/
function renderHeaderControls() {
const renderHeaderControls = () => {
return (
<>
<div class="kt-table__header-control-group">
@ -436,12 +436,12 @@ export default defineComponent({
</div>
</>
);
}
};
/**
* KtTable
*/
function renderPermissionModeToolbar() {
const renderPermissionModeToolbar = () => {
return (
<div class="kt-table__header-control-group">
<span class="kt-table__header-control-muted"></span>
@ -453,7 +453,7 @@ export default defineComponent({
/>
</div>
);
}
};
return () => (
<Page autoContentHeight>

View File

@ -563,20 +563,20 @@ export default defineComponent({
() => `请求 ${requestTimes.value} 次 / 操作 ${actionTimes.value}`,
);
function renderStatus(status: DemoStatus) {
const renderStatus = (status: DemoStatus) => {
const option = pickOption(statusOptions, status);
return <Tag color={option?.color}>{option?.label || status}</Tag>;
}
};
function renderLevel(level: DemoLevel) {
const renderLevel = (level: DemoLevel) => {
const option = pickOption(levelOptions, level);
return <Tag color={option?.color}>{option?.label || level}</Tag>;
}
};
function renderChannel(channel: DemoChannel) {
const renderChannel = (channel: DemoChannel) => {
const option = pickOption(channelOptions, channel);
return <Tag color={option?.color}>{option?.label || channel}</Tag>;
}
};
return () => (
<Page autoContentHeight>