mirror of
https://github.com/iczer/vue-antd-admin
synced 2025-04-05 19:41:37 +08:00
feat: add account state
This commit is contained in:
parent
f2a11aa058
commit
fef089a8b5
@ -124,28 +124,23 @@ export default {
|
||||
PageHeader},
|
||||
data () {
|
||||
return {
|
||||
currUser: {},
|
||||
projects: [],
|
||||
loading: true,
|
||||
activities: [],
|
||||
teams: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
currUser () {
|
||||
return this.$store.state.account.user
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.currentUser()
|
||||
this.getProjectList()
|
||||
this.getActivites()
|
||||
this.getTeams()
|
||||
},
|
||||
methods: {
|
||||
currentUser () {
|
||||
this.$axios({
|
||||
method: 'get',
|
||||
url: '/user/current'
|
||||
}).then(res => {
|
||||
this.currUser = res.data
|
||||
})
|
||||
},
|
||||
getProjectList () {
|
||||
this.$axios({
|
||||
method: 'get',
|
||||
|
@ -36,25 +36,9 @@ const AMenuDivider = AMenu.Divider
|
||||
export default {
|
||||
name: 'HeaderAvatar',
|
||||
components: {AMenu, AMenuItem, AMenuDivider, AIcon, AAvatar, ADropdown},
|
||||
data () {
|
||||
return {
|
||||
currUser: {
|
||||
name: 'XXXXX',
|
||||
avatar: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.currentUser()
|
||||
},
|
||||
methods: {
|
||||
currentUser () {
|
||||
this.$axios({
|
||||
method: 'get',
|
||||
url: '/user/current'
|
||||
}).then(res => {
|
||||
this.currUser = res.data
|
||||
})
|
||||
computed: {
|
||||
currUser () {
|
||||
return this.$store.state.account.user
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,9 @@ export default {
|
||||
this.logging = false
|
||||
const result = res.data
|
||||
if (result.code >= 0) {
|
||||
const user = result.data.user
|
||||
this.$router.push('/dashboard/workplace')
|
||||
this.$store.commit('account/setuser', user)
|
||||
this.$message.success(result.message, 3)
|
||||
} else {
|
||||
this.error = result.message
|
||||
|
@ -8,18 +8,18 @@ import Viser from 'viser-vue'
|
||||
import axios from 'axios'
|
||||
import message from 'ant-design-vue/es/message'
|
||||
import '@/mock'
|
||||
import Vuex from 'vuex'
|
||||
import store from './store'
|
||||
|
||||
Vue.prototype.$axios = axios
|
||||
Vue.prototype.$message = message
|
||||
Vue.config.productionTip = false
|
||||
Vue.use(Viser)
|
||||
Vue.use(Vuex)
|
||||
|
||||
/* eslint-disable no-new */
|
||||
new Vue({
|
||||
el: '#app',
|
||||
router,
|
||||
store,
|
||||
components: { App },
|
||||
template: '<App/>'
|
||||
})
|
||||
|
@ -1,6 +1,15 @@
|
||||
import Mock from 'mockjs'
|
||||
import '@/mock/extend'
|
||||
|
||||
const user = Mock.mock({
|
||||
name: '@ADMIN',
|
||||
avatar: '@AVATAR',
|
||||
address: '@CITY',
|
||||
welcome: '@WELCOME',
|
||||
timefix: '@TIMEFIX',
|
||||
position: '@POSITION'
|
||||
})
|
||||
|
||||
Mock.mock('/login', 'post', ({body}) => {
|
||||
let result = {}
|
||||
const {name, password} = JSON.parse(body)
|
||||
@ -11,6 +20,8 @@ Mock.mock('/login', 'post', ({body}) => {
|
||||
} else {
|
||||
result.code = 0
|
||||
result.message = Mock.mock('@TIMEFIX') + ',欢迎回来'
|
||||
result.data = {}
|
||||
result.data.user = user
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
11
src/store/index.js
Normal file
11
src/store/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import account from './modules/account'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
account
|
||||
}
|
||||
})
|
11
src/store/modules/account.js
Normal file
11
src/store/modules/account.js
Normal file
@ -0,0 +1,11 @@
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
user: {}
|
||||
},
|
||||
mutations: {
|
||||
setuser (state, user) {
|
||||
state.user = user
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user