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 hasSearch = (formOptions.value.schema?.length || 0) > 0;
const hasFormButtons = formButtons.value.length > 0; const hasFormButtons = formButtons.value.length > 0;
const hasCollapse = const hasCollapse =
@ -677,20 +677,23 @@ export default defineComponent({
}} }}
</KtTableSearch> </KtTableSearch>
); );
} };
/** /**
* *
* *
* @param record * @param record
*/ */
function renderActionCell(record: KtTableRecord) { const renderActionCell = (record: KtTableRecord) => {
const { inlineActions, overflowActions } = splitRowActions( const { inlineActions, overflowActions } = splitRowActions(
rowActions.value, rowActions.value,
); );
return ( return (
<ASpace class="kt-table__row-actions" size={0}> <ASpace class="kt-table__row-actions" size={0}>
{{
default: () => (
<>
{inlineActions.map((action) => renderRowAction(action, record))} {inlineActions.map((action) => renderRowAction(action, record))}
{overflowActions.length > 0 ? ( {overflowActions.length > 0 ? (
<APopover <APopover
@ -718,9 +721,12 @@ export default defineComponent({
}} }}
</APopover> </APopover>
) : null} ) : null}
</>
),
}}
</ASpace> </ASpace>
); );
} };
/** /**
* *
@ -759,7 +765,7 @@ export default defineComponent({
/** /**
* toolbar * toolbar
*/ */
function renderHeaderButtons() { const renderHeaderButtons = () => {
const toolbar = slots.toolbar?.(context); const toolbar = slots.toolbar?.(context);
const buttons = headerButtons.value.map((button) => renderButton(button)); const buttons = headerButtons.value.map((button) => renderButton(button));
@ -767,16 +773,22 @@ export default defineComponent({
return ( return (
<ASpace wrap> <ASpace wrap>
{{
default: () => (
<>
{buttons} {buttons}
{toolbar} {toolbar}
</>
),
}}
</ASpace> </ASpace>
); );
} };
/** /**
* *
*/ */
function renderHeaderSettings() { const renderHeaderSettings = () => {
if (!props.showTableSetting) return null; if (!props.showTableSetting) return null;
return ( return (
@ -807,7 +819,7 @@ export default defineComponent({
visibleColumnKeys={visibleColumnKeys.value} visibleColumnKeys={visibleColumnKeys.value}
/> />
); );
} };
/** /**
* *

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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