Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/views/home.vue
main
FOAM 2024-09-18 16:06:34 +08:00
commit b44c94512c
2 changed files with 92 additions and 6 deletions

View File

@ -1,10 +1,96 @@
<template>
<div id="app">
<router-view />
<router-view/>
</div>
</template>
<script>
export default {
name: 'App'
name: 'App',
data() {
return {
notificationInstance: null, //
showNotification: false, //
}
},
mounted() {
this.initWebSocket();
}, methods: {
initWebSocket() {
const wsUri = (process.env.VUE_APP_WS_API === '/' ? '/' : (process.env.VUE_APP_WS_API + '/')) + 'webSocket/stock'
this.websock = new WebSocket(wsUri)
this.websock.onerror = this.webSocketOnError
this.websock.onmessage = this.webSocketOnMessage
},
webSocketOnError(e) {
this.$notify({
title: 'WebSocket连接发生错误',
type: 'error',
duration: 0
})
}, webSocketOnMessage(e) {
const data = JSON.parse(e.data)
if (data.msgType === 'INFO') {
this.createOrUpdateNotification(data);
} else if (data.msgType === 'ERROR') {
this.$notify({
title: '',
message: data.msg,
dangerouslyUseHTMLString: true,
type: 'error',
duration: 0
})
}
},
webSocketSend(agentData) {
this.websock.send(agentData)
},
createOrUpdateNotification(data) {
//
if (this.showNotification && this.notificationInstance) {
this.updateNotification(data);
} else {
this.createNotification(data);
}
this.showNotification = true;
},
updateNotification(data) {
//
try {
this.notificationInstance.title = '点击关注公众号';
this.notificationInstance.message = data.msg;
} catch (error) {
//
this.createNotification(data);
}
},
createNotification(data) {
//
this.notificationInstance = this.$notify({
title: '点击关注公众号',
message: data.msg,
type: 'success',
offset: 100,
duration: 0,
onClose: this.onNotificationClose //
});
},
onNotificationClose() {
this.showNotification = false;
this.notificationInstance = null;
}
},
beforeDestroy() {
if (this.websock && this.websock.readyState === WebSocket.OPEN) {
this.websock.close();
}
if (this.notificationInstance) {
this.notificationInstance.close(); //
this.showNotification = false;
this.notificationInstance = null;
}
}
}
</script>

View File

@ -44,7 +44,7 @@ export function updateStockStatus(stockList) {
return request({
url: 'api/stock/updateStockStatus',
method: 'put',
data:stockList
data: stockList
})
}
@ -75,9 +75,9 @@ export function containerOut(data) {
export function stockMsg(data) {
return request({
url: 'api/stock/stockMsg',
method: 'post',
data
method: 'get',
params: {data}
})
}
export default { add, edit, del,containerIn,containerOut,updateStockStatus,stockMsg}
export default {add, edit, del, containerIn, containerOut, updateStockStatus, stockMsg}