You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
7.9 KiB

1 year ago
<template>
<view class="container">
<view class="wifi-data">
<view class="wifi-icon">
<u-icon color="#ffffff" name="wifi" size="30"></u-icon>
</view>
<view class="wifi-datas" color="#2979ff">
<view class="wifi-name">{{wifiForm.wifiName}}</view>
<view class="wifi-hot">
<text class="hot-text">快速连接</text>
<text class="hot-icon">.</text>
<text class="hot-text">无需密码</text>
<text class="hot-icon">.</text>
<text class="hot-text">保护隐私</text>
</view>
</view>
</view>
<view class="wifi-success" v-if="!showBtn">
WI-FI连接成功
</view>
<u-button type="primary" text="一键连接WI-FI" @click="handleLinkwifi()" v-if="showBtn"></u-button>
<u-popup :show="show" mode="bottom">
<view class="video-container">
<view class="video-btns" :style="{paddingTop:statusBarHeight+'rpx'}">
<view class="second" v-show="countdown > 0">{{countdown}} WI-FI</view>
1 year ago
<view class="second" v-show="countdown == 0"></view>
<view class="close" @click="handleClose()"></view>
</view>
<video id="video-box" v-if="show" :src="baseUrl + posterForm.videoPath" :autoplay="true"
:controls="false" @timeupdate="changeTimeupdate" @play="play" @ended="ended"></video>
1 year ago
</view>
</u-popup>
</view>
</template>
<script>
import {
getShanghu,
getPoster,
addNetHistory,
addPosterHistory,
getNet
} from '@/api/index.js'
export default {
data() {
return {
baseUrl: getApp().globalData.config.baseUrl,
showBtn: true,
show: false,
urlPath: '',
statusBarHeight: 0,
countdown: 0,
videoCurrentTime: 0, //视频播放时间
historyTime: null,
1 year ago
wifiForm: {},
posterForm: {},
platform: null,
1 year ago
}
},
onLoad(option) {
// #ifdef MP-WEIXIN
let sys = uni.$u.sys()
this.statusBarHeight = sys.statusBarHeight + 44
// #endif
if (option.posterId) {
this.getNetinfo(option.posterId)
} else {
uni.showToast({
title: '获取网络信息失败!',
icon: 'error'
})
}
1 year ago
},
methods: {
//根据微信扫小程序码进入首页拿到网络id查询网络详情
getNetinfo(netId) {
getNet(netId).then(response => {
this.wifiForm = response.data
})
},
//一键连接(提示用户连接WIFI需要看广告)
handleLinkwifi() {
let that = this
uni.showModal({
title: '温馨提示',
content: '连接WIFI需要观看一段视频广告是否确认',
success: (res) => {
if (res.confirm) {
// 根据当前网络的商户Id查询商户信息然后根据商户信息中的广告id查到商户的广告
getShanghu(that.wifiForm.shanghuId).then(shanghu => {
getPoster(shanghu.data.posterId).then(poster => {
that.posterForm = poster.data
that.countdown = that.posterForm.duration
1 year ago
that.show = true
})
})
}
}
})
},
//记录历史广告
setPosterHistory() {
let data = {
posterId: this.posterForm.id,
posterName: this.posterForm.posterName,
startTime: this.posterForm.startTime,
endTime: this.posterForm.endTime,
videoPath: this.posterForm.videoPath,
shanghuId: this.wifiForm.shanghuId
}
addPosterHistory(data)
},
// 开始播放
play() {
this.setPosterHistory()
},
//播放完毕
ended() {
this.handleClose()
1 year ago
},
//视频播放进度
changeTimeupdate(e) {
this.countdown = Math.floor(e.detail.duration) - Math.floor(e.detail.currentTime)
this.videoCurrentTime = Math.floor(e.detail.currentTime)
// 禁止拖动进度条快进
if (e.detail.currentTime - this.historyTime > 1) {
uni.showToast({
title: '不能快进哦',
icon: 'none',
});
let videoContext = wx.createVideoContext('video-box');
videoContext.seek(this.historyTime);
}
this.historyTime = e.detail.currentTime;
1 year ago
},
//关闭弹窗
handleClose() {
console.log('完毕', this.countdown)
this.show = false
if (this.countdown <= 1) {
1 year ago
//证明已经看过视频时间
this.handleWifi()
} else {
uni.showToast({
title: '连接WI-FI失败!',
1 year ago
icon: 'error'
})
}
},
//判断当前机器是否支持连接WIFI
handleWifi() {
uni.showLoading({
title: '连接中'
})
let that = this
uni.getSystemInfo({
success: function(res) {
var system = '';
that.platform = res.platform
1 year ago
if (res.platform == 'android') system = parseInt(res.system.substr(8));
if (res.platform == 'ios') system = parseInt(res.system.substr(4));
if (res.platform == 'android' && system < 6 || res.platform == 'ios' && system <
11.2) {
uni.showToast({
1 year ago
title: '手机版本不支持',
icon: 'error',
})
return
}
that.startWifi();
}
})
},
//初始化 Wi-Fi 模块
startWifi() {
var that = this
uni.startWifi({
success: function() {
//请求成功连接Wifi
that.Connected();
},
fail: function(res) {
uni.showToast({
title: '初始化WIFI失败',
icon: 'error'
})
}
})
},
linkWifi() {
addNetHistory({
netId: this.wifiForm.id,
netName: this.wifiForm.netName,
wifiName: this.wifiForm.wifiName,
wifiPass: this.wifiForm.wifiPass,
shanghuId: this.wifiForm.shanghuId
})
uni.showToast({
title: '连接成功',
icon: 'success'
})
this.showBtn = false
},
1 year ago
Connected() {
var that = this
uni.connectWifi({
SSID: this.wifiForm.wifiName, //wifi名
password: this.wifiForm.wifiPass, //wifi密码
success: function(res) {
if (that.platform == 'ios') {
uni.getConnectedWifi({
partialInfo: true,
success: function(reult) {
console.log('成功', reult, that.wifiForm.wifiName)
if (reult.wifi.SSID == that.wifiForm.wifiName) {
that.linkWifi()
} else {
uni.showToast({
title: '连接失败!',
icon: "error"
})
}
},
fail: function(error) {
uni.showToast({
title: '连接失败!',
icon: "error"
})
console.log('失败', error)
}
})
} else {
that.linkWifi()
}
1 year ago
},
fail: function(err) {
1 year ago
uni.showToast({
title: '连接失败',
icon: 'error'
})
},
1 year ago
})
},
}
}
</script>
<style lang="scss">
page {
height: 100%;
}
.container {
height: 100%;
background-color: #F6F7F8;
box-sizing: border-box;
padding: 25rpx;
}
.wifi-data {
border-radius: 16rpx;
background-color: #ffffff;
box-sizing: border-box;
padding: 20rpx;
display: flex;
align-items: center;
margin-bottom: 20rpx;
.wifi-icon {
height: 100rpx;
width: 100rpx;
border-radius: 50%;
background: $u-primary;
display: flex;
align-items: center;
justify-content: center;
}
.wifi-datas {
box-sizing: border-box;
padding-left: 20rpx;
.wifi-name {
font-size: 28rpx;
font-weight: bold;
color: #333;
margin-bottom: 6px;
}
.wifi-hot {
color: #9DA2AB;
.hot-text {
font-size: 24rpx;
}
.hot-icon {
margin: 0 10rpx;
}
}
}
}
.wifi-success {
border-radius: 16rpx;
background-color: #ffffff;
box-sizing: border-box;
padding: 40rpx 20rpx;
color: #32B78B;
font-size: 28rpx;
text-align: center;
}
.video-container {
width: 100%;
position: relative;
#video-box {
height: 100vh;
width: 100%;
}
.video-btns {
position: absolute;
left: 0;
top: 0;
z-index: 100;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
padding: 0 20rpx;
&>view {
border: 1px solid #ccc;
color: white;
font-size: 24rpx;
border-radius: 25rpx;
box-sizing: border-box;
padding: 8rpx 20rpx;
}
}
}
</style>