登录接口
This commit is contained in:
parent
415369a430
commit
9ff4038838
@ -13,8 +13,10 @@ import com.fuint.business.userManager.entity.MtInvitation;
|
|||||||
import com.fuint.business.userManager.entity.UserBalance;
|
import com.fuint.business.userManager.entity.UserBalance;
|
||||||
import com.fuint.business.userManager.mapper.MtInvitationMapper;
|
import com.fuint.business.userManager.mapper.MtInvitationMapper;
|
||||||
import com.fuint.business.userManager.mapper.UserBalanceMapper;
|
import com.fuint.business.userManager.mapper.UserBalanceMapper;
|
||||||
|
import com.fuint.business.userManager.service.LJUserService;
|
||||||
import com.fuint.business.userManager.service.MtInvitationService;
|
import com.fuint.business.userManager.service.MtInvitationService;
|
||||||
import com.fuint.business.userManager.service.UserBalanceService;
|
import com.fuint.business.userManager.service.UserBalanceService;
|
||||||
|
import com.fuint.business.userManager.vo.LJUserVo;
|
||||||
import com.fuint.common.dto.AccountInfo;
|
import com.fuint.common.dto.AccountInfo;
|
||||||
import com.fuint.common.dto.MemberTopDto;
|
import com.fuint.common.dto.MemberTopDto;
|
||||||
import com.fuint.common.dto.UserDto;
|
import com.fuint.common.dto.UserDto;
|
||||||
@ -725,9 +727,10 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserBalanceService userBalanceService;
|
private UserBalanceService userBalanceService;
|
||||||
@Autowired
|
@Resource
|
||||||
private ILJStoreService iljStoreService;
|
private ILJStoreService iljStoreService;
|
||||||
|
@Resource
|
||||||
|
LJUserService ljUserService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MtUser queryMemberByOpenId2(String openId, JSONObject userInfo) throws BusinessCheckException {
|
public MtUser queryMemberByOpenId2(String openId, JSONObject userInfo) throws BusinessCheckException {
|
||||||
@ -747,64 +750,31 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
|
|||||||
String source = StringUtil.isNotEmpty(userInfo.getString("source")) ? userInfo.getString("source") : MemberSourceEnum.WECHAT_LOGIN.getKey();
|
String source = StringUtil.isNotEmpty(userInfo.getString("source")) ? userInfo.getString("source") : MemberSourceEnum.WECHAT_LOGIN.getKey();
|
||||||
|
|
||||||
|
|
||||||
|
// 根绝手机号查询是否有该用户 没有则新建 有就更新
|
||||||
// openid没有时,使用手机号
|
if (ObjectUtil.isNotEmpty(mobile) || "".equals(mobile)) {
|
||||||
if (user == null) {
|
|
||||||
MtUser mtUser = new MtUser();
|
|
||||||
if (StringUtil.isNotEmpty(mobile)) {
|
|
||||||
MtUser mtUserMobile = queryMemberByMobile2(mobile);
|
MtUser mtUserMobile = queryMemberByMobile2(mobile);
|
||||||
if (mtUserMobile != null) {
|
MtUser mtUser = new MtUser();
|
||||||
mtUser = mtUserMobile;
|
|
||||||
}
|
if (ObjectUtil.isEmpty(mtUserMobile)) {
|
||||||
}
|
// 新增
|
||||||
// 昵称为空,用手机号
|
// LJUserVo userVo = new LJUserVo();
|
||||||
if (StringUtil.isEmpty(nickName) && StringUtil.isNotEmpty(mobile)) {
|
|
||||||
nickName = mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
|
|
||||||
}
|
|
||||||
String userNo = CommonUtil.createUserNo();
|
|
||||||
mobile = CommonUtil.replaceXSS(mobile);
|
|
||||||
avatar = CommonUtil.replaceXSS(avatar);
|
|
||||||
nickName = CommonUtil.replaceXSS(nickName);
|
|
||||||
mtUser.setUserNo(userNo);
|
|
||||||
mtUser.setMobile(mobile);
|
|
||||||
mtUser.setAvatar(avatar);
|
|
||||||
mtUser.setName(nickName);
|
|
||||||
mtUser.setOpenId(openId);
|
mtUser.setOpenId(openId);
|
||||||
// MtUserGrade grade = userGradeService.getInitUserGrade(merchantId);
|
|
||||||
// if (grade != null) {
|
mtUser.setMobile(mobile);
|
||||||
// mtUser.setGradeId(grade.getId() + "");
|
mtUser.setCreateTime(new Date());
|
||||||
// }
|
mtUser.setUpdateTime(new Date());
|
||||||
Date time = new Date();
|
|
||||||
mtUser.setCreateTime(time);
|
|
||||||
mtUser.setUpdateTime(time);
|
|
||||||
mtUser.setBalance(new BigDecimal(0));
|
|
||||||
mtUser.setPoint(0);
|
|
||||||
mtUser.setDescription("微信登录自动注册");
|
mtUser.setDescription("微信登录自动注册");
|
||||||
mtUser.setIdcard("");
|
|
||||||
mtUser.setStatus("qy");
|
mtUser.setStatus("qy");
|
||||||
mtUser.setAddress(country + province + city);
|
mtUser.setSex(Integer.parseInt(gender));
|
||||||
|
mtUser.setUserNo(editUserNo());
|
||||||
// 微信用户 1:男;2:女 0:未知
|
// 微信用户 1:男;2:女 0:未知
|
||||||
if (gender.equals(GenderEnum.FEMALE.getKey().toString())) {
|
if (gender.equals(GenderEnum.FEMALE.getKey().toString())) {
|
||||||
gender = GenderEnum.UNKNOWN.getKey().toString();
|
gender = GenderEnum.UNKNOWN.getKey().toString();
|
||||||
} else if (gender.equals(GenderEnum.UNKNOWN.getKey().toString())) {
|
} else if (gender.equals(GenderEnum.UNKNOWN.getKey().toString())) {
|
||||||
gender = GenderEnum.FEMALE.getKey().toString();
|
gender = GenderEnum.FEMALE.getKey().toString();
|
||||||
}
|
}
|
||||||
mtUser.setSex(Integer.parseInt(gender));
|
|
||||||
if (StringUtil.isNotEmpty(storeId)) {
|
|
||||||
mtUser.setStoreId(Integer.parseInt(storeId));
|
|
||||||
} else {
|
|
||||||
mtUser.setStoreId(0);
|
|
||||||
}
|
|
||||||
mtUser.setSource(source);
|
|
||||||
mtUser.setCreateTime(new Date());
|
|
||||||
mtUser.setUpdateTime(new Date());
|
|
||||||
if (mtUser.getId() == null || mtUser.getId() <= 0) {
|
|
||||||
save(mtUser);
|
|
||||||
} else {
|
|
||||||
updateById(mtUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
user = mtUserMapper.queryMemberByOpenId2(openId);
|
save(mtUser);
|
||||||
|
|
||||||
// 新增余额信息
|
// 新增余额信息
|
||||||
if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
|
if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
|
||||||
@ -842,16 +812,17 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
|
|||||||
mtInvitationMapper.insert(mtInvitation);
|
mtInvitationMapper.insert(mtInvitation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return mtUser;
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
// 已被禁用
|
// 已被禁用
|
||||||
if (user.getStatus().equals(StatusEnum.DISABLE.getKey())) {
|
if (user.getStatus().equals(StatusEnum.DISABLE.getKey())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 补充手机号
|
// 修改
|
||||||
if (StringUtil.isNotEmpty(mobile)) {
|
mtUserMobile.setOpenId(openId);
|
||||||
user.setMobile(mobile);
|
|
||||||
updateById(user);
|
updateById(mtUserMobile);
|
||||||
}
|
|
||||||
|
|
||||||
if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
|
if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
|
||||||
MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
|
MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
|
||||||
@ -865,12 +836,150 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return mtUserMobile;
|
||||||
|
|
||||||
return user;
|
} else {
|
||||||
|
// 使用openId查询
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// // openid没有时,使用手机号
|
||||||
|
// if (user == null) {
|
||||||
|
// MtUser mtUser = new MtUser();
|
||||||
|
// if (StringUtil.isNotEmpty(mobile)) {
|
||||||
|
// MtUser mtUserMobile = queryMemberByMobile2(mobile);
|
||||||
|
// if (mtUserMobile != null) {
|
||||||
|
// mtUser = mtUserMobile;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // 昵称为空,用手机号
|
||||||
|
// if (StringUtil.isEmpty(nickName) && StringUtil.isNotEmpty(mobile)) {
|
||||||
|
// nickName = mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
|
||||||
|
// }
|
||||||
|
// String userNo = CommonUtil.createUserNo();
|
||||||
|
// mobile = CommonUtil.replaceXSS(mobile);
|
||||||
|
// avatar = CommonUtil.replaceXSS(avatar);
|
||||||
|
// nickName = CommonUtil.replaceXSS(nickName);
|
||||||
|
// mtUser.setUserNo(userNo);
|
||||||
|
// mtUser.setMobile(mobile);
|
||||||
|
// mtUser.setAvatar(avatar);
|
||||||
|
// mtUser.setName(nickName);
|
||||||
|
// mtUser.setOpenId(openId);
|
||||||
|
//
|
||||||
|
// Date time = new Date();
|
||||||
|
// mtUser.setCreateTime(time);
|
||||||
|
// mtUser.setUpdateTime(time);
|
||||||
|
// mtUser.setBalance(new BigDecimal(0));
|
||||||
|
// mtUser.setPoint(0);
|
||||||
|
// mtUser.setDescription("微信登录自动注册");
|
||||||
|
// mtUser.setIdcard("");
|
||||||
|
// mtUser.setStatus("qy");
|
||||||
|
// // 微信用户 1:男;2:女 0:未知
|
||||||
|
// if (gender.equals(GenderEnum.FEMALE.getKey().toString())) {
|
||||||
|
// gender = GenderEnum.UNKNOWN.getKey().toString();
|
||||||
|
// } else if (gender.equals(GenderEnum.UNKNOWN.getKey().toString())) {
|
||||||
|
// gender = GenderEnum.FEMALE.getKey().toString();
|
||||||
|
// }
|
||||||
|
// mtUser.setSex(Integer.parseInt(gender));
|
||||||
|
//
|
||||||
|
// mtUser.setSource(source);
|
||||||
|
// if (mtUser.getId() == null || mtUser.getId() <= 0) {
|
||||||
|
// save(mtUser);
|
||||||
|
// } else {
|
||||||
|
// updateById(mtUser);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// user = mtUserMapper.queryMemberByOpenId2(openId);
|
||||||
|
//
|
||||||
|
// // 新增余额信息
|
||||||
|
// if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
|
||||||
|
// // 根据userid和stortId查询是否存在对应的余额信息
|
||||||
|
// UserBalance userBalance = userBalanceService.selectUserBalance(user.getId(), Integer.parseInt(storeId));
|
||||||
|
// if (ObjectUtil.isEmpty(userBalance)) {
|
||||||
|
// // 新增余额信息
|
||||||
|
// UserBalance userBalanceAdd = new UserBalance();
|
||||||
|
// userBalanceAdd.setMtUserId(user.getId());
|
||||||
|
// userBalanceAdd.setStoreId(Integer.parseInt(storeId));
|
||||||
|
// userBalanceAdd.setCardBalance(0.0);
|
||||||
|
// userBalanceAdd.setPoints(0);
|
||||||
|
// userBalanceAdd.setGrowthValue(0);
|
||||||
|
// userBalanceAdd.setConsumeNum(0);
|
||||||
|
//
|
||||||
|
// MtUserGrade lowGrade = userGradeService.getLowGrade(Integer.parseInt(storeId));
|
||||||
|
// if (ObjectUtil.isNotEmpty(lowGrade) && ObjectUtil.isNotEmpty(lowGrade.getId())) {
|
||||||
|
// userBalanceAdd.setGradeId(lowGrade.getId());
|
||||||
|
// }
|
||||||
|
// // 新增会员余额信息
|
||||||
|
// userBalanceService.insertUserBalance(userBalanceAdd);
|
||||||
|
// }
|
||||||
|
// LJStore store = iljStoreService.selectStoreByStoreId(Integer.parseInt(storeId));
|
||||||
|
// // 查询关联表里面是否有信息
|
||||||
|
// MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
|
||||||
|
// if (ObjectUtil.isEmpty(mtInvitation1)) {
|
||||||
|
// MtInvitation mtInvitation = new MtInvitation();
|
||||||
|
// mtInvitation.setUserId(user.getId());
|
||||||
|
// mtInvitation.setStoreId(Integer.parseInt(storeId));
|
||||||
|
// mtInvitation.setStaffId(Integer.parseInt(staffId));
|
||||||
|
// mtInvitation.setInviterId(Integer.parseInt(inviterId));
|
||||||
|
// if (!ObjectUtil.isEmpty(store)){
|
||||||
|
// mtInvitation.setChainStoreId(store.getChainStoreId());
|
||||||
|
// }
|
||||||
|
// mtInvitationMapper.insert(mtInvitation);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// // 已被禁用
|
||||||
|
// if (user.getStatus().equals(StatusEnum.DISABLE.getKey())) {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// // 补充手机号
|
||||||
|
// if (StringUtil.isNotEmpty(mobile)) {
|
||||||
|
// user.setMobile(mobile);
|
||||||
|
// updateById(user);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
|
||||||
|
// MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
|
||||||
|
// if (ObjectUtil.isEmpty(mtInvitation1)) {
|
||||||
|
// MtInvitation mtInvitation = new MtInvitation();
|
||||||
|
// mtInvitation.setUserId(user.getId());
|
||||||
|
// mtInvitation.setStoreId(Integer.parseInt(storeId));
|
||||||
|
// mtInvitation.setStaffId(Integer.parseInt(staffId));
|
||||||
|
// mtInvitation.setInviterId(Integer.parseInt(inviterId));
|
||||||
|
// mtInvitationMapper.insert(mtInvitation);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//生成用户编号
|
||||||
|
private String editUserNo() {
|
||||||
|
Random random = new Random();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
sb.append(random.nextInt(10));
|
||||||
|
}
|
||||||
|
String digits = sb.toString();
|
||||||
|
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < digits.length(); i++) {
|
||||||
|
int digit = Integer.parseInt(String.valueOf(digits.charAt(i)));
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
sum += digit;
|
||||||
|
} else {
|
||||||
|
sum += digit * 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int checksum = (10 - (sum % 10)) % 10;
|
||||||
|
|
||||||
|
String number = digits + checksum;
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,66 +106,32 @@ public class ClientSignController extends BaseController {
|
|||||||
logger.info("微信授权登录参数:{}", param);
|
logger.info("微信授权登录参数:{}", param);
|
||||||
JSONObject userInfo = paramsObj.getJSONObject("userInfo");
|
JSONObject userInfo = paramsObj.getJSONObject("userInfo");
|
||||||
String storeId = ObjectUtil.isEmpty(userInfo.get("storeId"))? "" : userInfo.get("storeId").toString();
|
String storeId = ObjectUtil.isEmpty(userInfo.get("storeId"))? "" : userInfo.get("storeId").toString();
|
||||||
String staffId = ObjectUtil.isEmpty(userInfo.get("staffId"))? "" : userInfo.get("staffId").toString();
|
// String staffId = ObjectUtil.isEmpty(userInfo.get("staffId"))? "" : userInfo.get("staffId").toString();
|
||||||
String inviterId = ObjectUtil.isEmpty(userInfo.get("inviterId"))? "" : userInfo.get("inviterId").toString();
|
// String inviterId = ObjectUtil.isEmpty(userInfo.get("inviterId"))? "" : userInfo.get("inviterId").toString();
|
||||||
JSONObject loginInfo = weixinService.getWxProfile2(param.get("code").toString()); // 发起的登录请求 merchantId(用来获取商户的appid 目前用不到)
|
JSONObject loginInfo = weixinService.getWxProfile2(param.get("code").toString()); // 发起的登录请求 merchantId(用来获取商户的appid 目前用不到)
|
||||||
if (loginInfo == null) {
|
if (loginInfo == null) {
|
||||||
return getFailureResult(0, "微信登录失败");
|
return getFailureResult(0, "微信登录失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户信息
|
|
||||||
// String type = userInfo.getString("type");
|
|
||||||
// type.equals("phone") &&
|
|
||||||
// String encryptedData = userInfo.getString("encryptedData");
|
|
||||||
// userInfo.put("phone", "");
|
|
||||||
// userInfo.put("source", MemberSourceEnum.WECHAT_LOGIN.getKey());
|
|
||||||
// if (StringUtil.isNotEmpty(encryptedData)) {
|
|
||||||
// String phone = weixinService.getPhoneNumber(userInfo.get("encryptedData").toString(), loginInfo.get("session_key").toString(), userInfo.get("iv").toString());
|
|
||||||
// userInfo.put("phone", phone);
|
|
||||||
// }
|
|
||||||
// 默认店铺(主页) ()
|
|
||||||
// if (storeId == null || StringUtil.isEmpty(storeId)) {
|
|
||||||
// MtStore mtStore = storeService.getDefaultStore(merchantNo);
|
|
||||||
// if (mtStore != null) {
|
|
||||||
// storeId = mtStore.getId().toString();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
MtUser mtUser = memberService.queryMemberByOpenId2(loginInfo.get("openid").toString(), userInfo);
|
MtUser mtUser = memberService.queryMemberByOpenId2(loginInfo.get("openid").toString(), userInfo);
|
||||||
if (mtUser == null) {
|
if (mtUser == null) {
|
||||||
return getFailureResult(0, "用户状态异常");
|
return getFailureResult(0, "用户状态异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
String userAgent = request.getHeader("user-agent");
|
String userAgent = request.getHeader("user-agent");
|
||||||
// String token = TokenUtil.generateToken(userAgent, mtUser.getId());
|
|
||||||
// UserInfo userLoginInfo = new UserInfo();
|
|
||||||
// userLoginInfo.setId(mtUser.getId());
|
|
||||||
// userLoginInfo.setStoreId(storeId);
|
|
||||||
//
|
|
||||||
// userLoginInfo.setToken(token);
|
|
||||||
// TokenUtil.saveToken(userLoginInfo);
|
|
||||||
//
|
|
||||||
// Map<String, Object> result = new HashMap<>();
|
|
||||||
// result.put("token", token);
|
|
||||||
// result.put("userId", mtUser.getId());
|
|
||||||
// result.put("userName", mtUser.getName());
|
|
||||||
// result.put("openId", mtUser.getOpenId());
|
|
||||||
|
|
||||||
AccountInfo accountInfo = new AccountInfo();
|
AccountInfo accountInfo = new AccountInfo();
|
||||||
accountInfo.setId(mtUser.getId());
|
accountInfo.setId(mtUser.getId());
|
||||||
accountInfo.setDeptId(-1L);
|
accountInfo.setDeptId(-1L);
|
||||||
if (ObjectUtil.isNotEmpty(storeId) && storeId!= "") {
|
if (ObjectUtil.isNotEmpty(storeId) && storeId!= "") {
|
||||||
accountInfo.setStoreId(Integer.parseInt(storeId));
|
accountInfo.setStoreId(Integer.parseInt(storeId));
|
||||||
}
|
}
|
||||||
String token1 = TokenUtil.generateToken(userAgent, mtUser.getId());
|
String token = TokenUtil.generateToken(userAgent, mtUser.getId());
|
||||||
accountInfo.setToken(token1);
|
accountInfo.setToken(token);
|
||||||
TokenUtil.saveAccountToken(accountInfo);
|
TokenUtil.saveAccountToken(accountInfo);
|
||||||
LoginResponse response = new LoginResponse();
|
LoginResponse response = new LoginResponse();
|
||||||
response.setLogin(true);
|
response.setLogin(true);
|
||||||
response.setToken(token1);
|
response.setToken(token);
|
||||||
response.setTokenCreatedTime(new Date());
|
response.setTokenCreatedTime(new Date());
|
||||||
// return getSuccessResult(response);
|
|
||||||
|
|
||||||
|
|
||||||
return getSuccessResult("登录成功", response);
|
return getSuccessResult("登录成功", response);
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,4 @@
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</style>
|
</style>
|
@ -75,6 +75,7 @@
|
|||||||
userInfo: {
|
userInfo: {
|
||||||
storeId: 0,
|
storeId: 0,
|
||||||
staffId: "",
|
staffId: "",
|
||||||
|
phone:'17753808121'
|
||||||
},
|
},
|
||||||
|
|
||||||
type: 'phone',
|
type: 'phone',
|
||||||
|
8
gasStation-uni/store/getters.js
Normal file
8
gasStation-uni/store/getters.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const getters = {
|
||||||
|
token: state => state.user.token,
|
||||||
|
avatar: state => state.user.avatar,
|
||||||
|
name: state => state.user.name,
|
||||||
|
roles: state => state.user.roles,
|
||||||
|
permissions: state => state.user.permissions
|
||||||
|
}
|
||||||
|
export default getters
|
15
gasStation-uni/store/index.js
Normal file
15
gasStation-uni/store/index.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
import user from '@/store/modules/user'
|
||||||
|
import getters from './getters'
|
||||||
|
|
||||||
|
Vue.use(Vuex)
|
||||||
|
|
||||||
|
const store = new Vuex.Store({
|
||||||
|
modules: {
|
||||||
|
user
|
||||||
|
},
|
||||||
|
getters
|
||||||
|
})
|
||||||
|
|
||||||
|
export default store
|
98
gasStation-uni/store/modules/user.js
Normal file
98
gasStation-uni/store/modules/user.js
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import config from '@/config'
|
||||||
|
import storage from '@/utils/storage'
|
||||||
|
import constant from '@/utils/constant'
|
||||||
|
import { login, logout, getInfo } from '@/api/login'
|
||||||
|
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||||
|
|
||||||
|
const baseUrl = config.baseUrl
|
||||||
|
|
||||||
|
const user = {
|
||||||
|
state: {
|
||||||
|
token: getToken(),
|
||||||
|
name: storage.get(constant.name),
|
||||||
|
avatar: storage.get(constant.avatar),
|
||||||
|
roles: storage.get(constant.roles),
|
||||||
|
permissions: storage.get(constant.permissions)
|
||||||
|
},
|
||||||
|
|
||||||
|
mutations: {
|
||||||
|
SET_TOKEN: (state, token) => {
|
||||||
|
state.token = token
|
||||||
|
},
|
||||||
|
SET_NAME: (state, name) => {
|
||||||
|
state.name = name
|
||||||
|
storage.set(constant.name, name)
|
||||||
|
},
|
||||||
|
SET_AVATAR: (state, avatar) => {
|
||||||
|
state.avatar = avatar
|
||||||
|
storage.set(constant.avatar, avatar)
|
||||||
|
},
|
||||||
|
SET_ROLES: (state, roles) => {
|
||||||
|
state.roles = roles
|
||||||
|
storage.set(constant.roles, roles)
|
||||||
|
},
|
||||||
|
SET_PERMISSIONS: (state, permissions) => {
|
||||||
|
state.permissions = permissions
|
||||||
|
storage.set(constant.permissions, permissions)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
// 登录
|
||||||
|
Login({ commit }, userInfo) {
|
||||||
|
const username = userInfo.username.trim()
|
||||||
|
const password = userInfo.password
|
||||||
|
const code = userInfo.code
|
||||||
|
const uuid = userInfo.uuid
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
login(username, password, code, uuid).then(res => {
|
||||||
|
setToken(res.token)
|
||||||
|
commit('SET_TOKEN', res.token)
|
||||||
|
resolve()
|
||||||
|
}).catch(error => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
GetInfo({ commit, state }) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
getInfo().then(res => {
|
||||||
|
const user = res.user
|
||||||
|
const avatar = baseUrl + user.avatar
|
||||||
|
const username = (user == null || user.userName == "" || user.userName == null) ? "" : user.userName
|
||||||
|
if (res.roles && res.roles.length > 0) {
|
||||||
|
commit('SET_ROLES', res.roles)
|
||||||
|
commit('SET_PERMISSIONS', res.permissions)
|
||||||
|
} else {
|
||||||
|
commit('SET_ROLES', ['ROLE_DEFAULT'])
|
||||||
|
}
|
||||||
|
commit('SET_NAME', username)
|
||||||
|
commit('SET_AVATAR', avatar)
|
||||||
|
resolve(res)
|
||||||
|
}).catch(error => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 退出系统
|
||||||
|
LogOut({ commit, state }) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
logout(state.token).then(() => {
|
||||||
|
commit('SET_TOKEN', '')
|
||||||
|
commit('SET_ROLES', [])
|
||||||
|
commit('SET_PERMISSIONS', [])
|
||||||
|
removeToken()
|
||||||
|
storage.clean()
|
||||||
|
resolve()
|
||||||
|
}).catch(error => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default user
|
Loading…
Reference in New Issue
Block a user