Blame view

src/views/login/index.vue 8.19 KB
80a28914e   吉鹏   init
1
2
  <template>
    <div class="login-container">
d7d9c38c2   Adam   auto commit the c...
3
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on" label-position="left">
80a28914e   吉鹏   init
4
        <div class="title-container">
d7d9c38c2   Adam   auto commit the c...
5
6
7
8
          <h3 class="title">
            {{ $t('login.title') }}
          </h3>
          <lang-select class="set-language" />
80a28914e   吉鹏   init
9
10
11
12
13
14
15
16
17
        </div>
  
        <el-form-item prop="username">
          <span class="svg-container">
            <svg-icon icon-class="user" />
          </span>
          <el-input
            ref="username"
            v-model="loginForm.username"
d7d9c38c2   Adam   auto commit the c...
18
            :placeholder="$t('login.username')"
80a28914e   吉鹏   init
19
20
21
            name="username"
            type="text"
            tabindex="1"
d7d9c38c2   Adam   auto commit the c...
22
            autocomplete="on"
80a28914e   吉鹏   init
23
24
          />
        </el-form-item>
d7d9c38c2   Adam   auto commit the c...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
        <el-tooltip v-model="capsTooltip" content="Caps lock is On" 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="$t('login.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">
          {{ $t('login.logIn') }}
        </el-button>
80a28914e   吉鹏   init
52

d7d9c38c2   Adam   auto commit the c...
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
        <div style="position:relative">
          <div class="tips">
            <span>{{ $t('login.username') }} : admin</span>
            <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
          </div>
          <div class="tips">
            <span style="margin-right:18px;">
              {{ $t('login.username') }} : editor
            </span>
            <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
          </div>
  
          <el-button class="thirdparty-button" type="primary" @click="showDialog=true">
            {{ $t('login.thirdparty') }}
          </el-button>
80a28914e   吉鹏   init
68
        </div>
80a28914e   吉鹏   init
69
      </el-form>
d7d9c38c2   Adam   auto commit the c...
70
71
72
73
74
75
76
77
  
      <el-dialog :title="$t('login.thirdparty')" :visible.sync="showDialog">
        {{ $t('login.thirdpartyTips') }}
        <br>
        <br>
        <br>
        <social-sign />
      </el-dialog>
80a28914e   吉鹏   init
78
79
80
81
    </div>
  </template>
  
  <script>
d7d9c38c2   Adam   auto commit the c...
82
83
84
  import { validUsername } from '@/utils/validate'
  import LangSelect from '@/components/LangSelect'
  import SocialSign from './components/SocialSignin'
80a28914e   吉鹏   init
85
86
  
  export default {
d7d9c38c2   Adam   auto commit the c...
87
88
    name: 'Login',
    components: { LangSelect, SocialSign },
80a28914e   吉鹏   init
89
90
91
    data() {
      const validateUsername = (rule, value, callback) => {
        if (!validUsername(value)) {
d7d9c38c2   Adam   auto commit the c...
92
          callback(new Error('Please enter the correct user name'))
80a28914e   吉鹏   init
93
        } else {
d7d9c38c2   Adam   auto commit the c...
94
          callback()
80a28914e   吉鹏   init
95
        }
d7d9c38c2   Adam   auto commit the c...
96
      }
80a28914e   吉鹏   init
97
98
      const validatePassword = (rule, value, callback) => {
        if (value.length < 6) {
d7d9c38c2   Adam   auto commit the c...
99
          callback(new Error('The password can not be less than 6 digits'))
80a28914e   吉鹏   init
100
        } else {
d7d9c38c2   Adam   auto commit the c...
101
          callback()
80a28914e   吉鹏   init
102
        }
d7d9c38c2   Adam   auto commit the c...
103
      }
80a28914e   吉鹏   init
104
105
      return {
        loginForm: {
d7d9c38c2   Adam   auto commit the c...
106
107
          username: 'admin',
          password: '111111'
80a28914e   吉鹏   init
108
109
        },
        loginRules: {
d7d9c38c2   Adam   auto commit the c...
110
111
          username: [{ required: true, trigger: 'blur', validator: validateUsername }],
          password: [{ required: true, trigger: 'blur', validator: validatePassword }]
80a28914e   吉鹏   init
112
        },
d7d9c38c2   Adam   auto commit the c...
113
114
        passwordType: 'password',
        capsTooltip: false,
80a28914e   吉鹏   init
115
        loading: false,
d7d9c38c2   Adam   auto commit the c...
116
117
118
119
        showDialog: false,
        redirect: undefined,
        otherQuery: {}
      }
80a28914e   吉鹏   init
120
121
122
123
    },
    watch: {
      $route: {
        handler: function(route) {
d7d9c38c2   Adam   auto commit the c...
124
125
126
127
128
          const query = route.query
          if (query) {
            this.redirect = query.redirect
            this.otherQuery = this.getOtherQuery(query)
          }
80a28914e   吉鹏   init
129
130
131
132
        },
        immediate: true
      }
    },
d7d9c38c2   Adam   auto commit the c...
133
134
135
136
137
138
139
140
141
142
143
144
145
    created() {
      // window.addEventListener('storage', this.afterQRScan)
    },
    mounted() {
      if (this.loginForm.username === '') {
        this.$refs.username.focus()
      } else if (this.loginForm.password === '') {
        this.$refs.password.focus()
      }
    },
    destroyed() {
      // window.removeEventListener('storage', this.afterQRScan)
    },
80a28914e   吉鹏   init
146
    methods: {
d7d9c38c2   Adam   auto commit the c...
147
148
149
150
      checkCapslock(e) {
        const { key } = e
        this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z')
      },
80a28914e   吉鹏   init
151
      showPwd() {
d7d9c38c2   Adam   auto commit the c...
152
153
        if (this.passwordType === 'password') {
          this.passwordType = ''
80a28914e   吉鹏   init
154
        } else {
d7d9c38c2   Adam   auto commit the c...
155
          this.passwordType = 'password'
80a28914e   吉鹏   init
156
157
        }
        this.$nextTick(() => {
d7d9c38c2   Adam   auto commit the c...
158
159
          this.$refs.password.focus()
        })
80a28914e   吉鹏   init
160
161
162
163
      },
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
d7d9c38c2   Adam   auto commit the c...
164
165
            this.loading = true
            this.$store.dispatch('user/login', this.loginForm)
60fa0be9d   Adam   auto commit the c...
166
              .then(() => {
d7d9c38c2   Adam   auto commit the c...
167
168
169
170
171
                this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
                this.loading = false
              })
              .catch(() => {
                this.loading = false
60fa0be9d   Adam   auto commit the c...
172
              })
80a28914e   吉鹏   init
173
          } else {
d7d9c38c2   Adam   auto commit the c...
174
175
            console.log('error submit!!')
            return false
80a28914e   吉鹏   init
176
          }
d7d9c38c2   Adam   auto commit the c...
177
178
179
180
181
182
183
184
185
        })
      },
      getOtherQuery(query) {
        return Object.keys(query).reduce((acc, cur) => {
          if (cur !== 'redirect') {
            acc[cur] = query[cur]
          }
          return acc
        }, {})
80a28914e   吉鹏   init
186
      }
