user.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. export const useUserStore = defineStore('user', {
  16. state: () => ({
  17. cardInfo: {
  18. "userId": "",
  19. "nickName": "",
  20. "phonenumber": "",
  21. "postName": "",
  22. "companyName": "",
  23. "companyAddress": "",
  24. "email": "",
  25. "sex": null,
  26. "avatar": ""
  27. },
  28. companyInfo: {
  29. "name": "",
  30. "email": "",
  31. "address": "",
  32. "introduce": ""
  33. },
  34. qrInfo: {
  35. }
  36. }),
  37. actions: {
  38. // 获取用户卡片信息
  39. queryCardInfo(userId = null) {
  40. return new Promise(async (resolve, reject) => {
  41. let parmas = userId ? {
  42. userId
  43. } : {}
  44. let res = await getCardInfo(parmas)
  45. console.log(res, "resresresresresres");
  46. this.cardInfo = res.data
  47. resolve(res.data)
  48. })
  49. },
  50. queryCompanyInfo(userId = null) {
  51. return new Promise(async (resolve, reject) => {
  52. let parmas = userId ? {
  53. userId
  54. } : {}
  55. let res = await getCompanyInfo(parmas)
  56. this.companyInfo = res.data
  57. this.companyInfo.introduce = formatRichText(res.data.introduce)
  58. resolve(this.companyInfo)
  59. })
  60. },
  61. queryCardQrcode(userId = null) {
  62. return new Promise(async (resolve, reject) => {
  63. let parmas = userId ? {
  64. userId
  65. } : {
  66. userId: this.cardInfo.userId
  67. }
  68. let res = await getCardQrcode(parmas)
  69. this.qrInfo = res.data ||{}
  70. resolve(res.data)
  71. })
  72. },
  73. // 退出登录,重置状态
  74. logout() {
  75. this.$reset()
  76. }
  77. }
  78. })