Commit f37f2115 authored by 夏敏伟's avatar 夏敏伟

增加连接状态

parent d0b7ca9c
...@@ -17,6 +17,13 @@ ...@@ -17,6 +17,13 @@
<el-form-item> <el-form-item>
<img class="goBack" :src="goBack" alt="" @click="goBackFn"> <img class="goBack" :src="goBack" alt="" @click="goBackFn">
</el-form-item> </el-form-item>
<el-form-item>
<div class="searchButton"
:style="{ background: stompClient.connected ? 'Green' : 'gray', color: 'white' }">
<span :class="[!stompClient.connected ? 'el-icon-loading' : '']"></span>
{{ stompClient.connected ? '已连接' : '重连中' }}
</div>
</el-form-item>
</el-form> </el-form>
</div> </div>
<div class="ddkz-info-content"> <div class="ddkz-info-content">
...@@ -112,7 +119,7 @@ export default { ...@@ -112,7 +119,7 @@ export default {
currentChatRoomInfo: {}, currentChatRoomInfo: {},
newsList: [], newsList: [],
publicNoticeList: [], publicNoticeList: [],
stompClient: null, stompClient: { connected: false },
peopleList: [] peopleList: []
} }
}, },
...@@ -292,6 +299,21 @@ export default { ...@@ -292,6 +299,21 @@ export default {
margin-right: 35px; margin-right: 35px;
cursor: pointer; cursor: pointer;
} }
.searchButton {
width: 80px;
height: 30px;
line-height: 30px;
margin-top: 4px;
margin-right: 30px;
font-size: 14px;
text-align: center;
background-size: 100% 100%;
background-repeat: no-repeat;
border: 1px solid #3a5f94c9 !important;
border-radius: 5px;
cursor: pointer;
}
} }
.ddkz-info-content { .ddkz-info-content {
......
...@@ -17,6 +17,13 @@ ...@@ -17,6 +17,13 @@
<el-form-item> <el-form-item>
<div class="searchButton" @click="searchChatList">搜索</div> <div class="searchButton" @click="searchChatList">搜索</div>
</el-form-item> </el-form-item>
<el-form-item>
<div class="searchButton"
:style="{ background: stompClient.connected ? 'Green' : 'gray', color: 'white' }">
<span :class="[!stompClient.connected?'el-icon-loading':'']"></span>
{{stompClient.connected ? '已连接' : '重连中'}}
</div>
</el-form-item>
</el-form> </el-form>
</div> </div>
<div class="ddkz-content"> <div class="ddkz-content">
...@@ -64,7 +71,7 @@ export default { ...@@ -64,7 +71,7 @@ export default {
}, },
methods: { methods: {
showInfo(item) { showInfo(item) {
this.$router.push({ name: '聊天室详情' + this.$route.meta.type_name,params:{data:item,client:this.stompClient} }); this.$router.push({ name: '聊天室详情' + this.$route.meta.type_name, params: { data: item, client: this.stompClient } });
}, },
queryChatRoomListFn(params) { queryChatRoomListFn(params) {
getChatRoomList(params).then(res => { getChatRoomList(params).then(res => {
...@@ -79,27 +86,28 @@ export default { ...@@ -79,27 +86,28 @@ export default {
this.stompClient.heartbeat.outgoing = 20000; //若使用STOMP 1.1 版本,默认开启了心跳检测机制(默认值都是10000ms) this.stompClient.heartbeat.outgoing = 20000; //若使用STOMP 1.1 版本,默认开启了心跳检测机制(默认值都是10000ms)
this.stompClient.heartbeat.incoming = 20000; //客户端从服务端接收心跳包 this.stompClient.heartbeat.incoming = 20000; //客户端从服务端接收心跳包
this.stompClient.debug = null; this.stompClient.debug = null;
this.stompClient.connect({ name: this.userInfo.account , token: sessionStorage.getItem("token")}, frame => { this.stompClient.connect({ name: this.userInfo.account, token: sessionStorage.getItem("token") }, frame => {
// resolve("连接成功") // resolve("连接成功")
}, err => { }, err => {
console.log(new Date().toLocaleTimeString() + (typeof err == "string" ? err : err.headers.message)) console.log(new Date().toLocaleTimeString() + (typeof err == "string" ? err : err.headers.message))
reject(typeof err == "string" ? err : err.headers.message) reject(typeof err == "string" ? err : err.headers.message)
}); });
console.log(this.stompClient);
}); });
}, },
reconnect(){ reconnect() {
if (this._lockReconnect) return; if (this._lockReconnect) return;
this._lockReconnect = true; this._lockReconnect = true;
let self = this; let self = this;
setTimeout(() => { setTimeout(() => {
this.connect().catch(err=>{ this.connect().catch(err => {
self.reconnect(); self.reconnect();
}); });
self._lockReconnect = false; self._lockReconnect = false;
}, 5000); }, 5000);
}, },
searchChatList() { searchChatList() {
this.queryChatRoomListFn({ startTime: this.form.dateRange&&this.form.dateRange.length > 0 ? this.form.dateRange[0] : '2023-01-01 00:00:00', endTime: this.form.dateRange&&this.form.dateRange.length > 0 ? this.form.dateRange[1] : getTime_extent(0).pre_rq_end, userId: this.userInfo.account, keyword: this.form.keyWord == '' ? null : this.form.keyWord }); this.queryChatRoomListFn({ startTime: this.form.dateRange && this.form.dateRange.length > 0 ? this.form.dateRange[0] : '2023-01-01 00:00:00', endTime: this.form.dateRange && this.form.dateRange.length > 0 ? this.form.dateRange[1] : getTime_extent(0).pre_rq_end, userId: this.userInfo.account, keyword: this.form.keyWord == '' ? null : this.form.keyWord });
}, },
}, },
computed: { computed: {
...@@ -113,7 +121,7 @@ export default { ...@@ -113,7 +121,7 @@ export default {
}, },
mounted() { mounted() {
this.queryChatRoomListFn({ userId: this.userInfo.account }); this.queryChatRoomListFn({ userId: this.userInfo.account });
this.connect().catch(err=>{ this.connect().catch(err => {
this.reconnect(); this.reconnect();
}); });
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment