Blame view

src/views/login/index.vue 9.36 KB
80a28914e   吉鹏   init
1
2
  <template>
    <div class="login-container">
50760eab9   Adam   auto commit the c...
3
4
5
6
7
8
9
10
      <el-form
        ref="loginForm"
        :model="loginForm"
        :rules="loginRules"
        class="login-form"
        autocomplete="on"
        label-position="left"
      >
80a28914e   吉鹏   init
11
        <div class="title-container">
50760eab9   Adam   auto commit the c...
12
          <h3 class="title">{{ $t('login.title') }}</h3>
d7d9c38c2   Adam   auto commit the c...
13
          <lang-select class="set-language" />
80a28914e   吉鹏   init
14
15
16
17
18
19
20
21
22
        </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...
23
            :placeholder="$t('login.username')"
80a28914e   吉鹏   init
24
25
26
            name="username"
            type="text"
            tabindex="1"
d7d9c38c2   Adam   auto commit the c...
27
            autocomplete="on"
80a28914e   吉鹏   init
28
29
          />
        </el-form-item>
d7d9c38c2   Adam   auto commit the c...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
        <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>
50760eab9   Adam   auto commit the c...
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        <div
          style="position:relative;text-align:right;height:30px;line-height:30px;border:0px #000 solid;margin-top:-20px;"
        >
          <!-- <el-checkbox v-model="checked">{{$t('rememberpassword')}}</el-checkbox> -->
          <el-link type="primary">{{ $t('login.forgetpassword') }}</el-link>
        </div>
        <el-button
          :loading="loading"
          type="primary"
          style="width:100%;"
          @click.native.prevent="handleLogin"
        >{{ $t('login.logIn') }}</el-button>
        <div
          style="position:relative;text-align:right;height:30px;line-height:30px;border:0px #000 solid;margin-bottom:30px;"
        >
          <div class="tips">
            <el-link type="primary">{{ $t('login.signup') }}</el-link>
          </div>
        </div>
d7d9c38c2   Adam   auto commit the c...
72
73
74
75
76
77
        <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">
50760eab9   Adam   auto commit the c...
78
            <span style="margin-right:18px;">{{ $t('login.username') }} : assistant</span>
d7d9c38c2   Adam   auto commit the c...
79
80
            <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
          </div>
50760eab9   Adam   auto commit the c...
81
82
83
84
85
86
87
88
89
90
91
92
93
          <div class="tips">
            <span style="margin-right:18px;">{{ $t('login.username') }} : runner</span>
            <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
          </div>
          <div class="tips">
            <span style="margin-right:18px;">{{ $t('login.username') }} : shoper</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
94
        </div>
80a28914e   吉鹏   init
95
      </el-form>
d7d9c38c2   Adam   auto commit the c...
96
97
98
99
100
101
102
103
  
      <el-dialog :title="$t('login.thirdparty')" :visible.sync="showDialog">
        {{ $t('login.thirdpartyTips') }}
        <br>
        <br>
        <br>
        <social-sign />
      </el-dialog>
50760eab9   Adam   auto commit the c...
104
      <!-- <vfd></vfd> -->
80a28914e   吉鹏   init
105
106
107
108
    </div>
  </template>
  
  <script>
d7d9c38c2   Adam   auto commit the c...
109
110
111
  import { validUsername } from '@/utils/validate'
  import LangSelect from '@/components/LangSelect'
  import SocialSign from './components/SocialSignin'
50760eab9   Adam   auto commit the c...
112
  // import vfd from "vfd";
