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

212 lines
6.0 KiB
Vue
Raw Normal View History

<script lang="ts" setup>
2025-11-04 17:32:12 +08:00
import { provide, reactive, ref } from 'vue';
2025-04-22 22:10:33 +08:00
2025-11-04 17:32:12 +08:00
import { useAccess } from '@vben/access';
import { Page } from '@vben/common-ui';
import { IconifyIcon } from '@vben/icons';
2025-11-06 15:25:11 +08:00
import {
Button,
Card,
Form,
message,
Modal,
Pagination,
Tabs,
} from 'ant-design-vue';
2025-11-04 17:32:12 +08:00
import * as MpMaterialApi from '#/api/mp/material';
2025-11-06 15:25:11 +08:00
import { WxAccountSelect } from '#/views/mp/components/wx-account-select';
2025-11-04 17:32:12 +08:00
import ImageTable from './components/ImageTable.vue';
import { UploadType } from './components/upload';
import UploadFile from './components/UploadFile.vue';
import UploadVideo from './components/UploadVideo.vue';
import VideoTable from './components/VideoTable.vue';
import VoiceTable from './components/VoiceTable.vue';
defineOptions({ name: 'MpMaterial' });
const { hasAccessByCodes } = useAccess();
const type = ref<UploadType>(UploadType.Image); // 素材类型
const loading = ref(false); // 遮罩层
const list = ref<any[]>([]); // 数据列表
const total = ref(0); // 总条数
const accountId = ref(-1);
provide('accountId', accountId);
const queryParams = reactive({
accountId,
pageNo: 1,
pageSize: 10,
permanent: true,
}); // 查询参数
2025-11-04 17:32:12 +08:00
const showCreateVideo = ref(false); // 是否新建视频的弹窗
/** 侦听公众号变化 */
2025-11-06 23:23:25 +08:00
function onAccountChanged(id: number) {
2025-11-04 17:32:12 +08:00
accountId.value = id;
queryParams.accountId = id;
queryParams.pageNo = 1;
getList();
2025-11-06 23:23:25 +08:00
}
2025-11-04 17:32:12 +08:00
/** 查询列表 */
2025-11-06 23:23:25 +08:00
async function getList() {
2025-11-04 17:32:12 +08:00
loading.value = true;
try {
const data = await MpMaterialApi.getMaterialPage({
...queryParams,
type: type.value,
});
list.value = data.list;
total.value = data.total;
} finally {
loading.value = false;
}
2025-11-06 23:23:25 +08:00
}
2025-11-04 17:32:12 +08:00
/** 搜索按钮操作 */
2025-11-06 23:23:25 +08:00
function handleQuery() {
2025-11-04 17:32:12 +08:00
queryParams.pageNo = 1;
getList();
2025-11-06 23:23:25 +08:00
}
2025-11-04 17:32:12 +08:00
/** 处理 tab 切换 */
2025-11-06 23:23:25 +08:00
function onTabChange() {
2025-11-04 17:32:12 +08:00
// 提前清空数据,避免 tab 切换后显示垃圾数据
list.value = [];
total.value = 0;
// 从第一页开始查询
handleQuery();
2025-11-06 23:23:25 +08:00
}
2025-11-04 17:32:12 +08:00
/** 处理删除操作 */
2025-11-06 23:23:25 +08:00
async function handleDelete(id: number) {
2025-11-04 17:32:12 +08:00
Modal.confirm({
content: '此操作将永久删除该文件, 是否继续?',
title: '提示',
async onOk() {
await MpMaterialApi.deletePermanentMaterial(id);
message.success('删除成功');
await getList();
},
});
2025-11-06 23:23:25 +08:00
}
</script>
<template>
2025-11-04 17:32:12 +08:00
<Page
description="公众号素材"
doc-link="https://doc.iocoder.cn/mp/material/"
title="公众号素材"
>
<!-- 搜索工作栏 -->
2025-11-06 15:25:11 +08:00
<Card class="mb-4" :bordered="false">
<Form :model="queryParams" layout="inline">
<Form.Item label="公众号">
2025-11-04 17:32:12 +08:00
<WxAccountSelect @change="onAccountChanged" />
2025-11-06 15:25:11 +08:00
</Form.Item>
</Form>
</Card>
2025-11-04 17:32:12 +08:00
2025-11-06 15:25:11 +08:00
<Card :bordered="false">
2025-11-04 17:32:12 +08:00
<Tabs v-model:active-key="type" @change="onTabChange">
<!-- tab 1图片 -->
<Tabs.TabPane :key="UploadType.Image">
<template #tab>
<span class="flex items-center">
<IconifyIcon icon="mdi:image" class="mr-1" />
图片
</span>
</template>
<UploadFile
v-if="hasAccessByCodes(['mp:material:upload-permanent'])"
:type="UploadType.Image"
@uploaded="getList"
>
支持 bmp/png/jpeg/jpg/gif 格式大小不超过 2M
</UploadFile>
<!-- 列表 -->
<ImageTable :list="list" :loading="loading" @delete="handleDelete" />
<!-- 分页组件 -->
<div class="mt-4 flex justify-end">
2025-11-06 15:25:11 +08:00
<Pagination
2025-11-04 17:32:12 +08:00
v-model:current="queryParams.pageNo"
v-model:page-size="queryParams.pageSize"
:total="total"
show-size-changer
@change="getList"
@show-size-change="getList"
/>
</div>
</Tabs.TabPane>
<!-- tab 2语音 -->
<Tabs.TabPane :key="UploadType.Voice">
<template #tab>
2025-11-06 15:36:08 +08:00
<span class="flex items-center">
<IconifyIcon icon="mdi:microphone" class="mr-1" />
语音
</span>
2025-11-04 17:32:12 +08:00
</template>
<UploadFile
v-if="hasAccessByCodes(['mp:material:upload-permanent'])"
:type="UploadType.Voice"
@uploaded="getList"
>
格式支持 mp3/wma/wav/amr文件大小不超过 2M播放长度不超过 60s
</UploadFile>
<!-- 列表 -->
<VoiceTable :list="list" :loading="loading" @delete="handleDelete" />
<!-- 分页组件 -->
<div class="mt-4 flex justify-end">
2025-11-06 15:25:11 +08:00
<Pagination
2025-11-04 17:32:12 +08:00
v-model:current="queryParams.pageNo"
v-model:page-size="queryParams.pageSize"
:total="total"
show-size-changer
@change="getList"
@show-size-change="getList"
/>
</div>
</Tabs.TabPane>
<!-- tab 3视频 -->
<Tabs.TabPane :key="UploadType.Video">
<template #tab>
<span class="flex items-center">
<IconifyIcon icon="mdi:video" class="mr-1" />
视频
</span>
</template>
2025-11-06 15:25:11 +08:00
<Button
2025-11-04 17:32:12 +08:00
v-if="hasAccessByCodes(['mp:material:upload-permanent'])"
type="primary"
@click="showCreateVideo = true"
>
新建视频
2025-11-06 15:25:11 +08:00
</Button>
2025-11-04 17:32:12 +08:00
<!-- 新建视频的弹窗 -->
<UploadVideo v-model:open="showCreateVideo" @uploaded="getList" />
<!-- 列表 -->
<VideoTable :list="list" :loading="loading" @delete="handleDelete" />
<!-- 分页组件 -->
<div class="mt-4 flex justify-end">
2025-11-06 15:25:11 +08:00
<Pagination
2025-11-04 17:32:12 +08:00
v-model:current="queryParams.pageNo"
v-model:page-size="queryParams.pageSize"
:total="total"
show-size-changer
@change="getList"
@show-size-change="getList"
/>
</div>
</Tabs.TabPane>
</Tabs>
2025-11-06 15:25:11 +08:00
</Card>
</Page>
2025-04-22 22:10:33 +08:00
</template>