fix: login page keyboard shortcut keys not working in macOS. (#352)

pull/353/head
Ryan Wang 2021-09-14 20:45:51 +08:00 committed by GitHub
parent 66955f94d8
commit 74eeaeca55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 30 deletions

View File

@ -9,42 +9,43 @@
> >
<a-form-model-item <a-form-model-item
v-if="!form.needAuthCode" v-if="!form.needAuthCode"
class="animated fadeInUp"
:style="{ 'animation-delay': '0.1s' }" :style="{ 'animation-delay': '0.1s' }"
class="animated fadeInUp"
prop="username" prop="username"
> >
<a-input placeholder="用户名/邮箱" v-model="form.model.username"> <a-input v-model="form.model.username" placeholder="用户名/邮箱">
<a-icon slot="prefix" type="user" style="color: rgba(0,0,0,.25)" /> <a-icon slot="prefix" style="color: rgba(0,0,0,.25)" type="user" />
</a-input> </a-input>
</a-form-model-item> </a-form-model-item>
<a-form-model-item <a-form-model-item
v-if="!form.needAuthCode" v-if="!form.needAuthCode"
class="animated fadeInUp"
:style="{ 'animation-delay': '0.2s' }" :style="{ 'animation-delay': '0.2s' }"
class="animated fadeInUp"
prop="password" prop="password"
> >
<a-input v-model="form.model.password" type="password" placeholder="密码"> <a-input v-model="form.model.password" placeholder="密码" type="password">
<a-icon slot="prefix" type="lock" style="color: rgba(0,0,0,.25)" /> <a-icon slot="prefix" style="color: rgba(0,0,0,.25)" type="lock" />
</a-input> </a-input>
</a-form-model-item> </a-form-model-item>
<a-form-model-item <a-form-model-item
v-if="form.needAuthCode" v-if="form.needAuthCode"
class="animated fadeInUp"
:style="{ 'animation-delay': '0.1s' }" :style="{ 'animation-delay': '0.1s' }"
class="animated fadeInUp"
prop="authcode" prop="authcode"
> >
<a-input placeholder="两步验证码" v-model="form.model.authcode" :maxLength="6"> <a-input v-model="form.model.authcode" :maxLength="6" placeholder="两步验证码">
<a-icon slot="prefix" type="safety-certificate" style="color: rgba(0,0,0,.25)" /> <a-icon slot="prefix" style="color: rgba(0,0,0,.25)" type="safety-certificate" />
</a-input> </a-input>
</a-form-model-item> </a-form-model-item>
<a-form-model-item class="animated fadeInUp" :style="{ 'animation-delay': '0.3s' }"> <a-form-model-item :style="{ 'animation-delay': '0.3s' }" class="animated fadeInUp">
<a-button <a-button
:block="true"
:loading="form.logging" :loading="form.logging"
type="primary" type="primary"
:block="true"
@click="form.needAuthCode ? handleLogin() : handleLoginClick()" @click="form.needAuthCode ? handleLogin() : handleLoginClick()"
>{{ buttonName }}</a-button
> >
{{ buttonName }}
</a-button>
</a-form-model-item> </a-form-model-item>
</a-form-model> </a-form-model>
</div> </div>
@ -52,6 +53,7 @@
<script> <script>
import adminApi from '@/api/admin' import adminApi from '@/api/admin'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
export default { export default {
name: 'LoginForm', name: 'LoginForm',
data() { data() {

View File

@ -13,7 +13,7 @@ export const deviceEnquire = function(callback) {
} }
} }
const matchLablet = { const matchTablet = {
match: () => { match: () => {
callback && callback(DEVICE_TYPE.TABLET) callback && callback(DEVICE_TYPE.TABLET)
} }
@ -28,6 +28,6 @@ export const deviceEnquire = function(callback) {
// screen and (max-width: 1087.99px) // screen and (max-width: 1087.99px)
enquireJs enquireJs
.register('screen and (max-width: 576px)', matchMobile) .register('screen and (max-width: 576px)', matchMobile)
.register('screen and (min-width: 576px) and (max-width: 1199px)', matchLablet) .register('screen and (min-width: 576px) and (max-width: 1199px)', matchTablet)
.register('screen and (min-width: 1200px)', matchDesktop) .register('screen and (min-width: 1200px)', matchDesktop)
} }

View File

@ -11,11 +11,11 @@
<a-row> <a-row>
<a-col :span="24"> <a-col :span="24">
<router-link :to="{ name: 'ResetPassword' }"> <router-link :to="{ name: 'ResetPassword' }">
<a class="tip animated fadeInRight" v-if="resetPasswordButtonVisible" href="javascript:void(0);"> <a v-if="resetPasswordButtonVisible" class="tip animated fadeInRight" href="javascript:void(0);">
找回密码 找回密码
</a> </a>
</router-link> </router-link>
<a @click="handleToggleShowApiForm" class="tip animated fadeInUp" :style="{ 'animation-delay': '0.4s' }"> <a :style="{ 'animation-delay': '0.4s' }" class="tip animated fadeInUp" @click="handleToggleShowApiForm">
<a-icon type="setting" /> <a-icon type="setting" />
</a> </a>
</a-col> </a-col>
@ -23,21 +23,21 @@
</div> </div>
<div v-show="apiForm.visible" class="api-form animated"> <div v-show="apiForm.visible" class="api-form animated">
<a-form layout="vertical"> <a-form layout="vertical">
<a-form-item class="animated fadeInUp" :style="{ 'animation-delay': '0.1s' }"> <a-form-item :style="{ 'animation-delay': '0.1s' }" class="animated fadeInUp">
<a-tooltip placement="top" title="如果 Admin 不是独立部署,请不要更改此 API" trigger="click"> <a-tooltip placement="top" title="如果 Admin 不是独立部署,请不要更改此 API" trigger="click">
<a-input placeholder="API 地址" v-model="apiForm.apiUrl"> <a-input v-model="apiForm.apiUrl" placeholder="API 地址">
<a-icon slot="prefix" type="api" style="color: rgba(0,0,0,.25)" /> <a-icon slot="prefix" style="color: rgba(0,0,0,.25)" type="api" />
</a-input> </a-input>
</a-tooltip> </a-tooltip>
</a-form-item> </a-form-item>
<a-form-item class="animated fadeInUp" :style="{ 'animation-delay': '0.2s' }"> <a-form-item :style="{ 'animation-delay': '0.2s' }" class="animated fadeInUp">
<a-button :block="true" @click="handleRestoreApiUrl"></a-button> <a-button :block="true" @click="handleRestoreApiUrl"></a-button>
</a-form-item> </a-form-item>
<a-form-item class="animated fadeInUp" :style="{ 'animation-delay': '0.3s' }"> <a-form-item :style="{ 'animation-delay': '0.3s' }" class="animated fadeInUp">
<a-button type="primary" :block="true" @click="handleModifyApiUrl"></a-button> <a-button :block="true" type="primary" @click="handleModifyApiUrl"></a-button>
</a-form-item> </a-form-item>
<a-row> <a-row>
<a @click="handleToggleShowApiForm" class="tip animated fadeInUp" :style="{ 'animation-delay': '0.4s' }"> <a :style="{ 'animation-delay': '0.4s' }" class="tip animated fadeInUp" @click="handleToggleShowApiForm">
<a-icon type="rollback" /> <a-icon type="rollback" />
</a> </a>
</a-row> </a-row>
@ -51,6 +51,7 @@ import adminApi from '@/api/admin'
import { mapActions, mapGetters, mapMutations } from 'vuex' import { mapActions, mapGetters, mapMutations } from 'vuex'
import LoginForm from '@/components/Login/LoginForm' import LoginForm from '@/components/Login/LoginForm'
export default { export default {
components: { components: {
LoginForm LoginForm
@ -68,13 +69,11 @@ export default {
...mapGetters({ defaultApiUrl: 'apiUrl' }) ...mapGetters({ defaultApiUrl: 'apiUrl' })
}, },
beforeMount() { beforeMount() {
const _this = this this.handleVerifyIsInstall()
_this.handleVerifyIsInstall() document.addEventListener('keydown', this.onRegisterResetPasswordKeydown)
document.addEventListener('keydown', function(e) { },
if (e.keyCode === 72 && e.altKey && e.shiftKey) { beforeDestroy() {
_this.resetPasswordButtonVisible = !_this.resetPasswordButtonVisible document.removeEventListener('keydown', this.onRegisterResetPasswordKeydown)
}
})
}, },
methods: { methods: {
...mapActions(['refreshUserCache', 'refreshOptionsCache']), ...mapActions(['refreshUserCache', 'refreshOptionsCache']),
@ -82,6 +81,14 @@ export default {
setApiUrl: 'SET_API_URL', setApiUrl: 'SET_API_URL',
restoreApiUrl: 'RESTORE_API_URL' restoreApiUrl: 'RESTORE_API_URL'
}), }),
onRegisterResetPasswordKeydown(e) {
// Windows / Linux: Shift + Alt + h
// maxOS: Shift + Command + h
if (e.keyCode === 72 && (e.altKey || e.metaKey) && e.shiftKey) {
e.preventDefault()
this.resetPasswordButtonVisible = !this.resetPasswordButtonVisible
}
},
async handleVerifyIsInstall() { async handleVerifyIsInstall() {
const response = await adminApi.isInstalled() const response = await adminApi.isInstalled()
if (!response.data.data) { if (!response.data.data) {