解决长连接 连接不上bug

This commit is contained in:
1340691923@qq.com 2022-01-27 13:26:00 +08:00
parent ebbf4120bf
commit a121765433
3 changed files with 52 additions and 66 deletions

View File

@ -20,7 +20,7 @@ func (this RealDataService) FailDataList(minutes int,appid int) (failDataResList
toStartOfInterval(a.part_date, INTERVAL `+strconv.Itoa(minutes)+` minute) as interval_date, toStartOfInterval(a.part_date, INTERVAL `+strconv.Itoa(minutes)+` minute) as interval_date,
formatDateTime(interval_date,'%Y-%m-%d') as year ,formatDateTime(interval_date,'%H:%M') as start_minute, formatDateTime(addMinutes(interval_date, ?),'%H:%M') as end_minute, formatDateTime(interval_date,'%Y-%m-%d') as year ,formatDateTime(interval_date,'%H:%M') as start_minute, formatDateTime(addMinutes(interval_date, ?),'%H:%M') as end_minute,
count(report_data) as count,a.error_reason,a.error_handling,report_type count(report_data) as count,a.error_reason,a.error_handling,report_type
from (select * from xwl_acceptance_status where table_id = ? and status = ? limit 1000 ) a from (select * from xwl_acceptance_status where table_id = ? and status = ? order by part_date desc limit 1000 ) a
group by interval_date,a.error_reason,a.error_handling,report_type group by interval_date,a.error_reason,a.error_handling,report_type
order by interval_date desc; order by interval_date desc;
`,minutes,appid,consumer_data.FailStatus) `,minutes,appid,consumer_data.FailStatus)

View File

