Blame view

src/views/login/index.vue 9.66 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>
a6e433928   Adam   auto commit the c...
30
31
32
33
34
35
        <el-tooltip
          v-model="capsTooltip"
          content="Caps lock is On"
          placement="right"
          manual
        >
d7d9c38c2   Adam   auto commit the c...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
          <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"
            />
a6e433928   Adam   auto commit the c...
53
54
55
56
            <span
              class="show-pwd"
              @click="showPwd"
            >
d7d9c38c2   Adam   auto commit the c...
57
58
59
60
              <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
            </span>
          </el-form-item>
        </el-tooltip>
a6e433928   Adam   auto commit the c...
61
        <div style="position:relative;text-align:right;height:30px;line-height:30px;border:0px #000 solid;margin-top:-20px;">
50760eab9   Adam   auto commit the c...
62
63
          <!-- <el-checkbox v-model="checked">{{$t('rememberpassword')}}</el-checkbox> -->
          <el-link type="primary">{{ $t('login.forgetpassword') }}</el-link>
a6e433928   Adam   auto commit the c...
64
          <el-link type="primary">{{ $t('login.signup') }}</el-link>
50760eab9   Adam   auto commit the c...
65
66
67
68
69
70
71
        </div>
        <el-button
          :loading="loading"
          type="primary"
          style="width:100%;"
          @click.native.prevent="handleLogin"
        >{{ $t('login.logIn') }}</el-button>
a6e433928   Adam   auto commit the c...
72
        <div style="position:relative;text-align:right;height:30px;line-height:30px;border:0px #000 solid;margin-bottom:30px;">
50760eab9   Adam   auto commit the c...
73
          <div class="tips">
a6e433928   Adam   auto commit the c...
74
75
76
77
78
            <el-button
              class="thirdparty-button"
              type="primary"
              @click="showDialog=true"
            >{{ $t('login.thirdparty') }}</el-button>
50760eab9   Adam   auto commit the c...
79
          </div>
a6e433928   Adam   auto commit the c...
80
81
82
83
          <!-- <div class="tips">
            <span style="margin-right:18px;">{{ $t('login.username') }} : runner</span>
            <el-link type="primary">{{ $t('login.signup') }}</el-link>
          </div> -->
50760eab9   Adam   auto commit the c...
84
        </div>
d59b2d89e   BigBoss   madd appManage page
85
86
        <!-- <div style="position:relative"> -->
        <!-- <div class="tips">
d7d9c38c2   Adam   auto commit the c...
87
88
89
90
            <span>{{ $t('login.username') }} : admin</span>
            <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
          </div>
          <div class="tips">
50760eab9   Adam   auto commit the c...
91
            <span style="margin-right:18px;">{{ $t('login.username') }} : assistant</span>
d7d9c38c2   Adam   auto commit the c...
92
93
            <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
          </div>
50760eab9   Adam   auto commit the c...
94
95
96
97
98
99
100
          <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>
a6e433928   Adam   auto commit the c...
101
          </div> -->
d59b2d89e   BigBoss   madd appManage page
102
        <!-- </div> -->
80a28914e   吉鹏   init
103
      </el-form>
d7d9c38c2   Adam   auto commit the c...
104

a6e433928   Adam   auto commit the c...
105
106
107
108
      <el-dialog
        :title="$t('login.thirdparty')"
        :visible.sync="showDialog"
      >
d7d9c38c2   Adam   auto commit the c...
109
110
111
112
113
114
        {{ $t('login.thirdpartyTips') }}
        <br>
        <br>
        <br>
        <social-sign />
      </el-dialog>
50760eab9   Adam   auto commit the c...
115
      <!-- <vfd></vfd> -->
80a28914e   吉鹏   init
116
117
118
119
    </div>
  </template>
  
  <script>
d7d9c38c2   Adam   auto commit the c...
120
121
122
  import { validUsername } from '@/utils/validate'
  import LangSelect from '@/components/LangSelect'
  import SocialSign from './components/SocialSignin'
50760eab9   Adam   auto commit the c...
123
  // import vfd from "vfd";
