273 lines
7.0 KiB
Plaintext
273 lines
7.0 KiB
Plaintext
<template>
|
||
<view class="videoview">
|
||
<video id='myvideo' class="video" :src="src" autoplay="true" duration="" controls="true" :danmu-list="list"
|
||
danmu-btn="true" enable-danmu="true" :loop="true" muted="false" initial-time="" direction="-90"
|
||
show-mute-btn="true" @play="onstart" @pause="onpause" @ended="onfinish" @error="onfail" @waiting="waiting"
|
||
@timeupdate="timeupdate" @fullscreenchange="fullscreenchange" @click="navToMain"></video>
|
||
|
||
<!-- <button class="btn" @click="play">播放</button>
|
||
<button class="btn" @click="pause">暂停</button>
|
||
<button class="btn" @click="seek">跳转到指定位置</button>
|
||
<button class="btn" @click="stop">停止</button>
|
||
<button class="btn" @click="fullScreen">全屏</button>
|
||
<button class="btn" @click="exitFullScreen">退出全屏</button>
|
||
<button class="btn" @click="playbackRate">设置倍速</button>
|
||
<button class="btn" @click="sendDanmu">发送弹幕</button> -->
|
||
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import APPUpdate, { getCurrentNo } from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
|
||
import Underlying from '../../utils/UnderlyingUpdate.js'
|
||
|
||
const db = uniCloud.database();
|
||
export default {
|
||
data() {
|
||
return {
|
||
src: "",
|
||
fil: true,
|
||
list: [{
|
||
text: '这是版本1.0.0',
|
||
color: '#FF0000',
|
||
time: 9
|
||
}],
|
||
version: '', // 版本号,
|
||
url: '', //视频地址
|
||
|
||
TextUrl: '', //文本下载地址
|
||
savebin: '',
|
||
timer1: null //定时更新
|
||
}
|
||
},
|
||
onLoad(e) {
|
||
getCurrentNo(res => {
|
||
// 进页面获取当前APP版本号(用于页面显示)
|
||
this.version = res.versionCode;
|
||
console.log(this.version)
|
||
db.collection('DownloadVersion').get().then((res) => {
|
||
const DownloadData = res.result.data[0]
|
||
console.log(DownloadData.versionCode)
|
||
APPUpdate();
|
||
//如果数据库上传的版本号大于本地应用的版本号就更新
|
||
if (DownloadData.versionCode > this.version) {
|
||
// this.timer = setInterval(() => {
|
||
console.log(this.version)
|
||
APPUpdate();
|
||
// //定时检测账号状态
|
||
// // this.AccountStatus();
|
||
// console.log("更新")
|
||
// }, 60 * 1000);
|
||
} else {
|
||
console.log("不更新")
|
||
}
|
||
});
|
||
});
|
||
// this.AccountStatus();
|
||
// this.onUnderlying();
|
||
// 定时更新底层程序
|
||
// this.timer1 = setInterval(() => {
|
||
// this.onUnderlying();
|
||
// }, 60 * 1000);
|
||
},
|
||
onReady() {
|
||
this.DownLoadVideo();
|
||
},
|
||
//uniapp中onHide()能监听到页面离开
|
||
onHide() {
|
||
// console.log('onHide');
|
||
clearInterval(this.timer);
|
||
this.timer1 = null;
|
||
|
||
this.exitFullScreen();
|
||
this.stop();
|
||
},
|
||
methods: {
|
||
// //更新账户状态
|
||
// AccountStatus() {
|
||
// //联表查询uni-id-users表的保存的数据
|
||
// db.collection('uni-id-users').where("'_id' == $cloudEnv_uid")
|
||
// .field('mobile,nickname,user_name,email,avatar_file,status')
|
||
// .get().then((res) => {
|
||
// const data = res.result.data[0]
|
||
// console.log(data.status)
|
||
// //如果账号是禁用状态就退出
|
||
// if (1 === data.status) {
|
||
// console.log(data.status)
|
||
// uni.showToast({
|
||
// title: "检测账号异常",
|
||
// icon: 'none'
|
||
// });
|
||
// //退出登录
|
||
// mutations.logout()
|
||
// uni.navigateTo({
|
||
// url: '/uni_modules/uni-id-pages/pages/login/login-withoutpwd',
|
||
// })
|
||
|
||
// } else {
|
||
// console.log("账号正常")
|
||
// }
|
||
// })
|
||
// },
|
||
// 检查APP是否有新版本
|
||
onAPPUpdate() {
|
||
APPUpdate();
|
||
},
|
||
//底层程序更新
|
||
onUnderlying() {
|
||
db.collection('Underlying').get().then((res) => {
|
||
const DownloadData = res.result.data[0]
|
||
console.log(res.result.data[0])
|
||
//从数据库下载
|
||
this.TextUrl = DownloadData.TextUrl;
|
||
console.log(this.TextUrl)
|
||
if (DownloadData.EnableUrl === "true") {
|
||
uni.request({
|
||
url: this.TextUrl,
|
||
responseType: 'arraybuffer',
|
||
success: (res) => {
|
||
const data = new Uint8Array(res.data);
|
||
console.log(data.length);
|
||
|
||
},
|
||
fail: (err) => {
|
||
console.error(err);
|
||
},
|
||
});
|
||
}
|
||
})
|
||
},
|
||
//下载视频
|
||
DownLoadVideo() {
|
||
db.collection('config').get().then((res) => {
|
||
const DownloadData = res.result.data[0]
|
||
//从数据库下载的数据
|
||
this.url = DownloadData.url;
|
||
// console.log(this.url);
|
||
// console.log(DownloadData.EnableUrl)
|
||
if (DownloadData.EnableUrl === "true") {
|
||
uni.downloadFile({
|
||
url: this.url,
|
||
success: (res) => {
|
||
if (res.statusCode === 200) {
|
||
console.log('下载成功');
|
||
console.log(res.tempFilePath)
|
||
uni.saveFile({
|
||
tempFilePath: res.tempFilePath,
|
||
success: (res) => {
|
||
var savedFilePath = res.savedFilePath;
|
||
console.log(savedFilePath)
|
||
db.collection('config').where(
|
||
"ConfigID == 'ConfigID001'").update({
|
||
LocalUrl: savedFilePath,
|
||
EnableUrl: 'false' //确保只下载一次
|
||
})
|
||
.then((res) => {
|
||
console.log(res)
|
||
})
|
||
this.src = savedFilePath;
|
||
this.context = uni.createVideoContext("myvideo",
|
||
this);
|
||
this.context.requestFullScreen({
|
||
direction: 90
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
} else {
|
||
//播放本地视频,获取本地视频列表
|
||
this.src = DownloadData.LocalUrl;
|
||
// console.log(this.src)
|
||
this.context = uni.createVideoContext("myvideo", this);
|
||
this.context.requestFullScreen({
|
||
direction: 90
|
||
});
|
||
}
|
||
|
||
})
|
||
},
|
||
navToMain() {
|
||
// this.exitFullScreen();
|
||
// this.stop();
|
||
|
||
uni.reLaunch({
|
||
url: '/pages/productlist/productlist'
|
||
})
|
||
this.exitFullScreen();
|
||
this.stop();
|
||
},
|
||
onstart(e) {
|
||
// console.log("onstart:" + JSON.stringify(e));
|
||
},
|
||
onpause(e) {
|
||
// console.log("onpause:" + JSON.stringify(e));
|
||
},
|
||
onfinish(e) {
|
||
// console.log("onfinish:" + JSON.stringify(e));
|
||
},
|
||
onfail(e) {
|
||
// console.log("onfail:" + JSON.stringify(e));
|
||
},
|
||
fullscreenchange(e) {
|
||
// console.log("fullscreenchange:" + JSON.stringify(e));
|
||
},
|
||
waiting(e) {
|
||
// console.log("waiting:" + JSON.stringify(e));
|
||
},
|
||
timeupdate(e) {
|
||
// console.log("timeupdate:" + JSON.stringify(e));
|
||
},
|
||
|
||
play() {
|
||
this.context.play();
|
||
},
|
||
pause() {
|
||
this.context.pause();
|
||
},
|
||
seek() {
|
||
this.context.seek(20);
|
||
},
|
||
stop() {
|
||
this.context.stop();
|
||
},
|
||
fullScreen() {
|
||
this.context.requestFullScreen({
|
||
direction: 90
|
||
});
|
||
},
|
||
exitFullScreen() {
|
||
this.context.exitFullScreen();
|
||
},
|
||
sendDanmu() {
|
||
this.context.sendDanmu({
|
||
text: '要显示的弹幕文本',
|
||
color: '#FF0000'
|
||
});
|
||
},
|
||
playbackRate() {
|
||
this.context.playbackRate(2);
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
.video {
|
||
width: 750rpx;
|
||
/* #ifdef H5 */
|
||
width: 100%;
|
||
/* #endif */
|
||
height: 400rpx;
|
||
font-size: 100rpx;
|
||
background-color: #808080;
|
||
|
||
}
|
||
|
||
.btn {
|
||
margin-top: 5px;
|
||
margin-bottom: 5px;
|
||
}
|
||
</style>
|