index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 || APP-PLUS
  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. //#ifdef H5
  31. Cache.clear('spread');
  32. //#endif
  33. //#ifdef MP || APP-PLUS
  34. getApp().globalData.spid = 0;
  35. getApp().globalData.code = 0;
  36. //#endif
  37. }).catch(res=>{
  38. });
  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}`;
  68. export {VUE_APP_WS_URL}
  69. // #endif
  70. export default parseQuery;