2025-11-04 14:31:32 +08:00
|
|
|
|
<script lang="ts" setup>
|
2025-11-07 13:21:42 +08:00
|
|
|
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
2025-11-27 09:55:24 +08:00
|
|
|
|
import type { MpMaterialApi } from '#/api/mp/material';
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
2025-11-07 13:21:42 +08:00
|
|
|
|
import { reactive, ref, watch } from 'vue';
|
|
|
|
|
|
|
|
|
|
|
|
import { Page } from '@vben/common-ui';
|
2025-11-20 10:34:21 +08:00
|
|
|
|
import { NewsType } from '@vben/constants';
|
2025-11-04 14:31:32 +08:00
|
|
|
|
import { IconifyIcon } from '@vben/icons';
|
|
|
|
|
|
|
2025-11-07 13:21:42 +08:00
|
|
|
|
import { Button, Pagination, Row, Spin } from 'ant-design-vue';
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
2025-11-07 13:21:42 +08:00
|
|
|
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
2025-11-13 16:57:06 +08:00
|
|
|
|
import { getDraftPage } from '#/api/mp/draft';
|
|
|
|
|
|
import { getFreePublishPage } from '#/api/mp/freePublish';
|
|
|
|
|
|
import { getMaterialPage } from '#/api/mp/material';
|
2025-11-13 14:44:25 +08:00
|
|
|
|
import { WxNews, WxVideoPlayer, WxVoicePlayer } from '#/views/mp/components';
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
2025-11-20 21:09:02 +08:00
|
|
|
|
/** 微信素材选择 */
|
2025-11-04 14:31:32 +08:00
|
|
|
|
defineOptions({ name: 'WxMaterialSelect' });
|
|
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
|
|
defineProps<{
|
|
|
|
|
|
accountId: number;
|
|
|
|
|
|
newsType?: NewsType;
|
|
|
|
|
|
type: string;
|
|
|
|
|
|
}>(),
|
|
|
|
|
|
{
|
|
|
|
|
|
newsType: NewsType.Published,
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
|
(e: 'selectMaterial', item: any): void;
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
2025-11-13 13:57:17 +08:00
|
|
|
|
const loading = ref(false); // 遮罩层
|
|
|
|
|
|
const total = ref(0); // 总条数
|
|
|
|
|
|
const list = ref<any[]>([]); // 数据列表
|
2025-11-04 14:31:32 +08:00
|
|
|
|
const queryParams = reactive({
|
|
|
|
|
|
accountId: props.accountId,
|
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
|
pageSize: 10,
|
2025-11-13 13:57:17 +08:00
|
|
|
|
}); // 查询参数
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
2025-11-27 09:55:24 +08:00
|
|
|
|
const voiceGridColumns: VxeTableGridOptions<MpMaterialApi.Material>['columns'] =
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'mediaId',
|
|
|
|
|
|
title: '编号',
|
|
|
|
|
|
align: 'center',
|
|
|
|
|
|
minWidth: 160,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'name',
|
|
|
|
|
|
title: '文件名',
|
|
|
|
|
|
minWidth: 200,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'voice',
|
|
|
|
|
|
title: '语音',
|
|
|
|
|
|
minWidth: 200,
|
|
|
|
|
|
align: 'center',
|
|
|
|
|
|
slots: { default: 'voice' },
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'createTime',
|
|
|
|
|
|
title: '上传时间',
|
|
|
|
|
|
width: 180,
|
|
|
|
|
|
formatter: 'formatDateTime',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '操作',
|
|
|
|
|
|
width: 140,
|
|
|
|
|
|
fixed: 'right',
|
|
|
|
|
|
align: 'center',
|
|
|
|
|
|
slots: { default: 'actions' },
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
2025-11-27 09:55:24 +08:00
|
|
|
|
const videoGridColumns: VxeTableGridOptions<MpMaterialApi.Material>['columns'] =
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'mediaId',
|
|
|
|
|
|
title: '编号',
|
|
|
|
|
|
minWidth: 160,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'name',
|
|
|
|
|
|
title: '文件名',
|
|
|
|
|
|
minWidth: 200,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'title',
|
|
|
|
|
|
title: '标题',
|
|
|
|
|
|
minWidth: 200,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'introduction',
|
|
|
|
|
|
title: '介绍',
|
|
|
|
|
|
minWidth: 220,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'video',
|
|
|
|
|
|
title: '视频',
|
|
|
|
|
|
minWidth: 220,
|
|
|
|
|
|
align: 'center',
|
|
|
|
|
|
slots: { default: 'video' },
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'createTime',
|
|
|
|
|
|
title: '上传时间',
|
|
|
|
|
|
width: 180,
|
|
|
|
|
|
formatter: 'formatDateTime',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '操作',
|
|
|
|
|
|
width: 140,
|
|
|
|
|
|
fixed: 'right',
|
|
|
|
|
|
align: 'center',
|
|
|
|
|
|
slots: { default: 'actions' },
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
2025-11-07 13:21:42 +08:00
|
|
|
|
const [VoiceGrid, voiceGridApi] = useVbenVxeGrid({
|
|
|
|
|
|
gridOptions: {
|
|
|
|
|
|
border: true,
|
|
|
|
|
|
columns: voiceGridColumns,
|
|
|
|
|
|
height: 'auto',
|
|
|
|
|
|
keepSource: true,
|
|
|
|
|
|
pagerConfig: {
|
|
|
|
|
|
enabled: true,
|
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
|
},
|
|
|
|
|
|
proxyConfig: {
|
|
|
|
|
|
ajax: {
|
|
|
|
|
|
query: async ({ page }, { accountId }) => {
|
|
|
|
|
|
const finalAccountId = accountId ?? queryParams.accountId;
|
2025-11-27 09:55:24 +08:00
|
|
|
|
if (!finalAccountId) {
|
2025-11-07 13:21:42 +08:00
|
|
|
|
return { list: [], total: 0 };
|
|
|
|
|
|
}
|
2025-11-13 16:57:06 +08:00
|
|
|
|
return await getMaterialPage({
|
2025-11-07 13:21:42 +08:00
|
|
|
|
pageNo: page.currentPage,
|
|
|
|
|
|
pageSize: page.pageSize,
|
|
|
|
|
|
accountId: finalAccountId,
|
|
|
|
|
|
type: 'voice',
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
rowConfig: {
|
|
|
|
|
|
keyField: 'mediaId',
|
|
|
|
|
|
isHover: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
toolbarConfig: {
|
|
|
|
|
|
refresh: true,
|
|
|
|
|
|
},
|
2025-11-27 09:55:24 +08:00
|
|
|
|
} as VxeTableGridOptions<MpMaterialApi.Material>,
|
2025-11-07 13:21:42 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const [VideoGrid, videoGridApi] = useVbenVxeGrid({
|
|
|
|
|
|
gridOptions: {
|
|
|
|
|
|
border: true,
|
|
|
|
|
|
columns: videoGridColumns,
|
|
|
|
|
|
height: 'auto',
|
|
|
|
|
|
keepSource: true,
|
|
|
|
|
|
pagerConfig: {
|
|
|
|
|
|
enabled: true,
|
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
|
},
|
|
|
|
|
|
proxyConfig: {
|
|
|
|
|
|
ajax: {
|
|
|
|
|
|
query: async ({ page }, { accountId }) => {
|
|
|
|
|
|
const finalAccountId = accountId ?? queryParams.accountId;
|
|
|
|
|
|
if (finalAccountId === undefined || finalAccountId === null) {
|
|
|
|
|
|
return { list: [], total: 0 };
|
|
|
|
|
|
}
|
2025-11-13 16:57:06 +08:00
|
|
|
|
return await getMaterialPage({
|
2025-11-07 13:21:42 +08:00
|
|
|
|
pageNo: page.currentPage,
|
|
|
|
|
|
pageSize: page.pageSize,
|
|
|
|
|
|
accountId: finalAccountId,
|
|
|
|
|
|
type: 'video',
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
rowConfig: {
|
|
|
|
|
|
keyField: 'mediaId',
|
|
|
|
|
|
isHover: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
toolbarConfig: {
|
|
|
|
|
|
refresh: true,
|
|
|
|
|
|
},
|
2025-11-27 09:55:24 +08:00
|
|
|
|
} as VxeTableGridOptions<MpMaterialApi.Material>,
|
2025-11-04 14:31:32 +08:00
|
|
|
|
});
|
2025-11-07 13:21:42 +08:00
|
|
|
|
|
|
|
|
|
|
function selectMaterialFun(item: any) {
|
|
|
|
|
|
emit('selectMaterial', item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getMaterialPageFun() {
|
2025-11-13 16:57:06 +08:00
|
|
|
|
const data = await getMaterialPage({
|
2025-11-07 13:21:42 +08:00
|
|
|
|
...queryParams,
|
|
|
|
|
|
type: props.type,
|
|
|
|
|
|
});
|
|
|
|
|
|
list.value = data.list;
|
|
|
|
|
|
total.value = data.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getFreePublishPageFun() {
|
2025-11-13 16:57:06 +08:00
|
|
|
|
const data = await getFreePublishPage(queryParams);
|
2025-11-07 13:21:42 +08:00
|
|
|
|
data.list.forEach((item: any) => {
|
|
|
|
|
|
const articles = item.content.newsItem;
|
|
|
|
|
|
articles.forEach((article: any) => {
|
|
|
|
|
|
article.picUrl = article.thumbUrl;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
list.value = data.list;
|
|
|
|
|
|
total.value = data.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getDraftPageFun() {
|
2025-11-13 16:57:06 +08:00
|
|
|
|
const data = await getDraftPage(queryParams);
|
2025-11-07 13:21:42 +08:00
|
|
|
|
data.list.forEach((draft: any) => {
|
|
|
|
|
|
const articles = draft.content.newsItem;
|
|
|
|
|
|
articles.forEach((article: any) => {
|
|
|
|
|
|
article.picUrl = article.thumbUrl;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
list.value = data.list;
|
|
|
|
|
|
total.value = data.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getPage() {
|
|
|
|
|
|
if (props.type === 'voice') {
|
|
|
|
|
|
await voiceGridApi.reload({ accountId: queryParams.accountId });
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (props.type === 'video') {
|
|
|
|
|
|
await videoGridApi.reload({ accountId: queryParams.accountId });
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loading.value = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (props.type === 'news' && props.newsType === NewsType.Published) {
|
|
|
|
|
|
await getFreePublishPageFun();
|
|
|
|
|
|
} else if (props.type === 'news' && props.newsType === NewsType.Draft) {
|
|
|
|
|
|
await getDraftPageFun();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
await getMaterialPageFun();
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => props.accountId,
|
|
|
|
|
|
(accountId) => {
|
|
|
|
|
|
queryParams.accountId = accountId;
|
|
|
|
|
|
queryParams.pageNo = 1;
|
|
|
|
|
|
getPage();
|
|
|
|
|
|
},
|
|
|
|
|
|
{ immediate: true },
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => props.type,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
queryParams.pageNo = 1;
|
|
|
|
|
|
getPage();
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => props.newsType,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
if (props.type === 'news') {
|
|
|
|
|
|
queryParams.pageNo = 1;
|
|
|
|
|
|
getPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
2025-11-04 14:31:32 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-11-07 13:21:42 +08:00
|
|
|
|
<Page :bordered="false" class="pb-8">
|
2025-11-04 14:31:32 +08:00
|
|
|
|
<!-- 类型:image -->
|
2025-11-07 13:21:42 +08:00
|
|
|
|
<template v-if="props.type === 'image'">
|
2025-11-04 14:31:32 +08:00
|
|
|
|
<Spin :spinning="loading">
|
2025-11-25 14:42:56 +08:00
|
|
|
|
<div
|
|
|
|
|
|
class="mx-auto w-full columns-1 [column-gap:10px] md:columns-2 lg:columns-3 xl:columns-4 2xl:columns-5"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-for="item in list"
|
|
|
|
|
|
:key="item.mediaId"
|
2025-11-27 09:55:24 +08:00
|
|
|
|
class="mb-2.5 h-72 break-inside-avoid border border-[#eaeaea] p-2.5"
|
2025-11-25 14:42:56 +08:00
|
|
|
|
>
|
2025-11-27 09:55:24 +08:00
|
|
|
|
<img
|
|
|
|
|
|
class="h-48 w-full object-contain"
|
|
|
|
|
|
:src="item.url"
|
|
|
|
|
|
alt="素材图片"
|
|
|
|
|
|
/>
|
2025-11-25 14:42:56 +08:00
|
|
|
|
<p class="truncate text-center text-xs leading-[30px]">
|
|
|
|
|
|
{{ item.name }}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<Row class="flex justify-center pt-2.5">
|
2025-11-04 14:31:32 +08:00
|
|
|
|
<Button type="primary" @click="selectMaterialFun(item)">
|
|
|
|
|
|
选择
|
|
|
|
|
|
<template #icon>
|
2025-11-13 18:36:35 +08:00
|
|
|
|
<IconifyIcon icon="lucide:circle-check" />
|
2025-11-04 14:31:32 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Spin>
|
|
|
|
|
|
<Pagination
|
|
|
|
|
|
v-model:current="queryParams.pageNo"
|
|
|
|
|
|
v-model:page-size="queryParams.pageSize"
|
|
|
|
|
|
:total="total"
|
|
|
|
|
|
class="mt-4"
|
2025-11-07 13:21:42 +08:00
|
|
|
|
@change="getPage"
|
|
|
|
|
|
@show-size-change="getPage"
|
2025-11-04 14:31:32 +08:00
|
|
|
|
/>
|
2025-11-07 13:21:42 +08:00
|
|
|
|
</template>
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 类型:voice -->
|
2025-11-07 13:21:42 +08:00
|
|
|
|
<template v-else-if="props.type === 'voice'">
|
|
|
|
|
|
<VoiceGrid>
|
|
|
|
|
|
<template #voice="{ row }">
|
|
|
|
|
|
<WxVoicePlayer :url="row.url" />
|
2025-11-04 14:31:32 +08:00
|
|
|
|
</template>
|
2025-11-07 13:21:42 +08:00
|
|
|
|
<template #actions="{ row }">
|
|
|
|
|
|
<Button type="link" @click="selectMaterialFun(row)">
|
|
|
|
|
|
选择
|
|
|
|
|
|
<template #icon>
|
2025-11-13 18:36:35 +08:00
|
|
|
|
<IconifyIcon icon="lucide:plus" />
|
2025-11-07 13:21:42 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</VoiceGrid>
|
|
|
|
|
|
</template>
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 类型:video -->
|
2025-11-07 13:21:42 +08:00
|
|
|
|
<template v-else-if="props.type === 'video'">
|
|
|
|
|
|
<VideoGrid>
|
|
|
|
|
|
<template #video="{ row }">
|
|
|
|
|
|
<WxVideoPlayer :url="row.url" />
|
2025-11-04 14:31:32 +08:00
|
|
|
|
</template>
|
2025-11-07 13:21:42 +08:00
|
|
|
|
<template #actions="{ row }">
|
|
|
|
|
|
<Button type="link" @click="selectMaterialFun(row)">
|
|
|
|
|
|
选择
|
|
|
|
|
|
<template #icon>
|
2025-11-13 18:36:35 +08:00
|
|
|
|
<IconifyIcon icon="lucide:circle-plus" />
|
2025-11-07 13:21:42 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</VideoGrid>
|
|
|
|
|
|
</template>
|
2025-11-04 14:31:32 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 类型:news -->
|
2025-11-07 13:21:42 +08:00
|
|
|
|
<template v-else-if="props.type === 'news'">
|
2025-11-04 14:31:32 +08:00
|
|
|
|
<Spin :spinning="loading">
|
2025-11-25 14:42:56 +08:00
|
|
|
|
<div
|
|
|
|
|
|
class="mx-auto w-full columns-1 [column-gap:10px] md:columns-2 lg:columns-3 xl:columns-4 2xl:columns-5"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-for="item in list"
|
|
|
|
|
|
:key="item.mediaId"
|
|
|
|
|
|
class="mb-2.5 break-inside-avoid border border-[#eaeaea] p-2.5"
|
|
|
|
|
|
>
|
2025-11-04 14:31:32 +08:00
|
|
|
|
<div v-if="item.content && item.content.newsItem">
|
|
|
|
|
|
<WxNews :articles="item.content.newsItem" />
|
2025-11-25 14:42:56 +08:00
|
|
|
|
<Row class="flex justify-center pt-2.5">
|
2025-11-04 14:31:32 +08:00
|
|
|
|
<Button type="primary" @click="selectMaterialFun(item)">
|
|
|
|
|
|
选择
|
|
|
|
|
|
<template #icon>
|
2025-11-13 18:36:35 +08:00
|
|
|
|
<IconifyIcon icon="lucide:circle-check" />
|
2025-11-04 14:31:32 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Spin>
|
|
|
|
|
|
<Pagination
|
|
|
|
|
|
v-model:current="queryParams.pageNo"
|
|
|
|
|
|
v-model:page-size="queryParams.pageSize"
|
|
|
|
|
|
:total="total"
|
|
|
|
|
|
class="mt-4"
|
2025-11-07 13:21:42 +08:00
|
|
|
|
@change="getPage"
|
|
|
|
|
|
@show-size-change="getPage"
|
2025-11-04 14:31:32 +08:00
|
|
|
|
/>
|
2025-11-07 13:21:42 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</Page>
|
2025-11-04 14:31:32 +08:00
|
|
|
|
</template>
|