no message

main
奥德彪本彪\92525 2024-09-15 18:42:26 +08:00
parent a082015468
commit b3d70503ac
3 changed files with 127 additions and 71 deletions

View File

@ -4,7 +4,61 @@
</div> </div>
</template> </template>
<script> <script>
import stockUrl from '@/api/stock'
export default { export default {
name: 'App' name: 'App',
data() {
return {
msg: '',
websock: null
}
},
mounted() {
stockUrl.stockMsg(null)
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.msg = data.msg
if (this.msg) {
this.$notify({
title: '消息通知',
message: data.msg,
dangerouslyUseHTMLString: true,
type: 'success',
offset: 50,
duration: 0
})
}
} else if (data.msgType === 'ERROR') {
this.$notify({
title: '',
message: data.msg,
dangerouslyUseHTMLString: true,
type: 'error',
duration: 0
})
}
},
webSocketSend(agentData) {
this.websock.send(agentData)
}
}
} }
</script> </script>

View File

@ -80,11 +80,11 @@ export function getItemCode(stockCode) {
}) })
} }
export function stockMsg(data) { export function stockMsg(msg) {
return request({ return request({
url: 'api/stock/stockMsg', url: 'api/stock/stockMsg',
method: 'post', method: 'get',
data params:{msg}
}) })
} }

View File

