liu
2026-09-29 982c97ab82f3beb1b4febcf014562eda34b9fc05
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<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>