Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cddf1ee8
authored
Apr 18, 2023
by
dhb52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 使用useUpload
parent
0beda6ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
45 deletions
+6
-45
src/views/mp/material/components/upload.ts
+5
-44
src/views/mp/menu/components/MenuPreviewer.vue
+1
-1
No files found.
src/views/mp/material/components/upload.ts
View file @
cddf1ee8
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
()
// 消息
import
{
MaterialType
,
useBeforeUpload
}
from
'@/views/mp/hooks/useUpload'
const
HEADERS
=
{
Authorization
:
'Bearer '
+
getAccessToken
()
}
// 请求头
const
HEADERS
=
{
Authorization
:
'Bearer '
+
getAccessToken
()
}
// 请求头
const
UPLOAD_URL
=
import
.
meta
.
env
.
VITE_BASE_URL
+
'/admin-api/mp/material/upload-permanent'
// 上传地址
const
UPLOAD_URL
=
import
.
meta
.
env
.
VITE_BASE_URL
+
'/admin-api/mp/material/upload-permanent'
// 上传地址
enum
MaterialType
{
Image
=
'image'
,
Voice
=
'voice'
,
Video
=
'video'
}
interface
UploadData
{
interface
UploadData
{
type
:
MaterialType
type
:
MaterialType
title
:
string
title
:
string
introduction
:
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
=
'视频'
break
}
// 格式不正确
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
)
=>
const
beforeImageUpload
:
UploadProps
[
'beforeUpload'
]
=
(
rawFile
:
UploadRawFile
)
=>
beforeUpload
(
rawFile
,
MaterialType
.
Imag
e
)
useBeforeUpload
(
MaterialType
.
Image
,
2
)(
rawFil
e
)
const
beforeVoiceUpload
:
UploadProps
[
'beforeUpload'
]
=
(
rawFile
:
UploadRawFile
)
=>
const
beforeVoiceUpload
:
UploadProps
[
'beforeUpload'
]
=
(
rawFile
:
UploadRawFile
)
=>
beforeUpload
(
rawFile
,
MaterialType
.
Voic
e
)
useBeforeUpload
(
MaterialType
.
Voice
,
2
)(
rawFil
e
)
const
beforeVideoUpload
:
UploadProps
[
'beforeUpload'
]
=
(
rawFile
:
UploadRawFile
)
=>
const
beforeVideoUpload
:
UploadProps
[
'beforeUpload'
]
=
(
rawFile
:
UploadRawFile
)
=>
beforeUpload
(
rawFile
,
MaterialType
.
Video
)
useBeforeUpload
(
MaterialType
.
Video
,
10
)(
rawFile
)
export
{
export
{
HEADERS
,
HEADERS
,
...
...
src/views/mp/menu/components/MenuPreviewer.vue
View file @
cddf1ee8
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
<div
<div
class=
"menu_subItem"
class=
"menu_subItem"
v-if=
"parent.children"
v-if=
"parent.children"
:class=
"
{ active: activeIndex === `${x}-${y}` }"
:class=
"
{ active:
props.
activeIndex === `${x}-${y}` }"
@click="subMenuClicked(child, x, y)"
@click="subMenuClicked(child, x, y)"
>
>
{{
child
.
name
}}
{{
child
.
name
}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment