export const getCurrCity = () => {
  return new Promise((resolve, reject) => {
    let script = document.createElement("script");
    const url = `https://apis.map.qq.com/tools/geolocation/min?key=RPZBZ-CJE3D-YN24W-POI53-IAHPE-5HBB4&referer=educoder`;
    script.id = url;
    script.src = url;
    script.onload = script.onreadystatechange = () => {
      if (
        !script.readyState || //这是FF的判断语句，因为ff下没有readyState这个值，IE的readyState肯定有值
        script.readyState === "loaded" ||
        script.readyState === "complete" // 这是IE的判断语句
      ) {
        const geolocation = new window.qq.maps.Geolocation();
        geolocation.getIpLocation(
          (position) => {
            resolve(position.city.replace("市",""));
          },
          (err) => {
            reject("fail");
          }
        );
      }
    };
    document.body.appendChild(script);
  });
};
