Skip to content

Commit

Permalink
refactor: login page (halo-dev#238)
Browse files Browse the repository at this point in the history
* refactor: login page

* feat: halo-dev#130
  • Loading branch information
ruibaby authored Aug 30, 2020
1 parent 121776d commit 2cfe229
Show file tree
Hide file tree
Showing 28 changed files with 485 additions and 487 deletions.
108 changes: 28 additions & 80 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"name": "halo-admin",
"version": "1.4.0-beta.2",
"author": "halo-dev",
"description": "Halo admin client.",
"repository": {
"type": "git",
"url": "git+https://github.com/halo-dev/halo-admin.git"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/halo-dev/halo-admin/issues"
},
"homepage": "https://github.com/halo-dev/halo-admin#readme",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
Expand Down Expand Up @@ -137,16 +148,5 @@
"> 1%",
"last 2 versions",
"not ie <= 10"
],
"description": "Halo admin client.",
"repository": {
"type": "git",
"url": "git+https://github.com/halo-dev/halo-admin.git"
},
"author": "halo-dev",
"license": "ISC",
"bugs": {
"url": "https://github.com/halo-dev/halo-admin/issues"
},
"homepage": "https://github.com/halo-dev/halo-admin#readme"
}
]
}
2 changes: 1 addition & 1 deletion src/components/Attachment/AttachmentSelectDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default {
this.queryParam.sort = this.pagination.sort
attachmentApi
.query(this.queryParam)
.then(response => {
.then((response) => {
this.attachments = response.data.data.content
this.pagination.total = response.data.data.total
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/MarkdownEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
handleAttachmentUpload(pos, $file) {
var formdata = new FormData()
formdata.append('file', $file)
attachmentApi.upload(formdata).then(response => {
attachmentApi.upload(formdata).then((response) => {
var responseObject = response.data
var HaloEditor = this.$refs.md
HaloEditor.$img2Url(pos, encodeURI(responseObject.data.path))
Expand Down
14 changes: 5 additions & 9 deletions src/components/Ellipsis/Ellipsis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,23 @@ export default {
},
methods: {
getStrDom(str, fullLength) {
return (
<span>{ cutStrByFullLength(str, this.length) + (fullLength > this.length ? '...' : '') }</span>
)
return <span>{cutStrByFullLength(str, this.length) + (fullLength > this.length ? '...' : '')}</span>
},
getTooltip(fullStr, fullLength) {
return (
<Tooltip>
<template slot="title">{ fullStr }</template>
{ this.getStrDom(fullStr, fullLength) }
<template slot="title">{fullStr}</template>
{this.getStrDom(fullStr, fullLength)}
</Tooltip>
)
}
},
render() {
const { tooltip, length } = this.$props
const str = this.$slots.default.map(vNode => vNode.text).join('')
const str = this.$slots.default.map((vNode) => vNode.text).join('')
const fullLength = getStrFullLength(str)
const strDom = tooltip && fullLength > length ? this.getTooltip(str, fullLength) : this.getStrDom(str, fullLength)
return (
strDom
)
return strDom
}
}
</script>
8 changes: 4 additions & 4 deletions src/components/FooterToolbar/index.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import "../index";
@import '../index';

@footer-toolbar-prefix-cls: ~"@{ant-pro-prefix}-footer-toolbar";
@footer-toolbar-prefix-cls: ~'@{ant-pro-prefix}-footer-toolbar';

.@{footer-toolbar-prefix-cls} {
position: fixed;
Expand All @@ -16,8 +16,8 @@
z-index: 1000;

&:after {
content: "";
content: '';
display: block;
clear: both;
}
}
}
162 changes: 162 additions & 0 deletions src/components/Login/LoginForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<template>
<div>
<a-form-model
ref="loginForm"
:model="form.model"
:rules="form.rules"
layout="vertical"
@keyup.enter.native="handleLogin"
>
<a-form-model-item
v-if="!form.needAuthCode"
class="animated fadeInUp"
:style="{'animation-delay': '0.1s'}"
prop="username"
>
<a-input
placeholder="用户名/邮箱"
v-model="form.model.username"
>
<a-icon
slot="prefix"
type="user"
style="color: rgba(0,0,0,.25)"
/>
</a-input>
</a-form-model-item>
<a-form-model-item
v-if="!form.needAuthCode"
class="animated fadeInUp"
:style="{'animation-delay': '0.2s'}"
prop="password"
>
<a-input
v-model="form.model.password"
type="password"
placeholder="密码"
>
<a-icon
slot="prefix"
type="lock"
style="color: rgba(0,0,0,.25)"
/>
</a-input>
</a-form-model-item>
<a-form-model-item
v-if="form.needAuthCode"
class="animated fadeInUp"
:style="{'animation-delay': '0.1s'}"
prop="authcode"
>
<a-input
placeholder="两步验证码"
v-model="form.model.authcode"
:maxLength="6"
>
<a-icon
slot="prefix"
type="safety-certificate"
style="color: rgba(0,0,0,.25)"
/>
</a-input>
</a-form-model-item>
<a-form-model-item
class="animated fadeInUp"
:style="{'animation-delay': '0.3s'}"
>
<a-button
:loading="form.logging"
type="primary"
:block="true"
@click="handleLoginClick"
>{{ buttonName }}</a-button>
</a-form-model-item>
</a-form-model>
</div>
</template>
<script>
import adminApi from '@/api/admin'
import { mapActions } from 'vuex'
export default {
name: 'LoginForm',
data() {
const authcodeValidate = (rule, value, callback) => {
if (!value && this.form.needAuthCode) {
callback(new Error('* 请输入两步验证码'))
} else {
callback()
}
}
return {
form: {
model: {
authcode: null,
password: null,
username: null
},
rules: {
username: [{ required: true, message: '* 用户名/邮箱不能为空', trigger: ['change'] }],
password: [{ required: true, message: '* 密码不能为空', trigger: ['change'] }],
authcode: [{ validator: authcodeValidate, trigger: ['change'] }]
},
needAuthCode: false,
logging: false
}
}
},
computed: {
buttonName() {
return this.form.needAuthCode ? '验证' : '登录'
}
},
methods: {
...mapActions(['login', 'refreshUserCache', 'refreshOptionsCache']),
handleLoginClick() {
const _this = this
_this.$refs.loginForm.validate((valid) => {
if (valid) {
_this.form.logging = true
if (_this.form.needAuthCode && _this.form.model.authcode) {
_this.handleLogin()
} else {
adminApi
.loginPreCheck(_this.form.model.username, _this.form.model.password)
.then((response) => {
const data = response.data.data
if (data && data.needMFACode) {
_this.form.needAuthCode = true
_this.form.model.authcode = null
} else {
_this.handleLogin()
}
})
.finally(() => {
setTimeout(() => {
_this.form.logging = false
}, 300)
})
}
}
})
},
handleLogin() {
const _this = this
_this.form.logging = true
_this.$refs.loginForm.validate((valid) => {
if (valid) {
_this
.login(_this.form.model)
.then((response) => {
_this.$emit('success')
})
.finally(() => {
setTimeout(() => {
_this.form.logging = false
}, 300)
})
}
})
}
}
}
</script>
Loading

0 comments on commit 2cfe229

Please sign in to comment.