@ -57,7 +57,8 @@
<dv-scroll-board <dv-scroll-board
:config="this.config2" :config="this.config2"
style="width: 365px; height: 280px;margin-left:10px;"/> style="width: 365px; height: 280px;margin-left:10px;"
/>
</dv-border-box-8> </dv-border-box-8>
</div> </div>
@ -75,7 +76,8 @@
@current-change="handleCurrentClick" @current-change="handleCurrentClick"
:current-page="currentPage" :current-page="currentPage"
:page-size="pageSize" :page-size="pageSize"
:total="total"> :total="total"
>
</el-pagination> </el-pagination>
</div> </div>
</dv-border-box-11> </dv-border-box-11>
@ -84,14 +86,14 @@
</template> </template>
<script> <script>
import * as echarts from 'echarts'; import * as echarts from 'echarts'
import moment from "moment"; import moment from 'moment'
import crudPoint from "@/api/point"; import crudPoint from '@/api/point'
import crudAgvTask from "@/api/agvTask" import crudAgvTask from '@/api/agvTask'
import CRUD from "@crud/crud"; import CRUD from '@crud/crud'
import 'echarts-gl'; import 'echarts-gl'
import VueMarquee from 'aring-vue-marquee'; import VueMarquee from 'aring-vue-marquee'
import stockUrl from "@/api/stock"; import stockUrl from '@/api/stock'
export default { export default {
name: 'DeptData', name: 'DeptData',
@ -101,7 +103,8 @@ export default {
data() { data() {
return { return {
msg: '', msg: '',
imageUrl: require("@/assets/images/igw-l-news-noticewhite.png"), websock: null,
imageUrl: require('@/assets/images/igw-l-news-noticewhite.png'),
total: 0, total: 0,
pageSize: 25, pageSize: 25,
currentPage: 1, currentPage: 1,
@ -132,7 +135,7 @@ export default {
{ {
name: '西峡', name: '西峡',
value: 98 value: 98
}, }
] ]
}, },
config2: { config2: {
@ -145,7 +148,7 @@ export default {
carousel: 'page', carousel: 'page',
rowNum: 8, rowNum: 8,
indexHeader: '序号' indexHeader: '序号'
}, }
} }
}, },
computed: { computed: {
@ -157,36 +160,39 @@ export default {
// //
beforeDestroy() { beforeDestroy() {
this.clearTimer() this.clearTimer()
if (this.websock && this.websock.readyState === WebSocket.OPEN) {
this.websock.close()
}
}, },
mounted() { mounted() {
// //
setInterval(this.updateTime, 1000);// setInterval(this.updateTime, 1000)//
this.getInit()// this.getInit()//
this.queryAgvTaskInfo();//AGV this.queryAgvTaskInfo()//AGV
this.queryListInfo(this.currentPage, this.pageSize)// this.queryListInfo(this.currentPage, this.pageSize)//
this.intervalId = setInterval(this.printNextItem, 5000);// this.intervalId = setInterval(this.printNextItem, 5000)//
this.stockMsg(); stockUrl.stockMsg(null)
this.initWebSocket(); this.initWebSocket()
}, },
methods: { methods: {
updateTime() { updateTime() {
this.currentTime = moment().format('YYYY-MM-DD HH:mm:ss'); this.currentTime = moment().format('YYYY-MM-DD HH:mm:ss')
let weekMap = { let weekMap = {
1: "一", 1: '一',
2: "二", 2: '二',
3: '三', 3: '三',
4: "四", 4: '四',
5: "五", 5: '五',
6: "六", 6: '六',
0: "日", 0: '日'
}; }
this.dayOfWeek = weekMap[moment().day()]; this.dayOfWeek = weekMap[moment().day()]
}, },
// //
getInit() { getInit() {
var chartDom = document.getElementById("main") var chartDom = document.getElementById('main')
var myChart = echarts.init(chartDom); var myChart = echarts.init(chartDom)
var option; var option
option = { option = {
xAxis: { xAxis: {
type: 'category', type: 'category',
@ -207,25 +213,25 @@ export default {
type: 'bar', type: 'bar',
itemStyle: { itemStyle: {
color: '#4675C0' color: '#4675C0'
}, }
} }
] ]
}; }
option && myChart.setOption(option); option && myChart.setOption(option)
}, },
// //
queryAgvTaskInfo() { queryAgvTaskInfo() {
crudAgvTask.queryAgvTaskInfo().then(res => { crudAgvTask.queryAgvTaskInfo().then(res => {
const cf = this.config2 const cf = this.config2
cf.data = res.data cf.data = res.data
this.config2 = null; this.config2 = null
setTimeout(() => { setTimeout(() => {
this.config2 = cf this.config2 = cf
}, 500) }, 500)
}).catch(() => { }).catch(() => {
this.crud.notify('数据加载失败!', CRUD.NOTIFICATION_TYPE.ERROR); this.crud.notify('数据加载失败!', CRUD.NOTIFICATION_TYPE.ERROR)
}) })
}, },
// //
@ -239,7 +245,7 @@ export default {
this.collection.push(i) this.collection.push(i)
} }
}).catch(() => { }).catch(() => {
this.crud.notify('数据加载失败!', CRUD.NOTIFICATION_TYPE.ERROR); this.crud.notify('数据加载失败!', CRUD.NOTIFICATION_TYPE.ERROR)
}) })
}, },
@ -247,12 +253,12 @@ export default {
if (this.total > 0 && this.collection.length > 0) { if (this.total > 0 && this.collection.length > 0) {
if (this.currentIndex < this.collection.length - 1) { if (this.currentIndex < this.collection.length - 1) {
this.currentIndex++; this.currentIndex++
this.queryListInfo(this.collection[this.currentIndex], this.pageSize); this.queryListInfo(this.collection[this.currentIndex], this.pageSize)
this.handleCurrentChange(this.collection[this.currentIndex]) this.handleCurrentChange(this.collection[this.currentIndex])
} else { } else {
this.currentIndex = 0; // this.currentIndex = 0 //
this.queryListInfo(this.collection[this.currentIndex], this.pageSize); this.queryListInfo(this.collection[this.currentIndex], this.pageSize)
this.handleCurrentChange(this.collection[this.currentIndex]) this.handleCurrentChange(this.collection[this.currentIndex])
} }
} }
@ -260,25 +266,25 @@ export default {
}, },
autoGrid(total, page) { autoGrid(total, page) {
// //
const start = ((page - 1) * this.pageSize) + 1; const start = ((page - 1) * this.pageSize) + 1
const end = start + this.pageSize;// const end = start + this.pageSize//
this.divs = []; this.divs = []
for (let i = start; i <= end; i++) { for (let i = start; i <= end; i++) {
const newItem = `Item ${+i}`; const newItem = `Item ${+i}`
this.$set(this.divs, this.divs.length, newItem); this.$set(this.divs, this.divs.length, newItem)
} }
}, },
handleCurrentChange(newPage) { handleCurrentChange(newPage) {
this.currentPage = newPage; this.currentPage = newPage
}, },
handleCurrentClick(newPage) { handleCurrentClick(newPage) {
this.queryListInfo(newPage, this.pageSize) this.queryListInfo(newPage, this.pageSize)
}, },
clearTimer() { clearTimer() {
if (this.intervalId) { if (this.intervalId) {
clearInterval(this.intervalId); clearInterval(this.intervalId)
this.intervalId = null; this.intervalId = null
} }
}, },
initWebSocket() { initWebSocket() {
@ -299,7 +305,7 @@ export default {
this.msg = data.msg this.msg = data.msg
} else if (data.msgType === 'ERROR') { } else if (data.msgType === 'ERROR') {
this.$notify({ this.$notify({
title: '', title: '消息通知',
message: data.msg, message: data.msg,
dangerouslyUseHTMLString: true, dangerouslyUseHTMLString: true,
type: 'error', type: 'error',
@ -309,14 +315,10 @@ export default {
}, },
webSocketSend(agentData) { webSocketSend(agentData) {
this.websock.send(agentData) this.websock.send(agentData)
},
stockMsg() {
stockUrl.stockMsg()
} }
} }
} }
</script> </script>