feat:【ele】【ai】manager 相关的迁移
This commit is contained in:
@@ -3,7 +3,7 @@ import { ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
|
||||
import { Card, Tabs } from 'ant-design-vue';
|
||||
import { Tabs } from 'ant-design-vue';
|
||||
|
||||
import ChatConversationList from './modules/conversation-list.vue';
|
||||
import ChatMessageList from './modules/message-list.vue';
|
||||
@@ -17,15 +17,13 @@ const activeTabName = ref('conversation');
|
||||
<DocAlert title="AI 对话聊天" url="https://doc.iocoder.cn/ai/chat/" />
|
||||
</template>
|
||||
|
||||
<Card>
|
||||
<Tabs v-model:active-key="activeTabName">
|
||||
<Tabs.TabPane tab="对话列表" key="conversation">
|
||||
<ChatConversationList />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane tab="消息列表" key="message">
|
||||
<ChatMessageList />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</Card>
|
||||
<Tabs v-model:active-key="activeTabName">
|
||||
<Tabs.TabPane tab="对话列表" key="conversation">
|
||||
<ChatConversationList />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane tab="消息列表" key="message">
|
||||
<ChatMessageList />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
@@ -23,7 +23,7 @@ function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 删除消息 */
|
||||
/** 删除对话 */
|
||||
async function handleDelete(row: AiChatConversationApi.ChatConversation) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||
@@ -72,9 +72,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid table-title="对话列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction :actions="[]" />
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
|
||||
@@ -17,7 +17,7 @@ function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
/** 删除图片 */
|
||||
async function handleDelete(row: AiImageApi.Image) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||
@@ -31,6 +31,7 @@ async function handleDelete(row: AiImageApi.Image) {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 修改是否发布 */
|
||||
async function handleUpdatePublicStatusChange(
|
||||
newStatus: boolean,
|
||||
@@ -56,6 +57,7 @@ async function handleUpdatePublicStatusChange(
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
|
||||
223
apps/web-ele/src/views/ai/chat/manager/data.ts
Normal file
223
apps/web-ele/src/views/ai/chat/manager/data.ts
Normal file
@@ -0,0 +1,223 @@
|
||||
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 { getSimpleUserList } from '#/api/system/user';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
/** 关联数据 */
|
||||
let userList: SystemUserApi.User[] = [];
|
||||
getSimpleUserList().then((data) => (userList = data));
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchemaConversation(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'userId',
|
||||
label: '用户编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入用户编号',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'title',
|
||||
label: '聊天标题',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入聊天标题',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumnsConversation(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '对话编号',
|
||||
fixed: 'left',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'title',
|
||||
title: '对话标题',
|
||||
minWidth: 180,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: '用户',
|
||||
minWidth: 180,
|
||||
field: 'userId',
|
||||
formatter: ({ cellValue }) => {
|
||||
if (cellValue === 0) {
|
||||
return '系统';
|
||||
}
|
||||
return userList.find((user) => user.id === cellValue)?.nickname || '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'roleName',
|
||||
title: '角色',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'model',
|
||||
title: '模型标识',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'messageCount',
|
||||
title: '消息数',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'temperature',
|
||||
title: '温度参数',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
title: '回复数 Token 数',
|
||||
field: 'maxTokens',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
title: '上下文数量',
|
||||
field: 'maxContexts',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchemaMessage(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'conversationId',
|
||||
label: '对话编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入对话编号',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'userId',
|
||||
label: '用户编号',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: getSimpleUserList,
|
||||
labelField: 'nickname',
|
||||
valueField: 'id',
|
||||
placeholder: '请选择用户编号',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumnsMessage(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '消息编号',
|
||||
fixed: 'left',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'conversationId',
|
||||
title: '对话编号',
|
||||
minWidth: 180,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: '用户',
|
||||
minWidth: 180,
|
||||
field: 'userId',
|
||||
formatter: ({ cellValue }) =>
|
||||
userList.find((user) => user.id === cellValue)?.nickname || '-',
|
||||
},
|
||||
{
|
||||
field: 'roleName',
|
||||
title: '角色',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
title: '消息类型',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'model',
|
||||
title: '模型标识',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'content',
|
||||
title: '消息内容',
|
||||
minWidth: 300,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'replyId',
|
||||
title: '回复消息编号',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '携带上下文',
|
||||
field: 'useContext',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||
},
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
29
apps/web-ele/src/views/ai/chat/manager/index.vue
Normal file
29
apps/web-ele/src/views/ai/chat/manager/index.vue
Normal file
@@ -0,0 +1,29 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
|
||||
import { ElTabs } from 'element-plus';
|
||||
|
||||
import ChatConversationList from './modules/conversation-list.vue';
|
||||
import ChatMessageList from './modules/message-list.vue';
|
||||
|
||||
const activeTabName = ref('conversation');
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert title="AI 对话聊天" url="https://doc.iocoder.cn/ai/chat/" />
|
||||
</template>
|
||||
|
||||
<ElTabs v-model:model-value="activeTabName">
|
||||
<ElTabs.TabPane label="对话列表" name="conversation">
|
||||
<ChatConversationList />
|
||||
</ElTabs.TabPane>
|
||||
<ElTabs.TabPane label="消息列表" name="message">
|
||||
<ChatMessageList />
|
||||
</ElTabs.TabPane>
|
||||
</ElTabs>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,93 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { AiChatConversationApi } from '#/api/ai/chat/conversation';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteChatConversationByAdmin,
|
||||
getChatConversationPage,
|
||||
} from '#/api/ai/chat/conversation';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import {
|
||||
useGridColumnsConversation,
|
||||
useGridFormSchemaConversation,
|
||||
} from '../data';
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 删除对话 */
|
||||
async function handleDelete(row: AiChatConversationApi.ChatConversation) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.id]),
|
||||
});
|
||||
try {
|
||||
await deleteChatConversationByAdmin(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchemaConversation(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumnsConversation(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getChatConversationPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<AiChatConversationApi.ChatConversation>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid table-title="对话列表">
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['ai:chat-conversation:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,90 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { AiChatConversationApi } from '#/api/ai/chat/conversation';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteChatMessageByAdmin,
|
||||
getChatMessagePage,
|
||||
} from '#/api/ai/chat/message';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumnsMessage, useGridFormSchemaMessage } from '../data';
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 删除消息 */
|
||||
async function handleDelete(row: AiChatConversationApi.ChatConversation) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.id]),
|
||||
});
|
||||
try {
|
||||
await deleteChatMessageByAdmin(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchemaMessage(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumnsMessage(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getChatMessagePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<AiChatConversationApi.ChatConversation>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid table-title="消息列表">
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['ai:chat-message:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
180
apps/web-ele/src/views/ai/image/manager/data.ts
Normal file
180
apps/web-ele/src/views/ai/image/manager/data.ts
Normal file
@@ -0,0 +1,180 @@
|
||||
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[] = [];
|
||||
async function getUserData() {
|
||||
userList = await getSimpleUserList();
|
||||
}
|
||||
|
||||
getUserData();
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'userId',
|
||||
label: '用户编号',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: getSimpleUserList,
|
||||
labelField: 'nickname',
|
||||
valueField: 'id',
|
||||
placeholder: '请选择用户编号',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'platform',
|
||||
label: '平台',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择平台',
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.AI_PLATFORM, 'string'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '绘画状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择绘画状态',
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.AI_IMAGE_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'publicStatus',
|
||||
label: '是否发布',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择是否发布',
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(
|
||||
onPublicStatusChange?: (
|
||||
newStatus: boolean,
|
||||
row: any,
|
||||
) => PromiseLike<boolean | undefined>,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '编号',
|
||||
minWidth: 180,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'picUrl',
|
||||
title: '图片',
|
||||
minWidth: 110,
|
||||
fixed: 'left',
|
||||
cellRender: {
|
||||
name: 'CellImage',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'userId',
|
||||
title: '用户',
|
||||
minWidth: 180,
|
||||
formatter: ({ cellValue }) =>
|
||||
userList.find((user) => user.id === cellValue)?.nickname || '-',
|
||||
},
|
||||
{
|
||||
field: 'platform',
|
||||
title: '平台',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.AI_PLATFORM },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'model',
|
||||
title: '模型',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '绘画状态',
|
||||
minWidth: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.AI_IMAGE_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
minWidth: 100,
|
||||
title: '是否发布',
|
||||
field: 'publicStatus',
|
||||
align: 'center',
|
||||
cellRender: {
|
||||
attrs: { beforeChange: onPublicStatusChange },
|
||||
name: 'CellSwitch',
|
||||
props: {
|
||||
activeValue: true,
|
||||
inactiveValue: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'prompt',
|
||||
title: '提示词',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'width',
|
||||
title: '宽度',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'height',
|
||||
title: '高度',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'errorMessage',
|
||||
title: '错误信息',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'taskId',
|
||||
title: '任务编号',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
116
apps/web-ele/src/views/ai/image/manager/index.vue
Normal file
116
apps/web-ele/src/views/ai/image/manager/index.vue
Normal file
@@ -0,0 +1,116 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { AiImageApi } from '#/api/ai/image';
|
||||
|
||||
import { confirm, DocAlert, Page } from '@vben/common-ui';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteImage, getImagePage, updateImage } from '#/api/ai/image';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 删除图片 */
|
||||
async function handleDelete(row: AiImageApi.Image) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.id]),
|
||||
});
|
||||
try {
|
||||
await deleteImage(row.id as number);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** 修改是否发布 */
|
||||
async function handleUpdatePublicStatusChange(
|
||||
newStatus: boolean,
|
||||
row: AiImageApi.Image,
|
||||
): Promise<boolean | undefined> {
|
||||
const text = newStatus ? '公开' : '私有';
|
||||
return new Promise((resolve, reject) => {
|
||||
confirm({
|
||||
content: `确认要将该图片切换为【${text}】吗?`,
|
||||
})
|
||||
.then(async () => {
|
||||
// 更新图片状态
|
||||
await updateImage({
|
||||
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 getImagePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<AiImageApi.Image>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert title="AI 绘图创作" url="https://doc.iocoder.cn/ai/image/" />
|
||||
</template>
|
||||
<Grid table-title="绘画管理列表">
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['ai:image:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
202
apps/web-ele/src/views/ai/music/manager/data.ts
Normal file
202
apps/web-ele/src/views/ai/music/manager/data.ts
Normal 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' },
|
||||
},
|
||||
];
|
||||
}
|
||||
152
apps/web-ele/src/views/ai/music/manager/index.vue
Normal file
152
apps/web-ele/src/views/ai/music/manager/index.vue
Normal 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>
|
||||
Reference in New Issue
Block a user