app.js 14 KB

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