location-search.ts 619 B

123456789101112131415161718192021222324252627282930
  1. class LocationSearch {
  2. obj = {} as any;
  3. constructor() {
  4. this.obj = this.str2Obj()
  5. }
  6. str2Obj() {
  7. const obj = {} as any;
  8. const searchArr = location.search.replace("?", "").split("&");
  9. searchArr.map((str) => {
  10. const [key, ...value] = str.split("=");
  11. obj[key] = value.map((item) => {
  12. return item ? item : "="
  13. }).join("");
  14. })
  15. return obj;
  16. }
  17. join2Str() {
  18. const arr = [];
  19. Object.keys(this.obj).map((key) => {
  20. if(key != 'token' && key != 'openid') {
  21. arr.push(`${key}=${this.obj[key]}`)
  22. }
  23. });
  24. return arr.length ? `?${arr.join("&")}` : "";
  25. }
  26. }
  27. export default LocationSearch