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/UploadVideo.vue |  129 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/src/views/mp/material/components/UploadVideo.vue b/src/views/mp/material/components/UploadVideo.vue
new file mode 100644
index 0000000..22347fd
--- /dev/null
+++ b/src/views/mp/material/components/UploadVideo.vue
@@ -0,0 +1,129 @@
+<template>
+  <el-dialog title="鏂板缓瑙嗛" v-model="showDialog" width="600px">
+    <el-upload
+      :action="UPLOAD_URL"
+      :headers="HEADERS"
+      multiple
+      :limit="1"
+      :file-list="fileList"
+      :data="uploadData"
+      :before-upload="beforeVideoUpload"
+      :on-error="onUploadError"
+      :on-success="onUploadSuccess"
+      ref="uploadVideoRef"
+      :auto-upload="false"
+      class="mb-5"
+    >
+      <template #trigger>
+        <el-button type="primary" plain>閫夋嫨瑙嗛</el-button>
+      </template>
+      <template #tip>
+        <span class="el-upload__tip" style="margin-left: 10px"
+          >鏍煎紡鏀寔 MP4锛屾枃浠跺ぇ灏忎笉瓒呰繃 10MB</span
+        >
+      </template>
+    </el-upload>
+    <el-divider />
+    <el-form :model="uploadData" :rules="uploadRules" ref="uploadFormRef">
+      <el-form-item label="鏍囬" prop="title">
+        <el-input
+          v-model="uploadData.title"
+          placeholder="鏍囬灏嗗睍绀哄湪鐩稿叧鎾斁椤甸潰锛屽缓璁~鍐欐竻鏅般�佸噯纭�佺敓鍔ㄧ殑鏍囬"
+        />
+      </el-form-item>
+      <el-form-item label="鎻忚堪" prop="introduction">
+        <el-input
+          :rows="3"
+          type="textarea"
+          v-model="uploadData.introduction"
+          placeholder="浠嬬粛璇皢灞曠ず鍦ㄧ浉鍏虫挱鏀鹃〉闈紝寤鸿濉啓绠�娲佹槑纭�佹湁淇℃伅閲忕殑鍐呭"
+        />
+      </el-form-item>
+    </el-form>
+    <template #footer>
+      <el-button @click="showDialog = false">鍙� 娑�</el-button>
+      <el-button type="primary" @click="submitVideo">鎻� 浜�</el-button>
+    </template>
+  </el-dialog>
+</template>
+
+<script lang="ts" setup>
+import type {
+  FormInstance,
+  FormRules,
+  UploadInstance,
+  UploadProps,
+  UploadUserFile
+} from 'element-plus'
+import { HEADERS, UploadData, UPLOAD_URL, UploadType, beforeVideoUpload } from './upload'
+
+const message = useMessage()
+
+const accountId = inject<number>('accountId')
+
+const uploadRules: FormRules = {
+  title: [{ required: true, message: '璇疯緭鍏ユ爣棰�', trigger: 'blur' }],
+  introduction: [{ required: true, message: '璇疯緭鍏ユ弿杩�', trigger: 'blur' }]
+}
+
+const props = defineProps({
+  modelValue: {
+    type: Boolean,
+    default: false
+  }
+})
+const emit = defineEmits<{
+  (e: 'update:modelValue', v: boolean)
+  (e: 'uploaded', v: void)
+}>()
+
+const showDialog = computed<boolean>({
+  get() {
+    return props.modelValue
+  },
+  set(val) {
+    emit('update:modelValue', val)
+  }
+})
+
+const fileList = ref<UploadUserFile[]>([])
+
+const uploadData: UploadData = reactive({
+  type: UploadType.Video,
+  title: '',
+  introduction: '',
+  accountId: accountId!
+})
+
+const uploadFormRef = ref<FormInstance | null>(null)
+const uploadVideoRef = ref<UploadInstance | null>(null)
+
+const submitVideo = () => {
+  uploadFormRef.value?.validate((valid) => {
+    if (!valid) {
+      return
+    }
+    uploadVideoRef.value?.submit()
+  })
+}
+
+/** 涓婁紶鎴愬姛澶勭悊 */
+const onUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
+  if (res.code !== 0) {
+    message.error('涓婁紶鍑洪敊锛�' + res.msg)
+    return false
+  }
+
+  // 娓呯┖涓婁紶鏃剁殑鍚勭鏁版嵁
+  fileList.value = []
+  uploadData.title = ''
+  uploadData.introduction = ''
+
+  showDialog.value = false
+  message.notifySuccess('涓婁紶鎴愬姛')
+  emit('uploaded')
+}
+
+/** 涓婁紶澶辫触澶勭悊 */
+const onUploadError = (err: Error) => message.error(`涓婁紶澶辫触: ${err.message}`)
+</script>

--
Gitblit v1.8.0