app.js 4.5 KB

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