<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { WxCpActivityApi } from '#/api/wxcp/activity';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
|
import { Button, message, Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
cancelActivity,
|
deleteActivity,
|
finishActivity,
|
getActivityPage,
|
publishActivity,
|
} from '#/api/wxcp/activity';
|
|
import {
|
ACTIVITY_STATUS,
|
ACTIVITY_STATUS_OPTIONS,
|
toLabelMap,
|
} from '../data';
|
import {
|
useActivityGridColumns,
|
useActivitySearchFormSchema,
|
} from './data';
|
import ActivityForm from './modules/form.vue';
|
import PushModal from './modules/push-modal.vue';
|
import QrCodeModal from './modules/qrcode-modal.vue';
|
import SignupListModal from './modules/signup-list.vue';
|
import StatsModal from './modules/stats-modal.vue';
|
|
defineOptions({ name: 'WxCpActivityList' });
|
|
const statusLabelMap = toLabelMap(ACTIVITY_STATUS_OPTIONS);
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: ActivityForm,
|
destroyOnClose: true,
|
});
|
const [PushModalComp, pushModalApi] = useVbenModal({
|
connectedComponent: PushModal,
|
destroyOnClose: true,
|
});
|
const [QrCodeModalComp, qrCodeModalApi] = useVbenModal({
|
connectedComponent: QrCodeModal,
|
destroyOnClose: true,
|
});
|
const [StatsModalComp, statsModalApi] = useVbenModal({
|
connectedComponent: StatsModal,
|
destroyOnClose: true,
|
});
|
const [SignupModalComp, signupModalApi] = useVbenModal({
|
connectedComponent: SignupListModal,
|
destroyOnClose: true,
|
});
|
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
function handleCreate() {
|
formModalApi.setData({ formType: 'create' }).open();
|
}
|
|
function handleDetail(row: WxCpActivityApi.Activity) {
|
formModalApi.setData({ formType: 'detail', id: row.id }).open();
|
}
|
|
function handleEdit(row: WxCpActivityApi.Activity) {
|
formModalApi.setData({ formType: 'update', id: row.id }).open();
|
}
|
|
async function handleDelete(row: WxCpActivityApi.Activity) {
|
await deleteActivity(row.id!);
|
message.success('删除成功');
|
handleRefresh();
|
}
|
|
async function handlePublish(row: WxCpActivityApi.Activity) {
|
await publishActivity(row.id!);
|
message.success('发布成功,现在可以推送和生成二维码了');
|
handleRefresh();
|
}
|
|
async function handleFinish(row: WxCpActivityApi.Activity) {
|
await finishActivity(row.id!);
|
message.success('已结束');
|
handleRefresh();
|
}
|
|
async function handleCancel(row: WxCpActivityApi.Activity) {
|
await cancelActivity(row.id!);
|
message.success('已取消');
|
handleRefresh();
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useActivitySearchFormSchema(),
|
},
|
gridOptions: {
|
columns: useActivityGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
return await getActivityPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: { keyField: 'id', isHover: true },
|
toolbarConfig: { refresh: true, search: true },
|
} as VxeTableGridOptions<WxCpActivityApi.Activity>,
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<FormModal @success="handleRefresh" />
|
<PushModalComp @success="handleRefresh" />
|
<QrCodeModalComp />
|
<StatsModalComp />
|
<SignupModalComp @success="handleRefresh" />
|
|
<Grid table-title="企业微信活动列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: '新建活动',
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['wxcp:activity:create'],
|
onClick: handleCreate,
|
},
|
]"
|
/>
|
</template>
|
|
<template #title="{ row }">
|
<Button type="link" class="p-0" @click="handleDetail(row)">
|
{{ row.title }}
|
</Button>
|
</template>
|
|
<template #signupCount="{ row }">
|
<span>
|
{{ row.signupCount ?? 0 }} /
|
{{ row.signupLimit && row.signupLimit > 0 ? row.signupLimit : '不限' }}
|
</span>
|
</template>
|
|
<template #status="{ row }">
|
<Tag
|
:color="
|
row.status === ACTIVITY_STATUS.PUBLISHED
|
? 'green'
|
: row.status === ACTIVITY_STATUS.DRAFT
|
? 'default'
|
: row.status === ACTIVITY_STATUS.FINISHED
|
? 'blue'
|
: 'red'
|
"
|
>
|
{{ 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:activity:update'],
|
ifShow: row.status !== ACTIVITY_STATUS.FINISHED && row.status !== ACTIVITY_STATUS.CANCELED,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '发布',
|
type: 'link',
|
auth: ['wxcp:activity:update'],
|
ifShow: row.status === ACTIVITY_STATUS.DRAFT,
|
popConfirm: {
|
title: '发布后成员即可通过二维码报名,确认发布?',
|
confirm: handlePublish.bind(null, row),
|
},
|
},
|
{
|
label: '推送',
|
type: 'link',
|
auth: ['wxcp:activity:push'],
|
ifShow: row.status === ACTIVITY_STATUS.PUBLISHED,
|
onClick: () => pushModalApi.setData({ activity: row }).open(),
|
},
|
{
|
label: '二维码',
|
type: 'link',
|
ifShow: row.status === ACTIVITY_STATUS.PUBLISHED,
|
onClick: () => qrCodeModalApi.setData({ activity: row }).open(),
|
},
|
{
|
label: '统计',
|
type: 'link',
|
auth: ['wxcp:activity:query'],
|
onClick: () => statsModalApi.setData({ activity: row }).open(),
|
},
|
{
|
label: '报名记录',
|
type: 'link',
|
auth: ['wxcp:signup:query'],
|
onClick: () => signupModalApi.setData({ activity: row }).open(),
|
},
|
]"
|
:drop-down-actions="[
|
{
|
label: '结束',
|
type: 'link',
|
auth: ['wxcp:activity:update'],
|
ifShow: row.status === ACTIVITY_STATUS.PUBLISHED,
|
popConfirm: {
|
title: '结束后成员将无法再报名,确认结束?',
|
confirm: handleFinish.bind(null, row),
|
},
|
},
|
{
|
label: '取消',
|
type: 'link',
|
auth: ['wxcp:activity:update'],
|
ifShow: row.status === ACTIVITY_STATUS.DRAFT || row.status === ACTIVITY_STATUS.PUBLISHED,
|
popConfirm: {
|
title: `确认取消活动【${row.title}】?`,
|
confirm: handleCancel.bind(null, row),
|
},
|
},
|
{
|
label: '删除',
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['wxcp:activity:delete'],
|
ifShow: row.status === ACTIVITY_STATUS.DRAFT,
|
popConfirm: {
|
title: `确认删除活动【${row.title}】?`,
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|