严智鑫
2024-05-29 62c74409a587d9921df1a2248ce23b3b0375fbd1
UI-Project/src/views/UnLoadGlass/loadmachinerack.vue
@@ -1,6 +1,7 @@
<script setup>
import {Search} from "@element-plus/icons-vue";
import {reactive,  onMounted} from "vue";
import {reactive, onMounted, onBeforeUnmount} from "vue";
import {useRouter} from "vue-router"
const router = useRouter()
@@ -9,75 +10,24 @@
import Landingindication from "./Landingindication.vue";
import Landingindicationtwo from "./Landingindicationtwo.vue";
import request from "@/utils/request";
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
 import { WebSocketHost } from '@/utils/constants';
const dialogFormVisiblea = ref(false)
const dialogFormVisiblea2 = ref(false)
let socket;
const initWebSocket = (token) =>{ //初始化we
let viewname = "unloadglass";
if (typeof WebSocket === "undefined") {
  console.log("您的浏览器不支持WebSocket");
} else {
  let socketUrl = "ws://" + "localhost"+":88" + "/api/talk/" + viewname;
  if (socket != null) {
    socket.close();
    socket = null;
  }
  // 开启一个websocket服务
  socket = new WebSocket(socketUrl);
  // 打开事件
  socket.onopen = function () {
    console.log("websocket已打开");
  };
socket.onmessage = (msg) => {
if (!msg.data) {
return; // 如果收到空数据,则直接返回,不执行后续逻辑
}
    let obj = JSON.parse(msg.data);
      console.log('收到消息:', obj.data);
  }
  }
  }
// 数据
const loading = ref(false);
// 弹框显示控制
const dialogFormVisible = ref(false);
// 表单数据
const workstationId = ref('');
const flowCardId = ref('');
const flowCardOptions = ref([]);
const tableData = reactive([]);
// 方法
const handleSelectionChange = () => {
  // 处理表格行选择事件
@@ -85,15 +35,10 @@
const handleBindRack = (row) => {
  workstationId.value = row.workstationId; // 假设rackNumber是架号字段的属性名
  // 发起接口请求获取流程卡号
    fetchFlowCardId(); 
  dialogFormVisiblea.value = true; // 打开绑定架子对话框
};
//获取流程卡号
const fetchFlowCardId = async () => {
@@ -101,9 +46,12 @@
    const response = await request.get('unLoadGlass/downWorkStation/getflowCardId');
    console.log(response)
    if (response.code === 200) {
      flowCardOptions.value = response.data.map(item => ({ flowcard_id: item.flow_card_Id }));
      console.log(flowCardOptions.value)
    } else {
  flowCardOptions.value = response.data
    .filter(item => item !== null)
    .map(item => ({ flowcard_id: item.flow_card_Id }));
  console.log(flowCardOptions.value);
}
 else {
      ElMessage.error(response.msg);
    }
  } catch (error) {
@@ -141,19 +89,12 @@
  // 假设你的页面上有一个名为 tableData 的 Vue 组件
  // 你可以直接更新 tableData 的数据
  fetchTableData()
  // 使用 $forceUpdate() 强制更新组件
 
};
const handleBindRack2 = (row) => {
  workstationId.value = row.workstationId; // 假设rackNumber是架号字段的属性名
  dialogFormVisiblea2.value = true; // 打开绑定架子对话框
};
//清除内容
@@ -185,9 +126,6 @@
};
// 发送获取表格数据的请求
const fetchTableData = async () => {
  try {
@@ -210,89 +148,36 @@
};
const socketUrl = `ws://${WebSocketHost}:8085/api/talk/unloadglass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  tableData.splice(0, tableData.length, ...data.params[0]);
 // console.log("更新后数据", tableData);
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  fetchFlowCardId();
  fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
});
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
// beforeUnmount(() => {
//   closeWebSocket();
// });
// initWebSocket();
onMounted(fetchTableData);
// setInterval(fetchTableData, 2000)
const open = () => {
  ElMessageBox.confirm(
    '是否删除该条信息?',
    '提示',
    {
      confirmButtonText: '是',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      ElMessage({
        type: 'success',
        message: '删除成功!',
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '删除失败',
      })
    })
}
const getTableRow = (row,type) =>{
  switch (type) {
    case 'edit' :{
      //alert('我接收到子组件传送的编辑信息')
      router.push({path: '/main/returns/createReturns', query: { ReturnID: 'TH24010101' }})
      break
    }
    case 'delete':{
      alert('我接收到子组件传送的删除信息')
      break
    }
  }
}
const gridOptions = reactive({
  border:  "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe:true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true,height: 50},//鼠标移动或选择高亮
  id: 'OrderList',
  showFooter: true,//显示脚
  printConfig: {},
  importConfig: {},
  exportConfig: {},
  scrollY:{ enabled: true },//开启虚拟滚动
  showOverflow:true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  filterConfig: {   //筛选配置项
    remote: true
  },
  customConfig: {
    storage: true
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },
  data:  [
    {
      'id': '1',
      'long': '5',
      'wide': '1005',
      'thick': '183.6',
    }
  ],
})
</script>
@@ -311,7 +196,19 @@
          <el-table-column prop="racksnumber" align="center" label="已落架数量" min-width="120" />
          <el-table-column prop="work_state" align="center" label="状态" min-width="120" />
          <el-table-column prop="deviceId" align="center" label="设备号" min-width="120" />
          <el-table-column prop="enableState" align="center" label="启用状态" min-width="120" />
          <el-table-column
            align="center"
            label="启用状态"
            min-width="80"
            prop="enableState"
          >
          <template #default="scope">
            <el-tag type="success" >{{ scope.row.enableState==1?"启用":"未启用"  }}</el-tag>
          </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" align="center" width="200">
            <template #default="scope">
            <el-button size="mini" type="text" plain v-show="scope.row.enableState !== '已启用' " @click="handleBindRack(scope.row)">绑定架子</el-button>