task#6524 获取定位城市,时间默认当前

This commit is contained in:
2025-06-19 19:55:32 +08:00
parent 16d4425e07
commit bb13a6e34e
2 changed files with 12 additions and 3 deletions

View File

@ -21,7 +21,7 @@
</template>
<script>
import { searchFun } from '@/utils/map'
import { searchFun, getLocal, getAddress } from '@/utils/map'
export default {
name: "addressMap",
data() {
@ -31,6 +31,7 @@
activeIndex: '',
map: '',
marker: null,
cityCode: ''
}
},
watch: {
@ -43,16 +44,22 @@
await this.initMap()
},
methods: {
initMap() { // 初始化地图
async initMap() { // 初始化地图
this.map = new AMap.Map('mapId', {
viewMode: '2D', // 默认使用 2D 模式
zoom:11, //初始化地图层级
})
let res = await getLocal(this.map);
let lnglat = new AMap.LngLat(res?.lng, res?.lat);
let location = await getAddress(this.map, lnglat)
this.cityCode = location?.regeocode.addressComponent.adcode
//location?.regeocode?.addressComponent?.city || location?.regeocode?.addressComponent?.province
console.log('location', location);
},
async searchHandler() {
this.activeIndex = null
if( this.keyword ) {
this.addressList = await searchFun(this.map, '', this.keyword)
this.addressList = await searchFun(this.map, this.cityCode, this.keyword,)
this.addressList = this.addressList.filter(item => !!item.location)
} else {
this.addressList = []

View File

@ -116,6 +116,7 @@
v-if="showDatetime"
v-model="appointTime"
type="datetime"
:min-date="minDate"
@confirm="onConfirm"
@cancel="showDatetime = false"
/>
@ -140,6 +141,7 @@
remark: '',
showDatetime: false,
appointTime: '',
minDate: new Date(),
address: '',
lat: '',
lng: '',