/** * 用户状态管理 */ import { defineStore } from 'pinia' import { getCardInfo, getCardQrcode, getCompanyInfo } from '@/api/card.js' import { formatRichText } from '@/utils/index.js' export const useUserStore = defineStore('user', { state: () => ({ cardInfo: { "userId": "", "nickName": "", "phonenumber": "", "postName": "", "companyName": "", "companyAddress": "", "email": "", "sex": null, "avatar": "" }, companyInfo: { "name": "", "email": "", "address": "", "introduce": "" }, qrInfo: { } }), actions: { // 获取用户卡片信息 queryCardInfo(userId = null) { return new Promise(async (resolve, reject) => { let parmas = userId ? { userId } : {} let res = await getCardInfo(parmas) console.log(res, "resresresresresres"); this.cardInfo = res.data resolve(res.data) }) }, queryCompanyInfo(userId = null) { return new Promise(async (resolve, reject) => { let parmas = userId ? { userId } : {} let res = await getCompanyInfo(parmas) this.companyInfo = res.data this.companyInfo.introduce = formatRichText(res.data.introduce) resolve(this.companyInfo) }) }, queryCardQrcode(userId = null) { return new Promise(async (resolve, reject) => { let parmas = userId ? { userId } : { userId: this.cardInfo.userId } let res = await getCardQrcode(parmas) this.qrInfo = res.data ||{} resolve(res.data) }) }, // 退出登录,重置状态 logout() { this.$reset() } } })