| | |
| | | <script> |
| | | import {validUsername} from "@/utils/validate" |
| | | import { validUsername } from "@/utils/validate"; |
| | | import { login } from "./api"; |
| | | import { mapMutations } from 'vuex'; |
| | | export default { |
| | | name: "loginPage", |
| | | data() { |
| | | const validateUsername = (rule, value, callback) => { |
| | | if (!validUsername(value)) { |
| | | callback(new Error('Please enter the correct user name')) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | const validatePassword = (rule, value, callback) => { |
| | | if (value.length < 6) { |
| | | callback(new Error('The password can not be less than 6 digits')) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | return { |
| | | loginForm: { |
| | | username: 'admin', |
| | | password: '111111' |
| | | }, |
| | | loginRules: { |
| | | username: [{ required: true, trigger: 'blur', validator: validateUsername }], |
| | | password: [{ required: true, trigger: 'blur', validator: validatePassword }] |
| | | }, |
| | | passwordType: 'password', |
| | | capsTooltip: false, |
| | | loading: false, |
| | | showDialog: false, |
| | | redirect: undefined, |
| | | otherQuery: {} |
| | | } |
| | | }, |
| | | methods: { |
| | | checkCapslock(e) { |
| | | const { key } = e |
| | | this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z') |
| | | }, |
| | | handleLogin() {}, |
| | | showPwd() { |
| | | if (this.passwordType === 'password') { |
| | | this.passwordType = '' |
| | | } else { |
| | | this.passwordType = 'password' |
| | | } |
| | | this.$nextTick(() => { |
| | | this.$refs.password.focus() |
| | | }) |
| | | }, |
| | | }, |
| | | } |
| | | name: "loginPage", |
| | | data() { |
| | | const validateUsername = (rule, value, callback) => { |
| | | if (!validUsername(value)) { |
| | | callback(new Error("用户名不能为空")); |
| | | } else { |
| | | callback(); |
| | | } |
| | | }; |
| | | const validatePassword = (rule, value, callback) => { |
| | | if (value.trim() == '') { |
| | | callback(new Error("密码不能为空")); |
| | | } else { |
| | | callback(); |
| | | } |
| | | }; |
| | | return { |
| | | loginForm: { |
| | | // username: "hw", |
| | | // password: "123456", |
| | | username: "", |
| | | password: "", |
| | | }, |
| | | loginRules: { |
| | | username: [ |
| | | { required: true, trigger: "blur", validator: validateUsername }, |
| | | ], |
| | | password: [ |
| | | { required: true, trigger: "blur", validator: validatePassword }, |
| | | ], |
| | | }, |
| | | passwordType: "password", |
| | | capsTooltip: false, |
| | | loading: false, |
| | | showDialog: false, |
| | | redirect: undefined, |
| | | otherQuery: {}, |
| | | }; |
| | | }, |
| | | methods: { |
| | | ...mapMutations('user', ['SETUSER', 'SETDOWNLOAD', 'SETUID']), |
| | | checkCapslock(e) { |
| | | const { key } = e; |
| | | this.capsTooltip = key && key.length === 1 && key >= "A" && key <= "Z"; |
| | | }, |
| | | handleLogin() { |
| | | let loading = this.$layer.loading(); |
| | | login(this.loginForm.username, this.loginForm.password) |
| | | .then((res) => { |
| | | let { code, data, data2 } = res.data; |
| | | if (code && data) { |
| | | // console.log(data); |
| | | this.$message.success('登录成功'); |
| | | this.SETUSER(data2.uname); |
| | | this.SETDOWNLOAD(data2.udownloadRole); |
| | | this.SETUID(data2.uid); |
| | | this.$router.push('/'); |
| | | } else { |
| | | this.$message.error(msg); |
| | | } |
| | | this.$layer.close(loading); |
| | | }) |
| | | .catch((err) => { |
| | | // console.log(err); |
| | | this.$message.error(err); |
| | | this.$layer.close(loading); |
| | | }); |
| | | }, |
| | | showPwd() { |
| | | if (this.passwordType === "password") { |
| | | this.passwordType = ""; |
| | | } else { |
| | | this.passwordType = "password"; |
| | | } |
| | | this.$nextTick(() => { |
| | | this.$refs.password.focus(); |
| | | }); |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | |
| | | <template> |
| | | <div class="login-container"> |
| | | <el-form |
| | | ref="loginForm" |
| | | :model="loginForm" |
| | | :rules="loginRules" |
| | | class="login-form" |
| | | autocomplete="on" |
| | | label-position="left"> |
| | | <div class="title-container"> |
| | | <h3 class="title">登录</h3> |
| | | </div> |
| | | <div class="login-container"> |
| | | <el-form |
| | | ref="loginForm" |
| | | :model="loginForm" |
| | | :rules="loginRules" |
| | | class="login-form" |
| | | autocomplete="on" |
| | | label-position="left" |
| | | > |
| | | <div class="title-container"> |
| | | <h3 class="title">登录</h3> |
| | | </div> |
| | | |
| | | <el-form-item prop="username"> |
| | | <el-form-item prop="username"> |
| | | <span class="svg-container"> |
| | | <svg-icon icon-class="user" /> |
| | | </span> |
| | | <el-input |
| | | ref="username" |
| | | v-model="loginForm.username" |
| | | placeholder="Username" |
| | | name="username" |
| | | type="text" |
| | | tabindex="1" |
| | | autocomplete="on" |
| | | /> |
| | | </el-form-item> |
| | | <el-input |
| | | ref="username" |
| | | v-model="loginForm.username" |
| | | placeholder="Username" |
| | | name="username" |
| | | type="text" |
| | | tabindex="1" |
| | | autocomplete="on" |
| | | /> |
| | | </el-form-item> |
| | | |
| | | <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual> |
| | | <el-form-item prop="password"> |
| | | <el-tooltip |
| | | v-model="capsTooltip" |
| | | content="输入了大写字母" |
| | | placement="right" |
| | | manual |
| | | > |
| | | <el-form-item prop="password"> |
| | | <span class="svg-container"> |
| | | <svg-icon icon-class="password" /> |
| | | </span> |
| | | <el-input |
| | | :key="passwordType" |
| | | ref="password" |
| | | v-model="loginForm.password" |
| | | :type="passwordType" |
| | | placeholder="Password" |
| | | name="password" |
| | | tabindex="2" |
| | | autocomplete="on" |
| | | @keyup.native="checkCapslock" |
| | | @blur="capsTooltip = false" |
| | | @keyup.enter.native="handleLogin" |
| | | /> |
| | | <span class="show-pwd" @click="showPwd"> |
| | | <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" /> |
| | | <el-input |
| | | :key="passwordType" |
| | | ref="password" |
| | | v-model="loginForm.password" |
| | | :type="passwordType" |
| | | placeholder="Password" |
| | | name="password" |
| | | tabindex="2" |
| | | autocomplete="on" |
| | | @keyup.native="checkCapslock" |
| | | @blur="capsTooltip = false" |
| | | @keyup.enter.native="handleLogin" |
| | | /> |
| | | <span class="show-pwd" @click="showPwd"> |
| | | <svg-icon |
| | | :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" |
| | | /> |
| | | </span> |
| | | </el-form-item> |
| | | </el-tooltip> |
| | | <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">Login</el-button> |
| | | </el-form> |
| | | </div> |
| | | </el-form-item> |
| | | </el-tooltip> |
| | | <el-button |
| | | :loading="loading" |
| | | type="primary" |
| | | style="width: 100%; margin-bottom: 30px" |
| | | @click.native.prevent="handleLogin" |
| | | >Login</el-button |
| | | > |
| | | </el-form> |
| | | </div> |
| | | </template> |
| | | |
| | | <style scoped lang="less"> |
| | | .login-container { |
| | | .el-input { |
| | | display: inline-block; |
| | | height: 47px; |
| | | width: 85%; |
| | | .el-input { |
| | | display: inline-block; |
| | | height: 47px; |
| | | width: 85%; |
| | | |
| | | /deep/ input { |
| | | background: transparent; |
| | | border: 0; |
| | | -webkit-appearance: none; |
| | | border-radius: 0; |
| | | padding: 12px 5px 12px 15px; |
| | | color: #FFFFFF; |
| | | height: 47px; |
| | | caret-color: #283443; |
| | | /deep/ input { |
| | | background: transparent; |
| | | border: 0; |
| | | -webkit-appearance: none; |
| | | border-radius: 0; |
| | | padding: 12px 5px 12px 15px; |
| | | color: #ffffff; |
| | | height: 47px; |
| | | caret-color: #283443; |
| | | |
| | | &:-webkit-autofill { |
| | | box-shadow: 0 0 0 1000px #283443 inset !important; |
| | | -webkit-text-fill-color: #fff !important; |
| | | } |
| | | } |
| | | } |
| | | &:-webkit-autofill { |
| | | box-shadow: 0 0 0 1000px #283443 inset !important; |
| | | -webkit-text-fill-color: #fff !important; |
| | | } |
| | | } |
| | | } |
| | | |
| | | .el-form-item { |
| | | border: 1px solid rgba(255, 255, 255, 0.1); |
| | | background: rgba(0, 0, 0, 0.1); |
| | | border-radius: 5px; |
| | | color: #454545; |
| | | } |
| | | .el-form-item { |
| | | border: 1px solid rgba(255, 255, 255, 0.1); |
| | | background: rgba(0, 0, 0, 0.1); |
| | | border-radius: 5px; |
| | | color: #454545; |
| | | } |
| | | } |
| | | </style> |
| | | |
| | | <style lang="less" scoped> |
| | | .login-container { |
| | | min-height: 100%; |
| | | width: 100%; |
| | | background-color: #2d3a4b; |
| | | overflow: hidden; |
| | | min-height: 100%; |
| | | width: 100%; |
| | | background-color: #2d3a4b; |
| | | overflow: hidden; |
| | | |
| | | .login-form { |
| | | position: relative; |
| | | width: 520px; |
| | | max-width: 100%; |
| | | padding: 160px 35px 0; |
| | | margin: 0 auto; |
| | | overflow: hidden; |
| | | } |
| | | .login-form { |
| | | position: relative; |
| | | width: 520px; |
| | | max-width: 100%; |
| | | padding: 160px 35px 0; |
| | | margin: 0 auto; |
| | | overflow: hidden; |
| | | } |
| | | |
| | | .tips { |
| | | font-size: 14px; |
| | | color: #fff; |
| | | margin-bottom: 10px; |
| | | .tips { |
| | | font-size: 14px; |
| | | color: #fff; |
| | | margin-bottom: 10px; |
| | | |
| | | span { |
| | | &:first-of-type { |
| | | margin-right: 16px; |
| | | } |
| | | } |
| | | } |
| | | span { |
| | | &:first-of-type { |
| | | margin-right: 16px; |
| | | } |
| | | } |
| | | } |
| | | |
| | | .svg-container { |
| | | padding: 6px 5px 6px 15px; |
| | | color: #889aa4; |
| | | vertical-align: middle; |
| | | width: 30px; |
| | | display: inline-block; |
| | | } |
| | | .svg-container { |
| | | padding: 6px 5px 6px 15px; |
| | | color: #889aa4; |
| | | vertical-align: middle; |
| | | width: 30px; |
| | | display: inline-block; |
| | | } |
| | | |
| | | .title-container { |
| | | position: relative; |
| | | .title-container { |
| | | position: relative; |
| | | |
| | | .title { |
| | | font-size: 26px; |
| | | color: #eee; |
| | | margin: 0 auto 40px auto; |
| | | text-align: center; |
| | | font-weight: bold; |
| | | } |
| | | } |
| | | .title { |
| | | font-size: 26px; |
| | | color: #eee; |
| | | margin: 0 auto 40px auto; |
| | | text-align: center; |
| | | font-weight: bold; |
| | | } |
| | | } |
| | | |
| | | .show-pwd { |
| | | position: absolute; |
| | | right: 10px; |
| | | top: 7px; |
| | | font-size: 16px; |
| | | color: #889aa4; |
| | | cursor: pointer; |
| | | user-select: none; |
| | | } |
| | | .show-pwd { |
| | | position: absolute; |
| | | right: 10px; |
| | | top: 7px; |
| | | font-size: 16px; |
| | | color: #889aa4; |
| | | cursor: pointer; |
| | | user-select: none; |
| | | } |
| | | |
| | | .thirdparty-button { |
| | | position: absolute; |
| | | right: 0; |
| | | bottom: 6px; |
| | | } |
| | | .thirdparty-button { |
| | | position: absolute; |
| | | right: 0; |
| | | bottom: 6px; |
| | | } |
| | | |
| | | @media only screen and (max-width: 470px) { |
| | | .thirdparty-button { |
| | | display: none; |
| | | } |
| | | } |
| | | @media only screen and (max-width: 470px) { |
| | | .thirdparty-button { |
| | | display: none; |
| | | } |
| | | } |
| | | } |
| | | </style> |