123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- <template>
- <div class="login view-box">
- <div class="login-header">
- <img class="login-header-img" src="../assets/images/logo-sj.png">
- <span class="login-h-text">首佳科技SSO平台</span>
- </div>
- <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-box">
- <div class="from-box">
- <div class="login-tit">请登录</div>
- <el-form-item prop="username">
- <el-input
- v-model="loginForm.username"
- auto-complete="off"
- placeholder="账号"
- type="text"
- class="sj-input-style"
- >
- </el-input>
- </el-form-item>
- <el-form-item prop="password">
- <el-input
- v-model="loginForm.password"
- auto-complete="off"
- placeholder="密码"
- type="password"
- @keyup.enter.native="handleLogin"
- class="sj-input-style"
- >
- </el-input>
- </el-form-item>
- <el-form-item v-if="captchaEnabled" prop="code" class="flex-r">
- <el-input
- v-model="loginForm.code"
- auto-complete="off"
- placeholder="验证码"
- style="width: 63%"
- @keyup.enter.native="handleLogin"
- class="sj-input-style"
- >
-
- </el-input>
- <div class="login-code">
- <img :src="codeUrl" class="login-code-img" @click="getCode"/>
- </div>
- </el-form-item>
- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;text-decoration: none;
- color: #50aeff; float: left;" >记住密码</el-checkbox>
- <el-form-item style="width:100%;">
- <el-button
- :loading="loading"
- size="medium"
- style="width:100%;"
- type="primary"
- @click.native.prevent="handleLogin"
- class="s-input s-btn login-btn"
- >
- <span v-if="!loading">登 录</span>
- <span v-else>登 录 中...</span>
- </el-button>
- <div v-if="register" style="float: right;">
- <router-link :to="'/register'" class="link-type">立即注册</router-link>
- </div>
- </el-form-item>
- </div>
- </el-form>
- </div>
- </template>
- <script>
- import {getCodeImg, getSecretKey} from "@/api/login";
- import Cookies from "js-cookie";
- import {decrypt, encrypt} from '@/utils/jsencrypt'
- import {encryptedData} from "@/api/tool/encrypt";
- export default {
- name: "Login",
- data() {
- return {
- codeUrl: "",
- loginForm: {
- username: "admin",
- password: "admin123",
- rememberMe: false,
- code: "",
- uuid: ""
- },
- loginRules: {
- username: [
- {required: true, trigger: "blur", message: "请输入您的账号"}
- ],
- password: [
- {required: true, trigger: "blur", message: "请输入您的密码"}
- ],
- code: [{required: true, trigger: "change", message: "请输入验证码"}]
- },
- loading: false,
- // 验证码开关
- captchaEnabled: true,
- // 注册开关
- register: false,
- redirect: undefined
- };
- },
- watch: {
- $route: {
- handler: function (route) {
- this.redirect = route.query && route.query.redirect;
- },
- immediate: true
- }
- },
- created() {
- this.getCode();
- this.getCookie();
- },
- methods: {
- getCode() {
- getCodeImg().then(res => {
- this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
- if (this.captchaEnabled) {
- this.codeUrl = "data:image/gif;base64," + res.img;
- this.loginForm.uuid = res.uuid;
- }
- });
- },
- getCookie() {
- const username = Cookies.get("username");
- const password = Cookies.get("password");
- const rememberMe = Cookies.get('rememberMe')
- this.loginForm = {
- username: username === undefined ? this.loginForm.username : username,
- password: password === undefined ? this.loginForm.password : decrypt(password),
- rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
- };
- },
- handleLogin() {
- this.$refs.loginForm.validate(valid => {
- if (valid) {
- this.loading = true;
- if (this.loginForm.rememberMe) {
- Cookies.set("username", this.loginForm.username, {expires: 30});
- Cookies.set("password", encrypt(this.loginForm.password), {expires: 30});
- Cookies.set('rememberMe', this.loginForm.rememberMe, {expires: 30});
- } else {
- Cookies.remove("username");
- Cookies.remove("password");
- Cookies.remove('rememberMe');
- }
- //登录前先获取密码加密传输的公钥,对密码进行加密
- getSecretKey().then((res) => {
- const encryptedPassword = encryptedData(
- res.data,
- this.loginForm.password
- );
- this.loginForm.password = encryptedPassword;
- this.$store.dispatch("Login", this.loginForm).then(() => {
- this.$router.push({path: "/"}).catch(() => {
- });
- }).catch(() => {
- this.loading = false;
- if (this.captchaEnabled) {
- this.getCode();
- }
- });
- });
- }
- });
- }
- }
- };
- </script>
- <style lang="scss" rel="stylesheet/scss">
- .login {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100%;
- background-image: url("../assets/images/login-background.jpg");
- background-size: cover;
- }
- .title {
- margin: 0px auto 30px auto;
- text-align: center;
- color: #707070;
- }
- .login-form {
- border-radius: 6px;
- background: #ffffff;
- width: 400px;
- padding: 25px 25px 5px 25px;
- .el-input {
- height: 38px;
- input {
- height: 38px;
- }
- }
- .input-icon {
- height: 39px;
- width: 14px;
- margin-left: 2px;
- }
- }
- .login-tip {
- font-size: 13px;
- text-align: center;
- color: #bfbfbf;
- }
- .login-code {
- width: 33%;
- height: 38px;
- float: right;
- img {
- cursor: pointer;
- vertical-align: middle;
- }
- }
- .el-login-footer {
- height: 40px;
- line-height: 40px;
- position: fixed;
- bottom: 0;
- width: 100%;
- text-align: center;
- color: #fff;
- font-family: Arial;
- font-size: 12px;
- letter-spacing: 1px;
- }
- .login-code-img {
- height: 38px;
- }
- ::-webkit-input-placeholder {
- color: #ccc;
- }
- /* 视图盒子 */
- .view-box {
- position: relative;
- width: 100vw;
- height: 100vh;
- overflow: hidden;
- background: url("../assets/images/login-bg.jpg") no-repeat;
- background-size: 100% 100%;
- }
- /* 头部 */
- .login-header {
- position: absolute;
- top: 0;
- width: 100%;
- height: 84px;
- background: url("../assets/images/login-header.png") no-repeat;
- background-size: 100% 100%;
- text-align: center;
- font-size: 34px;
- color: #fff;
- font-weight: bolder;
- display: flex;
- padding-top: 10px;
- justify-content: center;
- z-index: 1000;
- }
- .login-h-text {
- background-image: linear-gradient(180deg, #ffffff, #0c8eff);
- background-clip:text;
- color: transparent;
- }
- .login-header-img {
- margin-top: 6px;
- margin-right: 10px;
- width: 40px;
- height: 40px;
- }
- /* 登录盒子 */
- /* .login-box{width: 400px; height: 400px; position: absolute; left: calc(50% - 200px); top: calc(50% - 200px); max-width: 90%; } */
- .login-box {
- width: 663px;
- margin: auto;
- max-width: 90%;
- height: 100%;
- text-align: center;
- }
- /* logo */
- .logo-box {
- height: 150px;
- line-height: 150px;
- }
- .logo-box img {
- height: 100px;
- margin-right: 20px;
- }
- .login-tit {
- width: 50%;
- height: 64px;
- line-height: 64px;
- text-align: left;
- margin-top: 26px;
- margin-left: 20px;
- font-size: 24px;
- font-weight: bolder;
- color: #90c8ff;
- float: left;
- margin-bottom: 50px;
- }
- /* 表单 */
- .from-box {
- /* width: 100%; */
- height: 597px;
- background: url("../assets/images/login-box-bg.png") no-repeat;
- border-radius: 0px;
- transition: all 0.2s;
- background-size: cover;
- position: relative;
- top: 50%;
- transform: translateY(-50%);
- }
- .from-box > * {
- padding: 0px 80px;
- }
- .from-title {
- margin-top: 40px;
- margin-bottom: 40px;
- text-align: left;
- float: left;
- }
- .tab-box {
- }
- .tab-box > span {
- cursor: pointer;
- display: inline-block;
- margin-right: 10px;
- font-size: 17px; /* letter-spacing: 1px; */
- color: #90c8ff;
- }
- .tab-box > span.nat-tab {
- font-weight: bold;
- }
- .title-border {
- width: 68px;
- height: 3px;
- margin-top: 5px;
- background-color: #0084ff;
- border-radius: 5px;
- transform: translate3d(0px, 0px, 0px);
- transition: all 0.2s;
- }
- .title-border-2 {
- transform: translate3d(83px, 0px, 0px);
- }
- .login-dev,
- .reg-dev {
- display: none;
- }
- .native {
- display: block;
- }
- /* 输入框 */
- .from-item {
- border: 0px #000 solid;
- margin-bottom: 40px;
- }
- .s-input {
- width: 100%;
- line-height: 50px;
- color: #90c8ff;
- height: 50px;
- text-indent: 1em;
- outline: 0;
- border: 1px #4982c8 solid;
- border-radius: 0px;
- transition: all 0.2s;
- background: rgba(26, 61, 102, 0.8);
- }
- .s-input {
- font-size: 18px;
- }
- .s-input:focus {
- border-color: #409eff;
- }
- [name="vc"] {
- width: 200px;
- }
- .send-vc {
- font-size: 14px;
- color: #666;
- float: right;
- line-height: 40px;
- }
- .send-vc a {
- cursor: pointer;
- color: #409eff;
- }
- .send-vc a:hover {
- text-decoration: underline;
- }
- /* 登录按钮 */
- .s-btn {
- text-indent: 0;
- font-size: 14px;
- cursor: pointer;
- background-color: #409eff;
- border-color: #409eff;
- color: #fff;
-
- }
- .s-btn:hover {
- background-color: #50aeff;
- }
- .reg-tips {
- text-align: left;
- color: #50aeff;
- font-size: 14px;
- }
- .login-btn{
- background:linear-gradient(0deg,#23d6ee,#52a9ff );
- font-size: 23px;
- font-weight: bolder;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .login-btn:hover{
- background: linear-gradient(0deg,#63e7f8,#6fb6fd );
- }
- .reg-btn:hover{
- background: linear-gradient(0deg,#63e7f8,#3179df );
- }
- .reg-btn{
- background: linear-gradient(0deg,#63e7f8,#17478b );
- font-size: 23px;
- font-weight: bolder;
- }
- /* 重置按钮 */
- .reset-box {
- text-align: left;
- font-size: 14px;
-
- }
- .reset-box a {
- text-decoration: none;
- color: #50aeff;
- }
- .reset-box a:hover {
- text-decoration: underline;
- }
- /* loading框样式 */
- .ajax-layer-load.layui-layer-dialog {
- min-width: 0px !important;
- background-color: rgba(0, 0, 0, 0.85);
- }
- .ajax-layer-load.layui-layer-dialog .layui-layer-content {
- padding: 10px 20px 10px 40px;
- color: #fff;
- }
- .ajax-layer-load.layui-layer-dialog .layui-layer-content .layui-layer-ico {
- width: 20px;
- height: 20px;
- background-size: 20px 20px;
- top: 12px;
- }
- .sj-input-style{
- .el-input__inner{
- width: 100%;
- line-height: 50px;
- color: #90c8ff;
- height: 50px;
- text-indent: 1em;
- outline: 0;
- border: 1px #4982c8 solid;
- border-radius: 0px;
- transition: all 0.2s;
- background: rgba(26, 61, 102, 0.8);
- font-size: 18px;
- padding-left: 0;
- }
- }
- .flex-r{
- .el-form-item__content{
- display: flex;
- }
-
- }
- </style>
|