diff --git a/package.json b/package.json index 37a4c6f..24fa0ed 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "autofit.js": "^3.2.2", "axios": "0.28.1", "clipboard": "2.0.8", - "core-js": "3.37.1", + "core-js": "^3.42.0", "docx-preview": "^0.3.5", "echarts": "^5.4.0", "element-ui": "^2.15.13", @@ -57,10 +57,12 @@ "mars2d": "^3.3.1", "mars2d-esri": "^3.3.1", "moment": "^2.30.1", + "node-forge": "^1.3.1", "nprogress": "0.2.0", "quill": "2.0.2", + "regenerator-runtime": "^0.14.1", "screenfull": "5.0.2", - "sortablejs": "1.10.2", + "sortablejs": "^1.10.2", "splitpanes": "2.4.1", "vue": "2.6.12", "vue-count-to": "1.0.13", diff --git a/src/views/login.vue b/src/views/login.vue index e7f361d..cb19f5b 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -46,7 +46,7 @@ style="width:100%;background: #2B62F1;" @click.native.prevent="handleEnterpriseLogin"> 企业统一身份认证登录 - +
主办单位:苏州工业园区经济发展委员会
@@ -61,6 +61,7 @@ import { getCodeImg } from '@/api/login' import Cookies from 'js-cookie' import { encrypt, decrypt } from '@/utils/jsencrypt' +import forge from 'node-forge' export default { name: 'Login', @@ -86,31 +87,33 @@ export default { code: [{ required: true, trigger: 'change', message: '请输入验证码' }] }, loading: false, - // 验证码开关 captchaEnabled: true, - // 注册开关 register: false, - redirect: undefined + redirect: undefined, + a1: `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl8bS1kYTiMhIS5MZU253bc0ukaxrA1lfCziABFxQrC2c09tMrQGjuH6V1x2ofNBMGhOD9uWN/qkAQy/HwOe/NKUqCw6N0ov6guSrqMDW/BdZ3Bl0rmM1/95jTC1xffFFvej7xWNffIbaPI+bJ4WLX9NViNi9HmT0BRNzJ4d2R86LPPCa+bxLaPjsh2R2tBkbLkUot9769aJaPPiwPCZHMkuQenjHSmpWL0okleqMH8EGX7j6A5A/4IUXPMNKMMzkiSRpsIJ65GJmDAbnR3ZXRfC8MzVBBJB6zr5N0F4N9xZfF+JS/Yx726tCu+rA6GDCyTxtQ/wnKpPdwFP5nUWCWQIDAQAB` } }, watch: { - $route(route) { - this.redirect = route.query && route.query.redirect + $route: { + handler: function (route) { + this.redirect = route.query && route.query.redirect; + }, + immediate: true }, activeName(newVal) { if (newVal === 'first') { - this.loginForm.loginRole = 2; + this.loginForm.loginRole = 2 } else if (newVal === 'second') { - this.loginForm.loginRole = 1; + this.loginForm.loginRole = 1 } } }, computed: { showGovernmentLoginButton() { - return this.activeName === 'second'; + return this.activeName === 'second' }, showEnterpriseLoginButton() { - return this.activeName === 'first'; + return this.activeName === 'first' } }, created() { @@ -119,15 +122,13 @@ export default { }, methods: { getCode() { - getCodeImg().then((res) => { - this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled + getCodeImg().then(res => { + this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled; if (this.captchaEnabled) { - this.codeUrl = `data:image/gif;base64,${res.img}` - this.loginForm.uuid = res.uuid + this.codeUrl = "data:image/gif;base64," + res.img; + this.loginForm.uuid = res.uuid; } - }).catch((error) => { - console.error('获取验证码失败:', error) - }) + }); }, getCookie() { const username = Cookies.get('username') @@ -140,25 +141,47 @@ export default { } }, handleLogin() { - this.$refs.loginForm.validate((valid) => { + this.$refs.loginForm.validate(valid => { + if (valid) { this.loading = true; if (this.loginForm.rememberMe) { - Cookies.set('username', this.loginForm.username, { expires: 30 }); - Cookies.set('password', encrypt(this.loginForm.password), { expires: 30 }); + Cookies.set("username", this.loginForm.username, { expires: 30 }); + Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }); Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); } else { - Cookies.remove('username'); - Cookies.remove('password'); + Cookies.remove("username"); + Cookies.remove("password"); 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 = { username: this.loginForm.username, - password: this.loginForm.password, + password: encryptedBase64, code: this.loginForm.code, uuid: this.loginForm.uuid, - loginRole: this.activeName === 'first' ? 2 : 1 + loginRole: this.activeName === 'first' ? 2 : 1 }; this.$store.dispatch('Login', loginData) @@ -172,15 +195,15 @@ export default { } console.error('登录失败:', error); }); + } }); }, handleGovernmentLogin() { - // 跳转到政务统一身份认证登录页面 - window.location.href = 'https://qyt.sipac.gov.cn/'; + window.location.href = 'https://qyt.sipac.gov.cn/' }, handleEnterpriseLogin() { - // 跳转到企业统一身份认证登录页面 + // 示例跳转 // window.location.href = 'https://example.com/enterprise-login'; } }