小程序优化

This commit is contained in:
qsh
2023-08-29 10:34:48 +08:00
parent 15622a2e5a
commit dd53612b39
8 changed files with 188 additions and 169 deletions

View File

@@ -19,11 +19,12 @@ export default {
placeSearch: null,
currentPoint: undefined,
marker: null,
searchBody: undefined
}
searchBody: undefined,
geocoder: null
};
},
beforeDestroy() {
console.log("mapdialog----beforeDestroy")
console.log('mapdialog----beforeDestroy');
this.marker = null;
this.placeSearch = null;
@@ -31,23 +32,23 @@ export default {
this.dialogMap = null;
},
mounted() {
console.log("mounted")
this.initData()
console.log('mounted');
this.initData();
},
created() {
console.log("created")
console.log('created');
},
methods: {
initData(point = undefined) {
console.log(point)
this.visible = true
console.log(point);
this.visible = true;
// this.searchBody = undefined
this.$nextTick(() => {
this.resetData();
if (point) {
this.currentPoint = point;
}
this.initMap()
this.initMap();
});
},
resetData() {
@@ -55,10 +56,10 @@ export default {
this.dialogMap && this.marker && this.dialogMap.remove(this.marker);
this.marker = null;
// this.placeSearch = null;
this.searchBody = null
this.searchBody = null;
},
initMap() {
console.log("初始化地图")
console.log('初始化地图');
if (!this.dialogMap) {
this.dialogMap = new AMap.Map('dialogMap', {
zoom: 12,
@@ -78,20 +79,19 @@ export default {
});
this.dialogMap.addControl(new AMap.Scale());
const auto = new AMap.Autocomplete({
input: 'search', // 前端搜索框
})
input: 'search' // 前端搜索框
});
this.placeSearch = new AMap.PlaceSearch({
map: this.dialogMap,
pageSize: 10, // 单页显示结果条数
pageIndex: 1, // 页码
autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
})
AMap.event.addListener(auto, 'select', this.select)
autoFitView: true // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
});
AMap.event.addListener(auto, 'select', this.select);
this.geocoder = new AMap.Geocoder();
}
this.initMapCenter();
},
// 初始化编辑地图的中心点
initMapCenter() {
@@ -127,7 +127,7 @@ export default {
}
});
},
//定位地址
// 定位地址
regeoCode() {
this.geocoder.getAddress(
[this.currentPoint.lng, this.currentPoint.lat],
@@ -141,11 +141,10 @@ export default {
},
handleMapSave() {
if (this.currentPoint.lat && this.currentPoint.lng) {
//通知父组件
this.$emit("handleMapDialogPoint", this.currentPoint);
// 通知父组件
this.$emit('handleMapDialogPoint', this.currentPoint);
this.visible = false;
this.$emit('update:mapDialogVisible', false);
} else {
this.$message.error('请在地图上选择位置后保存!');
}
@@ -153,8 +152,8 @@ export default {
closeDialog() {
this.$emit('update:mapDialogVisible', false);
}
},
}
}
};
</script>
<style scoped>
@@ -162,10 +161,11 @@ export default {
width: 100%;
height: 400px;
}
.search-body {
position: absolute;
top: 90px;
left: 25px;
width: 350px;
}
</style>
</style>