<template>
|
<div class="login-right-new" :class="loginPageClass">
|
<div class="user-login">用户登录</div>
|
<el-form
|
class="login-form"
|
:rules="loginRules"
|
ref="loginForm"
|
:model="loginForm"
|
label-width="0"
|
label-position="top"
|
>
|
<div class="username">
|
<div>
|
<el-form-item prop="username" label="用户名">
|
<el-input
|
class="username-input"
|
@keyup.enter="handleLogin"
|
v-model="loginForm.username"
|
:placeholder="$t('login.username')"
|
></el-input>
|
</el-form-item>
|
</div>
|
</div>
|
<div class="password">
|
<el-form-item prop="password" label="密码">
|
<el-input
|
@keyup.enter="handleLogin"
|
:type="showPasswordModel ? 'text' : 'password'"
|
v-model="loginForm.password"
|
:placeholder="$t('login.password')"
|
></el-input>
|
<img
|
v-if="showPasswordModel"
|
@click="showPasswordModel = !showPasswordModel"
|
src="../../assets/images/login/close-eye.png"
|
alt=""
|
/>
|
<img v-else @click="showPasswordModel = !showPasswordModel" src="../../assets/images/login/see.png" alt="" />
|
</el-form-item>
|
</div>
|
<!-- <div class="forgot-password">忘记密码</div> -->
|
<div class="get-forget-password">
|
<div></div>
|
<div class="forget-password-text" @click.prevent="forgetPasswordClick">忘记密码</div>
|
</div>
|
<div class="login-submit">
|
<el-form-item>
|
<el-button type="primary" @click.prevent="handleLogin">
|
{{ $t('login.submit') }}
|
</el-button>
|
</el-form-item>
|
</div>
|
</el-form>
|
<el-dialog
|
v-model="tipDialogVisible"
|
:width="400"
|
:close-on-click-modal="false"
|
:destroy-on-close="false"
|
class="tip-dialogs"
|
>
|
<div class="dialog-close" @click="tipDialogVisible = false">
|
<img src="../../assets/images/close.png" alt="" />
|
</div>
|
<div class="dialog-contents">
|
<div class="tip-contents">{{ tipInfo }}</div>
|
<div class="dialog-btns" v-if="tipInfo === '请联系系统管理员'" @click="tipDialogVisible = false">关闭</div>
|
<el-upload
|
v-else
|
class="btn"
|
action="/upload"
|
accept=".lic"
|
:show-file-list="false"
|
:before-upload="handleUpload"
|
>
|
<div class="dialog-btns">密钥上传</div>
|
</el-upload>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import { mapGetters } from 'vuex'
|
import { info } from '@/api/system/tenant'
|
import { getCaptcha } from '@/api/user'
|
import { getTopUrl } from '@/utils/util'
|
import { validatenull } from '@/utils/validate'
|
import { uploadLicense } from '@/api/system/dict'
|
import { ElMessage } from 'element-plus'
|
import getBaseConfig from '@/buildConfig/config'
|
|
const { userLoginTitle, userLoginPageClass } = getBaseConfig()
|
|
export default {
|
name: 'userlogin',
|
data() {
|
const self = this
|
|
return {
|
tipDialogVisible: false, // 提示联系管理员
|
tipInfo: '请联系系统管理员',
|
tenantMode: this.website.tenantMode,
|
// captchaMode: this.website.captchaMode,
|
// registerMode: this.website.oauth2.registerMode,
|
loginForm: {
|
//租户ID
|
tenantId: '000000',
|
//部门ID
|
deptId: '',
|
//角色ID
|
roleId: '',
|
//用户名
|
username: '',
|
//密码
|
password: '',
|
//账号类型
|
type: 'account',
|
//验证码的值
|
code: '',
|
//验证码的索引
|
key: '',
|
//预加载白色背景
|
image: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
|
},
|
showPasswordModel: false,
|
loginRules: {
|
tenantId: [{ required: false, message: '请输入租户ID', trigger: 'blur' }],
|
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
password: [
|
{ required: true, message: '请输入密码', trigger: 'blur' },
|
{ min: 1, message: '密码长度最少为6位', trigger: 'blur' },
|
],
|
},
|
passwordType: 'password',
|
userBox: false,
|
userForm: {
|
deptId: '',
|
roleId: '',
|
},
|
userOption: {
|
labelWidth: 70,
|
submitBtn: true,
|
emptyBtn: false,
|
submitText: '登 录',
|
column: [
|
{
|
label: '角色',
|
prop: 'roleId',
|
type: 'select',
|
props: {
|
label: 'roleName',
|
value: 'id',
|
},
|
dicUrl: '/blade-system/role/select',
|
filterable: true,
|
span: 24,
|
display: false,
|
rules: [
|
{
|
required: true,
|
message: '请选择角色',
|
trigger: 'blur',
|
},
|
],
|
},
|
{
|
label: '部门',
|
prop: 'deptId',
|
type: 'select',
|
props: {
|
label: 'deptName',
|
value: 'id',
|
},
|
dicUrl: '/blade-system/dept/select',
|
filterable: true,
|
span: 24,
|
display: false,
|
rules: [
|
{
|
required: true,
|
message: '请选择部门',
|
trigger: 'blur',
|
},
|
],
|
},
|
],
|
},
|
|
loginTitle: userLoginTitle(self.$route?.query?.xtn),
|
loginPageClass: userLoginPageClass || '',
|
}
|
},
|
created() {
|
this.getTenant()
|
this.refreshCode()
|
},
|
mounted() {
|
this.$nextTick(() => {})
|
},
|
watch: {
|
'loginForm.deptId'() {
|
const column = this.findObject(this.userOption.column, 'deptId')
|
if (this.loginForm.deptId.includes(',')) {
|
column.dicUrl = `/blade-system/dept/select?deptId=${this.loginForm.deptId}`
|
column.display = true
|
} else {
|
column.dicUrl = ''
|
}
|
},
|
'loginForm.roleId'() {
|
const column = this.findObject(this.userOption.column, 'roleId')
|
if (this.loginForm.roleId.includes(',')) {
|
column.dicUrl = `/blade-system/role/select?roleId=${this.loginForm.roleId}`
|
column.display = true
|
} else {
|
column.dicUrl = ''
|
}
|
},
|
},
|
computed: {
|
...mapGetters(['tagWel', 'userInfo']),
|
},
|
props: [],
|
methods: {
|
refreshCode() {
|
// if (this.website.captchaMode) {
|
// getCaptcha().then(res => {
|
// const data = res.data;
|
// this.loginForm.key = data.key;
|
// this.loginForm.image = data.image;
|
// });
|
// }
|
},
|
showPassword() {
|
this.passwordType === '' ? (this.passwordType = 'password') : (this.passwordType = '')
|
},
|
submitLogin(form, done) {
|
// if (!validatenull(form.deptId)) {
|
// this.loginForm.deptId = form.deptId;
|
// }
|
// if (!validatenull(form.roleId)) {
|
// this.loginForm.roleId = form.roleId;
|
// }
|
this.handleLogin()
|
done()
|
},
|
handleLogin() {
|
this.$refs.loginForm.validate(valid => {
|
if (valid) {
|
const loading = this.$loading({
|
lock: true,
|
text: '登录中,请稍后',
|
background: 'rgba(0, 0, 0, 0.7)',
|
})
|
this.$store
|
.dispatch('LoginByUsername', this.loginForm)
|
.then(() => {
|
window.isRefreshing = false
|
if (this.website.switchMode) {
|
const deptId = this.userInfo.deptId
|
const roleId = this.userInfo.roleId
|
if (deptId.includes(',') || roleId.includes(',')) {
|
this.loginForm.deptId = deptId
|
this.loginForm.roleId = roleId
|
// this.userBox = true;
|
this.$store.dispatch('LogOut').then(() => {
|
loading.close()
|
})
|
return false
|
}
|
}
|
loading.close()
|
//加载工作流路由集
|
this.loadFlowRoutes()
|
})
|
.catch(err => {
|
console.log(err)
|
loading.close()
|
this.refreshCode()
|
})
|
}
|
})
|
},
|
// handleRegister() {
|
// // this.$parent.activeName = 'register';
|
// this.registerBox = true;
|
// },
|
loadFlowRoutes() {
|
this.$store
|
.dispatch('FlowRoutes')
|
.then(res => {
|
// 如果密钥在有效期,可以直接跳转
|
this.$router.push(this.tagWel)
|
})
|
.catch(error => {
|
// 弹出错误信息
|
this.tipInfo = '密钥已过期请联系运维单位'
|
this.tipDialogVisible = true
|
})
|
},
|
getTenant() {
|
let domain = getTopUrl()
|
// 临时指定域名,方便测试
|
//domain = "https://bladex.cn";
|
info(domain).then(res => {
|
const data = res.data
|
if (data.success && data.data.tenantId) {
|
this.tenantMode = false
|
this.loginForm.tenantId = data.data.tenantId
|
this.$parent.$refs.login.style.backgroundImage = `url(${data.data.backgroundUrl})`
|
}
|
})
|
},
|
// 上传
|
handleUpload(file) {
|
const formData = new FormData()
|
formData.append('file', file)
|
uploadLicense(formData)
|
.then(res => {
|
if (res.data.code !== 200) return ElMessage.error('上传失败')
|
ElMessage.success('上传成功')
|
this.tipDialogVisible = false
|
this.$router.push(this.tagWel)
|
})
|
.catch(err => {
|
ElMessage.error('上传失败')
|
})
|
},
|
forgetPasswordClick() {
|
this.tipInfo = '请联系系统管理员'
|
this.tipDialogVisible = true
|
},
|
},
|
}
|
</script>
|
<style scoped>
|
.login-right-new {
|
padding: 16px;
|
}
|
|
.user-login {
|
font-size: 18px;
|
font-weight: 600;
|
margin-bottom: 16px;
|
}
|
|
.login-form {
|
width: 100%;
|
}
|
|
.username,
|
.password,
|
.get-forget-password,
|
.login-submit {
|
margin-bottom: 12px;
|
}
|
|
.get-forget-password {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
}
|
|
.forget-password-text {
|
font-size: 14px;
|
color: #1677ff;
|
}
|
|
:deep(.el-button) {
|
width: 100%;
|
}
|
|
.password img {
|
width: 20px;
|
height: 20px;
|
margin-left: 8px;
|
vertical-align: middle;
|
cursor: pointer;
|
}
|
|
.dialog-close {
|
text-align: right;
|
cursor: pointer;
|
margin-bottom: 8px;
|
}
|
|
.dialog-contents {
|
text-align: center;
|
}
|
|
.dialog-btns {
|
display: inline-block;
|
padding: 6px 12px;
|
border: 1px solid #dcdfe6;
|
border-radius: 4px;
|
cursor: pointer;
|
}
|
</style>
|