index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {
  2. spread
  3. } from "@/api/user";
  4. import Cache from "@/utils/cache";
  5. /**
  6. * 绑定用户授权
  7. * @param {Object} puid
  8. */
  9. export function silenceBindingSpread() {
  10. //#ifdef H5
  11. let puid = Cache.get('spread');
  12. //#endif
  13. //#ifdef MP
  14. let puid = getApp().globalData.spid;
  15. if (!puid) {
  16. puid = getApp().globalData.code;
  17. }
  18. //#endif
  19. puid = parseInt(puid);
  20. if (Number.isNaN(puid)) {
  21. puid = 0;
  22. }
  23. if (puid) {
  24. //#ifdef H5
  25. Cache.clear('spread');
  26. //#endif
  27. //#ifdef MP
  28. getApp().globalData.spid = 0;
  29. getApp().globalData.code = 0;
  30. //#endif
  31. }
  32. }
  33. export function isWeixin() {
  34. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  35. }
  36. export function parseQuery() {
  37. const res = {};
  38. const query = (location.href.split("?")[1] || "")
  39. .trim()
  40. .replace(/^(\?|#|&)/, "");
  41. if (!query) {
  42. return res;
  43. }
  44. // const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}:20003`;
  45. // const ishttps = 'https:' == document.location.protocol ? true : false;
  46. // const VUE_APP_WS_URL = ishttps ? `wss://mer.crmeb.net?type=user&token=${token}` : `ws://mer.crmeb.net?type=user&token=${token}`;
  47. // export { VUE_APP_WS_URL }
  48. query.split("&").forEach(param => {
  49. const parts = param.replace(/\+/g, " ").split("=");
  50. const key = decodeURIComponent(parts.shift());
  51. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  52. if (res[key] === undefined) {
  53. res[key] = val;
  54. } else if (Array.isArray(res[key])) {
  55. res[key].push(val);
  56. } else {
  57. res[key] = [res[key], val];
  58. }
  59. });
  60. return res;
  61. }
  62. let token = ''
  63. try {
  64. token = uni.getStorageSync('LOGIN_STATUS_TOKEN')
  65. console.log(token, 'this')
  66. } catch (error) {
  67. }
  68. // const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}?type=user&token=${token}`;
  69. // const VUE_APP_WS_URL = `wss://mer.crmeb.net?type=user&token=${token}`
  70. export default parseQuery;