严飞永 1 month ago
parent a6049d585e
commit d2a44e5fb3

@ -26,29 +26,12 @@ router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start()
//政务登录 const { userToken, signature, timespan } = to.query
const url = window.location.href console.log(userToken, signature, timespan, '参数')
// 检查是否包含政务平台返回的关键参数
const hasUserToken = url.includes('userToken=')
const hasSignature = url.includes('signature=')
const hasTimespan = url.includes('timespan=')
if (hasUserToken && hasSignature && hasTimespan) {
const regUserToken = /[?&]userToken=([^&#]+)/
const regSignature = /[?&]signature=([^&#]+)/
const regTimespan = /[?&]timespan=([^&#]+)/
const userTokenMatch = url.match(regUserToken)
const signatureMatch = url.match(regSignature)
const timespanMatch = url.match(regTimespan)
const userToken = userTokenMatch ? userTokenMatch[1] : null
const signature = signatureMatch ? signatureMatch[1] : null
const timespan = timespanMatch ? timespanMatch[1] : null
if (userToken && signature && timespan) { if (userToken && signature && timespan) {
// 调用政务系统登录接口 // 政务登录
governmentGetInfo({ governmentGetInfo({
userToken, userToken,
signature, signature,
@ -59,15 +42,13 @@ router.beforeEach((to, from, next) => {
setToken(token) setToken(token)
localStorage.setItem('otherToken', userToken) localStorage.setItem('otherToken', userToken)
const cleanUrl = url const newQuery = { ...to.query }
.replace(regUserToken, '') delete newQuery.userToken
.replace(regSignature, '') delete newQuery.signature
.replace(regTimespan, '') delete newQuery.timespan
.replace(/^&/, '?') const newPath = to.path + '?' + new URLSearchParams(newQuery).toString()
window.history.replaceState({}, '', newPath)
window.history.replaceState({}, '', cleanUrl)
// 继续路由守卫流程
if (store.getters.roles.length === 0) { if (store.getters.roles.length === 0) {
isRelogin.show = true isRelogin.show = true
store.dispatch('GetInfo').then(() => { store.dispatch('GetInfo').then(() => {
@ -90,10 +71,7 @@ router.beforeEach((to, from, next) => {
console.error('政务系统登录失败:', err) console.error('政务系统登录失败:', err)
Message.error('政务系统登录失败,请重新登录') Message.error('政务系统登录失败,请重新登录')
}) })
} else {
Message.error('缺少必要的登录参数')
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`)
}
return return
} }

@ -43,7 +43,10 @@ export const constantRoutes = [
}, },
{ {
path: "/login", path: "/login",
component: () => import("@/views/login"), // 正式环境登录页
// component: () => import("@/views/login"),
// 测试
component: () => import("@/views/login_v1"),
hidden: true, hidden: true,
}, },
{ {
@ -77,7 +80,7 @@ export const constantRoutes = [
component: () => import("@/views/index"), component: () => import("@/views/index"),
name: "Index", name: "Index",
meta: { title: "角色判断", icon: "icon-tjfx-1" }, meta: { title: "角色判断", icon: "icon-tjfx-1" },
hidden:true hidden: true,
}, },
{ {
path: "/user", path: "/user",

@ -203,7 +203,7 @@ export default {
window.location.href = 'https://qyt.sipac.gov.cn/sipsg-enterprise-mobile-manage/#/login' window.location.href = 'https://qyt.sipac.gov.cn/sipsg-enterprise-mobile-manage/#/login'
}, },
handleEnterpriseLogin() { handleEnterpriseLogin() {
window.location.href = 'https://gysl.sipac.gov.cn'; // window.location.href = 'https://gysl.sipac.gov.cn';
} }
} }
} }

@ -61,7 +61,7 @@
import { getCodeImg } from '@/api/login' import { getCodeImg } from '@/api/login'
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import { encrypt, decrypt } from '@/utils/jsencrypt' import { encrypt, decrypt } from '@/utils/jsencrypt'
import forge from 'node-forge'
export default { export default {
name: 'Login', name: 'Login',
@ -87,31 +87,33 @@
code: [{ required: true, trigger: 'change', message: '请输入验证码' }] code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
}, },
loading: false, loading: false,
//
captchaEnabled: true, captchaEnabled: true,
//
register: false, register: false,
redirect: undefined redirect: undefined,
a1: `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl8bS1kYTiMhIS5MZU253bc0ukaxrA1lfCziABFxQrC2c09tMrQGjuH6V1x2ofNBMGhOD9uWN/qkAQy/HwOe/NKUqCw6N0ov6guSrqMDW/BdZ3Bl0rmM1/95jTC1xffFFvej7xWNffIbaPI+bJ4WLX9NViNi9HmT0BRNzJ4d2R86LPPCa+bxLaPjsh2R2tBkbLkUot9769aJaPPiwPCZHMkuQenjHSmpWL0okleqMH8EGX7j6A5A/4IUXPMNKMMzkiSRpsIJ65GJmDAbnR3ZXRfC8MzVBBJB6zr5N0F4N9xZfF+JS/Yx726tCu+rA6GDCyTxtQ/wnKpPdwFP5nUWCWQIDAQAB`
} }
}, },
watch: { watch: {
$route(route) { $route: {
this.redirect = route.query && route.query.redirect handler: function (route) {
this.redirect = route.query && route.query.redirect;
},
immediate: true
}, },
activeName(newVal) { activeName(newVal) {
if (newVal === 'first') { if (newVal === 'first') {
this.loginForm.loginRole = 2; this.loginForm.loginRole = 2
} else if (newVal === 'second') { } else if (newVal === 'second') {
this.loginForm.loginRole = 1; this.loginForm.loginRole = 1
} }
} }
}, },
computed: { computed: {
showGovernmentLoginButton() { showGovernmentLoginButton() {
return this.activeName === 'second'; return this.activeName === 'second'
}, },
showEnterpriseLoginButton() { showEnterpriseLoginButton() {
return this.activeName === 'first'; return this.activeName === 'first'
} }
}, },
created() { created() {
@ -120,15 +122,13 @@
}, },
methods: { methods: {
getCode() { getCode() {
getCodeImg().then((res) => { getCodeImg().then(res => {
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
if (this.captchaEnabled) { if (this.captchaEnabled) {
this.codeUrl = `data:image/gif;base64,${res.img}` this.codeUrl = "data:image/gif;base64," + res.img;
this.loginForm.uuid = res.uuid this.loginForm.uuid = res.uuid;
} }
}).catch((error) => { });
console.error('获取验证码失败:', error)
})
}, },
getCookie() { getCookie() {
const username = Cookies.get('username') const username = Cookies.get('username')
@ -141,22 +141,44 @@
} }
}, },
handleLogin() { handleLogin() {
this.$refs.loginForm.validate((valid) => { this.$refs.loginForm.validate(valid => {
if (valid) { if (valid) {
this.loading = true; this.loading = true;
if (this.loginForm.rememberMe) { if (this.loginForm.rememberMe) {
Cookies.set('username', this.loginForm.username, { expires: 30 }); Cookies.set("username", this.loginForm.username, { expires: 30 });
Cookies.set('password', encrypt(this.loginForm.password), { expires: 30 }); Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
} else { } else {
Cookies.remove('username'); Cookies.remove("username");
Cookies.remove('password'); Cookies.remove("password");
Cookies.remove('rememberMe'); Cookies.remove('rememberMe');
} }
// 2048 RSA
const lines = [];
lines.push('-----BEGIN PUBLIC KEY-----');
for (let i = 0; i < this.a1.length; i += 64) {
lines.push(this.a1.slice(i, i + 64));
}
lines.push('-----END PUBLIC KEY-----');
lines.join('\n')
const publicKey = forge.pki.publicKeyFromPem(lines.join('\n'));
//
var dataBytes = forge.util.encodeUtf8(this.loginForm.password);
//
var encryptedBytes = publicKey.encrypt(dataBytes, 'RSA-OAEP', {
md: forge.md.sha256.create(),
mgf1: {
md: forge.md.sha1.create()
}
});
// Base64
var encryptedBase64 = forge.util.encode64(encryptedBytes);
//
const loginData = { const loginData = {
username: this.loginForm.username, username: this.loginForm.username,
password: this.loginForm.password, password: encryptedBase64,
code: this.loginForm.code, code: this.loginForm.code,
uuid: this.loginForm.uuid, uuid: this.loginForm.uuid,
loginRole: this.activeName === 'first' ? 2 : 1 loginRole: this.activeName === 'first' ? 2 : 1
@ -173,16 +195,15 @@
} }
console.error('登录失败:', error); console.error('登录失败:', error);
}); });
} }
}); });
}, },
handleGovernmentLogin() { handleGovernmentLogin() {
// window.location.href = 'https://qyt.sipac.gov.cn/sipsg-enterprise-mobile-manage/#/login'
window.location.href = 'https://qyt.sipac.gov.cn/';
}, },
handleEnterpriseLogin() { handleEnterpriseLogin() {
// window.location.href = 'https://gysl.sipac.gov.cn';
// window.location.href = 'https://example.com/enterprise-login';
} }
} }
} }

Loading…
Cancel
Save