Files
aiot-platform-ui/apps/web-antd/src/views/mp/message/index.vue

201 lines
4.9 KiB
Vue
Raw Normal View History

<script lang="ts" setup>
2025-11-04 14:31:32 +08:00
import type { Dayjs } from 'dayjs';
import { reactive, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { DICT_TYPE, MpMsgType } from '@vben/constants';
2025-11-04 14:31:32 +08:00
import { getDictOptions } from '@vben/hooks';
import { IconifyIcon } from '@vben/icons';
import {
2025-11-13 18:36:35 +08:00
Button,
2025-11-04 14:31:32 +08:00
DatePicker,
Form,
FormItem,
Input,
Modal,
2025-11-13 16:12:44 +08:00
Pagination,
2025-11-04 14:31:32 +08:00
Select,
} from 'ant-design-vue';
import { getMessagePage } from '#/api/mp/message';
2025-11-20 10:34:21 +08:00
import { WxAccountSelect, WxMsg } from '#/views/mp/components';
2025-11-04 14:31:32 +08:00
2025-11-27 09:55:24 +08:00
import MessageTable from './message-table.vue';
2025-11-04 14:31:32 +08:00
defineOptions({ name: 'MpMessage' });
const loading = ref(false);
const total = ref(0); // 数据的总页数
const list = ref<any[]>([]); // 当前页的列表数据
const queryParams = reactive<{
accountId: number;
createTime: [Dayjs, Dayjs] | undefined;
openid: string;
pageNo: number;
pageSize: number;
type: string;
}>({
accountId: -1,
createTime: undefined,
openid: '',
pageNo: 1,
pageSize: 10,
type: MpMsgType.Text,
}); // 搜索参数
2025-11-04 14:31:32 +08:00
const queryFormRef = ref(); // 搜索的表单
// 消息对话框
const messageBoxVisible = ref(false);
const messageBoxUserId = ref(0);
2025-04-22 22:10:33 +08:00
/** 侦听 accountId */
2025-11-06 23:24:05 +08:00
function onAccountChanged(id: number) {
2025-11-04 14:31:32 +08:00
queryParams.accountId = id;
queryParams.pageNo = 1;
handleQuery();
2025-11-06 23:24:05 +08:00
}
2025-11-04 14:31:32 +08:00
/** 查询列表 */
2025-11-06 23:24:05 +08:00
function handleQuery() {
2025-11-04 14:31:32 +08:00
queryParams.pageNo = 1;
getList();
2025-11-06 23:24:05 +08:00
}
2025-11-04 14:31:32 +08:00
2025-11-06 23:24:05 +08:00
async function getList() {
2025-11-04 14:31:32 +08:00
try {
loading.value = true;
const data = await getMessagePage(queryParams);
list.value = data.list;
total.value = data.total;
} finally {
loading.value = false;
}
2025-11-06 23:24:05 +08:00
}
2025-11-04 14:31:32 +08:00
/** 重置按钮操作 */
2025-11-06 23:24:05 +08:00
async function resetQuery() {
2025-11-04 14:31:32 +08:00
// 暂存 accountId并在 reset 后恢复
const accountId = queryParams.accountId;
queryFormRef.value?.resetFields();
queryParams.accountId = accountId;
handleQuery();
2025-11-06 23:24:05 +08:00
}
2025-11-04 14:31:32 +08:00
/** 打开消息发送窗口 */
2025-11-06 23:24:05 +08:00
async function handleSend(userId: number) {
2025-11-04 14:31:32 +08:00
messageBoxUserId.value = userId;
messageBoxVisible.value = true;
2025-11-06 23:24:05 +08:00
}
2025-11-04 14:31:32 +08:00
/** 分页改变事件 */
2025-11-06 23:24:05 +08:00
function handlePageChange(page: number, pageSize: number) {
2025-11-04 14:31:32 +08:00
queryParams.pageNo = page;
queryParams.pageSize = pageSize;
getList();
2025-11-06 23:24:05 +08:00
}
/** 显示总条数 */
function showTotal(total: number) {
return `${total}`;
}
</script>
<template>
2025-11-04 14:31:32 +08:00
<Page auto-content-height class="flex flex-col">
<!-- 搜索工作栏 -->
2025-11-24 14:34:38 +08:00
<div class="mb-4 rounded-lg bg-background p-4">
2025-11-04 14:31:32 +08:00
<Form
ref="queryFormRef"
:model="queryParams"
layout="inline"
class="search-form"
>
<FormItem label="公众号" name="accountId">
<WxAccountSelect @change="onAccountChanged" />
</FormItem>
<FormItem label="消息类型" name="type">
<Select
v-model:value="queryParams.type"
placeholder="请选择消息类型"
class="!w-[240px]"
>
<Select.Option
v-for="dict in getDictOptions(DICT_TYPE.MP_MESSAGE_TYPE)"
:key="dict.value"
:value="dict.value"
>
{{ dict.label }}
</Select.Option>
</Select>
</FormItem>
<FormItem label="用户标识" name="openid">
<Input
v-model:value="queryParams.openid"
placeholder="请输入用户标识"
allow-clear
class="!w-[240px]"
/>
</FormItem>
<FormItem label="创建时间" name="createTime">
<DatePicker.RangePicker
v-model:value="queryParams.createTime"
:show-time="true"
class="!w-[240px]"
/>
</FormItem>
<FormItem>
2025-11-13 18:36:35 +08:00
<Button type="primary" @click="handleQuery">
2025-11-04 14:31:32 +08:00
<template #icon>
<IconifyIcon icon="mdi:magnify" />
</template>
搜索
2025-11-13 18:36:35 +08:00
</Button>
<Button class="ml-2" @click="resetQuery">
2025-11-04 14:31:32 +08:00
<template #icon>
<IconifyIcon icon="mdi:refresh" />
</template>
重置
2025-11-13 18:36:35 +08:00
</Button>
2025-11-04 14:31:32 +08:00
</FormItem>
</Form>
</div>
<!-- 列表 -->
2025-11-24 14:34:38 +08:00
<div class="flex-1 rounded-lg bg-background p-4">
2025-11-04 14:31:32 +08:00
<MessageTable :list="list" :loading="loading" @send="handleSend" />
<div v-show="total > 0" class="mt-4 flex justify-end">
2025-11-13 16:12:44 +08:00
<Pagination
2025-11-04 14:31:32 +08:00
v-model:current="queryParams.pageNo"
v-model:page-size="queryParams.pageSize"
:total="total"
show-size-changer
show-quick-jumper
2025-11-06 23:24:05 +08:00
:show-total="showTotal"
2025-11-04 14:31:32 +08:00
@change="handlePageChange"
/>
</div>
</div>
<!-- 发送消息的弹窗 -->
<Modal
v-model:open="messageBoxVisible"
title="粉丝消息列表"
:width="800"
:footer="null"
destroy-on-close
2025-04-22 22:10:33 +08:00
>
2025-11-04 14:31:32 +08:00
<WxMsg :user-id="messageBoxUserId" />
</Modal>
</Page>
2025-04-22 22:10:33 +08:00
</template>
2025-11-04 14:31:32 +08:00
<style scoped>
.search-form :deep(.ant-form-item) {
margin-bottom: 16px;
}
</style>