字段修改,添加websocket
This commit is contained in:
@@ -27,7 +27,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {getBillsCount} from '@/utils/getData2.js'
|
||||
// import {getBillsCount} from '@/utils/getData2.js'
|
||||
import { sendWebsocket, closeWebsocket } from '@/utils/websocket.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -38,24 +39,50 @@
|
||||
},
|
||||
onLoad () {
|
||||
this._getBillsCount()
|
||||
this.intervalId = setInterval(this._getBillsCount, this.$store.getters.setTime)
|
||||
// this.intervalId = setInterval(this._getBillsCount, this.$store.getters.setTime)
|
||||
},
|
||||
onUnload () {
|
||||
closeWebsocket(true)
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async _getBillsCount () {
|
||||
let res = await getBillsCount()
|
||||
if (res.code === 1) {
|
||||
this.menuList = [...res.result]
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.desc,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
// async _getBillsCount () {
|
||||
// let res = await getBillsCount()
|
||||
// if (res.code === 1) {
|
||||
// this.menuList = [...res.result]
|
||||
// } else {
|
||||
// uni.showToast({
|
||||
// title: res.desc,
|
||||
// icon: 'none'
|
||||
// })
|
||||
// }
|
||||
// },
|
||||
_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 = ''
|
||||
|
||||
Reference in New Issue
Block a user