import {controlPageList} from "@/enum/index.js";
import {ElMessage} from "element-plus";
import router from "@/router";

export const intoControlPage = (path, params) => {
    if (!controlPageList.includes(path)) {
        ElMessage.warning('该页面不在控制台页面中，无法打开');
        return
    }
    // const fullPath = `${window.location.origin}${path}/${params}`;
    // // 使用 window.open 在新标签页中打开
    // window.open(fullPath, '_blank');
    const fullPath = `${path}/${params}`; // 构造路由路径
    router.push(fullPath); // 使用路由跳转
}

// 定义需要转换的属性列表
const propertiesToConvert = [
    "workModule",
    "posStep",
    "postureStep",
    "jointStep",
    "joint1",
    "joint2",
    "joint3",
    "joint4",
    "joint5",
    "joint6",
    "x",
    "y",
    "z",
    "rx",
    "ry",
    "rz"
];
export const formatNumber = (data) => {
    const res = JSON.parse(JSON.stringify(data));
// 遍历属性列表并转换值
    propertiesToConvert.forEach(property => {
        if (data[property] !== null) {
            res[property] = Number(data[property]);
        }
    });
    return res
}

//对象中存在数字类型属性时，转换为字符串类型
export const convertNumbersToStrings = (obj) => {
    for (const key in obj) {
        if (obj.hasOwnProperty(key)) {
            const value = obj[key];
            // 检查值是否不是 null 且是数字类型
            if (value !== null && typeof value === 'number') {
                obj[key] = String(value); // 转换为字符串
            }
        }
    }
    return obj;
}
