Vue3 重构:REVIEW 公众号消息,修复 WxVoicePlayer 的 icon 报错

This commit is contained in:
YunaiV 2023-03-26 23:15:38 +08:00
parent e00834adf7
commit 708aef3e10
3 changed files with 15 additions and 17 deletions

View File

@ -35,6 +35,7 @@
"@zxcvbn-ts/core": "^2.2.1",
"animate.css": "^4.1.1",
"axios": "^1.3.4",
"benz-amr-recorder": "^1.1.5",
"bpmn-js-token-simulation": "^0.10.0",
"camunda-bpmn-moddle": "^7.0.1",
"cropperjs": "^1.5.13",

View File

@ -11,9 +11,9 @@
-->
<template>
<div class="wx-voice-div" @click="playVoice">
<el-icon
><VideoPlay v-if="playing !== true" />
<VideoPause v-if="playing === true" />
<el-icon>
<Icon v-if="playing !== true" icon="ep:video-play" />
<Icon v-else icon="ep:video-pause" />
<span class="amr-duration" v-if="duration">{{ duration }} </span>
</el-icon>
<div v-if="content">
@ -25,19 +25,15 @@
<script setup lang="ts" name="WxVoicePlayer">
// amr amr https://www.npmjs.com/package/benz-amr-recorder
import BenzAMRRecorder from 'benz-amr-recorder'
import { VideoPause, VideoPlay } from '@element-plus/icons-vue'
const props = defineProps({
url: {
// https://www.iocoder.cn/xxx.amr
type: String,
type: String, // https://www.iocoder.cn/xxx.amr
required: true
},
content: {
//
type: String,
type: String, //
required: false
}
})
@ -46,16 +42,14 @@ const amr = ref()
const playing = ref(false)
const duration = ref()
/** 处理点击,播放或暂停 */
const playVoice = () => {
// BenzAMRRecorder
debugger
console.log('进入' + amr.value)
if (amr.value === undefined) {
console.log('开始初始化')
amrInit()
return
}
//
if (amr.value.isPlaying()) {
amrStop()
} else {
@ -63,10 +57,9 @@ const playVoice = () => {
}
}
/** 音频初始化 */
const amrInit = () => {
amr.value = new BenzAMRRecorder()
console.log(amr.value)
console.log(props.url)
//
amr.value.initWithUrl(props.url).then(function () {
amrPlay()
@ -77,16 +70,20 @@ const amrInit = () => {
playing.value = false
})
}
/** 音频播放 */
const amrPlay = () => {
playing.value = true
amr.value.play()
}
/** 音频暂停 */
const amrStop = () => {
playing.value = false
amr.value.stop()
}
// TODO
</script>
<style lang="scss" scoped>
.wx-voice-div {
padding: 5px;

View File

@ -181,7 +181,7 @@
<script setup lang="ts" name="MpMessage">
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
// import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
// import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
// import WxMsg from '@/views/mp/components/wx-msg/main.vue'
import WxLocation from '@/views/mp/components/wx-location/main.vue'
// import WxMusic from '@/views/mp/components/wx-music/main.vue'