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", "@zxcvbn-ts/core": "^2.2.1",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
"axios": "^1.3.4", "axios": "^1.3.4",
"benz-amr-recorder": "^1.1.5",
"bpmn-js-token-simulation": "^0.10.0", "bpmn-js-token-simulation": "^0.10.0",
"camunda-bpmn-moddle": "^7.0.1", "camunda-bpmn-moddle": "^7.0.1",
"cropperjs": "^1.5.13", "cropperjs": "^1.5.13",

View File

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

View File

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