智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
6.8 KiB

import{d as te,k as v,M as ne,r as g,ap as oe,a5 as G,aG as se,P as j,b0 as ie,h,m as B,w as y,a as I,e as w,i as $,t as z,u as L,c as S,B as de,F as U,O as D,a6 as re,_ as ce,$ as ue,D as me,E as pe,V as ve}from"./index-4c331f20.js";/* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css */import{B as E}from"./sys-aa8fe7bc.js";import{c as fe,a as ge}from"./qqmap-011f3cfb.js";import{_ as he}from"./_plugin-vue_export-helper-c27b6911.js";const ye={class:"map-container",id:"container"},_e={key:0,class:"map-placeholder"},Ve={class:"address-search"},we={class:"dialog-footer"},Le=te({__name:"TencentMapPicker",props:{modelValue:{type:Object,default:()=>({lat:null,lng:null,address:""})},placeholder:{type:String,default:v("mapPickerPlaceholder")},visible:{type:Boolean,default:!1}},emits:["update:visible","update:modelValue","confirm"],setup(O,{emit:T}){const s=O,_=ne({get(){return s.visible},set(a){T("update:visible",a)}});let r=null,f=null;const P=g("YOUR_API_KEY");let p=null,b=null;const c=g(""),u=g(""),m=g(""),V=g(""),C=g([]),k=g([]),M=g([]);oe(()=>{const a=document.createElement("script");a.src=`https://map.qq.com/api/gljs?key= ${P.value}`,document.head.appendChild(a)}),G(_,async a=>{if(a)try{if(x(),await se(),!document.getElementById("container"))throw new Error("地图容器未找到");await J(),Q();const t=await E(0);C.value=t.data,s.modelValue.address&&await W(s.modelValue.address),X()}catch(e){N(e)}else x()},{immediate:!0});const F=a=>{a()},Y=()=>{var i,d,o;if(!s.modelValue.lat||!s.modelValue.lng){j.warning(v("mapPickerWarning"));return}const a=c.value&&((i=C.value.find(l=>l.id===c.value))==null?void 0:i.name)||"",e=u.value&&((d=k.value.find(l=>l.id===u.value))==null?void 0:d.name)||"",t=m.value&&((o=M.value.find(l=>l.id===m.value))==null?void 0:o.name)||"",n=`${a}${e}${t}${V.value}`;T("confirm",{lat:s.modelValue.lat,lng:s.modelValue.lng,address:n}),_.value=!1},W=async a=>{const{provinceName:e,cityName:t,districtName:n,detail:i}=H(a);if(V.value=i,e){const d=C.value.find(o=>o.name.includes(e));if(d){c.value=d.id;const o=await E(c.value);if(k.value=o.data,t){const l=k.value.find(A=>A.name.includes(t));if(l){u.value=l.id;const A=await E(u.value);if(M.value=A.data,n){const q=M.value.find(le=>le.name.includes(n));q&&(m.value=q.id)}}}}}R()},H=a=>{let e="",t="",n="",i=a;const d=a.match(/^([^省市自治区]+[省市区]|[^市]+市)/);d&&(e=d[0],i=a.slice(e.length));const o=i.match(/^([^市区]+市)/);o&&(t=o[0],i=i.slice(t.length));const l=i.match(/^([^区县]+[区县])/);return l&&(n=l[0],i=i.slice(n.length)),{provinceName:e,cityName:t,districtName:n,detail:i.trim()||""}},x=()=>{p&&(document.body.removeChild(p),p=null),r&&(r.destroy(),r=null),f=null,b&&(clearTimeout(b),b=null),window.removeEventListener("resize",K)},J=()=>new Promise((a,e)=>{P.value={}.VITE_MAP_KEY,p=document.createElement("script"),p.type="text/javascript",p.src=`https://map.qq.com/api/gljs?libraries=tools ,service&v=1.exp&key=${P.value}`,p.onload=()=>{window.TMap?a():e(new Error("TMap未定义"))},p.onerror=t=>{e(t)},document.body.appendChild(p)}),Q=()=>{const a=document.getElementById("container");if(!window.TMap||!a)throw new Error("地图SDK未加载或容器不存在");const e=window.TMap;let t;s.modelValue.lat&&s.modelValue.lng?t=new e.LatLng(s.modelValue.lat,s.modelValue.lng):t=new e.LatLng(39.90403,116.407526),r=new e.Map("container",{center:t,zoom:12}),f=fe(r),s.modelValue.lat&&s.modelValue.lng&&f.updateGeometries({id:"center",position:new e.LatLng(s.modelValue.lat,s.modelValue.lng)}),r.on("click",n=>{r.setCenter(n.latLng),f.updateGeometries({id:"center",position:n.latLng}),T("update:modelValue",{lat:n.latLng.lat,lng:n.latLng.lng,address:V.value})})},X=()=>{window.addEventListener("resize",K)},K=()=>{b&&clearTimeout(b),b=setTimeout(()=>{r==null||r.setSize()},300)},Z=async a=>{try{const e=await E(a);k.value=e.data,u.value="",m.value=""}catch(e){N(e)}},ee=async a=>{try{const e=await E(a);M.value=e.data,m.value=""}catch(e){N(e)}},ae=a=>{},R=async()=>{var a,e,t;try{const n=[c.value?(a=C.value.find(o=>o.id===c.value))==null?void 0:a.name:"",u.value?(e=k.value.find(o=>o.id===u.value))==null?void 0:e.name:"",m.value?(t=M.value.find(o=>o.id===m.value))==null?void 0:t.name:"",V.value].join(""),{message:i,result:d}=await ge({mapKey:P.value,address:n});if(i=="Success"||i=="query ok"){const o=new window.TMap.LatLng(d.location.lat,d.location.lng);r.setCenter(o),f.updateGeometries({id:"center",position:o}),T("update:modelValue",{lat:d.location.lat,lng:d.location.lng,address:V.value})}}catch(n){N(n)}},N=a=>{console.error("地图组件错误:",a),j.error(v("mapLoadFailed")),_.value=!1};return G(()=>s.modelValue,a=>{if(a!=null&&a.lat&&(a!=null&&a.lng)&&r)try{const e=new window.TMap.LatLng(a.lat,a.lng);r.setCenter(e),f==null||f.updateGeometries({id:"center",position:e})}catch(e){console.warn("地图更新失败:",e)}},{deep:!0,immediate:!0}),ie(()=>{x()}),(a,e)=>{const t=ce,n=ue,i=me,d=pe,o=ve;return h(),B(o,{modelValue:L(_),"onUpdate:modelValue":e[5]||(e[5]=l=>re(_)?_.value=l:null),title:"位置选择",width:"800px","before-close":F,"close-on-click-modal":!1,"close-on-press-escape":!1,"show-close":!1},{footer:y(()=>[I("span",we,[w(d,{onClick:e[4]||(e[4]=l=>_.value=!1)},{default:y(()=>[$(z(L(v)("cancel")),1)]),_:1}),w(d,{type:"primary",onClick:Y},{default:y(()=>[$(z(L(v)("confirm")),1)]),_:1})])]),default:y(()=>[I("div",ye,[!s.modelValue.lat||!s.modelValue.lng?(h(),S("div",_e)):de("",!0)]),I("div",Ve,[w(n,{modelValue:c.value,"onUpdate:modelValue":e[0]||(e[0]=l=>c.value=l),placeholder:L(v)("provincePlaceholder"),onChange:Z},{default:y(()=>[(h(!0),S(U,null,D(C.value,l=>(h(),B(t,{key:l.id,label:l.name,value:l.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder"]),w(n,{modelValue:u.value,"onUpdate:modelValue":e[1]||(e[1]=l=>u.value=l),placeholder:L(v)("cityPlaceholder"),onChange:ee,disabled:!c.value},{default:y(()=>[(h(!0),S(U,null,D(k.value,l=>(h(),B(t,{key:l.id,label:l.name,value:l.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder","disabled"]),w(n,{modelValue:m.value,"onUpdate:modelValue":e[2]||(e[2]=l=>m.value=l),placeholder:L(v)("districtPlaceholder"),onChange:ae,disabled:!c.value||!u.value},{default:y(()=>[(h(!0),S(U,null,D(M.value,l=>(h(),B(t,{key:l.id,label:l.name,value:l.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder","disabled"]),w(i,{modelValue:V.value,"onUpdate:modelValue":e[3]||(e[3]=l=>V.value=l),placeholder:"输入地区"},null,8,["modelValue"]),w(d,{type:"primary",onClick:R,disabled:!c.value||!u.value||!m.value},{default:y(()=>[$(z(L(v)("search")),1)]),_:1},8,["disabled"])])]),_:1},8,["modelValue"])}}});const $e=he(Le,[["__scopeId","data-v-c7cd1c16"]]);export{$e as default};