app.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. storeAuditModeEnabled: false, // 使用此字段控制审核时隐藏与显示
  25. carouselImages: [
  26. {
  27. id: 0,
  28. imageUrl: "",
  29. jumpUrl: "",
  30. sort: 0,
  31. },
  32. ],
  33. homePopupImage: "",
  34. inviteImage: "",
  35. isOpen: true,
  36. logoImage: "",
  37. mailingAddress: "",
  38. signCoinValue: 0,
  39. signGrowthValue: 0,
  40. },
  41. // 店铺信息
  42. shopInfo: {
  43. name: "水贝001号店铺",
  44. shopId: "001",
  45. },
  46. merchantId: null,
  47. // 首页展示刷新标识,当浏览了新店铺主页/扫店铺码时,改为true,首页onshow时判断true刷新列表并改为false
  48. indexRefreshFlag: false,
  49. cartRefreshFlag: false,
  50. cProductAttr: [],
  51. cProductAttrValue: [],
  52. };
  53. },
  54. getters: {
  55. uidComputed: (state) => state.uid,
  56. tokenComputed: (state) => state.token,
  57. isLogin: (state) => !!state.token,
  58. homeActiveComputed: (state) => state.homeActive,
  59. productTypeComputed: (state) => state.productType,
  60. chatUrlComputed: (state) => state.chatUrl,
  61. $userInfo: (state) => state.userInfo,
  62. navbarHeightGetter: (state) => state.navbarHeight,
  63. userPanelInfoGetter: (state) => state.userPanelInfo,
  64. $wxConfig: (state) => state.wxConfig,
  65. shopInfoGetter: (state) => state.shopInfo,
  66. merchantIdGetter: (state) => state.merchantId,
  67. },
  68. actions: {
  69. SET_REFRESH(val) {
  70. this.refreshArticles = val;
  71. },
  72. SET_CPATTR(val) {
  73. this.cProductAttr = val;
  74. },
  75. SET_CPATTRVALUE(val) {
  76. this.cProductAttrValue = val;
  77. },
  78. SET_CART_REFRESH(val) {
  79. this.cartRefreshFlag = val;
  80. },
  81. setIndexRefersh(val) {
  82. this.indexRefreshFlag = val;
  83. },
  84. SET_NAVBAR_HEIGHT(val) {
  85. this.navbarHeight = val;
  86. },
  87. LOGIN(opt) {
  88. this.token = opt.token;
  89. Cache.set(LOGIN_STATUS, opt.token);
  90. },
  91. SETUID(val) {
  92. this.uid = val;
  93. Cache.set(UID, val);
  94. },
  95. UPDATE_LOGIN(token) {
  96. this.token = token;
  97. },
  98. LOGOUT() {
  99. this.token = undefined;
  100. this.uid = undefined;
  101. this.merchantId = null;
  102. this.userInfo = null;
  103. Cache.clear(LOGIN_STATUS);
  104. Cache.clear(UID);
  105. Cache.clear(USER_INFO);
  106. Cache.clear(EXPIRES_TIME);
  107. },
  108. BACKGROUND_COLOR(color) {
  109. this.color = color;
  110. document.body.style.backgroundColor = color;
  111. },
  112. UPDATE_USERINFO(userInfo) {
  113. this.userInfo = userInfo;
  114. Cache.set(USER_INFO, userInfo);
  115. },
  116. OPEN_HOME() {
  117. this.homeActive = true;
  118. },
  119. CLOSE_HOME() {
  120. this.homeActive = false;
  121. },
  122. SET_CHATURL(chatUrl) {
  123. this.chatUrl = chatUrl;
  124. },
  125. SYSTEM_PLATFORM(systemPlatform) {
  126. this.systemPlatform = systemPlatform;
  127. Cache.set(PLATFORM, systemPlatform);
  128. },
  129. changInfo(payload) {
  130. this.userInfo[payload.amount1] = payload.amount2;
  131. Cache.set(USER_INFO, this.userInfo);
  132. },
  133. PRODUCT_TYPE(productType) {
  134. this.productType = productType;
  135. Cache.set("productType", productType);
  136. },
  137. async USERINFO(force) {
  138. try {
  139. const res = await getUserInfo();
  140. this.UPDATE_USERINFO(res.data);
  141. return res.data;
  142. } catch (e) {}
  143. },
  144. // 获取小程序基本配置
  145. async GET_WX_CONFIG() {
  146. try {
  147. const { data } = await getMiniProgramData();
  148. const configDate = {
  149. ...data,
  150. alipayList: data.alipayList ? JSON.parse(data.alipayList) : [],
  151. bankCardList: data.bankCardList ? JSON.parse(data.bankCardList) : [],
  152. };
  153. this.wxConfig = configDate;
  154. return configDate;
  155. } catch (e) {
  156. console.log("GET_WX_CONFIG-stores-res", e);
  157. throw e;
  158. }
  159. },
  160. UPDATE_userPanelInfo(userPanelInfo) {
  161. this.userPanelInfo = userPanelInfo;
  162. },
  163. UPDATE_MERCHANT_ID(merchantId) {
  164. this.merchantId = merchantId;
  165. },
  166. },
  167. });