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
84dcac77
authored
Apr 16, 2023
by
dhb52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 事件函数命名:onXxx
parent
b5fb700e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
20 deletions
+34
-20
src/views/mp/material/components/UploadFile.vue
+21
-10
src/views/mp/material/components/UploadVideo.vue
+13
-9
src/views/mp/material/components/upload.ts
+0
-1
No files found.
src/views/mp/material/components/UploadFile.vue
View file @
84dcac77
...
...
@@ -6,13 +6,13 @@
:limit=
"1"
:file-list=
"fileList"
:data=
"uploadData"
:on-progress=
"(
) => (u
ploading = true)"
:on-error=
"
(err: Error) => message.error(`上传失败: $
{err.message}`)
"
:before-upload="
b
eforeUpload"
:on-success="
handle
UploadSuccess"
:on-progress=
"(
isU
ploading = true)"
:on-error=
"
onUploadError
"
:before-upload=
"
onB
eforeUpload"
:on-success=
"
on
UploadSuccess"
>
<el-button
type=
"primary"
plain
:loading=
"
uploading"
:disabled=
"u
ploading"
>
{{
u
ploading
?
'正在上传'
:
'点击上传'
}}
<el-button
type=
"primary"
plain
:loading=
"
isUploading"
:disabled=
"isU
ploading"
>
{{
isU
ploading
?
'正在上传'
:
'点击上传'
}}
</el-button>
<template
#
tip
>
<span
class=
"el-upload__tip"
style=
"margin-left: 5px"
>
...
...
@@ -46,11 +46,13 @@ const uploadData: UploadData = reactive({
title
:
''
,
introduction
:
''
})
const
u
ploading
=
ref
(
false
)
const
isU
ploading
=
ref
(
false
)
const
beforeUpload
=
props
.
type
===
MaterialType
.
Image
?
beforeImageUpload
:
beforeVoiceUpload
/** 上传前检查 */
const
onBeforeUpload
=
props
.
type
===
MaterialType
.
Image
?
beforeImageUpload
:
beforeVoiceUpload
const
handleUploadSuccess
:
UploadProps
[
'onSuccess'
]
=
(
res
:
any
)
=>
{
/** 上传成功处理 */
const
onUploadSuccess
:
UploadProps
[
'onSuccess'
]
=
(
res
:
any
)
=>
{
if
(
res
.
code
!==
0
)
{
message
.
alertError
(
'上传出错:'
+
res
.
msg
)
return
false
...
...
@@ -62,7 +64,16 @@ const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
uploadData
.
introduction
=
''
message
.
notifySuccess
(
'上传成功'
)
u
ploading
.
value
=
false
isU
ploading
.
value
=
false
emit
(
'uploaded'
)
}
/** 上传失败处理 */
const
onUploadError
=
(
err
:
Error
)
=>
message
.
error
(
'上传失败: '
+
err
.
message
)
</
script
>
<
style
lang=
"scss"
scoped
>
.el-upload__tip
{
margin-left
:
5px
;
}
</
style
>
src/views/mp/material/components/UploadVideo.vue
View file @
84dcac77
...
...
@@ -8,9 +8,9 @@
:file-list=
"fileList"
:data=
"uploadData"
:before-upload=
"beforeVideoUpload"
:on-progress=
"(
) => (u
ploading = true)"
:on-error=
"
(err: Error) => message.error(`上传失败: $
{err.message}`)
"
:on-success="
handle
UploadSuccess"
:on-progress=
"(
isU
ploading = true)"
:on-error=
"
onUploadError
"
:on-success=
"
on
UploadSuccess"
ref=
"uploadVideoRef"
:auto-upload=
"false"
class=
"mb-5"
...
...
@@ -23,7 +23,7 @@
>
</el-upload>
<el-divider
/>
<el-form
:model=
"uploadData"
:rules=
"uploadRules"
ref=
"uploadFormRef"
v-loading=
"
u
ploading"
>
<el-form
:model=
"uploadData"
:rules=
"uploadRules"
ref=
"uploadFormRef"
v-loading=
"
isU
ploading"
>
<el-form-item
label=
"标题"
prop=
"title"
>
<el-input
v-model=
"uploadData.title"
...
...
@@ -41,7 +41,7 @@
</el-form>
<
template
#
footer
>
<el-button
@
click=
"showDialog = false"
>
取 消
</el-button>
<el-button
type=
"primary"
@
click=
"submitVideo"
:loading=
"
uploading"
:disabled=
"u
ploading"
<el-button
type=
"primary"
@
click=
"submitVideo"
:loading=
"
isUploading"
:disabled=
"isU
ploading"
>
提 交
</el-button
>
</
template
>
...
...
@@ -76,7 +76,7 @@ const emit = defineEmits<{
(
e
:
'uploaded'
,
v
:
void
)
}
>
()
const
showDialog
=
computed
({
const
showDialog
=
computed
<
boolean
>
({
get
()
{
return
props
.
modelValue
},
...
...
@@ -85,7 +85,7 @@ const showDialog = computed({
}
})
const
u
ploading
=
ref
(
false
)
const
isU
ploading
=
ref
(
false
)
const
fileList
=
ref
<
UploadUserFile
[]
>
([])
...
...
@@ -107,8 +107,9 @@ const submitVideo = () => {
})
}
const
handleUploadSuccess
:
UploadProps
[
'onSuccess'
]
=
(
res
:
any
)
=>
{
uploading
.
value
=
false
/** 上传成功处理 */
const
onUploadSuccess
:
UploadProps
[
'onSuccess'
]
=
(
res
:
any
)
=>
{
isUploading
.
value
=
false
if
(
res
.
code
!==
0
)
{
message
.
error
(
'上传出错:'
+
res
.
msg
)
return
false
...
...
@@ -123,4 +124,7 @@ const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
message
.
notifySuccess
(
'上传成功'
)
emit
(
'uploaded'
)
}
/** 上传失败处理 */
const
onUploadError
=
(
err
:
Error
)
=>
message
.
error
(
`上传失败:
${
err
.
message
}
`
)
</
script
>
src/views/mp/material/components/upload.ts
View file @
84dcac77
...
...
@@ -2,7 +2,6 @@ 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/' // 上传地址
const
UPLOAD_URL
=
import
.
meta
.
env
.
VITE_BASE_URL
+
'/admin-api/mp/material/upload-permanent'
// 上传地址
enum
MaterialType
{
...
...
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