app.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import { getUserInfo } from "@/api/user.js";
  11. import { diyProductApi } from "@/api/store.js"
  12. import {
  13. LOGIN_STATUS,
  14. NON_WIFI_AUTOPLAY,
  15. UID,
  16. USER_INFO,
  17. STORE_NUM
  18. } from '@/config/cache';
  19. import Cache from '@/utils/cache';
  20. const state = {
  21. token: Cache.get(LOGIN_STATUS) || false,
  22. backgroundColor: "#fff",
  23. userInfo: Cache.get(USER_INFO) || {},
  24. uid: Cache.get(UID) || 0,
  25. homeActive: false,
  26. phoneStatus: true,
  27. pageFooter: uni.getStorageSync('pageFoot') || {},
  28. autoplay: Cache.get(NON_WIFI_AUTOPLAY) || false,
  29. // 商品详情可视化数据
  30. diyProduct: {
  31. navList: [0, 1, 2, 3, 4], // 顶部菜单内容
  32. openShare: 1, //是否开启分享
  33. pictureConfig: 0, //轮播图模式 0 固定方图 1 高度自适应
  34. swiperDot: 1, //是否展示轮播指示点
  35. showPrice: [0, 1], //是否显示付费会员价和等级会员
  36. isOpen: [0, 1, 2], //是否展示 0 原价 1 累计销量 2 库存
  37. showSvip: 1, //是否展示付费会员卡片
  38. showRank: 1, // 是否展示 排行榜卡片
  39. showService: [0, 1, 2, 3], //服务区卡片 0 营销活动入口 1 sku选择 2 服务保障 3 参数
  40. showReply: 1, //是否展示评论区
  41. replyNum: 3, //评论数量
  42. showMatch: 1, //是否展示搭配购
  43. matchNum: 3, //搭配套餐数量
  44. showRecommend: 1, //是否展示推荐商品
  45. recommendNum: 12, //推荐商品数量
  46. menuList: [0, 1, 2], //底部左侧菜单
  47. showCart: 1 //是否显示购物车
  48. },
  49. // 商品分类可视化数据
  50. diyCategory: {
  51. level: 2,
  52. index: 0
  53. },
  54. productVideoStatus: true,
  55. nearbyStore: 0,
  56. storeNum: Cache.get(STORE_NUM) || 0 ,//1是平台,0是门店
  57. };
  58. const mutations = {
  59. SETPHONESTATUS(state, val) {
  60. state.phoneStatus = val;
  61. },
  62. LOGIN(state, opt) {
  63. state.token = opt.token;
  64. Cache.set(LOGIN_STATUS, opt.token, opt.time);
  65. },
  66. SETUID(state, val) {
  67. state.uid = val;
  68. Cache.set(UID, val);
  69. },
  70. UPDATE_LOGIN(state, token) {
  71. state.token = token;
  72. },
  73. LOGOUT(state) {
  74. Cache.clear(LOGIN_STATUS);
  75. Cache.clear(UID);
  76. Cache.clear(USER_INFO);
  77. Cache.clear('newcomerGift');
  78. state.token = undefined;
  79. state.uid = undefined
  80. state.userInfo = {}
  81. },
  82. BACKGROUND_COLOR(state, color) {
  83. state.color = color;
  84. document.body.style.backgroundColor = color;
  85. },
  86. UPDATE_USERINFO(state, userInfo) {
  87. state.userInfo = userInfo;
  88. Cache.set(USER_INFO, userInfo);
  89. },
  90. OPEN_HOME(state) {
  91. state.homeActive = true;
  92. },
  93. CLOSE_HOME(state) {
  94. state.homeActive = false;
  95. },
  96. FOOT_UPLOAD(state, data) {
  97. state.pageFooter = data
  98. },
  99. SET_AUTOPLAY(state, data) {
  100. state.autoplay = data
  101. Cache.set(NON_WIFI_AUTOPLAY, data)
  102. },
  103. SET_PRODUCT_DIY(state, data){
  104. state.diyProduct = data.product_detail;
  105. state.diyCategory = data.product_category;
  106. state.productVideoStatus = data.product_video_status;
  107. },
  108. SET_NEARBY(state,data){
  109. state.nearbyStore = data
  110. },
  111. SET_STORE(state,data){
  112. Cache.set(STORE_NUM, data);
  113. state.storeNum = data
  114. }
  115. };
  116. const actions = {
  117. USERINFO({
  118. state,
  119. commit
  120. }, force) {
  121. if (state.userInfo !== null && !force)
  122. return Promise.resolve(state.userInfo);
  123. else
  124. return new Promise(reslove => {
  125. getUserInfo().then(res => {
  126. commit("UPDATE_USERINFO", res.data);
  127. Cache.set(USER_INFO, res.data);
  128. reslove(res.data);
  129. });
  130. }).catch(() => {
  131. });
  132. },
  133. // div商品详情
  134. async getDiyProduct({commit}) {
  135. let result = await diyProductApi();
  136. if(result.status == 200){
  137. commit("SET_PRODUCT_DIY",result.data);
  138. }
  139. },
  140. };
  141. export default {
  142. state,
  143. mutations,
  144. actions
  145. };