| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783 |
- <template>
- <div class="report-panel">
- <!-- 最新报告 -->
- <div class="report-section">
- <div class="report-section__title">最新报告</div>
- <div
- v-for="report in latestReports"
- :key="report.id"
- class="latest-card"
- @click="handleReportClick(report)"
- >
- <div class="latest-card__header">
- <div class="latest-card__header-left">
- <div class="latest-card__type-icon">
- <el-icon><Search /></el-icon>
- </div>
- <div class="latest-card__type-meta">
- <div class="latest-card__type-name">{{ report.title || "—" }}</div>
- <div class="latest-card__date">{{ report.dateText }}</div>
- </div>
- </div>
- <span class="risk-badge">{{ report.riskLevel || "—" }}</span>
- </div>
- <div class="latest-card__subject">{{ report.riskName || "—" }}</div>
- <div class="latest-card__conclusion">
- <div class="latest-card__conclusion-label">核心结论</div>
- <div class="latest-card__conclusion-text">
- {{ report.desc || "—" }}
- </div>
- </div>
- <!-- <div class="latest-card__evidence">
- <div class="latest-card__avatars">
- <img
- v-for="(src, idx) in mockPhotoAvatars"
- :key="idx"
- class="latest-card__avatar"
- :src="src"
- alt=""
- />
- <span class="latest-card__avatar-more">+3</span>
- </div>
- <div class="latest-card__evidence-text">
- 基于 <em>6</em> 张待完善待完善 · <em>4</em> 项待完善
- </div>
- </div> -->
- <div class="latest-card__footer">
- <div class="latest-card__share" @click.stop="handleShare(report)">
- <Icon size="14" color="rgba(255,255,255,0.75)" name="share" />
- <span>转发</span>
- </div>
- <div class="latest-card__detail" @click.stop="handleReportClick(report)">
- 查看完整报告 <el-icon><ArrowRight /></el-icon>
- </div>
- </div>
- </div>
- <div v-if="!latestReports.length" class="report-empty">暂无最新报告</div>
- <!-- 报告生成中:暂写死 -->
- <div class="generating-card">
- <div class="generating-card__spinner"></div>
- <div class="generating-card__text">
- <div class="generating-card__title">报告生成中</div>
- <div class="generating-card__desc">
- 东区2号 · 已上传 <span class="generating-card__desc-count">3</span> 张巡园照片
- </div>
- </div>
- </div>
- </div>
- <!-- 历史报告 -->
- <div class="report-section report-section--history">
- <div class="report-section__head">
- <div class="report-section__title">历史报告</div>
- <div class="report-section__meta">
- 共 <span class="report-section__meta-count">{{ historyCount }}</span> 份 · 按时间排序
- </div>
- </div>
- <List
- v-model:loading="historyLoading"
- :finished="historyFinished"
- :finished-text="historyMonthGroups.length ? '没有更多了' : ''"
- @load="loadHistoryPage"
- >
- <div v-if="!historyMonthGroups.length && !historyLoading" class="report-empty">
- 暂无历史报告
- </div>
- <div
- v-for="monthGroup in historyMonthGroups"
- :key="monthGroup.key"
- class="history-month"
- >
- <div class="history-month__label">
- <span>{{ monthGroup.label }}</span>
- <i class="history-month__line"></i>
- </div>
- <div
- v-for="item in monthGroup.items"
- :key="item.id"
- class="history-card"
- @click="handleReportClick(item)"
- >
- <div class="history-card-wrap">
- <img class="history-card__cover" :src="item.cover" alt="" />
- <div class="history-card__body">
- <div class="history-card__top">
- <div class="history-card__type">
- <el-icon><WarningFilled /></el-icon>
- <span>{{ resolveTypeLabel(item.type) }}</span>
- </div>
- <span class="risk-badge">{{ item.riskLevel || "—" }}</span>
- </div>
- <div class="history-card__title van-ellipsis">
- {{ item.title || "—" }}
- </div>
- <div class="history-card__desc van-ellipsis">
- {{ item.desc || "—" }}
- </div>
- <div class="history-card__line"></div>
- <div class="history-card__bottom">
- <span class="history-card__time">
- <el-icon><Clock /></el-icon>
- {{ item.dateText }}
- </span>
- <el-icon class="history-card__arrow"><ArrowRight /></el-icon>
- </div>
- </div>
- </div>
- </div>
- </div>
- </List>
- </div>
- </div>
- </template>
- <script setup>
- import { computed, onActivated, onMounted, ref } from "vue";
- import { useRouter } from "vue-router";
- import { Icon, List } from "vant";
- import { ArrowRight, Clock, Search, WarningFilled } from "@element-plus/icons-vue";
- import { base_img_url2 } from "@/api/config";
- import wx from "weixin-js-sdk";
- const router = useRouter();
- const defaultCover = require("@/assets/img/common/sd-1.jpg");
- const emptyPhoto = require("@/assets/img/common/empty-bg.png");
- /** 证据区头像占位 */
- const mockPhotoAvatars = [emptyPhoto, emptyPhoto];
- const TYPE_LABEL_MAP = {
- warning: "预警报告",
- stress: "胁迫报告",
- diagnosis: "巡园诊断报告",
- patrol: "巡园诊断报告",
- };
- // ---------- 最新报告(today_reports,可多份) ----------
- const latestReports = ref([]);
- // ---------- 历史报告(滚动分页) ----------
- const historyList = ref([]);
- const historyLoading = ref(false);
- const historyFinished = ref(false);
- const historyPage = ref(0);
- const historyCount = ref(0);
- /** 历史按月分组,key 用 YYYY-MM */
- const historyMonthGroups = computed(() => {
- const map = new Map();
- historyList.value.forEach((item) => {
- const key = item.monthKey || "unknown";
- if (!map.has(key)) {
- map.set(key, {
- key,
- label: item.monthLabel || "其他",
- items: [],
- });
- }
- map.get(key).items.push(item);
- });
- return Array.from(map.values());
- });
- const getSelectedFarm = () => {
- try {
- return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
- } catch {
- return {};
- }
- };
- const resolveCoverUrl = (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(/^\//, "");
- };
- const resolveTypeLabel = (type) => {
- const key = String(type || "").toLowerCase();
- return TYPE_LABEL_MAP[key] || type || "报告";
- };
- /** 解析接口 time → 展示用日期 / 月份 */
- const parseReportTime = (raw) => {
- const text = String(raw || "").trim();
- const iso = text.match(/(\d{4})-(\d{2})-(\d{2})/);
- if (iso) {
- return {
- dateText: `${iso[2]}/${iso[3]}`,
- monthKey: `${iso[1]}-${iso[2]}`,
- monthLabel: `${Number(iso[2])} 月`,
- };
- }
- const slash = text.match(/(\d{1,2})\/(\d{1,2})/);
- if (slash) {
- const mm = slash[1].padStart(2, "0");
- const dd = slash[2].padStart(2, "0");
- return {
- dateText: `${mm}/${dd}`,
- monthKey: mm,
- monthLabel: `${Number(mm)} 月`,
- };
- }
- return {
- dateText: text || "—",
- monthKey: "unknown",
- monthLabel: "其他",
- };
- };
- const mapReportItem = (item, index) => {
- const timeInfo = parseReportTime(item.time || item.date);
- return {
- id: item.id ?? `${item.time || ""}-${index}`,
- title: item.title || "",
- type: item.type || "",
- desc: item.content || "",
- date: item.time || "",
- dateText: timeInfo.dateText,
- monthKey: timeInfo.monthKey,
- monthLabel: timeInfo.monthLabel,
- cover: resolveCoverUrl(item.cover_url),
- phenoName: item.phenophase_name || "",
- riskName: item.risk_name || "",
- riskLevel: item.risk_level || "",
- riskLevelNum: item.risk_level_num || "",
- };
- };
- const handleReportClick = (item) => {
- router.push({
- path: "/alert_detail",
- query: {
- title: item?.title || "具体预警",
- type: item?.type || "warning",
- },
- });
- };
- const handleShare = (item) => {
- const shareText = item?.type === 'warning' ? '预警报告已生成,请点击查看吧!' : '胁迫报告已生成,请点击查看吧!';
- const query = {
- askInfo: { title: "转发报告", content: "是否分享给好友" },
- shareText,
- targetUrl: "alert_detail",
- paramsPage: JSON.stringify({
- title: item?.title || "报告",
- type: item?.type || "warning",
- 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`,
- });
- };
- /**
- * 加载一页历史报告;首屏(page=1)同时写入「最新报告」。
- * 由 van-list 的 @load 在滚动到底部时持续触发。
- */
- const loadHistoryPage = async () => {
- const farm = getSelectedFarm();
- const farmId = farm.farm_id ?? farm.id;
- const zoneId = farm.zone_id ?? farm.zoneId;
- if (farmId == null || farmId === "" || zoneId == null || zoneId === "") {
- historyFinished.value = true;
- historyLoading.value = false;
- return;
- }
- const nextPage = historyPage.value + 1;
- historyLoading.value = true;
- try {
- const res = await VE_API.questionnaire.getReportList({
- farm_id: farmId,
- zone_id: zoneId,
- page: nextPage,
- page_size: 10,
- });
- const data = res?.data || {};
- if (nextPage === 1) {
- // 最新报告取 today_reports(当日可有多份)
- latestReports.value = Array.isArray(data.today_reports)
- ? data.today_reports.map((item, i) => mapReportItem(item, i))
- : [];
- historyCount.value = data.history_count ?? 0;
- }
- const flat = (Array.isArray(data.history) ? data.history : [])
- .flatMap((group) => (Array.isArray(group.reports) ? group.reports : []));
- const start = historyList.value.length;
- const mapped = flat.map((item, idx) => mapReportItem(item, start + idx));
- historyList.value = historyList.value.concat(mapped);
- historyPage.value = nextPage;
- historyFinished.value =
- !data.has_more || (data.total_pages && nextPage >= data.total_pages);
- } catch (e) {
- // 出错即停止,避免 van-list 死循环重试
- historyFinished.value = true;
- } finally {
- historyLoading.value = false;
- }
- };
- /** 进入 / 再次激活:重置分页并由 van-list 触发首屏加载 */
- const resetAndLoad = () => {
- historyList.value = [];
- historyPage.value = 0;
- historyFinished.value = false;
- historyLoading.value = true; // 先占位,防止 van-list 重复触发首屏
- latestReports.value = [];
- historyCount.value = 0;
- loadHistoryPage();
- };
- onMounted(resetAndLoad);
- onActivated(resetAndLoad);
- </script>
- <style lang="scss" scoped>
- .report-panel {
- .report-section--history {
- margin-top: 10px;
- }
- .report-section {
- & + & {
- margin-top: 20px;
- }
- &__title {
- margin-bottom: 10px;
- font-size: 16px;
- font-weight: 500;
- color: #fff;
- }
- &__head {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 8px;
- margin-bottom: 10px;
- .report-section__title {
- margin-bottom: 0;
- }
- }
- &__meta {
- flex-shrink: 0;
- font-size: 12px;
- color: rgba(255, 255, 255, 0.5);
- .report-section__meta-count {
- color: rgba(255, 255, 255, 0.9);
- font-weight: 600;
- }
- }
- }
- .risk-badge {
- flex-shrink: 0;
- height: 20px;
- background: rgba(107, 52, 18, 0.4);
- padding: 0 6px;
- border: 1px solid rgba(224, 122, 46, 0.4);
- border-radius: 4px;
- color: rgba(255, 159, 90, 1);
- font-size: 12px;
- box-sizing: border-box;
- line-height: 20px;
- }
- .report-empty {
- padding: 20px 0;
- text-align: center;
- font-size: 13px;
- color: rgba(255, 255, 255, 0.35);
- }
- // ---------- 最新报告卡片 ----------
- .latest-card {
- padding: 12px;
- border-radius: 12px;
- border: 1px solid rgba(255, 212, 137, 0.16);
- background: radial-gradient(80% 80% at 90% 0%, rgba(255, 212, 137, 0.12) 0%, rgba(255, 212, 137, 0) 100%);
- box-sizing: border-box;
- & + & {
- margin-top: 12px;
- }
- &__header {
- display: flex;
- align-items: flex-start;
- justify-content: space-between;
- gap: 8px;
- }
- &__header-left {
- display: flex;
- align-items: center;
- gap: 11px;
- min-width: 0;
- }
- &__type-icon {
- width: 35px;
- height: 35px;
- border-radius: 8px;
- background: rgba(255, 255, 255, 0.05);
- border: 1px solid rgba(255, 255, 255, 0.12);
- color: rgba(255, 255, 255, 0.8);
- display: flex;
- align-items: center;
- justify-content: center;
- flex-shrink: 0;
- font-size: 18px;
- }
- &__type-meta {
- min-width: 0;
- }
- &__type-name {
- font-size: 12px;
- color: rgba(255, 255, 255, 0.6);
- line-height: 18px;
- }
- &__date {
- font-size: 12px;
- font-weight: 600;
- color: rgba(255, 255, 255, 0.9);
- line-height: 16px;
- }
- &__subject {
- margin-top: 12px;
- font-size: 16px;
- color: #fff;
- line-height: 24px;
- }
- &__conclusion {
- margin-top: 7px;
- padding: 7px 14px;
- border-radius: 12px;
- background: rgba(255, 255, 255, 0.05);
- box-sizing: border-box;
- position: relative;
- &::after {
- content: "";
- position: absolute;
- left: 0;
- top: 12px;
- width: 2px;
- height: calc(100% - 24px);
- background: rgba(255, 255, 255, 0.3);
- }
- }
- &__conclusion-label {
- font-size: 12px;
- color: rgba(255, 255, 255, 0.5);
- line-height: 18px;
- }
- &__conclusion-text {
- margin-top: 4px;
- font-size: 14px;
- line-height: 20px;
- color: rgba(255, 255, 255, 1);
- word-break: break-all;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 3;
- overflow: hidden;
- }
- &__evidence {
- margin-top: 12px;
- display: flex;
- align-items: center;
- gap: 12px;
- }
- &__avatars {
- display: flex;
- align-items: center;
- flex-shrink: 0;
- gap: 4px;
- }
- &__avatar {
- width: 36px;
- height: 36px;
- border-radius: 8px;
- object-fit: cover;
- // margin-left: -6px;
- background: #2a2a2c;
- &:first-child {
- margin-left: 0;
- }
- }
- &__avatar-more {
- width: 36px;
- height: 36px;
- border-radius: 8px;
- background: linear-gradient(135deg, #22211F 0%, #121214 100%);
- color: rgba(255, 255, 255, 0.6);
- font-size: 12px;
- font-weight: 600;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- &__evidence-text {
- min-width: 0;
- font-size: 12px;
- line-height: 16px;
- color: rgba(255, 255, 255, 0.4);
- em {
- font-style: normal;
- color: #fff;
- font-weight: 500;
- }
- }
- &__footer {
- margin-top: 12px;
- display: flex;
- align-items: center;
- gap: 8px;
- }
- &__share {
- flex-shrink: 0;
- height: 32px;
- padding: 0 23px;
- border-radius: 8px;
- background: rgba(255, 255, 255, 0.05);
- color: rgba(255, 255, 255, 0.8);
- font-size: 12px;
- display: flex;
- align-items: center;
- gap: 8px;
- box-sizing: border-box;
- }
- &__detail {
- flex: 1;
- height: 32px;
- border-radius: 8px;
- background: linear-gradient(90deg, #FFEBC9 0%, #FFCA6D 100%);
- color: #1a1408;
- font-size: 14px;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 4px;
- }
- }
- // ---------- 报告生成中 ----------
- .generating-card {
- margin-top: 10px;
- padding: 14px;
- border-radius: 12px;
- border: 1px dashed rgba(255, 255, 255, 0.2);
- background: rgba(255, 255, 255, 0.03);
- display: flex;
- align-items: center;
- gap: 12px;
- box-sizing: border-box;
- &__spinner {
- width: 24px;
- height: 24px;
- flex-shrink: 0;
- border-radius: 50%;
- border: 2px solid rgba(255, 255, 255, 0.12);
- border-top-color: rgba(255, 212, 137, 1);
- animation: report-spin 0.9s linear infinite;
- box-sizing: border-box;
- }
- &__text {
- min-width: 0;
- }
- &__title {
- font-size: 14px;
- font-weight: 500;
- color: #fff;
- line-height: 20px;
- }
- &__desc {
- margin-top: 2px;
- font-size: 12px;
- color: rgba(255, 255, 255, 0.4);
- line-height: 16px;
- .generating-card__desc-count {
- font-style: normal;
- color: #fff;
- font-weight: 600;
- }
- }
- }
- @keyframes report-spin {
- to {
- transform: rotate(360deg);
- }
- }
- .history-card + .history-card {
- margin-top: 12px;
- }
- .history-month + .history-month {
- margin-top: 14px;
- }
- // ---------- 历史报告 ----------
- .history-month {
- &__label {
- display: flex;
- align-items: center;
- gap: 8px;
- margin-bottom: 8px;
- font-size: 12px;
- color: rgba(255, 255, 255, 0.5);
- }
- &__line {
- flex: 1;
- height: 1px;
- background: rgba(255, 255, 255, 0.08);
- }
- }
- .history-card {
- padding: 1px;
- border-radius: 12px;
- background: linear-gradient(0deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.12)),
- linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 25%);
- &-wrap {
- display: flex;
- gap: 10px;
- padding: 10px;
- background: linear-gradient(180deg, #1A191D 0%, #121216 100%);
- border-radius: 12px;
- }
- & + & {
- margin-top: 8px;
- }
- &__cover {
- width: 82px;
- height: 93px;
- flex-shrink: 0;
- border-radius: 8px;
- object-fit: cover;
- background: rgba(255, 255, 255, 0.06);
- }
- &__body {
- flex: 1;
- min-width: 0;
- display: flex;
- flex-direction: column;
- }
- &__top {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 6px;
- }
- &__type {
- display: flex;
- align-items: center;
- gap: 3px;
- min-width: 0;
- font-size: 12px;
- border-radius: 4px;
- padding: 0 6px;
- height: 19px;
- background: rgba(255, 255, 255, 0.05);
- color: rgba(255, 255, 255, 0.6);
- border: 1px solid rgba(255, 255, 255, 0.12);
- .el-icon {
- font-size: 12px;
- flex-shrink: 0;
- }
- }
- &__title {
- margin-top: 6px;
- font-size: 16px;
- color: #fff;
- line-height: 24px;
- }
- &__desc {
- margin-top: 2px;
- font-size: 12px;
- color: rgba(255, 255, 255, 0.6);
- line-height: 18px;
- }
- &__line {
- margin: 4px 0;
- height: 1px;
- width: 100%;
- background: rgba(255, 255, 255, 0.06);
- }
- &__bottom {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 6px;
- }
- &__time {
- display: flex;
- align-items: center;
- gap: 5px;
- font-size: 12px;
- font-weight: 600;
- color: rgba(255, 255, 255, 0.6);
- .el-icon {
- font-size: 12px;
- }
- }
- &__arrow {
- font-size: 12px;
- color: rgba(255, 255, 255, 0.4);
- }
- }
- }
- </style>
|