2025-06-13 13:42:14 +08:00
|
|
|
import{r as a,J as e,j as l,a4 as t,c as n,w as s,a5 as o,s as i,i as A,o as r,a as c,b as p,m as d,v as u,k as g,t as m,u as S,F as U,B as M,z as h,g as w,I as k,x as f,e as I}from"./index-DaJpSunw.js";import{r as K,b as x}from"./index.DXubNnP-.js";import{_ as B}from"./_plugin-vue_export-helper.BCo6x5W8.js";function Q(a){return K({url:`/api/proxy/get?apiUrl=${a.apiUrl}¶ms=${a.other}`,method:"get"})}const F=B({__name:"index",setup(K){const B=a(null),F=a(""),J=a([]),V=a(!1);let C=null,E=null;function T(a,e){const l=new qq.maps.LatLng(a,e);C=new qq.maps.Map(document.getElementById("map"),{center:l,zoom:15,zoomControl:!1,panControl:!1,mapTypeControl:!1}),E=new qq.maps.Marker({position:l,map:C})}async function y(){await new Promise((a=>{if(window.wx&&"function"==typeof wx.config)return a();const e=document.createElement("script");e.src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js",e.onload=()=>{const e=()=>{window.wx&&"function"==typeof wx.config?a():setTimeout(e,50)};e()},e.onerror=()=>{console.error("加载微信 JSSDK 脚本失败"),a()},document.head.appendChild(e)}));try{const a=await fetch(`${x}/weixin/getJsApiInfo`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:location.href.split("#")[0]})}),e=await a.json();window.wx&&"function"==typeof wx.config?(wx.config({debug:!1,appId:"wx8fc3e4305d2fbf0b",timestamp:e.timestamp,nonceStr:e.nonceStr,signature:e.signature,jsApiList:["getLocation","openLocation"]}),wx.ready((()=>{o({type:"wgs84",success(a){T(a.latitude,a.longitude),L(a.latitude,a.longitude)},fail(a){console.warn("微信定位失败,使用默认位置",a),i({title:"定位失败,使用默认位置",icon:"none"}),T(39.9042,116.4074),L(39.9042,116.4074)}})})),wx.error((a=>{console.error("wx.config 验证失败:",a),T(39.9042,116.4074)}))):(console.warn("wx.config 不可用,使用默认位置"),T(39.9042,116.4074))}catch(a){console.error("获取 JSSDK 签名失败:",a),T(39.9042,116.4074)}}const R=()=>{o({type:"wgs84",success(a){T(a.latitude,a.longitude),L(a.latitude,a.longitude)},fail(a){console.warn("微信定位失败,使用默认位置",a),i({title:a.errMsg,icon:"none"}),T(39.9042,116.4074),L(39.9042,116.4074)}})},Y=()=>{M()},Z=()=>{const a={name:J.value[G.value].name,lat:J.value[G.value].lat,lng:J.value[G.value].lng};h("dingwei",a),M()};const L=(a,e)=>{Q({apiUrl:"https://apis.map.qq.com/ws/geocoder/v1",other:`location=${a},${e}%26key=LOLBZ-Z2PKW-JJ6RO-3Y7Z7-BSKWT-DLFNC%26get_poi=1%26radius=1000%26poi_options=page_size=10;radius=1000;policy=distance;address_format=short`}).then((a=>{0===a.status?(J.value=[],a.result.pois.map((a=>{let e={name:a.title,juli:`${a._distance}km`,where:a.address,lat:a.location.lat,lng:a.location.lng};J.value.push(e)}))):i({title:"未搜索到结果",icon:"none"})}))},G=a(0);const O=()=>{const a=C.getCenter(),e=a.getLat(),l=a.getLng();G.value=0,L(e,l)},v=a("");let j=null;function D(a){var e;v.value=(null==(e=a.detail)?void 0:e.value)??a.target.value,j&&clearTimeout(j),/[A-Za-z]/.test(v.value)||(j=setTimeout((()=>{v.value.trim()&&async function(){const a=F.value.trim();if(!a)return void i({title:"请输入搜索内容",icon:"none"});J.value=[];const e=C.getCenter(),l=e.getLat(),t=e.getLng();Q({apiUrl:"https://apis.map.qq.com/ws/place/v1/search",other:`keyword=${encodeURIComponent(a)}%26boundary=nearby(${l},${t},1000)%26key=LOLBZ-Z2PKW-JJ6RO-3Y7Z7-BSKWT-DLFNC`}).then((a=>{0===a.status&&a.data.length?a.data.map((a=>{let e={name:a.title,juli:`${a._distance}km`,where:a.address,lat:a.location.lat,lng:a.location.lng};J.value.push(e)})):i({title:"未搜索到结果",icon:"none"})}))}()}),500))}const q=()=>{V.value=!1,G.value=-1,J.value.length||O()};return e((async()=>{await y()})),l((()=>{j&&clearTimeout(j)})),(a,e)=>{const l=w,o=A,i=k,M=t("uview");return r(),n(o,{class:"container"},{default:s((()=>[c(o,{class:"search-bar"},{default:s((()=>[c(o,{class:"search-bar-left"},{default:s((()=>[c(l,{class:"left-imge",src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAABpRJREFUeF7tnUfIXUUUx0/ssRAx2GKNvWvsvcTEbkzsK924E
|