d7d9c38c2   Adam   auto commit the c...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
      // afterQRScan() {
      //   if (e.key === 'x-admin-oauth-code') {
      //     const code = getQueryObject(e.newValue)
      //     const codeMap = {
      //       wechat: 'code',
      //       tencent: 'code'
      //     }
      //     const type = codeMap[this.auth_type]
      //     const codeName = code[type]
      //     if (codeName) {
      //       this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
      //         this.$router.push({ path: this.redirect || '/' })
      //       })
      //     } else {
      //       alert('第三方登录失败')
      //     }
      //   }
      // }
80a28914e   吉鹏   init
205
    }
d7d9c38c2   Adam   auto commit the c...
206
  }
80a28914e   吉鹏   init
207
208
209
210
211
  </script>
  
  <style lang="scss">
  /* 修复input 背景不协调 和光标变色 */
  /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
d7d9c38c2   Adam   auto commit the c...
212
213
  $bg:#283443;
  $light_gray:#fff;
80a28914e   吉鹏   init
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
  $cursor: #fff;
  
  @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
    .login-container .el-input input {
      color: $cursor;
    }
  }
  
  /* reset element-ui css */
  .login-container {
    .el-input {
      display: inline-block;
      height: 47px;
      width: 85%;
  
      input {
        background: transparent;
        border: 0px;
        -webkit-appearance: none;
        border-radius: 0px;
        padding: 12px 5px 12px 15px;
        color: $light_gray;
        height: 47px;
        caret-color: $cursor;
  
        &:-webkit-autofill {
          box-shadow: 0 0 0px 1000px $bg inset !important;
          -webkit-text-fill-color: $cursor !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;
    }
  }
  </style>
  
  <style lang="scss" scoped>
d7d9c38c2   Adam   auto commit the c...
256
257
258
  $bg:#2d3a4b;
  $dark_gray:#889aa4;
  $light_gray:#eee;
80a28914e   吉鹏   init
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  
  .login-container {
    min-height: 100%;
    width: 100%;
    background-color: $bg;
    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;
  
      span {
        &:first-of-type {
          margin-right: 16px;
        }
      }
    }
  
    .svg-container {
      padding: 6px 5px 6px 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
    }
  
    .title-container {
      position: relative;
  
      .title {
        font-size: 26px;
        color: $light_gray;
        margin: 0px auto 40px auto;
        text-align: center;
        font-weight: bold;
      }
d7d9c38c2   Adam   auto commit the c...
305
306
307
308
309
310
311
312
313
  
      .set-language {
        color: #fff;
        position: absolute;
        top: 3px;
        font-size: 18px;
        right: 0px;
        cursor: pointer;
      }
80a28914e   吉鹏   init
314
315
316
317
318
319
320
321
322
323
324
    }
  
    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
d7d9c38c2   Adam   auto commit the c...
325
326
327
328
329
330
331
332
333
334
335
336
  
    .thirdparty-button {
      position: absolute;
      right: 0;
      bottom: 6px;
    }
  
    @media only screen and (max-width: 470px) {
      .thirdparty-button {
        display: none;
      }
    }
80a28914e   吉鹏   init
337
338
  }
  </style>