2 lines
1.8 KiB
JavaScript
2 lines
1.8 KiB
JavaScript
"use strict";const e=require("../common/vendor.js"),t=require("../service/mapService.js"),i=require("../utils/commUtils.js");if(!Array){(e.resolveComponent("u-col")+e.resolveComponent("u-row"))()}const a={__name:"Map",props:{initialLongitude:{type:Number,default:null},initialLatitude:{type:Number,default:null},iconPath:{type:String,default:"/static/map/self.png"},locationName:{type:String,default:"本地位置"}},emits:["doneFun"],setup(a,{emit:l}){const u=a,n=e.ref(u.initialLongitude||0),o=e.ref(u.initialLatitude||0),d=e.ref(0),c=e.ref(0),r=e.ref("16"),s=e.ref(!0),v=l,g=e.reactive([{longitude:n.value,latitude:o.value,iconPath:u.iconPath,width:30,height:30,label:{content:u.locationName,textAlign:"center",color:"#FB3109"}}]),p=()=>{e.index.chooseLocation({success:e=>{n.value=e.longitude,o.value=e.latitude,g[0].longitude=e.longitude,g[0].latitude=e.latitude},fail:e=>{i.toast("获取位置失败")}})};return e.watch((()=>[u.initialLongitude,u.initialLatitude]),(([e,t])=>{null!==e&&(n.value=e,g[0].longitude=e),null!==t&&(o.value=t,g[0].latitude=t)})),e.onLoad((()=>{0===n.value&&0===o.value?e.index.getLocation({type:"gcj02",timeout:1e3,geocode:s.value,success:i=>{e.index.hideLoading(),n.value=i.longitude,o.value=i.latitude,d.value=i.longitude,c.value=i.latitude,g[0].longitude=i.longitude,g[0].latitude=i.latitude,t.getMapDetailAddress(i.longitude,i.latitude).then((e=>{v("doneFun",e)}))},fail:t=>{e.index.showModal({title:"提示",content:"位置信息获取失败(请确定定位功能是否打开)",showCancel:!1})}}):(g[0].longitude=n.value,g[0].latitude=o.value,t.getMapDetailAddress(n.value,o.value).then((e=>{v("doneFun",e)})))})),(t,i)=>({a:n.value,b:o.value,c:r.value,d:e.o(p),e:g,f:e.p({span:"12"})})}},l=e._export_sfc(a,[["__scopeId","data-v-78afe88e"]]);wx.createComponent(l);
|