index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { spread } from "@/api/user";
  2. import Cache from "@/utils/cache";
  3. /**
  4. * 静默授权绑定上下级,使用在已经登录后扫描了别人的推广二维码
  5. * @param {Object} puid
  6. */
  7. export function silenceBindingSpread() {
  8. //#ifdef H5
  9. let puid = Cache.get('spread');
  10. //#endif
  11. //#ifdef MP
  12. let puid = getApp().globalData.spid;
  13. //#endif
  14. puid = parseInt(puid);
  15. if (Number.isNaN(puid)) {
  16. puid = 0;
  17. }
  18. if (puid) {
  19. spread(puid).then(res => {}).catch(res => {});
  20. //#ifdef H5
  21. Cache.clear('spread');
  22. //#endif
  23. //#ifdef MP
  24. getApp().globalData.spid = 0;
  25. getApp().globalData.code = 0;
  26. //#endif
  27. } else {
  28. Cache.set('spread', 0);
  29. }
  30. }
  31. export function isWeixin() {
  32. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  33. }
  34. export function parseQuery() {
  35. const res = {};
  36. const query = (location.href.split("?")[1] || "")
  37. .trim()
  38. .replace(/^(\?|#|&)/, "");
  39. if (!query) {
  40. return res;
  41. }
  42. query.split("&").forEach(param => {
  43. const parts = param.replace(/\+/g, " ").split("=");
  44. const key = decodeURIComponent(parts.shift());
  45. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  46. if (res[key] === undefined) {
  47. res[key] = val;
  48. } else if (Array.isArray(res[key])) {
  49. res[key].push(val);
  50. } else {
  51. res[key] = [res[key], val];
  52. }
  53. });
  54. return res;
  55. }
  56. // #ifdef H5
  57. const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}:20001`;
  58. export {
  59. VUE_APP_WS_URL
  60. }
  61. // #endif
  62. export default parseQuery;