This commit is contained in:
lcw
2025-10-09 21:33:18 +08:00
parent 3b54e1bb47
commit 598c4fd3e2
23 changed files with 284 additions and 25 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0dd6ad"],{"80fe":function(e,t,o){"use strict";o.r(t);var s=o("7a23"),n=o("5502"),c=o("f3e4"),i=o("5d2d"),r=o("92c2"),u=o("5f87"),d={__name:"zeroTrust_login",setup(e){Object(s["ref"])(!1),Object(s["ref"])([]);const t=Object(n["b"])();function o(){d()}const d=e=>{const o=Object(c["a"])("clientKey");o?Object(r["f"])({cookie:o}).then(e=>{Object(r["k"])({idCardNo:e}).then(e=>{t.commit("user/setToken",e.jwtToken),t.commit("user/setDeptList",e.deptList),t.commit("user/setUserName",e.userName),t.commit("user/setMenuList",e.menuList),t.commit("user/setUserInfo",{token:e.jwtToken,permission:{buttonPermission:["removeTest","viewTest"],menus:e.menuCodeSet},menuList:e.menuList,deptList:e.deptList}),Object(i["c"])("USERNAME",e.userName),Object(i["c"])("deptId",e.deptList),Object(i["c"])("SFRH",e.sfrh),Object(i["c"])("USERID",e.userId),Object(i["c"])("menusPermission",e.menuCodeSet),Object(i["c"])("idEntityCard",e.idEntityCard),Object(u["b"])(),setTimeout(()=>{window.location.hash="/"},1e3)}).catch(e=>{console.error("免登失败:",e)})}).catch(e=>{console.error("获取会话信息失败:",e)}):(console.error("没有找到clientKey cookie"),window.location.hash="/login")};return Object(s["onMounted"])(()=>{o()}),(e,t)=>null}};const m=d;t["default"]=m}}]);

View File

@ -0,0 +1 @@
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d22bd3e"],{f141:function(t,e,n){"use strict";n.r(e);var o=n("7a23"),c=n("5502"),u=n("5d2d"),a=n("6605"),i={__name:"oatuh_login",setup(t){const e=Object(o["ref"])(!1),n=Object(o["ref"])([]),i=Object(c["b"])();function l(){const t=Object(a["c"])();let e=t.query.token||null;null!=e?(e=e.replace(/\ +/g,""),Object(u["c"])("SSOTOKEN",e),s({token:e})):window.location.href="http://155.240.22.188:9020"}const s=t=>{i.dispatch("user/oatuhLogin",t).then(t=>{1===t.deptList.length?window.location.hash="/":(n.value=[...t.deptList],e.value=!0,authorization.value=t.jwtToken)})};return Object(o["onMounted"])(()=>{l()}),(t,e)=>null}};const l=i;e["default"]=l}}]);

View File

@ -1 +0,0 @@
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d22bd3e"],{f141:function(t,e,n){"use strict";n.r(e);var o=n("7a23"),c=n("5502"),a=n("5d2d"),u={__name:"oatuh_login",setup(t){const e=Object(o["ref"])(!1),n=Object(o["ref"])([]),u=Object(c["b"])();function i(){let t=location.hash.slice(20)||null;null!=t?(t=t.replace(/\ +/g,""),Object(a["c"])("SSOTOKEN",t),l({token:t})):window.location.href="http://155.240.22.188:9020"}const l=t=>{u.dispatch("user/oatuhLogin",t).then(t=>{1===t.deptList.length?window.location.hash="/":(n.value=[...t.deptList],e.value=!0,authorization.value=t.jwtToken)})};return Object(o["onMounted"])(()=>{i()}),(t,e)=>null}};const i=u;e["default"]=i}}]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -609,4 +609,27 @@ export const unifiedLogin = (data) => {
method: "POST",
data
});
};
};
export const getSessionForToken = (params) => {
return request({
url: api + `/getSessionForToken`,
method: "GET",
params
});
};
// 身份证号登录
export const idCardNoLogin = (data) => {
return request({
url: api + `/idCardNoLogin`,
method: "POST",
data
});
}
// 通过身份证号获取会话信息
export const getSessionForSfzh = (params) => {
return request({
url: api + `/getSessionForSfzh`,
method: "GET",
params
});
};

View File

