|
@@ -84,12 +84,14 @@
|
|
|
@switchGrowing="handleSwitchGrowing"
|
|
@switchGrowing="handleSwitchGrowing"
|
|
|
/>
|
|
/>
|
|
|
<editPlantPointPopup ref="editPlantPointPopupRef" @confirm="handlePlantPointConfirm" />
|
|
<editPlantPointPopup ref="editPlantPointPopupRef" @confirm="handlePlantPointConfirm" />
|
|
|
|
|
+ <!-- 暂无农场时不弹「完善农场信息」,逻辑保留备用
|
|
|
<complete-farm-info-popup
|
|
<complete-farm-info-popup
|
|
|
v-model:show="showCompleteFarmPopup"
|
|
v-model:show="showCompleteFarmPopup"
|
|
|
:image="completeFarmPopupImage"
|
|
:image="completeFarmPopupImage"
|
|
|
highlight-text="种植全析报告"
|
|
highlight-text="种植全析报告"
|
|
|
@confirm="goCompleteFarmInfo"
|
|
@confirm="goCompleteFarmInfo"
|
|
|
/>
|
|
/>
|
|
|
|
|
+ -->
|
|
|
<restore-planting-popup />
|
|
<restore-planting-popup />
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
@@ -97,32 +99,36 @@
|
|
|
<script setup>
|
|
<script setup>
|
|
|
import { computed, onActivated, onDeactivated, onBeforeUnmount, ref } from "vue";
|
|
import { computed, onActivated, onDeactivated, onBeforeUnmount, ref } from "vue";
|
|
|
import { useRouter } from "vue-router";
|
|
import { useRouter } from "vue-router";
|
|
|
-import { useStore } from "vuex";
|
|
|
|
|
|
|
+// import { useStore } from "vuex";
|
|
|
import { ElMessage } from "element-plus";
|
|
import { ElMessage } from "element-plus";
|
|
|
import { Plus, Edit } from "@element-plus/icons-vue";
|
|
import { Plus, Edit } from "@element-plus/icons-vue";
|
|
|
import adjustPhenologyPopup from "../components/adjustPhenologyPopup.vue";
|
|
import adjustPhenologyPopup from "../components/adjustPhenologyPopup.vue";
|
|
|
import restingDatePopup from "../components/restingDatePopup.vue";
|
|
import restingDatePopup from "../components/restingDatePopup.vue";
|
|
|
import editPlantPointPopup from "../components/editPlantPointPopup.vue";
|
|
import editPlantPointPopup from "../components/editPlantPointPopup.vue";
|
|
|
-import completeFarmInfoPopup from "@/components/popup/completeFarmInfoPopup.vue";
|
|
|
|
|
|
|
+// import completeFarmInfoPopup from "@/components/popup/completeFarmInfoPopup.vue";
|
|
|
import tab1Icon from "@/assets/img/report/tab-1.png";
|
|
import tab1Icon from "@/assets/img/report/tab-1.png";
|
|
|
import tab2Icon from "@/assets/img/report/tab-2.png";
|
|
import tab2Icon from "@/assets/img/report/tab-2.png";
|
|
|
import tab3Icon from "@/assets/img/report/tab-3.png";
|
|
import tab3Icon from "@/assets/img/report/tab-3.png";
|
|
|
import tab4Icon from "@/assets/img/report/tab-4.png";
|
|
import tab4Icon from "@/assets/img/report/tab-4.png";
|
|
|
import tab5Icon from "@/assets/img/report/tab-5.png";
|
|
import tab5Icon from "@/assets/img/report/tab-5.png";
|
|
|
-import completeFarmPopupImage from "@/assets/img/common/empty-bg-3.png";
|
|
|
|
|
|
|
+// import completeFarmPopupImage from "@/assets/img/common/empty-bg-3.png";
|
|
|
import restorePlantingPopup from "@/components/popup/restorePlantingPopup.vue";
|
|
import restorePlantingPopup from "@/components/popup/restorePlantingPopup.vue";
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
// Props / Emits — 无
|
|
// Props / Emits — 无
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
-const store = useStore();
|
|
|
|
|
|
|
+// const store = useStore();
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
// 常量
|
|
// 常量
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
/** 报告未生成时轮询间隔(ms) */
|
|
/** 报告未生成时轮询间隔(ms) */
|
|
|
-const REPORT_POLL_INTERVAL = 3000;
|
|
|
|
|
|
|
+const REPORT_POLL_INTERVAL = 6000;
|
|
|
|
|
+/** 无农场时默认作物编码:水稻 */
|
|
|
|
|
+const NO_FARM_CROP = "PAD";
|
|
|
|
|
+/** 无定位时的默认点位(与录入页一致) */
|
|
|
|
|
+const DEFAULT_POINT = "POINT(113.6142086995688 23.585836479509055)";
|
|
|
|
|
|
|
|
/** module1_basic 字段标签 → 基本信息展示项(labels 含接口原文别名) */
|
|
/** module1_basic 字段标签 → 基本信息展示项(labels 含接口原文别名) */
|
|
|
const BASE_FIELD_META = [
|
|
const BASE_FIELD_META = [
|
|
@@ -166,16 +172,17 @@ const activeReportTab = ref("weather");
|
|
|
const adjustPhenologyPopupRef = ref(null);
|
|
const adjustPhenologyPopupRef = ref(null);
|
|
|
const restingDatePopupRef = ref(null);
|
|
const restingDatePopupRef = ref(null);
|
|
|
const editPlantPointPopupRef = ref(null);
|
|
const editPlantPointPopupRef = ref(null);
|
|
|
-const showCompleteFarmPopup = ref(false); // 无农场时展示「完善农场信息」
|
|
|
|
|
|
|
+// const showCompleteFarmPopup = ref(false); // 无农场时展示「完善农场信息」
|
|
|
let pollTimer = null;
|
|
let pollTimer = null;
|
|
|
|
|
+/** 当前轮询方式:farm | latlon */
|
|
|
|
|
+let pollMode = null;
|
|
|
|
|
+let pollParams = null;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
// 计算属性
|
|
// 计算属性
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
const pageLoading = computed(() => loading.value || reportGenerating.value);
|
|
const pageLoading = computed(() => loading.value || reportGenerating.value);
|
|
|
-const loadingText = computed(() =>
|
|
|
|
|
- reportGenerating.value ? "报告正在生成中..." : "加载中..."
|
|
|
|
|
-);
|
|
|
|
|
|
|
+const loadingText = "报告生成中,请稍后...";
|
|
|
|
|
|
|
|
const activeReportTabMeta = computed(
|
|
const activeReportTabMeta = computed(
|
|
|
() => reportTabs.find((tab) => tab.key === activeReportTab.value) || reportTabs[0]
|
|
() => reportTabs.find((tab) => tab.key === activeReportTab.value) || reportTabs[0]
|
|
@@ -190,9 +197,9 @@ const activeReportHtml = computed(() => {
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
// 工具函数
|
|
// 工具函数
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
-function getMiniUserId() {
|
|
|
|
|
- return store.state.home.miniUserId || localStorage.getItem("MINI_USER_ID");
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// function getMiniUserId() {
|
|
|
|
|
+// return store.state.home.miniUserId || localStorage.getItem("MINI_USER_ID");
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
function getSelectedFarm() {
|
|
function getSelectedFarm() {
|
|
|
try {
|
|
try {
|
|
@@ -202,6 +209,24 @@ function getSelectedFarm() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function hasFarmZone(farm = {}) {
|
|
|
|
|
+ const farmId = farm.farm_id ?? farm.id;
|
|
|
|
|
+ const zoneId = farm.zone_id ?? farm.zoneId;
|
|
|
|
|
+ return farmId != null && farmId !== "" && zoneId != null && zoneId !== "";
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** 无农场报告用点位:优先用户定位 */
|
|
|
|
|
+function getPointText() {
|
|
|
|
|
+ return localStorage.getItem("MINI_USER_LOCATION_POINT") || DEFAULT_POINT;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** report6_latlon:有 records[0] 即视为报告已生成 */
|
|
|
|
|
+function pickLatlonReport(res) {
|
|
|
|
|
+ const records = res?.data?.records;
|
|
|
|
|
+ if (Array.isArray(records) && records.length) return records[0];
|
|
|
|
|
+ return null;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/** 解析 module1_basic:兼容 `**标签**:` 与纯文本 `标签:`(内容可跨行) */
|
|
/** 解析 module1_basic:兼容 `**标签**:` 与纯文本 `标签:`(内容可跨行) */
|
|
|
function parseBasicSections(markdown = "") {
|
|
function parseBasicSections(markdown = "") {
|
|
|
const text = String(markdown).replace(/\r\n/g, "\n").trim();
|
|
const text = String(markdown).replace(/\r\n/g, "\n").trim();
|
|
@@ -353,39 +378,47 @@ function resetReportView(farm = {}) {
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
// 业务逻辑:无农场弹窗 / 加载报告
|
|
// 业务逻辑:无农场弹窗 / 加载报告
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
-/** 无果园信息时展示「完善农场信息」弹窗 */
|
|
|
|
|
-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("[diagnosisReport] getFarms failed", e);
|
|
|
|
|
- showCompleteFarmPopup.value = false;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+/** 无果园信息时展示「完善农场信息」弹窗(暂不启用) */
|
|
|
|
|
+// 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("[diagnosisReport] getFarms failed", e);
|
|
|
|
|
+// showCompleteFarmPopup.value = false;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
function stopReportPolling() {
|
|
function stopReportPolling() {
|
|
|
if (pollTimer) {
|
|
if (pollTimer) {
|
|
|
clearInterval(pollTimer);
|
|
clearInterval(pollTimer);
|
|
|
pollTimer = null;
|
|
pollTimer = null;
|
|
|
}
|
|
}
|
|
|
|
|
+ pollMode = null;
|
|
|
|
|
+ pollParams = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/** 报告未就绪时保持 loading,并定时重试 check */
|
|
|
|
|
-function startReportPolling(farmId, zoneId) {
|
|
|
|
|
|
|
+/** 报告未就绪时保持 loading,并定时重试 */
|
|
|
|
|
+function startReportPolling(mode, params) {
|
|
|
stopReportPolling();
|
|
stopReportPolling();
|
|
|
|
|
+ pollMode = mode;
|
|
|
|
|
+ pollParams = params;
|
|
|
pollTimer = setInterval(() => {
|
|
pollTimer = setInterval(() => {
|
|
|
- pollDiagnosisReport(farmId, zoneId);
|
|
|
|
|
|
|
+ if (pollMode === "farm") {
|
|
|
|
|
+ pollFarmReport(pollParams);
|
|
|
|
|
+ } else if (pollMode === "latlon") {
|
|
|
|
|
+ pollLatlonReport(pollParams);
|
|
|
|
|
+ }
|
|
|
}, REPORT_POLL_INTERVAL);
|
|
}, REPORT_POLL_INTERVAL);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function pollDiagnosisReport(farmId, zoneId) {
|
|
|
|
|
|
|
+async function pollFarmReport({ farmId, zoneId }) {
|
|
|
try {
|
|
try {
|
|
|
const raw = await VE_API.questionnaire.checkReportGenerated({
|
|
const raw = await VE_API.questionnaire.checkReportGenerated({
|
|
|
farm_id: farmId,
|
|
farm_id: farmId,
|
|
@@ -399,22 +432,62 @@ async function pollDiagnosisReport(farmId, zoneId) {
|
|
|
applyReportData(report, getSelectedFarm());
|
|
applyReportData(report, getSelectedFarm());
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- console.warn("[diagnosisReport] poll failed", error);
|
|
|
|
|
|
|
+ console.warn("[diagnosisReport] farm poll failed", error);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function fetchDiagnosisReport() {
|
|
|
|
|
- const farm = getSelectedFarm();
|
|
|
|
|
- const farmId = farm.farm_id ?? farm.id;
|
|
|
|
|
- const zoneId = farm.zone_id ?? farm.zoneId;
|
|
|
|
|
- stopReportPolling();
|
|
|
|
|
- reportGenerating.value = false;
|
|
|
|
|
|
|
+async function pollLatlonReport({ pointText, crop }) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const raw = await VE_API.report.report6Latlon({
|
|
|
|
|
+ point_text: pointText,
|
|
|
|
|
+ crop,
|
|
|
|
|
+ });
|
|
|
|
|
+ const res = Array.isArray(raw) ? raw[0] : raw;
|
|
|
|
|
+ const report = pickLatlonReport(res);
|
|
|
|
|
+ if (res?.code === 200 && report) {
|
|
|
|
|
+ stopReportPolling();
|
|
|
|
|
+ reportGenerating.value = false;
|
|
|
|
|
+ applyReportData(report, {});
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.warn("[diagnosisReport] latlon poll failed", error);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- if (farmId == null || farmId === "" || zoneId == null || zoneId === "") {
|
|
|
|
|
- resetReportView(farm);
|
|
|
|
|
- // ElMessage.warning("请先选择农场与分区");
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+/** 无农场:按定位点 + 水稻拉取 / 轮询六模块报告 */
|
|
|
|
|
+async function fetchLatlonReport() {
|
|
|
|
|
+ const pointText = getPointText();
|
|
|
|
|
+ const crop = NO_FARM_CROP;
|
|
|
|
|
+ const params = { pointText, crop };
|
|
|
|
|
+
|
|
|
|
|
+ loading.value = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const raw = await VE_API.report.report6Latlon({
|
|
|
|
|
+ point_text: pointText,
|
|
|
|
|
+ crop,
|
|
|
|
|
+ });
|
|
|
|
|
+ const res = Array.isArray(raw) ? raw[0] : raw;
|
|
|
|
|
+ const report = pickLatlonReport(res);
|
|
|
|
|
+ if (res?.code === 200 && report) {
|
|
|
|
|
+ applyReportData(report, {});
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ resetReportView({});
|
|
|
|
|
+ reportGenerating.value = true;
|
|
|
|
|
+ startReportPolling("latlon", params);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error("fetchLatlonReport failed", error);
|
|
|
|
|
+ resetReportView({});
|
|
|
|
|
+ reportGenerating.value = false;
|
|
|
|
|
+ ElMessage.error("报告加载失败");
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ loading.value = false;
|
|
|
}
|
|
}
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function fetchFarmReport(farm) {
|
|
|
|
|
+ const farmId = farm.farm_id ?? farm.id;
|
|
|
|
|
+ const zoneId = farm.zone_id ?? farm.zoneId;
|
|
|
|
|
|
|
|
loading.value = true;
|
|
loading.value = true;
|
|
|
try {
|
|
try {
|
|
@@ -428,12 +501,11 @@ async function fetchDiagnosisReport() {
|
|
|
applyReportData(report, farm);
|
|
applyReportData(report, farm);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- // 报告尚未生成:保持页面 loading,并轮询直到有数据
|
|
|
|
|
resetReportView(farm);
|
|
resetReportView(farm);
|
|
|
reportGenerating.value = true;
|
|
reportGenerating.value = true;
|
|
|
- startReportPolling(farmId, zoneId);
|
|
|
|
|
|
|
+ startReportPolling("farm", { farmId, zoneId });
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- console.error("fetchDiagnosisReport failed", error);
|
|
|
|
|
|
|
+ console.error("fetchFarmReport failed", error);
|
|
|
resetReportView(farm);
|
|
resetReportView(farm);
|
|
|
reportGenerating.value = false;
|
|
reportGenerating.value = false;
|
|
|
ElMessage.error("报告加载失败");
|
|
ElMessage.error("报告加载失败");
|
|
@@ -442,6 +514,18 @@ async function fetchDiagnosisReport() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function fetchDiagnosisReport() {
|
|
|
|
|
+ const farm = getSelectedFarm();
|
|
|
|
|
+ stopReportPolling();
|
|
|
|
|
+ reportGenerating.value = false;
|
|
|
|
|
+
|
|
|
|
|
+ if (!hasFarmZone(farm)) {
|
|
|
|
|
+ await fetchLatlonReport();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ await fetchFarmReport(farm);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
// 事件处理 / 生命周期
|
|
// 事件处理 / 生命周期
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
@@ -477,13 +561,13 @@ const handlePlantPointConfirm = (payload) => {
|
|
|
console.log("plant point confirm:", payload);
|
|
console.log("plant point confirm:", payload);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const goCompleteFarmInfo = () => {
|
|
|
|
|
- router.push("/entry_information");
|
|
|
|
|
-};
|
|
|
|
|
|
|
+// const goCompleteFarmInfo = () => {
|
|
|
|
|
+// router.push("/entry_information");
|
|
|
|
|
+// };
|
|
|
|
|
|
|
|
// tabbar 切换时组件被 keep-alive 缓存,需在激活时重新拉报告 / 校验农场
|
|
// tabbar 切换时组件被 keep-alive 缓存,需在激活时重新拉报告 / 校验农场
|
|
|
onActivated(() => {
|
|
onActivated(() => {
|
|
|
- checkCompleteFarmPopup();
|
|
|
|
|
|
|
+ // checkCompleteFarmPopup(); // 暂无农场时不弹「完善农场信息」
|
|
|
fetchDiagnosisReport();
|
|
fetchDiagnosisReport();
|
|
|
});
|
|
});
|
|
|
|
|
|