feat:【ele】【ai】manager 相关的迁移

This commit is contained in:
YunaiV
2025-10-26 20:13:39 +08:00
parent 60e199abf0
commit 94e9d9a228
11 changed files with 1098 additions and 16 deletions

View File

@@ -0,0 +1,202 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemUserApi } from '#/api/system/user';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { getSimpleUserList } from '#/api/system/user';
import { getRangePickerDefaultProps } from '#/utils';
/** 关联数据 */
let userList: SystemUserApi.User[] = [];
getSimpleUserList().then((data) => (userList = data));
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'userId',
label: '用户编号',
component: 'ApiSelect',
componentProps: {
api: getSimpleUserList,
labelField: 'nickname',
valueField: 'id',
placeholder: '请选择用户编号',
clearable: true,
},
},
{
fieldName: 'title',
label: '音乐名称',
component: 'Input',
componentProps: {
placeholder: '请输入音乐名称',
clearable: true,
},
},
{
fieldName: 'status',
label: '绘画状态',
component: 'Select',
componentProps: {
placeholder: '请选择绘画状态',
clearable: true,
options: getDictOptions(DICT_TYPE.AI_MUSIC_STATUS, 'number'),
},
},
{
fieldName: 'generateMode',
label: '生成模式',
component: 'Select',
componentProps: {
placeholder: '请选择生成模式',
clearable: true,
options: getDictOptions(DICT_TYPE.AI_GENERATE_MODE, 'number'),
},
},
{
fieldName: 'createTime',
label: '创建时间',
component: 'RangePicker',
componentProps: {
...getRangePickerDefaultProps(),
allowClear: true,
},
},
{
fieldName: 'publicStatus',
label: '是否发布',
component: 'Select',
componentProps: {
placeholder: '请选择是否发布',
clearable: true,
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
},
},
];
}
/** 列表的字段 */
export function useGridColumns(
onPublicStatusChange?: (
newStatus: boolean,
row: any,
) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: '编号',
minWidth: 180,
fixed: 'left',
},
{
title: '音乐名称',
minWidth: 180,
fixed: 'left',
field: 'title',
},
{
minWidth: 180,
title: '用户',
field: 'userId',
formatter: ({ cellValue }) => {
return userList.find((user) => user.id === cellValue)?.nickname || '-';
},
},
{
field: 'status',
title: '音乐状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.AI_MUSIC_STATUS },
},
},
{
field: 'model',
title: '模型',
minWidth: 180,
},
{
title: '内容',
minWidth: 180,
slots: { default: 'content' },
},
{
field: 'duration',
title: '时长(秒)',
minWidth: 100,
},
{
field: 'prompt',
title: '提示词',
minWidth: 180,
},
{
field: 'lyric',
title: '歌词',
minWidth: 180,
},
{
field: 'gptDescriptionPrompt',
title: '描述',
minWidth: 180,
},
{
field: 'generateMode',
title: '生成模式',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.AI_GENERATE_MODE },
},
},
{
field: 'tags',
title: '风格标签',
minWidth: 180,
cellRender: {
name: 'CellTags',
},
},
{
minWidth: 100,
title: '是否发布',
field: 'publicStatus',
align: 'center',
cellRender: {
attrs: { beforeChange: onPublicStatusChange },
name: 'CellSwitch',
props: {
activeValue: true,
inactiveValue: false,
},
},
},
{
field: 'taskId',
title: '任务编号',
minWidth: 180,
},
{
field: 'errorMessage',
title: '错误信息',
minWidth: 180,
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
title: '操作',
width: 130,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@@ -0,0 +1,152 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AiMusicApi } from '#/api/ai/music';
import { confirm, DocAlert, Page } from '@vben/common-ui';
import { ElButton, ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteMusic, getMusicPage, updateMusic } from '#/api/ai/music';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 删除音乐记录 */
async function handleDelete(row: AiMusicApi.Music) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
});
try {
await deleteMusic(row.id as number);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
handleRefresh();
} finally {
loadingInstance.close();
}
}
/** 修改是否发布 */
async function handleUpdatePublicStatusChange(
newStatus: boolean,
row: AiMusicApi.Music,
): Promise<boolean | undefined> {
const text = newStatus ? '公开' : '私有';
return new Promise((resolve, reject) => {
confirm({
content: `确认要将该音乐切换为【${text}】吗?`,
})
.then(async () => {
// 更新音乐状态
await updateMusic({
id: row.id,
publicStatus: newStatus,
});
// 提示并返回成功
ElMessage.success($t('ui.actionMessage.operationSuccess'));
resolve(true);
})
.catch(() => {
reject(new Error('取消操作'));
});
});
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(handleUpdatePublicStatusChange),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getMusicPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<AiMusicApi.Music>,
});
</script>
<template>
<Page auto-content-height>
<template #doc>
<DocAlert title="AI 音乐创作" url="https://doc.iocoder.cn/ai/music/" />
</template>
<Grid table-title="音乐管理列表">
<template #toolbar-tools>
<TableAction :actions="[]" />
</template>
<template #content="{ row }">
<ElButton
type="primary"
link
v-if="row.audioUrl?.length > 0"
:href="row.audioUrl"
target="_blank"
class="p-0"
>
音乐
</ElButton>
<ElButton
type="primary"
link
v-if="row.videoUrl?.length > 0"
:href="row.videoUrl"
target="_blank"
class="p-0 !pl-1"
>
视频
</ElButton>
<ElButton
type="primary"
link
v-if="row.imageUrl?.length > 0"
:href="row.imageUrl"
target="_blank"
class="p-0 !pl-1"
>
封面
</ElButton>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['ai:music:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>