| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /**
- * 用户状态管理
- */
- import {
- defineStore
- } from 'pinia'
- import {
- getCardInfo,
- getCardQrcode,
- getCompanyInfo
- } from '@/api/card.js'
- import {
- formatRichText
- } from '@/utils/index.js'
- import {
- generateCardPoster,
- } from '@/utils/poster.js'
- export const useUserStore = defineStore('user', {
- state: () => ({
- cardInfo: {
- "userId": "",
- "nickName": "",
- "phonenumber": "",
- "postName": "",
- "companyName": "",
- "companyAddress": "",
- "email": "",
- "sex": null,
- "avatar": ""
- },
- companyInfo: {
- "name": "",
- "email": "",
- "address": "",
- "introduce": ""
- },
- qrInfo: {
- },
- cardImage:"",
- }),
- 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)
- })
- },
- queryCardPoster() {
- return new Promise(async (resolve, reject) => {
- const cardImage = await generateCardPoster(this.cardInfo)
- this.cardImage = cardImage || ''
- resolve(cardImage)
- })
- },
- // 退出登录,重置状态
- logout() {
- this.$reset()
- }
- }
- })
|