refactor: 简化博客文章表单配置

This commit is contained in:
sunlei 2026-06-05 16:21:25 +08:00
parent f951edc816
commit 95c194e842

View File

@ -168,8 +168,8 @@ export default defineComponent({
]; ];
const api: KtTableApi<WordpressBlogApi.Article, ArticleSearchValues> = { const api: KtTableApi<WordpressBlogApi.Article, ArticleSearchValues> = {
list: async (params) => { list: (params) =>
return await getArticleList({ getArticleList({
categories: Array.isArray(params.categories) categories: Array.isArray(params.categories)
? params.categories.join(',') ? params.categories.join(',')
: params.categories, : params.categories,
@ -180,8 +180,7 @@ export default defineComponent({
tags: Array.isArray(params.tags) tags: Array.isArray(params.tags)
? params.tags.join(',') ? params.tags.join(',')
: params.tags, : params.tags,
}); }),
},
}; };
const buttons: Array< const buttons: Array<
KtTableButton<WordpressBlogApi.Article, ArticleSearchValues> KtTableButton<WordpressBlogApi.Article, ArticleSearchValues>
@ -235,52 +234,56 @@ export default defineComponent({
buttons, buttons,
columns, columns,
formOptions: { formOptions: {
schema: [ schema: getArticleSearchSchema(),
{
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '搜索标题或内容',
},
fieldName: 'search',
label: '关键词',
},
{
component: 'Select',
componentProps: {
allowClear: true,
options: articleStatusOptions,
},
fieldName: 'status',
label: '文章状态',
},
{
component: 'Select',
componentProps: {
allowClear: true,
mode: 'tags',
options: categoryOptions.value,
},
fieldName: 'categories',
label: '文章分类',
},
{
component: 'Select',
componentProps: {
allowClear: true,
mode: 'tags',
options: tagOptions.value,
},
fieldName: 'tags',
label: '文章标签',
},
],
}, },
immediate: false, immediate: false,
rowActions, rowActions,
tableTitle: '文章管理', tableTitle: '文章管理',
}); });
function getArticleSearchSchema() {
return [
{
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '搜索标题或内容',
},
fieldName: 'search',
label: '关键词',
},
{
component: 'Select',
componentProps: {
allowClear: true,
options: articleStatusOptions,
},
fieldName: 'status',
label: '文章状态',
},
{
component: 'Select',
componentProps: {
allowClear: true,
mode: 'tags',
options: categoryOptions.value,
},
fieldName: 'categories',
label: '文章分类',
},
{
component: 'Select',
componentProps: {
allowClear: true,
mode: 'tags',
options: tagOptions.value,
},
fieldName: 'tags',
label: '文章标签',
},
];
}
function getRenderedText(value?: string | WordpressBlogApi.RenderedField) { function getRenderedText(value?: string | WordpressBlogApi.RenderedField) {
if (!value) return ''; if (!value) return '';
if (typeof value === 'string') return stripHtml(value); if (typeof value === 'string') return stripHtml(value);
@ -342,46 +345,7 @@ export default defineComponent({
})); }));
tableApi.setProps({ tableApi.setProps({
formOptions: { formOptions: {
schema: [ schema: getArticleSearchSchema(),
{
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '搜索标题或内容',
},
fieldName: 'search',
label: '关键词',
},
{
component: 'Select',
componentProps: {
allowClear: true,
options: articleStatusOptions,
},
fieldName: 'status',
label: '文章状态',
},
{
component: 'Select',
componentProps: {
allowClear: true,
mode: 'tags',
options: categoryOptions.value,
},
fieldName: 'categories',
label: '文章分类',
},
{
component: 'Select',
componentProps: {
allowClear: true,
mode: 'tags',
options: tagOptions.value,
},
fieldName: 'tags',
label: '文章标签',
},
],
}, },
}); });
} }