index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export function trim(str) {
  2. return String.prototype.trim.call(str);
  3. }
  4. export function isType(arg, type) {
  5. return Object.prototype.toString.call(arg) === "[object " + type + "]";
  6. }
  7. export function isWeixin() {
  8. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  9. }
  10. export function parseQuery() {
  11. const res = {};
  12. const query = (location.href.split("?")[1] || "")
  13. .trim()
  14. .replace(/^(\?|#|&)/, "");
  15. if (!query) {
  16. return res;
  17. }
  18. query.split("&").forEach(param => {
  19. const parts = param.replace(/\+/g, " ").split("=");
  20. const key = decodeURIComponent(parts.shift());
  21. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  22. if (res[key] === undefined) {
  23. res[key] = val;
  24. } else if (Array.isArray(res[key])) {
  25. res[key].push(val);
  26. } else {
  27. res[key] = [res[key], val];
  28. }
  29. });
  30. return res;
  31. }
  32. const VUE_APP_API_URL = process.env.VUE_APP_API_URL || `${location.origin}/api`;
  33. const VUE_APP_WS_URL =
  34. process.env.VUE_APP_WS_URL || `ws:${location.hostname}:20003`;
  35. export { VUE_APP_API_URL, VUE_APP_WS_URL };