From de19681d9a193d86b940a2f20d3263940273d725 Mon Sep 17 00:00:00 2001 From: 董国庆 <364620639@qq.com> Date: 星期二, 20 五月 2025 19:17:58 +0800 Subject: [PATCH] 录音 --- H5/pages/Appeal/Appeal.vue | 66 +++++++++++++++++++++++++++++--- 1 files changed, 59 insertions(+), 7 deletions(-) diff --git a/H5/pages/Appeal/Appeal.vue b/H5/pages/Appeal/Appeal.vue index 8b612ac..dc38ba7 100644 --- a/H5/pages/Appeal/Appeal.vue +++ b/H5/pages/Appeal/Appeal.vue @@ -154,9 +154,9 @@ import config from '@/config/index.js' import voiceInputPopup from '@/components/voiceInputPopup.vue' import { - mapActions, - mapState - } from "vuex"; + mapActions, + mapState +} from "vuex"; export default { components: { @@ -183,6 +183,7 @@ longitude: '', images: [], videos: [], + voiceFile: '',//语音文件多个逗号拼接 userInfo: uni.getStorageSync('userInfo'), //个人信息 voiceInputShow: false, }; @@ -199,7 +200,7 @@ this.getproblem() this.time = dayjs().format('YYYY-MM-DD') }, - + methods: { ...mapActions(["playRecording", "pausePlaying"]), onPlayRecording(index) { @@ -221,8 +222,8 @@ this.voiceInputShow = false; }, submitVoiceInput(e) { - console.log('eeeeeeeeeeeeeeeeeee',e) - this.videoContent.push({url: e, playing: false}); + console.log('eeeeeeeeeeeeeeeeeee', e) + this.videoContent.push({ url: e.url, data: e.data, playing: false }); this.voiceInputShow = false; }, previewImage(index) { @@ -260,7 +261,55 @@ })] })) }, - submit(type) { + async submit(type) { + if (this.videoContent.length > 0) { + uni.showLoading({ + title: '正在上传语音文件...' + }); + + const uploadPromises = this.videoContent.map(item => { + return new Promise((resolve, reject) => { + console.log('item.data', item.data) + uni.uploadFile({ + url: config.imageUrl, + file: item.data, + name: 'file', + // fileType: 'audio/mpeg', + // filePath: item.url, + // name: 'file', + header: { + 'Content-Type': 'multipart/form-data', + 'Authorization': uni.getStorageSync('token') + }, + success: (uploadFileRes) => { + const response = JSON.parse(uploadFileRes.data); + if (response.code === 200) { + resolve(response.data); + } else { + reject(new Error('上传失败')); + } + }, + fail: (error) => { + reject(error); + } + }); + }); + }); + + try { + const uploadedUrls = await Promise.all(uploadPromises); + this.voiceFile = uploadedUrls.join(','); + console.log('this.voiceFile', this.voiceFile) + uni.hideLoading(); + } catch (error) { + uni.hideLoading(); + uni.showToast({ + title: '语音文件上传失败', + icon: 'error' + }); + return; + } + } const preciseRegex = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; if (!this.time) { uni.showToast({ @@ -306,6 +355,7 @@ }) return } + const data = { time: this.time, problemType: this.problemType, @@ -318,6 +368,7 @@ descriptionContent: this.descriptionContent, images: this.images.join(','), videos: this.videos.join(','), + voiceFile: this.voiceFile, } // 问题上报 if (type == 1) { @@ -380,6 +431,7 @@ success: (res) => { uni.showLoading() + console.log('res.tempFilePaths[0]', res.tempFilePaths[0]) uni.uploadFile({ url: config.imageUrl, filePath: res.tempFilePaths[0], -- Gitblit v1.7.1