feat: ai code

This commit is contained in:
xingyu4j
2025-10-22 14:52:42 +08:00
parent 7aacec3e69
commit 66647802af
26 changed files with 148 additions and 181 deletions

View File

@@ -1,5 +1,6 @@
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';
@@ -7,6 +8,13 @@ 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 [
@@ -69,15 +77,20 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
fixed: 'left',
},
{
field: 'picUrl',
title: '图片',
minWidth: 110,
fixed: 'left',
slots: { default: 'picUrl' },
cellRender: {
name: 'CellImage',
},
},
{
minWidth: 180,
field: 'userId',
title: '用户',
slots: { default: 'userId' },
minWidth: 180,
formatter: ({ cellValue }) =>
userList.find((user) => user.id === cellValue)?.nickname || '-',
},
{
field: 'platform',

View File

@@ -1,23 +1,18 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AiImageApi } from '#/api/ai/image';
import type { SystemUserApi } from '#/api/system/user';
import { onMounted, ref } from 'vue';
import { confirm, DocAlert, Page } from '@vben/common-ui';
import { AiImageStatusEnum } from '@vben/constants';
import { Image, message, Switch } from 'ant-design-vue';
import { message, Switch } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteImage, getImagePage, updateImage } from '#/api/ai/image';
import { getSimpleUserList } from '#/api/system/user';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
const userList = ref<SystemUserApi.User[]>([]); // 用户列表
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
@@ -40,7 +35,7 @@ async function handleDelete(row: AiImageApi.Image) {
}
}
/** 修改是否发布 */
const handleUpdatePublicStatusChange = async (row: AiImageApi.Image) => {
async function handleUpdatePublicStatusChange(row: AiImageApi.Image) {
try {
// 修改状态的二次确认
const text = row.publicStatus ? '公开' : '私有';
@@ -54,7 +49,7 @@ const handleUpdatePublicStatusChange = async (row: AiImageApi.Image) => {
} catch {
row.publicStatus = !row.publicStatus;
}
};
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -83,10 +78,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
} as VxeTableGridOptions<AiImageApi.Image>,
});
onMounted(async () => {
// 获得下拉数据
userList.value = await getSimpleUserList();
});
</script>
<template>
@@ -95,20 +86,6 @@ onMounted(async () => {
<DocAlert title="AI 绘图创作" url="https://doc.iocoder.cn/ai/image/" />
</template>
<Grid table-title="绘画管理列表">
<template #toolbar-tools>
<TableAction :actions="[]" />
</template>
<template #picUrl="{ row }">
<Image :src="row.picUrl" class="h-20 w-20" />
</template>
<template #userId="{ row }">
<span>
{{
userList.find((item: SystemUserApi.User) => item.id === row.userId)
?.nickname
}}
</span>
</template>
<template #publicStatus="{ row }">
<Switch
v-model:checked="row.publicStatus"