index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 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. /**
  13. * 绑定用户授权
  14. * @param {Object} puid
  15. */
  16. export function silenceBindingSpread()
  17. {
  18. //#ifdef H5
  19. let puid = Cache.get('spread'),code = 0;
  20. //#endif
  21. //#ifdef MP
  22. let puid = getApp().globalData.spid,code = getApp().globalData.code;
  23. //#endif
  24. puid = parseInt(puid);
  25. if(Number.isNaN(puid)){
  26. puid = 0;
  27. }
  28. if(puid){
  29. spread({puid,code}).then(res=>{
  30. console.log(res);
  31. //#ifdef H5
  32. Cache.clear('spread');
  33. //#endif
  34. //#ifdef MP
  35. getApp().globalData.spid = 0;
  36. getApp().globalData.code = 0;
  37. //#endif
  38. }).catch(res=>{
  39. console.log(res);
  40. });
  41. }
  42. }
  43. export function isWeixin() {
  44. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  45. }
  46. export function parseQuery() {
  47. const res = {};
  48. const query = (location.href.split("?")[1] || "")
  49. .trim()
  50. .replace(/^(\?|#|&)/, "");
  51. if (!query) {
  52. return res;
  53. }
  54. query.split("&").forEach(param => {
  55. const parts = param.replace(/\+/g, " ").split("=");
  56. const key = decodeURIComponent(parts.shift());
  57. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  58. if (res[key] === undefined) {
  59. res[key] = val;
  60. } else if (Array.isArray(res[key])) {
  61. res[key].push(val);
  62. } else {
  63. res[key] = [res[key], val];
  64. }
  65. });
  66. return res;
  67. }
  68. // #ifdef H5
  69. const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}:20003`;
  70. export {VUE_APP_WS_URL}
  71. // #endif
  72. export default parseQuery;