From 4d6369a514a39cf1161ba6299e4eedeed9e174f8 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Sat, 15 Apr 2023 15:59:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20MP=E6=B6=88=E6=81=AF=E7=AE=A1?= =?UTF-8?q?=E7=90=86-=E6=8B=86=E5=88=86=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 389c73d834ad710c1398581314cb96787078b954) --- src/views/mp/material/components/Upload.vue | 70 +++ .../mp/material/components/UploadVideo.vue | 127 ++++++ .../mp/material/components/VideoTable.vue | 61 +++ .../mp/material/components/VoiceTable.vue | 53 +++ .../mp/material/components/Waterfall.vue | 83 ++++ src/views/mp/material/components/upload.ts | 73 +++ src/views/mp/material/index.vue | 424 ++---------------- 7 files changed, 507 insertions(+), 384 deletions(-) create mode 100644 src/views/mp/material/components/Upload.vue create mode 100644 src/views/mp/material/components/UploadVideo.vue create mode 100644 src/views/mp/material/components/VideoTable.vue create mode 100644 src/views/mp/material/components/VoiceTable.vue create mode 100644 src/views/mp/material/components/Waterfall.vue create mode 100644 src/views/mp/material/components/upload.ts diff --git a/src/views/mp/material/components/Upload.vue b/src/views/mp/material/components/Upload.vue new file mode 100644 index 00000000..541dbc20 --- /dev/null +++ b/src/views/mp/material/components/Upload.vue @@ -0,0 +1,70 @@ + + + + + diff --git a/src/views/mp/material/components/UploadVideo.vue b/src/views/mp/material/components/UploadVideo.vue new file mode 100644 index 00000000..5da7d980 --- /dev/null +++ b/src/views/mp/material/components/UploadVideo.vue @@ -0,0 +1,127 @@ + + + + + diff --git a/src/views/mp/material/components/VideoTable.vue b/src/views/mp/material/components/VideoTable.vue new file mode 100644 index 00000000..3bd2fe00 --- /dev/null +++ b/src/views/mp/material/components/VideoTable.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/src/views/mp/material/components/VoiceTable.vue b/src/views/mp/material/components/VoiceTable.vue new file mode 100644 index 00000000..44bd01da --- /dev/null +++ b/src/views/mp/material/components/VoiceTable.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/src/views/mp/material/components/Waterfall.vue b/src/views/mp/material/components/Waterfall.vue new file mode 100644 index 00000000..118fc7bd --- /dev/null +++ b/src/views/mp/material/components/Waterfall.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/src/views/mp/material/components/upload.ts b/src/views/mp/material/components/upload.ts new file mode 100644 index 00000000..37441f5b --- /dev/null +++ b/src/views/mp/material/components/upload.ts @@ -0,0 +1,73 @@ +import type { UploadProps, UploadRawFile } from 'element-plus' +import { getAccessToken } from '@/utils/auth' + +const message = useMessage() + +const HEADERS = { Authorization: 'Bearer ' + getAccessToken() } +const UPLOAD_URL = 'http://127.0.0.1:8000/upload/' //import.meta.env.VITE_BASE_URL + '/admin-api/mp/material/upload-permanent' + +enum MaterialType { + Image = 'image', + Voice = 'voice', + Video = 'video' +} + +interface UploadData { + type: MaterialType + title: string + introduction: string +} + +const beforeUpload = (rawFile: UploadRawFile, materialType: MaterialType): boolean => { + let allowTypes: string[] = [] + let maxSizeMB = 0 + let name = '' + + switch (materialType) { + case MaterialType.Image: + allowTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/jpg'] + maxSizeMB = 2 + name = '图片' + break + case MaterialType.Voice: + allowTypes = ['audio/mp3', 'audio/mpeg', 'audio/wma', 'audio/wav', 'audio/amr'] + maxSizeMB = 2 + name = '图片' + break + case MaterialType.Video: + allowTypes = ['video/mp4'] + maxSizeMB = 10 + name = '视频' + } + + if (!allowTypes.includes(rawFile.type)) { + message.error(`上传${name}格式不对!`) + return false + } + + if (rawFile.size / 1024 / 1024 > maxSizeMB) { + message.error(`上传${name}大小不能超过${maxSizeMB}M!`) + return false + } + + return true +} + +const beforeImageUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => + beforeUpload(rawFile, MaterialType.Image) + +const beforeVoiceUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => + beforeUpload(rawFile, MaterialType.Voice) + +const beforeVideoUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => + beforeUpload(rawFile, MaterialType.Video) + +export { + HEADERS, + UPLOAD_URL, + MaterialType, + UploadData, + beforeImageUpload, + beforeVoiceUpload, + beforeVideoUpload +} diff --git a/src/views/mp/material/index.vue b/src/views/mp/material/index.vue index 6c1d085f..40c03968 100644 --- a/src/views/mp/material/index.vue +++ b/src/views/mp/material/index.vue @@ -11,47 +11,18 @@ - + -
- - 点击上传 - - -
-
- -
+ + 支持 bmp/png/jpeg/jpg/gif 格式,大小不超过 2M + + - + -
- - 点击上传 - - -
+ + 格式支持 mp3/wma/wav/amr,文件大小不超过 2M,播放长度不超过 60s + - - - - - - - - - - - - - + - + -
- 新建视频 -
- - 新建视频 - - - 格式支持 MP4,文件大小不超过 10MB - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + - +