Skip to content

Commit ed5990f

Browse files
committed
1、微信组件更新vue3.視頻組件更新使用video.js 6.0.0版本。
2、目前mp中視頻組件可以簡單的使用了。
1 parent 72ddb0c commit ed5990f

File tree

7 files changed

+719
-722
lines changed

7 files changed

+719
-722
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@form-create/designer": "^3.1.0",
3030
"@form-create/element-ui": "^3.1.17",
3131
"@iconify/iconify": "^3.1.0",
32+
"@videojs-player/vue": "^1.0.0",
3233
"@vueuse/core": "^9.13.0",
3334
"@wangeditor/editor": "^5.1.23",
3435
"@wangeditor/editor-for-vue": "^5.1.10",
@@ -58,6 +59,7 @@
5859
"qs": "^6.11.1",
5960
"steady-xml": "^0.1.0",
6061
"url": "^0.11.0",
62+
"video.js": "^8.0.4",
6163
"vue": "3.2.47",
6264
"vue-i18n": "9.2.2",
6365
"vue-router": "^4.1.6",

src/views/mp/components/wx-reply/main.vue

Lines changed: 623 additions & 623 deletions
Large diffs are not rendered by default.

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

Lines changed: 58 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -8,110 +8,84 @@
88
存在的问题:mediaId 有效期是 3 天,超过时间后无法播放
99
2)重构后的做法:后端接收到微信公众号的视频消息后,将视频消息的 media_id 的文件内容保存到文件服务器中,这样前端可以直接使用 URL 播放。
1010
② 体验优化:弹窗关闭后,自动暂停视频的播放
11+
1112
-->
1213
<template>
13-
<div>
14+
<div @click="playVideo()">
1415
<!-- 提示 -->
15-
<div @click="playVideo()">
16-
<el-icon>
17-
<VideoPlay />
18-
</el-icon>
16+
<div>
17+
<Icon icon="ep:video-play" class="mr-5px" />
1918
<p>点击播放视频</p>
2019
</div>
2120

2221
<!-- 弹窗播放 -->
2322
<el-dialog
23+
v-model="dialogVideo"
2424
title="视频播放"
25-
v-model:visible="dialogVideo"
2625
width="40%"
2726
append-to-body
2827
@close="closeDialog"
2928
>
30-
<video-player
31-
v-if="playerOptions.sources[0].src"
32-
class="video-player vjs-custom-skin"
33-
ref="videoPlayerRef"
34-
:playsinline="true"
35-
:options="playerOptions"
36-
@play="onPlayerPlay($event)"
37-
@pause="onPlayerPause($event)"
38-
/>
29+
<template #footer>
30+
<video-player
31+
v-if="dialogVideo"
32+
class="video-player vjs-big-play-centered"
33+
:src="url"
34+
poster=""
35+
crossorigin="anonymous"
36+
playsinline
37+
controls
38+
:volume="0.6"
39+
:height="320"
40+
:playback-rates="[0.7, 1.0, 1.5, 2.0]"
41+
/>
42+
</template>
43+
<!-- 事件,暫時沒用
44+
@mounted="handleMounted"-->
45+
<!-- @ready="handleEvent($event)"-->
46+
<!-- @play="handleEvent($event)"-->
47+
<!-- @pause="handleEvent($event)"-->
48+
<!-- @ended="handleEvent($event)"-->
49+
<!-- @loadeddata="handleEvent($event)"-->
50+
<!-- @waiting="handleEvent($event)"-->
51+
<!-- @playing="handleEvent($event)"-->
52+
<!-- @canplay="handleEvent($event)"-->
53+
<!-- @canplaythrough="handleEvent($event)"-->
54+
<!-- @timeupdate="handleEvent(player?.currentTime())"-->
3955
</el-dialog>
4056
</div>
4157
</template>
4258

