diff --git a/epmet-oper-web/.env.production b/epmet-oper-web/.env.production index 6592f04..5b72f6d 100644 --- a/epmet-oper-web/.env.production +++ b/epmet-oper-web/.env.production @@ -1,4 +1,4 @@ NODE_ENV=production VUE_APP_API_SERVER = https://epmet-cloud.elinkservice.cn/api VUE_APP_NODE_ENV=prod -VUE_APP_PUBLIC_PATH=epmet-oper \ No newline at end of file +VUE_APP_PUBLIC_PATH=epmet-oper diff --git a/epmet-oper-web/src/utils/index.js b/epmet-oper-web/src/utils/index.js index 80486e0..be79995 100644 --- a/epmet-oper-web/src/utils/index.js +++ b/epmet-oper-web/src/utils/index.js @@ -1,5 +1,6 @@ import Cookies from 'js-cookie' import store from '@/js/store' +import JSEncrypt from 'jsencrypt' //引入加密 /** * 获取字典数据列表 @@ -93,3 +94,13 @@ export function treeDataTranslate(data, id = 'id', pid = 'pid') { } return res } + +// 加密 +export function encryptedData(key, data) { + // 新建JSEncrypt对象 + let encryptor = new JSEncrypt() + // 设置公钥 + encryptor.setPublicKey(key) + // 加密数据 + return encryptor.encrypt(data) +} diff --git a/epmet-oper-web/src/views/main-navbar-update-password.vue b/epmet-oper-web/src/views/main-navbar-update-password.vue index b421aed..e4ac7b5 100644 --- a/epmet-oper-web/src/views/main-navbar-update-password.vue +++ b/epmet-oper-web/src/views/main-navbar-update-password.vue @@ -1,93 +1,157 @@ diff --git a/epmet-oper-web/src/views/pages/login.vue b/epmet-oper-web/src/views/pages/login.vue index 4f07493..5f4a49e 100644 --- a/epmet-oper-web/src/views/pages/login.vue +++ b/epmet-oper-web/src/views/pages/login.vue @@ -7,11 +7,13 @@

{{ $t('login.title') }}

- + - - - + - - - + @@ -49,39 +48,46 @@ - - - + - - {{ $t('login.title') }} + {{ $t('login.title') }}
@@ -92,12 +98,13 @@ import Cookies from 'js-cookie' import debounce from 'lodash/debounce' import { messages } from '@/i18n' -import { getUUID } from '@/utils' +import { getUUID, encryptedData } from '@/utils' export default { - data () { + data() { return { i18nMessages: messages, captchaPath: '', + pubKey: '', dataForm: { app: 'oper', client: 'web', @@ -110,11 +117,9 @@ export default { } }, computed: { - dataRule () { + dataRule() { return { - phone: [ - { required: true, message: '手机号不能为空', trigger: 'blur' } - ], + phone: [{ required: true, message: '手机号不能为空', trigger: 'blur' }], password: [ { required: true, message: '密码不能为空', trigger: 'blur' } ], @@ -124,32 +129,63 @@ export default { } } }, - created () { + created() { this.getCaptcha() + + //获取公钥 + this.getPubKey() }, methods: { // 获取验证码 - getCaptcha () { + getCaptcha() { this.dataForm.uuid = getUUID() this.captchaPath = `${window.SITE_CONFIG['apiURL']}/auth/login/captcha?uuid=${this.dataForm.uuid}` }, - // 表单提交 - dataFormSubmitHandle: debounce(function () { - this.$refs['dataForm'].validate((valid, messageObj) => { - if (!valid) { - app.util.validateRule(messageObj) - } - this.$http.post('/auth/login/operweb/loginbypassword', this.dataForm).then(({ data: res }) => { + + // 获取公钥 + getPubKey() { + this.$http + .post('/auth/govweb/getKey') + .then(({ data: res }) => { if (res.code !== 0) { - this.getCaptcha() return this.$message.error(res.msg) } - localStorage.setItem('userType', 'oper') - Cookies.set('token', res.data.token) - this.$router.replace({ name: 'home' }).catch(() => { }) - }).catch(() => { }) - }) - }, 1000, { 'leading': true, 'trailing': false }) + + this.pubKey = res.data // 获取到公钥; + }) + .catch(() => {}) + }, + + // 表单提交 + dataFormSubmitHandle: debounce( + function () { + this.$refs['dataForm'].validate((valid, messageObj) => { + if (!valid) { + app.util.validateRule(messageObj) + return + } + const { pubKey } = this + this.$http + .post('/auth/login/operweb/loginbypassword', { + ...this.dataForm, + phone: encryptedData(pubKey, this.dataForm.phone), + password: encryptedData(pubKey, this.dataForm.password) + }) + .then(({ data: res }) => { + if (res.code !== 0) { + this.getCaptcha() + return this.$message.error(res.msg) + } + localStorage.setItem('userType', 'oper') + Cookies.set('token', res.data.token) + this.$router.replace({ name: 'home' }).catch(() => {}) + }) + .catch(() => {}) + }) + }, + 1000, + { leading: true, trailing: false } + ) } }