wu
2024-06-24 09a010c5dc11c68a866a6075a74bd1bbefb4a9a8
UI-Project/src/views/Caching/cachingbefore.vue
@@ -4,9 +4,11 @@
import {useRouter} from "vue-router"
const router = useRouter()
const adda = ref(false)
import { WebSocketHost ,host} from '@/utils/constants'
import request from "@/utils/request"
import { ref, onMounted } from "vue";
import { ref, onMounted , onBeforeUnmount} from "vue";
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
// import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
//  import LanguageMixin from './lang/LanguageMixin'
@@ -14,7 +16,6 @@
const tableData = ref([])
const slot = ref('')
const adjustedRects = ref([]);
onMounted(async () => {  
  try {  
    const response = await request.post('/cacheGlass/edgStorageCage/selectEdgStorageCage'); // 替换为你的API端点  
@@ -35,7 +36,17 @@
    // console.error('Error fetching rects :', error);  
  }  
}); 
const toggleEnableState = async (row) => {
  const newState = row.enable_state === 1 ? 0 : 1;
  // 发送请求到后端更新状态(这里省略了实际的请求逻辑)
  const response = await request.post('/cacheGlass/edgStorageCage/updateEdgStorageCage', { id: row.id, enablestate: newState });
  if (response.code === 200) {
      ElMessage.success(response.message);
      } else {
      ElMessage.error(response.message);
      }
  row.enable_state = newState;
};
const open = async(row) => {  
  try {  
    const confirmResult = await ElMessageBox.confirm(  
@@ -67,6 +78,30 @@
    console.error('发生错误:', error);  
  }  
};   
const socketUrl = `ws://${WebSocketHost}:${host}/api/cacheGlass/api/talk/cacheGlass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  tableData.value = data.EdgStorageCageinfos[0]
  // adjustedRects.value = data.EdgStorageCageinfos[0]
  adjustedRects.value = data.EdgStorageCageinfos[0].map(rect => ({
            ...rect, // 复制原始对象的其他属性
            width: rect.width * 0.5 ,
            id: rect.id * 10,
          }));
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  // fetchFlowCardId();
  // fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
});
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
</script>
<template>
@@ -86,9 +121,17 @@
            min-width="80"
            prop="enable_state"
          >
          <template #default="scope">
          <template #default="scope">
          <el-tag
            :type="scope.row.enable_state === 1 ? 'success' : 'danger'"
            @click="toggleEnableState(scope.row)"
          >
            {{ scope.row.enable_state === 1 ? '启用' : '禁用' }}
          </el-tag>
        </template>
          <!-- <template #default="scope">
            <el-tag type="success" >{{ scope.row.enable_state==1?"启用":"未启用"  }}</el-tag>
          </template>
          </template> -->
          </el-table-column>
          <el-table-column fixed="right" label="操作" align="center" width="200">
            <template #default="scope">