修改
This commit is contained in:
parent
0cf725a07c
commit
13bf747f7a
23
main.js
23
main.js
@ -2,23 +2,28 @@ import App from './App'
|
||||
|
||||
// #ifndef VUE3
|
||||
import Vue from 'vue'
|
||||
import uView from "uview-ui";
|
||||
import './uni.promisify.adaptor'
|
||||
// main.js
|
||||
import uView from "uview-ui";
|
||||
import store from "@/store/index.js"
|
||||
Vue.use(uView);
|
||||
Vue.config.productionTip = false
|
||||
App.mpType = 'app'
|
||||
Vue.use(uView);
|
||||
const app = new Vue({
|
||||
...App
|
||||
store,
|
||||
...App
|
||||
})
|
||||
app.$mount()
|
||||
// #endif
|
||||
|
||||
// #ifdef VUE3
|
||||
import { createSSRApp } from 'vue'
|
||||
import {
|
||||
createSSRApp
|
||||
} from 'vue'
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
return {
|
||||
app
|
||||
}
|
||||
const app = createSSRApp(App)
|
||||
return {
|
||||
app
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
// #endif
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
<template>
|
||||
<view class="app">
|
||||
<!-- 家医 -->
|
||||
<!-- scoket聊天 -->
|
||||
<view class="" v-if="status==1">
|
||||
<u-sticky>
|
||||
<view class="">
|
||||
<!-- 只能有一个根元素 -->
|
||||
<u-tabs :list="tabslist" :is-scroll="false" :current="tabscurrent" @change="tabschange"
|
||||
inactive-color='#fff' active-color='#fff'></u-tabs>
|
||||
<view class="inputs">
|
||||
@ -56,7 +55,9 @@
|
||||
getSex
|
||||
} from '@/utils/conversion.js'
|
||||
import protocol from '@/pages/workorder/workorder.vue'
|
||||
import socketurl from '@/api/socketurl.js'
|
||||
import {
|
||||
mapMutations
|
||||
} from "vuex";
|
||||
export default {
|
||||
components: {
|
||||
protocol,
|
||||
@ -78,9 +79,6 @@
|
||||
tabscurrent: 0,
|
||||
optionindex: 0,
|
||||
optionname: '全部',
|
||||
missionlist: [],
|
||||
missiontotal: 0,
|
||||
remark: '',
|
||||
formdata: {
|
||||
pageNum: 1,
|
||||
pageSize: 1000,
|
||||
@ -91,10 +89,6 @@
|
||||
listinfo: [],
|
||||
listtotal: 0,
|
||||
status: '',
|
||||
SOCKETURL: '',
|
||||
socketOpen: false,
|
||||
timeoutObj: null,
|
||||
status: '',
|
||||
title: '',
|
||||
}
|
||||
},
|
||||
@ -103,89 +97,30 @@
|
||||
title: this.title,
|
||||
});
|
||||
},
|
||||
onLoad() {
|
||||
onShow() {
|
||||
if (uni.getStorageSync('id') && !this.$store.state.socketOpen) {
|
||||
this.scoket();
|
||||
}
|
||||
this.down = 1
|
||||
this.Refresh = 1
|
||||
this.status = uni.getStorageSync("status")
|
||||
if (this.status == 2) {
|
||||
this.title = '工单'
|
||||
} else {
|
||||
this.title = '消息列表'
|
||||
this.SOCKETURL = socketurl + uni.getStorageSync("id")
|
||||
this.connectSocket();
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.down = 1
|
||||
this.Refresh = 1
|
||||
if (this.status == 1) {
|
||||
this.info()
|
||||
this.socket();
|
||||
this.messagesocket();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
connectSocket() {
|
||||
let that = this
|
||||
console.log(that.SOCKETURL)
|
||||
try {
|
||||
uni.connectSocket({
|
||||
url: that.SOCKETURL
|
||||
})
|
||||
uni.onSocketOpen(res => {
|
||||
console.log('webScoket连接已打开', res);
|
||||
that.socketOpen = true
|
||||
that.reset()
|
||||
})
|
||||
uni.onSocketError(err => {
|
||||
console.log('webScoket连接打开失败', err);
|
||||
if (err && err.code != 1000) {
|
||||
setTimeout(() => {
|
||||
that.socketOpen = true
|
||||
uni.connectSocket({
|
||||
url: that.SOCKETURL
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
uni.onSocketClose(err => {
|
||||
console.log('webScoket连接关闭', err);
|
||||
if (err && err.code !== 1000) {
|
||||
setTimeout(() => {
|
||||
that.socketOpen = true
|
||||
uni.connectSocket({
|
||||
url: that.SOCKETURL
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
socket() {
|
||||
...mapMutations(['scoket']),
|
||||
messagesocket() {
|
||||
let that = this
|
||||
uni.onSocketMessage(res => {
|
||||
console.log("webScoket监听收到的信息", res);
|
||||
that.info();
|
||||
})
|
||||
},
|
||||
reset() {
|
||||
let that = this
|
||||
clearInterval(that.timeoutObj);
|
||||
that.timeoutObj = setInterval(() => {
|
||||
uni.sendSocketMessage({
|
||||
data: 'ping',
|
||||
success(res) {
|
||||
console.log('正在发送心跳');
|
||||
},
|
||||
fail(err) {
|
||||
console.log('心跳发送失败,重新连接...');
|
||||
that.socketOpen = true
|
||||
uni.connectSocket({
|
||||
url: that.SOCKETURL
|
||||
})
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
},
|
||||
//前往聊天
|
||||
goseekadvicefrom(item) {
|
||||
uni.navigateTo({
|
||||
@ -593,4 +528,4 @@
|
||||
::v-deep .u-cell-box {}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@ -35,6 +35,9 @@
|
||||
appLogin,
|
||||
createMobileToken
|
||||
} from '@/api/login/index.js'
|
||||
import {
|
||||
mapMutations
|
||||
} from "vuex";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -56,12 +59,16 @@
|
||||
// }
|
||||
// },
|
||||
methods: {
|
||||
...mapMutations(['scoket']),
|
||||
login() {
|
||||
var that = this
|
||||
appLogin(this.personAccount, this.personPassword).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
uni.setStorageSync("id", res.data.data.id)
|
||||
uni.setStorageSync("status", res.data.data.status)
|
||||
if (res.data.data.status == 1) {
|
||||
that.scoket()
|
||||
}
|
||||
if (res.data.data.status == 3) {
|
||||
that.$refs.uToast.show({
|
||||
title: '当前用户无权限',
|
||||
@ -81,13 +88,10 @@
|
||||
uni.reLaunch({
|
||||
url: '/pages/homepage/homepage',
|
||||
})
|
||||
}, 1500)
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
// uni.setStorageSync("nursePersonName", res.data.nursePersonName)
|
||||
// uni.setStorageSync("nurseStationId", res.data.nurseStationId)
|
||||
|
||||
|
||||
} else {
|
||||
that.$refs.uToast.show({
|
||||
title: res.data.msg,
|
||||
@ -229,4 +233,4 @@
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@ -219,11 +219,13 @@
|
||||
type: 'success',
|
||||
duration: '1000'
|
||||
})
|
||||
uni.closeSocket();
|
||||
clearInterval(that.$store.state.timeoutObj);
|
||||
setTimeout(e => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}, 1000)
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -461,4 +463,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@ -97,6 +97,9 @@
|
||||
markRead,
|
||||
editconsultationInfo
|
||||
} from '@/api/seekadvicefrom/seekadvicefrom.js';
|
||||
import {
|
||||
mapMutations
|
||||
} from "vuex";
|
||||
import baseurl from '@/api/baseurl.js'
|
||||
export default {
|
||||
data() {
|
||||
@ -172,6 +175,9 @@
|
||||
// });
|
||||
},
|
||||
onLoad(options) {
|
||||
if (uni.getStorageSync('id') && !this.$store.state.socketOpen) {
|
||||
this.scoket();
|
||||
}
|
||||
this.baseurl = baseurl;
|
||||
// uni.closeSocket()
|
||||
this.currentItem = JSON.parse(options.item)
|
||||
@ -180,7 +186,7 @@
|
||||
this.userName = this.currentItem.doctorName
|
||||
this.SOCKETURL = this.SOCKETURL + this.currentItem.doctorId
|
||||
this.getPageHistory()
|
||||
this.scoket()
|
||||
this.messagescoket()
|
||||
},
|
||||
mounted() {
|
||||
// this.infolist()
|
||||
@ -189,6 +195,38 @@
|
||||
// })
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(['scoket']),
|
||||
messagescoket() {
|
||||
const that = this
|
||||
try {
|
||||
uni.onSocketMessage(res => {
|
||||
console.log("webScoket监听收到的信息", res);
|
||||
that.getPageHistory()
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
// 心跳响应
|
||||
reset() {
|
||||
let that = this
|
||||
clearInterval(that.timeoutObj);
|
||||
that.timeoutObj = setInterval(() => {
|
||||
uni.sendSocketMessage({
|
||||
data: 'ping',
|
||||
success(res) {
|
||||
console.log('正在发送心跳');
|
||||
},
|
||||
fail(err) {
|
||||
console.log('心跳发送失败,重新连接...');
|
||||
// that.socketOpen = true
|
||||
uni.connectSocket({
|
||||
url: that.SOCKETURL
|
||||
})
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
},
|
||||
editupdata() {
|
||||
var obj = {
|
||||
status: 2,
|
||||
@ -232,7 +270,7 @@
|
||||
}
|
||||
getChatRecord(obj).then(res => {
|
||||
res.data.forEach(e => {
|
||||
if (e.readStatus == 0) {
|
||||
if (Number(e.readStatus) == 0) {
|
||||
this.Read()
|
||||
}
|
||||
})
|
||||
@ -502,77 +540,6 @@
|
||||
}).exec();
|
||||
}, 200)
|
||||
},
|
||||
scoket() {
|
||||
const that = this
|
||||
// this.socketOpen = false
|
||||
try {
|
||||
// uni.connectSocket({
|
||||
// url: that.SOCKETURL
|
||||
// })
|
||||
// uni.onSocketOpen(res => {
|
||||
// console.log('webScoket连接已打开', res);
|
||||
// that.socketOpen = true
|
||||
// that.reset()
|
||||
// })
|
||||
// uni.onSocketError(err => {
|
||||
// console.log('webScoket连接打开失败', err);
|
||||
// if (err && err.code != 1000) {
|
||||
// setTimeout(() => {
|
||||
// that.socketOpen = true
|
||||
// uni.connectSocket({
|
||||
// url: that.SOCKETURL
|
||||
// })
|
||||
// }, 3 * 1000)
|
||||
// }
|
||||
// })
|
||||
// uni.onSocketClose(err => {
|
||||
// console.log('webScoket连接关闭', err);
|
||||
// if (err && err.code !== 1000) {
|
||||
// setTimeout(() => {
|
||||
// that.socketOpen = true
|
||||
// uni.connectSocket({
|
||||
// url: that.SOCKETURL
|
||||
// })
|
||||
// }, 3 * 1000)
|
||||
// }
|
||||
// })
|
||||
uni.onSocketMessage(res => {
|
||||
console.log("webScoket监听收到的信息", res);
|
||||
that.newsList.push({
|
||||
senderName: that.currentItem.patientName,
|
||||
content: JSON.parse(res.data).message,
|
||||
messageType: Number(JSON.parse(res.data).messageType)
|
||||
})
|
||||
query.select('.input-box').boundingClientRect(data => {
|
||||
that.inputboxtop = data.height //赋值,待会要用
|
||||
that.scrollTop = that.scrollTop + 1;
|
||||
}).exec();
|
||||
that.Read()
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
// 心跳响应
|
||||
reset() {
|
||||
let that = this
|
||||
clearInterval(that.timeoutObj);
|
||||
that.timeoutObj = setInterval(() => {
|
||||
uni.sendSocketMessage({
|
||||
data: 'ping',
|
||||
success(res) {
|
||||
console.log('正在发送心跳');
|
||||
},
|
||||
fail(err) {
|
||||
console.log('心跳发送失败,重新连接...');
|
||||
// that.socketOpen = true
|
||||
uni.connectSocket({
|
||||
url: that.SOCKETURL
|
||||
})
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
},
|
||||
back() {
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
@ -882,4 +849,4 @@
|
||||
bottom: 38rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
69
store/index.js
Normal file
69
store/index.js
Normal file
@ -0,0 +1,69 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import socketurl from '@/api/socketurl.js'
|
||||
Vue.use(Vuex)
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
//公共的变量,这里的变量不能随便修改,只能通过触发mutations的方法才能改变
|
||||
timeoutObj: null,
|
||||
socketOpen: false,
|
||||
SOCKETURL: '',
|
||||
},
|
||||
mutations: {
|
||||
scoket(state) {
|
||||
state.SOCKETURL = socketurl + uni.getStorageSync('id')
|
||||
state.socketOpen = false
|
||||
try {
|
||||
uni.connectSocket({
|
||||
url: state.SOCKETURL
|
||||
})
|
||||
uni.onSocketOpen(res => {
|
||||
console.log('webScoket连接已打开', res);
|
||||
state.socketOpen = true
|
||||
clearInterval(state.timeoutObj);
|
||||
state.timeoutObj = setInterval(() => {
|
||||
uni.sendSocketMessage({
|
||||
data: 'ping',
|
||||
success(res) {
|
||||
console.log('正在发送心跳');
|
||||
},
|
||||
fail(err) {
|
||||
console.log('心跳发送失败,重新连接...');
|
||||
state.socketOpen = true
|
||||
uni.connectSocket({
|
||||
url: state.SOCKETURL
|
||||
})
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
})
|
||||
uni.onSocketError(err => {
|
||||
console.log('webScoket连接打开失败', err);
|
||||
if (err && err.code != 1000) {
|
||||
setTimeout(() => {
|
||||
state.socketOpen = true
|
||||
uni.connectSocket({
|
||||
url: state.SOCKETURL
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
uni.onSocketClose(err => {
|
||||
console.log('webScoket连接关闭', err);
|
||||
if (err && err.code !== 1000) {
|
||||
setTimeout(() => {
|
||||
state.socketOpen = true
|
||||
uni.connectSocket({
|
||||
url: state.SOCKETURL
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
},
|
||||
actions: {}
|
||||
})
|
||||
export default store
|
||||
Loading…
Reference in New Issue
Block a user