app.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. merchantId:null,
  46. };
  47. },
  48. getters: {
  49. uidComputed: (state) => state.uid,
  50. tokenComputed: (state) => state.token,
  51. isLogin: (state) => !!state.token,
  52. homeActiveComputed: (state) => state.homeActive,
  53. productTypeComputed: (state) => state.productType,
  54. chatUrlComputed: (state) => state.chatUrl,
  55. $userInfo: (state) => state.userInfo,
  56. navbarHeightGetter: (state) => state.navbarHeight,
  57. userPanelInfoGetter: (state) => state.userPanelInfo,
  58. $wxConfig: (state) => state.wxConfig,
  59. shopInfoGetter: (state) => state.shopInfo,
  60. merchantIdGetter: (state) => state.merchantId,
  61. },
  62. actions: {
  63. SET_REFRESH(val) {
  64. this.refreshArticles = val;
  65. },
  66. setIndexRefersh(val) {
  67. this.indexRefreshArticles = val;
  68. },
  69. SET_NAVBAR_HEIGHT(val) {
  70. this.navbarHeight = val;
  71. },
  72. LOGIN(opt) {
  73. this.token = opt.token;
  74. Cache.set(LOGIN_STATUS, opt.token);
  75. },
  76. SETUID(val) {
  77. this.uid = val;
  78. Cache.set(UID, val);
  79. },
  80. UPDATE_LOGIN(token) {
  81. this.token = token;
  82. },
  83. LOGOUT() {
  84. this.token = undefined;
  85. this.uid = undefined;
  86. Cache.clear(LOGIN_STATUS);
  87. Cache.clear(UID);
  88. Cache.clear(USER_INFO);
  89. Cache.clear(EXPIRES_TIME);
  90. },
  91. BACKGROUND_COLOR(color) {
  92. this.color = color;
  93. document.body.style.backgroundColor = color;
  94. },
  95. UPDATE_USERINFO(userInfo) {
  96. this.userInfo = userInfo;
  97. Cache.set(USER_INFO, userInfo);
  98. },
  99. OPEN_HOME() {
  100. this.homeActive = true;
  101. },
  102. CLOSE_HOME() {
  103. this.homeActive = false;
  104. },
  105. SET_CHATURL(chatUrl) {
  106. this.chatUrl = chatUrl;
  107. },
  108. SYSTEM_PLATFORM(systemPlatform) {
  109. this.systemPlatform = systemPlatform;
  110. Cache.set(PLATFORM, systemPlatform);
  111. },
  112. changInfo(payload) {
  113. this.userInfo[payload.amount1] = payload.amount2;
  114. Cache.set(USER_INFO, this.userInfo);
  115. },
  116. PRODUCT_TYPE(productType) {
  117. this.productType = productType;
  118. Cache.set("productType", productType);
  119. },
  120. async USERINFO(force) {
  121. try {
  122. const res = await getUserInfo();
  123. this.UPDATE_USERINFO(res.data);
  124. return res.data;
  125. } catch (e) {}
  126. },
  127. // 获取小程序基本配置
  128. async GET_WX_CONFIG() {
  129. try {
  130. const res = await getMiniProgramData();
  131. this.wxConfig = { ...res.data };
  132. } catch (e) {
  133. console.log("GET_WX_CONFIG-stores-res", e);
  134. throw e;
  135. }
  136. },
  137. UPDATE_userPanelInfo(userPanelInfo) {
  138. this.userPanelInfo = userPanelInfo;
  139. },
  140. UPDATE_MERCHANT_ID(merchantId) {
  141. this.merchantId = merchantId;
  142. },
  143. },
  144. });