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

383 lines
11 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">
2022-12-13 17:53:55 +08:00
<img src="../public/images/logo-title.svg" />
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
2022-12-13 17:53:55 +08:00
prefix-icon="cn-icon cn-icon-user2"
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 :disabled="licenseStatus === 0"
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"
:class="{'login-btn__license-error':licenseStatus === 0}"
@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-item v-if="licenseStatus === 0">
<div class="license-error-msg">{{licenseStatusErrMsg}}</div>
<div class="license-file">
<button style="position: relative;" class="license__btn margin-r-20" @click.prevent="downloadFile">
<i class="cn-icon-download1 cn-icon margin-r-6"></i><span>Download c2v file</span>
</button>
<el-upload :action="`${baseUrl}sys/license/upload`"
ref="licenseUpload"
id="licenseUpload"
:multiple="false"
:show-file-list="false"
:accept="fileTypeLimit"
:file-list="fileList"
:auto-upload="false"
:on-change="fileChange"
:on-success="uploadSuccess"
:on-error="uploadError">
<button style="position: relative;" class="license__btn" @click.prevent="">
<i class="cn-icon-upload1 cn-icon margin-r-6"></i><span>Upload license</span>
</button>
</el-upload>
</div>
</el-form-item>
2021-06-30 11:30:13 +08:00
</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'
2023-03-16 19:07:37 +08:00
import axios from 'axios'
2022-04-13 10:14:36 +08:00
import { useRouter } from 'vue-router'
2023-08-09 18:32:52 +08:00
import { storageKey, defaultLang } from '@/utils/constants'
import { api } from '@/utils/api'
import dayjs from 'dayjs'
import _ from 'lodash'
import utc from 'dayjs/plugin/utc'
import { ref } from 'vue'
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: '',
language: '',
licenseStatus: 1,
licenseStatusErrMsg: '',
downloadC2vUrl: api.downloadLicenseC2v,
supportID: ''
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
2023-03-16 19:07:37 +08:00
axios.post(api.login, { username: this.username, pin: this.pin }).then(
2021-06-30 11:30:13 +08:00
res => {
if (res.status === 200) {
2023-08-09 18:32:52 +08:00
if (!_.isEmpty(res.data.data.user.lang)) {
localStorage.setItem(storageKey.language, res.data.data.user.lang)
}
if (!localStorage.getItem(storageKey.language)) {
localStorage.setItem(storageKey.language, this.language)
}
2023-08-09 18:32:52 +08:00
if (!_.isEmpty(res.data.data.user.theme)) {
localStorage.setItem(storageKey.theme, res.data.data.user.theme)
}
res.loginSuccessPath = this.$route.query.redirect
2021-07-01 15:39:48 +08:00
this.loginSuccess(res)
localStorage.setItem(storageKey.username, this.username)
localStorage.setItem(storageKey.nickName, res.data.data.user.name)
// localStorage.setItem(storageKey.userId, res.data.data.user.userId)
localStorage.setItem(storageKey.userId, res.data.data.user.id)
2023-03-16 19:07:37 +08:00
localStorage.setItem(storageKey.token, res.data.data.token)
2023-08-09 18:32:52 +08:00
this.$i18n.locale = localStorage.getItem(storageKey.language)
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
if (_.get(e, 'response.data.code', 0) === 518005) {
this.$message.error(this.$t('Incorrect username or password'))
} else {
this.$message.error(this.errorMsgHandler(e))
}
2021-08-26 17:14:51 +08:00
})
},
downloadFile () {
axios.get(this.downloadC2vUrl, { responseType: 'blob' }).then(res => {
const fileName = 'CN-' + this.supportID + '-license-apply.xml'
if (window.navigator.msSaveOrOpenBlob) {
// 兼容ie11
const blobObject = new Blob([res.data])
window.navigator.msSaveOrOpenBlob(blobObject, fileName)
} else {
const url = URL.createObjectURL(new Blob([res.data]))
const a = document.createElement('a')
document.body.appendChild(a) // 此处增加了将创建的添加到body当中
a.href = url
a.download = fileName
a.target = '_blank'
a.click()
a.remove() // 将a标签移除
}
}, error => {
const $self = this
const reader = new FileReader()
reader.onload = function (event) {
const responseText = reader.result
const exception = JSON.parse(responseText)
if (exception.message) {
$self.$message.error(exception.message)
} else {
console.error(error)
}
}
reader.readAsText(error.response.data)
})
},
fileChange (file, fileList) {
if (file.status !== 'ready') return
if (!_.endsWith(file.name, '.xml')) {
this.fileList = []
this.$message.error('Only support '+ this.fileTypeLimit + ' files')
} else {
this.fileList = fileList.slice(-1)
this.$refs.licenseUpload.submit()
}
},
uploadSuccess (response) {
this.$message.success('Success')
this.licenseStatus = 1
},
uploadError (error) {
let errorMsg
if (error.message) {
errorMsg = JSON.parse(error.message).message
} else {
errorMsg = 'error'
}
this.$message.error('Upload failed: ' + errorMsg)
},
checkLicenseStatus () {
axios.get(api.licenseStatus).then(res => {
if (res.status === 200) {
this.licenseStatus = res.data.status
}
}).catch(e => {
this.licenseStatusErrMsg = this.errorMsgHandler(e)
})
},
queryAppearance () {
axios.get(api.appearance).then(res => {
if (res.status === 200) {
this.appearanceOut(res.data.data)
}
})
},
appearanceOut (data) {
this.language = data.lang || defaultLang
if (_.isEmpty(localStorage.getItem(storageKey.language))) {
2023-08-09 18:32:52 +08:00
localStorage.setItem(storageKey.language, data.lang || defaultLang)
}
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.date_format)
localStorage.setItem(storageKey.sysName, data.system_name)
localStorage.setItem(storageKey.sysLogo, data.system_logo)
2021-06-11 10:00:22 +08:00
}
},
async mounted () {
this.queryAppearance()
this.checkLicenseStatus()
await axios.get(api.license).then(res => {
if (res.status === 200) {
this.supportID = res.data.data.license.supportID
}
}).catch(e => {
console.log(e)
})
2022-04-13 10:14:36 +08:00
},
setup (props) {
const { currentRoute } = useRouter()
return {
loginSuccessPath: currentRoute.value.query.redirect,
baseUrl: BASE_CONFIG.baseUrl,
fileTypeLimit: '.xml',
fileList: ref([])
2022-04-13 10:14:36 +08:00
}
2021-06-11 10:00:22 +08:00
}
2021-06-07 18:35:16 +08:00
}
</script>
2022-12-13 17:53:55 +08:00
<style scoped>
.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;
2022-12-13 17:53:55 +08:00
height: 100%;
2021-06-30 11:30:13 +08:00
justify-content: center;
align-items: center;
}
:deep .el-input__inner {
2022-12-13 17:53:55 +08:00
background-color: #0B325C !important;
border: none;
border-radius: 0px;
border-bottom: 1px solid #295688;
font-size: 14px;
line-height: 14px;
}
:deep .el-input__inner:hover {
2022-12-13 17:53:55 +08:00
border-color: #295688;
}
:deep .el-input__inner:focus {
2022-12-13 17:53:55 +08:00
border-color: #295688;
}
.el-button--primary:hover, .el-button--primary:focus, .el-button--primary:active {
background: #21B4ED;
border-color: #21B4ED;
color: #FFFFFF;
}
:deep .el-loading-mask {
2022-12-13 17:53:55 +08:00
background-color: transparent;
}
:deep input {
2022-12-13 17:53:55 +08:00
-webkit-text-fill-color: rgba(231,234,237, .8) !important;
transition: background-color 500000000000000000s ease-in-out 0s !important;
caret-color: #fff ;
}
2021-06-30 11:30:13 +08:00
.inside {
2022-12-13 17:53:55 +08:00
width: 414px;
height: fit-content;/*524*/
2022-12-13 17:53:55 +08:00
background: #0B325C;
border: 1px solid rgba(103,179,245,0.65);
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.38);
border-radius: 4px;
}
.inside {
display: flex;
flex-direction: column;
justify-content: space-between;
2021-06-30 11:30:13 +08:00
}
.inside > div {
display: block;
}
2021-06-07 18:35:16 +08:00
2021-06-30 11:30:13 +08:00
.title {
2022-12-13 17:53:55 +08:00
margin-top: 65px;
margin-bottom: 44px;
text-align: center;
}
.title > img {
2022-12-13 17:53:55 +08:00
height: 135px;
}
.login__box {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
.is-disabled {
background: #21B4ED;
color: #FFFFFF;
opacity: 0.6;
}
.license-error-msg {
color:#c73249;
display: flex;
align-items: flex-start;
justify-content: center;
height:40px;
}
.license-file {
display: flex;
flex-direction: row;
height: 100%;
align-items: center;
justify-content: space-between;
.license__btn {
height: 40px;
padding-left:10px;
padding-right:10px;
min-width: 74px;
color: white;
background-color: #21B4ED;
border: none;
border-radius: 4px;
outline: none;
font-size: 14px;
cursor: pointer;
transition: background-color linear .2s, color linear .1s;
}
}
2022-12-13 17:53:55 +08:00
}
:deep .el-form-item {
2022-12-13 17:53:55 +08:00
width: 334px;
margin-bottom: 25px;
}
:deep .el-input__prefix {
2022-12-13 17:53:55 +08:00
color: #6DBBFF;
}
:deep .el-input__prefix i {
2022-12-13 17:53:55 +08:00
width: 17px;
font-size: 17px;
}
.login__box .el-form-item:nth-child(3){
margin-bottom: 0px;
2022-12-13 17:53:55 +08:00
}
.login--button {
2022-12-13 17:53:55 +08:00
background: #21B4ED;
2021-06-30 11:30:13 +08:00
border-radius: 4px;
2021-07-05 17:40:43 +08:00
border: 0;
2021-06-30 11:30:13 +08:00
font-weight: 400;
2022-12-13 17:53:55 +08:00
font-size: 16px;
color: #FFFFFF;
line-height: 22px;
width: 334px;
height: 52px;
margin-top: 25px;
margin-bottom:65px;
}
.login-btn__license-error {
margin-top: 25px;
margin-bottom: 10px;
height:40px;
2021-06-30 11:30:13 +08:00
}
2021-06-07 18:35:16 +08:00
</style>