app.js 4.6 KB

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