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

日志

parent 53451bf0
This diff is collapsed.
This diff is collapsed.
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 { 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'
......@@ -145,6 +146,7 @@ export default class Socket {
}
this.timeoutTimer = setInterval(() => {
if (this.timeoutCount > NETWORK_COUNT) {
writeLog('WARNING',`网络异常,请检测网络!连接超时${this.timeoutCount}s`)
this.stateStore.dealNetworkTip({ type: true, count: 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'
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'
......@@ -50,6 +51,18 @@ 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)
......
......@@ -34,6 +34,7 @@
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('')
......@@ -79,6 +80,7 @@
watch(getLoginAck, (value) => {
if (value && window.state === 'login') {
writeLog('INFO',"登陆成功")
let {code, number} = value
if (code === 0 && number === formItem.number) {
router.push({
......
......@@ -13,6 +13,7 @@
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
......@@ -52,6 +53,7 @@
watch(() => props.isShow, (value) => {
if (value) {
writeLog('INFO',"退出系统")
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