wu
5 天以前 7c0f20e25e870e055f88952f9ec57677730eda67
UI-Project/src/views/StockBasicData/stockBasicData.vue
@@ -1,146 +1,389 @@
<script setup>
import {Search} from "@element-plus/icons-vue";
import {reactive} from "vue";
import {onBeforeUnmount, onMounted, onUnmounted, reactive, ref} from "vue";
import {useRouter} from "vue-router"
import request from "@/utils/request"
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
import {ElMessage, ElMessageBox} from 'element-plus'
import {useI18n} from 'vue-i18n'
const router = useRouter()
const adda = ref(false)
import request from "@/utils/request"
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'
const {t} = useI18n()
let language = ref(localStorage.getItem('lang') || 'zh')
const tableData = ref([])
const blindb = ref(false)
const slot = ref('')
const requestData = {
  line: 2001
};
request.post("/cacheGlass/taskCache/selectEdgTask",{
  ...requestData,
}).then((res) => {
          if (res.code == 200) {
          console.log(res.data);
          tableData.value = res.data
          console.log(res.data[0].slot);
          } else {
          ElMessage.warning(res.msg)
          }
          });
const requestData = {
  line: 2001
};
const timeRange = ref([])
const selectValuesa = reactive([]);
// 磨边任务查询
const setEdgGlassInfoRequest = async () => {
  let celllist=[]
  let stateList=[]
  if(selectValuesa[0]!=null&&selectValuesa[0]!='undefined'){
    if(selectValuesa[0]!=""){
      celllist=[selectValuesa[0]];
    }
  }
  if(selectValuesa[1]!=null&&selectValuesa[1]!='undefined'){
    if(selectValuesa[1]!=""){
      stateList=[selectValuesa[1]];
    }
  }
  const response = await request.post("/cacheGlass/edgGlassTaskInfo/setEdgGlassInfoRequest", {
    cellList: celllist,
    stateList: stateList,
    beginDate: timeRange.value[0],
    endDate: timeRange.value[1],
  })
  if (response.code === 200) {
    ElMessage.success(response.message);
  } else {
    ElMessage.error(response.message);
  }
}
// 破损
 const open = async(row) => {
  try {
 const open = async(row) => {
  try {
    const confirmResult = await ElMessageBox.confirm(  
      '是否破损该条信息?',
      '提示',
      t('workOrder.messagedamaged'),
      t('workOrder.prompt'),
      {  
        confirmButtonText: '是',
        cancelButtonText: '取消',
        confirmButtonText: t('workOrder.yes'),
        cancelButtonText: t('workOrder.cancel'),
        type: 'warning',  
      }
    );
    if (confirmResult === 'confirm') {
      // 用户点击了“是”,现在调用删除接口
      }
    );
    if (confirmResult === 'confirm') {
      const response = await request.post("/cacheGlass/edgStorageCage/edgReportStatus", {
        glassId: row.GlassId,
        controlsId: 300
        glassId: row.glassId,
        state: 8,
        line: row.line,
        workingProcedure: '磨边',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {
        // 删除失败,您可以处理错误或显示错误信息给用户
      } else {
      ElMessage.error(response.msg);
        // alert('删除失败:' + deleteResponse.message);
      }  
    }  
  } catch (error) {
    // 处理可能出现的错误,比如 ElMessageBox 抛出的异常等
    console.error('发生错误:', error);
  } catch (error) {
  }  
};  
// 拿走 
 const opena = async(row) => {  
  try {
  try {
    const confirmResult = await ElMessageBox.confirm(  
      '是否拿走该条信息?',
      '提示',
      t('workOrder.takemessage'),
      t('workOrder.prompt'),
      {  
        confirmButtonText: '是',
        cancelButtonText: '取消',
        confirmButtonText: t('workOrder.yes'),
        cancelButtonText: t('workOrder.cancel'),
        type: 'warning',  
      }
    );
    if (confirmResult === 'confirm') {
      // 用户点击了“是”,现在调用删除接口
      }
    );
    if (confirmResult === 'confirm') {
      const response = await request.post("/cacheGlass/edgStorageCage/edgReportStatus", {
        glassId: row.GlassId,
        controlsId: 301
        glassId: row.glassId,
        state: 9,
        line: row.line,
        workingProcedure: '磨边',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {
        // 删除失败,您可以处理错误或显示错误信息给用户
      } else {
      ElMessage.error(response.msg);
        // alert('删除失败:' + deleteResponse.message);
      }  
    }  
  } catch (error) {
    // 处理可能出现的错误,比如 ElMessageBox 抛出的异常等
    console.error('发生错误:', error);
  } catch (error) {
  }  
};   
const socketUrl = `ws://10.153.19.150:88/api/cacheGlass/api/talk/cacheGlass`;
// 定义消息处理函数,更新 receivedData 变量
let socket = null;
const socketUrl = `ws://${window.ipConfig.serverUrl}/api/cacheGlass/api/talk/edgTasks`;
const handleMessage = (data) => {
  // 更新 tableData 的数据
  tableData.value = data.EdgTasks1[0]
  const formattedTasks = data.edgTasks[0].map(cageInfo => {
    if (cageInfo && cageInfo.createTime) {
      cageInfo.formattedCreateTime = formatTimestamp(cageInfo.createTime);
    }
    return cageInfo;
  });
  tableData.value = formattedTasks
};
// 初始化 WebSocket,并传递消息处理函数
//  模拟数据
// const generateMockData = () => {
//   const mockList = [
//     {
//       glassId: 'GL251209001',
//       width: 520,
//       height: 310,
//       thickness: 10,
//       filmsid: '钢化玻璃',
//       line: 1,
//       state: 2, // 未磨边
//       createTime: Date.now() - 3600 * 1000 * 2, // 2小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 2)
//     },
//     {
//       glassId: 'GL251209002',
//       width: 600,
//       height: 380,
//       thickness: 12,
//       filmsid: '浮法玻璃',
//       line: 2,
//       state: 1, // 磨边中
//       createTime: Date.now() - 3600 * 1000 * 1, // 1小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 1)
//     },
//     {
//       glassId: 'GL251209003',
//       width: 480,
//       height: 290,
//       thickness: 8,
//       filmsid: '夹胶玻璃',
//       line: 1,
//       state: 1, // 已磨边
//       createTime: Date.now() - 3600 * 1000 * 6, // 6小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 6)
//     },
//     {
//       glassId: 'GL251209004',
//       width: 550,
//       height: 330,
//       thickness: 9,
//       filmsid: '中空玻璃',
//       line: 2,
//       state: 0,
//       createTime: Date.now() - 3600 * 1000 * 3,
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 3)
//     },
//     {
//       glassId: 'GL251209005',
//       width: 580,
//       height: 350,
//       thickness: 11,
//       filmsid: '防弹玻璃',
//       line: '1',
//       state: 0,
//       createTime: Date.now() - 3600 * 1000 * 4,
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 4)
//     }
//   ];
//   return mockList;
// };
//   tableData.value = generateMockData();
//   ElMessage.success('模拟数据加载成功!');
// 历史任务
const iframeUrl = ref('');
const handlehistorical = (row) => {
  blindb.value = true;
  iframeUrl.value = `${window.location.origin}/#/StockBasicData/stockhistory`;
};
onMounted(() => {
  // fetchFlowCardId();
  // fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
  socket = initializeWebSocket(socketUrl, handleMessage);
});
  onUnmounted(() => {
    if (socket) {
      closeWebSocket(socket);
    }
  });
//   function getStatusTypeb(state) {
//   switch (state) {
//     case 0:
//       return 'info';
//     case 1:
//       return 'success';
//     case 1:
//       return 'danger';
//   }
// }
// 1. 辅助:获取行真实索引
function getRowRealIndex(row) {
  return tableData.value.findIndex(item => item.glassId === row.glassId);
}
// 2. 辅助:获取指定线路最新行状态
function getLineLatestState(line) {
  const targetLine = String(line || '').trim();
  if (!targetLine) return -1;
  for (const row of tableData.value) {
    const rowLine = String(row.line || '').trim();
    if (rowLine === targetLine) {
      return Number(row.state);
    }
  }
  return -1;
}
// 3. 核心判断:是否需要高亮/标红
function isNeedHighlight(row) {
  const currentState = Number(row.state);
  const currentLine = String(row.line || '').trim();
  if (!currentLine) return false;
  // 原有逻辑:未磨边 + 前序有磨边中/已磨边
  if (currentState === 0) {
    const currentIndex = getRowRealIndex(row);
    if (currentIndex === -1) return false;
    for (let i = 0; i < currentIndex; i++) {
      const compareRow = tableData.value[i];
      const compareLine = String(compareRow?.line || '').trim();
      const compareState = Number(compareRow?.state);
      if (compareLine === currentLine && [1, 2].includes(compareState)) {
        return true;
      }
    }
  }
  // 新增逻辑:磨边中 + 同线路最新是已磨边
  if (currentState === 1) {
    const latestState = getLineLatestState(currentLine);
    if (latestState === 2) {
      return true;
    }
  }
  return false;
}
// 4. 原始颜色映射
function getOriginalColor(state) {
  const stateNum = Number(state);
  switch (stateNum) {
    case 0: return 'info';
    case 1: return 'success';
    case 2: return 'primary';
    default: return 'info';
  }
}
// 5. 标签类型函数(调用isNeedHighlight)
function getStatusTypeb(row) {
  const currentState = Number(row.state);
  if ([0, 1].includes(currentState) && isNeedHighlight(row)) {
    return 'danger';
  }
  return getOriginalColor(row.state);
}
// 6. 行样式函数(调用isNeedHighlight)
function getTableRowClass({ row }) {
  const currentState = Number(row.state);
  if ([0, 1].includes(currentState) && isNeedHighlight(row)) {
    return 'leak-edge-highlight';
  }
  return '';
}
function getStatusTextb(state) {
  switch (state) {
    case 0:
      return t('workOrder.nedging');
    case 1:
      return t('workOrder.edging');
    case 2:
      return t('workOrder.finedging');
  }
}
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'); // 补零(如果需要显示时间)
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
</script>
<template>
  <div>
    <el-card style="flex: 1;margin-left: 10px;margin-top: 20px;" v-loading="loading">
  <div style="height: 500px;">
    <div>
      <el-card style="flex: 1;margin-left: 10px;margin-top: 20px;" >
        <div style="display: flex;">
        <!-- <el-button style="margin-left: 20px;" id="searchButton" type="success" @click="handlehistorical">{{
          $t('searchOrder.historicaltasks')
        }}
      </el-button> -->
        <el-select v-model="selectValuesa[0]" filterable :placeholder="$t('workOrder.cway')" clearable
                   style="margin-left: 20px;margin-bottom: 10px;">
          <el-option :label="$t('workOrder.edgingone')" value="930"></el-option>
          <el-option :label="$t('workOrder.edgingtwo')" value="931"></el-option>
        </el-select>
        <el-select v-model="selectValuesa[1]" filterable :placeholder="$t('workOrder.cstate')" clearable
                   style="margin-left: 20px;margin-bottom: 10px;">
          <el-option :label="$t('workOrder.nedging')" value="0"></el-option>
          <el-option :label="$t('workOrder.edging')" value="1"></el-option>
          <el-option :label="$t('workOrder.finedging')" value="2"></el-option>
          </el-select>
          <span class="demonstration" style="margin-left: 20px;margin-top: 3px;">{{ $t('workOrder.time') }}</span>
            <el-date-picker v-model="timeRange" type="datetimerange" range-separator="至" :start-placeholder="$t('reportmanage.starttime')"  style="margin-left: 15px;" value-format = "YYYY-MM-DD hh:mm:ss"
              :end-placeholder="$t('reportmanage.endtime')">
            </el-date-picker>
          <el-button type="primary" style="margin-left: 10px;margin-bottom: 10px;" @click="setEdgGlassInfoRequest()">{{
        $t('reportmanage.inquire')
      }}</el-button>
      </div>
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;">
        <el-table height="240" ref="table"
        <el-table height="750" ref="table"
        @selection-change="handleSelectionChange"
        :data="tableData" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
          <el-table-column prop="GlassId" align="center" label="玻璃id" min-width="180" />
          <el-table-column prop="Height" align="center" label="高" min-width="80" />
          <el-table-column prop="Width" align="center" label="宽" min-width="120" />
          <el-table-column prop="Thickness" align="center" label="厚度" min-width="120" />
          <el-table-column prop="FilmsId" align="center" label="膜系" min-width="120" />
          <el-table-column prop="SerialNumber" align="center" label="出片顺序" min-width="120" />
          <el-table-column prop="FlowCardId" align="center" label="流程卡号" min-width="120" />
          <el-table-column fixed="right" label="操作" align="center" width="200">
            <template #default="scope">
              <el-button size="mini" type="text" plain @click="open(scope.row)">破损</el-button>
              <el-button size="mini" type="text" plain @click="opena(scope.row)">拿走</el-button>
            </template>
        :data="tableData" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}"
        :row-class-name="getTableRowClass"
        >
        <el-table-column prop="glassId" align="center" :label="$t('workOrder.glassID')" min-width="180" />
          <el-table-column prop="width" align="center" :label="$t('workOrder.width')" min-width="120" />
          <el-table-column prop="height" align="center" :label="$t('workOrder.height')" min-width="80" />
          <el-table-column prop="thickness" align="center" :label="$t('workOrder.thickness')" min-width="120" />
          <el-table-column prop="filmsid" align="center" :label="$t('workOrder.glasstype')" min-width="120" />
          <el-table-column prop="line" align="center" :label="$t('workOrder.line')" min-width="120" />
          <el-table-column prop="formattedCreateTime" align="center" :label="$t('workOrder.time')" min-width="120" />
          <el-table-column prop="state" :label="$t('workOrder.status')" align="center" width="200">
            <!-- <template #default="scope">
              {{ scope.row.status==0?"未磨边":scope.row.status==1?"磨边中":"已磨边" }}
            </template> -->
            <template #default="scope">
          <el-tag :type="getStatusTypeb(scope.row || {}, scope.index)">
          {{ getStatusTextb(scope.row.state) }}
        </el-tag>
        <!-- <el-tag :type="getStatusTypeb(scope.row.state)">
          {{ getStatusTextb(scope.row.state) }}
        </el-tag>   -->
      </template>
        </el-table-column>
          <el-table-column fixed="right" :label="$t('workOrder.operate')" align="center" width="200">
            <template #default="scope">
              <el-button type="text" plain @click="open(scope.row)">{{
                  $t('workOrder.breakage')
                }}
              </el-button>
              <el-button type="text" plain @click="opena(scope.row)">{{
                  $t('workOrder.takeout')
                }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
      </el-card>
    </div>
  <!-- 历史任务 -->
<el-dialog v-model="blindb" top="10vh" width="95%" @close="iframeUrl=''">
     <iframe
     :src="iframeUrl"
     marginwidth="2000px"
     marginheight="2000px"
     width="100%"
     height="700px"
     frameborder="0"
     ></iframe>
  </el-dialog>
  </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{
@@ -160,4 +403,17 @@
  height: 460px;
  /* margin-top: -60px; */
}
/* 漏磨边行整行高亮样式(穿透scoped) */
:deep(.leak-edge-highlight) {
  background-color: #fff1f0 !important; /* 浅红背景(和danger标签呼应) */
}
/* 行内单元格文字标红 */
:deep(.leak-edge-highlight > td) {
  color: #f5222d !important; /* 红色文字 */
  font-weight: 500 !important; /* 可选:文字加粗,更醒目 */
}
/* 鼠标悬浮时保持高亮(可选) */
:deep(.el-table__row.leak-edge-highlight:hover > td) {
  background-color: #fee2e2 !important;
}
</style>