From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/views/mp/material/components/UploadFile.vue | 77 ++++++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
diff --git a/src/views/mp/material/components/UploadFile.vue b/src/views/mp/material/components/UploadFile.vue
new file mode 100644
index 0000000..276a798
--- /dev/null
+++ b/src/views/mp/material/components/UploadFile.vue
@@ -0,0 +1,77 @@
+<template>
+ <el-upload
+ :action="UPLOAD_URL"
+ :headers="HEADERS"
+ multiple
+ :limit="1"
+ :file-list="fileList"
+ :data="uploadData"
+ :on-error="onUploadError"
+ :before-upload="onBeforeUpload"
+ :on-success="onUploadSuccess"
+ >
+ <el-button type="primary" plain> 鐐瑰嚮涓婁紶 </el-button>
+ <template #tip>
+ <span class="el-upload__tip" style="margin-left: 5px">
+ <slot></slot>
+ </span>
+ </template>
+ </el-upload>
+</template>
+<script lang="ts" setup>
+import type { UploadProps, UploadUserFile } from 'element-plus'
+import {
+ HEADERS,
+ UPLOAD_URL,
+ UploadData,
+ UploadType,
+ beforeImageUpload,
+ beforeVoiceUpload
+} from './upload'
+
+const message = useMessage()
+
+const props = defineProps<{ type: UploadType }>()
+
+const accountId = inject<number>('accountId')
+
+const fileList = ref<UploadUserFile[]>([])
+const emit = defineEmits<{
+ (e: 'uploaded', v: void)
+}>()
+
+const uploadData: UploadData = reactive({
+ type: UploadType.Image,
+ title: '',
+ introduction: '',
+ accountId: accountId!
+})
+
+/** 涓婁紶鍓嶆鏌� */
+const onBeforeUpload = props.type === UploadType.Image ? beforeImageUpload : beforeVoiceUpload
+
+/** 涓婁紶鎴愬姛澶勭悊 */
+const onUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
+ if (res.code !== 0) {
+ message.alertError('涓婁紶鍑洪敊锛�' + res.msg)
+ return false
+ }
+
+ // 娓呯┖涓婁紶鏃剁殑鍚勭鏁版嵁
+ fileList.value = []
+ uploadData.title = ''
+ uploadData.introduction = ''
+
+ message.notifySuccess('涓婁紶鎴愬姛')
+ emit('uploaded')
+}
+
+/** 涓婁紶澶辫触澶勭悊 */
+const onUploadError = (err: Error) => message.error('涓婁紶澶辫触: ' + err.message)
+</script>
+
+<style lang="scss" scoped>
+.el-upload__tip {
+ margin-left: 5px;
+}
+</style>
--
Gitblit v1.8.0