lxf 2 дней назад
Родитель
Сommit
19539fdd5a

+ 17 - 7
src/views/old_mini/growth_report/components/CropAlertPanel.vue

@@ -228,6 +228,14 @@ const syncCropNameDisplay = () => {
     currentCropName.value = resolveCropNameDisplay();
 };
 
+/** 无农场:切换列表仅展示当前作物(与头部 crop-name 一致) */
+const syncNoFarmCropOptions = () => {
+    if (resolveFarmId()) return;
+    const name = currentCropName.value || pointCropName.value || props.cropName || "";
+    cropOptions.value = name ? [name] : [];
+    activeIndex.value = 0;
+};
+
 watch(
     () => props.cropName,
     () => {
@@ -316,8 +324,8 @@ let resizeObserver = null;
 let syncing = false;
 
 const emitPanelHeight = (panelH = height.value) => {
-    // 对外抛出「距视口底」的占用高度,方便邀请按钮等避让
-    emit("heightChange", panelH + tabBarHeight.value);
+    // 对外抛出面板自身高度(叠在地图上的部分),父页据此把地图中心定在面板以上区域
+    emit("heightChange", panelH);
 };
 
 const syncMidAnchor = () => {
@@ -439,8 +447,8 @@ const fetchZones = async (token = reloadToken) => {
     const farmId = resolveFarmId();
     if (farmId == null || farmId === "") {
         zoneList.value = [];
-        cropOptions.value = [];
         applySelectedZone(-1);
+        syncNoFarmCropOptions();
         return;
     }
     try {
@@ -573,6 +581,7 @@ const fetchAlertCards = async (token = reloadToken, options = {}) => {
             applyWeatherStress(null);
             pointCropName.value = "";
             syncCropNameDisplay();
+            syncNoFarmCropOptions();
             nextTick(() => syncMidAnchor());
             return;
         }
@@ -604,10 +613,11 @@ const fetchAlertCards = async (token = reloadToken, options = {}) => {
     applyWeatherRisk(riskRecord);
     applyWeatherStress(stressRecord);
 
-    // 无农场:作物名取任一接口返回的 crop_name
+    // 无农场:作物名取任一接口返回的 crop_name;切换列表同步为该作物
     if (!hasFarm) {
         pointCropName.value = riskRecord?.crop_name || stressRecord?.crop_name || "";
         syncCropNameDisplay();
+        syncNoFarmCropOptions();
     }
 
     nextTick(() => syncMidAnchor());
@@ -927,9 +937,9 @@ defineExpose({ refreshAlerts: fetchAlertCards, refreshZones: fetchZones, reloadF
             font-size: 16px;
             line-height: 24px;
             color: #fff;
-            overflow: hidden;
-            text-overflow: ellipsis;
-            white-space: nowrap;
+            // overflow: hidden;
+            // text-overflow: ellipsis;
+            // white-space: nowrap;
         }
 
         &__metric {

+ 47 - 8
src/views/old_mini/growth_report/growthReportMap.js

@@ -17,6 +17,8 @@ export let mapLocation = reactive({
 
 /** 无范围时中心示意方框边长(米) */
 const NO_RANGE_SIDE_METERS = 280;
+/** 可视区中心相对几何中心下移(px),点位略靠下更好看 */
+const VISIBLE_CENTER_OFFSET_Y = 28;
 
 /**
  * @description 地图层对象
@@ -27,6 +29,8 @@ class IndexMap {
     let vectorStyle = new KMap.VectorStyle();
     this.vectorStyle = vectorStyle;
     this.noRangeTipOverlay = null;
+    /** 底部浮层面板叠在地图上的高度(px),用于可视区中心偏移 */
+    this._bottomOverlayHeight = 0;
 
     // 位置图标
     this.clickPointLayer = new KMap.VectorLayer("clickPointLayer", 9999, {
@@ -62,17 +66,51 @@ class IndexMap {
     this.kmap.addXYZLayer(xyz2, { minZoom: 8, maxZoom: 22 }, 2);
     this.kmap.addLayer(this.noRangeGuideLayer.layer);
     this.kmap.addLayer(this.clickPointLayer.layer);
-    this.setMapPoint(coordinate)
+    // 初始按面板上方可视区定中心,避免被底部面板挡住
+    this.setMapPosition(coordinate);
     // this.addMapSingerClick()
   }
 
+  /** 底部面板叠在地图上的高度(px),中心点按「面板以上」区域计算 */
+  setBottomOverlayHeight(height) {
+    const next = Math.max(0, Number(height) || 0);
+    if (next === this._bottomOverlayHeight) return;
+    this._bottomOverlayHeight = next;
+  }
+
+  /**
+   * 将坐标放到「地图高度 - 底部面板」可视区的几何中心,不改 zoom
+   * OpenLayers: view.centerOn(coord, size, pixel)
+   */
+  centerOnVisibleArea(coordinate, bottomOverlayHeight = this._bottomOverlayHeight) {
+    const map = this.kmap?.map;
+    if (!map || !coordinate?.length) return;
+    map.updateSize?.();
+    const size = map.getSize();
+    if (!size?.length) return;
+    const overlay = Math.max(0, Math.min(Number(bottomOverlayHeight) || 0, size[1] - 1));
+    const visibleH = size[1] - overlay;
+    // Y 增大点位更靠下;限制在可视区内,避免贴到面板
+    const y = Math.min(visibleH - 8, visibleH / 2 + VISIBLE_CENTER_OFFSET_Y);
+    const pixel = [size[0] / 2, Math.max(8, y)];
+    const center = [Number(coordinate[0]), Number(coordinate[1])];
+    map.getView().centerOn(center, size, pixel);
+  }
+
   setMapPosition(center) {
-    this.kmap.getView().animate({
-      center,
-      zoom: 16,
-      duration: 0,
-    });
-    this.setMapPoint(center)
+    if (!this.kmap || !center?.length) return;
+    this.kmap.getView().setZoom(16);
+    this.centerOnVisibleArea(center);
+    this.setMapPoint(center);
+  }
+
+  /** 仅按当前面板高度重算可视中心(拖拽面板时用,保留缩放与标记点) */
+  syncVisibleCenter(coordinate) {
+    const coord =
+      coordinate ||
+      this.getCurrentCoordinate();
+    if (!coord?.length) return;
+    this.centerOnVisibleArea(coord);
   }
 
   setMapPoint(coordinate) {
@@ -215,9 +253,10 @@ class IndexMap {
     const extent = this.kmap.polygonLayer.source.getExtent();
     if (!extent || !isFinite(extent[0])) return;
 
+    const bottom = Math.max(48, this._bottomOverlayHeight || 0);
     map.getView().fit(extent, {
       duration: options.duration ?? 0,
-      padding: options.padding ?? [120, 48, 48, 48],
+      padding: options.padding ?? [120, 48, bottom, 48],
       maxZoom: options.maxZoom ?? 18,
     });
   }

+ 15 - 1
src/views/old_mini/growth_report/index.vue

@@ -82,7 +82,7 @@
 
 
         <crop-alert-panel :crop-name="currentCropName" :farm-id="selectedFarmId" :county-code="countyCode"
-            @zone-change="handleZoneChange" />
+            @zone-change="handleZoneChange" @height-change="handlePanelHeightChange" />
     </div>
 
     <!-- 恢复种植弹窗 -->
@@ -129,6 +129,8 @@ const selectedFarmId = ref(localStorage.getItem("selectedFarmId") || "");
 const countyCode = ref(localStorage.getItem(COUNTY_CODE_STORAGE_KEY) || "");
 /** CropAlertPanel 当前选中分区 */
 const panelZoneId = ref(null);
+/** 面板叠在地图上的高度,中心点按「面板以上」可视区计算 */
+const panelOverlayHeight = ref(280);
 const currentCropName = computed(() => {
     // 依赖 selectedFarmId,切换农场后重新读缓存
     void selectedFarmId.value;
@@ -509,6 +511,17 @@ const handleZoneChange = (zoneId) => {
     fetchInteractTask();
 };
 
+/** 面板高度变化:地图中心改到「面板以上」区域的几何中心 */
+const handlePanelHeightChange = (panelHeight) => {
+    const next = Math.max(0, Number(panelHeight) || 0);
+    panelOverlayHeight.value = next;
+    growthReportMap.setBottomOverlayHeight(next);
+    if (!growthReportMap.kmap) return;
+    growthReportMap.syncVisibleCenter(
+        convertPointToArray(currentMapPoint.value)?.map(Number)
+    );
+};
+
 async function getLocationName(point = currentMapPoint.value) {
     // 已选农场且带 county_address:直接使用,不再请求逆地理
     const farm = getSelectedFarm();
@@ -568,6 +581,7 @@ function saveCurrentMapPoint(point) {
 const initMap = async () => {
     await nextTick();
     if (!mapContainer.value) return;
+    growthReportMap.setBottomOverlayHeight(panelOverlayHeight.value);
     if (growthReportMap.kmap) {
         growthReportMap.kmap.map?.updateSize?.();
         const coordinate = convertPointToArray(currentMapPoint.value)?.map(Number);