@ -63,7 +63,21 @@ onMounted(() => {
//登陆用户信息
username.value = localStorage.getItem("USERNAME");
let dept = getItem("deptId");
activeMeun.value = window.localStorage.getItem("activeId");
// 获取本地存储的activeId如果没有则默认选中第一个
const savedActiveId = window.localStorage.getItem("activeId");
if (savedActiveId !== null && !isNaN(savedActiveId)) {
activeMeun.value = Number(savedActiveId);
} else {
// 默认选中第一个菜单
activeMeun.value = 0;
window.localStorage.setItem("activeId", "0");
// 如果有菜单数据,触发第一个菜单的选择事件
if (props.meunList && props.meunList.length > 0) {
emits("getMeunList", props.meunList[0]);
}
}
});
const logout = () => {
window.opener = null;

View File

@ -49,8 +49,63 @@ const router = useRouter();
const activeMeun = ref(0);
const defMeun= computed(()=>{
return route.path
})
// 如果当前路由不在菜单中或者是空的,返回菜单中的第一个可用路由
const currentPath = route.path;
// 检查当前路由是否存在于菜单中
let hasMatch = false;
const checkMenuMatch = (menus) => {
if (!menus || !Array.isArray(menus)) return;
for (const item of menus) {
if (item.path === currentPath) {
hasMatch = true;
return;
}
if (item.children) {
checkMenuMatch(item.children);
}
}
};
checkMenuMatch(props.meuns?.children || []);
// 如果当前路由存在于菜单中,返回当前路由
if (hasMatch) {
return currentPath;
}
// 如果当前路由不存在于菜单中或者为空,返回菜单中的第一个可用路由
if (props.meuns?.children && props.meuns.children.length > 0) {
// 查找第一个有path的菜单项
const firstValidMenu = findFirstValidMenu(props.meuns.children);
return firstValidMenu || '/qwbb'; // 降级方案
}
// 如果菜单为空,返回降级路由
return '/qwbb';
});
// 辅助函数:查找第一个有效的菜单项路径
function findFirstValidMenu(menus) {
if (!menus || !Array.isArray(menus)) return null;
for (const menu of menus) {
// 如果菜单项有path且不为空返回该path
if (menu.path && menu.path.trim()) {
return menu.path;
}
// 如果菜单项有子菜单,递归查找
if (menu.children && menu.children.length > 0) {
const childPath = findFirstValidMenu(menu.children);
if (childPath) {
return childPath;
}
}
}
return null;
}
const changeMeun = (item, idx) => {
if (activeMeun.value == idx) return;
activeMeun.value = idx;

View File

@ -1,12 +1,16 @@
import router from './router'
import Base64 from "base-64";
import store from './store'
import {
setItem,
getItem,
removeAllItem
} from "@/utils/storage";
import {
getCookie
} from "@/utils/cookie";
// 白名单
const whiteList = ['/login', '/oatuh_login', '/404', '/401']
const whiteList = ['/login', '/oatuh_login', '/404', '/401', '/zeroTrust_login', '/focusExploration', '/clueVerification', '/deploymentApproval']
/**
* 路由前置守卫
* to 去哪里
@ -40,15 +44,22 @@ router.beforeEach(async (to, from, next) => {
}
// 利用 addRoute 循环添加
} else {
const isOatuh = getItem('isOatuh')
// 没有token的情况下可以进入白名单
if (whiteList.indexOf(to.path) > -1) {
next()
} else {
if (isOatuh) {
next('/oatuh_login')
const cookie = getCookie("clientKey");
if (cookie) {
next(`/zeroTrust_login`)
} else {
next('/login')
const isOatuh = getItem('isOatuh')
// 没有token的情况下可以进入白名单
if (isOatuh) {
const idEntityCard = getItem('idEntityCard')
next(`/oatuh_login?token=${Base64.encode(idEntityCard)}`)
} else {
next('/login')
}
}
}
}

View File

@ -29,10 +29,15 @@ export const publicRoutes = [
path: "/oatuh_login",
name: "oatuh_login",
component: () => import("@/views/login/oatuh_login")
}, {
},
{
path: "/login",
name: 'login',
component: () => import("@/views/login/index") //系统登录
}, {
path: "/zeroTrust_login",
name: "zeroTrust_login",
component: () => import("@/views/login/zeroTrust_login")
},
{
path: "/preview",

61
src/utils/cookie.js Normal file
View File

@ -0,0 +1,61 @@
/*
* 1.设置cookie
* @param {string} key - cookie的名称
* @param {string} value - cookie的值
* @param {number} days - 过期天数默认7天
*/
export const setCookie = (key, value, days = 7) => {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
const expires = `expires=${date.toGMTString()}`;
document.cookie = `${key}=${encodeURIComponent(value)}; ${expires}; path=/`;
};
/*
* 2.获取cookie
* @param {string} key - cookie的名称
* @returns {string|null} - cookie的值如果不存在则返回null
*/
export const getCookie = (key) => {
const name = `${key}=`;
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i].trim();
if (c.indexOf(name) === 0) {
return decodeURIComponent(c.substring(name.length, c.length));
}
}
return null;
};
/*
* 3.删除指定cookie
* @param {string} key - cookie的名称
*/
export const removeCookie = (key) => {
setCookie(key, '', -1);
};
/*
* 4.删除所有cookie
*/
export const removeAllCookies = () => {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i];
const eqPos = cookie.indexOf('=');
const name = eqPos > -1 ? cookie.substr(0, eqPos).trim() : '';
if (name) {
removeCookie(name);
}
}
};
/*
* 5.检查cookie是否存在
* @param {string} key - cookie的名称
* @returns {boolean} - 是否存在该cookie
*/
export const hasCookie = (key) => {
return getCookie(key) !== null;
};

