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
39d8ecbf
authored
Apr 18, 2023
by
dhb52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: MP/wx-reply组件,抽离useUpload钩子
parent
c27be373
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
src/views/mp/components/wx-reply/main.vue
+0
-0
src/views/mp/hooks/useUpload.ts
+50
-0
No files found.
src/views/mp/components/wx-reply/main.vue
View file @
39d8ecbf
This diff is collapsed.
Click to expand it.
src/views/mp/hooks/useUpload.ts
0 → 100644
View file @
39d8ecbf
import
type
{
UploadRawFile
}
from
'element-plus'
const
message
=
useMessage
()
// 消息
enum
MaterialType
{
Image
=
'image'
,
Voice
=
'voice'
,
Video
=
'video'
}
const
useBeforeUpload
=
(
type
:
MaterialType
,
maxSizeMB
:
number
)
=>
{
const
fn
=
(
rawFile
:
UploadRawFile
):
boolean
=>
{
let
allowTypes
:
string
[]
=
[]
let
name
=
''
switch
(
type
)
{
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
}
return
fn
}
export
{
MaterialType
,
useBeforeUpload
}
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