配合前后端
This commit is contained in:
18
Yi.Vue/src/store/index.js
Normal file
18
Yi.Vue/src/store/index.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import home from './modules/home'
|
||||
import user from './modules/user'
|
||||
import theme from './modules/theme'
|
||||
import loader from './modules/loader'
|
||||
Vue.use(Vuex);
|
||||
|
||||
//实例化
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
home,
|
||||
user,
|
||||
theme,
|
||||
loader
|
||||
}
|
||||
})
|
||||
export default store
|
||||
42
Yi.Vue/src/store/modules/home.js
Normal file
42
Yi.Vue/src/store/modules/home.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const state = { //状态
|
||||
plateId: 0,
|
||||
discussId: 0,
|
||||
plateString: "",
|
||||
}
|
||||
|
||||
const mutations = { //变化//载荷
|
||||
SET_PLATEID(state, n) {
|
||||
state.plateId = n
|
||||
},
|
||||
SET_DOSCUSSIDSTRING(state, n) {
|
||||
state.plateString = n
|
||||
},
|
||||
SET_DOSCUSSID(state, n) {
|
||||
state.discussId = n
|
||||
},
|
||||
}
|
||||
|
||||
//在action中可以配合axios进行权限判断
|
||||
const actions = { //动作
|
||||
set_plateId(context, n) {
|
||||
context.commit('SET_PLATEID', n)
|
||||
},
|
||||
set_plateString(context, n) {
|
||||
context.commit('SET_DOSCUSSIDSTRING', n)
|
||||
},
|
||||
set_discussId(context, n) {
|
||||
context.commit('SET_DOSCUSSID', n)
|
||||
}
|
||||
}
|
||||
|
||||
// const getters = { //类似与计算属性 派生属性
|
||||
// msg(state) {
|
||||
// if (state.count > 80) {
|
||||
// return "成绩优异"
|
||||
// } else {
|
||||
// return "成绩不合格"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
export default { state, mutations, actions }
|
||||
34
Yi.Vue/src/store/modules/loader.js
Normal file
34
Yi.Vue/src/store/modules/loader.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const state = { //状态
|
||||
load: false
|
||||
}
|
||||
|
||||
const mutations = { //变化//载荷
|
||||
OPEN(state) {
|
||||
state.load = true;
|
||||
},
|
||||
CLOSE(state) {
|
||||
state.load = false;
|
||||
},
|
||||
}
|
||||
|
||||
//在action中可以配合axios进行权限判断
|
||||
const actions = { //动作
|
||||
openLoad(context) {
|
||||
context.commit('OPEN')
|
||||
},
|
||||
closeLoad(context) {
|
||||
context.commit('CLOSE')
|
||||
}
|
||||
}
|
||||
|
||||
// const getters = { //类似与计算属性 派生属性
|
||||
// msg(state) {
|
||||
// if (state.count > 80) {
|
||||
// return "成绩优异"
|
||||
// } else {
|
||||
// return "成绩不合格"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
export default { state, mutations, actions }
|
||||
33
Yi.Vue/src/store/modules/theme.js
Normal file
33
Yi.Vue/src/store/modules/theme.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import vuetify from '../../plugins/vuetify';
|
||||
const state = { //状态
|
||||
light: {
|
||||
primary: '#1976D2',
|
||||
secondary: '#424242',
|
||||
accent: '#82B1FF',
|
||||
error: '#FF5252',
|
||||
info: '#2196F3',
|
||||
success: '#4CAF50',
|
||||
warning: '#FFC107',
|
||||
cyan: "#FAB2B1",
|
||||
blue: "#2196F3"
|
||||
},
|
||||
dark: {}
|
||||
}
|
||||
|
||||
const mutations = { //变化//载荷
|
||||
SET_Light(state, n) {
|
||||
state.light = n
|
||||
vuetify.framework.theme.themes.light = n
|
||||
},
|
||||
}
|
||||
|
||||
//在action中可以配合axios进行权限判断
|
||||
const actions = { //动作
|
||||
set_light(context, n) {
|
||||
context.commit('SET_Light', n)
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default { state, mutations, actions }
|
||||
122
Yi.Vue/src/store/modules/user.js
Normal file
122
Yi.Vue/src/store/modules/user.js
Normal file
@@ -0,0 +1,122 @@
|
||||
import { getToken, setToken, getUser, setUser, removeToken } from '../../util/usertoken'
|
||||
import accountApi from "@/api/accountApi"
|
||||
|
||||
//再导入axion请求
|
||||
const state = { //状态
|
||||
token: getToken(),
|
||||
user: getUser()
|
||||
}
|
||||
|
||||
const mutations = { //变化//载荷
|
||||
SET_TOKEN(state, token) {
|
||||
state.token = token
|
||||
setToken(token)
|
||||
},
|
||||
SET_USER(state, user) {
|
||||
state.user = user
|
||||
setUser(user)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//在action中可以配合axios进行权限判断
|
||||
const actions = { //动作
|
||||
setIcon({ commit, state }, icon) {
|
||||
state.user.icon = icon
|
||||
commit('SET_USER', state.user)
|
||||
},
|
||||
|
||||
|
||||
setLevel({ commit, state }, level) {
|
||||
|
||||
commit('SET_USER', state.user)
|
||||
},
|
||||
|
||||
// qqUpdate({ state }, openid) {
|
||||
// return new Promise((resolv, reject) => {
|
||||
// qqApi.qqupdate(openid, state.user.id).then(resp => {
|
||||
// resolv(resp)
|
||||
// }).catch(error => {
|
||||
// reject(error)
|
||||
// })
|
||||
// })
|
||||
// },
|
||||
|
||||
// qqLogin({ commit }, openid) {
|
||||
// return new Promise((resolv, reject) => {
|
||||
// qqApi.qqlogin(openid).then(resp => {
|
||||
// if (resp.status) {
|
||||
// commit('SET_TOKEN', resp.data.token)
|
||||
// commit('SET_USER', resp.data.user)
|
||||
// }
|
||||
// resolv(resp)
|
||||
// }).catch(error => {
|
||||
// reject(error)
|
||||
// })
|
||||
// })
|
||||
// },
|
||||
|
||||
Login({ commit }, form) {
|
||||
return new Promise((resolv, reject) => {
|
||||
accountApi.login(form.username.trim(), form.password.trim()).then(resp => {
|
||||
if (resp.status) {
|
||||
commit('SET_TOKEN', resp.data.token)
|
||||
commit('SET_USER', resp.data.user)
|
||||
}
|
||||
|
||||
resolv(resp)
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
|
||||
Register({ commit }, form) {
|
||||
return new Promise((resolv, reject) => {
|
||||
accountApi.register(form.username.trim(), form.password.trim(), form.email.trim(), form.code.trim()).then(resp => {
|
||||
resolv(resp)
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
Logged({ commit }) {
|
||||
return new Promise((resolv, reject) => {
|
||||
accountApi.logged().then(resp => {
|
||||
resolv(resp)
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// GetUserInfo({ commit, state }) {
|
||||
// return new Promise((resolv, reject) => {
|
||||
// // getUserInfo(state.token).then(response => {
|
||||
// // commit('SET_USER', response.data)
|
||||
// // resolve(response)
|
||||
// // }).catch(error=>{
|
||||
// // reject(error)
|
||||
// // })
|
||||
// })
|
||||
// },
|
||||
Logout({ commit, state }) {
|
||||
return new Promise((resolv, reject) => {
|
||||
accountApi.logout().then(response => {
|
||||
commit('SET_TOKEN', '')
|
||||
commit('SET_USER', null)
|
||||
removeToken()
|
||||
resolv(response)
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default { state, mutations, actions }
|
||||
Reference in New Issue
Block a user