123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <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">川仪READOPC后台管理系统</h3>
- </div>
- <el-form-item prop="userName">
- <span class="svg-container">
- <svg-icon icon-class="user" />
- </span>
- <el-input
- ref="userName"
- v-model="loginForm.userName"
- placeholder="帐号"
- name="userName"
- type="text"
- tabindex="1"
- auto-complete="off"
- />
- </el-form-item>
- <el-tooltip
- v-model="capsTooltip"
- content="已开启大写字母"
- placement="bottom-start"
- 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="密码"
- name="password"
- tabindex="2"
- auto-complete="off"
- @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-form-item
- v-if="captchaEnabled"
- prop="code"
- class="code-div"
- >
- <div
- class="el-form-item"
- style="width: 63%;float: left;"
- >
- <span class="svg-container">
- <svg-icon icon-class="validCode" />
- </span>
- <el-input
- ref="code"
- v-model="loginForm.code"
- placeholder="验证码"
- name="code"
- type="text"
- tabindex="3"
- auto-complete="off"
- />
- </div>
- <div class="login-code">
- <img
- :src="codeUrl"
- class="login-code-img"
- @click="getCode"
- >
- </div>
- </el-form-item>
- <el-button
- :loading="loading"
- type="primary"
- style="width:100%;margin-bottom:30px;"
- @click.native.prevent="handleLogin"
- >
- 登录
- </el-button>
- </el-form>
- </div>
- </template>
- <script>
- import { getCode } from '@/api/user'
- import { Message } from 'element-ui'
- import errorCode from '@/utils/errorCode'
- export default {
- name: 'Login',
- data() {
- return {
- codeUrl: '',
- loginForm: {
- publicKey: '',
- userName: '',
- password: '',
- code: '',
- uid: ''
- },
- loginRules: {
- userName: [{ required: true, trigger: ['blur', 'change'], message: '请输入您的用户名', pattern: '[^ \x22]+' }],
- password: [{ required: true, trigger: ['blur', 'change'], message: '请输入您的密码', pattern: '[^ \x22]+' }],
- code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
- },
- passwordType: 'password',
- // 大写字母开启提示
- capsTooltip: false,
- // 加载状态
- loading: false,
- // 验证码开关
- captchaEnabled: true,
- redirect: undefined,
- otherQuery: {}
- }
- },
- watch: {
- $route: {
- handler: function(route) {
- const query = route.query
- if (query) {
- this.redirect = query.redirect
- this.otherQuery = this.getOtherQuery(query)
- }
- },
- immediate: true
- }
- },
- created() {
- this.getCode()
- },
- mounted() {
- },
- destroyed() {
- },
- methods: {
- getCode() {
- getCode(true).then(res => {
- this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
- if (this.captchaEnabled) {
- const data = res.data
- this.loginForm.uid = data.uid
- this.loginForm.publicKey = data.publicKey
- this.codeUrl = 'data:image/gif;base64,' + data.verifyCode
- }
- })
- },
- checkCapslock(e) {
- const { key } = e
- this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z')
- },
- showPwd() {
- if (this.passwordType === 'password') {
- this.passwordType = ''
- } else {
- this.passwordType = 'password'
- }
- this.$nextTick(() => {
- this.$refs.password.focus()
- })
- },
- handleLogin() {
- if (!this.loginForm.publicKey) {
- const msg = errorCode[900]
- Message.error(msg)
- return
- }
- this.$refs.loginForm.validate(valid => {
- if (valid) {
- console.log(this.loginForm)
- this.loading = true
- this.$store.dispatch('user/Login', this.loginForm).then(() => {
- this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
- this.loading = false
- }).catch(() => {
- this.loading = false
- if (this.captchaEnabled) {
- this.getCode()
- }
- })
- }
- })
- },
- getOtherQuery(query) {
- return Object.keys(query).reduce((acc, cur) => {
- if (cur !== 'redirect') {
- acc[cur] = query[cur]
- }
- return acc
- }, {})
- }
- }
- }
- </script>
- <style lang="scss">
- $imgBg: url("~@/assets/images/loginbg.png");
- $dark_gray: #889aa4;
- .login-container {
- .el-input {
- display: inline-block;
- width: 85%;
- input {
- background: transparent;
- border: 0px;
- -webkit-appearance: none;
- border-radius: 0px;
- }
- }
- .el-form-item {
- border: 1px solid rgba(0, 0, 0, 0.1);
- border-radius: 5px;
- color: #454545;
- }
- }
- .login-container {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100%;
- background-color: #2c3e50;
- //background-image: $imgBg;
- //background-size: cover;
- overflow: hidden;
- .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;
- }
- }
- .svg-container {
- padding-left: 15px;
- color: $dark_gray;
- vertical-align: middle;
- width: 30px;
- display: inline-block;
- }
- .title {
- margin: 0px auto 30px auto;
- text-align: center;
- color: #707070;
- }
- .show-pwd {
- position: absolute;
- right: 10px;
- top: 7px;
- font-size: 16px;
- color: $dark_gray;
- cursor: pointer;
- user-select: none;
- }
- .login-code {
- width: 33%;
- height: 38px;
- float: right;
- display: flex;
- justify-content: flex-end;
- img {
- cursor: pointer;
- vertical-align: middle;
- }
- }
- .code-div {
- border: 0;
- position: relative;
- }
- .login-code-img {
- height: 38px;
- }
- }
- </style>
|