index.js 1.6 KB

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