优化代码

This commit is contained in:
小小 2025-04-15 14:55:48 +08:00
parent 2ec2dfb5b8
commit eb69eb582d

View File

@ -234,7 +234,7 @@
// //
onMounted(() => { onMounted(() => {
mapContext = map.getMap("mapRef", getCurrentInstance()); mapContext = map.getMap("mapRef", getCurrentInstance());
getZone(() => { getZone((arrData) => {
// //
map.getLoalcation(mapContext, (res) => { map.getLoalcation(mapContext, (res) => {
const { const {
@ -265,8 +265,9 @@
city: "当前定位" + city, city: "当前定位" + city,
country: [data] country: [data]
} }
const arrData=arrAreaData.value||[]; arrData = arrData || [];
arrAreaData.value=arrData.splice(0, 0, locationPoint); arrData.splice(0, 0, locationPoint);
arrAreaData.value = arrData;
changeArea(data); changeArea(data);
}, (res) => { }, (res) => {
showModelMessage("切换区域失败!"); showModelMessage("切换区域失败!");
@ -277,15 +278,19 @@
}); });
// //
const getZone = (callback) => { function getZone(callback) {
api.callOperateApi("ebikeRegion/getZone", null, "get").then((res) => { api.callOperateApi("ebikeRegion/getZone", null, "get").then((res) => {
const arrData = [];
const { const {
code, code,
data, data,
message message
} = res; } = res;
if (code == 200) { if (code != 200) {
const arrData = []; showModelMessage(message);
if(callback) callback(arrData);
return;
}
if (data && data.length > 0) { if (data && data.length > 0) {
data.map(item => { data.map(item => {
const { const {
@ -320,17 +325,12 @@
if (locationPoint) { if (locationPoint) {
arrData.splice(0, 0, locationPoint); arrData.splice(0, 0, locationPoint);
} }
arrAreaData.value = arrData; if(callback) callback(arrData);
} else {
showModelMessage(message);
}
callback();
}); });
} }
// //
const getLocation = () => { function getLocation() {
map.getLoalcation(mapContext, (res) => { map.getLoalcation(mapContext, (res) => {
const { const {
latitude, latitude,
@ -341,18 +341,18 @@
} }
// //
const onShowDrawer = () => { function onShowDrawer() {
showArea.value.open(); showArea.value.open();
} }
// //
const clickArea = (data) => { function clickArea(data) {
changeArea(data); changeArea(data);
showArea.value.close(); showArea.value.close();
} }
const changeArea = (data, refresh) => { function changeArea(data, refresh) {
const { const {
id, id,
lng, lng,
@ -472,13 +472,13 @@
} }
// //
const loadMapData = (data) => { function loadMapData(data) {
loadMapBikeData(showBike.value, data); loadMapBikeData(showBike.value, data);
loadMapRegionData(showRegion.value, data); loadMapRegionData(showRegion.value, data);
} }
// //
const showBikeData = () => { function showBikeData() {
const show = !showBike.value const show = !showBike.value
showBike.value = show; showBike.value = show;
const { const {
@ -491,7 +491,7 @@
loadMapBikeData(show, data); loadMapBikeData(show, data);
}; };
const loadMapBikeData = (show, data) => { function loadMapBikeData(show, data) {
const { const {
bikeData bikeData
} = data; } = data;
@ -509,7 +509,7 @@
} }
// //
const showRegionData = () => { function showRegionData() {
const show = !showRegion.value; const show = !showRegion.value;
showRegion.value = show; showRegion.value = show;
const { const {
@ -522,7 +522,7 @@
loadMapRegionData(show, data); loadMapRegionData(show, data);
} }
const loadMapRegionData = (show, data) => { function loadMapRegionData(show, data) {
const { const {
arrCircles, arrCircles,
arrPolygons, arrPolygons,
@ -540,13 +540,13 @@
}; };
// //
const refreshArea = () => { function refreshArea() {
changeArea(selArea, true); changeArea(selArea, true);
} }
// //
const onZoom = (lx) => { function onZoom(lx) {
switch (lx) { switch (lx) {
case "out": case "out":
scale.value = scale.value + 1; scale.value = scale.value + 1;
@ -558,7 +558,7 @@
} }
// //
const quantityChange = (e) => { function quantityChange(e) {
const { const {
detail: { detail: {
value value
@ -576,12 +576,12 @@
} }
// //
const changeBatteries = () => { function changeBatteries() {
showModelMessage("该功能暂未实现!"); showModelMessage("该功能暂未实现!");
} }
// //
const queryOrders = (lx) => { function queryOrders(lx) {
showModelMessage("该功能暂未实现!"); showModelMessage("该功能暂未实现!");
} }
</script> </script>