fix: mp tag
parent
d900aa1d71
commit
f105df0457
|
@ -16,6 +16,11 @@ export namespace MpAccountApi {
|
||||||
remark?: string;
|
remark?: string;
|
||||||
createTime?: Date;
|
createTime?: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AccountSimple {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 查询公众号账号列表 */
|
/** 查询公众号账号列表 */
|
||||||
|
@ -35,7 +40,7 @@ export function getAccount(id: number) {
|
||||||
|
|
||||||
/** 查询公众号账号列表 */
|
/** 查询公众号账号列表 */
|
||||||
export function getSimpleAccountList() {
|
export function getSimpleAccountList() {
|
||||||
return requestClient.get<MpAccountApi.Account[]>(
|
return requestClient.get<MpAccountApi.AccountSimple[]>(
|
||||||
'/mp/account/list-all-simple',
|
'/mp/account/list-all-simple',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { VxeGridPropTypes } from '#/adapter/vxe-table';
|
import type { VxeGridPropTypes } from '#/adapter/vxe-table';
|
||||||
|
|
||||||
import { getSimpleAccountList } from '#/api/mp/account';
|
|
||||||
|
|
||||||
/** 新增/修改的表单 */
|
/** 新增/修改的表单 */
|
||||||
export function useFormSchema(): VbenFormSchema[] {
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
return [
|
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 {
|
export function useGridColumns(): VxeGridPropTypes.Columns {
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -2,26 +2,64 @@
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { MpTagApi } from '#/api/mp/tag';
|
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 { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { useTabs } from '@vben/hooks';
|
||||||
|
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { getSimpleAccountList } from '#/api/mp/account';
|
||||||
import { deleteTag, getTagPage, syncTag } from '#/api/mp/tag';
|
import { deleteTag, getTagPage, syncTag } from '#/api/mp/tag';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns } from './data';
|
||||||
import Form from './modules/form.vue';
|
import Form from './modules/form.vue';
|
||||||
|
|
||||||
|
const { push } = useRouter(); // 路由
|
||||||
|
const tabs = useTabs();
|
||||||
|
|
||||||
const accountId = ref(-1);
|
const accountId = ref(-1);
|
||||||
|
const accountOptions = ref<{ label: string; value: number }[]>([]);
|
||||||
|
|
||||||
const [FormModal, formModalApi] = useVbenModal({
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
connectedComponent: Form,
|
connectedComponent: Form,
|
||||||
destroyOnClose: true,
|
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() {
|
function onRefresh() {
|
||||||
gridApi.query();
|
gridApi.query();
|
||||||
|
@ -29,12 +67,12 @@ function onRefresh() {
|
||||||
|
|
||||||
/** 创建标签 */
|
/** 创建标签 */
|
||||||
function handleCreate() {
|
function handleCreate() {
|
||||||
formModalApi.setData(null).open();
|
formModalApi.setData({ accountId: accountId.value }).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 编辑标签 */
|
/** 编辑标签 */
|
||||||
function handleEdit(row: MpTagApi.Tag) {
|
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({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: [],
|
||||||
},
|
},
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: useGridColumns(),
|
columns: useGridColumns(),
|
||||||
|
@ -87,7 +125,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
return await getTagPage({
|
return await getTagPage({
|
||||||
pageNo: page.currentPage,
|
pageNo: page.currentPage,
|
||||||
pageSize: page.pageSize,
|
pageSize: page.pageSize,
|
||||||
accountId: accountId.value,
|
|
||||||
...formValues,
|
...formValues,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -102,11 +139,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<MpTagApi.Tag>,
|
} as VxeTableGridOptions<MpTagApi.Tag>,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await getAccountList();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page auto-content-height>
|
<Page auto-content-height>
|
||||||
<FormModal @success="onRefresh" :account-id="accountId" />
|
<FormModal @success="onRefresh" />
|
||||||
<Grid table-title="公众号账号列表">
|
<Grid table-title="公众号账号列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<TableAction
|
<TableAction
|
||||||
|
|
|
@ -13,10 +13,6 @@ import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useFormSchema } from '../data';
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
accountId: number;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const emit = defineEmits(['success']);
|
const emit = defineEmits(['success']);
|
||||||
|
|
||||||
const formData = ref<MpTagApi.Tag>();
|
const formData = ref<MpTagApi.Tag>();
|
||||||
|
@ -48,7 +44,6 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const data = (await formApi.getValues()) as MpTagApi.Tag;
|
const data = (await formApi.getValues()) as MpTagApi.Tag;
|
||||||
data.accountId = props.accountId;
|
|
||||||
try {
|
try {
|
||||||
await (formData.value?.id ? updateTag(data) : createTag(data));
|
await (formData.value?.id ? updateTag(data) : createTag(data));
|
||||||
// 关闭并提示
|
// 关闭并提示
|
||||||
|
@ -65,13 +60,13 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加载数据
|
// 加载数据
|
||||||
const data = modalApi.getData<MpTagApi.Tag>();
|
const data = modalApi.getData<{ accountId: number; row: MpTagApi.Tag }>();
|
||||||
if (!data || !data.id) {
|
if (!data || !data.row || !data.accountId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
formData.value = await getTag(data.id as number);
|
formData.value = await getTag(data.row.id as number);
|
||||||
// 设置到 values
|
// 设置到 values
|
||||||
await formApi.setValues(formData.value);
|
await formApi.setValues(formData.value);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue