app.js 4.4 KB

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