This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/Login.vue

194 lines
4.9 KiB
Vue
Raw Normal View History

2021-06-07 18:35:16 +08:00
<template>
2021-06-30 15:30:55 +08:00
<div class="logins">
2021-06-30 11:30:13 +08:00
<div class="inside">
<div class="title">
2021-06-30 15:30:55 +08:00
<img src="../public/images/cion.png" />
2021-06-30 11:30:13 +08:00
</div>
2021-06-30 17:50:19 +08:00
<el-form class="login__box">
2021-06-30 11:30:13 +08:00
<el-form-item>
<el-input
prefix-icon="el-icon-user"
class="login--input login__input"
2021-06-30 11:30:13 +08:00
v-model="username"
></el-input>
</el-form-item>
<el-form-item>
<el-input
class="login--input"
2021-06-30 11:30:13 +08:00
prefix-icon="el-icon-lock"
type="password"
@keyup.enter="login"
2021-06-30 11:30:13 +08:00
v-model="pin"
></el-input>
</el-form-item>
<el-form-item>
<el-button
2021-06-30 17:32:20 +08:00
v-loading="loading"
2021-06-30 15:30:55 +08:00
type="primary"
class="login--input login--button"
@click="login"
@keyup.enter="login"
2021-07-05 22:58:12 +08:00
style="font-size: 16px;"
>Login</el-button
2021-06-30 11:30:13 +08:00
>
</el-form-item>
</el-form>
</div>
2021-06-11 10:00:22 +08:00
</div>
2021-06-07 18:35:16 +08:00
</template>
<script>
2021-06-11 10:00:22 +08:00
import { mapActions } from 'vuex'
import { post, get } from '@/utils/http'
2022-04-13 10:14:36 +08:00
import { useRouter } from 'vue-router'
import { storageKey } from '@/utils/constants'
import { api } from '@/utils/api'
import dayjs from 'dayjs'
import _ from 'lodash'
import utc from 'dayjs/plugin/utc'
dayjs.extend(utc)
2021-06-07 18:35:16 +08:00
export default {
2021-06-11 10:00:22 +08:00
name: 'Login',
data () {
return {
2021-06-30 17:39:36 +08:00
loading: false,
2021-08-11 22:14:23 +08:00
username: '',
pin: ''
2021-06-11 10:00:22 +08:00
}
},
methods: {
...mapActions(['loginSuccess']),
login () {
2021-08-11 22:14:23 +08:00
if (!this.username || !this.pin) {
return
}
if (!this.blockOperation.query) {
this.blockOperation.query = true
} else {
return
}
this.loading = true
2022-04-14 17:22:48 +08:00
post(api.login, { username: this.username, pin: this.pin }).then(
2021-06-30 11:30:13 +08:00
res => {
2021-08-26 17:14:51 +08:00
if (res.code === 200) {
if (!_.isEmpty(res.data.lang)) {
localStorage.setItem(storageKey.language, res.data.lang)
}
if (!_.isEmpty(res.data.theme)) {
localStorage.setItem(storageKey.theme, res.data.theme)
}
res.loginSuccessPath = this.$route.query.redirect
2021-07-01 15:39:48 +08:00
this.loginSuccess(res)
localStorage.setItem(storageKey.username, this.username)
2022-08-04 12:03:15 +08:00
localStorage.setItem(storageKey.userId, '1')
localStorage.setItem(storageKey.token, res.data.token)
2021-08-26 17:14:51 +08:00
} else if (res.code === 518005) {
2021-08-29 22:19:26 +08:00
this.$message.error(this.$t('Incorrect username or password'))
2021-08-27 16:45:03 +08:00
this.loading = false
this.blockOperation.query = false
} else {
2021-08-29 22:19:26 +08:00
this.$message.error('Unknown error')
2021-08-27 16:45:03 +08:00
this.loading = false
this.blockOperation.query = false
2021-07-01 15:39:48 +08:00
}
2021-06-11 10:00:22 +08:00
}
2021-08-26 18:33:49 +08:00
).catch(e => {
console.error(e)
2021-08-26 17:14:51 +08:00
this.loading = false
this.blockOperation.query = false
2021-08-26 18:33:49 +08:00
this.$message.error(this.$t('tip.unknownError'))
2021-08-26 17:14:51 +08:00
})
},
queryAppearance () {
get(api.appearance).then(res => {
if (res.code === 200) {
this.appearanceOut(res.data)
}
})
},
appearanceOut (data) {
if (_.isEmpty(localStorage.getItem(storageKey.language))) {
localStorage.setItem(storageKey.language, data.lang || 'zh')
}
if (_.isEmpty(localStorage.getItem(storageKey.theme))) {
localStorage.setItem(storageKey.theme, data.theme || 'light')
}
localStorage.setItem(storageKey.s3Enable, data.s3_enable)
localStorage.setItem(storageKey.sysTimezone, data.timezone)
window.$dayJs.tz.setDefault(data.timezone)
localStorage.setItem(storageKey.timezoneOffset, window.$dayJs.tz().utcOffset() / 60)
localStorage.setItem(storageKey.timezoneLocalOffset, dayjs().utcOffset() / 60)
localStorage.setItem(storageKey.dateFormat, data.dateFormat)
localStorage.setItem(storageKey.sysName, data.system_name)
localStorage.setItem(storageKey.sysLogo, data.system_logo)
2021-06-11 10:00:22 +08:00
}
},
mounted () {
this.queryAppearance()
2022-04-13 10:14:36 +08:00
},
setup (props) {
const { currentRoute } = useRouter()
return {
loginSuccessPath: currentRoute.value.query.redirect
}
2021-06-11 10:00:22 +08:00
}
2021-06-07 18:35:16 +08:00
}
</script>
<style>
2021-06-30 15:30:55 +08:00
.logins{
2021-06-30 15:45:45 +08:00
background-color: #000C18;
2021-06-30 15:30:55 +08:00
background-size: auto;
background-repeat: round;
2021-06-30 11:30:13 +08:00
background-image: url('../public/images/bg.png');
display: flex;
2021-06-30 15:45:45 +08:00
height: 100%;
2021-06-30 11:30:13 +08:00
justify-content: center;
align-items: center;
margin: auto;
}
.inside {
opacity: 0.78;
background: #051a37;
border-radius: 6px;
width: 368px;
height: 400px;
/* margin-top:340px; */
}
.inside > div {
display: block;
}
2021-06-07 18:35:16 +08:00
2021-06-30 11:30:13 +08:00
.title {
margin-top: 70px;
text-align: center;
}
.title > img {
height: 43px;
width: 248px;
2021-06-30 11:30:13 +08:00
}
.login--input{
2021-06-30 15:30:55 +08:00
width: 300px;
height: 40px;
}
2021-06-30 17:50:19 +08:00
.login__input:first-of-type{
2021-06-30 15:30:55 +08:00
margin-top: 45.57px;
}
2021-06-30 17:50:19 +08:00
.login__box{
2021-06-30 15:30:55 +08:00
width: 300px;
height: 250px;
margin: auto;
}
.login--button {
2021-06-30 11:30:13 +08:00
background: #0091ff;
color: #fff;
border-radius: 4px;
2021-07-05 17:40:43 +08:00
border: 0;
2021-06-30 11:30:13 +08:00
font-weight: 400;
text-align: center;
}
2021-06-07 18:35:16 +08:00
</style>