feat: ✨ store 添加会员信息模块
This commit is contained in:
		
							parent
							
								
									ea92217020
								
							
						
					
					
						commit
						8b7c2fbf4f
					
				@ -1,3 +1,4 @@
 | 
			
		||||
import type { LoginResult } from '@/types/member'
 | 
			
		||||
import { defineStore } from 'pinia'
 | 
			
		||||
import { ref } from 'vue'
 | 
			
		||||
 | 
			
		||||
@ -5,7 +6,25 @@ import { ref } from 'vue'
 | 
			
		||||
export const useMemberStore = defineStore(
 | 
			
		||||
  'member',
 | 
			
		||||
  () => {
 | 
			
		||||
    return {}
 | 
			
		||||
    // 会员信息
 | 
			
		||||
    const profile = ref<LoginResult>()
 | 
			
		||||
 | 
			
		||||
    // 保存会员信息,登录时使用
 | 
			
		||||
    const setProfile = (val: LoginResult) => {
 | 
			
		||||
      profile.value = val
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 清理会员信息,退出时使用
 | 
			
		||||
    const clearProfile = () => {
 | 
			
		||||
      profile.value = undefined
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 记得 return
 | 
			
		||||
    return {
 | 
			
		||||
      profile,
 | 
			
		||||
      setProfile,
 | 
			
		||||
      clearProfile,
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    // 网页端配置
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										46
									
								
								src/types/member.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/types/member.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
/** 通用的用户信息 */
 | 
			
		||||
type BaseProfile = {
 | 
			
		||||
  /** 用户ID */
 | 
			
		||||
  id: number
 | 
			
		||||
  /** 头像  */
 | 
			
		||||
  avatar: string
 | 
			
		||||
  /** 账户名  */
 | 
			
		||||
  account: string
 | 
			
		||||
  /** 昵称 */
 | 
			
		||||
  nickname?: string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 小程序登录 登录用户信息 */
 | 
			
		||||
export type LoginResult = BaseProfile & {
 | 
			
		||||
  /** 手机号 */
 | 
			
		||||
  mobile: string
 | 
			
		||||
  /** 登录凭证 */
 | 
			
		||||
  token: string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 个人信息 用户详情信息 */
 | 
			
		||||
export type ProfileDetail = BaseProfile & {
 | 
			
		||||
  /** 性别 */
 | 
			
		||||
  gender?: Gender
 | 
			
		||||
  /** 生日 */
 | 
			
		||||
  birthday?: string
 | 
			
		||||
  /** 省市区 */
 | 
			
		||||
  fullLocation?: string
 | 
			
		||||
  /** 职业 */
 | 
			
		||||
  profession?: string
 | 
			
		||||
}
 | 
			
		||||
/** 性别 */
 | 
			
		||||
export type Gender = '女' | '男'
 | 
			
		||||
 | 
			
		||||
/** 个人信息 修改请求体参数 */
 | 
			
		||||
export type ProfileParams = Pick<
 | 
			
		||||
  ProfileDetail,
 | 
			
		||||
  'nickname' | 'gender' | 'birthday' | 'profession'
 | 
			
		||||
> & {
 | 
			
		||||
  /** 省份编码 */
 | 
			
		||||
  provinceCode?: string
 | 
			
		||||
  /** 城市编码 */
 | 
			
		||||
  cityCode?: string
 | 
			
		||||
  /** 区/县编码 */
 | 
			
		||||
  countyCode?: string
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user