优化websocket

This commit is contained in:
2024-04-30 13:51:32 +08:00
parent 243ef444c7
commit 068ffaaf6c
8 changed files with 70 additions and 84 deletions

View File

@@ -32,12 +32,16 @@
data() {
return {
intervalId: null,
interTime: this.$store.getters.setTime,
userName: this.$store.getters.userInfo !== '' ? JSON.parse(this.$store.getters.userInfo).username : '',
menuList: []
};
},
created () {
onLoad() {
// setTimeout(() => {
// uni.showLoading({
// title: '加载中...'
// })
// }, 200)
this._getBillsCount()
},
beforeDestroy () {
@@ -60,16 +64,8 @@
wsMessage (res) {
console.log(res)
clearTimeout(this.intervalId)
let data = res.head
this.$store.dispatch('materObj', res.home.result)
if (data.code === '1') {
this.menuList = [...data.result]
} else {
uni.showToast({
title: data.desc,
icon: 'none'
})
}
// uni.hideLoading()
this.menuList = [...res]
},
wsErr () {
this.intervalId = setTimeout(() => {
@@ -79,15 +75,15 @@
toPage (e) {
let url = ''
url = '/pages/management/in-storage?id=' + e.djlx + '&name=' + e.name + '&type=' + e.ywlx
uni.redirectTo({
uni.navigateTo({
url: url
})
},
Quit () {
this.$store.dispatch('delUserInfo', '')
uni.redirectTo({
url: '/pages/login/login'
})
this.$store.dispatch('delUserInfo', '')
uni.redirectTo({
url: '/pages/login/login'
})
}
}
}

View File

@@ -28,7 +28,6 @@
<script>
import {getBillsCount} from '@/utils/getData2.js'
import { sendWebsocket, closeWebsocket } from '@/utils/websocket.js'
export default {
data() {
return {
@@ -45,12 +44,10 @@
}, this.interTime)
},
beforeDestroy () {
// closeWebsocket(true)
clearInterval(this.intervalId)
this.intervalId = null
},
destroyed () {
// closeWebsocket(true)
clearInterval(this.intervalId)
this.intervalId = null
},
@@ -66,31 +63,6 @@
})
}
},
// _getBillsCount () {
// let getTimestamp = new Date().getTime()
// let url = this.$store.getters.baseUrl
// url = url.substring(7)
// sendWebsocket('ws://' + url + '/webSocket/SendHomeInfo/' + getTimestamp, {}, this.wsMessage, this.wsErr)
// },
// wsMessage (res) {
// console.log(res)
// clearTimeout(this.intervalId)
// let data = res.head
// this.$store.dispatch('materObj', res.home.result)
// if (data.code === '1') {
// this.menuList = [...data.result]
// } else {
// uni.showToast({
// title: data.desc,
// icon: 'none'
// })
// }
// },
// wsErr () {
// this.intervalId = setTimeout(() => {
// this._getBillsCount()
// }, 10000)
// },
toPage (e) {
let url = ''
url = '/pages/management/in-storage?id=' + e.djlx + '&name=' + e.name + '&type=' + e.ywlx