|
@@ -7,10 +7,9 @@ import { ref, computed, watch } from 'vue'
|
|
|
import { useRouterStore } from './router'
|
|
import { useRouterStore } from './router'
|
|
|
import {getSpotList,search,getTab} from '@/api/mes/job'
|
|
import {getSpotList,search,getTab} from '@/api/mes/job'
|
|
|
import {getMachineMac} from '@/api/jixiaoguanli/jitairibaobiao'
|
|
import {getMachineMac} from '@/api/jixiaoguanli/jitairibaobiao'
|
|
|
-
|
|
|
|
|
|
|
+// import { setUserInfo, setToken, ClearStorage } from 'store' // 本地存储操作相关
|
|
|
export const useUserStore = defineStore('user', () => {
|
|
export const useUserStore = defineStore('user', () => {
|
|
|
const loadingInstance = ref(null)
|
|
const loadingInstance = ref(null)
|
|
|
-
|
|
|
|
|
const userInfo = ref({
|
|
const userInfo = ref({
|
|
|
uuid: '',
|
|
uuid: '',
|
|
|
nickName: '',
|
|
nickName: '',
|
|
@@ -42,56 +41,24 @@ export const useUserStore = defineStore('user', () => {
|
|
|
...value
|
|
...value
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- let MAC=ref()
|
|
|
|
|
- const GetAddr = () => {
|
|
|
|
|
- var xmlhttp = null;
|
|
|
|
|
- var res;
|
|
|
|
|
- if (window.XMLHttpRequest) {
|
|
|
|
|
- xmlhttp = new XMLHttpRequest();
|
|
|
|
|
- } else if (window.ActiveXObject) {
|
|
|
|
|
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
|
|
|
|
- }
|
|
|
|
|
- // 设置回调函数
|
|
|
|
|
- xmlhttp.onreadystatechange = function () {
|
|
|
|
|
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
|
|
|
|
- res = eval("(" + xmlhttp.response + ")");
|
|
|
|
|
- let result = "";
|
|
|
|
|
- for (let i = 0; i < res.macAddress.length; i++) {
|
|
|
|
|
- if (i % 2 === 0 && i !== 0) {
|
|
|
|
|
- result += "-"; // 根据实际需求修改分隔符
|
|
|
|
|
- }
|
|
|
|
|
- result += res.macAddress[i];
|
|
|
|
|
- }
|
|
|
|
|
- MAC = result
|
|
|
|
|
- console.log("自动获取物理地址")
|
|
|
|
|
- console.log(result)
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- // 打开一个连接
|
|
|
|
|
- xmlhttp.open("get", "http://127.0.0.1:8090/init");
|
|
|
|
|
- // 发送请求
|
|
|
|
|
- xmlhttp.send();
|
|
|
|
|
- };
|
|
|
|
|
- GetAddr()
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- /* 获取用户信息*/
|
|
|
|
|
- const GetUserInfo = async() => {
|
|
|
|
|
- const res = await getUserInfo()
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- setUserInfo(res.data.userInfo)
|
|
|
|
|
- console.log("获取用户信息")
|
|
|
|
|
- console.log(res)
|
|
|
|
|
- }
|
|
|
|
|
- return res
|
|
|
|
|
- }
|
|
|
|
|
- /* 登录*/
|
|
|
|
|
- const LoginIn = async(loginInfo) => {
|
|
|
|
|
- loadingInstance.value = ElLoading.service({
|
|
|
|
|
- fullscreen: true,
|
|
|
|
|
- text: '登录中,请稍候...',
|
|
|
|
|
- })
|
|
|
|
|
|
|
+/* 获取用户信息*/
|
|
|
|
|
+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 {
|
|
try {
|
|
|
- const res = await login(loginInfo)
|
|
|
|
|
|
|
+ const res = await login(loginInfo)
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
|
setUserInfo(res.data.user)
|
|
setUserInfo(res.data.user)
|
|
|
setToken(res.data.token)
|
|
setToken(res.data.token)
|
|
@@ -117,75 +84,186 @@ export const useUserStore = defineStore('user', () => {
|
|
|
}
|
|
}
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
|
- } catch (e) {
|
|
|
|
|
- loadingInstance.value.close()
|
|
|
|
|
|
|
+ } 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");
|
|
|
|
|
+ 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地址');
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ throw new Error('获取MAC地址失败:' + error.message);
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 获取机器MAC列表,并设置Machine.value
|
|
|
|
|
+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("未获取到有效的机台号,可能是初次登录");
|
|
|
}
|
|
}
|
|
|
- loadingInstance.value.close()
|
|
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ handleGlobalError("获取机器MAC列表时出错", error);
|
|
|
}
|
|
}
|
|
|
- const LoginIn2 = async(loginInfo) => {
|
|
|
|
|
- loadingInstance.value = ElLoading.service({
|
|
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// 获取MAC地址并格式化
|
|
|
|
|
+const GetAddr = async () => {
|
|
|
|
|
+ const macAddress = await fetchMACAddress();
|
|
|
|
|
+ await getMachineMaclist(macAddress);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果未获取到机台号,使用默认值 CF01
|
|
|
|
|
+ if (!Machine.value) {
|
|
|
|
|
+ Machine.value = 'CF01';
|
|
|
|
|
+ console.warn("未获取到机台号,使用默认机台号 CF01");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 进行登录操作
|
|
|
|
|
+ await proceedWithLogin();
|
|
|
|
|
+
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 处理登录逻辑
|
|
|
|
|
+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); // 输出结果进行验证
|
|
|
|
|
+
|
|
|
|
|
+ console.log("准备登录,登录信息:", loginInfo);
|
|
|
|
|
+ await LoginIn2(loginInfo); // 进行登录操作
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 登录处理实现
|
|
|
|
|
+const LoginIn2 = async (loginInfo) => {
|
|
|
|
|
+ let loadingInstance;
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 显示加载提示
|
|
|
|
|
+ loadingInstance = ElLoading.service({
|
|
|
fullscreen: true,
|
|
fullscreen: true,
|
|
|
text: '登录中,请稍候...',
|
|
text: '登录中,请稍候...',
|
|
|
- })
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await login2(loginInfo)
|
|
|
|
|
- // console.log(loginInfo)
|
|
|
|
|
- // console.log(res)
|
|
|
|
|
- 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)
|
|
|
|
|
- })
|
|
|
|
|
- console.log("MAC")
|
|
|
|
|
- console.log(MAC)
|
|
|
|
|
- const response = await getMachineMac({sys_sbID:MAC});
|
|
|
|
|
- console.log(response)
|
|
|
|
|
- if(response.data===null){
|
|
|
|
|
- // ElMessage.error('请输入账号密码')
|
|
|
|
|
- ClearStorage()
|
|
|
|
|
- }else{
|
|
|
|
|
- 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;
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ 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 === null) {
|
|
|
|
|
+ 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');
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
- } catch (e) {
|
|
|
|
|
- loadingInstance.value.close()
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 登录失败
|
|
|
|
|
+ throw new Error('登录失败:' + res.message);
|
|
|
}
|
|
}
|
|
|
- loadingInstance.value.close()
|
|
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ throw new Error('登录时发生错误:' + error.message);
|
|
|
|
|
+ } 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 GetMachineMac = async (sys_sbID) => {
|
|
|
|
|
- console.log(985)
|
|
|
|
|
-const response = await getMachineMac({ sys_sbID: 'B4-2E-99-28-FB-E7' });
|
|
|
|
|
-console.log(response)
|
|
|
|
|
-if(response.data===null){
|
|
|
|
|
- LoginOut()
|
|
|
|
|
-}else{
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
-// console.log(loginFormData2)
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
/* 登出*/
|
|
/* 登出*/
|
|
|
const LoginOut = async() => {
|
|
const LoginOut = async() => {
|