Skip to content
This repository was archived by the owner on May 12, 2020. It is now read-only.

Commit c789ac8

Browse files
committed
feat(Login): login module implementation
1 parent 7c8099c commit c789ac8

8 files changed

Lines changed: 45 additions & 16 deletions

File tree

src/pages/Home.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
</template>
66

77
<script>
8-
98
export default {
109
name: 'home'
1110
}

src/pages/Login/index.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,8 @@ export default {
6868
onSubmit () {
6969
this.$refs.login.validate(isValid => {
7070
if (!isValid) return
71-
this.loading = true
72-
// this.pushLogin({
73-
// userInfo: this.loginForm,
74-
// replace: this.$router.replace.bind(this.$router)
75-
// })
76-
// .finally(() => { this.loading = false })
77-
this.$router.push('/')
71+
this.$store.dispatch('login/userLogin', this.userInfo)
72+
.then(() => this.$router.push('/'))
7873
})
7974
}
8075
}

src/store/modules/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import login from './login'
22

33
export default {
4-
login: {
5-
namespaced: true,
6-
...login
7-
}
4+
login
85
}

src/store/modules/login/actions.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { userLogin } from 'API'
2+
import types from './mutations/types'
3+
4+
export default {
5+
userLogin ({ commit }, { username, password }) {
6+
return userLogin({
7+
username,
8+
password
9+
})
10+
.then(res => {
11+
commit(types.SET_USERNAME, username)
12+
commit(types.SET_ACCESS_TOKEN, res.access_token)
13+
})
14+
.catch(console.error)
15+
}
16+
}

src/store/modules/login/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import state from './state'
2+
import mutations from './mutations'
3+
import actions from './actions'
4+
15
export default {
2-
state: {},
3-
getters: {},
4-
mutations: {},
5-
actions: {}
6+
namespaced: true,
7+
state,
8+
mutations,
9+
actions
610
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import types from './types'
2+
3+
export default {
4+
[types.SET_USERNAME] (state, username) {
5+
state.username = username
6+
},
7+
[types.SET_ACCESS_TOKEN] (state, accessToken) {
8+
state.accessToken = accessToken
9+
}
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
SET_USERNAME: 'SET_USERNAME',
3+
SET_ACCESS_TOKEN: 'SET_ACCESS_TOKEN'
4+
}

src/store/modules/login/state.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
username: '',
3+
accessToken: ''
4+
}

0 commit comments

Comments
 (0)