Browse Source

user username to login

Pan 7 years ago
parent
commit
25a4be5a93
4 changed files with 92 additions and 78 deletions
  1. 2 2
      src/api/login.js
  2. 2 2
      src/store/modules/user.js
  3. 3 4
      src/utils/validate.js
  4. 85 70
      src/views/login/index.vue

+ 2 - 2
src/api/login.js

@@ -1,11 +1,11 @@
1 1
 import fetch from '@/utils/fetch'
2 2
 
3
-export function login(email, password) {
3
+export function login(username, password) {
4 4
   return fetch({
5 5
     url: '/user/login',
6 6
     method: 'post',
7 7
     data: {
8
-      email,
8
+      username,
9 9
       password
10 10
     }
11 11
   })

+ 2 - 2
src/store/modules/user.js

@@ -27,9 +27,9 @@ const user = {
27 27
   actions: {
28 28
     // 登录
29 29
     Login({ commit }, userInfo) {
30
-      const email = userInfo.email.trim()
30
+      const username = userInfo.username.trim()
31 31
       return new Promise((resolve, reject) => {
32
-        login(email, userInfo.password).then(response => {
32
+        login(username, userInfo.password).then(response => {
33 33
           const data = response.data
34 34
           setToken(data.token)
35 35
           commit('SET_TOKEN', data.token)

+ 3 - 4
src/utils/validate.js

@@ -2,10 +2,9 @@
2 2
  * Created by jiachenpan on 16/11/18.
3 3
  */
4 4
 
5
-/* 是否是公司邮箱*/
6
-export function isWscnEmail(str) {
7
-  const reg = /^[a-z0-9](?:[-_.+]?[a-z0-9]+)*@wallstreetcn\.com$/i
8
-  return reg.test(str.trim())
5
+export function isvalidUsername(str) {
6
+  const valid_map = ['admin', 'editor']
7
+  return valid_map.indexOf(str.trim()) >= 0
9 8
 }
10 9
 
11 10
 /* 合法uri*/

+ 85 - 70
src/views/login/index.vue

@@ -3,11 +3,11 @@
3 3
     <el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left" label-width="0px"
4 4
       class="card-box login-form">
5 5
       <h3 class="title">系统登录</h3>
6
-      <el-form-item prop="email">
7
-        <span class="svg-container">
8
-          <icon-svg icon-class="email"></icon-svg>
6
+       <el-form-item prop="username">
7
+        <span class="svg-container svg-container_login">
8
+          <icon-svg icon-class="yonghuming" />
9 9
         </span>
10
-        <el-input name="email" type="text" v-model="loginForm.email" autoComplete="on" placeholder="邮箱"></el-input>
10
+        <el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="邮箱" />
11 11
       </el-form-item>
12 12
       <el-form-item prop="password">
13 13
         <span class="svg-container">
@@ -21,21 +21,21 @@
21 21
           登录
22 22
         </el-button>
23 23
       </el-form-item>
24
-      <div class='tips'>admin账号:admin@wallstreetcn.com 密码随便填</div>
25
-      <div class='tips'>editor账号:editor@wallstreetcn.com 密码随便填</div>
24
+      <div class='tips'>账号:admin 密码随便填</div>
25
+      <div class='tips'>账号:editor  密码随便填</div>
26 26
     </el-form>
27 27
   </div>
28 28
 </template>
29 29
 
30 30
 <script>
31
-import { isWscnEmail } from '@/utils/validate'
31
+import { isvalidUsername } from '@/utils/validate'
32 32
 
33 33
 export default {
34 34
   name: 'login',
35 35
   data() {
36
-    const validateEmail = (rule, value, callback) => {
37
-      if (!isWscnEmail(value)) {
38
-        callback(new Error('请输入正确的合法邮箱'))
36
+    const validateUsername = (rule, value, callback) => {
37
+      if (!isvalidUsername(value)) {
38
+        callback(new Error('请输入正确的用户名'))
39 39
       } else {
40 40
         callback()
41 41
       }
@@ -49,16 +49,12 @@ export default {
49 49
     }
50 50
     return {
51 51
       loginForm: {
52
-        email: 'admin@wallstreetcn.com',
52
+        username: 'admin',
53 53
         password: '111111'
54 54
       },
55 55
       loginRules: {
56
-        email: [
57
-                { required: true, trigger: 'blur', validator: validateEmail }
58
-        ],
59
-        password: [
60
-                { required: true, trigger: 'blur', validator: validatePass }
61
-        ]
56
+        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
57
+        password: [{ required: true, trigger: 'blur', validator: validatePass }]
62 58
       },
63 59
       loading: false
64 60
     }
@@ -85,63 +81,82 @@ export default {
85 81
 </script>
86 82
 
87 83
 <style rel="stylesheet/scss" lang="scss">
88
-    @import "src/styles/mixin.scss";
84
+  @import "src/styles/mixin.scss";
85
+  $bg:#2d3a4b;
86
+  $dark_gray:#889aa4;
87
+  $light_gray:#eee;
88
+
89
+  .login-container {
90
+    @include relative;
91
+    height: 100vh;
92
+    background-color: $bg;
93
+    input:-webkit-autofill {
94
+      -webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
95
+      -webkit-text-fill-color: #fff !important;
96
+    }
97
+    input {
98
+      background: transparent;
99
+      border: 0px;
100
+      -webkit-appearance: none;
101
+      border-radius: 0px;
102
+      padding: 12px 5px 12px 15px;
103
+      color: $light_gray;
104
+      height: 47px;
105
+    }
106
+    .el-input {
107
+      display: inline-block;
108
+      height: 47px;
109
+      width: 85%;
110
+    }
89 111
     .tips {
90 112
       font-size: 14px;
91 113
       color: #fff;
92
-      margin-bottom: 5px;
114
+      margin-bottom: 10px;
93 115
     }
94
-
95
-    .login-container {
96
-      @include relative;
97
-      height: 100vh;
98
-      background-color: #2d3a4b;
99
-      input:-webkit-autofill {
100
-        -webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
101
-        -webkit-text-fill-color: #fff !important;
102
-      }
103
-      input {
104
-        background: transparent;
105
-        border: 0px;
106
-        -webkit-appearance: none;
107
-        border-radius: 0px;
108
-        padding: 12px 5px 12px 15px;
109
-        color: #eeeeee;
110
-        height: 47px;
111
-      }
112
-      .el-input {
113
-        display: inline-block;
114
-        height: 47px;
115
-        width: 85%;
116
-      }
117
-      .svg-container {
118
-        padding: 6px 5px 6px 15px;
119
-        color: #889aa4;
120
-      }
121
-      .title {
122
-        font-size: 26px;
123
-        font-weight: 400;
124
-        color: #eeeeee;
125
-        margin: 0px auto 40px auto;
126
-        text-align: center;
127
-        font-weight: bold;
128
-      }
129
-      .login-form {
130
-        position: absolute;
131
-        left: 0;
132
-        right: 0;
133
-        width: 400px;
134
-        padding: 35px 35px 15px 35px;
135
-        margin: 120px auto;
136
-      }
137
-      .el-form-item {
138
-        border: 1px solid rgba(255, 255, 255, 0.1);
139
-        background: rgba(0, 0, 0, 0.1);
140
-        border-radius: 5px;
141
-        color: #454545;
142
-      }
143
-      .forget-pwd {
144
-        color: #fff;
116
+    .svg-container {
117
+      padding: 6px 5px 6px 15px;
118
+      color: $dark_gray;
119
+      vertical-align: middle;
120
+      width: 30px;
121
+      display: inline-block;
122
+      &_login {
123
+        font-size: 20px;
145 124
       }
146 125
     }
126
+    .title {
127
+      font-size: 26px;
128
+      font-weight: 400;
129
+      color: $light_gray;
130
+      margin: 0px auto 40px auto;
131
+      text-align: center;
132
+      font-weight: bold;
133
+    }
134
+    .login-form {
135
+      position: absolute;
136
+      left: 0;
137
+      right: 0;
138
+      width: 400px;
139
+      padding: 35px 35px 15px 35px;
140
+      margin: 120px auto;
141
+    }
142
+    .el-form-item {
143
+      border: 1px solid rgba(255, 255, 255, 0.1);
144
+      background: rgba(0, 0, 0, 0.1);
145
+      border-radius: 5px;
146
+      color: #454545;
147
+    }
148
+    .show-pwd {
149
+      position: absolute;
150
+      right: 10px;
151
+      top: 7px;
152
+      font-size: 16px;
153
+      color: $dark_gray;
154
+      cursor: pointer;
155
+    }
156
+    .thirdparty-button{
157
+      position: absolute;
158
+      right: 35px;
159
+      bottom: 28px;
160
+    }
161
+  }
147 162
 </style>