user.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * 用户状态管理
  3. */
  4. import {
  5. defineStore
  6. } from 'pinia'
  7. import {
  8. getCardInfo,
  9. getCardQrcode,
  10. getCompanyInfo
  11. } from '@/api/card.js'
  12. import {
  13. formatRichText
  14. } from '@/utils/index.js'
  15. import {
  16. generateCardPoster,
  17. } from '@/utils/poster.js'
  18. export const useUserStore = defineStore('user', {
  19. state: () => ({
  20. cardInfo: {
  21. "userId": "",
  22. "nickName": "",
  23. "phonenumber": "",
  24. "postName": "",
  25. "companyName": "",
  26. "companyAddress": "",
  27. "email": "",
  28. "sex": null,
  29. "avatar": ""
  30. },
  31. companyInfo: {
  32. "name": "",
  33. "email": "",
  34. "address": "",
  35. "introduce": ""
  36. },
  37. qrInfo: {
  38. },
  39. cardImage:"",
  40. }),
  41. actions: {
  42. // 获取用户卡片信息
  43. queryCardInfo(userId = null) {
  44. return new Promise(async (resolve, reject) => {
  45. let parmas = userId ? {
  46. userId
  47. } : {}
  48. let res = await getCardInfo(parmas)
  49. console.log(res, "resresresresresres");
  50. this.cardInfo = res.data
  51. resolve(res.data)
  52. })
  53. },
  54. queryCompanyInfo(userId = null) {
  55. return new Promise(async (resolve, reject) => {
  56. let parmas = userId ? {
  57. userId
  58. } : {}
  59. let res = await getCompanyInfo(parmas)
  60. this.companyInfo = res.data
  61. this.companyInfo.introduce = formatRichText(res.data.introduce)
  62. resolve(this.companyInfo)
  63. })
  64. },
  65. queryCardQrcode(userId = null) {
  66. return new Promise(async (resolve, reject) => {
  67. let parmas = userId ? {
  68. userId
  69. } : {
  70. userId: this.cardInfo.userId
  71. }
  72. let res = await getCardQrcode(parmas)
  73. this.qrInfo = res.data || {}
  74. resolve(res.data)
  75. })
  76. },
  77. queryCardPoster() {
  78. return new Promise(async (resolve, reject) => {
  79. const cardImage = await generateCardPoster(this.cardInfo)
  80. this.cardImage = cardImage || ''
  81. resolve(cardImage)
  82. })
  83. },
  84. // 退出登录,重置状态
  85. logout() {
  86. this.$reset()
  87. }
  88. }
  89. })