|
@@ -116,51 +116,35 @@ const fetchMACAddress = async () => {
|
|
|
|
|
|
|
|
// 获取机器MAC列表,并设置Machine.value
|
|
// 获取机器MAC列表,并设置Machine.value
|
|
|
const getMachineMaclist = async (macAddress) => {
|
|
const getMachineMaclist = async (macAddress) => {
|
|
|
- // try {
|
|
|
|
|
- console.log("macAddress:",macAddress)
|
|
|
|
|
|
|
+ console.log("macAddress:", macAddress);
|
|
|
|
|
+ try {
|
|
|
const response = await getMachineMac({ sys_sbID: macAddress });
|
|
const response = await getMachineMac({ sys_sbID: macAddress });
|
|
|
|
|
+ console.log("response:", response);
|
|
|
|
|
|
|
|
- if (response.code === 7) {console.log("未登录或非法访问");return;}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if (response.data.机台号 === macAddress) {
|
|
|
|
|
- Machine.value = response.data.机台号;
|
|
|
|
|
- console.log("获取到的机台号:", Machine.value);
|
|
|
|
|
- }else{
|
|
|
|
|
- if (response.data === null) {
|
|
|
|
|
- console.log("未能获取响应数据,请检查请求或网络连接。");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (response.code === 7) {
|
|
|
|
|
- console.log("未登录或非法访问,已忽略该提示");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (response.data.机台号 === undefined) {
|
|
|
|
|
- console.log("该电脑未绑定 MAC 地址");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (response.data === null) {
|
|
|
|
|
- console.log("未能获取响应数据,请检查请求或网络连接。");
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if (response.code === 7) {
|
|
|
|
|
+ console.log("未登录或非法访问");
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if (response.data.机台号 === undefined) {
|
|
|
|
|
- console.log("该电脑未绑定 MAC 地址");
|
|
|
|
|
- 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地址并格式化
|
|
// 获取MAC地址并格式化
|
|
|
const GetAddr = async () => {
|
|
const GetAddr = async () => {
|
|
|
|
|
+ try {
|
|
|
const macAddress = await fetchMACAddress();
|
|
const macAddress = await fetchMACAddress();
|
|
|
await getMachineMaclist(macAddress);
|
|
await getMachineMaclist(macAddress);
|
|
|
|
|
|
|
@@ -169,30 +153,31 @@ const GetAddr = async () => {
|
|
|
Machine.value = 'CF01';
|
|
Machine.value = 'CF01';
|
|
|
console.warn("未获取到机台号,使用默认机台号 CF01");
|
|
console.warn("未获取到机台号,使用默认机台号 CF01");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// 进行登录操作
|
|
// 进行登录操作
|
|
|
await proceedWithLogin();
|
|
await proceedWithLogin();
|
|
|
-
|
|
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ handleGlobalError("初始化失败", error);
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 处理登录逻辑
|
|
// 处理登录逻辑
|
|
|
const proceedWithLogin = async () => {
|
|
const proceedWithLogin = async () => {
|
|
|
- let machineId = Machine.value;
|
|
|
|
|
-
|
|
|
|
|
- // 匹配任意两位字母或字母数字开头,后面是两位数字,且后缀不是01的情况
|
|
|
|
|
- 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); // 输出结果进行验证
|
|
|
|
|
-
|
|
|
|
|
|
|
+ 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);
|
|
console.log("准备登录,登录信息:", loginInfo);
|
|
|
- await LoginIn2(loginInfo); // 进行登录操作
|
|
|
|
|
|
|
+ await LoginIn2(loginInfo);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 登录处理实现
|
|
// 登录处理实现
|
|
@@ -208,7 +193,6 @@ const LoginIn2 = async (loginInfo) => {
|
|
|
const res = await login2(loginInfo);
|
|
const res = await login2(loginInfo);
|
|
|
|
|
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
|
- // 登录成功
|
|
|
|
|
console.log("登录成功:", res);
|
|
console.log("登录成功:", res);
|
|
|
|
|
|
|
|
// 设置用户信息和Token
|
|
// 设置用户信息和Token
|
|
@@ -226,31 +210,36 @@ const LoginIn2 = async (loginInfo) => {
|
|
|
|
|
|
|
|
// 再次获取MAC并校验
|
|
// 再次获取MAC并校验
|
|
|
const response = await getMachineMac({ sys_sbID: MAC.value });
|
|
const response = await getMachineMac({ sys_sbID: MAC.value });
|
|
|
- if (response.data === null) {
|
|
|
|
|
|
|
+ if (!response.data) {
|
|
|
ClearStorage(); // 清理本地存储
|
|
ClearStorage(); // 清理本地存储
|
|
|
} else {
|
|
} else {
|
|
|
- // 检查默认路由是否存在
|
|
|
|
|
const userInfo = res.data.user;
|
|
const userInfo = res.data.user;
|
|
|
if (!router.hasRoute(userInfo.authority.defaultRouter)) {
|
|
if (!router.hasRoute(userInfo.authority.defaultRouter)) {
|
|
|
ElMessage.error('请联系管理员进行授权');
|
|
ElMessage.error('请联系管理员进行授权');
|
|
|
} else {
|
|
} else {
|
|
|
- // 跳转到默认路由
|
|
|
|
|
await router.replace({ name: userInfo.authority.defaultRouter });
|
|
await router.replace({ name: userInfo.authority.defaultRouter });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 处理系统类型
|
|
|
|
|
|
|
+ // 设置系统类型
|
|
|
const isWin = /windows/i.test(navigator.userAgent);
|
|
const isWin = /windows/i.test(navigator.userAgent);
|
|
|
window.localStorage.setItem('osType', isWin ? 'WIN' : 'MAC');
|
|
window.localStorage.setItem('osType', isWin ? 'WIN' : 'MAC');
|
|
|
|
|
+
|
|
|
|
|
+ // 登录成功后刷新页面,只刷新一次
|
|
|
|
|
+ if (!localStorage.getItem('pageRefreshed')) {
|
|
|
|
|
+ localStorage.setItem('pageRefreshed', 'true');
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ location.reload(); // 刷新页面
|
|
|
|
|
+ }, 1000);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- // 登录失败
|
|
|
|
|
throw new Error('登录失败:' + res.message);
|
|
throw new Error('登录失败:' + res.message);
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- throw new Error('登录时发生错误:' + error.message);
|
|
|
|
|
|
|
+ handleGlobalError("登录时发生错误", error);
|
|
|
} finally {
|
|
} finally {
|
|
|
- // 关闭加载提示
|
|
|
|
|
loadingInstance?.close();
|
|
loadingInstance?.close();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|