This commit is contained in:
2026-07-22 13:55:54 +08:00
@@ -52,7 +52,7 @@
prefix-icon="el-icon-lock" prefix-icon="el-icon-lock"
></el-input> ></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="platformCaptcha"> <el-form-item v-if="!captchaDisabled" prop="platformCaptcha">
<el-input <el-input
v-model="loginForm.platformCaptcha" v-model="loginForm.platformCaptcha"
auto-complete="off" auto-complete="off"
@@ -124,11 +124,14 @@
} }
</script> </script>
<script nonce="${cspNonce!}"> <script nonce="${cspNonce!}">
const DISABLE_LOGIN_CAPTCHA = ["localhost", "127.0.0.1", "::1"].includes(window.location.hostname)
new Vue({ new Vue({
el: "#app", el: "#app",
data() { data() {
return { return {
codeUrl: "", codeUrl: "",
captchaDisabled: DISABLE_LOGIN_CAPTCHA,
loginForm: { loginForm: {
username: "", username: "",
password: "", password: "",
@@ -138,17 +141,21 @@
loginRules: { loginRules: {
username: [{ required: true, trigger: ["blur", "change"], message: "账号不能为空" }], username: [{ required: true, trigger: ["blur", "change"], message: "账号不能为空" }],
password: [{ required: true, trigger: ["blur", "change"], message: "密码不能为空" }], password: [{ required: true, trigger: ["blur", "change"], message: "密码不能为空" }],
platformCaptcha: [{ required: true, trigger: ["blur", "change"], message: "验证码不能为空" }] platformCaptcha: []
}, },
loading: false, loading: false,
rasParams: { rasParams: {
publicKey: '', publicKey: '',
keyId: '', keyId: '',
expireAt: 0,
}, },
} }
}, },
methods: { methods: {
getCode() { getCode() {
if (this.captchaDisabled) {
return
}
axios.post("/platform/login/captcha").then((resp) => { axios.post("/platform/login/captcha").then((resp) => {
if (resp.data.code === 0) { if (resp.data.code === 0) {
this.codeUrl = resp.data.data.codeUrl this.codeUrl = resp.data.data.codeUrl
@@ -159,7 +166,15 @@
handleLogin() { handleLogin() {
this.$refs.loginForm.validate(async (valid) => { this.$refs.loginForm.validate(async (valid) => {
if (valid) { if (valid) {
await this.ensurePublicKey()
const { publicKey, keyId } = this.rasParams 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() const encrypt = new JSEncrypt()
encrypt.setPublicKey(publicKey) encrypt.setPublicKey(publicKey)
@@ -200,10 +215,17 @@
}, },
// 获取公钥 // 获取公钥
fetchPublicKey() { fetchPublicKey() {
axios.get("/platform/login/publicKey").then(res => { return axios.get("/platform/login/publicKey").then(res => {
this.rasParams = res.data.data 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() { created() {
this.fetchPublicKey() this.fetchPublicKey()