ezhizao_zx 4 meses atrás
pai
commit
2a1bf3070d

+ 10 - 0
src/api/business/beforeCheckoutVerify.js

@@ -44,4 +44,14 @@ export function checkMultiplyFurnace(data) {
     method: 'post',
     data: data
   })
+}
+
+
+// 异步导出excel
+export function exportAsync(data) {
+  return request({
+    url: baseUrl + '/business/asyncExport/processInspectionexport',
+    method: 'post',
+    data: data
+  })
 }

+ 12 - 12
src/api/business/processInspecion.js

@@ -4,7 +4,7 @@ const baseUrl = import.meta.env.VITE_APP_PRODUCTION_API
 // 查询序检主表列表
 export function listInspecion(query) {
   return request({
-    url: baseUrl +'/business/inspecion/listInfo',
+    url: baseUrl + '/business/inspecion/listInfo',
     method: 'get',
     params: query
   })
@@ -13,23 +13,23 @@ export function listInspecion(query) {
 // 查询序检主表详细
 export function getInspecion(id) {
   return request({
-    url:  baseUrl +'/business/inspecion/' + id,
+    url: baseUrl + '/business/inspecion/' + id,
     method: 'get'
   })
 }
 export function getDayworkItemInspectionDetail(data) {
-	return request({
-		url: baseUrl + '/business/inspecion/getDayworkItemInspectionDetail',
-		method: 'post',
-		data:data
-	})
+  return request({
+    url: baseUrl + '/business/inspecion/getDayworkItemInspectionDetail',
+    method: 'post',
+    data: data
+  })
 }
 export function getInspectionType(data) {
-	return request({
-		url: baseUrl + '/business/inspecion/getInspectionType',
-		method: 'post',
-		data:data
-	})
+  return request({
+    url: baseUrl + '/business/inspecion/getInspectionType',
+    method: 'post',
+    data: data
+  })
 }
 
 // 新增序检主表

+ 5 - 0
src/plugins/notification.js

@@ -1,11 +1,16 @@
 import { render, createVNode } from "vue";
 import notification from "../views/dialog/updateAnnouncement.vue";
+// import auth from '@/plugins/auth'
 const div = document.createElement('div')
 div.setAttribute('class', 'my-message-contsiner')
 // div.setAttribute('style', 'z-index: 2007;position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);')
 document.body.appendChild(div)
 
 export default (data) => {
+  // 有某个权限则不显示
+  // if (auth.hasPermi('')) {
+  //   return
+  // }
   // console.log(data)
   const { title, content, updateContent } = data
   // console.log(notification)

+ 3 - 4
src/store/modules/message.js

@@ -37,7 +37,7 @@ const useMessageStore = defineStore('message', {
         this.ws = new WebSocket(wsUrl + id, [token])
       } catch (e) {
         // console.log(e)
-        this.reconnection()
+        this.reconnection(id, token)
       }
     },
     async connection(id, token) {
@@ -76,7 +76,7 @@ const useMessageStore = defineStore('message', {
       this.timerHeart && clearTimeout(this.timerHeart)
       this.timerServerHeart && clearTimeout(this.timerServerHeart)
     },
-    reconnection() {
+    reconnection(id, token) {
       console.log("重新连接")
       if (this.lockReconnect) {
         return
@@ -88,7 +88,7 @@ const useMessageStore = defineStore('message', {
       //没连上会一直重连, 设置迟延,避免请求过多
       this.timerReconnect = setTimeout(() => {
         //setTimeout 到点了执行
-        this.connection()
+        this.connection(id, token)
         this.lockReconnect = false
       }, 5000);
     },
@@ -116,7 +116,6 @@ const useMessageStore = defineStore('message', {
       this.ws.close()
     },
     initMessageCount() {
-
     }
   }
 })

+ 116 - 7
src/views/business/outsourceInspectionVerify/index.vue

@@ -126,9 +126,13 @@ import {
   rejectInspection,
   confirmInspection,
   checkFurnace,
-  checkMultiplyFurnace
+  checkMultiplyFurnace,
+  exportAsync
 } from "@/api/business/beforeCheckoutVerify";
+
 import { nextTick } from "vue";
+import { getToken } from '@/utils/auth'
+import useUserStore from '@/store/modules/user'
 const { proxy } = getCurrentInstance();
 /** 字典数组区 */
 const { outsource_before_checkout_verify_status } = proxy.useDict(
@@ -148,6 +152,11 @@ const total = ref(0);
 const selections = ref([])
 const printCarriers = ref([]);
 const confirmLoading = ref(false)
+const exportSuccess = ref(false)
+const doingExport = ref(false)
+const wsUrl = 'ws://localhost:8081/wsExport/'
+let ws = null
+
 const webHost = import.meta.env.VITE_APP_PRODUCTION_API;
 /** 查询对象 */
 const queryParams = ref({
@@ -170,7 +179,6 @@ const queryParams = ref({
 /** 查询外协单主 带箱方式,是整单的。如果换新箱子,明细中,都需要更换箱子列表 */
 function getList() {
   loading.value = true;
-
   listCheckoutInspection(queryParams.value).then((response) => {
     orderList.value = response.rows;
     total.value = response.total;
@@ -204,12 +212,12 @@ function handlePass() {
           })
           .then(() => {
             confirmInspection(res.data).then((res) => {
-              getList();
+              getList()
               confirmLoading.value = false
             }).catch(e => {
               confirmLoading.value = false
-            });
-          });
+            })
+          })
       } else {
         proxy
           .$confirm("该炉已全部质检,是否全部确认通过?", "提示", {
@@ -229,7 +237,7 @@ function handlePass() {
           })
       }
     } else {
-      proxy.$msgError(res.msg);
+      proxy.$msgError(res.msg)
       confirmLoading.value = false
     }
   }).catch(e => {
@@ -331,9 +339,110 @@ function handleReject(row) {
     }
   });
 }
+/** 异步导出excel */
+async function exportForYear() {
+  if (ws == null) {
+    // 启动一个websocket
+    console.log(useUserStore().user.userId)
+    await createWebSocket(useUserStore().user.userId, getToken())
+    initWebsocket()
+  } else {
+    initWebsocket()
+  }
+  // 发送请求要求导出excel
+  exportAsync(queryParams.value).then(res => {
+    if (res.code == 200) {
+      doingExport.value = true
+    }
+  })
+}
 
-function exportForYear(row) {
+async function createWebSocket(id, token) {
+  try {
+    // const options = { headers: { Authorization: 'Bearer ' + token } }
+    // console.log(options)
+    ws = new WebSocket(wsUrl + id, [token])
+  } catch (e) {
+    console.log(e)
+    reconnection()
+  }
+}
+let lockReconnect = false
+let timerReconnect = undefined
+let timerHeart = undefined
+let timerServerHeart = undefined
+const heartTimeOut = 40000
+let handClose = false
+function reconnection() {
+  console.log("重新连接")
+  if (lockReconnect) {
+    return
+  }
+  lockReconnect = true
+  if (timerReconnect) {
+    clearTimer(timerReconnect)
+  }
+  //没连上会一直重连, 设置迟延,避免请求过多
+  timerReconnect = setTimeout(() => {
+    //setTimeout 到点了执行
+    connection(useUserStore().user.userId, getToken())
+    lockReconnect = false
+  }, 5000);
+}
+
+async function connection(id, token) {
+  await createWebSocket(id, token)
+}
+
+function clearTimer() {
+  timerReconnect && clearTimeout(timerReconnect)
+  timerHeart && clearTimeout(timerHeart)
+  timerServerHeart && clearTimeout(timerServerHeart)
+}
+
+function initWebsocket() {
+  ws.onopen = (e) => {
+    ws.send("open server")
+    console.log("链接成功")
+    heartCheck()
+  }
+  ws.onmessage = (message) => {
+    console.log(message)
+    heartCheck()
+  }
+  ws.onerror = (e) => {
+    console.log('链接失败')
+    reconnection()
+  }
+  ws.onclose = (e) => {
+    console.log("关闭连接")
+    if (!handClose) {
+      reconnection()
+    }
+  }
+}
+
+function sentMessage(message) {
+  ws.send(message)
+}
+
+function closeWs() {
+  handClose = true
+  clearTimer()
+  ws.close()
+  ws = null
+}
 
+function heartCheck() {
+  console.log('心跳检测')
+  if (timerHeart) {
+    clearTimeout(timerHeart)
+  }
+  timerHeart = setTimeout(() => {
+    // console.log("ping")
+    ws.send("ping")
+    lockReconnect = false
+  }, heartTimeOut)
 }
 
 getList();

+ 9 - 2
src/views/dialog/updateAnnouncement.vue

@@ -1,6 +1,6 @@
 <template>
   <!-- 公告 -->
-  <el-dialog v-model="visible" :show-close="false" width="500" :close-on-click-modal="false"
+  <el-dialog v-model="visible" :show-close="canClose()" width="500" :close-on-click-modal="false"
     :close-on-press-escape="false">
     <template #header>
       <div class="my-header">
@@ -13,6 +13,7 @@
 <script>
 import { getCurrentInstance, toRefs, onMounted } from 'vue'
 import { ElDialog } from 'element-plus';
+import auth from '@/plugins/auth'
 import 'element-plus/theme-chalk/el-dialog.css'; // 引入 el-dialog 的样式
 import 'element-plus/theme-chalk/el-button.css';
 // import { ElDialog } from 'element-plus';
@@ -39,7 +40,13 @@ export default {
     const open = () => {
       visible.value = true
     }
-    return { visible }
+    const canClose = () => {
+      if (auth.hasPermi('business:notification:close')) {
+        return true
+      }
+      return false
+    }
+    return { visible, canClose, open }
   }
 }