Skip to content

Commit abf9b50

Browse files
committed
REVIEW 素材管理的重构
1 parent 71fd9af commit abf9b50

File tree

8 files changed

+21
-41
lines changed

8 files changed

+21
-41
lines changed

src/views/mp/components/img.png

-15 KB
Binary file not shown.

src/views/mp/material/components/Upload.vue renamed to src/views/mp/material/components/UploadFile.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
</template>
2121
</el-upload>
2222
</template>
23-
2423
<script setup lang="ts">
2524
import type { UploadProps, UploadUserFile } from 'element-plus'
2625
import {
@@ -66,5 +65,3 @@ const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
6665
emit('uploaded')
6766
}
6867
</script>
69-
70-
<style scoped></style>

src/views/mp/material/components/UploadVideo.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,3 @@ const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
123123
emit('uploaded')
124124
}
125125
</script>
126-
127-
<style scoped></style>

src/views/mp/material/components/VideoTable.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,3 @@ const handleDownload = (url: string) => {
5757
window.open(url, '_blank')
5858
}
5959
</script>
60-
61-
<style scoped></style>

src/views/mp/material/components/VoiceTable.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,3 @@ const emit = defineEmits<{
4949
(e: 'delete', v: number)
5050
}>()
5151
</script>
52-
53-
<style scoped></style>

src/views/mp/material/components/upload.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { UploadProps, UploadRawFile } from 'element-plus'
22
import { getAccessToken } from '@/utils/auth'
3-
4-
const message = useMessage()
5-
6-
const HEADERS = { Authorization: 'Bearer ' + getAccessToken() }
7-
const UPLOAD_URL = 'http://127.0.0.1:8000/upload/' //import.meta.env.VITE_BASE_URL + '/admin-api/mp/material/upload-permanent'
3+
const message = useMessage() // 消息
4+
const HEADERS = { Authorization: 'Bearer ' + getAccessToken() } // 请求头
5+
// const UPLOAD_URL = 'http://127.0.0.1:8000/upload/' // 上传地址
6+
const UPLOAD_URL = import.meta.env.VITE_BASE_URL + '/admin-api/mp/material/upload-permanent' // 上传地址
87

98
enum MaterialType {
109
Image = 'image',
@@ -22,7 +21,6 @@ const beforeUpload = (rawFile: UploadRawFile, materialType: MaterialType): boole
2221
let allowTypes: string[] = []
2322
let maxSizeMB = 0
2423
let name = ''
25-
2624
switch (materialType) {
2725
case MaterialType.Image:
2826
allowTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/jpg']
@@ -38,18 +36,18 @@ const beforeUpload = (rawFile: UploadRawFile, materialType: MaterialType): boole
3836
allowTypes = ['video/mp4']
3937
maxSizeMB = 10
4038
name = '视频'
39+
break
4140
}
42-
41+
// 格式不正确
4342
if (!allowTypes.includes(rawFile.type)) {
4443
message.error(`上传${name}格式不对!`)
4544
return false
4645
}
47-
46+
// 大小不正确
4847
if (rawFile.size / 1024 / 1024 > maxSizeMB) {
4948
message.error(`上传${name}大小不能超过${maxSizeMB}M!`)
5049
return false
5150
}
52-
5351
return true
5452
}
5553

src/views/mp/material/index.vue

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
<template #label>
1717
<span> <Icon icon="ep:picture" />图片 </span>
1818
</template>
19-
<Upload
19+
<UploadFile
2020
v-hasPermi="['mp:material:upload-permanent']"
2121
:type="MaterialType.Image"
2222
@uploaded="getList"
2323
>
2424
支持 bmp/png/jpeg/jpg/gif 格式,大小不超过 2M
25-
</Upload>
26-
<Waterfall :loading="loading" :list="list" @delete="handleDelete" />
25+
</UploadFile>
26+
<!-- 列表 -->
27+
<ImageTable :loading="loading" :list="list" @delete="handleDelete" />
2728
<!-- 分页组件 -->
2829
<Pagination
2930
:total="total"
@@ -38,14 +39,13 @@
3839
<template #label>
3940
<span> <Icon icon="ep:microphone" />语音 </span>
4041
</template>
41-
<Upload
42+
<UploadFile
4243
v-hasPermi="['mp:material:upload-permanent']"
4344
:type="MaterialType.Voice"
4445
@uploaded="getList"
4546
>
4647
格式支持 mp3/wma/wav/amr,文件大小不超过 2M,播放长度不超过 60s
47-
</Upload>
48-
48+
</UploadFile>
4949
<!-- 列表 -->
5050
<VoiceTable :list="list" :loading="loading" @delete="handleDelete" />
5151
<!-- 分页组件 -->
@@ -71,7 +71,6 @@
7171
>
7272
<!-- 新建视频的弹窗 -->
7373
<UploadVideo v-model="showCreateVideo" />
74-
7574
<!-- 列表 -->
7675
<VideoTable :list="list" :loading="loading" @delete="handleDelete" />
7776
<!-- 分页组件 -->
@@ -85,21 +84,18 @@
8584
</el-tabs>
8685
</ContentWrap>
8786
</template>
88-
8987
<script lang="ts" setup name="MpMaterial">
9088
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
91-
import Waterfall from './components/Waterfall.vue'
89+
import ImageTable from './components/ImageTable.vue'
9290
import VoiceTable from './components/VoiceTable.vue'
9391
import VideoTable from './components/VideoTable.vue'
94-
import Upload from './components/Upload.vue'
92+
import UploadFile from './components/UploadFile.vue'
9593
import UploadVideo from './components/UploadVideo.vue'
9694
import { MaterialType } from './components/upload'
9795
import * as MpMaterialApi from '@/api/mp/material'
96+
const message = useMessage() // 消息
9897
99-
const message = useMessage()
100-
101-
// 素材类型
102-
const type = ref<MaterialType>(MaterialType.Image)
98+
const type = ref<MaterialType>(MaterialType.Image) // 素材类型
10399
const loading = ref(false) // 遮罩层
104100
const list = ref<any[]>([]) // 总条数
105101
const total = ref(0) // 数据列表
@@ -116,17 +112,14 @@ const queryParams: QueryParams = reactive({
116112
accountId: undefined,
117113
permanent: true
118114
})
119-
120-
// === 视频上传,独有变量 ===
121-
const showCreateVideo = ref(false)
115+
const showCreateVideo = ref(false) // 是否新建视频的弹窗
122116
123117
/** 侦听公众号变化 **/
124118
const onAccountChanged = (id?: number) => {
125119
queryParams.accountId = id
126120
getList()
127121
}
128122
129-
// ======================== 列表查询 ========================
130123
/** 查询列表 */
131124
const getList = async () => {
132125
loading.value = true
@@ -148,21 +141,19 @@ const handleQuery = () => {
148141
getList()
149142
}
150143
144+
/** 处理 table 切换 */
151145
const onTabChange = () => {
152-
// 提前情况数据,避免tab切换后显示垃圾数据
146+
// 提前情况数据,避免 tab 切换后显示垃圾数据
153147
list.value = []
154148
total.value = 0
155-
156149
// 从第一页开始查询
157150
handleQuery()
158151
}
159152
160-
// ======================== 其它操作 ========================
153+
/** 处理删除操作 */
161154
const handleDelete = async (id: number) => {
162155
await message.confirm('此操作将永久删除该文件, 是否继续?')
163156
await MpMaterialApi.deletePermanentMaterial(id)
164157
message.alertSuccess('删除成功')
165158
}
166159
</script>
167-
168-
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)