Commit 9804b54b00630388eac3014b248589d1c0c458de
1 parent
89d744de
提交登陆
Showing
6 changed files
with
55 additions
and
35 deletions
.env.development
src/api/user.js
... | ... | @@ -2,23 +2,36 @@ import request from '@/utils/request' |
2 | 2 | |
3 | 3 | export function login(data) { |
4 | 4 | return request({ |
5 | - url: '/user/login', | |
5 | + url: '/personPc/login', | |
6 | 6 | method: 'post', |
7 | - data | |
7 | + params: { userPhone:data.userPhone,validatorCode:data.validatorCode } | |
8 | 8 | }) |
9 | 9 | } |
10 | 10 | |
11 | 11 | export function getInfo(token) { |
12 | + debugger | |
12 | 13 | return request({ |
13 | - url: '/user/info', | |
14 | - method: 'get', | |
14 | + url: '/personPc/getUserInfo', | |
15 | + method: 'post', | |
15 | 16 | params: { token } |
16 | 17 | }) |
17 | 18 | } |
18 | 19 | |
20 | +/** | |
21 | + * userPhone | |
22 | + * @param userPhone | |
23 | + */ | |
24 | +export function sendValidatorCode(userPhone) { | |
25 | + return request({ | |
26 | + url: '/personPc/sendValidatorCode', | |
27 | + method: 'post', | |
28 | + params: { userPhone } | |
29 | + }) | |
30 | +} | |
31 | + | |
19 | 32 | export function logout() { |
20 | 33 | return request({ |
21 | - url: '/user/logout', | |
34 | + url: '/personPc/logout', | |
22 | 35 | method: 'post' |
23 | 36 | }) |
24 | 37 | } | ... | ... |
src/main.js
... | ... | @@ -23,10 +23,10 @@ import '@/permission' // permission control |
23 | 23 | * Currently MockJs will be used in the production environment, |
24 | 24 | * please remove it before going online! ! ! |
25 | 25 | */ |
26 | -import { mockXHR } from '../mock' | |
27 | -if (process.env.NODE_ENV === 'production') { | |
28 | - mockXHR() | |
29 | -} | |
26 | +// import { mockXHR } from '../mock' | |
27 | +// if (process.env.NODE_ENV === 'production') { | |
28 | +// mockXHR() | |
29 | +// } | |
30 | 30 | |
31 | 31 | // set ElementUI lang to EN |
32 | 32 | Vue.use(ElementUI, { locale }) | ... | ... |
src/store/modules/user.js
... | ... | @@ -5,7 +5,8 @@ import { resetRouter } from '@/router' |
5 | 5 | const state = { |
6 | 6 | token: getToken(), |
7 | 7 | name: '', |
8 | - avatar: '' | |
8 | + avatar: '', | |
9 | + userInfo:'' | |
9 | 10 | } |
10 | 11 | |
11 | 12 | const mutations = { |
... | ... | @@ -17,16 +18,21 @@ const mutations = { |
17 | 18 | }, |
18 | 19 | SET_AVATAR: (state, avatar) => { |
19 | 20 | state.avatar = avatar |
21 | + }, | |
22 | + SET_USERINFO: (state, userInfo) => { | |
23 | + state.userInfo = userInfo | |
20 | 24 | } |
21 | 25 | } |
22 | 26 | |
23 | 27 | const actions = { |
24 | 28 | // user login |
25 | 29 | login({ commit }, userInfo) { |
26 | - const { username, password } = userInfo | |
30 | + debugger | |
31 | + const { phone, password } = userInfo | |
27 | 32 | return new Promise((resolve, reject) => { |
28 | - login({ username: username.trim(), password: password }).then(response => { | |
33 | + login({ userPhone: phone.trim(), validatorCode: password }).then(response => { | |
29 | 34 | const { data } = response |
35 | + debugger; | |
30 | 36 | commit('SET_TOKEN', data.token) |
31 | 37 | setToken(data.token) |
32 | 38 | resolve() |
... | ... | @@ -39,6 +45,7 @@ const actions = { |
39 | 45 | // get user info |
40 | 46 | getInfo({ commit, state }) { |
41 | 47 | return new Promise((resolve, reject) => { |
48 | + debugger | |
42 | 49 | getInfo(state.token).then(response => { |
43 | 50 | const { data } = response |
44 | 51 | |
... | ... | @@ -46,11 +53,13 @@ const actions = { |
46 | 53 | reject('Verification failed, please Login again.') |
47 | 54 | } |
48 | 55 | |
49 | - const { name, avatar } = data | |
56 | + const { custName, headPicUrl } = data | |
57 | + | |
58 | + commit('SET_NAME', custName) | |
59 | + commit('SET_AVATAR', headPicUrl) | |
60 | + commit('SET_USERINFO', data) | |
50 | 61 | |
51 | - commit('SET_NAME', name) | |
52 | - commit('SET_AVATAR', avatar) | |
53 | - resolve(data) | |
62 | + resolve({roles:[]}) | |
54 | 63 | }).catch(error => { |
55 | 64 | reject(error) |
56 | 65 | }) | ... | ... |
src/utils/request.js
... | ... | @@ -7,7 +7,7 @@ import { getToken } from '@/utils/auth' |
7 | 7 | const service = axios.create({ |
8 | 8 | baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url |
9 | 9 | // withCredentials: true, // send cookies when cross-domain requests |
10 | - timeout: 5000 // request timeout | |
10 | + timeout: 50000 // request timeout | |
11 | 11 | }) |
12 | 12 | |
13 | 13 | // request interceptor |
... | ... | @@ -19,7 +19,7 @@ service.interceptors.request.use( |
19 | 19 | // let each request carry token |
20 | 20 | // ['X-Token'] is a custom headers key |
21 | 21 | // please modify it according to the actual situation |
22 | - config.headers['X-Token'] = getToken() | |
22 | + config.headers['X-Auth-Token'] = getToken() | |
23 | 23 | } |
24 | 24 | return config |
25 | 25 | }, |
... | ... | @@ -44,34 +44,21 @@ service.interceptors.response.use( |
44 | 44 | */ |
45 | 45 | response => { |
46 | 46 | const res = response.data |
47 | - | |
48 | 47 | // if the custom code is not 20000, it is judged as an error. |
49 | - if (res.code !== 20000) { | |
48 | + if (res.code !='8888') { | |
50 | 49 | Message({ |
51 | 50 | message: res.message || 'Error', |
52 | 51 | type: 'error', |
53 | 52 | duration: 5 * 1000 |
54 | 53 | }) |
55 | 54 | |
56 | - // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired; | |
57 | - if (res.code === 50008 || res.code === 50012 || res.code === 50014) { | |
58 | - // to re-login | |
59 | - MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', { | |
60 | - confirmButtonText: 'Re-Login', | |
61 | - cancelButtonText: 'Cancel', | |
62 | - type: 'warning' | |
63 | - }).then(() => { | |
64 | - store.dispatch('user/resetToken').then(() => { | |
65 | - location.reload() | |
66 | - }) | |
67 | - }) | |
68 | - } | |
69 | 55 | return Promise.reject(new Error(res.message || 'Error')) |
70 | 56 | } else { |
71 | 57 | return res |
72 | 58 | } |
73 | 59 | }, |
74 | 60 | error => { |
61 | + debugger | |
75 | 62 | console.log('err' + error) // for debug |
76 | 63 | Message({ |
77 | 64 | message: error.message, | ... | ... |
src/views/login/index.vue
... | ... | @@ -51,6 +51,7 @@ |
51 | 51 | |
52 | 52 | <script> |
53 | 53 | import {validUsername} from '@/utils/validate' |
54 | +import {sendValidatorCode} from '@/api/user.js' | |
54 | 55 | |
55 | 56 | export default { |
56 | 57 | name: 'Login', |
... | ... | @@ -99,6 +100,7 @@ export default { |
99 | 100 | }, |
100 | 101 | methods: { |
101 | 102 | getVerifyCode(){ |
103 | + let phone = this.loginForm.phone; | |
102 | 104 | if (!this.loginForm.phone) { |
103 | 105 | new Error('请输入手机号!'); |
104 | 106 | } else if(!/^1[345678]\d{9}$/.test(this.loginForm.phone)) { |
... | ... | @@ -106,7 +108,15 @@ export default { |
106 | 108 | } |
107 | 109 | //获取验证码 |
108 | 110 | else { |
109 | - this.validateBtn() | |
111 | + sendValidatorCode(phone).then(response =>{ | |
112 | + if(response.code=='8888'){ | |
113 | + this.$message({ | |
114 | + type: 'success', | |
115 | + message: '验证码发送成功!' | |
116 | + }); | |
117 | + } | |
118 | + }); | |
119 | + this.validateBtn(); | |
110 | 120 | } |
111 | 121 | }, |
112 | 122 | validateBtn(){ |
... | ... | @@ -126,6 +136,7 @@ export default { |
126 | 136 | }, |
127 | 137 | handleLogin() { |
128 | 138 | this.$refs.loginForm.validate(valid => { |
139 | + debugger | |
129 | 140 | if (valid) { |
130 | 141 | this.loading = true |
131 | 142 | this.$store.dispatch('user/login', this.loginForm).then(() => { | ... | ... |