app.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import Auth from '../../libs/wechat';
  11. import {
  12. getPayConfigApi
  13. } from '../../api/order.js';
  14. import {
  15. getUserInfoApi,
  16. getLogout
  17. } from "../../api/user.js";
  18. import {
  19. getMerTypeListApi,
  20. getMerCategoryListApi
  21. } from '@/api/merchant.js';
  22. import {
  23. getTheme,
  24. tokenIsExistApi
  25. } from '../../api/api.js';
  26. import {
  27. LOGIN_STATUS,
  28. UID,
  29. PLATFORM,
  30. GLOBAL_DATA,
  31. SELECT_MERID,
  32. MERCHANT_EMPLOYEE_LIST,
  33. SELECT_MERCHANT,
  34. MANAGER_STATUS,
  35. IS_EMPLOYEE
  36. } from '../../config/cache';
  37. import Cache from '../../utils/cache';
  38. import {
  39. USER_INFO
  40. } from '../../config/cache';
  41. import util from '../../utils/util';
  42. import {
  43. globalConfigApi, loginConfigApi
  44. } from "../../api/public";
  45. import store from "../index";
  46. import Routine from "../../libs/routine";
  47. let cartArr = [{
  48. name: "微信支付",
  49. icon: "icon-weixinzhifu1",
  50. value: 'weixin',
  51. title: '微信快捷支付',
  52. payStatus: 1,
  53. },
  54. {
  55. name: "余额支付",
  56. icon: "icon-yuezhifu",
  57. value: 'yue',
  58. title: '可用余额:',
  59. payStatus: 1,
  60. userBalance: ''
  61. },
  62. // #ifndef MP
  63. {
  64. name: "支付宝支付",
  65. icon: "icon-zhifubao",
  66. value: 'alipay',
  67. title: '支付宝快捷支付',
  68. payStatus: 1,
  69. }
  70. // #endif
  71. ];
  72. const state = {
  73. token: Cache.get(LOGIN_STATUS) || false,
  74. managerToken: Cache.get(MANAGER_STATUS) || false,
  75. backgroundColor: "#fff",
  76. userInfo: Cache.get(USER_INFO) ? JSON.parse(Cache.get(USER_INFO)) : null,
  77. uid: Cache.get(UID) || '',
  78. homeActive: false,
  79. chatUrl: Cache.get('chatUrl') || '',
  80. systemPlatform: Cache.get(PLATFORM) ? Cache.get(PLATFORM) : '',
  81. productType: Cache.get('productType') || '',
  82. globalData: Cache.get(GLOBAL_DATA) || {},
  83. merchantClassify: Cache.get('merchantClassify') ? JSON.parse(Cache.get('merchantClassify')) : [],
  84. /** 商户分类 **/
  85. merchantType: Cache.get('merchantType') ? JSON.parse(Cache.get('merchantType')) : [],
  86. /** 商户类型 **/
  87. merchantAPPInfo: Cache.get('merchantAPPInfo') ? JSON.parse(Cache.get('merchantAPPInfo')) : {},
  88. merSttledData: Cache.get('merSttledData') ? JSON.parse(Cache.get('merSttledData')) : {},
  89. bottomNavigationIsCustom: false, //是否使用自定义导航
  90. merTokenIsExist: Cache.get('merTokenIsExist') || false,
  91. discoverTopic: [],
  92. merchantEmployeeList: Cache.get('merchantEmployeeList') ? JSON.parse(Cache.get('merchantEmployeeList')) : [],
  93. isEmployee: Cache.get(IS_EMPLOYEE) ? JSON.parse(Cache.get(IS_EMPLOYEE)) : null,
  94. selectMerId: Cache.get('selectMerId') ? JSON.parse(Cache.get('selectMerId')) : null,
  95. selectMerchantRole: Cache.get('selectMerchantRole') || null
  96. };
  97. const mutations = {
  98. LOGIN(state, opt) {
  99. state.token = opt.token;
  100. Cache.set(LOGIN_STATUS, opt.token);
  101. },
  102. SET_MANAGER_TOKEN(state, opt) {
  103. state.managerToken = opt.managerToken;
  104. Cache.set(MANAGER_STATUS, opt.managerToken);
  105. },
  106. SETUID(state, val) {
  107. state.uid = val;
  108. Cache.set(UID, val);
  109. },
  110. UPDATE_LOGIN(state, token) {
  111. state.token = token;
  112. },
  113. LOGOUT(state) {
  114. uni.clearStorageSync();
  115. state.token = '';
  116. state.managerToken = '';
  117. state.selectMerchantRole = '';
  118. state.uid = '';
  119. state.merchantEmployeeList = [];
  120. state.isEmployee = '';
  121. state.selectMerId = '';
  122. state.selectMerchantRole = '';
  123. Cache.clear(LOGIN_STATUS);
  124. Cache.clear(UID);
  125. Cache.clear(USER_INFO);
  126. Cache.clear(SELECT_MERID);
  127. Cache.clear(MERCHANT_EMPLOYEE_LIST);
  128. Cache.clear(SELECT_MERCHANT);
  129. Cache.clear(MANAGER_STATUS);
  130. Cache.clear(IS_EMPLOYEE);
  131. },
  132. //清除所有本地缓存
  133. clearStorage(state) {
  134. uni.clearStorageSync();
  135. },
  136. BACKGROUND_COLOR(state, color) {
  137. state.color = color;
  138. document.body.style.backgroundColor = color;
  139. },
  140. UPDATE_USERINFO(state, userInfo) {
  141. state.userInfo = userInfo;
  142. Cache.set(USER_INFO, userInfo);
  143. },
  144. OPEN_HOME(state) {
  145. state.homeActive = true;
  146. },
  147. CLOSE_HOME(state) {
  148. state.homeActive = false;
  149. },
  150. SET_CHATURL(state, chatUrl) {
  151. state.chatUrl = chatUrl;
  152. },
  153. SYSTEM_PLATFORM(state, systemPlatform) {
  154. state.systemPlatform = systemPlatform;
  155. Cache.set(PLATFORM, systemPlatform);
  156. },
  157. //更新useInfo数据
  158. changInfo(state, payload) {
  159. state.userInfo[payload.amount1] = payload.amount2;
  160. Cache.set(USER_INFO, state.userInfo);
  161. },
  162. //商品类型,用于区分视频号商品与一般商品
  163. PRODUCT_TYPE(state, productType) {
  164. state.productType = productType;
  165. Cache.set('productType', productType);
  166. },
  167. GLOBAL_DATA(state, key) {
  168. Cache.set(GLOBAL_DATA, key);
  169. state.globalData = key;
  170. },
  171. /** 商户全部分类 **/
  172. SET_MerchantClassify: (state, merchantClassify) => {
  173. state.merchantClassify = changeNodes(merchantClassify)
  174. Cache.set('merchantClassify', JSON.stringify(changeNodes(merchantClassify)));
  175. },
  176. /** 商户全部类型 **/
  177. SET_MerchantType: (state, merchantType) => {
  178. state.merchantType = changeNodes(merchantType)
  179. Cache.set('merchantType', JSON.stringify(changeNodes(merchantType)));
  180. },
  181. /** 商户信息 **/
  182. MERCHANTJINFO: (state, merchantJInfo) => {
  183. state.merchantAPPInfo = merchantJInfo
  184. Cache.set('merchantAPPInfo', merchantJInfo);
  185. },
  186. /** 入驻申请信息 **/
  187. MERSTTLEDDATA: (state, merSttledData) => {
  188. state.merSttledData = merSttledData
  189. Cache.set('merSttledData', merSttledData);
  190. },
  191. /** 是否使用自定义导航 **/
  192. BottomNavigationIsCustom: (state, bottomNavigationIsCustom) => {
  193. state.bottomNavigationIsCustom = bottomNavigationIsCustom
  194. },
  195. /** 校验token是否有效 **/
  196. TokenIsExist: (state, merTokenIsExist) => {
  197. state.merTokenIsExist = merTokenIsExist
  198. Cache.set('merTokenIsExist', merTokenIsExist);
  199. },
  200. /** 选中的话题列表 **/
  201. DiscoverTopic: (state, discoverTopic) => {
  202. state.discoverTopic = discoverTopic
  203. //Cache.set('merTokenIsExist', merTokenIsExist);
  204. },
  205. /** 商家管理列表 **/
  206. SetMerchantEmployeeList(state, val) {
  207. state.merchantEmployeeList = val;
  208. Cache.set('merchantEmployeeList', val);
  209. },
  210. SetIsEmployee(state, val) {
  211. state.isEmployee = val;
  212. Cache.set(IS_EMPLOYEE, val);
  213. },
  214. /** 当前商铺ID **/
  215. SetSelectMerId(state, val) {
  216. state.selectMerId = val;
  217. Cache.set('selectMerId', val);
  218. },
  219. CLEAR_SELECTMERID(state, val) {
  220. state.selectMerId = null;
  221. Cache.clear(SELECT_MERID);
  222. },
  223. /** 当前管理员权限 **/
  224. SetSelectMerchantRole(state, val) {
  225. state.selectMerchantRole = val;
  226. Cache.set('selectMerchantRole', val);
  227. },
  228. updatePaidMember: (state, userIsPaidMember) => {
  229. state.globalData.userIsPaidMember = userIsPaidMember;
  230. Cache.set(GLOBAL_DATA, state.globalData);
  231. },
  232. //修改globalData的值
  233. Change_GLOBAL_DATA(state, data) {
  234. //公司名称
  235. state.globalData.companyName = data.siteName || '欢迎你';
  236. uni.setStorageSync('companyName', data.siteName);
  237. state.globalData.paidMemberPriceDisplay = data.paidMemberPriceDisplay;
  238. state.globalData.userIsPaidMember = data.userIsPaidMember;
  239. state.globalData.changeColorConfig = data.changeColorConfig;
  240. state.globalData.copyrightCompanyImage = data.copyrightCompanyImage;
  241. state.globalData.frontDomain = data.frontDomain;
  242. state.globalData.imageDomain = data.imageDomain;
  243. Cache.set(GLOBAL_DATA, state.globalData);
  244. },
  245. // 分销码
  246. Change_Spread(state, spread) {
  247. state.globalData.spread = spread;
  248. Cache.set(GLOBAL_DATA, state.globalData);
  249. },
  250. //修改globalData的值
  251. Change_GLOBAL_DATA_loginConfig(state, data) {
  252. //公众号登录方式(单选),1微信授权,2手机号登录
  253. state.globalData.publicLoginType = data.wechatBrowserVisit;
  254. Cache.set('publicLoginType', data.wechatBrowserVisit);
  255. //小程序手机号校验类型(多选)1微信小程序验证 2短信验证
  256. state.globalData.routinePhoneVerification = data.routinePhoneVerification;
  257. //登录页logo
  258. state.globalData.mobileLoginLogo = data.mobileLoginLogo;
  259. Cache.set(GLOBAL_DATA, state.globalData);
  260. uni.setStorageSync('mobileLoginLogo', data.mobileLoginLogo);
  261. },
  262. //修改globalData中的值,分销码,id等
  263. Change_GLOBAL_DATA_Spread(state, data) {
  264. state.globalData.spread = data.sd ? data.sd : '';
  265. state.globalData.id = data.id ? data.id : '';
  266. state.globalData.marketingType = data.mt ? data.mt : '0';
  267. Cache.set(GLOBAL_DATA, state.globalData);
  268. },
  269. // 颜色
  270. Change_GLOBAL_theme(state,data){
  271. state.globalData.theme = data;
  272. Cache.set(GLOBAL_DATA, state.globalData);
  273. }
  274. };
  275. /** tree去除 childList=[] 的结构**/
  276. const changeNodes = function(data) {
  277. if (data.length > 0) {
  278. for (var i = 0; i < data.length; i++) {
  279. if (!data[i].childList || data[i].childList.length < 1) {
  280. data[i].childList = undefined;
  281. } else {
  282. changeNodes(data[i].childList);
  283. }
  284. }
  285. }
  286. return data
  287. };
  288. const actions = {
  289. /**
  290. * 全局配置信息
  291. */
  292. GetGlobalConfig({
  293. state,
  294. commit
  295. }) {
  296. return new Promise(reslove => {
  297. globalConfigApi().then(res => {
  298. let data = res.data;
  299. Cache.set('imgHost', data.imageDomain + '/');
  300. commit('Change_GLOBAL_DATA', data)
  301. });
  302. }).catch(err => {
  303. return util.Tips({
  304. title: err
  305. });
  306. });
  307. },
  308. //获取登录配置
  309. GetLoginConfig({
  310. state,
  311. commit
  312. }) {
  313. return new Promise(reslove => {
  314. loginConfigApi().then(res => {
  315. let data = res.data;
  316. commit('Change_GLOBAL_DATA_loginConfig', data)
  317. })
  318. }).catch(err => {
  319. return util.Tips({
  320. title: err
  321. });
  322. });
  323. },
  324. //获取diy颜色配置
  325. GetThemeConfig({
  326. state,
  327. commit
  328. }) {
  329. return new Promise(reslove => {
  330. getTheme().then(res => {
  331. Cache.set('theme', `theme${Number(res.data.value)}`);
  332. commit('Change_GLOBAL_theme', `theme${Number(res.data.value)}`)
  333. // #ifdef H5
  334. window.document.documentElement.setAttribute('data-theme', res.data.value);
  335. // #endif
  336. })
  337. }).catch(err => {
  338. return util.Tips({
  339. title: err
  340. });
  341. });
  342. },
  343. /**
  344. * 校验token是否有效,true为有效,false为无效
  345. */
  346. GetTokenIsExist({
  347. state,
  348. commit
  349. }, force) {
  350. return new Promise(reslove => {
  351. tokenIsExistApi().then(res => {
  352. commit('TokenIsExist', res.data)
  353. if (!res.data) {
  354. store.commit('UPDATE_LOGIN', '');
  355. store.commit('UPDATE_USERINFO', {});
  356. store.commit('SETUID', '');
  357. }
  358. reslove(res.data);
  359. });
  360. }).catch(err => {
  361. return util.Tips({
  362. title: err
  363. });
  364. });
  365. },
  366. /**
  367. * 用户信息
  368. */
  369. USERINFO({
  370. state,
  371. commit
  372. }, force) {
  373. return new Promise(reslove => {
  374. getUserInfoApi().then(res => {
  375. commit("UPDATE_USERINFO", res.data);
  376. commit("SETUID", res.data.id);
  377. reslove(res.data);
  378. });
  379. }).catch(() => {
  380. });
  381. },
  382. /**
  383. * 退出登录
  384. */
  385. GETLOGOUT({
  386. state,
  387. commit,
  388. dispatch
  389. }, force) {
  390. return new Promise(reslove => {
  391. getLogout().then(async () => {
  392. await commit("LOGOUT");
  393. await dispatch("GetTokenIsExist");
  394. await commit("Change_Spread", 0)
  395. await commit('updatePaidMember', false);
  396. uni.reLaunch({
  397. url: '/pages/index/index'
  398. });
  399. });
  400. }).catch(() => {
  401. });
  402. },
  403. MerCategoryList({
  404. state,
  405. commit
  406. }, force) {
  407. return new Promise(reslove => {
  408. getMerCategoryListApi().then(res => {
  409. commit('SET_MerchantClassify', res.data)
  410. reslove(res.data);
  411. });
  412. }).catch(err => {
  413. return util.Tips({
  414. title: err
  415. });
  416. });
  417. },
  418. MerTypeList({
  419. state,
  420. commit
  421. }, force) {
  422. return new Promise(reslove => {
  423. getMerTypeListApi().then(res => {
  424. commit('SET_MerchantType', res.data)
  425. reslove(res.data);
  426. });
  427. }).catch(err => {
  428. return util.Tips({
  429. title: err
  430. });
  431. });
  432. },
  433. getPayConfig({
  434. state,
  435. commit
  436. }, force) {
  437. return new Promise(reslove => {
  438. getPayConfigApi().then(res => {
  439. let data = res.data;
  440. cartArr[0].payStatus = data.payWechatOpen ? 1 : 0;
  441. cartArr[1].payStatus = data.yuePayStatus ? 1 : 0;
  442. cartArr[1].userBalance = data.userBalance ? data.userBalance : 0;
  443. // #ifdef H5
  444. if (Auth.isWeixin()) {
  445. cartArr[2].payStatus = 0;
  446. } else {
  447. cartArr[2].payStatus = data.aliPayStatus ? 1 : 0;
  448. }
  449. // #endif
  450. // #ifdef APP-PLUS
  451. cartArr[2].payStatus = data.aliPayStatus ? 1 : 0;
  452. // #endif
  453. let cartArrs = cartArr.filter(e => e.payStatus === 1);
  454. reslove({
  455. userBalance: data.userBalance,
  456. payConfig: cartArrs
  457. });
  458. })
  459. }).catch(err => {
  460. return util.Tips({
  461. title: err
  462. });
  463. });
  464. }
  465. }
  466. export default {
  467. state,
  468. mutations,
  469. actions
  470. };