网络状态

This commit is contained in:
yj 2025-03-04 15:01:25 +08:00
parent b978744362
commit 348b5d2ddc
2 changed files with 90 additions and 31 deletions

View File

@ -12,6 +12,7 @@ let refreshTime = "" as any;
let isAutoApplySpeakTime = "" as any;
let isSpeakTime = "" as any;
let netWorkTime = "" as any;
let isReconnecTime = "" as any;
Page({
behaviors: [computedBehavior],
data: {
@ -112,7 +113,7 @@ Page({
setting: {
voiceStimulation: true, //语音激励
},
network: -1
network: 0
},
watch: {
'roomUserList.**': function (roomUserList) {
@ -278,6 +279,7 @@ Page({
this.setStorageData()
},
async onShow() {
this.getNetWorkSpeed()
wx.setKeepScreenOn({
keepScreenOn: true,
});
@ -325,6 +327,72 @@ Page({
wx.offNetworkStatusChange(this.listener)
this.clearTimer()
},
// 获取网络质量
getNetWorkSpeed() {
this.getNetworkStatus().then(networkStatus => {
this.setData({
network: networkStatus,
})
netWorkTime = setTimeout(() => {
this.getNetWorkSpeed()
}, 3000);
})
},
getNetworkStatus() {
const DOWNLOAD_TIME = [500, 1500];
return new Promise((resolve) => {
try {
let networkStatus = 0
this.getNetworkType().then(({ networkType }) => {
if (['unknown', 'none'].includes(networkType)) {
return resolve(-1);
}
if (['2g', '3g'].includes(networkType)) {
return resolve(2);
}
const startTime = +new Date();
this.requestImage().then(() => {
const requestTime = +new Date() - startTime;
if (requestTime < DOWNLOAD_TIME[0]) {
networkStatus = 0;
} else if (requestTime > DOWNLOAD_TIME[1]) {
networkStatus = 1
} else {
networkStatus = 2;
}
return resolve(networkStatus);
})
});
} catch (error) {
resolve(0);
}
})
},
requestImage() {
return new Promise((resolve) => {
wx.request({
url: `https://meeting-api.23544.com/meeting/update/ddq.png?t=${+new Date()}`,
success() {
resolve('');
},
fail() {
resolve('')
}
})
})
},
getNetworkType() {
return new Promise((resolve) => {
wx.getNetworkType({
success(res) {
resolve(res);
},
fail(err) {
resolve(err);
}
})
})
},
// 设置缓存
async setStorageData() {
const setting: any = await getStorage('setting')
@ -341,6 +409,16 @@ Page({
},
// 重连
async reconnecFun() {
if (isReconnecTime) {
clearTimeout(isReconnecTime)
isReconnecTime = ''
}
isReconnecTime = setTimeout(() => {
wx.hideLoading()
this.setData({
isReconnec: true
})
}, 1000 * 30);
wx.hideLoading()
wx.showLoading({
title: '重连中',
@ -376,6 +454,10 @@ Page({
this.setData({
isReconnec: false
})
if (isReconnecTime) {
clearTimeout(isReconnecTime)
isReconnecTime = ''
}
} else {
this.setData({
isReconnec: true
@ -430,6 +512,10 @@ Page({
clearTimeout(netWorkTime)
netWorkTime = ''
}
if (isReconnecTime) {
clearTimeout(isReconnecTime)
isReconnecTime = ''
}
},
// 显示聊天输入框
showInputPopup() {
@ -1053,33 +1139,6 @@ Page({
this.message('操作成功').success()
}
},
measureSpeed() {
const startTime = Date.now();
wx.request({
url: 'https://meeting-api.23544.com/pc/room/checkout?roomNum=111111',
timeout: 10000,
header: {
'content-type': 'application/json',
},
success: res => {
const endTime = Date.now();
const duration = endTime - startTime;
this.setData({
network: Number((duration / 1000).toFixed(0))
})
},
fail: res => {
this.setData({
network: -1
})
},
complete: res => {
netWorkTime = setTimeout(() => {
this.measureSpeed()
}, 3000);
}
})
},
// 关闭弹窗
async closeDialog(e) {
const { type } = e.currentTarget.dataset;

View File

@ -2,10 +2,10 @@
<view class="meeting">
<view wx:if="{{!isFullscreen}}" style="position: relative;">
<header-tab title='会议号:{{roomInfo.roomNum}} 会议名称:{{roomInfo.roomName}}' backGround='rgb(35,36,38)' iconSize='24' color="white" titleStyle='padding:12rpx 0;font-size:16rpx' isStatusBarHeight="{{false}}" isBack='{{false}}'></header-tab>
<!-- <image src="/assets/icon11.png" style="width: 20rpx;height: 20rpx;position: absolute;left: 20rpx;top: 50%;transform: translate(0,-50%);" wx:if="{{network >=0 && network < 4}}" />
<image src="/assets/icon12.png" style="width: 20rpx;height: 20rpx;position: absolute;left: 20rpx;top: 50%;transform: translate(0,-50%);" wx:elif="{{network > 4 && network < 7}}" />
<image src="/assets/icon11.png" style="width: 20rpx;height: 20rpx;position: absolute;left: 20rpx;top: 50%;transform: translate(0,-50%);" wx:if="{{network === 0}}" />
<image src="/assets/icon12.png" style="width: 20rpx;height: 20rpx;position: absolute;left: 20rpx;top: 50%;transform: translate(0,-50%);" wx:elif="{{network === 2}}" />
<image src="/assets/icon14.png" style="width: 20rpx;height: 20rpx;position: absolute;left: 20rpx;top: 50%;transform: translate(0,-50%);" wx:elif="{{network === -1}}" />
<image src="/assets/icon13.png" style="width: 20rpx;height: 20rpx;position: absolute;left: 20rpx;top: 50%;transform: translate(0,-50%);" wx:else /> -->
<image src="/assets/icon13.png" style="width: 20rpx;height: 20rpx;position: absolute;left: 20rpx;top: 50%;transform: translate(0,-50%);" wx:else />
</view>
<view class="meeting-content">
<view class="meeting-content-noAdmin" wx:if="{{isAdmin === 0}}">