UI-Project/src/views/Caching/cachingun.vue
@@ -1,200 +1,244 @@
<template>
  <div style="height: 500px;">
    <el-card style="flex: 1;margin-left: 10px;margin-top: 20px;" v-loading="loading">
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;">
        <el-table height="340" ref="table" @selection-change="handleSelectionChange" :data="tableData"
          :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129' }">
          <el-table-column prop="slot" align="center" :label="$t('sorter.gridnumber')" min-width="80" />
          <el-table-column prop="glass_id" align="center" :label="$t('sorter.glassnumber')" min-width="80" />
          <el-table-column prop="width" align="center" :label="$t('sorter.width')" min-width="120" />
          <el-table-column prop="height" align="center" :label="$t('sorter.height')" min-width="120" />
          <el-table-column align="center" :label="$t('sorter.startstatus')" min-width="80" prop="enable_state">
            <template #default="scope">
              <el-tag :type="scope.row.enable_state === 1 ? 'success' : 'danger'" @click="toggleEnableState(scope.row)">
                {{ scope.row.enable_state === 1 ? $t('sorter.start') : $t('sorter.disable') }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column fixed="right" :label="$t('sorter.operate')" align="center" width="200">
            <template #default="scope">
              <el-button size="mini" type="text" plain @click="open(scope.row)">{{ $t('sorter.deficiencieste')
                }}</el-button>
              <el-button size="mini" type="text" plain @click="opena(scope.row)">{{ $t('sorter.updown') }}</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <div class="awatch">
      <img src="../../assets/woshihuancun.png" alt=""
        style="width: 70%;height: 90%;margin-left: 200px;margin-top: 20px;position: relative;">
      <div style="position: relative; width: 500px;height: 95px;margin-top: -165px;margin-left: 450px;">
        <div v-for="(rect, index) in adjustedRects" :key="rect" :style="{
      position: 'absolute',
      top: `${rect.id}px`, left: `10px`, width: `${rect.width}px`, height: `5px`,
      backgroundColor: '#409EFF'
    }">
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { Search, Lock, Avatar } from "@element-plus/icons-vue";
import { reactive } from "vue";
import { useRouter } from "vue-router"
const router = useRouter()
import { WebSocketHost, host } from '@/utils/constants'
import {onBeforeUnmount, onMounted, onUnmounted, ref} from "vue";
import {useRouter} from "vue-router"
import {host, WebSocketHost} from '@/utils/constants'
import request from "@/utils/request"
import { ref, onMounted, onBeforeUnmount, onUnmounted } from "vue";
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
import { ElMessage, ElMessageBox } from 'element-plus'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const tableData = reactive([]);
const slot = ref('')
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
import {ElMessage, ElMessageBox} from 'element-plus'
import {useI18n} from 'vue-i18n'
const {t} = useI18n()
let language = ref(localStorage.getItem('lang') || 'zh')
const tableDataa = ref([])
const tableDatab = ref([])
const adjustedRects = ref([]);
onMounted(async () => {
  try {
    const response = await request.get('/unLoadGlass/downStorage/selectStorageCage');
    if (response.code === 200) {
      const rawRects = response.data;
      tableData.value = response.data
      console.log(response.data);
      adjustedRects.value = rawRects.map(rect => ({
        ...rect,
        width: rect.width * 0.5,
        id: rect.id * 10,
      }));
      console.log(adjustedRects.value);
    } else {
      ElMessage.warning(res.msg)
    }
  } catch (error) {
    // console.error('Error fetching rects :', error);
  }
});
const open = async (row) => {
  try {
    const confirmResult = await ElMessageBox.confirm(
      t('sorter.information'),
      t('sorter.prompt'),
      {
        confirmButtonText: t('sorter.yes'),
        cancelButtonText: t('sorter.cancel'),
        type: 'warning',
      }
    );
    if (confirmResult === 'confirm') {
      var url = "/unLoadGlass/downStorage/deleteDownStorageCage";
      console.log(url);
      const response = await request.post(url, {
        glassId: row.glass_id,
        state: 9,
        line: 1001,
        workingProcedure: '磨边',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
    } else {
      ElMessage.error(response.message);
    }
  }
  }
  catch (error) {
  console.error('发生错误:', error);
}
};
// 人工下片
const opena = async (row) => {
  try {
    const confirmResult = await ElMessageBox.confirm(
      t('sorter.infor'),
      t('sorter.prompt'),
      {
        confirmButtonText: t('sorter.yes'),
        cancelButtonText: t('sorter.cancel'),
        type: 'warning',
      }
    );
    if (confirmResult === 'confirm') {
      const response = await request.post("/unLoadGlass/downGlassTask/generateOutGlassTask", {
        glassId: row.glass_id
      })
      if (response.code === 200) {
        ElMessage.success(response.message);
      } else {
        ElMessage.error(response.message);
      }
    }
  }
  catch (error) {
    console.error('发生错误:', error);
  }
};
const toggleEnableState = async (row) => {
  const newState = row.enable_state === 1 ? 0 : 1;
  const response = await request.post('/unLoadGlass/downStorage/updateDownStorageCage', { id: row.id, enableState: newState });
  if (response.code === 200) {
    ElMessage.success(response.message);
  } else {
    ElMessage.error(response.message);
  }
  row.enable_state = newState;
};
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/unLoadGlass/api/talk/downcache`;
const socketUrl = `ws://${WebSocketHost}:${host}/api/cacheGlass/api/talk/cacheGlassTwo`;
const handleMessage = (data) => {
  tableData.splice(0, tableData.length, ...data.params2[0]);
  adjustedRects.value = data.params2[0].map(rect => ({
    ...rect,
    width: rect.width * 0.5,
    id: rect.id * 10,
  }));
  const cageInfo = data.taskMessage[0];
  if (cageInfo && cageInfo.createTime) {
    cageInfo.formattedCreateTime = formatTimestamp(cageInfo.createTime);
  }
  if (cageInfo && cageInfo.updateTime) {
    cageInfo.formattedupdateTime = formatTimestamp(cageInfo.updateTime);
  }
  tableDataa.value = data.EdgStorageCageinfos[0]
  tableDatab.value = data.taskMessage
  // adjustedRects.value = data.EdgStorageCageinfos[0].map(rect => ({
  //     ...rect,
  //     width: rect.width * 0.5 ,
  //     id: rect.id * 10,
  //   }));
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  socket = initializeWebSocket(socketUrl, handleMessage);
});
onUnmounted(() => {
  if (socket) {
    closeWebSocket(socket);
function getStatusTypea(taskRunning) {
  switch (taskRunning) {
    case 0:
      return 'info';
    case 1:
      return 'success';
    case 2:
      return 'success';
    case 3:
      return 'success';
    case 4:
      return 'success';
    case 5:
      return 'danger';
    case 6:
      return 'info';
  }
});
}
function getStatusTexta(taskRunning) {
  switch (taskRunning) {
    case 0:
      return t('sorter.emptymissions');
    case 1:
      return t('sorter.advancetask');
    case 2:
      return t('sorter.outputtasks');
    case 3:
      return t('sorter.straighttasks');
    case 4:
      return t('searchOrder.infilm');
    case 5:
      return t('sorter.endingtask');
    case 6:
      return t('sorter.another');
  }
}
function getStatusTypeb(taskState) {
  switch (taskState) {
    case 0:
      return 'info';
    case 1:
      return 'success';
    case 2:
      return 'success';
    case 3:
      return 'success';
    case 4:
      return 'success';
    case 5:
      return 'danger';
    case 6:
      return 'info';
  }
}
function getStatusTextb(taskState) {
  switch (taskState) {
    case 0:
      return t('sorter.emptymissions');
    case 1:
      return t('sorter.advancetask');
    case 2:
      return t('sorter.outputtasks');
    case 3:
      return t('sorter.straighttasks');
    case 4:
      return t('searchOrder.infilm');
    case 5:
      return t('sorter.endingtask');
    case 6:
      return t('sorter.another');
  }
}
// 格式化时间戳为年月日时间字符串的函数
function formatTimestamp(timestamp) {
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并补零
  const day = String(date.getDate()).padStart(2, '0'); // 补零
  const hours = String(date.getHours()).padStart(2, '0'); // 补零(如果需要显示时间)
  const minutes = String(date.getMinutes()).padStart(2, '0'); // 补零(如果需要显示时间)
  const seconds = String(date.getSeconds()).padStart(2, '0'); // 补零(如果需要显示时间)
  // 只显示年月日,如果需要显示时间,则拼接 hours + ':' + minutes + ':' + seconds
  return `${year}-${month}-${day}`;
}
  onUnmounted(() => {
    if (socket) {
    closeWebSocket(socket);
    }
    });
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
</script>
<template>
  <div style="height: 500px;">
    <el-card style="flex: 1;margin-left: 10px;margin-top: 20px;" v-loading="loading">
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;">
        <el-table height="300" ref="table"
        @selection-change="handleSelectionChange"
        :data="tableDataa" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
          <el-table-column prop="id" align="center" :label="$t('sorter.id')" min-width="80" />
          <el-table-column prop="deviceId" align="center" :label="$t('searchOrder.tid')" min-width="80" />
          <el-table-column prop="slot" align="center" :label="$t('sorter.gridnumber')" min-width="80" />
          <el-table-column
            align="center"
            :label="$t('sorter.startstatus')"
            min-width="80"
            prop="enableState"
          >
          <template #default="scope">
            <el-tag
              :type="scope.row.enableState === 1 ? 'success' : 'warning'"
            >
              {{ scope.row.enableState === 1 ? $t('sorter.start') : $t('sorter.disable') }}
            </el-tag>
          </template>
      </el-table-column>
          <el-table-column prop="remainWidth" align="center" :label="$t('sorter.remainWidth')" min-width="80" />
        </el-table>
      </div>
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;margin-top: 15px;">
        <el-table height="90" ref="table"
        @selection-change="handleSelectionChange"
        :data="tableDatab" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
          <el-table-column prop="glassIdOut" align="center" :label="$t('searchOrder.outputglassID')" min-width="80" />
          <el-table-column prop="currentCell" align="center" :label="$t('sorter.layernow')" min-width="80" />
          <el-table-column prop="startCell" align="center" :label="$t('processCard.layer')" min-width="120" />
          <el-table-column
            align="center"
            :label="$t('sorter.place')"
            min-width="80"
            prop="inPlace"
          >
          <template #default="scope">
            <el-tag
              :type="scope.row.inPlace === 1 ? 'success' : 'warning'"
            >
              {{ scope.row.inPlace === 1 ? $t('sorter.inPlace') : $t('sorter.ninPlace') }}
            </el-tag>
          </template>
      </el-table-column>
          <el-table-column
            align="center"
            :label="$t('sorter.taskRunning')"
            min-width="80"
            prop="taskRunning"
          >
          <template #default="scope">
        <el-tag :type="getStatusTypea(scope.row.taskRunning)">
          {{ getStatusTexta(scope.row.taskRunning) }}
        </el-tag>
      </template>
          </el-table-column>
          <el-table-column
            align="center"
            :label="$t('film.taskstatus')"
            min-width="80"
            prop="taskState"
          >
          <template #default="scope">
        <el-tag :type="getStatusTypeb(scope.row.taskState)">
          {{ getStatusTextb(scope.row.taskState) }}
        </el-tag>
      </template>
          </el-table-column>
          <el-table-column prop="formattedCreateTime" align="center" :label="$t('film.createtime')" min-width="120" />
          <el-table-column prop="formattedupdateTime" align="center" :label="$t('sorter.updateTime')" min-width="120" />
        </el-table>
      </div>
    </el-card>
  <div class="awatch">
    <img src="../../assets/woshihuancun.png" alt="" style="width: 50%;height: 70%;margin-left: 30%;margin-top: 20px;position: relative;">
    <div style="position: relative; width: 500px;height: 95px;margin-top: -165px;margin-left: 450px;">
    <div
      v-for="(rect, index) in adjustedRects"
      :key="rect"
      :style="{ position: 'absolute',
       top: `${rect.id}px`, left: `10px`, width: `${rect.width}px`, height: `5px`,
      backgroundColor: '#409EFF'
       }"
    >
  </div>
  </div>
</div>
</div>
</template>
<style scoped>
#dt {
  display: block;
  float: left;
  line-height: 20px;
  margin-left: 100px;
}
#dta {
  display: block;
  float: left;
  line-height: 20px;
  margin-left: 80%;
}
#dialog-footer {
#dt { display:block; float:left;line-height: 20px;margin-left: 100px;}
#dta { display:block; float:left;line-height: 20px;margin-left: 80%;}
#dialog-footer{
  text-align: center;
  margin-top: -15px;
}
#message {
#message{
  text-align: center;
  align-items: center;
  color: black;
  width: 200px;
  height: 100px;
  background-color: #337ecc;
  margin-left: 28%;
   width: 200px;
   height: 100px;
   background-color: #337ecc;
   margin-left: 28%;
}
.awatch {
.awatch{
  height: 460px;
  width: 1500px;
  max-width: 100%;
  /* margin-top: -60px; */
}
</style>
</style>