|
|
@@ -185,6 +185,7 @@ import proxyAuthPopup from "@/components/popup/proxyAuthPopup.vue";
|
|
|
import phenologyUpdatePopup from "@/components/popup/phenologyUpdatePopup.vue";
|
|
|
import PhenologyTrackTimelineItem from "@/components/pageComponents/PhenologyTrackTimelineItem.vue";
|
|
|
import wx from "weixin-js-sdk";
|
|
|
+import { base_img_url2 } from "@/api/config";
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
const store = useStore();
|
|
|
@@ -223,12 +224,7 @@ const navCards = [
|
|
|
},
|
|
|
];
|
|
|
|
|
|
-const zoneList = ref([
|
|
|
- { id: 1, name: "", count: 2, cover: defaultCover, longitude: 113.612409, latitude: 23.587036 },
|
|
|
- { id: 2, name: "", count: 2, cover: defaultCover, longitude: 113.615809, latitude: 23.586636 },
|
|
|
- { id: 3, name: "", count: 2, cover: defaultCover, longitude: 113.613609, latitude: 23.584436 },
|
|
|
- { id: 4, name: "", count: 2, cover: defaultCover, longitude: 113.615609, latitude: 23.585036 },
|
|
|
-]);
|
|
|
+const zoneList = ref([]);
|
|
|
|
|
|
const albumList = ref([
|
|
|
{ id: 1, name: "", count: 0, cover: "" },
|
|
|
@@ -245,6 +241,27 @@ const reportList = ref([
|
|
|
|
|
|
const showUploadPopup = ref(false);
|
|
|
const showCompleteFarmPopup = ref(false);
|
|
|
+
|
|
|
+function getMiniUserId() {
|
|
|
+ return store.state.home.miniUserId || localStorage.getItem("MINI_USER_ID");
|
|
|
+}
|
|
|
+
|
|
|
+/** 无果园信息时展示「完善农场信息」弹窗 */
|
|
|
+async function checkCompleteFarmPopup() {
|
|
|
+ const id = getMiniUserId();
|
|
|
+ if (!id) {
|
|
|
+ showCompleteFarmPopup.value = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const res = await VE_API.questionnaire.getFarms({ id });
|
|
|
+ const list = Array.isArray(res?.data) ? res.data : [];
|
|
|
+ showCompleteFarmPopup.value = list.length === 0;
|
|
|
+ } catch (e) {
|
|
|
+ console.warn("[agri_file] getFarms failed", e);
|
|
|
+ showCompleteFarmPopup.value = false;
|
|
|
+ }
|
|
|
+}
|
|
|
// 后续由接口控制是否展示代管授权弹窗
|
|
|
const showProxyAuthPopup = ref(false);
|
|
|
const proxyServiceName = ref("农服名称");
|
|
|
@@ -349,6 +366,71 @@ const setMarkerEl = (id, el) => {
|
|
|
else delete markerEls[id];
|
|
|
};
|
|
|
|
|
|
+function getSelectedFarmId() {
|
|
|
+ const stored = localStorage.getItem("selectedFarmId");
|
|
|
+ if (stored != null && stored !== "") {
|
|
|
+ return Number(stored);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const farm = JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
|
|
|
+ const id = farm.farm_id ?? farm.id;
|
|
|
+ return id != null && id !== "" ? Number(id) : null;
|
|
|
+ } catch {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function parsePointCoordinates(pointWkt) {
|
|
|
+ if (!pointWkt || !/^POINT\s*\(/i.test(String(pointWkt).trim())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const coord = util.wktCastGeom(pointWkt).getFirstCoordinate();
|
|
|
+ if (!coord || coord.length < 2) return null;
|
|
|
+ return { longitude: coord[0], latitude: coord[1] };
|
|
|
+ } catch {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function resolveZoneCoverUrl(path) {
|
|
|
+ if (!path) return defaultCover;
|
|
|
+ const text = String(path).trim();
|
|
|
+ if (!text) return defaultCover;
|
|
|
+ if (/^https?:\/\//i.test(text)) return text;
|
|
|
+ return base_img_url2 + text.replace(/^\//, "");
|
|
|
+}
|
|
|
+
|
|
|
+function mapZoneItem(zone) {
|
|
|
+ const coords = parsePointCoordinates(zone?.point);
|
|
|
+ return {
|
|
|
+ id: zone.zone_id,
|
|
|
+ zoneId: zone.zone_id,
|
|
|
+ name: zone.zone_name || "",
|
|
|
+ count: zone.image_count ?? 0,
|
|
|
+ cover: resolveZoneCoverUrl(zone.cover_url),
|
|
|
+ longitude: coords?.longitude,
|
|
|
+ latitude: coords?.latitude,
|
|
|
+ point: zone.point,
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+async function fetchZoneList() {
|
|
|
+ const farmId = getSelectedFarmId();
|
|
|
+ if (!farmId) {
|
|
|
+ zoneList.value = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const res = await VE_API.questionnaire.getZones({ farm_id: farmId });
|
|
|
+ const zones = res?.data?.zones;
|
|
|
+ zoneList.value = Array.isArray(zones) ? zones.map(mapZoneItem) : [];
|
|
|
+ } catch (e) {
|
|
|
+ console.warn("[agri_file] getZones failed", e);
|
|
|
+ zoneList.value = [];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const getFarmCenter = () => {
|
|
|
try {
|
|
|
const farm = JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
|
|
|
@@ -359,6 +441,12 @@ const getFarmCenter = () => {
|
|
|
} catch {
|
|
|
// ignore
|
|
|
}
|
|
|
+ const firstZone = zoneList.value.find(
|
|
|
+ (z) => z.longitude != null && z.latitude != null
|
|
|
+ );
|
|
|
+ if (firstZone) {
|
|
|
+ return [firstZone.longitude, firstZone.latitude];
|
|
|
+ }
|
|
|
return DEFAULT_CENTER;
|
|
|
};
|
|
|
|
|
|
@@ -391,22 +479,21 @@ const bindZoneOverlays = () => {
|
|
|
const initAlbumMap = async () => {
|
|
|
await nextTick();
|
|
|
if (!mapContainer.value) return;
|
|
|
- const center = getFarmCenter();
|
|
|
- fileMap.initMap(`POINT(${center[0]} ${center[1]})`, mapContainer.value);
|
|
|
- await nextTick();
|
|
|
if (noFarmRange.value) {
|
|
|
zoneList.value = [];
|
|
|
albumList.value = [];
|
|
|
return;
|
|
|
}
|
|
|
+ await fetchZoneList();
|
|
|
+ const center = getFarmCenter();
|
|
|
+ fileMap.initMap(`POINT(${center[0]} ${center[1]})`, mapContainer.value);
|
|
|
+ await nextTick();
|
|
|
bindZoneOverlays();
|
|
|
fileMap.kmap?.map?.updateSize?.();
|
|
|
};
|
|
|
|
|
|
const fillMockLabels = () => {
|
|
|
- const zoneName = t("agriFile.zoneLabel", { n: 1 });
|
|
|
const albumName = t("agriFile.zoneOne");
|
|
|
- zoneList.value = zoneList.value.map((item) => ({ ...item, name: zoneName }));
|
|
|
albumList.value = albumList.value.map((item) => ({ ...item, name: albumName }));
|
|
|
reportList.value = reportList.value.map((item) => ({
|
|
|
...item,
|
|
|
@@ -556,6 +643,7 @@ const goAlbumDetail = (item) => {
|
|
|
|
|
|
onMounted(() => {
|
|
|
fillMockLabels();
|
|
|
+ checkCompleteFarmPopup();
|
|
|
fetchPatrolInteractTask();
|
|
|
initAlbumMap();
|
|
|
tryShowGuide();
|
|
|
@@ -563,6 +651,7 @@ onMounted(() => {
|
|
|
});
|
|
|
onActivated(() => {
|
|
|
fillMockLabels();
|
|
|
+ checkCompleteFarmPopup();
|
|
|
fetchPatrolInteractTask();
|
|
|
initAlbumMap();
|
|
|
tryShowGuide();
|