You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.4 KiB

3 months ago
  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 { spread } from "@/api/user";
  11. import Cache from "@/utils/cache";
  12. import { getCity } from '@/api/api.js';
  13. /**
  14. * 静默授权绑定上下级使用在已经登录后扫描了别人的推广二维码
  15. * @param {Object} puid
  16. */
  17. export function silenceBindingSpread() {
  18. //#ifdef H5
  19. let puid = Cache.get('spread');
  20. //#endif
  21. //#ifdef MP || APP-PLUS
  22. let puid = getApp().globalData.spread;
  23. //#endif
  24. puid = parseInt(puid);
  25. if (Number.isNaN(puid)) {
  26. puid = 0;
  27. }
  28. if (puid) {
  29. spread(puid).then(res => {}).catch(res => {
  30. //#ifdef H5
  31. Cache.clear("spread");
  32. //#endif
  33. //#ifdef MP || APP-PLUS
  34. getApp().globalData.spread = 0;
  35. //#endif
  36. });
  37. } else {
  38. Cache.set('spread', 0);
  39. }
  40. }
  41. export function isWeixin() {
  42. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  43. }
  44. export function parseQuery() {
  45. const res = {};
  46. const query = (location.href.split("?")[1] || "")
  47. .trim()
  48. .replace(/^(\?|#|&)/, "");
  49. if (!query) {
  50. return res;
  51. }
  52. query.split("&").forEach(param => {
  53. const parts = param.replace(/\+/g, " ").split("=");
  54. const key = decodeURIComponent(parts.shift());
  55. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  56. if (res[key] === undefined) {
  57. res[key] = val;
  58. } else if (Array.isArray(res[key])) {
  59. res[key].push(val);
  60. } else {
  61. res[key] = [res[key], val];
  62. }
  63. });
  64. return res;
  65. }
  66. // #ifdef H5
  67. const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}:20001`;
  68. export {
  69. VUE_APP_WS_URL
  70. }
  71. // #endif
  72. // 获取地址数据
  73. export function getCityList() {
  74. return new Promise((resolve, reject) => {
  75. getCity().then(res => {
  76. resolve(res.data);
  77. let oneDay = 24 * 3600 * 1000;
  78. Cache.setItem({
  79. name: 'cityList',
  80. value: res.data,
  81. expires: oneDay * 7
  82. }); //设置七天过期时间
  83. })
  84. });
  85. }
  86. export default parseQuery;