首次完整推送,

V:1.20240808.006
This commit is contained in:
fm453
2024-08-13 18:32:37 +08:00
parent 15be3e9373
commit c62d15b288
939 changed files with 111777 additions and 0 deletions

61
store/modules/user.js Normal file
View File

@ -0,0 +1,61 @@
// 上次启动时的用户信息
let userInfoHistory = uni.getStorageSync('userinfo') || {};
let state = {
//是否已经登录
hasLogin: Boolean(Object.keys(userInfoHistory).length), //Object.keys().length 判断对象长度,用以检测对象是否为空
//用户信息
info: userInfoHistory
},
getters = {
info(state) {
return state.info;
},
hasLogin(state) {
return state.hasLogin;
}
},
mutations = {
login(state, info) { //登录成功后的操作
//原有的结合传来的参数
let _info = state.info;
state.info = Object.assign({}, _info, info);
//设置为已经登录
state.hasLogin = true;
// console.log('state.info', state.info);
//存储最新的用户数据到本地持久化存储
uni.setStorageSync('userinfo', state.info);
if (info.token) {
uni.setStorage({
key: 'uni_id_token',
data: state.info.token,
complete(e) {
// console.log('setStorage-------',e);
}
});
uni.setStorageSync('uni_id_token_expired', state.info.tokenExpired)
}
},
logout(state) {
state.info = {};
state.hasLogin = false;
uni.setStorageSync('userinfo', {});
uni.removeStorageSync('uni_id_token');
uni.setStorageSync('uni_id_token_expired', 0)
}
},
actions = {
logout(context) {
uni.showLoading({
mask: true
})
}
}
export default {
namespaced: true,
state,
getters,
mutations,
//同步执行触发用store.commit
actions
//异步执行触发用store.dispatch
}

View File

@ -0,0 +1,61 @@
//通过云端一体模板来登陆的,返回用户id、手机号等信息。
import {
store
} from '@/uni_modules/uni-id-pages/common/store.js'
// 用户信息、是否登陆
let userInfoCloud = store.userInfo || {},
isLogin = Boolean(Object.keys(userInfoCloud).length);
// {
// "_id": "668ca11209664cbba01ed3c7",
// "mobile": "18608981880",
// "realNameAuth": {
// "errCode": 0,
// "realName": "",
// "identity": ""
// }
// }
// let user = uniCloud.getCurrentUserInfo();
// {
// "uid": "668ca11209664cbba01ed3c7",
// "role": [],
// "permission": [],
// "uniIdVersion": "1.0.17",
// "tokenExpired": 1720499506000
// }
let state = {
//是否已经登录
hasLogin: isLogin,
//用户信息
info: userInfoCloud,
openid: userInfoCloud._id || '',
mobile: userInfoCloud.mobile || '',
},
getters = {
info(state) {
return state.info;
},
hasLogin(state) {
return state.hasLogin;
},
openid(state) {
return state.openid;
},
mobile(state) {
return state.mobile;
}
},
mutations = {
logout(state) {
state.info = {};
state.hasLogin = false;
uni.setStorageSync('uni-id-pages-userInfo', {});
}
}
export default {
namespaced: true,
state,
getters,
mutations
}