|
|
@@ -72,16 +72,9 @@ const GetAddr = async () => {
|
|
|
const macAddress = await fetchMACAddress();
|
|
|
console.log('GetAddr MAC 地址:', macAddress);
|
|
|
|
|
|
- // 获取机台号
|
|
|
- // await getMachineMaclist(macAddress);
|
|
|
-
|
|
|
const response = await getMachineMac({ sys_sbID: macAddress });
|
|
|
console.log("获取数据库列表:", response);
|
|
|
|
|
|
- // if (response.code === 7) {
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
if (!response.data) {
|
|
|
console.log("未能获取响应数据,请检查请求或网络连接。");
|
|
|
return;
|
|
|
@@ -94,12 +87,7 @@ const GetAddr = async () => {
|
|
|
Machine.value = 'CF01';
|
|
|
console.log("该电脑未绑定 MAC 地址");
|
|
|
}
|
|
|
-
|
|
|
- //默认值
|
|
|
- // if (!Machine.value) {
|
|
|
- // Machine.value = 'CF01';
|
|
|
- // console.warn("使用默认机台号 CF01");
|
|
|
- // }
|
|
|
+
|
|
|
let machineId = Machine.value;
|
|
|
console.log("当前默认机台号:", machineId);
|
|
|
|
|
|
@@ -255,6 +243,7 @@ const LoginIn = async(loginInfo) => {
|
|
|
})
|
|
|
try {
|
|
|
const res = await login(loginInfo)
|
|
|
+ console.log(res)
|
|
|
if (res.code === 0) {
|
|
|
setUserInfo(res.data.user)
|
|
|
setToken(res.data.token)
|
|
|
@@ -285,201 +274,6 @@ const LoginIn = async(loginInfo) => {
|
|
|
}
|
|
|
loadingInstance.value.close()
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// // 定义全局变量
|
|
|
-// const Machine = ref(''); // 机台号
|
|
|
-// const MAC = ref(''); // MAC地址
|
|
|
-
|
|
|
-// // 封装获取MAC地址的函数
|
|
|
-// const fetchMACAddress = async () => {
|
|
|
-// try {
|
|
|
-// const response = await fetch("http://127.0.0.1:8090/init");
|
|
|
-// console.log(response)
|
|
|
-// console.log(123)
|
|
|
-// console.log(response)
|
|
|
-// const res = await response.json();
|
|
|
-
|
|
|
-// if (res.macAddress) {
|
|
|
-// MAC.value = res.macAddress.match(/.{1,2}/g).join("-");
|
|
|
-// console.log('自动获取物理地址:', MAC.value);
|
|
|
-// return MAC.value;
|
|
|
-// } else {
|
|
|
-// console.log('无法获取MAC地址:', MAC.value);
|
|
|
-// throw new Error('无法获取MAC地址');
|
|
|
-// }
|
|
|
-// } catch (error) {
|
|
|
-// throw new Error('获取MAC地址失败:' + error.message);
|
|
|
-// }
|
|
|
-// };
|
|
|
-
|
|
|
-// // 获取机器MAC列表,并设置Machine.value
|
|
|
-// const getMachineMaclist = async (macAddress) => {
|
|
|
-// console.log("macAddress:", macAddress);
|
|
|
-// try {
|
|
|
-// const response = await getMachineMac({ sys_sbID: macAddress });
|
|
|
-// console.log("response:", response);
|
|
|
-
|
|
|
-// if (response.code === 7) {
|
|
|
-// console.log("未登录或非法访问");
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
-// if (!response.data) {
|
|
|
-// console.log("未能获取响应数据,请检查请求或网络连接。");
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
-// if (response.data.sys_sbID === macAddress) {
|
|
|
-// Machine.value = response.data.机台号;
|
|
|
-// console.log("获取到的机台号:", Machine.value);
|
|
|
-// } else {
|
|
|
-// console.log("该电脑未绑定 MAC 地址");
|
|
|
-// }
|
|
|
-// } catch (error) {
|
|
|
-// console.error("获取机台号失败:", error.message);
|
|
|
-// }
|
|
|
-// };
|
|
|
-
|
|
|
-// // 获取MAC地址并格式化
|
|
|
-// const GetAddr = async () => {
|
|
|
-// try {
|
|
|
-// const macAddress = await fetchMACAddress();
|
|
|
-// console.log(macAddress)
|
|
|
-// console.log(123)
|
|
|
-// console.log(macAddress)
|
|
|
-// await getMachineMaclist(macAddress);
|
|
|
-
|
|
|
-// // 如果未获取到机台号,使用默认值 CF01
|
|
|
-// if (!Machine.value) {
|
|
|
-// Machine.value = 'CF01';
|
|
|
-// console.warn("未获取到机台号,使用默认机台号 CF01");
|
|
|
-// }
|
|
|
-
|
|
|
-// // 进行登录操作
|
|
|
-// await proceedWithLogin();
|
|
|
-// } catch (error) {
|
|
|
-// handleGlobalError("初始化失败", error);
|
|
|
-// }
|
|
|
-// };
|
|
|
-
|
|
|
-// // 处理登录逻辑
|
|
|
-// const proceedWithLogin = async () => {
|
|
|
-// let machineId = Machine.value;
|
|
|
-
|
|
|
-// // 将机台号格式化为指定形式
|
|
|
-// machineId = machineId.replace(/([A-Za-z]{2})\d{2}$/, "$101");
|
|
|
-
|
|
|
-// const loginInfo = {
|
|
|
-// username: machineId,
|
|
|
-// password: "123456",
|
|
|
-// captcha: "443188",
|
|
|
-// captchaId: "0FZfnUtAOrdXvTETkJRc",
|
|
|
-// openCaptcha: false,
|
|
|
-// };
|
|
|
-
|
|
|
-// console.log("准备登录,登录信息:", loginInfo);
|
|
|
-// await LoginIn2(loginInfo);
|
|
|
-// };
|
|
|
-
|
|
|
-// // 登录处理实现
|
|
|
-// const LoginIn2 = async (loginInfo) => {
|
|
|
-// let loadingInstance;
|
|
|
-// try {
|
|
|
-// // 显示加载提示
|
|
|
-// loadingInstance = ElLoading.service({
|
|
|
-// fullscreen: true,
|
|
|
-// text: '登录中,请稍候...',
|
|
|
-// });
|
|
|
-
|
|
|
-// const res = await login2(loginInfo);
|
|
|
-
|
|
|
-// if (res.code === 0) {
|
|
|
-// console.log("登录成功:", res);
|
|
|
-
|
|
|
-// // 设置用户信息和Token
|
|
|
-// setUserInfo(res.data.user);
|
|
|
-// setToken(res.data.token);
|
|
|
-
|
|
|
-// // 设置动态路由
|
|
|
-// const routerStore = useRouterStore();
|
|
|
-// await routerStore.SetAsyncRouter();
|
|
|
-// const asyncRouters = routerStore.asyncRouters;
|
|
|
-
|
|
|
-// for (const asyncRouter of asyncRouters) {
|
|
|
-// await router.addRoute(asyncRouter);
|
|
|
-// }
|
|
|
-
|
|
|
-// // 再次获取MAC并校验
|
|
|
-// const response = await getMachineMac({ sys_sbID: MAC.value });
|
|
|
-// if (!response.data) {
|
|
|
-// ClearStorage(); // 清理本地存储
|
|
|
-// } else {
|
|
|
-// const userInfo = res.data.user;
|
|
|
-// if (!router.hasRoute(userInfo.authority.defaultRouter)) {
|
|
|
-// ElMessage.error('请联系管理员进行授权');
|
|
|
-// } else {
|
|
|
-// await router.replace({ name: userInfo.authority.defaultRouter });
|
|
|
-// }
|
|
|
-
|
|
|
-// // 设置系统类型
|
|
|
-// const isWin = /windows/i.test(navigator.userAgent);
|
|
|
-// window.localStorage.setItem('osType', isWin ? 'WIN' : 'MAC');
|
|
|
-
|
|
|
-// // 登录成功后刷新页面,只刷新一次
|
|
|
-// if (!localStorage.getItem('pageRefreshed')) {
|
|
|
-// localStorage.setItem('pageRefreshed', 'true');
|
|
|
-// setTimeout(() => {
|
|
|
-// location.reload(); // 刷新页面
|
|
|
-// }, 1000);
|
|
|
-// }
|
|
|
-
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// throw new Error('登录失败:' + res.message);
|
|
|
-// }
|
|
|
-// } catch (error) {
|
|
|
-// handleGlobalError("登录时发生错误", error);
|
|
|
-// } finally {
|
|
|
-// loadingInstance?.close();
|
|
|
-// }
|
|
|
-// };
|
|
|
-
|
|
|
-// // 全局错误处理函数
|
|
|
-// const handleGlobalError = (message, error) => {
|
|
|
-// console.error(message, error);
|
|
|
-// ElMessage.error(message);
|
|
|
-// };
|
|
|
-
|
|
|
-// // 调用GetAddr获取MAC地址和机台号,并进行登录
|
|
|
-// GetAddr();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// const getMachineMaclist = async (macAddress) => {
|
|
|
-// try {
|
|
|
-// console.log("Fetching MAC details for:", macAddress);
|
|
|
-// const response = await getMachineMac({ sys_sbID: macAddress });
|
|
|
-// console.log(response)
|
|
|
-
|
|
|
-// if (response?.data?.机台号) {
|
|
|
-// Machine.value = response.data.机台号;
|
|
|
-// console.log("获取到的机台号:", Machine.value);
|
|
|
-// } else {
|
|
|
-// console.warn("未获取到有效的机台号,可能是初次登录");
|
|
|
-// }
|
|
|
-// } catch (error) {
|
|
|
-// handleGlobalError("获取机器MAC列表时出错", error);
|
|
|
-// }
|
|
|
-// };
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
/* 登出*/
|
|
|
const LoginOut = async() => {
|