From b43bad8ef992d4abdebf96feb6f4fe862e8f4d8a Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期一, 17 六月 2024 09:38:14 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/views/exam/question/edit/audio.vue |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/views/exam/question/edit/audio.vue b/src/views/exam/question/edit/audio.vue
index 7f88df7..4743443 100644
--- a/src/views/exam/question/edit/audio.vue
+++ b/src/views/exam/question/edit/audio.vue
@@ -11,8 +11,10 @@
       </el-form-item>
       <el-form-item label="璇煶锛�" prop="audioFile" required>
         <el-upload v-model="form.audioFile" :action="uploadUrl" :limit="1" accept="audio/*" :on-success="uploadSuccess"
-          :file-list="audioList">
+          :on-remove="handleRemove" :file-list="audioList">
           <el-button size="small" type="primary">鐐瑰嚮涓婁紶</el-button>
+          <el-button v-if="form.audioFile" size="small" type="primary" @click.stop="audioPlay(form.audioFile)">{{
+      audioInstance ? '鏆傚仠' : '璇曞惉' }}</el-button>
         </el-upload>
       </el-form-item>
       <el-form-item label="閫夐」锛�" required>
@@ -125,7 +127,8 @@
         dialog: false,
         question: null,
         loading: false
-      }
+      },
+      audioInstance: null
     }
   },
   created() {
@@ -144,6 +147,18 @@
     }
   },
   methods: {
+    handleRemove() {
+      this.form.audioFile = ''
+    },
+    audioPlay(url) {
+      if (this.audioInstance) {
+        this.audioInstance.pause();
+        this.audioInstance = null;
+      } else {
+        this.audioInstance = new Audio('/api/files/' + url);
+        this.audioInstance.play();
+      }
+    },
     uploadSuccess(response) {
       this.form.audioFile = response.data.url;
       this.form.originalFile = response.data.name;

--
Gitblit v1.8.0