app.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { defineStore } from "pinia";
  2. import { getUserInfo } from "@/api/user.js";
  3. import { LOGIN_STATUS, UID, PLATFORM, EXPIRES_TIME } from "@/config/cache.js";
  4. import Cache from "@/utils/cache.js";
  5. import { USER_INFO } from "@/config/cache.js";
  6. import { getMiniProgramData } from "@/api/api";
  7. export const useAppStore = defineStore("app", {
  8. state: () => {
  9. return {
  10. token: Cache.get(LOGIN_STATUS) || "",
  11. backgroundColor: "#fff",
  12. userInfo: Cache.get(USER_INFO) ? JSON.parse(Cache.get(USER_INFO)) : null,
  13. uid: Cache.get(UID) || null,
  14. homeActive: false,
  15. chatUrl: Cache.get("chatUrl") || "",
  16. systemPlatform: Cache.get(PLATFORM) ? Cache.get(PLATFORM) : "",
  17. productType: Cache.get("productType") || "",
  18. navbarHeight: 0,
  19. userPanelInfo: {},
  20. refreshArticles: false,
  21. indexRefreshArticles: false,
  22. wxConfig: {
  23. auditModeEnabled: false,
  24. carouselImages: [
  25. {
  26. id: 0,
  27. imageUrl: "",
  28. jumpUrl: "",
  29. sort: 0,
  30. },
  31. ],
  32. homePopupImage: "",
  33. inviteImage: "",
  34. isOpen: true,
  35. logoImage: "",
  36. mailingAddress: "",
  37. signCoinValue: 0,
  38. signGrowthValue: 0,
  39. },
  40. // 店铺信息
  41. shopInfo:{
  42. name:"水贝001号店铺",
  43. shopId:"001"
  44. }
  45. };
  46. },
  47. getters: {
  48. uidComputed: (state) => state.uid,
  49. tokenComputed: (state) => state.token,
  50. isLogin: (state) => !!state.token,
  51. homeActiveComputed: (state) => state.homeActive,
  52. productTypeComputed: (state) => state.productType,
  53. chatUrlComputed: (state) => state.chatUrl,
  54. $userInfo: (state) => state.userInfo,
  55. navbarHeightGetter: (state) => state.navbarHeight,
  56. userPanelInfoGetter: (state) => state.userPanelInfo,
  57. $wxConfig: (state) => state.wxConfig,
  58. shopInfoGetter: (state) => state.shopInfo,
  59. },
  60. actions: {
  61. SET_REFRESH(val) {
  62. this.refreshArticles = val;
  63. },
  64. setIndexRefersh(val) {
  65. this.indexRefreshArticles = val;
  66. },
  67. SET_NAVBAR_HEIGHT(val) {
  68. this.navbarHeight = val;
  69. },
  70. LOGIN(opt) {
  71. this.token = opt.token;
  72. Cache.set(LOGIN_STATUS, opt.token);
  73. },
  74. SETUID(val) {
  75. this.uid = val;
  76. Cache.set(UID, val);
  77. },
  78. UPDATE_LOGIN(token) {
  79. this.token = token;
  80. },
  81. LOGOUT() {
  82. this.token = undefined;
  83. this.uid = undefined;
  84. Cache.clear(LOGIN_STATUS);
  85. Cache.clear(UID);
  86. Cache.clear(USER_INFO);
  87. Cache.clear(EXPIRES_TIME);
  88. },
  89. BACKGROUND_COLOR(color) {
  90. this.color = color;
  91. document.body.style.backgroundColor = color;
  92. },
  93. UPDATE_USERINFO(userInfo) {
  94. this.userInfo = userInfo;
  95. Cache.set(USER_INFO, userInfo);
  96. },
  97. OPEN_HOME() {
  98. this.homeActive = true;
  99. },
  100. CLOSE_HOME() {
  101. this.homeActive = false;
  102. },
  103. SET_CHATURL(chatUrl) {
  104. this.chatUrl = chatUrl;
  105. },
  106. SYSTEM_PLATFORM(systemPlatform) {
  107. this.systemPlatform = systemPlatform;
  108. Cache.set(PLATFORM, systemPlatform);
  109. },
  110. changInfo(payload) {
  111. this.userInfo[payload.amount1] = payload.amount2;
  112. Cache.set(USER_INFO, this.userInfo);
  113. },
  114. PRODUCT_TYPE(productType) {
  115. this.productType = productType;
  116. Cache.set("productType", productType);
  117. },
  118. async USERINFO(force) {
  119. try {
  120. const res = await getUserInfo();
  121. this.UPDATE_USERINFO(res.data);
  122. return res.data;
  123. } catch (e) {}
  124. },
  125. // 获取小程序基本配置
  126. async GET_WX_CONFIG() {
  127. try {
  128. const res = await getMiniProgramData();
  129. this.wxConfig = { ...res.data };
  130. } catch (e) {
  131. console.log("GET_WX_CONFIG-stores-res", e);
  132. throw e;
  133. }
  134. },
  135. UPDATE_userPanelInfo(userPanelInfo) {
  136. this.userPanelInfo = userPanelInfo;
  137. },
  138. },
  139. });