parent
5c6c5e8ea4
commit
7d741c9436
5 changed files with 420 additions and 449 deletions
@ -1,137 +1,128 @@ |
|||||||
import Setting from "@/setting"; |
import Setting from "@/setting"; |
||||||
import util from "@/libs/util"; |
import util from "@/libs/util"; |
||||||
import { post, get, del, put } from "@/plugins/requests/index.js"; |
import { post } from "@/plugins/requests/index.js"; |
||||||
import api from "@/api"; |
import api from "@/api"; |
||||||
import addRoutes from "@/libs/route/addRoutes"; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 用户信息 |
* 用户信息 |
||||||
* */ |
* */ |
||||||
export default { |
export default { |
||||||
namespaced: true, |
namespaced: true, |
||||||
state: { |
state: { |
||||||
customer: false, // true:为客户,没有个人中心
|
customerName: "", // 客户名称
|
||||||
customerName: "", // 客户名称
|
title: "", |
||||||
title: "", |
logoUrl: "", |
||||||
logoUrl: "", |
avatar: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png", |
||||||
avatar: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png", |
userId: '', |
||||||
userId: '', |
userName: "", |
||||||
userName: "", |
roleId: "", |
||||||
roleId: "", |
dataTime: "", |
||||||
dataTime: "", |
roleName: '', |
||||||
roleName: '', |
schoolId: '', |
||||||
schoolId: '', |
fromClient: false, // 是否从学生端登录
|
||||||
fromClient: false, // 是否从学生端登录
|
logView: false // 是否查询过日志状态,如果有,则不再调接口
|
||||||
logView: false // 是否查询过日志状态,如果有,则不再调接口
|
}, |
||||||
}, |
mutations: { |
||||||
mutations: { |
SET_INFO: (state, info) => { |
||||||
SET_INFO: (state, info) => { |
if (info.avatar) state.avatar = info.userAvatars; |
||||||
if (info.avatar) state.avatar = info.userAvatars; |
state.userId = info.userId; |
||||||
state.userId = info.userId; |
state.userName = info.userName; |
||||||
state.userName = info.userName; |
state.roleId = info.roleId; |
||||||
state.roleId = info.roleId; |
state.dataTime = info.dataTime; |
||||||
state.dataTime = info.dataTime; |
}, |
||||||
}, |
SET_CUSTOMER_NAME: (state, customerName) => { |
||||||
SET_CUSTOMER: (state, customer) => { |
state.customerName = customerName; |
||||||
state.customer = customer; |
}, |
||||||
}, |
SET_TITLE: (state, title) => { |
||||||
SET_CUSTOMER_NAME: (state, customerName) => { |
state.title = title; |
||||||
state.customerName = customerName; |
}, |
||||||
}, |
SET_LOGO_URL: (state, logoUrl) => { |
||||||
SET_TITLE: (state, title) => { |
state.logoUrl = logoUrl; |
||||||
state.title = title; |
}, |
||||||
}, |
SET_AVATAR: (state, avatar) => { |
||||||
SET_LOGO_URL: (state, logoUrl) => { |
state.avatar = avatar; |
||||||
state.logoUrl = logoUrl; |
}, |
||||||
}, |
SET_USERNAME: (state, userName) => { |
||||||
SET_AVATAR: (state, avatar) => { |
state.userName = userName; |
||||||
state.avatar = avatar; |
}, |
||||||
}, |
SET_ROLENAME: (state, roleName) => { |
||||||
SET_USERNAME: (state, userName) => { |
state.roleName = roleName |
||||||
state.userName = userName; |
}, |
||||||
}, |
SET_FROM: (state, fromClient) => { |
||||||
SET_ROLENAME: (state, roleName) => { |
state.fromClient = fromClient |
||||||
state.roleName = roleName |
}, |
||||||
}, |
SET_SCHOOLID: (state, schoolId) => { |
||||||
SET_FROM: (state, fromClient) => { |
state.schoolId = schoolId |
||||||
state.fromClient = fromClient |
}, |
||||||
}, |
SET_LOG: (state) => { |
||||||
SET_SCHOOLID: (state, schoolId) => { |
state.logView = true |
||||||
state.schoolId = schoolId |
}, |
||||||
}, |
setUserId: (state, userId) => { |
||||||
SET_LOG: (state) => { |
state.userId = userId |
||||||
state.logView = true |
}, |
||||||
}, |
}, |
||||||
setUserId: (state, userId) => { |
actions: { |
||||||
state.userId = userId |
login ({ state, commit }, userInfo) { |
||||||
}, |
return new Promise((resolve, reject) => { |
||||||
}, |
post(api.logins, userInfo).then(res => { |
||||||
actions: { |
// console.log(JSON.stringify(res));
|
||||||
login({ state, commit }, userInfo) { |
if (res.status == 200) { |
||||||
return new Promise((resolve, reject) => { |
let { data } = res |
||||||
post(api.logins, userInfo).then(res => { |
util.local.set(Setting.tokenKey, data.token, Setting.tokenExpires); |
||||||
// console.log(JSON.stringify(res));
|
commit("SET_CUSTOMER", data.customer); |
||||||
if (res.status == 200) { |
commit("SET_CUSTOMER_NAME", data.customerName); |
||||||
let { data } = res; |
util.successMsg("登录成功"); |
||||||
// 生成路由权限
|
commit("SET_INFO", data); |
||||||
// 每个系统都是用这套角色权限代码的,后端也是基本一样,除了个别字段可能会不一样
|
resolve(); |
||||||
// 总体来说就两个步骤: 1是生成能够访问的路由的数组集合,2是生成能看到的按钮的数组集合
|
} else { |
||||||
// res.message.listValue && Setting.dynamicRoute && addRoutes(res.message.listValue)
|
console.log(res.message) |
||||||
// 2021-10-13重做权限,因权限系统封装
|
util.errorMsg(res.message); |
||||||
util.local.set(Setting.tokenKey, data.token, Setting.tokenExpires); |
|
||||||
commit("SET_CUSTOMER", data.customer); |
|
||||||
commit("SET_CUSTOMER_NAME", data.customerName); |
|
||||||
util.successMsg("登录成功"); |
|
||||||
commit("SET_INFO", data); |
|
||||||
resolve(); |
|
||||||
} else { |
|
||||||
console.log(res.message) |
|
||||||
util.errorMsg(res.message); |
|
||||||
|
|
||||||
reject(res); |
reject(res); |
||||||
} |
} |
||||||
}).catch(error => { |
}).catch(error => { |
||||||
reject(error); |
reject(error); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
logout({ commit, state, dispatch }) { |
logout ({ commit, state, dispatch }) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
util.local.remove(Setting.storeKey); |
post(api.logout).then(() => { |
||||||
util.local.remove(Setting.tokenKey); |
util.local.remove(Setting.storeKey) |
||||||
if (state.fromClient) { |
util.local.remove(Setting.tokenKey) |
||||||
util.cookies.remove('serverLogin') |
if (state.fromClient) { |
||||||
location.href = Setting.isDev |
util.cookies.remove('serverLogin') |
||||||
? `http://${location.hostname}:8082/#/` |
location.href = Setting.isDev |
||||||
: Setting.isTest |
? `http://${location.hostname}:8082/#/` |
||||||
? `${location.origin}/student/#/login` |
: Setting.isTest |
||||||
: `${location.origin}/#/login` |
? `${location.origin}/student/#/login` |
||||||
} else { |
: `${location.origin}/#/login` |
||||||
location.reload() |
} else { |
||||||
} |
location.reload() |
||||||
resolve(); |
} |
||||||
}); |
resolve() |
||||||
}, |
}).catch(error => { |
||||||
setInfo({ state, commit }, info) { |
reject(error) |
||||||
commit("SET_INFO", info); |
}) |
||||||
}, |
}) |
||||||
setTitle({ state, commit }, title) { |
}, |
||||||
commit("SET_TITLE", title); |
setInfo ({ state, commit }, info) { |
||||||
}, |
commit("SET_INFO", info); |
||||||
setLogoUrl({ state, commit }, logoUrl) { |
}, |
||||||
commit("SET_LOGO_URL", logoUrl); |
setTitle ({ state, commit }, title) { |
||||||
}, |
commit("SET_TITLE", title); |
||||||
setCustomer({ state, commit }, customer) { |
}, |
||||||
commit("SET_CUSTOMER", customer); |
setLogoUrl ({ state, commit }, logoUrl) { |
||||||
}, |
commit("SET_LOGO_URL", logoUrl); |
||||||
setCustomerName({ state, commit }, customerName) { |
}, |
||||||
commit("SET_CUSTOMER_NAME", customerName); |
setCustomerName ({ state, commit }, customerName) { |
||||||
}, |
commit("SET_CUSTOMER_NAME", customerName); |
||||||
setAvatar({ state, commit }, avatar) { |
}, |
||||||
commit("SET_AVATAR", avatar); |
setAvatar ({ state, commit }, avatar) { |
||||||
}, |
commit("SET_AVATAR", avatar); |
||||||
setUserName({ state, commit }, userName) { |
}, |
||||||
commit("SET_USERNAME", userName); |
setUserName ({ state, commit }, userName) { |
||||||
} |
commit("SET_USERNAME", userName); |
||||||
} |
} |
||||||
|
} |
||||||
}; |
}; |
Loading…
Reference in new issue