common.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * 公共API
  3. */
  4. import { http, Method } from "@/utils/request.js";
  5. import api from "@/config/api.js";
  6. import config from "@/config/config";
  7. /**
  8. * 逆地址解析
  9. * @param location
  10. */
  11. export function wxGeocoder(location) {
  12. return http.request({
  13. url: `https://apis.map.qq.com/ws/geocoder/v1/?key=${config.wxMapSubKey}&location=${location}`,
  14. method: Method.GET,
  15. message: false,
  16. });
  17. }
  18. /**
  19. * 获取地区数据
  20. * @param id
  21. */
  22. export function getRegionsById(id = 0) {
  23. return http.request({
  24. url: `${api.common}/common/region/item/${id}`,
  25. method: Method.GET,
  26. message: false,
  27. });
  28. }
  29. // 获取IM接口前缀
  30. export function getIMDetail() {
  31. return http.request({
  32. url: `${api.common}/IM`,
  33. method: Method.GET,
  34. message: false,
  35. });
  36. }
  37. /**
  38. * url encode
  39. * @param {String} url
  40. * @param {Object} params
  41. */
  42. export function encodeURL(url, params) {
  43. const arr = [];
  44. Object.entries(params).forEach((param) => {
  45. if (param[1]) {
  46. arr.push(`${param[0]}=${encodeURIComponent(param[1])}`);
  47. }
  48. });
  49. const result = url + "?" + arr.join("&");
  50. return result;
  51. }
  52. /**
  53. * 文件上传地址
  54. * @type {string}
  55. */
  56. export const upload = api.common + "/mp/v1/file/upload";