Commit 014f5ff8 authored by 高晓帆's avatar 高晓帆

日志

parent 53451bf0
import { useStateStore } from '@/store/StateStore'
import { useVehicleStore } from '@/store/VehicleStore.js'
import { useMapStore } from '@/store/MapStore.js'
import writeLog from '@/js/writeLog.js'
import router from '../../router'
import { storeToRefs } from 'pinia'
import { Message } from 'view-ui-plus'
const pingIntervalSec = 5000 // 心跳链接时间
const NETWORK_COUNT = 3
const TRUCK_MONITOR_EXIT = 15 * 60
const TOPIC_CLASS = {
vehicle: ['/vehicle/positioninfo'],
map: ['/map/obstacles', '/map/lanenode', '/map/lane', '/map/runablearea', '/map/centerline', '/map/diggingworkarea', '/map/dumparea', '/map/barricade', '/map/stationarea', '/map/parkspot', '/map/staticobjs', '/map/electronicFence', 'mapVersionAck'],
path: ['/vehicle/currPathinfo', '/vehicle/nextPathinfo', '/singleTrack/morepoint', '/singleTrack/morePath', '/vehicle/basicinfo', '/vehicle/dynamicPathinfo'], // 车辆循迹路径信息,当前路径;车辆循迹路径信息,下一段路径;单机循迹预览多路径;单机循迹预览单路径; 车辆动态路权信息
hmi: [
'/vehicle/debuginfo', // 车辆调试信息
'/vehicle/statusinfo', // 车辆状态信息
'/vehicle/errorCode', // 车辆故障码信息
'/vehicle/pairinfo', // 车辆配对信息
'/info/commandInfo', // 车辆提示信息(左下角)
'/info/tipInfo', // 车辆弹框提示信息
'/vehicle/paraminfo', // 车辆全局参数信息
'/command/debugack', //
'/pattern/ack', // 车辆模式切换按钮-发送模式切换回复
'/task/retranTimer', // 车辆任务重传定时器消息
'/setting/singleTrackAck', // 设置单机循迹
'/product',
'/info/popup', // 弹框确认信息
'/setting/basicinfo', // 基本设置数据信息
'/setting/light', // 灯光
'/setting/safe', // 安全
'/setting/controlInfo', // 启动参数
'/setting/ack', // 设置信息结果返回
'/setting/terminal', // 终端对应关系列表
'/setting/terminalAck',
'/setting/ignoreObstaclesAck', // 忽略障碍物回复消息
],
mapHmi: [
'/setting/map', // 地图管理图层
'/setting/mapControlAck', // 地图设置回复
'/setting/roughnessFileAck', // 地图不平整度文件回复
],
login: [
'/login/ack', // 登录信息
'/btn/quitApp', // 退出
'/truckmonitor/start', // 车端登录成功,有连结进来 车端就会发这个消息
'/truckmonitor/exit', // 车端程序退出,不关闭websocket
],
heart: ['heartbeat']
}
const SETTING_TYPE = {
1: '基本信息',
2: '灯光信息',
3: '安全信息',
4: '启动控制信息',
5: '地图管理信息',
6: '单机循迹信息',
// 7: '终端打印信息'
}
export default class Socket {
constructor(root) {
this.ws = new WebSocket(`ws://${document.location.serviceIP}`)
this.stateStore = useStateStore()
this.vehicleStore = useVehicleStore()
this.mapStore = useMapStore()
this.heartTimer = null // 心跳定时器
this.serverTimer = null // 服务器超时定时器
this.sendFixHeartTimer = null // 定时发送心跳
this.timeoutTimer = null // 超时定时器
this.lockReconnect = false // 是否真正建立连接
this.reconnectTimer = null // 重连倒计时
this.isSendSync = false // 是否要重连成功之后,发送同步消息
this.heartCount = 0 // 重连之后,如果没有收到车端登录的消息,需要发送同步消息
this.root = root
}
getConnection() {
const self = this
return new Promise((resolve, reject) => {
self.ws = new WebSocket(`ws://${document.location.serviceIP}`)
self.ws.onopen = function () {
// 开启心跳
self.start()
self.sendFixHeart()
self.resetTimeout()
self.count = 0
resolve(self.ws)
}
self.ws.onerror = function (err) {
console.log(err)
self.isSendSync = true
self.reconnect()
}
self.ws.onclose = function () {
!self.isClosed && self.reconnect()
console.log('closed', new Date())
}
self.ws.onmessage = function (msg) {
self.dealData(msg.data)
// 收到服务器信息,心跳重置
self.reset()
}
})
}
start() {
this.heartTimer && clearTimeout(this.heartTimer)
this.serverTimer && clearTimeout(this.serverTimer)
this.heartTimer = setTimeout(() => {
this.send({
type: 'heartbeat',
msg: 'heart beat'
})
// 超时关闭
this.serverTimer = setTimeout(() => {
this.ws.close()
}, 15000)
}, pingIntervalSec)
}
// 15s定时发送心跳
sendFixHeart() {
this.sendFixHeartTimer && clearInterval(this.sendFixHeartTimer)
this.sendFixHeartTimer = setInterval(() => {
this.send({
type: 'heartbeat',
msg: 'heart beat'
})
}, 15000)
}
resetTimeout() {
const self = this
if (this.timeoutTimer) {
this.timeoutCount = 0
this.stateStore.dealNetworkTip({ type: false })
clearInterval(this.timeoutTimer)
}
this.timeoutTimer = setInterval(() => {
if (this.timeoutCount > NETWORK_COUNT) {
this.stateStore.dealNetworkTip({ type: true, count: this.timeoutCount })
}
this.timeoutCount++
// 超时一定时间,认为车端程序未启动,跳转登录页面
if (self.timeoutCount > TRUCK_MONITOR_EXIT) {
this.dealTruckMointor({
visible: true,
msg: '车端程序未运行',
type: 1
})
router.push({
name: 'login'
})
}
}, 1000)
}
reset() {
this.start()
}
reconnect() {
if (this.lockReconnect) return
const self = this
// this.resetTimeout()
console.log('reconnect-----')
if (this.count > 5) {
Message.error('当前网络不稳定')
this.count = 0
// return
}
this.count++
this.lockReconnect = true
this.reconnectTimer && clearTimeout(this.reconnectTimer)
this.reconnectTimer = setTimeout(() => {
this.getConnection().then(sock => {
self.root.sock = sock
})
this.lockReconnect = false
}, 4000)
}
send(msg) {
msg = JSON.stringify(msg)
console.log(`发送消息${msg}`, new Date())
this.ws && this.ws.send(msg)
}
sendLoginMsg() {
let loginForm = this.stateStore.loginForm || localStorage.getItem(`${location.host}loginForm`)
if (typeof loginForm === 'string') {
loginForm = JSON.parse(loginForm)
}
this.send({
type: '/login/req',
msg: loginForm
})
}
judgeCurrentPath() {
let currentPath = router.currentRoute.value.path
if (currentPath.includes('basic-message')) {
this.sendLoginMsg()
}
}
dealTruckMointor(msg) {
this.stateStore.setTruckMonitor(msg)
}
// 初始化indexDB里的地图图层数据
initMapLayer(layerName, version) {
let db = this.root.indexDB
db.getStoreData(layerName, version).then(res => {
if (res) {
this.mapStore.setData(layerName, res.msg)
} else {
let data = {
type: 'syncMapData',
msg: [layerName]
}
this.send(data)
}
}).catch(error => {
console.warn(error)
})
}
sendVehicleSyncMsg() {
let syncVehicleData = {
type: 'syncVehicleData',
msg: {}
}
this.send(syncVehicleData)
}
async dealMapVersion(msg) {
console.log('msg', msg)
let storeLayers = window.localStorage.getItem('layers')
let syncMapLayers = [], initLayers = []
if (storeLayers) {
let layers = JSON.parse(storeLayers)
for (let i = 0; i < msg.length; i++) {
let item = msg[i]
let { layerName, layerVersion } = item
let oldLayer = layers.find(item => item.layerName === layerName)
if (oldLayer) {
let { layerVersion: oldLayerVersion } = oldLayer
if (oldLayerVersion !== layerVersion) {
syncMapLayers.push(layerName)
} else {
initLayers.push({ layerName, layerVersion })
}
} else {
syncMapLayers.push(layerName)
}
}
} else {
syncMapLayers = msg.map(item => item.layerName)
}
if (syncMapLayers.length) {
await this.root.indexDB.initStore(syncMapLayers)
if (initLayers.length) {
await this.root.indexDB.compareTable(initLayers)
initLayers.forEach(({ layerName, layerVersion }) => {
this.initMapLayer(layerName, layerVersion)
})
}
let data = {
type: 'syncMapData',
msg: syncMapLayers
}
this.send(data)
} else {
if (initLayers.length) {
await this.root.indexDB.compareTable(initLayers)
initLayers.forEach(({ layerName, layerVersion }) => {
this.initMapLayer(layerName, layerVersion)
})
}
this.sendVehicleSyncMsg()
}
localStorage.setItem('layers', JSON.stringify(msg))
}
dealheartData() {
if (this.isSendSync && this.heartCount > 2) {
// 没有收到车端退出的消息时,收到3次心跳,就发送同步消息
if (this.heartCount > 2) {
this.judgeCurrentPath()
this.isSendSync = false
this.heartCount = 0
} else {
this.heartCount++
}
}
}
dealmapData(result, key) {
const self = this
const { type, msg, version } = result
let worker = this.root.worker.worker[key]
switch (type) {
case 'mapVersionAck':
this.dealMapVersion(msg)
break
default:
let strData = window.atob(msg);
worker.postMessage({ type, msg: strData, version })
break
}
worker.onmessage = ({ data }) => {
const { mapName, result, mapVersion } = data
self.mapStore.setData(mapName, result)
self.root.indexDB.storeData(mapName, result, mapVersion)
self.sendVehicleSyncMsg()
}
}
dealpathData(result, key) {
const { type, msg } = result
let [, , name] = type.split('/')
const worker = this.root.worker.worker[key]
switch (type) {
case '/vehicle/basicinfo':
const { avoidancePath, obstacle } = msg
avoidancePath && worker.postMessage({ name: 'avoidancePath', msg: avoidancePath })
obstacle && worker.postMessage({ name: 'obstacle', msg: obstacle })
this.vehicleStore.setBasicInfo(msg)
break
case '/vehicle/nextPathinfo':
let { available, path } = msg
this.mapStore.setData('nextPathAvailable', available)
path && worker.postMessage({ name, msg: path })
break
default:
msg && worker.postMessage({ name, msg })
break
}
worker.onmessage = ({ data }) => {
const { name, dealedData } = data
this.mapStore.setData(name === 'obstacle' ? 'obstacleData' : name, dealedData)
}
}
dealvehicleData(result, key) {
const { type, msg } = result
const vehicleStoreToRefs = storeToRefs(this.vehicleStore)
const { paraminfo, positioninfo } = vehicleStoreToRefs
const { deviceId } = paraminfo.value
const worker = this.root.worker.worker[key]
const prePositionInfo = JSON.parse(JSON.stringify(positioninfo.value))
worker.postMessage({ type, msg, deviceId, pre: prePositionInfo })
const diffWorker = this.root.worker.worker['vehicleDiff']
diffWorker.postMessage({ pre: prePositionInfo, cur: msg })
worker.onmessage = ({ data }) => {
const { vehicles, safeObj, trajObj, gps, currentBasic } = data
this.stateStore.setData('gps', gps)
currentBasic && this.vehicleStore.setData('currentBasic', currentBasic)
this.vehicleStore.$patch({
vehiclesPositioninfo: vehicles,
safeObj: safeObj,
trajObj: trajObj
})
}
diffWorker.onmessage = ({ data }) => {
this.vehicleStore.setData('deleteVehicles', data)
}
this.vehicleStore.setData('positioninfo', msg)
}
handleSettingAck(msg) {
let { type, code } = msg
if (!SETTING_TYPE[type]) return
let ackType = code === 0 ? 'success' : 'error'
let text = SETTING_TYPE[type];
if (type == 4) {
text = '指令'
}
Message[ackType](`${text}设置${code === 0 ? '成功' : '失败'}`)
if (type == 6 && code === 0) {
let data = {
type: '/setting/req',
msg: {
type: 6
}
}
this.send(data)
}
}
dealObstaclesAck(msg) {
let { code } = msg
let type = code === 0 ? 'success' : 'error'
let tip = code === 0 ? '成功' : '失败'
Message[type](`发送车端${tip}`)
}
dealhmiData(result) {
const { type, msg } = result
let [, , name] = type.split('/')
// console.log(name, msg)
switch (type) {
// 车辆状态信息
case '/vehicle/statusinfo':
const { pattern, connStatus } = msg
this.stateStore.setData('wifi', connStatus)
this.vehicleStore.setData('pattern', pattern)
this.vehicleStore.setData(name, msg)
break
// 车辆故障码信息
case '/vehicle/errorCode':
this.vehicleStore.dealErrorCode(msg)
break
// 车辆模式切换按钮-发送模式切换回复
case '/pattern/ack':
this.vehicleStore.setData('patternAck', msg)
break
// 弹框确认信息
case '/info/popup':
this.vehicleStore.dealInfoPop(msg)
break
// 设置信息结果返回
case '/setting/ack':
this.handleSettingAck(msg)
break
case '/setting/terminalAck':
this.vehicleStore.dealTerminalAck(msg)
break
case '/setting/ignoreObstaclesAck':
this.dealObstaclesAck(msg)
break
default:
this.vehicleStore.setData(name, msg)
break
}
}
dealmapHmiData(result) {
const { type, msg } = result
let [, , name] = type.split('/')
switch (type) {
// 地图不平整度文件回复
case '/setting/roughnessFileAck':
const { type, fileName } = msg
if (type === 1) {
this.mapStore.setData(name, fileName)
}
break
default:
this.mapStore.setData(name, msg)
break
}
}
startTime() {
const self = this
const worker = this.root.worker.worker.time
worker.postMessage('start')
worker.onmessage = ({ data }) => {
self.stateStore.setData('currentTime', data)
}
}
postParentMessage(data) {
if (data) {
let loginInfo = data
if (window.top && loginInfo && data.code === 0) {
window.top.postMessage({
type: 'token',
data: {
ip: window.location.host,
loginInfo,
}
}, '*')
}
try {
localStorage.setItem(window.location.host, JSON.stringify(loginInfo))
} catch (error) {
this.isTraceless = true
console.log(error)
Message.error('请退出无痕模式!')
}
}
}
dealloginData(result) {
const { type, msg } = result
switch (type) {
// 车端登录成功,有连结进来 车端就会发这个消息
case '/truckmonitor/start':
// 收到车端登录成功的消息,则不需要判断收到心跳的次数
// 需要判断是否再登录页面,如果再登录页面,不需要处理,如果不在登录页面,则需要发送同步信息
this.isSendSync = false
this.judgeCurrentPath()
this.dealTruckMointor({
visible: false,
type: 1
})
break
case '/truckmonitor/exit':
router.push({
name: 'login'
})
this.dealTruckMointor({
visible: true,
msg: '车端程序未运行',
type: 1
})
this.stateStore.setData('loginAck', msg)
break
// 登录
case '/login/ack':
console.log('收到登录信息', new Date())
this.stateStore.setData('loginAck', msg)
this.postParentMessage(msg)
// this.startTime()
break
// 退出
case '/btn/quitApp':
if (window.state === 'logout') {
window.state = null
localStorage.removeItem(window.location.host)
this.close()
router.push({
name: 'login'
})
}
}
}
async dealData(data) {
this.resetTimeout()
let result = await (new Response(data)).text()
if (typeof result === 'string' && result !== 'heart beat') {
try {
result = JSON.parse(result)
} catch (err) {
console.log('err----', result)
}
}
const { type, msg } = result
// console.log(`接收消息${type}`, new Date().format('yyyy-MM-dd hh:mm:ss'))
if (!type) return
// console.log(type)
let keys = Object.keys(TOPIC_CLASS)
for (let i = 0; i < keys.length; i++) {
let key = keys[i]
if (TOPIC_CLASS[key].includes(type)) {
this[`deal${key}Data`](result, key)
break
}
}
}
close() {
this.isClosed = true
this.heartTimer && clearTimeout(this.heartTimer)
this.serverTimer && clearTimeout(this.serverTimer)
this.reconnectTimer && clearTimeout(this.reconnectTimer)
this.sendFixHeartTimer && clearInterval(this.sendFixHeartTimer)
this.timeoutTimer && clearInterval(this.timeoutTimer)
this.heartTimer = null
this.serverTimer = null
this.reconnectTimer = null
this.sendFixHeartTimer = null
this.ws.close()
this.root.sock = null
this.root.worker = null
this.root.indexDB = null
}
}
\ No newline at end of file
import { useStateStore } from '@/store/StateStore'
import { useVehicleStore } from '@/store/VehicleStore.js'
import { useMapStore } from '@/store/MapStore.js'
import writeLog from '@/js/writeLog.js'
import router from '../../router'
import { storeToRefs } from 'pinia'
import { Message } from 'view-ui-plus'
const pingIntervalSec = 5000 // 心跳链接时间
const NETWORK_COUNT = 3
const TRUCK_MONITOR_EXIT = 15 * 60
const TOPIC_CLASS = {
vehicle: ['/vehicle/positioninfo'],
map: ['/map/obstacles', '/map/lanenode', '/map/lane', '/map/runablearea', '/map/centerline', '/map/diggingworkarea', '/map/dumparea', '/map/barricade', '/map/stationarea', '/map/parkspot', '/map/staticobjs', '/map/electronicFence', 'mapVersionAck'],
path: ['/vehicle/currPathinfo', '/vehicle/nextPathinfo', '/singleTrack/morepoint', '/singleTrack/morePath', '/vehicle/basicinfo', '/vehicle/dynamicPathinfo'], // 车辆循迹路径信息,当前路径;车辆循迹路径信息,下一段路径;单机循迹预览多路径;单机循迹预览单路径; 车辆动态路权信息
hmi: [
'/vehicle/debuginfo', // 车辆调试信息
'/vehicle/statusinfo', // 车辆状态信息
'/vehicle/errorCode', // 车辆故障码信息
'/vehicle/pairinfo', // 车辆配对信息
'/info/commandInfo', // 车辆提示信息(左下角)
'/info/tipInfo', // 车辆弹框提示信息
'/vehicle/paraminfo', // 车辆全局参数信息
'/command/debugack', //
'/pattern/ack', // 车辆模式切换按钮-发送模式切换回复
'/task/retranTimer', // 车辆任务重传定时器消息
'/setting/singleTrackAck', // 设置单机循迹
'/product',
'/info/popup', // 弹框确认信息
'/setting/basicinfo', // 基本设置数据信息
'/setting/light', // 灯光
'/setting/safe', // 安全
'/setting/controlInfo', // 启动参数
'/setting/ack', // 设置信息结果返回
'/setting/terminal', // 终端对应关系列表
'/setting/terminalAck',
'/setting/ignoreObstaclesAck', // 忽略障碍物回复消息
],
mapHmi: [
'/setting/map', // 地图管理图层
'/setting/mapControlAck', // 地图设置回复
'/setting/roughnessFileAck', // 地图不平整度文件回复
],
login: [
'/login/ack', // 登录信息
'/btn/quitApp', // 退出
'/truckmonitor/start', // 车端登录成功,有连结进来 车端就会发这个消息
'/truckmonitor/exit', // 车端程序退出,不关闭websocket
],
heart: ['heartbeat']
}
const SETTING_TYPE = {
1: '基本信息',
2: '灯光信息',
3: '安全信息',
4: '启动控制信息',
5: '地图管理信息',
6: '单机循迹信息',
// 7: '终端打印信息'
}
export default class Socket {
constructor(root) {
this.ws = new WebSocket(`ws://${document.location.serviceIP}`)
this.stateStore = useStateStore()
this.vehicleStore = useVehicleStore()
this.mapStore = useMapStore()
this.heartTimer = null // 心跳定时器
this.serverTimer = null // 服务器超时定时器
this.sendFixHeartTimer = null // 定时发送心跳
this.timeoutTimer = null // 超时定时器
this.lockReconnect = false // 是否真正建立连接
this.reconnectTimer = null // 重连倒计时
this.isSendSync = false // 是否要重连成功之后,发送同步消息
this.heartCount = 0 // 重连之后,如果没有收到车端登录的消息,需要发送同步消息
this.root = root
}
getConnection() {
const self = this
return new Promise((resolve, reject) => {
self.ws = new WebSocket(`ws://${document.location.serviceIP}`)
self.ws.onopen = function () {
// 开启心跳
self.start()
self.sendFixHeart()
self.resetTimeout()
self.count = 0
resolve(self.ws)
}
self.ws.onerror = function (err) {
console.log(err)
self.isSendSync = true
self.reconnect()
}
self.ws.onclose = function () {
!self.isClosed && self.reconnect()
console.log('closed', new Date())
}
self.ws.onmessage = function (msg) {
self.dealData(msg.data)
// 收到服务器信息,心跳重置
self.reset()
}
})
}
start() {
this.heartTimer && clearTimeout(this.heartTimer)
this.serverTimer && clearTimeout(this.serverTimer)
this.heartTimer = setTimeout(() => {
this.send({
type: 'heartbeat',
msg: 'heart beat'
})
// 超时关闭
this.serverTimer = setTimeout(() => {
this.ws.close()
}, 15000)
}, pingIntervalSec)
}
// 15s定时发送心跳
sendFixHeart() {
this.sendFixHeartTimer && clearInterval(this.sendFixHeartTimer)
this.sendFixHeartTimer = setInterval(() => {
this.send({
type: 'heartbeat',
msg: 'heart beat'
})
}, 15000)
}
resetTimeout() {
const self = this
if (this.timeoutTimer) {
this.timeoutCount = 0
this.stateStore.dealNetworkTip({ type: false })
clearInterval(this.timeoutTimer)
}
this.timeoutTimer = setInterval(() => {
if (this.timeoutCount > NETWORK_COUNT) {
writeLog('WARNING',`网络异常,请检测网络!连接超时${this.timeoutCount}s`)
this.stateStore.dealNetworkTip({ type: true, count: this.timeoutCount })
}
this.timeoutCount++
// 超时一定时间,认为车端程序未启动,跳转登录页面
if (self.timeoutCount > TRUCK_MONITOR_EXIT) {
this.dealTruckMointor({
visible: true,
msg: '车端程序未运行',
type: 1
})
router.push({
name: 'login'
})
}
}, 1000)
}
reset() {
this.start()
}
reconnect() {
if (this.lockReconnect) return
const self = this
// this.resetTimeout()
console.log('reconnect-----')
if (this.count > 5) {
Message.error('当前网络不稳定')
this.count = 0
// return
}
this.count++
this.lockReconnect = true
this.reconnectTimer && clearTimeout(this.reconnectTimer)
this.reconnectTimer = setTimeout(() => {
this.getConnection().then(sock => {
self.root.sock = sock
})
this.lockReconnect = false
}, 4000)
}
send(msg) {
msg = JSON.stringify(msg)
console.log(`发送消息${msg}`, new Date())
this.ws && this.ws.send(msg)
}
sendLoginMsg() {
let loginForm = this.stateStore.loginForm || localStorage.getItem(`${location.host}loginForm`)
if (typeof loginForm === 'string') {
loginForm = JSON.parse(loginForm)
}
this.send({
type: '/login/req',
msg: loginForm
})
}
judgeCurrentPath() {
let currentPath = router.currentRoute.value.path
if (currentPath.includes('basic-message')) {
this.sendLoginMsg()
}
}
dealTruckMointor(msg) {
this.stateStore.setTruckMonitor(msg)
}
// 初始化indexDB里的地图图层数据
initMapLayer(layerName, version) {
let db = this.root.indexDB
db.getStoreData(layerName, version).then(res => {
if (res) {
this.mapStore.setData(layerName, res.msg)
} else {
let data = {
type: 'syncMapData',
msg: [layerName]
}
this.send(data)
}
}).catch(error => {
console.warn(error)
})
}
sendVehicleSyncMsg() {
let syncVehicleData = {
type: 'syncVehicleData',
msg: {}
}
this.send(syncVehicleData)
}
async dealMapVersion(msg) {
console.log('msg', msg)
let storeLayers = window.localStorage.getItem('layers')
let syncMapLayers = [], initLayers = []
if (storeLayers) {
let layers = JSON.parse(storeLayers)
for (let i = 0; i < msg.length; i++) {
let item = msg[i]
let { layerName, layerVersion } = item
let oldLayer = layers.find(item => item.layerName === layerName)
if (oldLayer) {
let { layerVersion: oldLayerVersion } = oldLayer
if (oldLayerVersion !== layerVersion) {
syncMapLayers.push(layerName)
} else {
initLayers.push({ layerName, layerVersion })
}
} else {
syncMapLayers.push(layerName)
}
}
} else {
syncMapLayers = msg.map(item => item.layerName)
}
if (syncMapLayers.length) {
await this.root.indexDB.initStore(syncMapLayers)
if (initLayers.length) {
await this.root.indexDB.compareTable(initLayers)
initLayers.forEach(({ layerName, layerVersion }) => {
this.initMapLayer(layerName, layerVersion)
})
}
let data = {
type: 'syncMapData',
msg: syncMapLayers
}
this.send(data)
} else {
if (initLayers.length) {
await this.root.indexDB.compareTable(initLayers)
initLayers.forEach(({ layerName, layerVersion }) => {
this.initMapLayer(layerName, layerVersion)
})
}
this.sendVehicleSyncMsg()
}
localStorage.setItem('layers', JSON.stringify(msg))
}
dealheartData() {
if (this.isSendSync && this.heartCount > 2) {
// 没有收到车端退出的消息时,收到3次心跳,就发送同步消息
if (this.heartCount > 2) {
this.judgeCurrentPath()
this.isSendSync = false
this.heartCount = 0
} else {
this.heartCount++
}
}
}
dealmapData(result, key) {
const self = this
const { type, msg, version } = result
let worker = this.root.worker.worker[key]
switch (type) {
case 'mapVersionAck':
this.dealMapVersion(msg)
break
default:
let strData = window.atob(msg);
worker.postMessage({ type, msg: strData, version })
break
}
worker.onmessage = ({ data }) => {
const { mapName, result, mapVersion } = data
self.mapStore.setData(mapName, result)
self.root.indexDB.storeData(mapName, result, mapVersion)
self.sendVehicleSyncMsg()
}
}
dealpathData(result, key) {
const { type, msg } = result
let [, , name] = type.split('/')
const worker = this.root.worker.worker[key]
switch (type) {
case '/vehicle/basicinfo':
const { avoidancePath, obstacle } = msg
avoidancePath && worker.postMessage({ name: 'avoidancePath', msg: avoidancePath })
obstacle && worker.postMessage({ name: 'obstacle', msg: obstacle })
this.vehicleStore.setBasicInfo(msg)
break
case '/vehicle/nextPathinfo':
let { available, path } = msg
this.mapStore.setData('nextPathAvailable', available)
path && worker.postMessage({ name, msg: path })
break
default:
msg && worker.postMessage({ name, msg })
break
}
worker.onmessage = ({ data }) => {
const { name, dealedData } = data
this.mapStore.setData(name === 'obstacle' ? 'obstacleData' : name, dealedData)
}
}
dealvehicleData(result, key) {
const { type, msg } = result
const vehicleStoreToRefs = storeToRefs(this.vehicleStore)
const { paraminfo, positioninfo } = vehicleStoreToRefs
const { deviceId } = paraminfo.value
const worker = this.root.worker.worker[key]
const prePositionInfo = JSON.parse(JSON.stringify(positioninfo.value))
worker.postMessage({ type, msg, deviceId, pre: prePositionInfo })
const diffWorker = this.root.worker.worker['vehicleDiff']
diffWorker.postMessage({ pre: prePositionInfo, cur: msg })
worker.onmessage = ({ data }) => {
const { vehicles, safeObj, trajObj, gps, currentBasic } = data
this.stateStore.setData('gps', gps)
currentBasic && this.vehicleStore.setData('currentBasic', currentBasic)
this.vehicleStore.$patch({
vehiclesPositioninfo: vehicles,
safeObj: safeObj,
trajObj: trajObj
})
}
diffWorker.onmessage = ({ data }) => {
this.vehicleStore.setData('deleteVehicles', data)
}
this.vehicleStore.setData('positioninfo', msg)
}
handleSettingAck(msg) {
let { type, code } = msg
if (!SETTING_TYPE[type]) return
let ackType = code === 0 ? 'success' : 'error'
let text = SETTING_TYPE[type];
if (type == 4) {
text = '指令'
}
Message[ackType](`${text}设置${code === 0 ? '成功' : '失败'}`)
if (type == 6 && code === 0) {
let data = {
type: '/setting/req',
msg: {
type: 6
}
}
this.send(data)
}
}
dealObstaclesAck(msg) {
let { code } = msg
let type = code === 0 ? 'success' : 'error'
let tip = code === 0 ? '成功' : '失败'
Message[type](`发送车端${tip}`)
}
dealhmiData(result) {
const { type, msg } = result
let [, , name] = type.split('/')
// console.log(name, msg)
switch (type) {
// 车辆状态信息
case '/vehicle/statusinfo':
const { pattern, connStatus } = msg
this.stateStore.setData('wifi', connStatus)
this.vehicleStore.setData('pattern', pattern)
this.vehicleStore.setData(name, msg)
break
// 车辆故障码信息
case '/vehicle/errorCode':
this.vehicleStore.dealErrorCode(msg)
break
// 车辆模式切换按钮-发送模式切换回复
case '/pattern/ack':
this.vehicleStore.setData('patternAck', msg)
break
// 弹框确认信息
case '/info/popup':
this.vehicleStore.dealInfoPop(msg)
break
// 设置信息结果返回
case '/setting/ack':
this.handleSettingAck(msg)
break
case '/setting/terminalAck':
this.vehicleStore.dealTerminalAck(msg)
break
case '/setting/ignoreObstaclesAck':
this.dealObstaclesAck(msg)
break
default:
this.vehicleStore.setData(name, msg)
break
}
}
dealmapHmiData(result) {
const { type, msg } = result
let [, , name] = type.split('/')
switch (type) {
// 地图不平整度文件回复
case '/setting/roughnessFileAck':
const { type, fileName } = msg
if (type === 1) {
this.mapStore.setData(name, fileName)
}
break
default:
this.mapStore.setData(name, msg)
break
}
}
startTime() {
const self = this
const worker = this.root.worker.worker.time
worker.postMessage('start')
worker.onmessage = ({ data }) => {
self.stateStore.setData('currentTime', data)
}
}
postParentMessage(data) {
if (data) {
let loginInfo = data
if (window.top && loginInfo && data.code === 0) {
window.top.postMessage({
type: 'token',
data: {
ip: window.location.host,
loginInfo,
}
}, '*')
}
try {
localStorage.setItem(window.location.host, JSON.stringify(loginInfo))
} catch (error) {
this.isTraceless = true
console.log(error)
Message.error('请退出无痕模式!')
}
}
}
dealloginData(result) {
const { type, msg } = result
switch (type) {
// 车端登录成功,有连结进来 车端就会发这个消息
case '/truckmonitor/start':
// 收到车端登录成功的消息,则不需要判断收到心跳的次数
// 需要判断是否再登录页面,如果再登录页面,不需要处理,如果不在登录页面,则需要发送同步信息
this.isSendSync = false
this.judgeCurrentPath()
this.dealTruckMointor({
visible: false,
type: 1
})
break
case '/truckmonitor/exit':
router.push({
name: 'login'
})
this.dealTruckMointor({
visible: true,
msg: '车端程序未运行',
type: 1
})
this.stateStore.setData('loginAck', msg)
break
// 登录
case '/login/ack':
console.log('收到登录信息', new Date())
this.stateStore.setData('loginAck', msg)
this.postParentMessage(msg)
// this.startTime()
break
// 退出
case '/btn/quitApp':
if (window.state === 'logout') {
window.state = null
localStorage.removeItem(window.location.host)
this.close()
router.push({
name: 'login'
})
}
}
}
async dealData(data) {
this.resetTimeout()
let result = await (new Response(data)).text()
if (typeof result === 'string' && result !== 'heart beat') {
try {
result = JSON.parse(result)
} catch (err) {
console.log('err----', result)
}
}
const { type, msg } = result
// console.log(`接收消息${type}`, new Date().format('yyyy-MM-dd hh:mm:ss'))
if (!type) return
// console.log(type)
let keys = Object.keys(TOPIC_CLASS)
for (let i = 0; i < keys.length; i++) {
let key = keys[i]
if (TOPIC_CLASS[key].includes(type)) {
this[`deal${key}Data`](result, key)
break
}
}
}
close() {
this.isClosed = true
this.heartTimer && clearTimeout(this.heartTimer)
this.serverTimer && clearTimeout(this.serverTimer)
this.reconnectTimer && clearTimeout(this.reconnectTimer)
this.sendFixHeartTimer && clearInterval(this.sendFixHeartTimer)
this.timeoutTimer && clearInterval(this.timeoutTimer)
this.heartTimer = null
this.serverTimer = null
this.reconnectTimer = null
this.sendFixHeartTimer = null
this.ws.close()
this.root.sock = null
this.root.worker = null
this.root.indexDB = null
}
}
\ No newline at end of file
import axios from 'axios';
let loginForm=JSON.parse(window.localStorage.getItem(`${location.host}loginForm`))
const writeLog=(type,data)=>{
let log=type+' '+new Date().format('yyyy-MM-dd hh:mm:ss')+' '+loginForm.number+' '+location.host+' '+data
axios.post("//"+document.location.logServe+"/ht/api/web/log/upload",{log:log}).then(res=>{
if(res.code!=0){
console.log('writeLog',res.msg)
}
}).catch(err=>{
console.log('writeLog',err)
})
}
export default writeLog
\ No newline at end of file
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import IndexRoot from './js/IndexRoot.js'
import ViewUIPlus from 'view-ui-plus'
import 'leaflet/dist/leaflet.css'
import 'view-ui-plus/dist/styles/viewuiplus.css'
import './assets/main.css'
window.state = null
/**
* usage:
* let x = new Date()
* x.format('yyyy-MM-dd hh:mm:ss')
*
* @method format
*
* @param {[type]} format [description]
*
* @return {[type]} [description]
*/
Date.prototype.format = function (format) { // eslint-disable-line
let o = {
'M+': this.getMonth() + 1, // month
'd+': this.getDate(), // day
'h+': this.getHours(), // hour
'm+': this.getMinutes(), // minute
's+': this.getSeconds(), // second
'q+': Math.floor((this.getMonth() + 3) / 3), // quarter
'S': this.getMilliseconds() // millisecond
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (let k in o) {
if (new RegExp('(' + k + ')').test(format)) {
format = format.replace(RegExp.$1,
RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
}
}
return format
}
const pinia = createPinia()
const app = createApp(App)
let $indexRoot = new IndexRoot()
app.config.globalProperties.$indexRoot = $indexRoot
app.use(router)
.use(ViewUIPlus)
.use(pinia)
function getSysConfig() {
return new Promise((resolve, reject) => {
axios.get('/config.json').then((result) => {
let config = result.data
resolve(config)
}).catch((error) => {
console.log(error)
reject()
})
})
}
async function init() {
const {SERVICE_IP, MAP_CENTER} = await getSysConfig()
document.location.serviceIP = SERVICE_IP
document.location.mapCenter = MAP_CENTER
}
init().then(() => app.mount('#app'))
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import IndexRoot from './js/IndexRoot.js'
import writeLog from './js/writeLog.js'
import ViewUIPlus from 'view-ui-plus'
import 'leaflet/dist/leaflet.css'
import 'view-ui-plus/dist/styles/viewuiplus.css'
import './assets/main.css'
window.state = null
/**
* usage:
* let x = new Date()
* x.format('yyyy-MM-dd hh:mm:ss')
*
* @method format
*
* @param {[type]} format [description]
*
* @return {[type]} [description]
*/
Date.prototype.format = function (format) { // eslint-disable-line
let o = {
'M+': this.getMonth() + 1, // month
'd+': this.getDate(), // day
'h+': this.getHours(), // hour
'm+': this.getMinutes(), // minute
's+': this.getSeconds(), // second
'q+': Math.floor((this.getMonth() + 3) / 3), // quarter
'S': this.getMilliseconds() // millisecond
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (let k in o) {
if (new RegExp('(' + k + ')').test(format)) {
format = format.replace(RegExp.$1,
RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
}
}
return format
}
const pinia = createPinia()
const app = createApp(App)
let $indexRoot = new IndexRoot()
app.config.globalProperties.$indexRoot = $indexRoot
window.onerror=(message, source, lineno, colno, error)=>{
var data = {
message: message,
source: source,
lineno: lineno,
colno: colno,
error: error
};
writeLog('ERROR', JSON.stringify(data))
}
app.use(router)
.use(ViewUIPlus)
.use(pinia)
function getSysConfig() {
return new Promise((resolve, reject) => {
axios.get('/config.json').then((result) => {
let config = result.data
resolve(config)
}).catch((error) => {
console.log(error)
reject()
})
})
}
async function init() {
const {SERVICE_IP, MAP_CENTER} = await getSysConfig()
document.location.serviceIP = SERVICE_IP
document.location.mapCenter = MAP_CENTER
}
init().then(() => app.mount('#app'))
<template>
<div class="login">
<p v-show="isShow" class="tips">
{{ tip }}
</p>
<div class="loadingContainer" v-show="isShowLoading">
<Spin fix>
<Icon type="ios-loading" size="30" class="spin-icon-load" style="color: #dec02b"></Icon>
<span class="loading-tip">正在登录,请稍后...</span>
</Spin>
</div>
<img class="logo" src="/image/logo.png" alt="" />
<Form>
<FormItem prop="number">
<Input type="text" v-model.trim="formItem.number" placeholder="请输入用户名">
<Icon type="ios-person-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem prop="name">
<Input type="password" v-model.trim="formItem.password" placeholder="请输入密码">
<Icon type="ios-lock-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem>
<Button long type="primary" @click="handleSubmit">登录</Button>
</FormItem>
</Form>
</div>
</template>
<script setup>
import { reactive, ref, watch, getCurrentInstance } from 'vue';
import { storeToRefs } from 'pinia'
import { Message } from 'view-ui-plus';
import { useStateStore } from '@/store/StateStore.js'
import router from '@/router'
const isShow = ref(false)
const tip = ref('')
const isShowLoading = ref(false)
const truckMonitorStatus = ref(false)
const rootBus = ref(null)
const stateStore = useStateStore()
const stateStoreToRefs = storeToRefs(stateStore)
const { getLoginAck, truckMonitorMsg, isShowNetworkTip } = stateStoreToRefs
const instance = getCurrentInstance()
const { appContext } = instance
const { $indexRoot } = appContext.config.globalProperties
const formItem = reactive({
number: '',
password: ''
})
function handleSubmit() {
if (isShowLoading.value) return
if (truckMonitorStatus.value) return Message.error('车端未启动,无法登录!')
if (!formItem.number || !formItem.password) return Message.error('请将用户名和密码填写完整!')
window.state = "login";
let loginForm = JSON.stringify({
type: "/login/req",
msg: {
number: formItem.number,
password: formItem.password
}
})
if ($indexRoot.sock) {
$indexRoot.sock.send(loginForm)
} else {
$indexRoot.init().then(socket => {
socket.send(loginForm)
})
}
}
watch(getLoginAck, (value) => {
if (value && window.state === 'login') {
let {code, number} = value
if (code === 0 && number === formItem.number) {
router.push({
name: 'main'
})
window.state = null
stateStore.setLoginForm(formItem)
} else {
Message.error(value.msg)
stateStore.setData('loginAck', null)
}
}
})
watch([truckMonitorMsg, isShowNetworkTip], ([data, isNetworkTip]) => {
if (data) {
let { visible, msg } = data
truckMonitorStatus.value = visible
isShow.value = visible
tip.value = msg
isShowLoading.value = false
}
if (isNetworkTip) {
isShow.value = isNetworkTip.value
}
}, {deep: true, immediate: true})
</script>
<style lang="less" scoped>
.login {
width: 100%;
height: 100%;
background: url("/image/background.png") no-repeat;
background-size: cover;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
.logo {
margin-bottom: 20px;
width: 25vw;
height: auto;
}
.tips {
color: #ff6363;
animation: roll 5s infinite;
position: absolute;
top: 2vh;
}
@keyframes roll {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-200px);
}
}
.loadingContainer {
display: block;
position: absolute;
width: 200px;
top: 15vh;
background: rgba(0, 0, 0, 0);
}
.loadingContainer .ivu-spin-fix {
background: rgba(0, 0, 0, 0) !important;
}
.loading-tip {
white-space: nowrap;
color: #fff;
}
}
</style>
\ No newline at end of file
<template>
<div class="login">
<p v-show="isShow" class="tips">
{{ tip }}
</p>
<div class="loadingContainer" v-show="isShowLoading">
<Spin fix>
<Icon type="ios-loading" size="30" class="spin-icon-load" style="color: #dec02b"></Icon>
<span class="loading-tip">正在登录,请稍后...</span>
</Spin>
</div>
<img class="logo" src="/image/logo.png" alt="" />
<Form>
<FormItem prop="number">
<Input type="text" v-model.trim="formItem.number" placeholder="请输入用户名">
<Icon type="ios-person-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem prop="name">
<Input type="password" v-model.trim="formItem.password" placeholder="请输入密码">
<Icon type="ios-lock-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem>
<Button long type="primary" @click="handleSubmit">登录</Button>
</FormItem>
</Form>
</div>
</template>
<script setup>
import { reactive, ref, watch, getCurrentInstance } from 'vue';
import { storeToRefs } from 'pinia'
import { Message } from 'view-ui-plus';
import { useStateStore } from '@/store/StateStore.js'
import router from '@/router'
import writeLog from '@/js/writeLog.js'
const isShow = ref(false)
const tip = ref('')
const isShowLoading = ref(false)
const truckMonitorStatus = ref(false)
const rootBus = ref(null)
const stateStore = useStateStore()
const stateStoreToRefs = storeToRefs(stateStore)
const { getLoginAck, truckMonitorMsg, isShowNetworkTip } = stateStoreToRefs
const instance = getCurrentInstance()
const { appContext } = instance
const { $indexRoot } = appContext.config.globalProperties
const formItem = reactive({
number: '',
password: ''
})
function handleSubmit() {
if (isShowLoading.value) return
if (truckMonitorStatus.value) return Message.error('车端未启动,无法登录!')
if (!formItem.number || !formItem.password) return Message.error('请将用户名和密码填写完整!')
window.state = "login";
let loginForm = JSON.stringify({
type: "/login/req",
msg: {
number: formItem.number,
password: formItem.password
}
})
if ($indexRoot.sock) {
$indexRoot.sock.send(loginForm)
} else {
$indexRoot.init().then(socket => {
socket.send(loginForm)
})
}
}
watch(getLoginAck, (value) => {
if (value && window.state === 'login') {
writeLog('INFO',"登陆成功")
let {code, number} = value
if (code === 0 && number === formItem.number) {
router.push({
name: 'main'
})
window.state = null
stateStore.setLoginForm(formItem)
} else {
Message.error(value.msg)
stateStore.setData('loginAck', null)
}
}
})
watch([truckMonitorMsg, isShowNetworkTip], ([data, isNetworkTip]) => {
if (data) {
let { visible, msg } = data
truckMonitorStatus.value = visible
isShow.value = visible
tip.value = msg
isShowLoading.value = false
}
if (isNetworkTip) {
isShow.value = isNetworkTip.value
}
}, {deep: true, immediate: true})
</script>
<style lang="less" scoped>
.login {
width: 100%;
height: 100%;
background: url("/image/background.png") no-repeat;
background-size: cover;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
.logo {
margin-bottom: 20px;
width: 25vw;
height: auto;
}
.tips {
color: #ff6363;
animation: roll 5s infinite;
position: absolute;
top: 2vh;
}
@keyframes roll {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-200px);
}
}
.loadingContainer {
display: block;
position: absolute;
width: 200px;
top: 15vh;
background: rgba(0, 0, 0, 0);
}
.loadingContainer .ivu-spin-fix {
background: rgba(0, 0, 0, 0) !important;
}
.loading-tip {
white-space: nowrap;
color: #fff;
}
}
</style>
\ No newline at end of file
<template>
<div class="log-out">
<p>{{ tipsLogout }}</p>
<div class="footer">
<Button type="info" class="btn" @click="doSureLogout">确定</Button>
<Button type="error" @click="doCancelLogout">取消</Button>
</div>
</div>
</template>
<script setup>
import { ref, watch } from 'vue'
import { useVehicleStore } from '../store/VehicleStore';
import { useStateStore } from '../store/StateStore';
import { storeToRefs } from 'pinia';
const props = defineProps({
isShow: Boolean
})
const tipsLogout = ref('退出当前系统')
const logoutStep = ref(0)
const vehicleStore = useVehicleStore()
const vehicleStoreToRefs = storeToRefs(vehicleStore)
const { pattern } = vehicleStoreToRefs
const stateStore = useStateStore()
const emits = defineEmits(['handleSend', 'closeModal'])
function doCancelLogout() {
logoutStep.value = 0
emits('closeModal')
}
function closeSystem() {
logoutStep.value = 0
window.state = 'logout'
emits('handleSend', {
type: '/btn/quitApp',
msg: {}
})
stateStore.setData('loginAck', null)
}
function doSureLogout() {
if (pattern.value === 1 && logoutStep.value === 0) {
tipsLogout.value = '当前是无人模式,确定退出程序'
logoutStep.value = 1
} else {
closeSystem()
}
}
watch(() => props.isShow, (value) => {
if (value) {
tipsLogout.value = '退出当前系统'
}
}, {
immediate: true
})
</script>
<style lang="less" scoped>
.log-out {
&>p {
margin-bottom: 20px;
}
.footer {
text-align: end;
.btn {
margin-right: 10px;
}
}
}
</style>
\ No newline at end of file
<template>
<div class="log-out">
<p>{{ tipsLogout }}</p>
<div class="footer">
<Button type="info" class="btn" @click="doSureLogout">确定</Button>
<Button type="error" @click="doCancelLogout">取消</Button>
</div>
</div>
</template>
<script setup>
import { ref, watch } from 'vue'
import { useVehicleStore } from '../store/VehicleStore';
import { useStateStore } from '../store/StateStore';
import { storeToRefs } from 'pinia';
import writeLog from '../js/writeLog.js'
const props = defineProps({
isShow: Boolean
})
const tipsLogout = ref('退出当前系统')
const logoutStep = ref(0)
const vehicleStore = useVehicleStore()
const vehicleStoreToRefs = storeToRefs(vehicleStore)
const { pattern } = vehicleStoreToRefs
const stateStore = useStateStore()
const emits = defineEmits(['handleSend', 'closeModal'])
function doCancelLogout() {
logoutStep.value = 0
emits('closeModal')
}
function closeSystem() {
logoutStep.value = 0
window.state = 'logout'
emits('handleSend', {
type: '/btn/quitApp',
msg: {}
})
stateStore.setData('loginAck', null)
}
function doSureLogout() {
if (pattern.value === 1 && logoutStep.value === 0) {
tipsLogout.value = '当前是无人模式,确定退出程序'
logoutStep.value = 1
} else {
closeSystem()
}
}
watch(() => props.isShow, (value) => {
if (value) {
writeLog('INFO',"退出系统")
tipsLogout.value = '退出当前系统'
}
}, {
immediate: true
})
</script>
<style lang="less" scoped>
.log-out {
&>p {
margin-bottom: 20px;
}
.footer {
text-align: end;
.btn {
margin-right: 10px;
}
}
}
</style>
\ No newline at end of file
import { useStateStore } from '@/store/StateStore' import { useStateStore } from '@/store/StateStore'
import { useVehicleStore } from '@/store/VehicleStore.js' import { useVehicleStore } from '@/store/VehicleStore.js'
import { useMapStore } from '@/store/MapStore.js' import { useMapStore } from '@/store/MapStore.js'
import writeLog from '@/js/writeLog.js'
import router from '../../router' import router from '../../router'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { Message } from 'view-ui-plus' import { Message } from 'view-ui-plus'
...@@ -145,6 +146,7 @@ export default class Socket { ...@@ -145,6 +146,7 @@ export default class Socket {
} }
this.timeoutTimer = setInterval(() => { this.timeoutTimer = setInterval(() => {
if (this.timeoutCount > NETWORK_COUNT) { if (this.timeoutCount > NETWORK_COUNT) {
writeLog('WARNING',`网络异常,请检测网络!连接超时${this.timeoutCount}s`)
this.stateStore.dealNetworkTip({ type: true, count: this.timeoutCount }) this.stateStore.dealNetworkTip({ type: true, count: this.timeoutCount })
} }
this.timeoutCount++ this.timeoutCount++
......
import axios from 'axios';
let loginForm=JSON.parse(window.localStorage.getItem(`${location.host}loginForm`))
const writeLog=(type,data)=>{
let log=type+' '+new Date().format('yyyy-MM-dd hh:mm:ss')+' '+loginForm.number+' '+location.host+' '+data
axios.post("//"+document.location.logServe+"/ht/api/web/log/upload",{log:log}).then(res=>{
if(res.code!=0){
console.log('writeLog',res.msg)
}
}).catch(err=>{
console.log('writeLog',err)
})
}
export default writeLog
\ No newline at end of file
...@@ -4,6 +4,7 @@ import App from './App.vue' ...@@ -4,6 +4,7 @@ import App from './App.vue'
import router from './router' import router from './router'
import axios from 'axios' import axios from 'axios'
import IndexRoot from './js/IndexRoot.js' import IndexRoot from './js/IndexRoot.js'
import writeLog from './js/writeLog.js'
import ViewUIPlus from 'view-ui-plus' import ViewUIPlus from 'view-ui-plus'
import 'leaflet/dist/leaflet.css' import 'leaflet/dist/leaflet.css'
import 'view-ui-plus/dist/styles/viewuiplus.css' import 'view-ui-plus/dist/styles/viewuiplus.css'
...@@ -50,6 +51,18 @@ const app = createApp(App) ...@@ -50,6 +51,18 @@ const app = createApp(App)
let $indexRoot = new IndexRoot() let $indexRoot = new IndexRoot()
app.config.globalProperties.$indexRoot = $indexRoot app.config.globalProperties.$indexRoot = $indexRoot
window.onerror=(message, source, lineno, colno, error)=>{
var data = {
message: message,
source: source,
lineno: lineno,
colno: colno,
error: error
};
writeLog('ERROR', JSON.stringify(data))
}
app.use(router) app.use(router)
.use(ViewUIPlus) .use(ViewUIPlus)
.use(pinia) .use(pinia)
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
import { Message } from 'view-ui-plus'; import { Message } from 'view-ui-plus';
import { useStateStore } from '@/store/StateStore.js' import { useStateStore } from '@/store/StateStore.js'
import router from '@/router' import router from '@/router'
import writeLog from '@/js/writeLog.js'
const isShow = ref(false) const isShow = ref(false)
const tip = ref('') const tip = ref('')
...@@ -79,6 +80,7 @@ ...@@ -79,6 +80,7 @@
watch(getLoginAck, (value) => { watch(getLoginAck, (value) => {
if (value && window.state === 'login') { if (value && window.state === 'login') {
writeLog('INFO',"登陆成功")
let {code, number} = value let {code, number} = value
if (code === 0 && number === formItem.number) { if (code === 0 && number === formItem.number) {
router.push({ router.push({
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
import { useVehicleStore } from '../store/VehicleStore'; import { useVehicleStore } from '../store/VehicleStore';
import { useStateStore } from '../store/StateStore'; import { useStateStore } from '../store/StateStore';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import writeLog from '../js/writeLog.js'
const props = defineProps({ const props = defineProps({
isShow: Boolean isShow: Boolean
...@@ -52,6 +53,7 @@ ...@@ -52,6 +53,7 @@
watch(() => props.isShow, (value) => { watch(() => props.isShow, (value) => {
if (value) { if (value) {
writeLog('INFO',"退出系统")
tipsLogout.value = '退出当前系统' tipsLogout.value = '退出当前系统'
} }
}, { }, {
......
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