Merge branch 'main' of https://dd3skj.picp.vip/JyuHsin/zhgh_cug_v4
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
prefix-icon="el-icon-lock"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="platformCaptcha">
|
||||
<el-form-item v-if="!captchaDisabled" prop="platformCaptcha">
|
||||
<el-input
|
||||
v-model="loginForm.platformCaptcha"
|
||||
auto-complete="off"
|
||||
@@ -124,11 +124,14 @@
|
||||
}
|
||||
</script>
|
||||
<script nonce="${cspNonce!}">
|
||||
const DISABLE_LOGIN_CAPTCHA = ["localhost", "127.0.0.1", "::1"].includes(window.location.hostname)
|
||||
|
||||
new Vue({
|
||||
el: "#app",
|
||||
data() {
|
||||
return {
|
||||
codeUrl: "",
|
||||
captchaDisabled: DISABLE_LOGIN_CAPTCHA,
|
||||
loginForm: {
|
||||
username: "",
|
||||
password: "",
|
||||
@@ -138,17 +141,21 @@
|
||||
loginRules: {
|
||||
username: [{ required: true, trigger: ["blur", "change"], message: "账号不能为空" }],
|
||||
password: [{ required: true, trigger: ["blur", "change"], message: "密码不能为空" }],
|
||||
platformCaptcha: [{ required: true, trigger: ["blur", "change"], message: "验证码不能为空" }]
|
||||
platformCaptcha: []
|
||||
},
|
||||
loading: false,
|
||||
rasParams: {
|
||||
publicKey: '',
|
||||
keyId: '',
|
||||
expireAt: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getCode() {
|
||||
if (this.captchaDisabled) {
|
||||
return
|
||||
}
|
||||
axios.post("/platform/login/captcha").then((resp) => {
|
||||
if (resp.data.code === 0) {
|
||||
this.codeUrl = resp.data.data.codeUrl
|
||||
@@ -159,7 +166,15 @@
|
||||
handleLogin() {
|
||||
this.$refs.loginForm.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await this.ensurePublicKey()
|
||||
const { publicKey, keyId } = this.rasParams
|
||||
if (!publicKey || !keyId) {
|
||||
this.$message({
|
||||
message: "Login key unavailable, please refresh and try again",
|
||||
type: "error"
|
||||
})
|
||||
return
|
||||
}
|
||||
// 加密密码
|
||||
const encrypt = new JSEncrypt()
|
||||
encrypt.setPublicKey(publicKey)
|
||||
@@ -200,10 +215,17 @@
|
||||
},
|
||||
// 获取公钥
|
||||
fetchPublicKey() {
|
||||
axios.get("/platform/login/publicKey").then(res => {
|
||||
return axios.get("/platform/login/publicKey").then(res => {
|
||||
this.rasParams = res.data.data
|
||||
})
|
||||
},
|
||||
ensurePublicKey() {
|
||||
const refreshBeforeMillis = 30 * 1000
|
||||
if (this.rasParams.publicKey && this.rasParams.keyId && Date.now() < this.rasParams.expireAt - refreshBeforeMillis) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return this.fetchPublicKey()
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.fetchPublicKey()
|
||||
|
||||
Reference in New Issue
Block a user