|
| 1 | +<template> |
| 2 | + <div class="container"> |
| 3 | + <div class="logo"></div> |
| 4 | + <!-- 登录区域 --> |
| 5 | + <div class="content"> |
| 6 | + <!-- 配图 --> |
| 7 | + <div class="pic"></div> |
| 8 | + <!-- 表单 --> |
| 9 | + <div class="field"> |
| 10 | + <!-- [移动端]标题 --> |
| 11 | + <h2 class="mobile-title"> |
| 12 | + <h3 class="title">芋道后台管理系统</h3> |
| 13 | + </h2> |
| 14 | + |
| 15 | + <!-- 表单 --> |
| 16 | + <div class="form-cont"> |
| 17 | + <el-tabs class="form" style=" float:none;"> |
| 18 | + <el-tab-pane label="三方授权" name="uname"> |
| 19 | + </el-tab-pane> |
| 20 | + </el-tabs> |
| 21 | + <div> |
| 22 | + <el-form ref="loginForm" :model="loginForm" :rules="LoginRules" class="login-form"> |
| 23 | + <el-form-item prop="tenantName" v-if="tenantEnable"> |
| 24 | + <el-input v-model="loginForm.tenantName" type="text" auto-complete="off" placeholder='租户'> |
| 25 | + <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon"/> |
| 26 | + </el-input> |
| 27 | + </el-form-item> |
| 28 | + <!-- 账号密码登录 --> |
| 29 | + <div v-if="loginForm.loginType === 'uname'"> |
| 30 | + <el-form-item prop="username"> |
| 31 | + <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号"> |
| 32 | + <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/> |
| 33 | + </el-input> |
| 34 | + </el-form-item> |
| 35 | + <el-form-item prop="password"> |
| 36 | + <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" |
| 37 | + @keyup.enter.native="handleLogin"> |
| 38 | + <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/> |
| 39 | + </el-input> |
| 40 | + </el-form-item> |
| 41 | + <el-form-item prop="code" v-if="captchaEnable"> |
| 42 | + <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" |
| 43 | + @keyup.enter.native="handleLogin"> |
| 44 | + <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/> |
| 45 | + </el-input> |
| 46 | + </el-form-item> |
| 47 | + </div> |
| 48 | + |
| 49 | + <!-- 下方的登录按钮 --> |
| 50 | + <el-form-item style="width:100%;"> |
| 51 | + <el-button :loading="loading" size="medium" type="primary" style="width:60%;" |
| 52 | + @click.native.prevent="handleLogin"> |
| 53 | + <span v-if="!loading">同意授权</span> |
| 54 | + <span v-else>登 录 中...</span> |
| 55 | + </el-button> |
| 56 | + <el-button size="medium" style="width:37%">拒绝</el-button> |
| 57 | + </el-form-item> |
| 58 | + </el-form> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + <!-- footer --> |
| 64 | + <div class="footer"> |
| 65 | + Copyright © 2020-2022 iocoder.cn All Rights Reserved. |
| 66 | + </div> |
| 67 | + </div> |
| 68 | +</template> |
| 69 | + |
| 70 | +<script> |
| 71 | +import {getTenantIdByName} from "@/api/system/tenant"; |
| 72 | +import Cookies from "js-cookie"; |
| 73 | +import {SystemUserSocialTypeEnum} from "@/utils/constants"; |
| 74 | +import {getTenantEnable} from "@/utils/ruoyi"; |
| 75 | +import {authorize} from "@/api/login"; |
| 76 | +
|
| 77 | +export default { |
| 78 | + name: "Login", |
| 79 | + data() { |
| 80 | + return { |
| 81 | + tenantEnable: true, |
| 82 | + loginForm: { |
| 83 | + tenantName: "芋道源码", |
| 84 | + }, |
| 85 | + LoginRules: { |
| 86 | + tenantName: [ |
| 87 | + {required: true, trigger: "blur", message: "租户不能为空"}, |
| 88 | + { |
| 89 | + validator: (rule, value, callback) => { |
| 90 | + // debugger |
| 91 | + getTenantIdByName(value).then(res => { |
| 92 | + const tenantId = res.data; |
| 93 | + if (tenantId && tenantId >= 0) { |
| 94 | + // 设置租户 |
| 95 | + Cookies.set("tenantId", tenantId); |
| 96 | + callback(); |
| 97 | + } else { |
| 98 | + callback('租户不存在'); |
| 99 | + } |
| 100 | + }); |
| 101 | + }, |
| 102 | + trigger: 'blur' |
| 103 | + } |
| 104 | + ] |
| 105 | + }, |
| 106 | + loading: false, |
| 107 | + redirect: undefined, |
| 108 | + // 枚举 |
| 109 | + SysUserSocialTypeEnum: SystemUserSocialTypeEnum, |
| 110 | + }; |
| 111 | + }, |
| 112 | + created() { |
| 113 | + // 租户开关 |
| 114 | + this.tenantEnable = getTenantEnable(); |
| 115 | + // 重定向地址 |
| 116 | + this.redirect = this.$route.query.redirect; |
| 117 | + this.getCookie(); |
| 118 | + }, |
| 119 | + methods: { |
| 120 | + getCookie() { |
| 121 | + const tenantName = Cookies.get('tenantName'); |
| 122 | + this.loginForm = { |
| 123 | + tenantName: tenantName === undefined ? this.loginForm.tenantName : tenantName |
| 124 | + }; |
| 125 | + }, |
| 126 | + handleLogin() { |
| 127 | + if (true) { |
| 128 | + authorize() |
| 129 | + return; |
| 130 | + } |
| 131 | + this.$refs.loginForm.validate(valid => { |
| 132 | + if (valid) { |
| 133 | + this.loading = true; |
| 134 | + // 发起登陆 |
| 135 | + console.log("发起登录", this.loginForm); |
| 136 | + this.$store.dispatch(this.loginForm.loginType === "sms" ? "SmsLogin" : "Login", this.loginForm).then(() => { |
| 137 | + this.$router.push({path: this.redirect || "/"}).catch(() => { |
| 138 | + }); |
| 139 | + }).catch(() => { |
| 140 | + this.loading = false; |
| 141 | + this.getCode(); |
| 142 | + }); |
| 143 | + } |
| 144 | + }); |
| 145 | + } |
| 146 | + } |
| 147 | +}; |
| 148 | +</script> |
| 149 | +<style lang="scss" scoped> |
| 150 | +@import "~@/assets/styles/login.scss"; |
| 151 | +.oauth-login { |
| 152 | + display: flex; |
| 153 | + align-items: cen; |
| 154 | + cursor:pointer; |
| 155 | +} |
| 156 | +.oauth-login-item { |
| 157 | + display: flex; |
| 158 | + align-items: center; |
| 159 | + margin-right: 10px; |
| 160 | +} |
| 161 | +.oauth-login-item img { |
| 162 | + height: 25px; |
| 163 | + width: 25px; |
| 164 | +} |
| 165 | +.oauth-login-item span:hover { |
| 166 | + text-decoration: underline red; |
| 167 | + color: red; |
| 168 | +} |
| 169 | +</style> |
0 commit comments