feat(voice): 大神语音介绍真实落地(录制/上传/试听)
- DB: companions.voice_intro_url;仓储 updateCompanionVoice;详情与 /api/expert/me 返回 voiceIntroUrl/voiceDuration - 后端: POST /api/companions/:id/voice(音频白名单 mp3/m4a/aac/wav/ogg、5MB、≤60s、限流、仅本人或管理员) - 小程序: api.uploadVoiceIntro(uni.uploadFile + 用户令牌);工作台新增「语音介绍」卡片(录制/重录/试听,60s mp3);详情页改为 uni.createInnerAudioContext 真实播放,卸载销毁 - 修复 uploadImage 未携带用户令牌(生产 fail-closed 后会导致上传失败) - 新增 voice-intro.spec.ts(104 套件/701 用例全绿);冒烟 7/7
这个提交包含在:
@@ -52,14 +52,14 @@
|
||||
<image class="play-svg" :src="isPlayingVoice ? ICONS.pause : ICONS.play" mode="aspectFit" />
|
||||
</view>
|
||||
<view class="voice-info">
|
||||
<text class="voice-title">{{ isPlayingVoice ? '正在播放打招呼原声...' : '点击试听打招呼原声' }}</text>
|
||||
<text class="voice-title">{{ isPlayingVoice ? '正在播放语音介绍...' : (expert.voiceIntroUrl ? '点击试听语音介绍' : '暂未上传语音介绍') }}</text>
|
||||
<view class="voice-wave" v-if="isPlayingVoice">
|
||||
<view class="bar b1"></view>
|
||||
<view class="bar b2"></view>
|
||||
<view class="bar b3"></view>
|
||||
<view class="bar b4"></view>
|
||||
</view>
|
||||
<text class="voice-dur" v-else>{{ expert.voiceDuration }}s 真实原声</text>
|
||||
<text class="voice-dur" v-else>{{ expert.voiceIntroUrl ? expert.voiceDuration + 's 真实录音' : '暂无可试听内容' }}</text>
|
||||
</view>
|
||||
<text class="listen-tag">试听</text>
|
||||
</view>
|
||||
@@ -280,6 +280,7 @@ onMounted(() => {
|
||||
|
||||
onUnmounted(() => {
|
||||
uni.$off('theme-change', onThemeChanged);
|
||||
try { if (voiceAudio) { voiceAudio.destroy(); voiceAudio = null; } } catch (_) {}
|
||||
});
|
||||
|
||||
const stopPropagation = (e) => {
|
||||
@@ -335,6 +336,7 @@ const expert = ref({
|
||||
const isCompanion = computed(() => expert.value.isCompanion !== false);
|
||||
const selectedServiceId = ref('srv_1');
|
||||
const isPlayingVoice = ref(false);
|
||||
let voiceAudio = null;
|
||||
let currentExpertTargetId = null;
|
||||
|
||||
const refreshFavoriteState = async () => {
|
||||
@@ -526,13 +528,27 @@ const selectService = (srv) => {
|
||||
};
|
||||
|
||||
const toggleVoice = () => {
|
||||
isPlayingVoice.value = !isPlayingVoice.value;
|
||||
if (isPlayingVoice.value) {
|
||||
uni.showToast({ title: '正在播放大神打招呼原声', icon: 'none' });
|
||||
setTimeout(() => {
|
||||
isPlayingVoice.value = false;
|
||||
}, 4000);
|
||||
const url = String((expert.value && expert.value.voiceIntroUrl) || '');
|
||||
if (!url) {
|
||||
uni.showToast({ title: '该大神暂未上传语音介绍', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (isPlayingVoice.value) {
|
||||
try { voiceAudio && voiceAudio.pause(); } catch (_) {}
|
||||
isPlayingVoice.value = false;
|
||||
return;
|
||||
}
|
||||
if (!voiceAudio) {
|
||||
voiceAudio = uni.createInnerAudioContext();
|
||||
voiceAudio.onEnded(() => { isPlayingVoice.value = false; });
|
||||
voiceAudio.onError(() => {
|
||||
isPlayingVoice.value = false;
|
||||
uni.showToast({ title: '语音播放失败,请稍后重试', icon: 'none' });
|
||||
});
|
||||
}
|
||||
voiceAudio.src = url;
|
||||
voiceAudio.play();
|
||||
isPlayingVoice.value = true;
|
||||
};
|
||||
|
||||
const chatOnline = () => {
|
||||
|
||||
在新工单中引用
屏蔽一个用户