ZengTao
2024-08-05 fcb40e1279647faa25a27cc2977eea79c17012fc
UI-Project/src/views/UnLoadGlass/loadmachinerack.vue
@@ -1,6 +1,6 @@
<script setup>
import {Search} from "@element-plus/icons-vue";
import {reactive, onMounted, onBeforeUnmount} from "vue";
import {reactive, onMounted, onBeforeUnmount,onUnmounted} from "vue";
import {useRouter} from "vue-router"
const router = useRouter()
import { useI18n } from 'vue-i18n'
@@ -15,6 +15,7 @@
import { WebSocketHost ,host} from '@/utils/constants'
const dialogFormVisiblea = ref(false)
const dialogFormVisiblea2 = ref(false)
const dialogFormVisibleaDownGlass = ref(false)
// 数据
const loading = ref(false);
// 弹框显示控制
@@ -25,6 +26,7 @@
const flowCardId = ref('');
const flowCardOptions = ref('[]');
const tableData = reactive([]);
const downGlass= reactive([]);
// 方法
const handleSelectionChange = () => {
  // 处理表格行选择事件
@@ -106,7 +108,7 @@
            console.log('清除成功');
            ElMessage.success(response.message);
            dialogFormVisiblea2.value = false;
        } else if (response.code === 400) {
        } else if (response.code === 500) {
            // 清除失败的逻辑
            console.log('清除失败');
            console.log(response.message); // 打印服务器返回的错误信息
@@ -139,23 +141,70 @@
    ElMessage.error('获取表格数据失败,请重试');
  }
};
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/unLoadGlass/api/talk/unloadglass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  downGlass.value=data.sendDownGlass[0];
  tableData.splice(0, tableData.length, ...data.params[0]);
//  console.log("更新后数据", data.params[0]);
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  fetchFlowCardId();
  fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
  socket = initializeWebSocket(socketUrl, handleMessage);
});
  onUnmounted(() => {
    if (socket) {
    closeWebSocket(socket);
    }
    });
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
const getTagType =(status) => {
      return status === 1 ? 'success' : 'danger';
      // 根据状态值决定标签类型,这里假设状态为1时为成功(绿色),否则为失败(红色)
    }
    const toggleStatus = (row) => {
      // 切换料架状态的逻辑
      row.enableState = 1 - row.enableState; // Toggle between 0 and 1
      // 此处可以添加保存状态的逻辑,比如调用 API 更新数据
      updateRowStatus(row);
    };
    const updateRowStatus = async (row) => {
  try {
    // 假设你的后端 API 接收 PUT 请求,并且需要传递 row.id 和 row.enableState 参数
    const response = await request.post('unLoadGlass/downWorkStation/updateDownWorkstation', {
      enableState: row.enableState,
      id: row.id
    });
    console.log('Updated row status:', response.data);
    // 可以根据后端返回的数据进行进一步处理,比如更新本地状态等
  } catch (error) {
    console.error('Error updating row status:', error);
    // 处理错误情况,比如提示用户更新失败
  }
};
// beforeUnmount(() => {
//   closeWebSocket();
// });
@@ -185,7 +234,10 @@
            prop="enableState"
          >
          <template #default="scope">
            <el-tag type="success" >{{ scope.row.enableState==1? $t('reportWork.enable') : $t('reportWork.unenable')}}</el-tag>
            <el-tag :type="getTagType(scope.row.enableState)" @click="toggleStatus(scope.row)">
          {{ scope.row.enableState === 1 ? $t('reportWork.enable') : $t('reportWork.unenable') }}
        </el-tag>
          </template>
          </el-table-column>
          <el-table-column fixed="right" :label="$t('reportWork.operate')" align="center" width="200">
@@ -196,6 +248,24 @@
        </el-table-column>
        </el-table>
      </div>
      <el-dialog v-model="dialogFormVisibleaDownGlass" top="2vh" width="97%" :title="$t('searchOrder.cageinformation')">
        <el-table height="200px" ref="table"
        @selection-change="handleSelectionChange"
        :data="downGlass" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
          <el-table-column prop="flowCardId" align="center" :label="$t('flowCardId')" min-width="80" />
          <el-table-column prop="layer" align="center" :label="$t('layer')" min-width="120" />
          <el-table-column prop="sequence" align="center" :label="$t('sequence')" min-width="150" />
          <el-table-column prop="width" align="center" :label="$t('width')" min-width="120" />
          <el-table-column prop="height" align="center" :label="$t('height')" min-width="120" />
          <el-table-column prop="thickness" align="center" label="thickness" min-width="120" />
          <el-table-column prop="otherNumber" align="center" label="人工下片数" min-width="120" />
          <!-- <el-table-column prop="work_state" align="center" :label="$t('reportWork.state')" min-width="120" /> -->
          <el-table-column prop="Filmsid" align="center" :label="$t('Filmsid')" min-width="120" />
          <el-table-column prop="glassId" align="center" :label="$t('glassId')" min-width="120" />
        </el-table>
      </el-dialog>
    </el-card>
    <!-- workstationId: '1',
    workstationId: '1005',