diff --git a/apps/web-antd/src/api/mp/account/index.ts b/apps/web-antd/src/api/mp/account/index.ts index 9e7d27712..60833058c 100644 --- a/apps/web-antd/src/api/mp/account/index.ts +++ b/apps/web-antd/src/api/mp/account/index.ts @@ -16,6 +16,11 @@ export namespace MpAccountApi { remark?: string; createTime?: Date; } + + export interface AccountSimple { + id: number; + name: string; + } } /** 查询公众号账号列表 */ @@ -35,7 +40,7 @@ export function getAccount(id: number) { /** 查询公众号账号列表 */ export function getSimpleAccountList() { - return requestClient.get( + return requestClient.get( '/mp/account/list-all-simple', ); } diff --git a/apps/web-antd/src/views/mp/tag/data.ts b/apps/web-antd/src/views/mp/tag/data.ts index ce0a4f9aa..bdb857050 100644 --- a/apps/web-antd/src/views/mp/tag/data.ts +++ b/apps/web-antd/src/views/mp/tag/data.ts @@ -1,8 +1,6 @@ import type { VbenFormSchema } from '#/adapter/form'; import type { VxeGridPropTypes } from '#/adapter/vxe-table'; -import { getSimpleAccountList } from '#/api/mp/account'; - /** 新增/修改的表单 */ export function useFormSchema(): VbenFormSchema[] { return [ @@ -35,23 +33,6 @@ export function useFormSchema(): VbenFormSchema[] { ]; } -/** 搜索表单配置 */ -export function useGridFormSchema(): VbenFormSchema[] { - return [ - { - fieldName: 'accountId', - label: '公众号', - component: 'ApiSelect', - componentProps: { - api: getSimpleAccountList, - labelField: 'name', - valueField: 'id', - allowClear: true, - }, - }, - ]; -} - /** 表格列配置 */ export function useGridColumns(): VxeGridPropTypes.Columns { return [ diff --git a/apps/web-antd/src/views/mp/tag/index.vue b/apps/web-antd/src/views/mp/tag/index.vue index e5ccef0c7..b9471c42c 100644 --- a/apps/web-antd/src/views/mp/tag/index.vue +++ b/apps/web-antd/src/views/mp/tag/index.vue @@ -2,26 +2,64 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { MpTagApi } from '#/api/mp/tag'; -import { ref } from 'vue'; +import { onMounted, ref } from 'vue'; +import { useRouter } from 'vue-router'; import { Page, useVbenModal } from '@vben/common-ui'; +import { useTabs } from '@vben/hooks'; import { message } from 'ant-design-vue'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; +import { getSimpleAccountList } from '#/api/mp/account'; import { deleteTag, getTagPage, syncTag } from '#/api/mp/tag'; import { $t } from '#/locales'; -import { useGridColumns, useGridFormSchema } from './data'; +import { useGridColumns } from './data'; import Form from './modules/form.vue'; +const { push } = useRouter(); // 路由 +const tabs = useTabs(); + const accountId = ref(-1); +const accountOptions = ref<{ label: string; value: number }[]>([]); const [FormModal, formModalApi] = useVbenModal({ connectedComponent: Form, destroyOnClose: true, }); +async function getAccountList() { + const res = await getSimpleAccountList(); + if (res.length > 0) { + accountId.value = res[0]?.id as number; + accountOptions.value = res.map((item) => ({ + label: item.name, + value: item.id, + })); + gridApi.setState({ + formOptions: { + schema: [ + { + fieldName: 'accountId', + label: '公众号', + component: 'Select', + componentProps: { + options: accountOptions, + }, + }, + ], + }, + }); + gridApi.formApi.setValues({ + accountId: accountId.value, + }); + } else { + message.error('未配置公众号,请在【公众号管理 -> 账号管理】菜单,进行配置'); + await push({ name: 'MpAccount' }); + tabs.closeCurrentTab(); + } +} /** 刷新表格 */ function onRefresh() { gridApi.query(); @@ -29,12 +67,12 @@ function onRefresh() { /** 创建标签 */ function handleCreate() { - formModalApi.setData(null).open(); + formModalApi.setData({ accountId: accountId.value }).open(); } /** 编辑标签 */ function handleEdit(row: MpTagApi.Tag) { - formModalApi.setData(row).open(); + formModalApi.setData({ row, accountId: accountId.value }).open(); } /** 删除标签 */ @@ -74,7 +112,7 @@ async function handleSync() { const [Grid, gridApi] = useVbenVxeGrid({ formOptions: { - schema: useGridFormSchema(), + schema: [], }, gridOptions: { columns: useGridColumns(), @@ -87,7 +125,6 @@ const [Grid, gridApi] = useVbenVxeGrid({ return await getTagPage({ pageNo: page.currentPage, pageSize: page.pageSize, - accountId: accountId.value, ...formValues, }); }, @@ -102,11 +139,15 @@ const [Grid, gridApi] = useVbenVxeGrid({ }, } as VxeTableGridOptions, }); + +onMounted(async () => { + await getAccountList(); +});