|
|
@@ -43,68 +43,20 @@ export const useUserStore = defineStore('user', () => {
|
|
|
}
|
|
|
|
|
|
|
|
|
-/* 获取用户信息*/
|
|
|
-const GetUserInfo = async() => {
|
|
|
- const res = await getUserInfo()
|
|
|
- if (res.code === 0) {
|
|
|
- setUserInfo(res.data.userInfo)
|
|
|
- }
|
|
|
- return res
|
|
|
-}
|
|
|
-/* 登录*/
|
|
|
-const LoginIn = async(loginInfo) => {
|
|
|
- loadingInstance.value = ElLoading.service({
|
|
|
- fullscreen: true,
|
|
|
- text: '登录中,请稍候...',
|
|
|
- })
|
|
|
- try {
|
|
|
- const res = await login(loginInfo)
|
|
|
- if (res.code === 0) {
|
|
|
- setUserInfo(res.data.user)
|
|
|
- setToken(res.data.token)
|
|
|
- const routerStore = useRouterStore()
|
|
|
- await routerStore.SetAsyncRouter()
|
|
|
- const asyncRouters = routerStore.asyncRouters
|
|
|
- asyncRouters.forEach(asyncRouter => {
|
|
|
- router.addRoute(asyncRouter)
|
|
|
- })
|
|
|
- if (!router.hasRoute(userInfo.value.authority.defaultRouter)) {
|
|
|
- ElMessage.error('请联系管理员进行授权')
|
|
|
- } else {
|
|
|
- await router.replace({ name: userInfo.value.authority.defaultRouter })
|
|
|
- }
|
|
|
-
|
|
|
- loadingInstance.value.close()
|
|
|
-
|
|
|
- const isWin = ref(/windows/i.test(navigator.userAgent))
|
|
|
- if (isWin.value) {
|
|
|
- window.localStorage.setItem('osType', 'WIN')
|
|
|
- } else {
|
|
|
- window.localStorage.setItem('osType', 'MAC')
|
|
|
- }
|
|
|
- return true
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- loadingInstance.value.close()
|
|
|
- }
|
|
|
- loadingInstance.value.close()
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// 定义全局变量
|
|
|
+// 定义全局状态
|
|
|
const Machine = ref(''); // 机台号
|
|
|
const MAC = ref(''); // MAC地址
|
|
|
|
|
|
-// 封装获取MAC地址的函数
|
|
|
+// 封装MAC地址的函数
|
|
|
const fetchMACAddress = async () => {
|
|
|
try {
|
|
|
const response = await fetch("http://127.0.0.1:8090/init");
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error('网络响应不正常: ' + response.status);
|
|
|
+ }
|
|
|
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 {
|
|
|
throw new Error('无法获取MAC地址');
|
|
|
@@ -114,17 +66,74 @@ const fetchMACAddress = async () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 获取机器MAC列表,并设置Machine.value
|
|
|
+// 自动获取MAC地址并登录
|
|
|
+const GetAddr = async () => {
|
|
|
+ try {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (response.data.sys_sbID === macAddress) {
|
|
|
+ Machine.value = response.data.机台号;
|
|
|
+ console.log("获取到的机台号:", Machine.value);
|
|
|
+ } else {
|
|
|
+ Machine.value = 'CF01';
|
|
|
+ console.log("该电脑未绑定 MAC 地址");
|
|
|
+ }
|
|
|
+
|
|
|
+ //默认值
|
|
|
+ // if (!Machine.value) {
|
|
|
+ // Machine.value = 'CF01';
|
|
|
+ // console.warn("使用默认机台号 CF01");
|
|
|
+ // }
|
|
|
+ let machineId = Machine.value;
|
|
|
+ console.log("当前默认机台号:", machineId);
|
|
|
+
|
|
|
+ // 如果 `machineId` 格式不正确,进行格式调整
|
|
|
+ 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);
|
|
|
+ // await proceedWithLogin();
|
|
|
+ } catch (error) {
|
|
|
+ console.error("初始化失败,错误信息:", error.message);
|
|
|
+ handleGlobalError("初始化失败", error);
|
|
|
+ }
|
|
|
+};
|
|
|
+GetAddr();
|
|
|
+
|
|
|
+// 获取机器MAC列表
|
|
|
const getMachineMaclist = async (macAddress) => {
|
|
|
- console.log("macAddress:", macAddress);
|
|
|
+ console.log("获取机器MAC列表:", macAddress);
|
|
|
try {
|
|
|
- const response = await getMachineMac({ sys_sbID: macAddress });
|
|
|
- console.log("response:", response);
|
|
|
+ const response = await getMachineMac({ sys_sbID: macAddress });
|
|
|
+ console.log("获取数据库列表:", response);
|
|
|
|
|
|
- if (response.code === 7) {
|
|
|
- console.log("未登录或非法访问");
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (response.code === 7) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
if (!response.data) {
|
|
|
console.log("未能获取响应数据,请检查请求或网络连接。");
|
|
|
@@ -142,30 +151,12 @@ const getMachineMaclist = async (macAddress) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 获取MAC地址并格式化
|
|
|
-const GetAddr = async () => {
|
|
|
- try {
|
|
|
- const macAddress = await fetchMACAddress();
|
|
|
- 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;
|
|
|
+ console.log("当前默认机台号:", machineId);
|
|
|
|
|
|
- // 将机台号格式化为指定形式
|
|
|
+ // 如果 `machineId` 格式不正确,进行格式调整
|
|
|
machineId = machineId.replace(/([A-Za-z]{2})\d{2}$/, "$101");
|
|
|
|
|
|
const loginInfo = {
|
|
|
@@ -180,6 +171,7 @@ const proceedWithLogin = async () => {
|
|
|
await LoginIn2(loginInfo);
|
|
|
};
|
|
|
|
|
|
+
|
|
|
// 登录处理实现
|
|
|
const LoginIn2 = async (loginInfo) => {
|
|
|
let loadingInstance;
|
|
|
@@ -238,20 +230,231 @@ const LoginIn2 = async (loginInfo) => {
|
|
|
throw new Error('登录失败:' + res.message);
|
|
|
}
|
|
|
} catch (error) {
|
|
|
+ console.error("登录时发生错误:", error);
|
|
|
handleGlobalError("登录时发生错误", error);
|
|
|
} finally {
|
|
|
loadingInstance?.close();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 全局错误处理函数
|
|
|
-const handleGlobalError = (message, error) => {
|
|
|
- console.error(message, error);
|
|
|
- ElMessage.error(message);
|
|
|
-};
|
|
|
+/* 获取用户信息*/
|
|
|
+const GetUserInfo = async() => {
|
|
|
+ const res = await getUserInfo()
|
|
|
+ if (res.code === 0) {
|
|
|
+ setUserInfo(res.data.userInfo)
|
|
|
+ }
|
|
|
+ return res
|
|
|
+}
|
|
|
|
|
|
-// 调用GetAddr获取MAC地址和机台号,并进行登录
|
|
|
-GetAddr();
|
|
|
+/* 登录*/
|
|
|
+const LoginIn = async(loginInfo) => {
|
|
|
+ console.log(12312312321321)
|
|
|
+ loadingInstance.value = ElLoading.service({
|
|
|
+ fullscreen: true,
|
|
|
+ text: '登录中,请稍候...',
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ const res = await login(loginInfo)
|
|
|
+ if (res.code === 0) {
|
|
|
+ setUserInfo(res.data.user)
|
|
|
+ setToken(res.data.token)
|
|
|
+ const routerStore = useRouterStore()
|
|
|
+ await routerStore.SetAsyncRouter()
|
|
|
+ const asyncRouters = routerStore.asyncRouters
|
|
|
+ asyncRouters.forEach(asyncRouter => {
|
|
|
+ router.addRoute(asyncRouter)
|
|
|
+ })
|
|
|
+ if (!router.hasRoute(userInfo.value.authority.defaultRouter)) {
|
|
|
+ ElMessage.error('请联系管理员进行授权')
|
|
|
+ } else {
|
|
|
+ await router.replace({ name: userInfo.value.authority.defaultRouter })
|
|
|
+ }
|
|
|
+
|
|
|
+ loadingInstance.value.close()
|
|
|
+
|
|
|
+ const isWin = ref(/windows/i.test(navigator.userAgent))
|
|
|
+ if (isWin.value) {
|
|
|
+ window.localStorage.setItem('osType', 'WIN')
|
|
|
+ } else {
|
|
|
+ window.localStorage.setItem('osType', 'MAC')
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ loadingInstance.value.close()
|
|
|
+ }
|
|
|
+ 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();
|
|
|
|
|
|
|
|
|
|