@ -35,7 +35,7 @@ func Init() *App {
) )
app.Post("/api/gm_user/login", ManagerUserController{}.Login) app.Post("/api/gm_user/login", ManagerUserController{}.Login)
routerWebsocket(app)
app.Use( app.Use(
Timer, Timer,
JwtMiddleware, JwtMiddleware,
@ -44,7 +44,6 @@ func Init() *App {
runRouterGroupFn( runRouterGroupFn(
app, app,
routerWebsocket,
runOperaterLog, runOperaterLog,
runGmUser, runGmUser,
runRealData, runRealData,

View File

@ -6,14 +6,13 @@
<template slot="title"> <template slot="title">
<span>添加distinctId为白名单仅适用于客户端SDK并开启Debug模式设备ID可通过查看客户端日志获取该模式的作用及使用过程请参考官网文档对应SDK页面中的Debug模式说明部分</span> <span>添加distinctId为白名单仅适用于客户端SDK并开启Debug模式设备ID可通过查看客户端日志获取该模式的作用及使用过程请参考官网文档对应SDK页面中的Debug模式说明部分</span>
</template> </template>
<span class="title_xwl" style="color: #202d3f">Debug模式&nbsp<a-icon type="question-circle" /> <span class="title_xwl" style="color: #202d3f">Debug模式&nbsp<a-icon type="question-circle"/>
</span> </span>
</a-tooltip> </a-tooltip>
</div> </div>
<div <div
style="height: 60px;line-height: 50px;display: flex;align-items: center;justify-content: space-between;border-bottom: 1px solid #f0f2f5" style="height: 60px;line-height: 50px;display: flex;align-items: center;justify-content: space-between;border-bottom: 1px solid #f0f2f5">
>
<div> <div>
<a-button @click="openDeviceDialog">查看distinctId列表</a-button> <a-button @click="openDeviceDialog">查看distinctId列表</a-button>
<template v-if="linkedID!=''"> <template v-if="linkedID!=''">
@ -23,22 +22,15 @@
</div> </div>
<div> <div>
<a-input-search <a-input-search v-model="input" allow-clear placeholder="请输入搜索如distinctId,事件名..." style="width: 200px"
v-model="input" @change="search"/>
allow-clear
placeholder="请输入搜索如distinctId,事件名..."
style="width: 200px"
@change="search"
/>
</div> </div>
</div> </div>
<el-table <el-table border v-if="showList"
v-if="showList" v-loading="connectLoading"
v-loading="connectLoading" :data="filterList"
border stripe
:data="filterList" style="width: 100%"
stripe
style="width: 100%"
> >
<el-table-column <el-table-column
prop="report_time" prop="report_time"
@ -76,7 +68,7 @@
<template slot="title"> <template slot="title">
<span>格式化数据</span> <span>格式化数据</span>
</template> </template>
<a-button type="link" icon="eye" @click="lookData(scope.row.index,true)" /> <a-button type="link" icon="eye" @click="lookData(scope.row.index,true)"/>
</a-tooltip> </a-tooltip>
</div> </div>
<div v-else> <div v-else>
@ -93,7 +85,7 @@
<template slot="title"> <template slot="title">
<span>还原数据</span> <span>还原数据</span>
</template> </template>
<a-button style="color: red" type="link" icon="eye-invisible" @click="lookData(scope.row.index,false)" /> <a-button style="color: red" type="link" icon="eye-invisible" @click="lookData(scope.row.index,false)"/>
</a-tooltip> </a-tooltip>
</div> </div>
</template> </template>
@ -110,27 +102,20 @@
@size-change="handleSizeChange" @size-change="handleSizeChange"
@current-change="handlePageChange" @current-change="handlePageChange"
/> />
<el-dialog <el-dialog v-if="dialogVisible" width="80%" :visible.sync="dialogVisible" title="测试distinctId管理"
v-if="dialogVisible" @close="dialogVisible = false">
width="80%"
:visible.sync="dialogVisible"
title="测试distinctId管理"
@close="dialogVisible = false"
>
<el-card class="app-container"> <el-card class="app-container">
<div class="filter-container"> <div class="filter-container">
<el-tag class="filter-item">distinctId:</el-tag> <el-tag class="filter-item">distinctId:</el-tag>
<el-input v-model="deviceId" style="width: 300px" placeholder="请输入distinctId" class="filter-item" /> <el-input v-model="deviceId" style="width: 300px" placeholder="请输入distinctId" class="filter-item"/>
<el-tag class="filter-item">备注:</el-tag> <el-tag class="filter-item">备注:</el-tag>
<el-input v-model="remark" style="width: 200px" placeholder="请输入备注" class="filter-item" /> <el-input v-model="remark" style="width: 200px" placeholder="请输入备注" class="filter-item"/>
<el-button class="filter-item" type="primary" @click="addDeviceId">添加</el-button> <el-button class="filter-item" type="primary" @click="addDeviceId">添加</el-button>
</div> </div>
<el-table <el-table border v-if="showDebugDeviceList"
v-if="showDebugDeviceList" :data="debugDeviceList"
border stripe
:data="debugDeviceList" style="width: 100%"
stripe
style="width: 100%"
> >
<el-table-column <el-table-column
label="测试distinctId" label="测试distinctId"
@ -165,15 +150,10 @@
align="center" align="center"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button size="mini" type="success" icon="el-icon-link" v-if="scope.row.device_id!=linkedID"
v-if="scope.row.device_id!=linkedID" @click="initWs(scope.row.device_id)">连接设备
size="mini"
type="success"
icon="el-icon-link"
@click="initWs(scope.row.device_id)"
>连接设备
</el-button> </el-button>
<el-button v-else size="mini" type="warning" icon="el-icon-link" @click="closeWs()">断开连接</el-button> <el-button size="mini" type="warning" icon="el-icon-link" v-else @click="closeWs()">断开连接</el-button>
<el-button size="mini" type="danger" icon="el-icon-close" @click="delteDeviceId(scope.row.device_id)"> <el-button size="mini" type="danger" icon="el-icon-close" @click="delteDeviceId(scope.row.device_id)">
删除 删除
</el-button> </el-button>
@ -189,9 +169,9 @@
<script> <script>
import { AddDebugDeviceID, DebugDeviceIDList, DelDebugDeviceID } from '@/api/realdata' import {AddDebugDeviceID, DebugDeviceIDList, DelDebugDeviceID} from '@/api/realdata'
import { filterData } from '@/utils/table' import {filterData} from '@/utils/table'
import { getToken } from '@/utils/auth' import {getToken} from '@/utils/auth'
export default { export default {
@ -217,7 +197,7 @@ export default {
deviceId: '', deviceId: '',
remark: '', remark: '',
linkedID: '', linkedID: '',
socket: null socket: null,
} }
}, },
computed: { computed: {
@ -227,8 +207,15 @@ export default {
return table return table
}, },
path() { path() {
const api = process.env.VUE_APP_BASE_API let api = process.env.VUE_APP_BASE_API
return api.replace('http', 'ws') + '/ws'
if(api == ""){
return "ws://"+ window.location.host+"/ws"
}
return api.replace("http", "ws") + "/ws"
} }
}, },
mounted() { mounted() {
@ -246,7 +233,7 @@ export default {
} }
}, },
async delteDeviceId(deviceId) { async delteDeviceId(deviceId) {
const res = await DelDebugDeviceID({ 'appid': this.$store.state.baseData.EsConnectID, deviceID: deviceId }) const res = await DelDebugDeviceID({'appid': this.$store.state.baseData.EsConnectID, deviceID: deviceId})
if (res.code != 0) { if (res.code != 0) {
this.$message({ this.$message({
showClose: true, showClose: true,
@ -300,7 +287,7 @@ export default {
}, },
async deviceList() { async deviceList() {
this.connectLoading = true this.connectLoading = true
const res = await DebugDeviceIDList({ 'appid': this.$store.state.baseData.EsConnectID }) const res = await DebugDeviceIDList({'appid': this.$store.state.baseData.EsConnectID})
this.connectLoading = false this.connectLoading = false
if (res.code != 0) { if (res.code != 0) {
this.$message({ this.$message({
@ -312,7 +299,7 @@ export default {
return return
} }
const list = res.data.list let list = res.data.list
this.debugDeviceList = [] this.debugDeviceList = []
if (list != null) { if (list != null) {
this.debugDeviceList = list this.debugDeviceList = list
@ -350,45 +337,45 @@ export default {
}, },
initWs(uuid) { initWs(uuid) {
this.closeWs() this.closeWs()
if (this.linkedID != '' && uuid != this.linkedID) { if (this.linkedID != "" && uuid != this.linkedID) {
this.list = [] this.list = []
} }
if (typeof (WebSocket) === 'undefined') { if (typeof (WebSocket) === "undefined") {
this.$message({ this.$message({
showClose: true, showClose: true,
offset: 60, offset: 60,
type: 'error', type: 'error',
message: '您的浏览器不支持socket' message: "您的浏览器不支持socket"
}) })
} else { } else {
// socket // socket
this.socket = new WebSocket(this.path) this.socket = new WebSocket(this.path)
// socket // socket
this.socket.onopen = () => { this.socket.onopen = () => {
this.send(JSON.stringify({ uuid: uuid, token: getToken() })) this.send(JSON.stringify({uuid: uuid, token: getToken()}))
this.$message({ this.$message({
showClose: true, showClose: true,
offset: 60, offset: 60,
type: 'success', type: 'success',
message: 'socket连接成功' message: "socket连接成功"
}) })
} }
// socket // socket
this.socket.onerror = (err) => { this.socket.onerror = (err) => {
console.log('onerror', err) console.log("onerror", err)
this.$message({ this.$message({
showClose: true, showClose: true,
offset: 60, offset: 60,
type: 'error', type: 'error',
message: 'socket连接失败' message: "socket连接失败",
}) })
} }
// socket // socket
this.socket.onmessage = (msg) => { this.socket.onmessage = (msg) => {
const res = JSON.parse(msg.data) let res = JSON.parse(msg.data)
if (res.code == 1) { if (res.code == 1) {
const data = JSON.parse(res.data) let data = JSON.parse(res.data)
data['isFormatData'] = false data['isFormatData'] = false
data['index'] = this.list.length data['index'] = this.list.length
data['dataFormat'] = JSON.stringify(JSON.parse(data['report_data']), null, '\t') data['dataFormat'] = JSON.stringify(JSON.parse(data['report_data']), null, '\t')
@ -399,11 +386,11 @@ export default {
this.socket.onclose = (res) => { this.socket.onclose = (res) => {
if (res.code == 1006) { if (res.code == 1006) {
setTimeout(() => { setTimeout(() => {
console.log('进行重连') console.log("进行重连")
this.initWs(uuid) this.initWs(uuid)
}, 2000) }, 2000)
} }
console.log('socket已经关闭') console.log("socket已经关闭")
} }
this.linkedID = uuid this.linkedID = uuid
} }
@ -412,7 +399,7 @@ export default {
this.socket.send(data) this.socket.send(data)
}, },
async search() { async search() {
const list = filterData(this.list, this.input.trim()) let list = filterData(this.list, this.input.trim())
this.list = list this.list = list
} }
} }