| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348 |
- <template>
- <div
- class="diagnosis-report-page"
- :class="{ 'is-from-share': isFromShare }"
- v-loading="loading"
- element-loading-background="rgba(15, 15, 15, 0.55)"
- >
- <custom-header
- v-if="isFromShare"
- name="种植全析"
- :showHome="true"
- :isGoBack="false"
- />
- <div class="page-content">
- <div v-if="reportGenerating" class="report-progress">
- <div class="report-progress__content">
- <div>
- <el-progress :percentage="progressPercent" :stroke-width="15" :duration="30" status="warning"
- striped striped-flow />
- </div>
- <div class="report-progress__desc">
- 依据您的定位和作物品类,
- <div>正在生成专属报告,预计耗时2分钟...</div>
- </div>
- </div>
- </div>
- <template v-else>
- <div class="diagnosis-header">
- <div class="header-share" @click="handleShare">
- <Icon name="share" color="rgba(255,255,255,0.85)" />
- <span>转发</span>
- </div>
- <div class="diagnosis-header__title-row">
- <div class="diagnosis-header__title">
- <div>一份报告</div>
- <div>看懂你的农场</div>
- </div>
- <!-- <img class="diagnosis-header__icon" src="@/assets/img/report/star.png" alt="" /> -->
- </div>
- <div class="diagnosis-header__desc">{{ headerDesc }}</div>
- <!-- <div class="diagnosis-header__base">{{ headerBase }}</div> -->
- </div>
- <div class="diagnosis-content">
- <div class="variety-bar">
- <div class="variety-bar__tags">
- <div
- v-for="item in zoneList"
- :key="item.zone_id"
- class="variety-bar__tag"
- :class="{ active: String(item.zone_id) === String(selectedZoneId) }"
- @click="handleSelectZone(item)"
- >
- {{ item.zone_name }}
- </div>
- </div>
- <div class="variety-bar__add" @click="goAddVariety">
- <el-icon>
- <Plus />
- </el-icon>
- <span>新增品种</span>
- </div>
- </div>
- <div class="base-data">
- <!-- <div class="base-data__title">
- <span class="title-dot"></span>
- <span>基本信息</span>
- </div> -->
- <div class="base-data__body">
- <div v-if="!loading && !baseInfoList.length" class="base-data__empty">暂无基本信息</div>
- <div v-for="item in baseInfoList" :key="item.key" class="base-info-item">
- <div class="base-info-item__row">
- <span class="base-info-item__label">{{ item.label }}</span>
- <span class="base-info-item__value">{{ item.value }}</span>
- <!-- <span v-if="item.actionInline" class="base-info-action"
- @click="handleBaseAction(item.actionInline.key)">
- {{ item.actionInline.text }}
- <el-icon><Edit /></el-icon>
- </span> -->
- </div>
- <!-- <div v-if="item.actionBlock" class="base-info-action base-info-action--block"
- @click="handleBaseAction(item.actionBlock.key)">
- {{ item.actionBlock.text }}
- <el-icon><Edit /></el-icon>
- </div> -->
- </div>
- </div>
- </div>
- <div class="report-module">
- <div class="report-tabs">
- <div v-for="tab in reportTabs" :key="tab.key" class="report-tabs__item"
- :class="{ active: tab.key === activeReportTab }" @click="activeReportTab = tab.key">
- {{ tab.label }}
- </div>
- </div>
- <div class="report-panel">
- <template v-if="activeModule">
- <div v-if="activeModule.lead" class="core-card">
- <div class="core-card__head">
- <img class="core-card__star" src="@/assets/img/home/start-icon.png" alt="" />
- <span>核心结论</span>
- </div>
- <div class="core-card__body">{{ activeModule.lead }}</div>
- </div>
- <div v-for="(block, bi) in activeModule.blocks" :key="`${block.no}-${bi}`"
- class="point-block" :class="`point-block--s${bi % 3}`">
- <div class="point-block__head">
- <span class="point-block__no">{{ block.no }}</span>
- <span class="point-block__title">{{ block.title }}</span>
- </div>
- <div v-if="block.sub?.length" class="point-block__card">
- <div v-for="(sub, si) in block.sub" :key="`${bi}-${si}`" class="point-sub">
- <!-- 样式 0:金色描边标签 -->
- <template v-if="bi % 3 === 0">
- <span class="point-sub__badge">{{ sub.title }}</span>
- <div class="point-sub__text">{{ sub.text }}</div>
- </template>
- <!-- 样式 1:纯白标题 -->
- <template v-else-if="bi % 3 === 1">
- <div class="point-sub__plain">{{ sub.title }}</div>
- <div class="point-sub__text">{{ sub.text }}</div>
- </template>
- <!-- 样式 2:图标 + 标题 -->
- <template v-else>
- <div class="point-sub__icon-row">
- <span class="point-sub__icon">
- <el-icon size="16">
- <List />
- </el-icon>
- </span>
- <span class="point-sub__icon-title">{{ sub.title }}</span>
- </div>
- <div class="point-sub__text">{{ sub.text }}</div>
- </template>
- </div>
- </div>
- </div>
- </template>
- <div v-else class="report-panel__empty">暂无报告内容</div>
- </div>
- </div>
- </div>
- </template>
- </div>
- <adjustPhenologyPopup ref="adjustPhenologyPopupRef" @confirm="handlePhenologyConfirm" />
- <restingDatePopup ref="restingDatePopupRef" @confirm="handleRestingDateConfirm"
- @switchGrowing="handleSwitchGrowing" />
- <editPlantPointPopup ref="editPlantPointPopupRef" @confirm="handlePlantPointConfirm" />
- <!-- 暂无农场时不弹「完善农场信息」,逻辑保留备用
- <complete-farm-info-popup
- v-model:show="showCompleteFarmPopup"
- :image="completeFarmPopupImage"
- highlight-text="种植全析报告"
- @confirm="goCompleteFarmInfo"
- />
- -->
- <restore-planting-popup />
- </div>
- </template>
- <script setup>
- import { computed, onActivated, onDeactivated, onBeforeUnmount, ref } from "vue";
- import { useRoute, useRouter } from "vue-router";
- import { Icon } from "vant";
- // import { useStore } from "vuex";
- import { ElMessage } from "element-plus";
- import { Plus, Edit, List } from "@element-plus/icons-vue";
- import adjustPhenologyPopup from "../components/adjustPhenologyPopup.vue";
- import restingDatePopup from "../components/restingDatePopup.vue";
- import editPlantPointPopup from "../components/editPlantPointPopup.vue";
- // import completeFarmInfoPopup from "@/components/popup/completeFarmInfoPopup.vue";
- // import completeFarmPopupImage from "@/assets/img/common/empty-bg-3.png";
- import restorePlantingPopup from "@/components/popup/restorePlantingPopup.vue";
- import customHeader from "@/components/customHeader.vue";
- import { ensureFarmContext } from "@/utils/selectedFarm";
- import wx from "weixin-js-sdk";
- // ---------------------------------------------------------------------------
- // Props / Emits — 无
- // ---------------------------------------------------------------------------
- const route = useRoute();
- const router = useRouter();
- // const store = useStore();
- // ---------------------------------------------------------------------------
- // 常量
- // ---------------------------------------------------------------------------
- /** 报告未生成时轮询间隔(ms) */
- const REPORT_POLL_INTERVAL = 6000;
- /** exists=0 时进度条走满的模拟时长 */
- const PROGRESS_DURATION_MS = 2 * 60 * 1000;
- /** 按农场记进度;切页回来从该农场上次百分比接着走 */
- const PROGRESS_STORAGE_KEY = "DIAGNOSIS_REPORT_PROGRESS";
- const PROGRESS_MIN = 10;
- const PROGRESS_CAP = 99;
- const PROGRESS_NO_FARM_KEY = "nofarm";
- /** 无农场时默认作物编码:水稻 */
- const NO_FARM_CROP = "PAD";
- /** 无定位时的默认点位(与录入页一致) */
- const DEFAULT_POINT = "POINT(113.6142086995688 23.585836479509055)";
- /** 报告分模块:tab 文案取自各 module JSON 的 tab 字段 */
- const MODULE_DEFS = [
- { key: "weather", field: "module2_weather", fallbackLabel: "关键物候风险" },
- { key: "pest", field: "module3_pest", fallbackLabel: "病虫害风险" },
- { key: "input", field: "module5_input", fallbackLabel: "建议必要投入" },
- { key: "quality", field: "module4_quality", fallbackLabel: "潜力品质分析" },
- ];
- /** rows.label → 基本信息展示 */
- const BASE_ROW_LABEL_MAP = {
- 物候信息: { key: "phenology", label: "物候信息" },
- 物候期: { key: "phenology", label: "物候信息" },
- 土壤条件: { key: "soil", label: "土壤条件" },
- 地形条件: { key: "terrain", label: "地形条件" },
- };
- // ---------------------------------------------------------------------------
- // 页面状态
- // ---------------------------------------------------------------------------
- const loading = ref(false); // 接口尚未返回:只转圈,不带文字
- const reportGenerating = ref(false); // exists=0:模拟进度条,并继续轮询
- const progressPercent = ref(10);
- /** 分区列表(getZones) */
- const zoneList = ref([]);
- const selectedZoneId = ref(null);
- const headerDesc = ref("");
- const headerBase = ref("");
- const baseInfoList = ref([]);
- /** key → 解析后的模块对象 { id, tab, lead, blocks } */
- const moduleMap = ref({});
- const activeReportTab = ref("weather");
- const adjustPhenologyPopupRef = ref(null);
- const restingDatePopupRef = ref(null);
- const editPlantPointPopupRef = ref(null);
- // const showCompleteFarmPopup = ref(false); // 无农场时展示「完善农场信息」
- let pollTimer = null;
- let progressTimer = null;
- /** 当前进度条绑定的农场 key,切页时按它写回缓存 */
- let progressFarmKey = "";
- /** 当前轮询方式:farm | latlon */
- let pollMode = null;
- let pollParams = null;
- /** 离开页面或重新拉取时作废尚未结束的完成动画 */
- let viewToken = 0;
- // ---------------------------------------------------------------------------
- // 计算属性
- // ---------------------------------------------------------------------------
- const pageParams = computed(() => resolvePageParams());
- /** 通过分享进入:顶栏小房子回首页,且 App 侧隐藏底部菜单 */
- const isFromShare = computed(() => isTruthyFlag(pageParams.value?.fromShare));
- const shareFarmId = computed(
- () => pageParams.value.farm_id || pageParams.value.farmId || "",
- );
- const shareZoneId = computed(
- () => pageParams.value.zone_id || pageParams.value.zoneId || "",
- );
- const reportTabs = computed(() =>
- MODULE_DEFS.map((def) => {
- const mod = moduleMap.value[def.key];
- if (!mod) return null;
- return {
- key: def.key,
- label: mod.tab || def.fallbackLabel,
- };
- }).filter(Boolean),
- );
- const activeModule = computed(() => moduleMap.value[activeReportTab.value] || null);
- // ---------------------------------------------------------------------------
- // 工具函数
- // ---------------------------------------------------------------------------
- function isTruthyFlag(value) {
- return value === 1 || value === "1" || value === true || value === "true";
- }
- function parseMaybeJson(value) {
- if (value == null || value === "") return null;
- if (typeof value === "object") return value;
- try {
- return JSON.parse(value);
- } catch {
- return null;
- }
- }
- /**
- * 分享链路:dev_login 把整份登录 query 塞进 miniJson,
- * 真正的页面参数在 miniJson.paramsPage(farm_id / zone_id / fromShare)
- */
- function resolvePageParams() {
- const mini = parseMaybeJson(route.query.miniJson);
- if (mini) {
- const page = parseMaybeJson(mini.paramsPage) || {};
- return { ...mini, ...page };
- }
- const paramsPage = parseMaybeJson(route.query.paramsPage);
- if (paramsPage) {
- return { ...route.query, ...paramsPage };
- }
- return { ...(route.query || {}) };
- }
- function getSelectedFarm() {
- try {
- return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
- } catch {
- return {};
- }
- }
- /** 与 diagnosisReportPopup 同源:标记该农场/分区弹窗已读 */
- const DIAGNOSIS_POPUP_SHOWN_PREFIX = "DIAGNOSIS_REPORT_POPUP_SHOWN_";
- function markDiagnosisPopupShown(farmId, zoneId) {
- if (farmId == null || farmId === "") return;
- const key = `${DIAGNOSIS_POPUP_SHOWN_PREFIX}${farmId}_${zoneId ?? ""}`;
- localStorage.setItem(key, "1");
- }
- /** 无农场报告用点位:优先用户定位 */
- 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;
- }
- /** 模块字段可能是 JSON 字符串或对象 */
- function parseModuleJson(raw) {
- if (raw == null || raw === "") return null;
- if (typeof raw === "object") return raw;
- try {
- return JSON.parse(raw);
- } catch {
- return null;
- }
- }
- function normalizeModule(raw) {
- const data = parseModuleJson(raw);
- if (!data || typeof data !== "object") return null;
- const blocks = Array.isArray(data.blocks)
- ? data.blocks.map((block) => ({
- no: block?.no || "",
- title: block?.title || "",
- text: block?.text || "",
- sub: Array.isArray(block?.sub)
- ? block.sub.map((item) => ({
- title: item?.title || "",
- text: item?.text || "",
- }))
- : [],
- }))
- : [];
- return {
- id: data.id || "",
- tab: data.tab || "",
- lead: data.lead || "",
- blocks,
- };
- }
- function buildBaseInfoList(basic, report = {}) {
- const list = [];
- const crop = report.crop || "";
- const variety = basic?.variety || report.variety || "";
- const cropValue = [crop, variety].filter(Boolean).join("-");
- list.push({
- key: "crop",
- label: "种植作物",
- value: cropValue || "—",
- });
- const rows = Array.isArray(basic?.rows) ? basic.rows : [];
- rows.forEach((row, index) => {
- const labelText = String(row?.label || "").trim();
- const meta = BASE_ROW_LABEL_MAP[labelText] || {
- key: `row-${index}`,
- label: labelText ? `${labelText}:` : "信息:",
- };
- list.push({
- key: meta.key,
- label: meta.label,
- value: row?.text || "—",
- });
- });
- return list;
- }
- function applyReportData(report, farm) {
- const region = report.region || farm.rawAddress || farm.farm_address || farm.city || "";
- const farmName = farm.farm_name || farm.name || "";
- headerDesc.value = region ? `${region}的${farmName || "飞鸟智慧农业"}` : "飞鸟智慧农业";
- const basic = parseModuleJson(report.module1_basic) || {};
- baseInfoList.value = buildBaseInfoList(basic, report);
- const nextModules = {};
- MODULE_DEFS.forEach((def) => {
- const mod = normalizeModule(report[def.field]);
- if (mod) nextModules[def.key] = mod;
- });
- moduleMap.value = nextModules;
- const firstTab = MODULE_DEFS.find((def) => nextModules[def.key]);
- activeReportTab.value = firstTab?.key || "weather";
- }
- function resetReportView(farm = {}) {
- headerDesc.value = farm.rawAddress || farm.farm_address || farm.city
- ? `${farm.rawAddress || farm.farm_address || farm.city}的飞鸟智慧农业`
- : "飞鸟智慧农业";
- headerBase.value = farm.farm_name || farm.name || "我的基地";
- baseInfoList.value = [];
- moduleMap.value = {};
- }
- /** 拉取分区;优先分享 zone_id → 当前选中 → 农场缓存分区 */
- async function fetchZoneList(farmId) {
- if (farmId == null || farmId === "") {
- zoneList.value = [];
- selectedZoneId.value = null;
- return;
- }
- try {
- const res = await VE_API.questionnaire.getZones({ farm_id: farmId });
- const zones = Array.isArray(res?.data?.zones) ? res.data.zones : [];
- zoneList.value = zones;
- const farm = getSelectedFarm();
- const prefer =
- shareZoneId.value ||
- selectedZoneId.value ||
- farm.zone_id ||
- farm.zoneId;
- const matched = zones.find((z) => String(z.zone_id) === String(prefer));
- selectedZoneId.value = (matched || zones[0])?.zone_id ?? null;
- } catch (e) {
- console.warn("[diagnosisReport] getZones failed", e);
- zoneList.value = [];
- selectedZoneId.value = null;
- }
- }
- // ---------------------------------------------------------------------------
- // 业务逻辑:无农场弹窗 / 加载报告
- // ---------------------------------------------------------------------------
- /** 无果园信息时展示「完善农场信息」弹窗(暂不启用) */
- // 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() {
- if (pollTimer) {
- clearInterval(pollTimer);
- pollTimer = null;
- }
- pollMode = null;
- pollParams = null;
- }
- function stopProgressTimer() {
- if (progressTimer) {
- clearInterval(progressTimer);
- progressTimer = null;
- }
- }
- /** 有农场用 farm_id;无农场共用 nofarm,避免互相覆盖 */
- function resolveProgressFarmKey(farm) {
- const farmId = farm?.farm_id ?? farm?.id;
- if (farmId != null && farmId !== "") return String(farmId);
- return PROGRESS_NO_FARM_KEY;
- }
- function readProgressStore() {
- try {
- const raw = JSON.parse(localStorage.getItem(PROGRESS_STORAGE_KEY) || "{}");
- return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
- } catch {
- return {};
- }
- }
- function readProgressCache(farmKey = progressFarmKey) {
- if (!farmKey) return null;
- const percent = Number(readProgressStore()[farmKey]);
- if (!Number.isFinite(percent)) return null;
- return Math.min(PROGRESS_CAP, Math.max(PROGRESS_MIN, Math.floor(percent)));
- }
- function writeProgressCache(percent, farmKey = progressFarmKey) {
- if (!farmKey) return;
- const value = Math.min(PROGRESS_CAP, Math.max(PROGRESS_MIN, Math.floor(percent)));
- const store = readProgressStore();
- store[farmKey] = value;
- localStorage.setItem(PROGRESS_STORAGE_KEY, JSON.stringify(store));
- }
- function clearProgressCache(farmKey = progressFarmKey) {
- if (!farmKey) return;
- const store = readProgressStore();
- if (!(farmKey in store)) return;
- delete store[farmKey];
- localStorage.setItem(PROGRESS_STORAGE_KEY, JSON.stringify(store));
- }
- /** 切页时记下当前农场进度,回来不要从头走 */
- function saveProgressSnapshot() {
- if (!reportGenerating.value || !progressFarmKey) return;
- writeProgressCache(progressPercent.value || PROGRESS_MIN, progressFarmKey);
- }
- /** exists=0 才走进度条;按农场从 10% 或已记下的进度接着走到 99 */
- function beginProgress(farm) {
- progressFarmKey = resolveProgressFarmKey(farm);
- reportGenerating.value = true;
- if (progressTimer) return;
- const startPercent = readProgressCache(progressFarmKey) ?? PROGRESS_MIN;
- progressPercent.value = startPercent;
- writeProgressCache(startPercent, progressFarmKey);
- const span = PROGRESS_CAP - startPercent;
- const remainMs = ((PROGRESS_CAP - PROGRESS_MIN) > 0
- ? span / (PROGRESS_CAP - PROGRESS_MIN)
- : 0) * PROGRESS_DURATION_MS;
- if (remainMs <= 0) return;
- const farmKey = progressFarmKey;
- const startedAt = Date.now();
- progressTimer = setInterval(() => {
- const ratio = Math.min((Date.now() - startedAt) / remainMs, 1);
- const next = Math.min(PROGRESS_CAP, Math.floor(startPercent + span * ratio));
- progressPercent.value = next;
- writeProgressCache(next, farmKey);
- if (ratio >= 1) stopProgressTimer();
- }, 200);
- }
- /** 进度条进行中才先收到 100;首次就有报告则直接出正文 */
- async function revealReport(report, farm, token) {
- if (token !== viewToken) return;
- stopReportPolling();
- const showComplete = reportGenerating.value;
- const farmKey = progressFarmKey || resolveProgressFarmKey(farm);
- stopProgressTimer();
- clearProgressCache(farmKey);
- progressFarmKey = "";
- if (!showComplete) {
- reportGenerating.value = false;
- applyReportData(report || {}, farm);
- return;
- }
- progressPercent.value = 100;
- await new Promise((resolve) => setTimeout(resolve, 400));
- if (token !== viewToken) return;
- reportGenerating.value = false;
- applyReportData(report || {}, farm);
- }
- /** 有 exists 时以它为准;没有该字段时看是否已经有报告体 */
- function isReportPending(res, report) {
- const exists = res?.data?.exists;
- if (exists != null && exists !== "") return Number(exists) === 0;
- return !report;
- }
- /** 报告未就绪时保持 loading,并定时重试 */
- function startReportPolling(mode, params, token) {
- stopReportPolling();
- pollMode = mode;
- pollParams = params;
- pollTimer = setInterval(() => {
- if (token !== viewToken) return;
- if (pollMode === "farm") {
- pollFarmReport(pollParams, token);
- } else if (pollMode === "latlon") {
- pollLatlonReport(pollParams, token);
- }
- }, REPORT_POLL_INTERVAL);
- }
- async function pollFarmReport({ farmId, zoneId }, token) {
- try {
- const raw = await VE_API.questionnaire.checkReportGenerated({
- farm_id: farmId,
- zone_id: zoneId,
- });
- if (token !== viewToken) return;
- const res = Array.isArray(raw) ? raw[0] : raw;
- const report = res?.data?.report;
- if (res?.code === 200 && !isReportPending(res, report)) {
- // 进入报告页并拿到数据:标记该农场弹窗已读,避免再弹
- markDiagnosisPopupShown(farmId, zoneId);
- revealReport(report, getSelectedFarm(), token);
- }
- } catch (error) {
- console.warn("[diagnosisReport] farm poll failed", error);
- }
- }
- async function pollLatlonReport({ pointText, crop }, token) {
- try {
- const raw = await VE_API.report.report6Latlon({
- point_text: pointText,
- crop: '水稻',
- });
- if (token !== viewToken) return;
- const res = Array.isArray(raw) ? raw[0] : raw;
- const report = pickLatlonReport(res);
- if (res?.code === 200 && !isReportPending(res, report)) {
- revealReport(report, {}, token);
- }
- } catch (error) {
- console.warn("[diagnosisReport] latlon poll failed", error);
- }
- }
- /** 无农场:按定位点 + 水稻拉取 / 轮询六模块报告 */
- async function fetchLatlonReport(token) {
- 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: '水稻',
- });
- if (token !== viewToken) return;
- const res = Array.isArray(raw) ? raw[0] : raw;
- const report = pickLatlonReport(res);
- if (res?.code === 200 && !isReportPending(res, report)) {
- revealReport(report, {}, token);
- return;
- }
- resetReportView({});
- beginProgress({});
- startReportPolling("latlon", params, token);
- } catch (error) {
- if (token !== viewToken) return;
- console.error("fetchLatlonReport failed", error);
- resetReportView({});
- reportGenerating.value = false;
- stopProgressTimer();
- ElMessage.error("报告加载失败");
- } finally {
- if (token === viewToken) loading.value = false;
- }
- }
- async function fetchFarmReport(farm, token) {
- const farmId = farm.farm_id ?? farm.id;
- const zoneId = selectedZoneId.value ?? farm.zone_id ?? farm.zoneId;
- loading.value = true;
- try {
- const raw = await VE_API.questionnaire.checkReportGenerated({
- farm_id: farmId,
- zone_id: zoneId,
- });
- if (token !== viewToken) return;
- const res = Array.isArray(raw) ? raw[0] : raw;
- const report = res?.data?.report;
- if (res?.code === 200 && !isReportPending(res, report)) {
- markDiagnosisPopupShown(farmId, zoneId);
- revealReport(report, farm, token);
- return;
- }
- resetReportView(farm);
- beginProgress(farm);
- startReportPolling("farm", { farmId, zoneId }, token);
- } catch (error) {
- if (token !== viewToken) return;
- console.error("fetchFarmReport failed", error);
- resetReportView(farm);
- reportGenerating.value = false;
- stopProgressTimer();
- ElMessage.error("报告加载失败");
- } finally {
- if (token === viewToken) loading.value = false;
- }
- }
- async function fetchDiagnosisReport() {
- const farm = getSelectedFarm();
- viewToken += 1;
- const token = viewToken;
- stopReportPolling();
- saveProgressSnapshot();
- stopProgressTimer();
- reportGenerating.value = false;
- loading.value = true;
- const farmId = farm.farm_id ?? farm.id;
- if (farmId == null || farmId === "") {
- zoneList.value = [];
- selectedZoneId.value = null;
- await fetchLatlonReport(token);
- return;
- }
- await fetchZoneList(farmId);
- if (token !== viewToken) return;
- if (selectedZoneId.value == null || selectedZoneId.value === "") {
- resetReportView(farm);
- loading.value = false;
- return;
- }
- await fetchFarmReport(farm, token);
- }
- // ---------------------------------------------------------------------------
- // 事件处理 / 生命周期
- // ---------------------------------------------------------------------------
- /** 切换分区后按新 zone_id 重拉报告 */
- const handleSelectZone = (zone) => {
- if (!zone || String(zone.zone_id) === String(selectedZoneId.value)) return;
- selectedZoneId.value = zone.zone_id;
- viewToken += 1;
- const token = viewToken;
- stopReportPolling();
- saveProgressSnapshot();
- stopProgressTimer();
- reportGenerating.value = false;
- fetchFarmReport(getSelectedFarm(), token);
- };
- /** 与巡园面板一致:进入新增分区 */
- const goAddVariety = () => {
- router.push({
- path: "/add_zone",
- query: { type: "region", isSuccessPopup: "1" },
- });
- };
- /** 转发种植全析:带 farm_id / zone_id / fromShare */
- const handleShare = () => {
- const farm = getSelectedFarm();
- const farmId = farm.farm_id ?? farm.id ?? shareFarmId.value;
- const zoneId = selectedZoneId.value ?? shareZoneId.value;
- const farmName = farm.farmName || "我的农场";
- if (farmId == null || farmId === "" || zoneId == null || zoneId === "") {
- ElMessage.warning("当前农场或分区信息不全,暂无法转发");
- return;
- }
- const query = {
- askInfo: { title: "转发种植全析", content: "是否分享该报告给好友" },
- shareText: `【${farmName}】 种植全析报告已生成,请点击查看!`,
- targetUrl: "diagnosis_report",
- paramsPage: JSON.stringify({
- farm_id: farmId,
- zone_id: zoneId,
- fromShare: 1,
- }),
- imageUrl: "https://birdseye-img.sysuimars.com/farm-h5/report_cover.png",
- };
- wx.miniProgram.navigateTo({
- url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=sharePage`,
- });
- };
- const handleBaseAction = (key) => {
- if (key === "adjustPhenology") {
- adjustPhenologyPopupRef.value?.open();
- return;
- }
- if (key === "editLocation") {
- editPlantPointPopupRef.value?.open();
- return;
- }
- if (key === "soilSense") {
- router.push("/soil_sense");
- return;
- }
- console.log("base action:", key);
- };
- const handlePhenologyConfirm = (payload) => {
- restingDatePopupRef.value?.open(payload);
- };
- const handleSwitchGrowing = () => {
- adjustPhenologyPopupRef.value?.open();
- };
- const handleRestingDateConfirm = (payload) => {
- console.log("resting date confirm:", payload);
- };
- const handlePlantPointConfirm = (payload) => {
- console.log("plant point confirm:", payload);
- };
- // const goCompleteFarmInfo = () => {
- // router.push("/entry_information");
- // };
- // tabbar 切换时组件被 keep-alive 缓存,需在激活时重新拉报告 / 校验农场
- onActivated(async () => {
- // 分享进页:先按 farm_id / zone_id 切回分享上下文
- await ensureFarmContext({
- farmId: shareFarmId.value,
- zoneId: shareZoneId.value,
- });
- if (shareZoneId.value) {
- selectedZoneId.value = shareZoneId.value;
- }
- // checkCompleteFarmPopup(); // 暂无农场时不弹「完善农场信息」
- fetchDiagnosisReport();
- });
- onDeactivated(() => {
- viewToken += 1;
- saveProgressSnapshot();
- stopReportPolling();
- stopProgressTimer();
- });
- onBeforeUnmount(() => {
- viewToken += 1;
- saveProgressSnapshot();
- stopReportPolling();
- stopProgressTimer();
- });
- </script>
- <style lang="scss" scoped>
- .diagnosis-report-page {
- width: 100%;
- height: calc(100vh - 50px);
- overflow: auto;
- -webkit-overflow-scrolling: touch;
- box-sizing: border-box;
- padding-bottom: 20px;
- background: #060300;
- position: relative;
- &.is-from-share {
- height: 100vh;
- display: flex;
- flex-direction: column;
- padding-bottom: calc(2px + env(safe-area-inset-bottom));
- &::before {
- top: 36px;
- background: none;
- }
- .page-content {
- position: relative;
- &::before {
- content: "";
- height: 250px;
- width: 100%;
- position: absolute;
- top: 0;
- left: 0;
- background: #0a0a0a url("@/assets/img/agricultural/report-bg.png") no-repeat top center;
- background-size: 100% 250px;
- }
- }
- .page-content {
- flex: 1;
- min-height: 0;
- overflow: auto;
- -webkit-overflow-scrolling: touch;
- }
- }
- &::before {
- content: "";
- height: 250px;
- width: 100%;
- position: absolute;
- top: 0;
- left: 0;
- background: #0a0a0a url("@/assets/img/agricultural/report-bg.png") no-repeat top center;
- background-size: 100% 250px;
- }
- .page-content {
- position: relative;
- z-index: 2;
- }
- ::v-deep {
- .el-loading-spinner .path {
- stroke: rgba(255, 212, 137, 0.8);
- }
- }
- .report-progress {
- display: flex;
- align-items: center;
- min-height: calc(100vh - 70px);
- padding: 0 36px;
- box-sizing: border-box;
- :deep(.el-progress) {
- width: 100%;
- }
- :deep(.el-progress-bar__outer) {
- background: rgba(255, 255, 255, 0.08);
- }
- :deep(.el-progress__text) {
- display: none;
- color: #ffd489;
- }
- }
- .report-progress__content {
- width: 100%;
- }
- .report-progress__desc {
- margin-top: 16px;
- font-size: 16px;
- line-height: 20px;
- color: #A8A094;
- gap: 4px;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .diagnosis-header {
- padding: 42px 14px 8px;
- box-sizing: border-box;
- color: #fff;
- position: relative;
- .header-share {
- position: absolute;
- right: 16px;
- top: 20px;
- z-index: 2;
- display: inline-flex;
- align-items: center;
- gap: 4px;
- height: 28px;
- padding: 0 12px;
- border-radius: 14px;
- background: rgba(0, 0, 0, 0.6);
- border: 1px solid rgba(255, 255, 255, 0.12);
- color: rgba(255, 255, 255, 0.85);
- backdrop-filter: blur(4px);
- font-size: 12px;
- cursor: pointer;
- }
- &__title-row {
- display: flex;
- align-items: center;
- gap: 6px;
- }
- &__title {
- font-size: 25px;
- line-height: 31px;
- font-weight: 600;
- // background: linear-gradient(180deg, #ffe2ae 0%, #ffd489 100%);
- // -webkit-background-clip: text;
- // background-clip: text;
- // -webkit-text-fill-color: transparent;
- color: #F7ECD3;
- }
- &__icon {
- width: 24px;
- height: 24px;
- }
- &__desc {
- width: fit-content;
- margin-top: 9px;
- font-size: 12px;
- line-height: 20px;
- padding: 5px 8px;
- color: #A8A094;
- background: rgba(20, 16, 8, 0.89);
- border: 1px solid rgba(201, 164, 79, 0.6);
- border-radius: 10px;
- }
- &__base {
- margin-top: 2px;
- font-size: 12px;
- line-height: 18px;
- color: #ffd489;
- }
- }
- .diagnosis-content {
- padding: 12px 12px;
- background: #060300;
- position: relative;
- z-index: 2;
- background: linear-gradient(180deg, rgba(6, 3, 0, 0.1) 0%, rgba(6, 3, 0, 0.8) 2%, #060300 100%);
- .variety-bar {
- display: flex;
- align-items: center;
- // justify-content: space-between;
- &__tags {
- display: flex;
- align-items: center;
- flex-wrap: wrap;
- gap: 6px;
- }
- &__tag {
- padding: 5px 14px;
- border-radius: 30px;
- background: rgba(255, 255, 255, 0.05);
- color: rgba(255, 255, 255, 0.5);
- border: 1px solid rgba(255, 255, 255, 0.12);
- &.active {
- background: rgba(255, 255, 255, 0.1);
- // background: linear-gradient(90deg, #ffebc9 0%, #ffca6d 100%);
- color: rgba(255, 255, 255, 1);
- border-color: rgba(255, 255, 255, 0.4);
- font-weight: 500;
- }
- }
- &__add {
- display: flex;
- align-items: center;
- margin-left: 8px;
- border-radius: 30px;
- gap: 2px;
- padding: 5px 14px;
- background: rgba(255, 255, 255, 0.05);
- color: rgba(255, 255, 255, 0.6);
- border: 1px dashed rgba(255, 255, 255, 0.12);
- }
- }
- .base-data {
- margin: 10px 0;
- padding: 12px;
- min-height: auto;
- background: linear-gradient(180deg, #1a191d 0%, #121216 100%);
- border: 1px solid rgba(255, 255, 255, 0.1);
- border-radius: 12px;
- box-sizing: border-box;
- &__title {
- display: flex;
- align-items: center;
- gap: 6px;
- font-size: 17px;
- color: #fff;
- .title-dot {
- width: 2px;
- height: 16px;
- background: #FFD489;
- border-radius: 2px;
- margin-top: 2px;
- }
- }
- &__icon {
- width: 28px;
- height: 28px;
- }
- &__body {
- .base-data__empty {
- padding: 20px 0;
- text-align: center;
- color: rgba(255, 255, 255, 0.45);
- font-size: 13px;
- }
- .base-info-item {
- margin-bottom: 8px;
- &__row {
- color: rgba(255, 255, 255, 0.88);
- line-height: 22px;
- }
- &__label {
- display: inline-block;
- padding: 1px 6px;
- background: rgba(204, 204, 204, 0.1);
- border: 1px solid rgba(255, 255, 255, 0.16);
- border-radius: 4px;
- height: 19px;
- line-height: 22px;
- margin-right: 10px;
- color: rgba(225, 225, 225, 1);
- }
- &__value {
- color: rgba(255, 255, 255, 0.8);
- line-height: 24px;
- }
- }
- .base-info-action {
- display: inline-flex;
- align-items: center;
- gap: 2px;
- margin-left: 6px;
- padding: 2px 8px;
- border-radius: 20px;
- background: rgba(255, 212, 137, 0.12);
- color: #ffd489;
- font-size: 12px;
- .el-icon {
- font-size: 12px;
- }
- &--block {
- display: inline-flex;
- margin: 8px 0 0;
- }
- }
- }
- }
- .report-module {
- margin-top: 4px;
- }
- .report-tabs {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding-bottom: 12px;
- // gap: 6px;
- // overflow-x: auto;
- // -webkit-overflow-scrolling: touch;
- // scrollbar-width: none;
- &::-webkit-scrollbar {
- display: none;
- }
- &__item {
- flex: 0 0 auto;
- width: 80px;
- padding: 8px 12px;
- border-radius: 8px;
- font-size: 13px;
- box-sizing: border-box;
- line-height: 20px;
- background: rgba(37, 37, 41, 0.8);
- text-align: center;
- color: #E1E1E1;
- border: 1px solid transparent;
- cursor: pointer;
- &.active {
- border: 1px solid rgba(255, 212, 137, 0.4);
- background: #1E180E;
- color: #FFD489;
- font-weight: 500;
- position: relative;
- &::after {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- width: 0;
- height: 0;
- bottom: -7px;
- margin: 0 auto;
- border-left: 8px solid transparent;
- border-top: 7px solid #78633F;
- border-bottom: 0px solid transparent;
- border-right: 8px solid transparent;
- }
- }
- }
- }
- .report-panel {
- margin-top: 12px;
- padding-bottom: 8px;
- &__empty {
- margin-top: 14px;
- padding: 24px 0;
- text-align: center;
- color: rgba(255, 255, 255, 0.45);
- font-size: 13px;
- }
- }
- .core-card {
- padding: 14px;
- border-radius: 12px;
- background: linear-gradient(90.51deg, #1A191D 0%, rgba(76, 68, 53, 0.4) 102.25%);
- border: 1px solid rgba(255, 212, 137, 0.24);
- &__head {
- display: flex;
- align-items: center;
- gap: 6px;
- font-size: 15px;
- font-weight: 600;
- color: #ffd489;
- }
- &__star {
- width: 11px;
- // height: 16px;
- }
- &__body {
- margin-top: 10px;
- font-size: 14px;
- line-height: 22px;
- color: rgba(255, 255, 255, 0.88);
- word-break: break-word;
- }
- }
- .point-block {
- margin-top: 18px;
- &__head {
- display: flex;
- align-items: baseline;
- gap: 8px;
- margin-bottom: 10px;
- }
- &__no {
- flex-shrink: 0;
- font-size: 16px;
- font-weight: 600;
- color: #ffd489;
- font-variant-numeric: tabular-nums;
- }
- &__title {
- font-size: 16px;
- line-height: 22px;
- color: #fff;
- }
- // 样式 0:整行标题金色
- &--s0 &__title {
- color: #ffd489;
- }
- &__card {
- padding: 14px;
- border-radius: 12px;
- background: linear-gradient(180deg, #1A191D 0%, #121216 100%);
- border: 1px solid rgba(255, 255, 255, 0.1);
- }
- }
- .point-sub + .point-sub {
- margin-top: 12px;
- }
- .point-sub {
- &+& {
- margin-top: 12px;
- padding-top: 12px;
- border-top: 1px solid rgba(255, 255, 255, 0.08);
- }
- &__badge {
- display: inline-flex;
- background: rgba(255, 212, 137, 0.1);
- align-items: center;
- padding: 1px 6px;
- border-radius: 4px;
- border: 1px solid rgba(255, 212, 137, 0.16);
- font-size: 12px;
- color: #FFD489;
- }
- &__plain {
- font-size: 16px;
- line-height: 22px;
- color: #fff;
- }
- &__icon-row {
- display: flex;
- align-items: flex-start;
- gap: 8px;
- }
- &__icon {
- flex-shrink: 0;
- width: 28px;
- height: 28px;
- border-radius: 6px;
- border: 1px solid rgba(255, 212, 137, 0.55);
- display: inline-flex;
- align-items: center;
- justify-content: center;
- color: #ffd489;
- font-size: 14px;
- }
- &__icon-title {
- flex: 1;
- font-size: 16px;
- line-height: 22px;
- color: #fff;
- padding-top: 3px;
- }
- &__text {
- margin-top: 8px;
- font-size: 14px;
- line-height: 20px;
- color: #8A8580;
- word-break: break-word;
- }
- }
- }
- }
- </style>
|