mirror of
				https://gitee.com/hhyykk/ipms-sjy-ui.git
				synced 2025-11-01 02:38:44 +08:00 
			
		
		
		
	Vue3 重构:REVIEW 公众号消息,修复 WxVoicePlayer 的 icon 报错
This commit is contained in:
		| @@ -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", | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
| @@ -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' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV