index.js 1.6 KB

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