Files
anmo/server/public/admin/assets/useMap-JUBpQuQU.js
2025-08-19 14:16:51 +08:00

2 lines
2.7 KiB
JavaScript
Executable File

import{u as v,c as w,j as k,T as M,eD as S,eE as f,C as m,eF as $,eG as E}from"./index-CGub03FT.js";const b=c=>new Promise((r,u)=>{const o=document.getElementById(c);if(o)return r(o);try{const n=document.createElement("script");n.setAttribute("id",c),n.setAttribute("src",c),document.body.append(n),("onload"in n?y:g)(n).then(()=>r(n)).catch(()=>u())}catch(n){u(n)}function y(n){return new Promise((l,s)=>{n.onload=function(){this.onerror=this.onload=null,l(n)},n.onerror=function(){this.onerror=this.onload=null,s()}})}function g(n){return new Promise((l,s)=>{n.onreadystatechange=function(){(this.readyState==="loaded"||this.readyState==="complete")&&(this.onreadystatechange=null,l(n))}})}}),L=v(),h=w(()=>L.config);function j(){let c=null,r=null,u=null;const o=k({province_id:"",city_id:"",district_id:"",address:"",latitude:"39.954104",longitude:"116.357503"}),y=M((s,a)=>{const t=`https://map.qq.com/api/gljs?v=1.exp&key=${h.value.tencent_map_key}`;b(t).then(()=>g(s,a))},2e3),g=(s,a)=>{r=window.TMap;const t=r.LatLng,d=new t(s,a);new r.Map("container",{center:d}).destroy(),c=new r.Map("container",{center:d}),u=new r.MultiMarker({map:c,styles:{myStyle:new r.MarkerStyle({anchor:{x:17,y:34}})},geometries:[{id:"1",styleId:"myStyle",position:d}]}),c.on("click",e=>{const{lat:i,lng:p}=e.latLng;u.updateGeometries([{styleId:"myStyle",id:"1",position:new r.LatLng(i,p)}]),l(i,p)})},n=async(s,a,t,d)=>{const e=S(s,a,t);return f("https://apis.map.qq.com/ws/geocoder/v1/",{key:h.value.tencent_map_key,address:`${e==null?void 0:e.province}${e==null?void 0:e.city}${e==null?void 0:e.district}${d}`,output:"jsonp"}).then(i=>{if(i.status===0){console.log(`${e==null?void 0:e.province}${e==null?void 0:e.city}${e==null?void 0:e.district}${d}`),console.log(i);const{lat:p,lng:_}=i.result.location;y(p,_),c==null||c.setCenter({lat:p,lng:_})}else console.log("err",i),m.msgError(i.message)}).catch(i=>Promise.reject(i))},l=async(s,a)=>{try{const t=await f("https://apis.map.qq.com/ws/geocoder/v1/",{key:h.value.tencent_map_key,location:`${s},${a}`,output:"jsonp"});if(t.status===0){const d=$(t.result.address_component.province);if(d===!1)return m.msgError("请选择有效地区");o.province_id=d,t.result.address_component.city=="北京市"||t.result.address_component.city=="天津市"||t.result.address_component.city=="上海市"||t.result.address_component.city=="重庆市"?o.city_id=E(o.province_id,t.result.address_component.city):o.city_id=t.result.ad_info.city_code.substring(3,9),o.district_id=Number(t.result.ad_info.adcode),o.address=t.result.formatted_addresses.recommend,o.latitude=s,o.longitude=a}else m.msgError(t.message)}catch(t){t&&m.msgError(String(t))}};return{obj:o,loadTencentMapScript:y,addressGeocoder:n}}export{j as u};