Compare commits
10 Commits
dfd5665ca4
...
c615a96e2f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c615a96e2f | ||
|
|
19d61ee266 | ||
|
|
2f5fcace53 | ||
|
|
e153d5cb6c | ||
|
|
74ee0a696b | ||
|
|
47558cdaee | ||
|
|
583487a52e | ||
|
|
e9227892a0 | ||
|
|
13bf747f7a | ||
|
|
0cf725a07c |
@ -1,3 +1,37 @@
|
||||
{
|
||||
"prompt" : "template"
|
||||
"version" : "1",
|
||||
"prompt" : "template",
|
||||
"title" : "用户协议与隐私政策",
|
||||
"message" : "请你务必审慎阅读、充分理解“用户协议与隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/> 你可阅读<a href=\"https://app.xinelu.cn/privacypolicy/content.html\">《用户协议与隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。",
|
||||
"buttonAccept" : "同意并接受",
|
||||
"buttonRefuse" : "暂不同意",
|
||||
"hrefLoader" : "system|default",
|
||||
"second" : {
|
||||
"title" : "确认提示",
|
||||
"message" : "进入应用前,你需先同意<a href=\"https://app.xinelu.cn/privacypolicy/content.html\">《用户协议与隐私政策》</a>,否则将退出应用。",
|
||||
"buttonAccept" : "同意并继续",
|
||||
"buttonRefuse" : "退出应用"
|
||||
},
|
||||
"disagreeMode" : {
|
||||
"support" : false,
|
||||
"loadNativePlugins" : false,
|
||||
"visitorEntry" : false,
|
||||
"showAlways" : false
|
||||
},
|
||||
"styles" : {
|
||||
"backgroundColor" : "#ffffff",
|
||||
"borderRadius" : "5px",
|
||||
"title" : {
|
||||
"color" : "#000000"
|
||||
},
|
||||
"buttonAccept" : {
|
||||
"color" : "#000000"
|
||||
},
|
||||
"buttonRefuse" : {
|
||||
"color" : "#000000"
|
||||
},
|
||||
"buttonVisitor" : {
|
||||
"color" : "#000000"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
var baseurl = "https://1608.xinelu.cn";
|
||||
// var baseurl = "http://8.131.93.145:54011";
|
||||
export default baseurl
|
||||
var baseurl = "https://hekou-nurse-api.xinyilu.cn";
|
||||
export default baseurl
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
var socketurl = "wss://1608.xinelu.cn/webSocket/";
|
||||
|
||||
var socketurl = "wss://hekou-nurse-api.xinyilu.cn/webSocket/";
|
||||
export default socketurl
|
||||
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,9 +1,9 @@
|
||||
{
|
||||
"name" : "xinelu-doctor-app",
|
||||
"name" : "医生助手",
|
||||
"appid" : "__UNI__9BA7A08",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : 100,
|
||||
"versionName" : "1.0.1",
|
||||
"versionCode" : 101,
|
||||
"transformPx" : false,
|
||||
/* 5+App特有相关 */
|
||||
"app-plus" : {
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
}
|
||||
},
|
||||
onLoad(e) {
|
||||
console.log(e)
|
||||
if (e) {
|
||||
this.list = JSON.parse(e.list)
|
||||
}
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
<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">
|
||||
<view class="inputitem">
|
||||
<i class="icon"></i>
|
||||
<input type="text" name="" id="" class="input" placeholder="搜索" v-model="formdata.name">
|
||||
<input type="text" name="" id="" class="input" placeholder="搜索" v-model="formdata.patientName">
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -23,7 +22,7 @@
|
||||
<image src="../../static/headsculpture.png" mode=""></image>
|
||||
<view class="name">
|
||||
{{item.patientName?item.patientName+' ':' '}}
|
||||
( {{item.problemDescription?item.problemDescription:''}} )
|
||||
{{item.problemDescription?"("+item.problemDescription+')':''}}
|
||||
</view>
|
||||
<view class="text">
|
||||
{{Number(item.messageType)==1?item.content?item.content:'':''}}
|
||||
@ -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,114 +79,58 @@
|
||||
tabscurrent: 0,
|
||||
optionindex: 0,
|
||||
optionname: '全部',
|
||||
missionlist: [],
|
||||
missiontotal: 0,
|
||||
remark: '',
|
||||
formdata: {
|
||||
patientName: '',
|
||||
pageNum: 1,
|
||||
pageSize: 1000,
|
||||
doctorId: uni.getStorageSync("id"),
|
||||
consultationType: 'IMAGE_TEXT_CONSULTATION',
|
||||
// consultationType: 'IMAGE_TEXT_CONSULTATION',
|
||||
status: '',
|
||||
},
|
||||
listinfo: [],
|
||||
listtotal: 0,
|
||||
status: '',
|
||||
SOCKETURL: '',
|
||||
socketOpen: false,
|
||||
timeoutObj: null,
|
||||
status: '',
|
||||
title: '',
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
"formdata.patientName": {
|
||||
handler(newvalue, oldvalue) {
|
||||
if (this.status == 1) {
|
||||
this.info()
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
onReady() { //更改导航栏文字
|
||||
uni.setNavigationBarTitle({
|
||||
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({
|
||||
|
||||
@ -2,20 +2,19 @@
|
||||
<view class="app">
|
||||
<image src="../../static/logos.png" mode=""></image>
|
||||
<view class="text">
|
||||
欢迎加入新医路
|
||||
欢迎登录医生助手
|
||||
</view>
|
||||
<view class="body">
|
||||
<view class="login">
|
||||
<!-- <view class="login">
|
||||
<view class="logins" @tap="pwdlogin">
|
||||
登录
|
||||
</view>
|
||||
<view class="border">
|
||||
</view>
|
||||
</view>
|
||||
</view> -->
|
||||
<view class="name">
|
||||
<u-form :model="form" ref="uForm" label-width="110">
|
||||
<u-form-item label="用户名:"><u-input placeholder="请输入用户名" maxlength="11"
|
||||
v-model="personAccount" /></u-form-item>
|
||||
<u-form-item label="用户名:"><u-input placeholder="请输入用户名" v-model="personAccount" /></u-form-item>
|
||||
<u-form-item label="密码:">
|
||||
<u-input placeholder="请输入密码" :password-icon="true" type="password" v-model="personPassword" />
|
||||
<!-- <span class="pwd">忘记密码</span> -->
|
||||
@ -35,6 +34,9 @@
|
||||
appLogin,
|
||||
createMobileToken
|
||||
} from '@/api/login/index.js'
|
||||
import {
|
||||
mapMutations
|
||||
} from "vuex";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -55,13 +57,21 @@
|
||||
// this.password = options.password
|
||||
// }
|
||||
// },
|
||||
onShow() {
|
||||
this.personAccount = uni.getStorageSync('loginform').personAccount
|
||||
this.personPassword = uni.getStorageSync('loginform').personPassword
|
||||
},
|
||||
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: '当前用户无权限',
|
||||
@ -69,6 +79,11 @@
|
||||
duration: '1500'
|
||||
})
|
||||
} else if (res.data.data.status == 2 || res.data.data.status == 1) {
|
||||
let form = {
|
||||
personAccount: this.personAccount,
|
||||
personPassword: this.personPassword
|
||||
}
|
||||
uni.setStorageSync('loginform', form);
|
||||
that.$refs.uToast.show({
|
||||
title: '登录成功',
|
||||
type: 'success',
|
||||
@ -81,13 +96,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,
|
||||
@ -122,16 +134,15 @@
|
||||
overflow: scroll;
|
||||
|
||||
.text {
|
||||
width: 235rpx;
|
||||
height: 30rpx;
|
||||
font-size: 32rpx;
|
||||
font-family: SourceHanSansCN-Medium, SourceHanSansCN;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
top: 22%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 100%;
|
||||
left: 0;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
image {
|
||||
@ -227,6 +238,5 @@
|
||||
border-radius: 100rpx
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
@ -27,7 +27,7 @@
|
||||
<image src="../../static/huijiantou.png" mode=""></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="myorder titles">
|
||||
<!-- <view class="myorder titles">
|
||||
<view class="title">
|
||||
检查更新
|
||||
</view>
|
||||
@ -42,7 +42,7 @@
|
||||
<view class="righttitle">
|
||||
<image src="../../static/huijiantou.png" mode=""></image>
|
||||
</view>
|
||||
</view>
|
||||
</view> -->
|
||||
<view class="myorder titles" @tap="remove()">
|
||||
<view class="title">
|
||||
退出账号
|
||||
@ -213,17 +213,20 @@
|
||||
uni.closeSocket();
|
||||
}
|
||||
uni.closeSocket();
|
||||
uni.clearStorageSync();
|
||||
uni.removeStorageSync('id');
|
||||
uni.removeStorageSync('status');
|
||||
that.$refs.uToast.show({
|
||||
title: '退出账号成功',
|
||||
type: 'success',
|
||||
duration: '1000'
|
||||
})
|
||||
uni.closeSocket();
|
||||
clearInterval(that.$store.state.timeoutObj);
|
||||
setTimeout(e => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}, 1000)
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -11,7 +11,8 @@
|
||||
<view class="navbartitle" @tap="goprevious">
|
||||
{{title}}
|
||||
</view>
|
||||
<view class="navbarrighttitle" @tap='editconsultationInfoshowtrue' v-show='Number(currentItem.status)!=2'>
|
||||
<view class="navbarrighttitle" @tap='editconsultationInfoshowtrue'
|
||||
v-show="Number(currentItem.status)!=2&¤tItem.consultationType=='IMAGE TEXT CONSULTATION'">
|
||||
已解决
|
||||
</view>
|
||||
</u-navbar>
|
||||
@ -38,7 +39,8 @@
|
||||
<view class="placeholder" id="placeholder"></view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<image class="background" src="/static/huanzhe.png" mode="" @tap="information"></image>
|
||||
<image class="background" src="/static/huanzhe.png" mode="" @tap="information"
|
||||
v-if="currentItem.consultationType=='IMAGE TEXT CONSULTATION'"></image>
|
||||
<!-- 底部输入 -->
|
||||
<view class="input-box" :class="{ 'input-box-mpInputMargin': mpInputMargin }"
|
||||
v-if='Number(currentItem.status)!=2'>
|
||||
@ -97,6 +99,9 @@
|
||||
markRead,
|
||||
editconsultationInfo
|
||||
} from '@/api/seekadvicefrom/seekadvicefrom.js';
|
||||
import {
|
||||
mapMutations
|
||||
} from "vuex";
|
||||
import baseurl from '@/api/baseurl.js'
|
||||
export default {
|
||||
data() {
|
||||
@ -172,6 +177,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 +188,7 @@
|
||||
this.userName = this.currentItem.doctorName
|
||||
this.SOCKETURL = this.SOCKETURL + this.currentItem.doctorId
|
||||
this.getPageHistory()
|
||||
this.scoket()
|
||||
this.messagescoket()
|
||||
},
|
||||
mounted() {
|
||||
// this.infolist()
|
||||
@ -189,6 +197,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 +272,7 @@
|
||||
}
|
||||
getChatRecord(obj).then(res => {
|
||||
res.data.forEach(e => {
|
||||
if (e.readStatus == 0) {
|
||||
if (Number(e.readStatus) == 0) {
|
||||
this.Read()
|
||||
}
|
||||
})
|
||||
@ -301,7 +341,8 @@
|
||||
senderName: that.currentItem.doctorName,
|
||||
messageType: 1,
|
||||
sendTime: new Date(),
|
||||
content: this.formData.content
|
||||
content: this.formData.content,
|
||||
sourcePlatform: 'APP'
|
||||
}
|
||||
that.formData.content = '' //清空输入框的文本
|
||||
sendMessage(obj).then(res => {
|
||||
@ -453,7 +494,8 @@
|
||||
senderName: that.currentItem.doctorName,
|
||||
messageType: 2,
|
||||
sendTime: new Date(),
|
||||
content: fileurls.fileUrl
|
||||
content: fileurls.fileUrl,
|
||||
sourcePlatform: 'APP'
|
||||
}
|
||||
sendMessage(obj).then(respp => {
|
||||
if (respp.code == 200) {
|
||||
@ -502,77 +544,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
|
||||
|
||||
BIN
static/logos.png
BIN
static/logos.png
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 99 KiB |
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