43-
<script setup lang="ts" name="WxVideoPlayer">
44-
// 引入 videoPlayer 相关组件。教程:https://juejin.cn/post/6923056942281654285
45-
import { videoPlayer } from 'vue-video-player'
59+
<script lang="ts" name="WxVideoPlayer">
60+
//升级videojs6.0版本,重寫6.0版本
61+
import 'video.js/dist/video-js.css'
62+
import { defineComponent } from 'vue'
63+
import { VideoPlayer } from '@videojs-player/vue'
4664
import 'video.js/dist/video-js.css'
47-
import 'vue-video-player/src/custom-theme.css'
48-
import { VideoPlay } from '@element-plus/icons-vue'
4965
50-
const props = defineProps({
51-
url: {
52-
// 视频地址,例如说:https://www.iocoder.cn/xxx.mp4
53-
type: String,
54-
required: true
55-
}
56-
})
57-
const videoPlayerRef = ref()
58-
const dialogVideo = ref(false)
59-
const playerOptions = reactive({
60-
playbackRates: [0.5, 1.0, 1.5, 2.0], // 播放速度
61-
autoplay: false, // 如果 true,浏览器准备好时开始回放。
62-
muted: false, // 默认情况下将会消除任何音频。
63-
loop: false, // 导致视频一结束就重新开始。
64-
preload: 'auto', // 建议浏览器在 <video> 加载元素后是否应该开始下载视频数据。auto 浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
65-
language: 'zh-CN',
66-
aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
67-
fluid: true, // 当true时,Video.js player 将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
68-
sources: [
69-
{
70-
type: 'video/mp4',
71-
src: '' // 你的视频地址(必填)【重要】
66+
export default defineComponent({
67+
components: {
68+
VideoPlayer
69+
},
70+
props: {
71+
url: {
72+
// 视频地址,例如说:https://vjs.zencdn.net/v/oceans.mp4
73+
type: String,
74+
required: true
7275
}
73-
],
74-
poster: '', // 你的封面地址
75-
width: document.documentElement.clientWidth,
76-
notSupportedMessage: '此视频暂无法播放,请稍后再试', //允许覆盖 Video.js 无法播放媒体源时显示的默认信息。
77-
controlBar: {
78-
timeDivider: true,
79-
durationDisplay: true,
80-
remainingTimeDisplay: false,
81-
fullscreenToggle: true //全屏按钮
82-
}
83-
})
76+
},
77+
setup() {
78+
// const videoPlayerRef = ref(null)
79+
const dialogVideo = ref(false)
8480
85-
const playVideo = () => {
86-
dialogVideo.value = true
87-
playerOptions.sources[0].src = props.url
88-
}
89-
const closeDialog = () => {
90-
// 暂停播放
91-
// videoPlayerRef.player.pause()
92-
}
93-
// onPlayerPlay(player) {},
94-
// // // eslint-disable-next-line @typescript-eslint/no-unused-vars
95-
// // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
96-
// onPlayerPause(player) {}
81+
const handleEvent = (log) => {
82+
console.log('Basic player event', log)
83+
}
84+
const playVideo = () => {
85+
dialogVideo.value = true
86+
}
9787
98-
// methods: {
99-
// playVideo() {
100-
// this.dialogVideo = true
101-
// // 设置地址
102-
// this.playerOptions.sources[0]['src'] = this.url
103-
// },
104-
// closeDialog() {
105-
// // 暂停播放
106-
// this.$refs.videoPlayer.player.pause()
107-
// },
108-
//
109-
// //todo player组件引入可能有问题
110-
//
111-
// // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
112-
// onPlayerPlay(player) {},
113-
// // // eslint-disable-next-line @typescript-eslint/no-unused-vars
114-
// // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
115-
// onPlayerPause(player) {}
116-
// }
88+
return { handleEvent, playVideo, dialogVideo }
89+
}
90+
})
11791
</script>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
<script setup lang="ts" name="WxVoicePlayer">
2727
// 因为微信语音是 amr 格式,所以需要用到 amr 解码器:https://www.npmjs.com/package/benz-amr-recorder
28+
2829
import BenzAMRRecorder from 'benz-amr-recorder'
2930
3031
const props = defineProps({

src/views/mp/freePublish/index.vue

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@
1919
</el-select>
2020
</el-form-item>
2121
<el-form-item>
22-
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
23-
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
22+
<el-button @click="handleQuery">
23+
<Icon icon="ep:search" class="mr-5px" />
24+
搜索
25+
</el-button>
26+
<el-button @click="resetQuery">
27+
<Icon icon="ep:refresh" class="mr-5px" />
28+
重置
29+
</el-button>
2430
</el-form-item>
2531
</el-form>
2632
</content-wrap>
@@ -63,12 +69,19 @@
6369
import { getFreePublishPage, deleteFreePublish } from '@/api/mp/freePublish'
6470
import * as MpAccountApi from '@/api/mp/account'
6571
import WxNews from '@/views/mp/components/wx-news/main.vue'
72+
6673
const message = useMessage() // 消息弹窗
6774
6875
const loading = ref(true) // 列表的加载中
6976
const total = ref(0) // 列表的总页数
7077
const list = ref([]) // 列表的数据
71-
const queryParams = reactive({
78+
interface QueryParams {
79+
currentPage: number | undefined | string
80+
pageNo: number | undefined | string
81+
accountId: number | undefined | string
82+
}
83+
84+
const queryParams: QueryParams = reactive({
7285
currentPage: 1, // 当前页数
7386
pageNo: 1, // 当前页数
7487
accountId: undefined // 当前页数
@@ -115,7 +128,6 @@ const resetQuery = () => {
115128
queryFormRef.value.resetFields()
116129
// 默认选中第一个
117130
if (accountList.value.length > 0) {
118-
// @ts-ignore
119131
queryParams.accountId = accountList.value[0].id
120132
}
121133
handleQuery()
@@ -144,7 +156,6 @@ onMounted(async () => {
144156
accountList.value = await MpAccountApi.getSimpleAccountList()
145157
// 选中第一个
146158
if (accountList.value.length > 0) {
147-
// @ts-ignore
148159
queryParams.accountId = accountList.value[0].id
149160
}
150161
await getList()

src/views/mp/message/index.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,17 @@
181181
</ContentWrap>
182182
</template>
183183
<script setup lang="ts" name="MpMessage">
184-
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
185-
import { dateFormatter } from '@/utils/formatTime'
186-
// import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
184+
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
187185
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
188-
// import WxMsg from '@/views/mp/components/wx-msg/main.vue'
186+
import WxMsg from '@/views/mp/components/wx-msg/main.vue'
189187
import WxLocation from '@/views/mp/components/wx-location/main.vue'
190-
// import WxMusic from '@/views/mp/components/wx-music/main.vue'
191-
// import WxNews from '@/views/mp/components/wx-news/main.vue'
188+
import WxMusic from '@/views/mp/components/wx-music/main.vue'
189+
import WxNews from '@/views/mp/components/wx-news/main.vue'
192190
import * as MpAccountApi from '@/api/mp/account'
193191
import * as MpMessageApi from '@/api/mp/message'
194192
const message = useMessage() // 消息弹窗
193+
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
194+
import { dateFormatter } from '@/utils/formatTime'
195195
196196
const loading = ref(true) // 列表的加载中
197197
const total = ref(0) // 列表的总页数

src/views/mp/tag/index.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,21 @@
2828
/>
2929
</el-form-item>
3030
<el-form-item>
31-
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
32-
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
31+
<el-button @click="handleQuery">
32+
<Icon icon="ep:search" class="mr-5px" />
33+
搜索
34+
</el-button>
35+
<el-button @click="resetQuery">
36+
<Icon icon="ep:refresh" class="mr-5px" />
37+
重置
38+
</el-button>
3339
<el-button type="primary" plain @click="openForm('create')" v-hasPermi="['mp:tag:create']">
34-
<Icon icon="ep:plus" class="mr-5px" /> 新增
40+
<Icon icon="ep:plus" class="mr-5px" />
41+
新增
3542
</el-button>
3643
<el-button type="success" plain @click="handleSync" v-hasPermi="['mp:tag:sync']">
37-
<Icon icon="ep:refresh" class="mr-5px" /> 同步
44+
<Icon icon="ep:refresh" class="mr-5px" />
45+
同步
3846
</el-button>
3947
</el-form-item>
4048
</el-form>
@@ -91,6 +99,7 @@ import { dateFormatter } from '@/utils/formatTime'
9199
import * as MpTagApi from '@/api/mp/tag'
92100
import * as MpAccountApi from '@/api/mp/account'
93101
import TagForm from './TagForm.vue'
102+
94103
const message = useMessage() // 消息弹窗
95104
const { t } = useI18n() // 国际化
96105

0 commit comments

Comments
 (0)