Skip to content

Commit 84dcac7

Browse files
committed
refactor: 事件函数命名:onXxx
1 parent b5fb700 commit 84dcac7

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
:limit="1"
77
:file-list="fileList"
88
:data="uploadData"
9-
:on-progress="() => (uploading = true)"
10-
:on-error="(err: Error) => message.error(`上传失败: ${err.message}`)"
11-
:before-upload="beforeUpload"
12-
:on-success="handleUploadSuccess"
9+
:on-progress="(isUploading = true)"
10+
:on-error="onUploadError"
11+
:before-upload="onBeforeUpload"
12+
:on-success="onUploadSuccess"
1313
>
14-
<el-button type="primary" plain :loading="uploading" :disabled="uploading">
15-
{{ uploading ? '正在上传' : '点击上传' }}
14+
<el-button type="primary" plain :loading="isUploading" :disabled="isUploading">
15+
{{ isUploading ? '正在上传' : '点击上传' }}
1616
</el-button>
1717
<template #tip>
1818
<span class="el-upload__tip" style="margin-left: 5px">
@@ -46,11 +46,13 @@ const uploadData: UploadData = reactive({
4646
title: '',
4747
introduction: ''
4848
})
49-
const uploading = ref(false)
49+
const isUploading = ref(false)
5050
51-
const beforeUpload = props.type === MaterialType.Image ? beforeImageUpload : beforeVoiceUpload
51+
/** 上传前检查 */
52+
const onBeforeUpload = props.type === MaterialType.Image ? beforeImageUpload : beforeVoiceUpload
5253
53-
const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
54+
/** 上传成功处理 */
55+
const onUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
5456
if (res.code !== 0) {
5557
message.alertError('上传出错:' + res.msg)
5658
return false
@@ -62,7 +64,16 @@ const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
6264
uploadData.introduction = ''
6365
6466
message.notifySuccess('上传成功')
65-
uploading.value = false
67+
isUploading.value = false
6668
emit('uploaded')
6769
}
70+
71+
/** 上传失败处理 */
72+
const onUploadError = (err: Error) => message.error('上传失败: ' + err.message)
6873
</script>
74+
75+
<style lang="scss" scoped>
76+
.el-upload__tip {
77+
margin-left: 5px;
78+
}
79+
</style>

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
:file-list="fileList"
99
:data="uploadData"
1010
:before-upload="beforeVideoUpload"
11-
:on-progress="() => (uploading = true)"
12-
:on-error="(err: Error) => message.error(`上传失败: ${err.message}`)"
13-
:on-success="handleUploadSuccess"
11+
:on-progress="(isUploading = true)"
12+
:on-error="onUploadError"
13+
:on-success="onUploadSuccess"
1414
ref="uploadVideoRef"
1515
:auto-upload="false"
1616
class="mb-5"
@@ -23,7 +23,7 @@
2323
>
2424
</el-upload>
2525
<el-divider />
26-
<el-form :model="uploadData" :rules="uploadRules" ref="uploadFormRef" v-loading="uploading">
26+
<el-form :model="uploadData" :rules="uploadRules" ref="uploadFormRef" v-loading="isUploading">
2727
<el-form-item label="标题" prop="title">
2828
<el-input
2929
v-model="uploadData.title"
@@ -41,7 +41,7 @@
4141
</el-form>
4242
<template #footer>
4343
<el-button @click="showDialog = false">取 消</el-button>
44-
<el-button type="primary" @click="submitVideo" :loading="uploading" :disabled="uploading"
44+
<el-button type="primary" @click="submitVideo" :loading="isUploading" :disabled="isUploading"
4545
>提 交</el-button
4646
>
4747
</template>
@@ -76,7 +76,7 @@ const emit = defineEmits<{
7676
(e: 'uploaded', v: void)
7777
}>()
7878
79-
const showDialog = computed({
79+
const showDialog = computed<boolean>({
8080
get() {
8181
return props.modelValue
8282
},
@@ -85,7 +85,7 @@ const showDialog = computed({
8585
}
8686
})
8787
88-
const uploading = ref(false)
88+
const isUploading = ref(false)
8989
9090
const fileList = ref<UploadUserFile[]>([])
9191
@@ -107,8 +107,9 @@ const submitVideo = () => {
107107
})
108108
}
109109
110-
const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
111-
uploading.value = false
110+
/** 上传成功处理 */
111+
const onUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
112+
isUploading.value = false
112113
if (res.code !== 0) {
113114
message.error('上传出错:' + res.msg)
114115
return false
@@ -123,4 +124,7 @@ const handleUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
123124
message.notifySuccess('上传成功')
124125
emit('uploaded')
125126
}
127+
128+
/** 上传失败处理 */
129+
const onUploadError = (err: Error) => message.error(`上传失败: ${err.message}`)
126130
</script>

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

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

87
enum MaterialType {

0 commit comments

Comments
 (0)