index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <div class="monitor-index" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
  3. <!-- 天气遮罩 -->
  4. <div class="weather-mask" v-show="isExpanded"></div>
  5. <!-- 天气 -->
  6. <weather-info
  7. ref="weatherInfoRef"
  8. class="weather-info"
  9. @weatherExpanded="weatherExpanded"
  10. @changeGarden="changeGarden"
  11. :isGarden="true"
  12. ></weather-info>
  13. <!-- 操作按钮 -->
  14. <div class="operation-button">
  15. <div class="button-group">
  16. <div class="button-item" @click="toFarmInfo">
  17. <img class="button-icon" src="@/assets/img/tab_bar/home-active.png" alt="" />
  18. <span>基本信息</span>
  19. </div>
  20. <div class="button-item" @click="handlePage('/farm_photo')">
  21. <img class="button-icon" src="@/assets/img/home/photo-icon.png" alt="" />
  22. <span>农场相册</span>
  23. </div>
  24. </div>
  25. <badge dot :offset="[-4, 5]" @click="handlePage('/message_list')">
  26. <div class="add-farm-button">
  27. <img class="icon" src="@/assets/img/monitor/notice.png" alt="" />
  28. <span>农场消息</span>
  29. </div>
  30. </badge>
  31. </div>
  32. <!-- 功能卡片网格 -->
  33. <div class="function-cards">
  34. <div
  35. v-for="(card, index) in functionCards"
  36. :key="index"
  37. class="function-card"
  38. @click="handleCardClick(card)"
  39. >
  40. <div class="card-title">{{ card.title }}</div>
  41. <img :src="require(`@/assets/img/monitor/grid-${index + 1}.png`)" :alt="card.title" />
  42. <div class="card-status" :class="card.className" v-if="card.status">
  43. {{ card.status }}
  44. </div>
  45. </div>
  46. </div>
  47. <!-- 实时播报 -->
  48. <div class="realtime-broadcast">
  49. <div class="broadcast-header">
  50. <div class="header-left">
  51. <span class="broadcast-title">实时播报</span>
  52. <!-- <div class="broadcast-action" :class="{ speaking: isSpeaking }" @click="handleBroadcast">
  53. <img class="speaker-icon" src="@/assets/img/monitor/speaker.png" alt="播报" />
  54. <span class="broadcast-text">{{ isSpeaking ? '停止播报' : '点击播报' }}</span>
  55. </div> -->
  56. </div>
  57. </div>
  58. <list
  59. v-model:loading="loading"
  60. :finished="finished"
  61. finished-text="暂无更多播报"
  62. @load="onLoad"
  63. class="broadcast-list"
  64. >
  65. <div
  66. v-for="(item, index) in broadcastList"
  67. :key="index"
  68. class="broadcast-item"
  69. >
  70. <div class="item-content">
  71. <div class="content-top">
  72. <div class="item-icon">
  73. <img src="@/assets/img/monitor/bell.png" alt="通知" />
  74. </div>
  75. <div class="item-title">{{ item.title }}</div>
  76. </div>
  77. <div class="item-status van-multi-ellipsis--l2">{{ item.content }}</div>
  78. </div>
  79. <div class="item-zone" v-if="item.regionId">
  80. <div class="point"></div>
  81. <span>{{ item.regionId }}</span>
  82. </div>
  83. </div>
  84. </list>
  85. </div>
  86. </div>
  87. <!-- 农场信息 -->
  88. <farm-info-popup ref="farmInfoRef" :farmId="gardenId"></farm-info-popup>
  89. </template>
  90. <script setup>
  91. import { ref, computed, onMounted, onUnmounted, onActivated } from "vue";
  92. import { useStore } from "vuex";
  93. import { Badge, List } from "vant";
  94. import weatherInfo from "@/components/weatherInfo.vue";
  95. import { useRouter, useRoute } from "vue-router";
  96. import farmInfoPopup from "../home/components/farmInfoPopup.vue";
  97. const store = useStore();
  98. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  99. const router = useRouter();
  100. const route = useRoute();
  101. const farmInfoRef = ref(null);
  102. const weatherInfoRef = ref(null);
  103. function toFarmInfo() {
  104. farmInfoRef.value.handleShow();
  105. }
  106. // 功能卡片数据
  107. const functionCards = ref([
  108. {
  109. title: "农事规划",
  110. route: "/plan",
  111. },
  112. {
  113. title: "农场报告",
  114. status: "最新",
  115. route: "/farm-report",
  116. className: "blue",
  117. },
  118. {
  119. title: "农事方案",
  120. route: "/agricultural_plan",
  121. },
  122. {
  123. title: "复核成效",
  124. status: "最新",
  125. route: "/review-results",
  126. className: "yellow",
  127. },
  128. ]);
  129. const getStayCount = () => {
  130. VE_API.monitor
  131. .getCountByStatusAndFarmId({
  132. farmId: gardenId.value,
  133. startStatus: 1,
  134. endStatus: 3,
  135. })
  136. .then((res) => {
  137. functionCards.value[0].status = null;
  138. if (res.data && res.data != 0) {
  139. functionCards.value[0].status = res.data + " 待完成";
  140. }
  141. });
  142. };
  143. // 实时播报数据
  144. const broadcastList = ref([]);
  145. const loading = ref(false);
  146. const finished = ref(false);
  147. const currentPage = ref(1);
  148. const pageSize = ref(10);
  149. const getBroadcastList = (page = 1, isLoadMore = false) => {
  150. loading.value = true;
  151. VE_API.monitor
  152. .broadcastPage({
  153. farmId: gardenId.value,
  154. limit: pageSize.value,
  155. page: page,
  156. })
  157. .then((res) => {
  158. const newData = res.data || [];
  159. if (isLoadMore) {
  160. broadcastList.value = [...broadcastList.value, ...newData];
  161. } else {
  162. broadcastList.value = newData;
  163. }
  164. // 判断是否还有更多数据
  165. if (newData.length < pageSize.value) {
  166. finished.value = true;
  167. }
  168. loading.value = false;
  169. })
  170. .catch(() => {
  171. loading.value = false;
  172. });
  173. };
  174. // 滚动加载更多
  175. const onLoad = () => {
  176. if (finished.value) return;
  177. currentPage.value += 1;
  178. getBroadcastList(currentPage.value, true);
  179. };
  180. // 卡片点击事件
  181. const handleCardClick = (card) => {
  182. const params = {
  183. farmId: gardenId.value,
  184. containerId: card.containerId,
  185. };
  186. router.push({
  187. path: card.route,
  188. query: params,
  189. });
  190. };
  191. // 播报相关事件
  192. const isSpeaking = ref(false);
  193. const speechSynthesis = window.speechSynthesis;
  194. const handleBroadcast = () => {
  195. if (isSpeaking.value) {
  196. // 如果正在播放,则停止
  197. speechSynthesis.cancel();
  198. isSpeaking.value = false;
  199. return;
  200. }
  201. // 构建播报文本
  202. let broadcastText = "实时播报:";
  203. if (broadcastList.value.length === 0) {
  204. broadcastText += "暂无更多播报";
  205. } else {
  206. broadcastList.value.forEach((item, index) => {
  207. broadcastText += `${index + 1}、${item.title}。${item.content}。`;
  208. });
  209. }
  210. // 创建语音合成对象
  211. const utterance = new SpeechSynthesisUtterance(broadcastText);
  212. // 设置语音参数
  213. utterance.lang = 'zh-CN';
  214. utterance.rate = 0.8; // 语速
  215. utterance.pitch = 1; // 音调
  216. utterance.volume = 1; // 音量
  217. // 播放开始事件
  218. utterance.onstart = () => {
  219. isSpeaking.value = true;
  220. };
  221. // 播放结束事件
  222. utterance.onend = () => {
  223. isSpeaking.value = false;
  224. };
  225. // 播放错误事件
  226. utterance.onerror = (event) => {
  227. isSpeaking.value = false;
  228. console.error("播报错误:", event.error);
  229. };
  230. // 开始播报
  231. speechSynthesis.speak(utterance);
  232. };
  233. // 组件激活时检查是否需要刷新农场列表
  234. onActivated(() => {
  235. weatherInfoRef.value.getFarmList();
  236. });
  237. // 组件卸载时停止语音播放
  238. onUnmounted(() => {
  239. if (isSpeaking.value) {
  240. speechSynthesis.cancel();
  241. isSpeaking.value = false;
  242. }
  243. });
  244. const isExpanded = ref(false);
  245. const weatherExpanded = (isExpandedValue) => {
  246. isExpanded.value = isExpandedValue;
  247. };
  248. const gardenId = ref(store.state.home.gardenId);
  249. const changeGarden = (id) => {
  250. gardenId.value = id;
  251. // 更新 store 中的状态
  252. store.commit('home/SET_GARDEN_ID', id);
  253. // 重置分页状态
  254. currentPage.value = 1;
  255. finished.value = false;
  256. broadcastList.value = [];
  257. getStayCount();
  258. getBroadcastList();
  259. };
  260. function handlePage(url) {
  261. router.push({
  262. path: url,
  263. });
  264. }
  265. </script>
  266. <style scoped lang="scss">
  267. .monitor-index {
  268. width: 100%;
  269. height: 100%;
  270. padding: 13px 10px;
  271. box-sizing: border-box;
  272. background-image: linear-gradient(250deg, #cbebff 0%, #dceffd 50%, #e7f3fd 100%);
  273. .weather-mask {
  274. position: fixed;
  275. top: 0;
  276. left: 0;
  277. width: 100%;
  278. height: 100%;
  279. background-color: rgba(0, 0, 0, 0.52);
  280. z-index: 2;
  281. }
  282. .weather-info {
  283. width: calc(100% - 20px);
  284. position: absolute;
  285. z-index: 3;
  286. }
  287. .operation-button {
  288. position: absolute;
  289. top: 117px;
  290. left: 12px;
  291. width: calc(100% - 24px);
  292. z-index: 1;
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. font-size: 12px;
  297. font-weight: 500;
  298. .button-group {
  299. display: flex;
  300. align-items: center;
  301. justify-content: space-between;
  302. .button-item {
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. gap: 4px;
  307. color: rgba(0, 0, 0, 0.8);
  308. background-color: #fff;
  309. border: 1px solid #f2f2f2;
  310. .button-icon {
  311. width: 13px;
  312. height: 13px;
  313. }
  314. }
  315. .button-item:first-child {
  316. margin-right: 10px;
  317. }
  318. }
  319. .add-farm-button {
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. gap: 4px;
  324. color: rgba(0, 0, 0, 0.8);
  325. background: rgba(33, 153, 248, 0.1);
  326. border: 1px solid #fff;
  327. .icon {
  328. width: 14px;
  329. height: 14px;
  330. }
  331. }
  332. .button-item,
  333. .add-farm-button {
  334. border-radius: 25px;
  335. padding: 8px 12px;
  336. }
  337. }
  338. .function-cards {
  339. display: grid;
  340. grid-template-columns: 1fr 1fr;
  341. gap: 10px;
  342. margin-top: 155px;
  343. .function-card {
  344. background: #fff;
  345. border-radius: 12px;
  346. padding: 20px 0;
  347. box-shadow: 0 1px 6px rgba(0, 0, 0, 0.05);
  348. position: relative;
  349. display: flex;
  350. align-items: center;
  351. justify-content: center;
  352. gap: 10px;
  353. img {
  354. width: 40px;
  355. height: 40px;
  356. }
  357. .card-title {
  358. font-size: 16px;
  359. font-weight: 500;
  360. color: #1d2129;
  361. }
  362. .card-status {
  363. position: absolute;
  364. top: -5px;
  365. right: 0;
  366. padding: 1px 4px;
  367. border-radius: 6px 8px 8px 2px;
  368. font-size: 11px;
  369. background: #2199f8;
  370. color: #fff;
  371. &.yellow {
  372. background: #fdcf4c;
  373. }
  374. &.blue {
  375. background: #8a87ff;
  376. }
  377. }
  378. }
  379. }
  380. .realtime-broadcast {
  381. margin-top: 10px;
  382. background: #fff;
  383. border-radius: 8px;
  384. box-sizing: border-box;
  385. padding: 12px;
  386. .broadcast-header {
  387. display: flex;
  388. align-items: center;
  389. margin-bottom: 4px;
  390. .header-left {
  391. display: flex;
  392. align-items: center;
  393. gap: 12px;
  394. .broadcast-title {
  395. font-size: 16px;
  396. font-weight: 600;
  397. color: #1d2129;
  398. }
  399. .broadcast-action {
  400. display: flex;
  401. align-items: center;
  402. gap: 4px;
  403. cursor: pointer;
  404. transition: all 0.3s ease;
  405. &:hover {
  406. opacity: 0.8;
  407. }
  408. .speaker-icon {
  409. width: 16px;
  410. height: 14px;
  411. transition: transform 0.3s ease;
  412. }
  413. .broadcast-text {
  414. color: #2199f8;
  415. font-size: 14px;
  416. }
  417. // 播放状态下的样式
  418. &.speaking {
  419. .speaker-icon {
  420. animation: pulse 1s infinite;
  421. }
  422. .broadcast-text {
  423. color: #ff4757;
  424. }
  425. }
  426. }
  427. @keyframes pulse {
  428. 0% { transform: scale(1); }
  429. 50% { transform: scale(1.1); }
  430. 100% { transform: scale(1); }
  431. }
  432. }
  433. }
  434. .broadcast-list {
  435. .broadcast-item {
  436. display: flex;
  437. align-items: center;
  438. justify-content: space-between;
  439. padding: 12px 0;
  440. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  441. &:last-child {
  442. border-bottom: none;
  443. }
  444. .item-content {
  445. width: calc(100% - 50px);
  446. .content-top {
  447. display: flex;
  448. align-items: center;
  449. }
  450. .item-icon {
  451. margin-right: 8px;
  452. background: rgba(255, 0, 0, 0.05);
  453. width: 26px;
  454. height: 26px;
  455. border-radius: 50%;
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. img {
  460. width: 18px;
  461. height: 12px;
  462. }
  463. }
  464. .item-title {
  465. color: #1d2129;
  466. }
  467. .item-status {
  468. margin-top: 3px;
  469. font-size: 13px;
  470. color: rgba(29, 33, 41, 0.5);
  471. .countdown {
  472. color: #ff7254;
  473. }
  474. }
  475. }
  476. .item-zone {
  477. background: rgba(241, 243, 246, 0.5);
  478. color: #7c7e81;
  479. font-size: 12px;
  480. padding: 3px 11px;
  481. border-radius: 25px;
  482. display: flex;
  483. align-items: center;
  484. gap: 8px;
  485. .point {
  486. width: 6px;
  487. height: 6px;
  488. border-radius: 50%;
  489. background: rgba(124, 126, 129, 0.5);
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. </style>