REVIEW 素材管理的重构
This commit is contained in:
parent
71fd9af2e1
commit
abf9b50c2f
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
@ -20,7 +20,6 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { UploadProps, UploadUserFile } from 'element-plus'
|
import type { UploadProps, UploadUserFile } from 'element-plus'
|
||||||
import {
|
import {
|
||||||
@ -66,5 +65,3 @@ const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
|
|||||||
emit('uploaded')
|
emit('uploaded')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
@ -123,5 +123,3 @@ const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
|
|||||||
emit('uploaded')
|
emit('uploaded')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
|
@ -57,5 +57,3 @@ const handleDownload = (url: string) => {
|
|||||||
window.open(url, '_blank')
|
window.open(url, '_blank')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
|
@ -49,5 +49,3 @@ const emit = defineEmits<{
|
|||||||
(e: 'delete', v: number)
|
(e: 'delete', v: number)
|
||||||
}>()
|
}>()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import type { UploadProps, UploadRawFile } from 'element-plus'
|
import type { UploadProps, UploadRawFile } from 'element-plus'
|
||||||
import { getAccessToken } from '@/utils/auth'
|
import { getAccessToken } from '@/utils/auth'
|
||||||
|
const message = useMessage() // 消息
|
||||||
const message = useMessage()
|
const HEADERS = { Authorization: 'Bearer ' + getAccessToken() } // 请求头
|
||||||
|
// const UPLOAD_URL = 'http://127.0.0.1:8000/upload/' // 上传地址
|
||||||
const HEADERS = { Authorization: 'Bearer ' + getAccessToken() }
|
const UPLOAD_URL = import.meta.env.VITE_BASE_URL + '/admin-api/mp/material/upload-permanent' // 上传地址
|
||||||
const UPLOAD_URL = 'http://127.0.0.1:8000/upload/' //import.meta.env.VITE_BASE_URL + '/admin-api/mp/material/upload-permanent'
|
|
||||||
|
|
||||||
enum MaterialType {
|
enum MaterialType {
|
||||||
Image = 'image',
|
Image = 'image',
|
||||||
@ -22,7 +21,6 @@ const beforeUpload = (rawFile: UploadRawFile, materialType: MaterialType): boole
|
|||||||
let allowTypes: string[] = []
|
let allowTypes: string[] = []
|
||||||
let maxSizeMB = 0
|
let maxSizeMB = 0
|
||||||
let name = ''
|
let name = ''
|
||||||
|
|
||||||
switch (materialType) {
|
switch (materialType) {
|
||||||
case MaterialType.Image:
|
case MaterialType.Image:
|
||||||
allowTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/jpg']
|
allowTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/jpg']
|
||||||
@ -38,18 +36,18 @@ const beforeUpload = (rawFile: UploadRawFile, materialType: MaterialType): boole
|
|||||||
allowTypes = ['video/mp4']
|
allowTypes = ['video/mp4']
|
||||||
maxSizeMB = 10
|
maxSizeMB = 10
|
||||||
name = '视频'
|
name = '视频'
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
// 格式不正确
|
||||||
if (!allowTypes.includes(rawFile.type)) {
|
if (!allowTypes.includes(rawFile.type)) {
|
||||||
message.error(`上传${name}格式不对!`)
|
message.error(`上传${name}格式不对!`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
// 大小不正确
|
||||||
if (rawFile.size / 1024 / 1024 > maxSizeMB) {
|
if (rawFile.size / 1024 / 1024 > maxSizeMB) {
|
||||||
message.error(`上传${name}大小不能超过${maxSizeMB}M!`)
|
message.error(`上传${name}大小不能超过${maxSizeMB}M!`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,15 @@
|
|||||||
<template #label>
|
<template #label>
|
||||||
<span> <Icon icon="ep:picture" />图片 </span>
|
<span> <Icon icon="ep:picture" />图片 </span>
|
||||||
</template>
|
</template>
|
||||||
<Upload
|
<UploadFile
|
||||||
v-hasPermi="['mp:material:upload-permanent']"
|
v-hasPermi="['mp:material:upload-permanent']"
|
||||||
:type="MaterialType.Image"
|
:type="MaterialType.Image"
|
||||||
@uploaded="getList"
|
@uploaded="getList"
|
||||||
>
|
>
|
||||||
支持 bmp/png/jpeg/jpg/gif 格式,大小不超过 2M
|
支持 bmp/png/jpeg/jpg/gif 格式,大小不超过 2M
|
||||||
</Upload>
|
</UploadFile>
|
||||||
<Waterfall :loading="loading" :list="list" @delete="handleDelete" />
|
<!-- 列表 -->
|
||||||
|
<ImageTable :loading="loading" :list="list" @delete="handleDelete" />
|
||||||
<!-- 分页组件 -->
|
<!-- 分页组件 -->
|
||||||
<Pagination
|
<Pagination
|
||||||
:total="total"
|
:total="total"
|
||||||
@ -38,14 +39,13 @@
|
|||||||
<template #label>
|
<template #label>
|
||||||
<span> <Icon icon="ep:microphone" />语音 </span>
|
<span> <Icon icon="ep:microphone" />语音 </span>
|
||||||
</template>
|
</template>
|
||||||
<Upload
|
<UploadFile
|
||||||
v-hasPermi="['mp:material:upload-permanent']"
|
v-hasPermi="['mp:material:upload-permanent']"
|
||||||
:type="MaterialType.Voice"
|
:type="MaterialType.Voice"
|
||||||
@uploaded="getList"
|
@uploaded="getList"
|
||||||
>
|
>
|
||||||
格式支持 mp3/wma/wav/amr,文件大小不超过 2M,播放长度不超过 60s
|
格式支持 mp3/wma/wav/amr,文件大小不超过 2M,播放长度不超过 60s
|
||||||
</Upload>
|
</UploadFile>
|
||||||
|
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<VoiceTable :list="list" :loading="loading" @delete="handleDelete" />
|
<VoiceTable :list="list" :loading="loading" @delete="handleDelete" />
|
||||||
<!-- 分页组件 -->
|
<!-- 分页组件 -->
|
||||||
@ -71,7 +71,6 @@
|
|||||||
>
|
>
|
||||||
<!-- 新建视频的弹窗 -->
|
<!-- 新建视频的弹窗 -->
|
||||||
<UploadVideo v-model="showCreateVideo" />
|
<UploadVideo v-model="showCreateVideo" />
|
||||||
|
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<VideoTable :list="list" :loading="loading" @delete="handleDelete" />
|
<VideoTable :list="list" :loading="loading" @delete="handleDelete" />
|
||||||
<!-- 分页组件 -->
|
<!-- 分页组件 -->
|
||||||
@ -85,21 +84,18 @@
|
|||||||
</el-tabs>
|
</el-tabs>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup name="MpMaterial">
|
<script lang="ts" setup name="MpMaterial">
|
||||||
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
|
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
|
||||||
import Waterfall from './components/Waterfall.vue'
|
import ImageTable from './components/ImageTable.vue'
|
||||||
import VoiceTable from './components/VoiceTable.vue'
|
import VoiceTable from './components/VoiceTable.vue'
|
||||||
import VideoTable from './components/VideoTable.vue'
|
import VideoTable from './components/VideoTable.vue'
|
||||||
import Upload from './components/Upload.vue'
|
import UploadFile from './components/UploadFile.vue'
|
||||||
import UploadVideo from './components/UploadVideo.vue'
|
import UploadVideo from './components/UploadVideo.vue'
|
||||||
import { MaterialType } from './components/upload'
|
import { MaterialType } from './components/upload'
|
||||||
import * as MpMaterialApi from '@/api/mp/material'
|
import * as MpMaterialApi from '@/api/mp/material'
|
||||||
|
const message = useMessage() // 消息
|
||||||
|
|
||||||
const message = useMessage()
|
const type = ref<MaterialType>(MaterialType.Image) // 素材类型
|
||||||
|
|
||||||
// 素材类型
|
|
||||||
const type = ref<MaterialType>(MaterialType.Image)
|
|
||||||
const loading = ref(false) // 遮罩层
|
const loading = ref(false) // 遮罩层
|
||||||
const list = ref<any[]>([]) // 总条数
|
const list = ref<any[]>([]) // 总条数
|
||||||
const total = ref(0) // 数据列表
|
const total = ref(0) // 数据列表
|
||||||
@ -116,9 +112,7 @@ const queryParams: QueryParams = reactive({
|
|||||||
accountId: undefined,
|
accountId: undefined,
|
||||||
permanent: true
|
permanent: true
|
||||||
})
|
})
|
||||||
|
const showCreateVideo = ref(false) // 是否新建视频的弹窗
|
||||||
// === 视频上传,独有变量 ===
|
|
||||||
const showCreateVideo = ref(false)
|
|
||||||
|
|
||||||
/** 侦听公众号变化 **/
|
/** 侦听公众号变化 **/
|
||||||
const onAccountChanged = (id?: number) => {
|
const onAccountChanged = (id?: number) => {
|
||||||
@ -126,7 +120,6 @@ const onAccountChanged = (id?: number) => {
|
|||||||
getList()
|
getList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 列表查询 ========================
|
|
||||||
/** 查询列表 */
|
/** 查询列表 */
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
@ -148,21 +141,19 @@ const handleQuery = () => {
|
|||||||
getList()
|
getList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 处理 table 切换 */
|
||||||
const onTabChange = () => {
|
const onTabChange = () => {
|
||||||
// 提前情况数据,避免tab切换后显示垃圾数据
|
// 提前情况数据,避免 tab 切换后显示垃圾数据
|
||||||
list.value = []
|
list.value = []
|
||||||
total.value = 0
|
total.value = 0
|
||||||
|
|
||||||
// 从第一页开始查询
|
// 从第一页开始查询
|
||||||
handleQuery()
|
handleQuery()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 其它操作 ========================
|
/** 处理删除操作 */
|
||||||
const handleDelete = async (id: number) => {
|
const handleDelete = async (id: number) => {
|
||||||
await message.confirm('此操作将永久删除该文件, 是否继续?')
|
await message.confirm('此操作将永久删除该文件, 是否继续?')
|
||||||
await MpMaterialApi.deletePermanentMaterial(id)
|
await MpMaterialApi.deletePermanentMaterial(id)
|
||||||
message.alertSuccess('删除成功')
|
message.alertSuccess('删除成功')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped></style>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user