Browse Source

websocket

master
maochaoying 2 years ago
parent
commit
c43b7ba2ed
  1. 1
      .env
  2. 3
      src/components/Task.vue
  3. 13
      src/pages/index.vue
  4. 27
      src/utils/websocket.js

1
.env

@ -1 +1,2 @@
VITE_BASE_URL=http://192.168.1.111:8899 VITE_BASE_URL=http://192.168.1.111:8899
VITE_WEBSOCKET_URL=ws://127.0.0.1:8899/websocket/nuclear

3
src/components/Task.vue

@ -17,7 +17,7 @@
row-key="id" row-key="id"
:data="data" :data="data"
:columns="columns" :columns="columns"
table-layout="auto"
table-layout="fixed"
:height="500" :height="500"
:scroll="{ type: 'virtual', rowHeight: 69, bufferSize: 10 }" :scroll="{ type: 'virtual', rowHeight: 69, bufferSize: 10 }"
resizable resizable
@ -291,6 +291,7 @@ export default {
{ {
title: '操作', title: '操作',
fixed: 'right', fixed: 'right',
colKey: 'oper',
cell: (h, { row }) => { cell: (h, { row }) => {
if (this.role == 'ROLE_ADMIN') { if (this.role == 'ROLE_ADMIN') {
return ( return (

13
src/pages/index.vue

@ -337,6 +337,7 @@
<script setup> <script setup>
import { useAccountStore, useTaskStore, useImageStore } from '@/store' import { useAccountStore, useTaskStore, useImageStore } from '@/store'
import socket from '@/utils/websocket'
import Cookie from '@/utils/cookie' import Cookie from '@/utils/cookie'
import { ref, onMounted, computed } from 'vue' import { ref, onMounted, computed } from 'vue'
import Excel from 'cpns/Excel' import Excel from 'cpns/Excel'
@ -355,6 +356,9 @@ const imageStore = useImageStore()
const hasTestedLength = ref(0) const hasTestedLength = ref(0)
const testArrLength = ref(121) const testArrLength = ref(121)
// websocket
const websocket = ref(null)
const detailProcess = computed(() => { const detailProcess = computed(() => {
const testArr = taskStore.excelData.filter( const testArr = taskStore.excelData.filter(
item => item.firstSign && item.secondSign, item => item.firstSign && item.secondSign,
@ -413,8 +417,17 @@ const logout = () => {
window.location.href = '/login' window.location.href = '/login'
} }
const getSocketdata = res => {
console.log(res)
if (res == 'update') {
//
}
}
onMounted(async () => { onMounted(async () => {
// taskStore.getExcelList(1) // taskStore.getExcelList(1)
websocket.value = new socket()
websocket.value.WebSocketSet(getSocketdata)
}) })
</script> </script>

27
src/utils/websocket.js

@ -0,0 +1,27 @@
class socket {
constructor() {
this.ws = null
}
WebSocketSet(callBack) {
if ('WebSocket' in window) {
this.ws = new WebSocket(`${import.meta.env.VITE_WEBSOCKET_URL}`)
this.ws.onopen = res => {
console.log('socket连接成功')
}
this.ws.onmessage = res => {
console.log('数据已接收...', res.data)
callBack(res.data)
}
} else {
alert('当前浏览器不支持websocket')
}
}
close() {
this.ws.close()
this.ws.onclose = res => {
console.log(console.log('socket已经关闭'))
}
}
}
export default socket
Loading…
Cancel
Save