严智鑫
2024-04-19 1bd93d6d748edfda1b95b692f7d4ce4f38363e32
UI-Project/src/views/UnLoadGlass/loadmachinerack.vue
@@ -1,52 +1,209 @@
<script setup>
import {Search} from "@element-plus/icons-vue";
import {reactive} from "vue";
import {reactive,  onMounted} from "vue";
import {useRouter} from "vue-router"
const router = useRouter()
const dialogFormVisiblea = ref(false)
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import Landingindication from "./Landingindication.vue";
// import Landingindicationtwo from "./Landingindicationtwo.vue";
import Landingindicationtwo from "./Landingindicationtwo.vue";
import unloadrequest from "@/utils/unloadrequest";
const dialogFormVisiblea = ref(false)
const tableData = [
  {
    id: '1',
    long: '1005',
    wide: '183.6',
    thick: '1991',
    state: '未启用',
  },
  {
    id: '2',
    long: '105',
    wide: '183',
    thick: '191',
    state: '未启用'
  },
  {
    id: '3',
    long: '105',
    wide: '183',
    thick: '191',
    state: '未启用'
  },
  {
    id: '4',
    long: '105',
    wide: '183',
    thick: '191',
    state: '未启用'
  },
  {
    id: '5',
    long: '105',
    wide: '183',
    thick: '191',
    state: '未启用'
  },
]
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/unLoadGlass/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 handleSelectionChange = () => {
  // 处理表格行选择事件
};
const handleBindRack = (row) => {
  workstationId.value = row.workstationId; // 假设rackNumber是架号字段的属性名
  // 发起接口请求获取流程卡号
    fetchFlowCardId();
  dialogFormVisiblea.value = true; // 打开绑定架子对话框
};
//获取流程卡号
const fetchFlowCardId = async () => {
  try {
    const response = await unloadrequest.get('/api/unLoadGlass/getflowCardId');
    console.log(response)
    if (response.code === 200) {
      flowCardOptions.value = response.data.map(item => ({ flowcard_id: item.flowcard_id }));
    } else {
      ElMessage.error(response.msg);
    }
  } catch (error) {
    console.error(error);
  }
};
//确认
const handleConfirm = async () => {
  try {
    const response = await unloadrequest.post('/api/unLoadGlass/updateFlowCardId', {
      workstationId: workstationId.value,
      flowCardId: flowCardId.value
    });
    console.log(response)
    if (response.code == 200) {
      // 绑定成功,处理逻辑
      console.log('绑定成功');
      ElMessage.success(response.message);
      dialogFormVisiblea.value = false;
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.msg);
    }
  } catch (error) {
    // 处理错误
    console.error(error);
  }
};
const handleBindRack2 = (row) => {
  workstationId.value = row.workstationId; // 假设rackNumber是架号字段的属性名
  dialogFormVisiblea2.value = true; // 打开绑定架子对话框
};
//清除内容
const handleclear = async () => {
    try {
        const response = await unloadrequest.post('/api/unLoadGlass/clear', {
            workstationId: workstationId.value,
        });
        console.log(response);
        if (response.code === 200) {
            // 清除成功的逻辑
            console.log('清除成功');
            ElMessage.success(response.message);
            dialogFormVisiblea2.value = false;
        } else if (response.code === 400) {
            // 清除失败的逻辑
            console.log('清除失败');
            console.log(response.message); // 打印服务器返回的错误信息
            ElMessage.error(response.message);
            dialogFormVisiblea2.value = false;
        }
    } catch (error) {
        // console.log(error);
         ElMessage.error("清除失败");
            dialogFormVisiblea2.value = false;
    }
};
const tableData = reactive([]);
// 发送获取表格数据的请求
const fetchTableData = async () => {
  try {
    // 发送获取表格数据的请求,并等待响应
    const response = await unloadrequest.get('/api/unLoadGlass/getone');
    // 检查响应状态
    if (response.code === 200) {
      // 更新表格数据
      console.log('成功获取表格数据:', response.data);
      tableData.splice(0, tableData.length, ...response.data);
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.msg);
    }
  } catch (error) {
    // 处理请求失败的情况
    ElMessage.error('获取表格数据失败,请重试');
  }
};
initWebSocket();
onMounted(fetchTableData);
setInterval(fetchTableData, 2000)
const open = () => {
  ElMessageBox.confirm(
    '是否删除该条信息?',
@@ -84,17 +241,6 @@
  }
}
const dialogForm = () => {
  ElMessageBox.confirm(
    '是否清空该条信息?',
    '提示',
    {
      confirmButtonText: '是',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
}
const gridOptions = reactive({
  border:  "full",//表格加边框
  keepSource: true,//保持源数据
@@ -133,6 +279,10 @@
  ],
})
</script>
<template>
@@ -142,53 +292,80 @@
        <el-table height="100%" ref="table" 
        @selection-change="handleSelectionChange"
        :data="tableData" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
          <el-table-column prop="id" align="center" label="下片位" min-width="80" />
          <el-table-column prop="long" align="center" label="架号" min-width="120" />
          <el-table-column prop="wide" align="center" label="流程卡号" min-width="120" />
          <el-table-column prop="wide" align="center" label="总数量" min-width="120" />
          <el-table-column prop="wide" align="center" label="已落架数量" min-width="120" />
          <el-table-column prop="state" align="center" label="启用状态" min-width="120" />
          <el-table-column prop="workstationId" align="center" label="下片位" min-width="80" />
          <el-table-column prop="workstationId" align="center" label="架号" min-width="120" />
          <el-table-column prop="flowCardId" align="center" label="流程卡号" min-width="120" />
          <el-table-column prop="totalquantity" align="center" label="总数量" min-width="120" />
          <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 fixed="right" label="操作" align="center" width="200">
            <template #default>
              <el-button size="mini" type="text" plain v-show="state !== '已启用' " @click="dialogFormVisiblea = true">绑定架子</el-button>
              <el-button size="mini" type="text" plain   @click="dialogForm">清空</el-button>
            </template>
            <template #default="scope">
            <el-button size="mini" type="text" plain v-show="scope.row.enableState !== '已启用' " @click="handleBindRack(scope.row)">绑定架子</el-button>
            <el-button size="mini" type="text" plain  @click="handleBindRack2(scope.row)">清空</el-button>
          </template>
        </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
  <div style="display: flex;">
  <div id="main-body">
      <Landingindication></Landingindication>
    </div>
  <!-- <div id="main-body">
    <Landingindicationtwo></Landingindicationtwo>
    </div> -->
    </div>
    <el-dialog v-model="dialogFormVisiblea" top="21vh" width="30%" title="绑定架子" >
    <div style="margin-left: 50px;margin-top: 10px;margin-bottom: 10px;">
            <el-form  size="mini" label-width="150px">
      <el-form  label-width="100px" label-position="right">
              <el-form-item label="架号:" :required="true" style="width: 18vw">
                <el-input  autocomplete="off"/>
              </el-form-item>
              <el-form-item label="流程卡号:" :required="true" style="width: 18vw;">
                <el-input autocomplete="off" />
              </el-form-item>
        </el-form>
            </el-form>
          </div>
      <el-form  size="mini" label-width="150px">
        <el-form  label-width="100px" label-position="right">
          <el-form-item label="架号:" :required="true" style="width: 18vw">
            <el-input v-model="workstationId" autocomplete="off"/>
          </el-form-item>
          <el-form-item label="流程卡号:" :required="true" style="width: 18vw;">
          <el-select v-model="flowCardId" placeholder="请选择流程卡号">
            <el-option v-for="item in flowCardOptions" :key="item.flowcard_id" :label="item.flowcard_id" :value="item.flowcard_id" />
          </el-select>
        </el-form-item>
      </el-form>
      </el-form>
    </div>
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="dialogFormVisiblea = false">
        <el-button type="primary" @click="handleConfirm">
          确认
        </el-button>
        <el-button @click="dialogFormVisiblea = false">取消</el-button>
      </div>
    </template>
  </el-dialog>
  <el-dialog v-model="dialogFormVisiblea2" top="21vh" width="30%" title="清除架子玻璃" >
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="handleclear">
          确认
        </el-button>
        <el-button @click="dialogFormVisiblea2 = false">取消</el-button>
      </div>
    </template>
  </el-dialog>
    <!-- workstationId: '1',
    workstationId: '1005',
    flowCardId: '183.6',
    totalquantity: '1991',
    racksnumber:"1",
    work_state: '待识别', -->
  </div>
  <div style="display: flex;">
  <div id="main-body">
      <Landingindication></Landingindication>
    </div>
  <div id="main-bodya">
    <Landingindicationtwo></Landingindicationtwo>
    </div></div>
</template>
<style scoped>
@@ -212,7 +389,11 @@
  height: 450px;
}
#main-body{
  margin-top: -20px;
  margin-left: 300px;
}
#main-bodya{
  margin-top: -10px;
  margin-left: 450px;
  margin-left: 100px;
}
</style>