Skip to content

Commit 708aef3

Browse files
committed
Vue3 重构:REVIEW 公众号消息,修复 WxVoicePlayer 的 icon 报错
1 parent e00834a commit 708aef3

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@zxcvbn-ts/core": "^2.2.1",
3636
"animate.css": "^4.1.1",
3737
"axios": "^1.3.4",
38+
"benz-amr-recorder": "^1.1.5",
3839
"bpmn-js-token-simulation": "^0.10.0",
3940
"camunda-bpmn-moddle": "^7.0.1",
4041
"cropperjs": "^1.5.13",

src/views/mp/components/wx-voice-play/main.vue

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
-->
1212
<template>
1313
<div class="wx-voice-div" @click="playVoice">
14-
<el-icon
15-
><VideoPlay v-if="playing !== true" />
16-
<VideoPause v-if="playing === true" />
14+
<el-icon>
15+
<Icon v-if="playing !== true" icon="ep:video-play" />
16+
<Icon v-else icon="ep:video-pause" />
1717
<span class="amr-duration" v-if="duration">{{ duration }} 秒</span>
1818
</el-icon>
1919
<div v-if="content">
@@ -25,19 +25,15 @@
2525

2626
<script setup lang="ts" name="WxVoicePlayer">
2727
// 因为微信语音是 amr 格式,所以需要用到 amr 解码器:https://www.npmjs.com/package/benz-amr-recorder
28-
2928
import BenzAMRRecorder from 'benz-amr-recorder'
30-
import { VideoPause, VideoPlay } from '@element-plus/icons-vue'
3129
3230
const props = defineProps({
3331
url: {
34-
// 语音地址,例如说:https://www.iocoder.cn/xxx.amr
35-
type: String,
32+
type: String, // 语音地址,例如说:https://www.iocoder.cn/xxx.amr
3633
required: true
3734
},
3835
content: {
39-
// 语音文本
40-
type: String,
36+
type: String, // 语音文本
4137
required: false
4238
}
4339
})
@@ -46,27 +42,24 @@ const amr = ref()
4642
const playing = ref(false)
4743
const duration = ref()
4844
45+
/** 处理点击,播放或暂停 */
4946
const playVoice = () => {
5047
// 情况一:未初始化,则创建 BenzAMRRecorder
51-
debugger
52-
console.log('进入' + amr.value)
5348
if (amr.value === undefined) {
54-
console.log('开始初始化')
5549
amrInit()
5650
return
5751
}
58-
52+
// 情况二:已经初始化,则根据情况播放或暂时
5953
if (amr.value.isPlaying()) {
6054
amrStop()
6155
} else {
6256
amrPlay()
6357
}
6458
}
6559
60+
/** 音频初始化 */
6661
const amrInit = () => {
6762
amr.value = new BenzAMRRecorder()
68-
console.log(amr.value)
69-
console.log(props.url)
7063
// 设置播放
7164
amr.value.initWithUrl(props.url).then(function () {
7265
amrPlay()
@@ -77,16 +70,20 @@ const amrInit = () => {
7770
playing.value = false
7871
})
7972
}
73+
74+
/** 音频播放 */
8075
const amrPlay = () => {
8176
playing.value = true
8277
amr.value.play()
8378
}
79+
80+
/** 音频暂停 */
8481
const amrStop = () => {
8582
playing.value = false
8683
amr.value.stop()
8784
}
85+
// TODO 芋艿:下面样式有点问题
8886
</script>
89-
9087
<style lang="scss" scoped>
9188
.wx-voice-div {
9289
padding: 5px;

src/views/mp/message/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
<script setup lang="ts" name="MpMessage">
182182
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
183183
// import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
184-
// import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
184+
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
185185
// import WxMsg from '@/views/mp/components/wx-msg/main.vue'
186186
import WxLocation from '@/views/mp/components/wx-location/main.vue'
187187
// import WxMusic from '@/views/mp/components/wx-music/main.vue'

0 commit comments

Comments
 (0)