feat: 素材管理迁移
This commit is contained in:
@@ -1,29 +1,204 @@
|
||||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import { provide, reactive, ref } from 'vue';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { useAccess } from '@vben/access';
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { message, Modal, Tabs } from 'ant-design-vue';
|
||||
|
||||
import * as MpMaterialApi from '#/api/mp/material';
|
||||
import WxAccountSelect from '#/views/mp/components/wx-account-select';
|
||||
|
||||
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,
|
||||
});
|
||||
const showCreateVideo = ref(false); // 是否新建视频的弹窗
|
||||
|
||||
/** 侦听公众号变化 */
|
||||
const onAccountChanged = (id: number) => {
|
||||
accountId.value = id;
|
||||
queryParams.accountId = id;
|
||||
queryParams.pageNo = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNo = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 处理 tab 切换 */
|
||||
const onTabChange = () => {
|
||||
// 提前清空数据,避免 tab 切换后显示垃圾数据
|
||||
list.value = [];
|
||||
total.value = 0;
|
||||
// 从第一页开始查询
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 处理删除操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
Modal.confirm({
|
||||
content: '此操作将永久删除该文件, 是否继续?',
|
||||
title: '提示',
|
||||
async onOk() {
|
||||
await MpMaterialApi.deletePermanentMaterial(id);
|
||||
message.success('删除成功');
|
||||
await getList();
|
||||
},
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<DocAlert title="公众号素材" url="https://doc.iocoder.cn/mp/material/" />
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mp/material/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mp/material/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<Page
|
||||
description="公众号素材"
|
||||
doc-link="https://doc.iocoder.cn/mp/material/"
|
||||
title="公众号素材"
|
||||
>
|
||||
<!-- 搜索工作栏 -->
|
||||
<a-card class="mb-4" :bordered="false">
|
||||
<a-form :model="queryParams" layout="inline">
|
||||
<a-form-item label="公众号">
|
||||
<WxAccountSelect @change="onAccountChanged" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-card>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<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">
|
||||
<a-pagination
|
||||
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>
|
||||
<span class="flex items-center">
|
||||
<IconifyIcon icon="mdi:microphone" class="mr-1" />
|
||||
语音
|
||||
</span>
|
||||
</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">
|
||||
<a-pagination
|
||||
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>
|
||||
<a-button
|
||||
v-if="hasAccessByCodes(['mp:material:upload-permanent'])"
|
||||
type="primary"
|
||||
@click="showCreateVideo = true"
|
||||
>
|
||||
新建视频
|
||||
</a-button>
|
||||
<!-- 新建视频的弹窗 -->
|
||||
<UploadVideo v-model:open="showCreateVideo" @uploaded="getList" />
|
||||
<!-- 列表 -->
|
||||
<VideoTable :list="list" :loading="loading" @delete="handleDelete" />
|
||||
<!-- 分页组件 -->
|
||||
<div class="mt-4 flex justify-end">
|
||||
<a-pagination
|
||||
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>
|
||||
</a-card>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user