app.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. this.merchantId = null;
  87. this.userInfo = null;
  88. Cache.clear(LOGIN_STATUS);
  89. Cache.clear(UID);
  90. Cache.clear(USER_INFO);
  91. Cache.clear(EXPIRES_TIME);
  92. },
  93. BACKGROUND_COLOR(color) {
  94. this.color = color;
  95. document.body.style.backgroundColor = color;
  96. },
  97. UPDATE_USERINFO(userInfo) {
  98. this.userInfo = userInfo;
  99. Cache.set(USER_INFO, userInfo);
  100. },
  101. OPEN_HOME() {
  102. this.homeActive = true;
  103. },
  104. CLOSE_HOME() {
  105. this.homeActive = false;
  106. },
  107. SET_CHATURL(chatUrl) {
  108. this.chatUrl = chatUrl;
  109. },
  110. SYSTEM_PLATFORM(systemPlatform) {
  111. this.systemPlatform = systemPlatform;
  112. Cache.set(PLATFORM, systemPlatform);
  113. },
  114. changInfo(payload) {
  115. this.userInfo[payload.amount1] = payload.amount2;
  116. Cache.set(USER_INFO, this.userInfo);
  117. },
  118. PRODUCT_TYPE(productType) {
  119. this.productType = productType;
  120. Cache.set("productType", productType);
  121. },
  122. async USERINFO(force) {
  123. try {
  124. const res = await getUserInfo();
  125. this.UPDATE_USERINFO(res.data);
  126. return res.data;
  127. } catch (e) {}
  128. },
  129. // 获取小程序基本配置
  130. async GET_WX_CONFIG() {
  131. try {
  132. const { data } = await getMiniProgramData();
  133. const configDate = {
  134. ...data,
  135. alipayList: data.alipayList ? JSON.parse(data.alipayList) : [],
  136. bankCardList: data.bankCardList ? JSON.parse(data.bankCardList) : [],
  137. };
  138. this.wxConfig = configDate;
  139. return configDate;
  140. } catch (e) {
  141. console.log("GET_WX_CONFIG-stores-res", e);
  142. throw e;
  143. }
  144. },
  145. UPDATE_userPanelInfo(userPanelInfo) {
  146. this.userPanelInfo = userPanelInfo;
  147. },
  148. UPDATE_MERCHANT_ID(merchantId) {
  149. this.merchantId = merchantId;
  150. },
  151. },
  152. });