修改
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
|
// #ifndef VUE3
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import uView from "uview-ui";
|
|
||||||
import './uni.promisify.adaptor'
|
import './uni.promisify.adaptor'
|
||||||
|
// main.js
|
||||||
|
import uView from "uview-ui";
|
||||||
|
import store from "@/store/index.js"
|
||||||
|
Vue.use(uView);
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
App.mpType = 'app'
|
App.mpType = 'app'
|
||||||
Vue.use(uView);
|
|
||||||
const app = new Vue({
|
const app = new Vue({
|
||||||
...App
|
store,
|
||||||
|
...App
|
||||||
})
|
})
|
||||||
app.$mount()
|
app.$mount()
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef VUE3
|
// #ifdef VUE3
|
||||||
import { createSSRApp } from 'vue'
|
import {
|
||||||
|
createSSRApp
|
||||||
|
} from 'vue'
|
||||||
export function createApp() {
|
export function createApp() {
|
||||||
const app = createSSRApp(App)
|
const app = createSSRApp(App)
|
||||||
return {
|
return {
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="app">
|
<view class="app">
|
||||||
<!-- 家医 -->
|
<!-- scoket聊天 -->
|
||||||
<view class="" v-if="status==1">
|
<view class="" v-if="status==1">
|
||||||
<u-sticky>
|
<u-sticky>
|
||||||
<view class="">
|
<view class="">
|
||||||
<!-- 只能有一个根元素 -->
|
|
||||||
<u-tabs :list="tabslist" :is-scroll="false" :current="tabscurrent" @change="tabschange"
|
<u-tabs :list="tabslist" :is-scroll="false" :current="tabscurrent" @change="tabschange"
|
||||||
inactive-color='#fff' active-color='#fff'></u-tabs>
|
inactive-color='#fff' active-color='#fff'></u-tabs>
|
||||||
<view class="inputs">
|
<view class="inputs">
|
||||||
@ -56,7 +55,9 @@
|
|||||||
getSex
|
getSex
|
||||||
} from '@/utils/conversion.js'
|
} from '@/utils/conversion.js'
|
||||||
import protocol from '@/pages/workorder/workorder.vue'
|
import protocol from '@/pages/workorder/workorder.vue'
|
||||||
import socketurl from '@/api/socketurl.js'
|
import {
|
||||||
|
mapMutations
|
||||||
|
} from "vuex";
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
protocol,
|
protocol,
|
||||||
@ -78,9 +79,6 @@
|
|||||||
tabscurrent: 0,
|
tabscurrent: 0,
|
||||||
optionindex: 0,
|
optionindex: 0,
|
||||||
optionname: '全部',
|
optionname: '全部',
|
||||||
missionlist: [],
|
|
||||||
missiontotal: 0,
|
|
||||||
remark: '',
|
|
||||||
formdata: {
|
formdata: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 1000,
|
pageSize: 1000,
|
||||||
@ -91,10 +89,6 @@
|
|||||||
listinfo: [],
|
listinfo: [],
|
||||||
listtotal: 0,
|
listtotal: 0,
|
||||||
status: '',
|
status: '',
|
||||||
SOCKETURL: '',
|
|
||||||
socketOpen: false,
|
|
||||||
timeoutObj: null,
|
|
||||||
status: '',
|
|
||||||
title: '',
|
title: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -103,89 +97,30 @@
|
|||||||
title: this.title,
|
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")
|
this.status = uni.getStorageSync("status")
|
||||||
if (this.status == 2) {
|
if (this.status == 2) {
|
||||||
this.title = '工单'
|
this.title = '工单'
|
||||||
} else {
|
} else {
|
||||||
this.title = '消息列表'
|
this.title = '消息列表'
|
||||||
this.SOCKETURL = socketurl + uni.getStorageSync("id")
|
|
||||||
this.connectSocket();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onShow() {
|
|
||||||
this.down = 1
|
|
||||||
this.Refresh = 1
|
|
||||||
if (this.status == 1) {
|
|
||||||
this.info()
|
this.info()
|
||||||
this.socket();
|
this.messagesocket();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
connectSocket() {
|
...mapMutations(['scoket']),
|
||||||
let that = this
|
messagesocket() {
|
||||||
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() {
|
|
||||||
let that = this
|
let that = this
|
||||||
uni.onSocketMessage(res => {
|
uni.onSocketMessage(res => {
|
||||||
console.log("webScoket监听收到的信息", res);
|
console.log("webScoket监听收到的信息", res);
|
||||||
that.info();
|
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) {
|
goseekadvicefrom(item) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
@ -593,4 +528,4 @@
|
|||||||
::v-deep .u-cell-box {}
|
::v-deep .u-cell-box {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -35,6 +35,9 @@
|
|||||||
appLogin,
|
appLogin,
|
||||||
createMobileToken
|
createMobileToken
|
||||||
} from '@/api/login/index.js'
|
} from '@/api/login/index.js'
|
||||||
|
import {
|
||||||
|
mapMutations
|
||||||
|
} from "vuex";
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -56,12 +59,16 @@
|
|||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapMutations(['scoket']),
|
||||||
login() {
|
login() {
|
||||||
var that = this
|
var that = this
|
||||||
appLogin(this.personAccount, this.personPassword).then(res => {
|
appLogin(this.personAccount, this.personPassword).then(res => {
|
||||||
if (res.data.code == 200) {
|
if (res.data.code == 200) {
|
||||||
uni.setStorageSync("id", res.data.data.id)
|
uni.setStorageSync("id", res.data.data.id)
|
||||||
uni.setStorageSync("status", res.data.data.status)
|
uni.setStorageSync("status", res.data.data.status)
|
||||||
|
if (res.data.data.status == 1) {
|
||||||
|
that.scoket()
|
||||||
|
}
|
||||||
if (res.data.data.status == 3) {
|
if (res.data.data.status == 3) {
|
||||||
that.$refs.uToast.show({
|
that.$refs.uToast.show({
|
||||||
title: '当前用户无权限',
|
title: '当前用户无权限',
|
||||||
@ -81,13 +88,10 @@
|
|||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pages/homepage/homepage',
|
url: '/pages/homepage/homepage',
|
||||||
})
|
})
|
||||||
}, 1500)
|
}, 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// uni.setStorageSync("nursePersonName", res.data.nursePersonName)
|
// uni.setStorageSync("nursePersonName", res.data.nursePersonName)
|
||||||
// uni.setStorageSync("nurseStationId", res.data.nurseStationId)
|
// uni.setStorageSync("nurseStationId", res.data.nurseStationId)
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.$refs.uToast.show({
|
that.$refs.uToast.show({
|
||||||
title: res.data.msg,
|
title: res.data.msg,
|
||||||
@ -229,4 +233,4 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -219,11 +219,13 @@
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
duration: '1000'
|
duration: '1000'
|
||||||
})
|
})
|
||||||
|
uni.closeSocket();
|
||||||
|
clearInterval(that.$store.state.timeoutObj);
|
||||||
setTimeout(e => {
|
setTimeout(e => {
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pages/login/login'
|
url: '/pages/login/login'
|
||||||
})
|
})
|
||||||
}, 1000)
|
}, 1500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -461,4 +463,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -97,6 +97,9 @@
|
|||||||
markRead,
|
markRead,
|
||||||
editconsultationInfo
|
editconsultationInfo
|
||||||
} from '@/api/seekadvicefrom/seekadvicefrom.js';
|
} from '@/api/seekadvicefrom/seekadvicefrom.js';
|
||||||
|
import {
|
||||||
|
mapMutations
|
||||||
|
} from "vuex";
|
||||||
import baseurl from '@/api/baseurl.js'
|
import baseurl from '@/api/baseurl.js'
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -172,6 +175,9 @@
|
|||||||
// });
|
// });
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
|
if (uni.getStorageSync('id') && !this.$store.state.socketOpen) {
|
||||||
|
this.scoket();
|
||||||
|
}
|
||||||
this.baseurl = baseurl;
|
this.baseurl = baseurl;
|
||||||
// uni.closeSocket()
|
// uni.closeSocket()
|
||||||
this.currentItem = JSON.parse(options.item)
|
this.currentItem = JSON.parse(options.item)
|
||||||
@ -180,7 +186,7 @@
|
|||||||
this.userName = this.currentItem.doctorName
|
this.userName = this.currentItem.doctorName
|
||||||
this.SOCKETURL = this.SOCKETURL + this.currentItem.doctorId
|
this.SOCKETURL = this.SOCKETURL + this.currentItem.doctorId
|
||||||
this.getPageHistory()
|
this.getPageHistory()
|
||||||
this.scoket()
|
this.messagescoket()
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
// this.infolist()
|
// this.infolist()
|
||||||
@ -189,6 +195,38 @@
|
|||||||
// })
|
// })
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
editupdata() {
|
||||||
var obj = {
|
var obj = {
|
||||||
status: 2,
|
status: 2,
|
||||||
@ -232,7 +270,7 @@
|
|||||||
}
|
}
|
||||||
getChatRecord(obj).then(res => {
|
getChatRecord(obj).then(res => {
|
||||||
res.data.forEach(e => {
|
res.data.forEach(e => {
|
||||||
if (e.readStatus == 0) {
|
if (Number(e.readStatus) == 0) {
|
||||||
this.Read()
|
this.Read()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -502,77 +540,6 @@
|
|||||||
}).exec();
|
}).exec();
|
||||||
}, 200)
|
}, 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() {
|
back() {
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
delta: 1
|
delta: 1
|
||||||
@ -882,4 +849,4 @@
|
|||||||
bottom: 38rpx;
|
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