index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 { spreadApi } from "@/api/user";
  11. import Cache from "@/utils/cache";
  12. import { getCity } from '@/api/api.js';
  13. import Store from '@/store/index';
  14. import store from "../store";
  15. /**
  16. * 取值
  17. */
  18. export function configMap(args, init) {
  19. if(Array.isArray(args)) {
  20. return args.reduce((i, v)=>{
  21. i[v] = () => Store.getters.globalData[v];
  22. return i;
  23. }, init || {})
  24. }else{
  25. return Object.keys(args).reduce((i, v)=>{
  26. i[v] = () => {
  27. const val = Store.getters.globalData[v];
  28. return (val === undefined || val === null || val === '') ? args[v] : val;
  29. };
  30. return i;
  31. }, init || {})
  32. }
  33. }
  34. /**
  35. * 获取浏览器的分销码
  36. * @param options
  37. */
  38. export function getUserSpread(options){
  39. if(options.sd) store.commit('Change_Spread', options.sd);
  40. }
  41. /**
  42. * 静默授权绑定上下级,绑定后清除分销码
  43. * @param islogin
  44. * @param sd
  45. */
  46. export function silenceBindingSpread(islogin,sd) {
  47. if (islogin && sd) {
  48. spreadApi(sd).then(res => {
  49. //#ifdef MP
  50. getApp().globalData.spread = 0;
  51. //#endif
  52. //清空分销码
  53. store.commit("Change_Spread",0)
  54. }).catch(res => {})
  55. }
  56. }
  57. export function isWeixin() {
  58. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  59. }
  60. export function parseQuery() {
  61. const res = {};
  62. const query = (location.href.split("?")[1] || "")
  63. .trim()
  64. .replace(/^(\?|#|&)/, "");
  65. if (!query) {
  66. return res;
  67. }
  68. query.split("&").forEach(param => {
  69. const parts = param.replace(/\+/g, " ").split("=");
  70. const key = decodeURIComponent(parts.shift());
  71. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  72. if (res[key] === undefined) {
  73. res[key] = val;
  74. } else if (Array.isArray(res[key])) {
  75. res[key].push(val);
  76. } else {
  77. res[key] = [res[key], val];
  78. }
  79. });
  80. return res;
  81. }
  82. // #ifdef H5
  83. const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}:20001`;
  84. export {
  85. VUE_APP_WS_URL
  86. }
  87. // #endif
  88. // 获取地址数据
  89. export function getCityList() {
  90. return new Promise((resolve, reject) => {
  91. getCity().then(res => {
  92. resolve(res.data);
  93. Cache.set('cityList',res.data)
  94. })
  95. });
  96. }
  97. export default parseQuery;