解决前端模拟计算,数据丢失问题,解决前端调整界面,掰片与优化结果不匹配问题
3个文件已修改
139 ■■■■ 已修改文件
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/GlassComputed.vue 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/Compute.vue 102 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/GlassComputed.vue
@@ -58,7 +58,7 @@
// 用于存储从后端获取到的数据,初始化为空数组
const receivedData = ref([]);
const emit = defineEmits(['update:project']);
const fetchProjectInfo = async (projectNumber) => {
  try {
    const res = await request.post(`/glassOptimize/getProjectByProjectNo/${projectNumber}`);
@@ -67,10 +67,21 @@
    if (Number(res.code) === 200 && res.data && res.data.data && res.data.data.length > 0) {
      // 正确访问嵌套的数据结构
      const projectData = res.data.data[0]; // 注意这里是 res.data.data[0]
      const updatedProject = {
        ...props.project,
        glass_thickness: projectData.glass_thickness || '',
        glass_type: projectData.glass_type || ''
      };
      console.log('获取到的glass_thickness:', projectData.glass_thickness);
      console.log('获取到的glass_type:', projectData.glass_type);
      // // 通过 emit 更新 project
      emit('update:project', updatedProject);
      // 更新 computed.value
      computed.value = {
        ...computed.value,
        glass_thickness: projectData.glass_thickness,
        glass_type: projectData.glass_type
      };
      // 确保computed.value已初始化
      if (!computed.value) {
        computed.value = {};
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/Compute.vue
@@ -145,6 +145,12 @@
  await firstLoading()
})
onMounted(async () => {
  if (props.project && props.project.projectNumber) {
    await fetchProjectData(props.project.projectNumber);
  }
});
const firstLoading = async() => {
    request.post(`/glassOptimize/selectOptimizeParms/${username}`).then((res) => {
      if (res.code == "200") {
@@ -182,7 +188,11 @@
  }
})
const inputValues = {
// let emit = defineEmits(['fetch-data']);
const emit = defineEmits(['fetch-data', 'sendData', 'simulate-click']);
const inputValues =  reactive({
  project_no:inputValue.value,
  glass_thickness:"",
  glass_type:"",
@@ -202,30 +212,86 @@
  rotate_mode:0,
  polys_allow_rotate: 0,
  process_cards:[]
});
const fetchProjectData = async (projectNumber) => {
  try {
    const res = await request.post(`/glassOptimize/getProjectByProjectNo/${projectNumber}`);
    if (Number(res.code) === 200 && res.data && res.data.data && res.data.data.length > 0) {
      const projectData = res.data.data[0];
      // 更新 inputValues
      inputValues.glass_thickness = projectData.glass_thickness || '';
      inputValues.glass_type = projectData.glass_type || '';
      console.log('更新后的 inputValues:', inputValues);
    } else {
      ElMessage.warning('未找到项目信息或数据格式不正确');
    }
  } catch (error) {
    console.error('请求失败:', error);
    ElMessage.error('获取项目信息失败');
  }
};
// let emit = defineEmits(['fetch-data']);
let emit = defineEmits(['fetch-data', 'sendData'])
const handleSearchClick = () => {
  // 通过 $emit 触发自定义事件,将工程号传递给父组件,由父组件去调用接口获取数据
  emit('fetch-data', inputValue.value);
  const projectNumber = inputValue.value;
  if (!projectNumber) {
    ElMessage.warning('请输入工程号');
    return;
  }
  // 通知父组件更新(可选)
  emit('fetch-data', projectNumber);
  // 子组件自己调用接口更新数据
  fetchProjectData(projectNumber);
};
const handleSimulationClick = () => {
      inputValues.project_no = inputValue.value;
      inputValues.glass_thickness =  props.project.glass_thickness ;
      inputValues.glass_type = props.project.glass_type;
const handleSimulationClick = () => {
  inputValues.project_no = inputValue.value;
  inputValues.chaos_pct = optionVal.value * 0.01; // 混排等级
  inputValues.cage_free = percentage2.value * 0.01; // 理片龙空闲度
  inputValues.heat_mode = 0; // 模式选择(默认值)
  inputValues.max_load_pct = percentage1.value * 0.01; // 最大装载率
  inputValues.max_area = 0; // 最大面积(默认值)
  inputValues.max_qty = 0; // 最大片数(默认值)
  inputValues.load_width = furnaceWidth.value;
  inputValues.load_length = furnaceLength.value;
  inputValues.x_space = spacingWidth.value;
  inputValues.y_space = spacingLong.value;
  inputValues.polys_allow_rotate = parseInt(rotateMode.value.value);
      inputValues.tempering_time = heatingTime.value || inputValues.tempering_time || 0;
      inputValues.load_width = furnaceWidth.value
      inputValues.load_length = furnaceLength.value
      inputValues.x_space = spacingWidth.value
      inputValues.y_space = spacingLong.value
      inputValues.polys_allow_rotate = parseInt(rotateMode.value.value)
  const sendData = {
    project_no: inputValues.project_no,
    glass_thickness: inputValues.glass_thickness,
    glass_type: inputValues.glass_type,
    chaos_pct: inputValues.chaos_pct, // 混排等级
    cage_free: inputValues.cage_free, // 理片龙空闲度
    tempering_time: inputValues.tempering_time,
    heat_mode: inputValues.heat_mode, // 模式选择
    max_load_pct: inputValues.max_load_pct, // 最大装载率
    max_area: inputValues.max_area, // 最大面积
    max_qty: inputValues.max_qty, // 最大片数
    load_width: inputValues.load_width,
    load_length: inputValues.load_length,
    x_space: inputValues.x_space,
    y_space: inputValues.y_space,
    load_rate: inputValues.load_rate, // 装载率(可能为空)
    furnaces_qty: inputValues.furnaces_qty, // 炉子数量(可能为空)
    rotate_mode: inputValues.rotate_mode, // 钢化旋转模式(可能为空)
    polys_allow_rotate: inputValues.polys_allow_rotate,
    process_cards: inputValues.process_cards || [] // 流程卡列表(默认空数组)
  };
  emit('sendData', sendData);
  emit('simulate-click');
      inputValues.project_no = inputValue.value;
  emit('sendData', {
    ...inputValues
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
@@ -332,7 +332,7 @@
  return {
    position: 'absolute',
    left: `${glassDetail.x * scale}px`,
    top: `${glassDetail.y * scale}px`,
    bottom: `${glassDetail.y * scale}px`,
    width: `${glassDetail.width * scale}px`,
    height: `${glassDetail.height * scale}px`,
    backgroundColor: glassDetail.isRemain ? '#f0f0f0' : themeColor.value,
@@ -563,7 +563,7 @@
  const newRect = { ...glassDetail };
  newRect.x += deltaX / scale;
  newRect.y += deltaY / scale;
  newRect.y -= deltaY / scale;
  const otherRects = layout.glassDetails.filter(r => !r.isRemain && r !== glassDetail);
  let isValidMove = true;
@@ -620,19 +620,19 @@
  const threshold = Math.max(glassDetail.width, glassDetail.height) * 0.1;
  otherRects.forEach(otherRect => {
    // 水平对齐
    // 水平对齐保持不变
    if (Math.abs(glassDetail.x - otherRect.x) < threshold) {
      glassDetail.x = Math.round((glassDetail.x + otherRect.x) / 2);
    }
    // 水平对齐右侧边缘
    // 水平对齐右侧边缘保持不变
    if (Math.abs((glassDetail.x + glassDetail.width) - (otherRect.x + otherRect.width)) < threshold) {
      glassDetail.x = Math.round((otherRect.x + otherRect.width - glassDetail.width));
    }
    // 垂直对齐
    // 垂直对齐需要调整(基于左下角坐标系)
    if (Math.abs(glassDetail.y - otherRect.y) < threshold) {
      glassDetail.y = Math.round((glassDetail.y + otherRect.y) / 2);
    }
    // 垂直对齐下边缘
    // 垂直对齐上边缘(基于左下角坐标系)
    if (Math.abs((glassDetail.y + glassDetail.height) - (otherRect.y + otherRect.height)) < threshold) {
      glassDetail.y = Math.round((otherRect.y + otherRect.height - glassDetail.height));
    }
@@ -829,10 +829,10 @@
  switch (direction) {
    case 'up':
      glassDetail.y += maxStep;
      glassDetail.y -= maxStep;
      break;
    case 'down':
      glassDetail.y -= maxStep;
      glassDetail.y += maxStep;
      break;
    case 'left':
      glassDetail.x -= maxStep;
@@ -962,7 +962,7 @@
//向上移动计算坐标
const getAvailableSpaceUp = (glassDetail, layout, obstacles) => {
  let maxSpace = layout.height - (glassDetail.y + glassDetail.height);
  let maxSpace = glassDetail.y;
  obstacles.forEach(obstacle => {
    if (obstacle.y > glassDetail.y + glassDetail.height &&
        obstacle.x <= glassDetail.x + glassDetail.width &&
@@ -975,7 +975,7 @@
//向下移动计算坐标
const getAvailableSpaceDown = (glassDetail, layout, obstacles) => {
  let maxSpace = glassDetail.y;
  let maxSpace = layout.height - (glassDetail.y + glassDetail.height);;
  obstacles.forEach(obstacle => {
    if (obstacle.y + obstacle.height < glassDetail.y &&
        obstacle.x <= glassDetail.x + glassDetail.width &&