80a28914e   吉鹏   init
113
  export default {
d7d9c38c2   Adam   auto commit the c...
114
    name: 'Login',
50760eab9   Adam   auto commit the c...
115
    // components: { LangSelect, SocialSign, vfd },
d7d9c38c2   Adam   auto commit the c...
116
    components: { LangSelect, SocialSign },
80a28914e   吉鹏   init
117
118
119
    data() {
      const validateUsername = (rule, value, callback) => {
        if (!validUsername(value)) {
d7d9c38c2   Adam   auto commit the c...
120
          callback(new Error('Please enter the correct user name'))
80a28914e   吉鹏   init
121
        } else {
d7d9c38c2   Adam   auto commit the c...
122
          callback()
80a28914e   吉鹏   init
123
        }
d7d9c38c2   Adam   auto commit the c...
124
      }
80a28914e   吉鹏   init
125
126
      const validatePassword = (rule, value, callback) => {
        if (value.length < 6) {
d7d9c38c2   Adam   auto commit the c...
127
          callback(new Error('The password can not be less than 6 digits'))
80a28914e   吉鹏   init
128
        } else {
d7d9c38c2   Adam   auto commit the c...
129
          callback()
80a28914e   吉鹏   init
130
        }
d7d9c38c2   Adam   auto commit the c...
131
      }
80a28914e   吉鹏   init
132
133
      return {
        loginForm: {
d7d9c38c2   Adam   auto commit the c...
134
135
          username: 'admin',
          password: '111111'
80a28914e   吉鹏   init
136
137
        },
        loginRules: {
50760eab9   Adam   auto commit the c...
138
139
140
141
142
143
          username: [
            { required: true, trigger: 'blur', validator: validateUsername }
          ],
          password: [
            { required: true, trigger: 'blur', validator: validatePassword }
          ]
80a28914e   吉鹏   init
144
        },
d7d9c38c2   Adam   auto commit the c...
145
146
        passwordType: 'password',
        capsTooltip: false,
80a28914e   吉鹏   init
147
        loading: false,
d7d9c38c2   Adam   auto commit the c...
148
149
150
151
        showDialog: false,
        redirect: undefined,
        otherQuery: {}
      }
80a28914e   吉鹏   init
152
153
154
155
    },
    watch: {
      $route: {
        handler: function(route) {
d7d9c38c2   Adam   auto commit the c...
156
157
158
159
160
          const query = route.query
          if (query) {
            this.redirect = query.redirect
            this.otherQuery = this.getOtherQuery(query)
          }
80a28914e   吉鹏   init
161
162
163
164
        },
        immediate: true
      }
    },
d7d9c38c2   Adam   auto commit the c...
165
166
167
168
169
170
171
172
173
174
175
176
177
    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
178
    methods: {
d7d9c38c2   Adam   auto commit the c...
179
180
      checkCapslock(e) {
        const { key } = e
50760eab9   Adam   auto commit the c...
181
        this.capsTooltip = key && key.length === 1 && key >= 'A' && key <= 'Z'
d7d9c38c2   Adam   auto commit the c...
182
      },
80a28914e   吉鹏   init
183
      showPwd() {
d7d9c38c2   Adam   auto commit the c...
184
185
        if (this.passwordType === 'password') {
          this.passwordType = ''
80a28914e   吉鹏   init
186
        } else {
d7d9c38c2   Adam   auto commit the c...
187
          this.passwordType = 'password'
80a28914e   吉鹏   init
188
189
        }
        this.$nextTick(() => {
d7d9c38c2   Adam   auto commit the c...
190
191
          this.$refs.password.focus()
        })
80a28914e   吉鹏   init
192
193
194
195
      },
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
d7d9c38c2   Adam   auto commit the c...
196
            this.loading = true
50760eab9   Adam   auto commit the c...
197
198
            this.$store
              .dispatch('user/login', this.loginForm)
60fa0be9d   Adam   auto commit the c...
199
              .then(() => {
50760eab9   Adam   auto commit the c...
200
201
202
203
                this.$router.push({
                  path: this.redirect || '/',
                  query: this.otherQuery
                })
d7d9c38c2   Adam   auto commit the c...
204
205
206
207
                this.loading = false
              })
              .catch(() => {
                this.loading = false
60fa0be9d   Adam   auto commit the c...
208
              })
80a28914e   吉鹏   init
209
          } else {
d7d9c38c2   Adam   auto commit the c...
210
211
            console.log('error submit!!')
            return false
80a28914e   吉鹏   init
212
          }
d7d9c38c2   Adam   auto commit the c...
213
214
215
216
217
218
219
220
221
        })
      },
      getOtherQuery(query) {
        return Object.keys(query).reduce((acc, cur) => {
          if (cur !== 'redirect') {
            acc[cur] = query[cur]
          }
          return acc
        }, {})
80a28914e   吉鹏   init
222
      }
d7d9c38c2   Adam   auto commit the c...
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
      // 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
241
    }
d7d9c38c2   Adam   auto commit the c...
242
  }
80a28914e   吉鹏   init
243
244
245
246
247
  </script>
  
  <style lang="scss">
  /* 修复input 背景不协调 和光标变色 */
  /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
50760eab9   Adam   auto commit the c...
248
249
  $bg: #283443;
  $light_gray: #fff;
80a28914e   吉鹏   init
250
251
252
253
254
255
256
257
258
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
  $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>
50760eab9   Adam   auto commit the c...
292
293
294
  $bg: #2d3a4b;
  $dark_gray: #889aa4;
  $light_gray: #eee;
80a28914e   吉鹏   init
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
  
  .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...
341
342
343
344
345
346
347
348
349
  
      .set-language {
        color: #fff;
        position: absolute;
        top: 3px;
        font-size: 18px;
        right: 0px;
        cursor: pointer;
      }
80a28914e   吉鹏   init
350
351
352
353
354
355
356
357
358
359
360
    }
  
    .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...
361
362
363
364
365
366
367
368
369
370
371
372
  
    .thirdparty-button {
      position: absolute;
      right: 0;
      bottom: 6px;
    }
  
    @media only screen and (max-width: 470px) {
      .thirdparty-button {
        display: none;
      }
    }
80a28914e   吉鹏   init
373
374
  }
  </style>