80a28914e   吉鹏   init
124
  export default {
d7d9c38c2   Adam   auto commit the c...
125
    name: 'Login',
50760eab9   Adam   auto commit the c...
126
    // components: { LangSelect, SocialSign, vfd },
d7d9c38c2   Adam   auto commit the c...
127
    components: { LangSelect, SocialSign },
80a28914e   吉鹏   init
128
129
130
    data() {
      const validateUsername = (rule, value, callback) => {
        if (!validUsername(value)) {
d7d9c38c2   Adam   auto commit the c...
131
          callback(new Error('Please enter the correct user name'))
80a28914e   吉鹏   init
132
        } else {
d7d9c38c2   Adam   auto commit the c...
133
          callback()
80a28914e   吉鹏   init
134
        }
d7d9c38c2   Adam   auto commit the c...
135
      }
80a28914e   吉鹏   init
136
137
      const validatePassword = (rule, value, callback) => {
        if (value.length < 6) {
d7d9c38c2   Adam   auto commit the c...
138
          callback(new Error('The password can not be less than 6 digits'))
80a28914e   吉鹏   init
139
        } else {
d7d9c38c2   Adam   auto commit the c...
140
          callback()
80a28914e   吉鹏   init
141
        }
d7d9c38c2   Adam   auto commit the c...
142
      }
80a28914e   吉鹏   init
143
144
      return {
        loginForm: {
d7d9c38c2   Adam   auto commit the c...
145
146
          username: 'admin',
          password: '111111'
80a28914e   吉鹏   init
147
148
        },
        loginRules: {
50760eab9   Adam   auto commit the c...
149
150
151
152
153
154
          username: [
            { required: true, trigger: 'blur', validator: validateUsername }
          ],
          password: [
            { required: true, trigger: 'blur', validator: validatePassword }
          ]
80a28914e   吉鹏   init
155
        },
d7d9c38c2   Adam   auto commit the c...
156
157
        passwordType: 'password',
        capsTooltip: false,
80a28914e   吉鹏   init
158
        loading: false,
d7d9c38c2   Adam   auto commit the c...
159
160
161
162
        showDialog: false,
        redirect: undefined,
        otherQuery: {}
      }
80a28914e   吉鹏   init
163
164
165
166
    },
    watch: {
      $route: {
        handler: function(route) {
d7d9c38c2   Adam   auto commit the c...
167
168
169
170
171
          const query = route.query
          if (query) {
            this.redirect = query.redirect
            this.otherQuery = this.getOtherQuery(query)
          }
80a28914e   吉鹏   init
172
173
174
175
        },
        immediate: true
      }
    },
d7d9c38c2   Adam   auto commit the c...
176
177
178
179
180
181
182
183
184
185
186
187
188
    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
189
    methods: {
d7d9c38c2   Adam   auto commit the c...
190
191
      checkCapslock(e) {
        const { key } = e
50760eab9   Adam   auto commit the c...
192
        this.capsTooltip = key && key.length === 1 && key >= 'A' && key <= 'Z'
d7d9c38c2   Adam   auto commit the c...
193
      },
80a28914e   吉鹏   init
194
      showPwd() {
d7d9c38c2   Adam   auto commit the c...
195
196
        if (this.passwordType === 'password') {
          this.passwordType = ''
80a28914e   吉鹏   init
197
        } else {
d7d9c38c2   Adam   auto commit the c...
198
          this.passwordType = 'password'
80a28914e   吉鹏   init
199
200
        }
        this.$nextTick(() => {
d7d9c38c2   Adam   auto commit the c...
201
202
          this.$refs.password.focus()
        })
80a28914e   吉鹏   init
203
204
205
206
      },
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
d7d9c38c2   Adam   auto commit the c...
207
            this.loading = true
50760eab9   Adam   auto commit the c...
208
209
            this.$store
              .dispatch('user/login', this.loginForm)
60fa0be9d   Adam   auto commit the c...
210
              .then(() => {
50760eab9   Adam   auto commit the c...
211
212
213
214
                this.$router.push({
                  path: this.redirect || '/',
                  query: this.otherQuery
                })
d7d9c38c2   Adam   auto commit the c...
215
216
217
218
                this.loading = false
              })
              .catch(() => {
                this.loading = false
60fa0be9d   Adam   auto commit the c...
219
              })
80a28914e   吉鹏   init
220
          } else {
d7d9c38c2   Adam   auto commit the c...
221
222
            console.log('error submit!!')
            return false
80a28914e   吉鹏   init
223
          }
d7d9c38c2   Adam   auto commit the c...
224
225
226
227
228
229
230
231
232
        })
      },
      getOtherQuery(query) {
        return Object.keys(query).reduce((acc, cur) => {
          if (cur !== 'redirect') {
            acc[cur] = query[cur]
          }
          return acc
        }, {})
80a28914e   吉鹏   init
233
      }
d7d9c38c2   Adam   auto commit the c...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
      // 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
252
    }
d7d9c38c2   Adam   auto commit the c...
253
  }
80a28914e   吉鹏   init
254
255
256
257
258
  </script>
  
  <style lang="scss">
  /* 修复input 背景不协调 和光标变色 */
  /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
50760eab9   Adam   auto commit the c...
259
260
  $bg: #283443;
  $light_gray: #fff;
80a28914e   吉鹏   init
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
  $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...
303
304
305
  $bg: #2d3a4b;
  $dark_gray: #889aa4;
  $light_gray: #eee;
80a28914e   吉鹏   init
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
341
342
343
344
345
346
347
348
349
350
351
  
  .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...
352
353
354
355
356
357
358
359
360
  
      .set-language {
        color: #fff;
        position: absolute;
        top: 3px;
        font-size: 18px;
        right: 0px;
        cursor: pointer;
      }
80a28914e   吉鹏   init
361
362
363
364
365
366
367
368
369
370
371
    }
  
    .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...
372
373
374
375
376
377
378
379
380
381
382
383
  
    .thirdparty-button {
      position: absolute;
      right: 0;
      bottom: 6px;
    }
  
    @media only screen and (max-width: 470px) {
      .thirdparty-button {
        display: none;
      }
    }
80a28914e   吉鹏   init
384
385
  }
  </style>