View File

@ -3,15 +3,18 @@
<script setup>
import { ref, onMounted } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import {
setItem
} from "@/utils/storage";
import { useRoute } from "vue-router";
const loginDialog = ref(false);
const deptList = ref([]);
const store = useStore();
function redirectAuth() {
let token = location.hash.slice(20) || null;
// 从路由参数中获取token
const route = useRoute();
let token = route.query.token || null;
if (token != null) {
token = token.replace(/\ +/g, "");
setItem("SSOTOKEN", token)
@ -38,4 +41,4 @@ onMounted(() => {
});
</script>
<style></style>
<style></style>

View File

@ -0,0 +1,86 @@
<template></template>
<script setup>
import { ref, onMounted } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import {
getCookie
} from "@/utils/cookie";
import {
setItem
} from "@/utils/storage";
import { getSessionForSfzh, idCardNoLogin } from "@/api/user-manage";
import {
setTimeStamp
} from "@/utils/auth";
const loginDialog = ref(false);
const deptList = ref([]);
const store = useStore();
function redirectAuth() {
handleLogin();
}
const handleLogin = (e) => {
// 先尝试获取cookie中的clientKey
const token = getCookie("clientKey");
if (token) {
// 使用clientKey获取会话信息
getSessionForSfzh({ cookie: token }).then((res) => {
// 使用获取到的idEntityCard进行免登
idCardNoLogin({
idCardNo: res
}).then((resIdCard) => {
// 登录成功后设置token和用户信息到store
store.commit("user/setToken", resIdCard.jwtToken);
store.commit("user/setDeptList", resIdCard.deptList);
store.commit("user/setUserName", resIdCard.userName);
store.commit("user/setMenuList", resIdCard.menuList);
store.commit("user/setUserInfo", {
token: resIdCard.jwtToken,
permission: {
buttonPermission: ["removeTest", "viewTest"],
menus: resIdCard.menuCodeSet
},
menuList: resIdCard.menuList,
deptList: resIdCard.deptList
});
// 保存用户信息到本地存储
setItem("USERNAME", resIdCard.userName);
setItem("deptId", resIdCard.deptList);
setItem("SFRH", resIdCard.sfrh);
setItem("USERID", resIdCard.userId);
setItem("menusPermission", resIdCard.menuCodeSet);
setItem("idEntityCard", resIdCard.idEntityCard);
// 保存登录时间
setTimeStamp();
// 重定向到首页
setTimeout(() => {
window.location.hash = "/";
// window.location.hash = "/user/userList";
}, 1000);
}).catch((error) => {
console.error("免登失败:", error);
// 免登失败时重定向到登录页面
// window.location.hash = "/login";
});
}).catch((error) => {
console.error("获取会话信息失败:", error);
// 获取会话信息失败时重定向到登录页面
// window.location.hash = "/login";
});
} else {
console.error("没有找到clientKey cookie");
// 没有cookie时重定向到登录页面
window.location.hash = "/login";
}
};
onMounted(() => {
redirectAuth();
});
</script>
<style></style>

View File

@ -3,8 +3,8 @@ const path = require("path");
function resolve(dir) {
return path.join(__dirname, dir);
}
// const serverHost = "http://192.192.192.109:8006";
const serverHost = "http://192.168.0.231:8006";
const serverHost = "http://47.108.232.77:9537";
// const serverHost = "http://192.168.0.231:8006";
// const serverHost ="http://80.60.36.64:8006"
module.exports = {
publicPath: "/",