登录逻辑+注册有礼
This commit is contained in:
@@ -5,12 +5,12 @@ import { createPinia } from 'pinia';
|
||||
import useAppStore from './modules/app';
|
||||
import useUserStore from './modules/user';
|
||||
|
||||
// import piniaPersist from 'pinia-plugin-persist-uni';
|
||||
import piniaPersist from 'pinia-plugin-persistedstate';
|
||||
|
||||
// 安装pinia状态管理插件
|
||||
function setupStore(app: App) {
|
||||
const store = createPinia();
|
||||
// store.use(piniaPersist);
|
||||
store.use(piniaPersist);
|
||||
|
||||
app.use(store);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,33 @@ import {
|
||||
login as userLogin,
|
||||
logout as userLogout, login
|
||||
} from '@/api/user/index';
|
||||
import { clearToken, setToken } from '@/utils/auth';
|
||||
import { clearToken, setCompanyId, setToken } from '@/utils/auth';
|
||||
import type { LoginParams } from '@/api/user/types';
|
||||
|
||||
const useUserStore = defineStore('user', {
|
||||
state: (): UserState => ({
|
||||
user_id: '',
|
||||
user_name: '江阳小道',
|
||||
avatar: '',
|
||||
token: ''
|
||||
state: (): UserState => <UserState>({
|
||||
id: '',
|
||||
unionId: '',
|
||||
name: '未登录',
|
||||
nickName: '未登录',
|
||||
image: '',
|
||||
telephone: '',
|
||||
balance: 0,
|
||||
integration: 0,
|
||||
birthday: ''
|
||||
}),
|
||||
|
||||
persist: true,
|
||||
|
||||
// persist: {
|
||||
// // 修改存储中使用的键名称,默认为当前 Store的 id
|
||||
// key: 'userState',
|
||||
// // 修改为 sessionStorage,默认为 localStorage
|
||||
// // storage: window.localStorage,
|
||||
// // 部分持久化状态的点符号路径数组,[]意味着没有状态被持久化(默认为undefined,持久化整个状态)
|
||||
// paths: undefined
|
||||
// },
|
||||
|
||||
getters: {
|
||||
userInfo(state: UserState): UserState {
|
||||
return { ...state };
|
||||
@@ -22,7 +39,7 @@ const useUserStore = defineStore('user', {
|
||||
},
|
||||
actions: {
|
||||
// 设置用户的信息
|
||||
setInfo(partial: Partial<UserState>) {
|
||||
setUserInfo(partial: Partial<UserState>) {
|
||||
this.$patch(partial);
|
||||
},
|
||||
// 重置用户信息
|
||||
@@ -32,7 +49,7 @@ const useUserStore = defineStore('user', {
|
||||
// 获取用户信息
|
||||
async info() {
|
||||
const result = await getUserProfile();
|
||||
this.setInfo(result);
|
||||
this.setUserInfo(result);
|
||||
},
|
||||
// 异步登录并存储token
|
||||
login(loginForm: LoginParams) {
|
||||
@@ -63,7 +80,6 @@ const useUserStore = defineStore('user', {
|
||||
success: async (result: UniApp.LoginRes) => {
|
||||
if(result.code) {
|
||||
const wechatUserInfo = await uni.getUserInfo();
|
||||
console.log(wechatUserInfo);
|
||||
const userInfo = {
|
||||
...wechatUserInfo.userInfo,
|
||||
encryptedData: wechatUserInfo?.encryptedData,
|
||||
@@ -77,6 +93,10 @@ const useUserStore = defineStore('user', {
|
||||
userInfo: userInfo,
|
||||
referrerUserId: '1727303781559697409'
|
||||
});
|
||||
|
||||
this.setUserInfo(res.user);
|
||||
setToken(res.token);
|
||||
setCompanyId(res.user.companyId);
|
||||
resolve(res);
|
||||
} else {
|
||||
reject(new Error(result.errMsg));
|
||||
|
||||
@@ -1,9 +1,55 @@
|
||||
export type RoleType = '' | '*' | 'user';
|
||||
|
||||
export interface UserState {
|
||||
user_id?: string;
|
||||
user_name?: string;
|
||||
avatar?: string;
|
||||
token?: string;
|
||||
address: string;
|
||||
balance: number;
|
||||
birthday: string;
|
||||
birthdayMD: string;
|
||||
birthdayType: number;
|
||||
card: string;
|
||||
companyId: string;
|
||||
consumption: string;
|
||||
consumptionDay: string;
|
||||
couponsCount: number;
|
||||
createTime: string;
|
||||
creatorId: string;
|
||||
creatorName: string;
|
||||
customerPrice: string;
|
||||
email: string;
|
||||
gender: number;
|
||||
gold: string;
|
||||
goodsNum: number;
|
||||
id: string;
|
||||
image: string;
|
||||
integration: number;
|
||||
lastConsumTime: string;
|
||||
levelEntity: string;
|
||||
levelId: string;
|
||||
levelName: string;
|
||||
maOpenId: string;
|
||||
memberLabel: string;
|
||||
name: string;
|
||||
nickName: string;
|
||||
openId: string;
|
||||
orderNum: number;
|
||||
ownerId: string;
|
||||
ownerName: string;
|
||||
registerDay: number;
|
||||
relatedRate: number;
|
||||
remark: string;
|
||||
salePrice: number;
|
||||
source: string;
|
||||
status: string;
|
||||
storeId: string;
|
||||
telephone: string;
|
||||
totalConsumption: string;
|
||||
totalIncoming: number;
|
||||
totalIntegral: number;
|
||||
unionId: string;
|
||||
updateTime: string;
|
||||
useCouponsPrice: number;
|
||||
wirelinedTelephone: string;
|
||||
}
|
||||
|
||||
export type providerType =
|
||||
|
||||
Reference in New Issue
Block a user