index.vue 15 KB

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