<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { WxCpNoticeApi } from '#/api/wxcp/notice';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
|
import { Button, message, Tag, Tooltip } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
deleteNotice,
|
getNoticePage,
|
publishNotice,
|
revokeNotice,
|
} from '#/api/wxcp/notice';
|
|
import { NOTICE_STATUS, NOTICE_STATUS_OPTIONS, toLabelMap } from '../data';
|
import {
|
useNoticeGridColumns,
|
useNoticeSearchFormSchema,
|
} from './data';
|
import NoticeForm from './modules/form.vue';
|
import NoticePushModal from './modules/push-modal.vue';
|
|
defineOptions({ name: 'WxCpNoticeList' });
|
|
const statusLabelMap = toLabelMap(NOTICE_STATUS_OPTIONS);
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: NoticeForm,
|
destroyOnClose: true,
|
});
|
const [PushModalComp, pushModalApi] = useVbenModal({
|
connectedComponent: NoticePushModal,
|
destroyOnClose: true,
|
});
|
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
function handleCreate() {
|
formModalApi.setData({ formType: 'create' }).open();
|
}
|
|
function handleDetail(row: WxCpNoticeApi.Notice) {
|
formModalApi.setData({ formType: 'detail', id: row.id }).open();
|
}
|
|
function handleEdit(row: WxCpNoticeApi.Notice) {
|
formModalApi.setData({ formType: 'update', id: row.id }).open();
|
}
|
|
async function handleDelete(row: WxCpNoticeApi.Notice) {
|
await deleteNotice(row.id!);
|
message.success('删除成功');
|
handleRefresh();
|
}
|
|
async function handlePublish(row: WxCpNoticeApi.Notice) {
|
await publishNotice(row.id!);
|
message.success('发布成功,现在可以推送了');
|
handleRefresh();
|
}
|
|
async function handleRevoke(row: WxCpNoticeApi.Notice) {
|
await revokeNotice(row.id!);
|
message.success('已撤回');
|
handleRefresh();
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useNoticeSearchFormSchema(),
|
},
|
gridOptions: {
|
columns: useNoticeGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
return await getNoticePage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: { keyField: 'id', isHover: true },
|
toolbarConfig: { refresh: true, search: true },
|
} as VxeTableGridOptions<WxCpNoticeApi.Notice>,
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<FormModal @success="handleRefresh" />
|
<PushModalComp @success="handleRefresh" />
|
|
<Grid table-title="企业微信通知列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: '新建通知',
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['wxcp:notice:create'],
|
onClick: handleCreate,
|
},
|
]"
|
/>
|
</template>
|
|
<template #title="{ row }">
|
<Button type="link" class="p-0" @click="handleDetail(row)">
|
{{ row.title }}
|
</Button>
|
</template>
|
|
<template #content="{ row }">
|
<Tooltip v-if="row.content" :title="row.content">
|
<span class="line-clamp-2">{{ row.content }}</span>
|
</Tooltip>
|
<span v-else class="text-gray-400">-</span>
|
</template>
|
|
<template #status="{ row }">
|
<Tag
|
:color="
|
row.status === NOTICE_STATUS.PUBLISHED
|
? 'green'
|
: row.status === NOTICE_STATUS.DRAFT
|
? 'default'
|
: 'orange'
|
"
|
>
|
{{ statusLabelMap[row.status!] || '-' }}
|
</Tag>
|
</template>
|
|
<template #pushStatus="{ row }">
|
<Tag :color="row.pushStatus === 1 ? 'green' : 'default'">
|
{{ row.pushStatus === 1 ? '已推送' : '未推送' }}
|
</Tag>
|
</template>
|
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: '编辑',
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['wxcp:notice:update'],
|
ifShow: row.status !== NOTICE_STATUS.REVOKED,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '发布',
|
type: 'link',
|
auth: ['wxcp:notice:update'],
|
ifShow: row.status === NOTICE_STATUS.DRAFT,
|
popConfirm: {
|
title: '发布后即可推送给成员,确认发布?',
|
confirm: handlePublish.bind(null, row),
|
},
|
},
|
{
|
label: '推送',
|
type: 'link',
|
auth: ['wxcp:notice:push'],
|
ifShow: row.status === NOTICE_STATUS.PUBLISHED,
|
onClick: () => pushModalApi.setData({ notice: row }).open(),
|
},
|
{
|
label: '撤回',
|
type: 'link',
|
auth: ['wxcp:notice:update'],
|
ifShow: row.status === NOTICE_STATUS.PUBLISHED,
|
popConfirm: {
|
title: '撤回后该通知不能再推送,确认撤回?',
|
confirm: handleRevoke.bind(null, row),
|
},
|
},
|
{
|
label: '删除',
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['wxcp:notice:delete'],
|
popConfirm: {
|
title: `确认删除通知【${row.title}】?`,
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|