index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class="home-index" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
  3. <img class="banner" src="@/assets/img/home/banner.png" alt="" />
  4. <!-- 天气遮罩 -->
  5. <div class="weather-mask" v-show="isExpanded"></div>
  6. <!-- 天气 -->
  7. <weather-info class="weather-info" @weatherExpanded="weatherExpanded" :isGarden="false"></weather-info>
  8. <div class="farm-monitor-container">
  9. <div class="farm-monitor-left" @click="handleCardClick(monitorCards.left)">
  10. <div class="title">{{ monitorCards.left.title }}</div>
  11. <div class="content">{{ monitorCards.left.content }}</div>
  12. <div class="arrow">
  13. <el-icon class="icon"><ArrowRightBold /></el-icon>
  14. </div>
  15. </div>
  16. <div class="farm-monitor-right">
  17. <div
  18. v-for="(item, index) in monitorCards.right"
  19. :key="index"
  20. class="right-item"
  21. :class="{ expert: index === 1 }"
  22. @click="handleCardClick(item)"
  23. >
  24. <div class="title">
  25. <span>{{ item.title }}</span>
  26. <el-icon class="icon"><ArrowRightBold /></el-icon>
  27. </div>
  28. <div class="content">{{ item.content }}</div>
  29. </div>
  30. </div>
  31. </div>
  32. <AgriculturalDynamics />
  33. </div>
  34. <!-- 创建农场弹窗 -->
  35. <popup v-model:show="showFarmPopup" round class="create-farm-popup">
  36. <template v-if="farmPopupType === 'create'">
  37. <img class="create-farm-icon" src="@/assets/img/home/create-farm-icon.png" alt="" />
  38. <div class="create-farm-text">
  39. <div>您当前还没有农场</div>
  40. <div>请先创建农场</div>
  41. </div>
  42. </template>
  43. <template v-else>
  44. <img class="farm-check-icon" src="@/assets/img/home/right.png" alt="">
  45. <div class="create-farm-text success-text">农场创建成功</div>
  46. </template>
  47. <div class="create-farm-btn" @click="handleBtn">{{ farmPopupType === 'create' ? '去创建农场' : '我知道了' }}</div>
  48. </popup>
  49. <!-- 问题提醒 -->
  50. <problem-reminder></problem-reminder>
  51. </template>
  52. <script setup>
  53. import { ref, computed, onMounted, onActivated } from "vue";
  54. import { useStore } from "vuex";
  55. import { Popup } from "vant";
  56. import weatherInfo from "@/components/weatherInfo.vue";
  57. import AgriculturalDynamics from "./components/AgriculturalDynamics.vue";
  58. import { useRouter, useRoute } from "vue-router";
  59. import wx from "weixin-js-sdk";
  60. import problemReminder from "./components/problemReminder.vue";
  61. const store = useStore();
  62. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  63. const router = useRouter();
  64. const route = useRoute();
  65. const showFarmPopup = ref(false);
  66. const farmPopupType = ref("create");
  67. // 监测卡片数据
  68. const monitorCards = ref({
  69. left: {
  70. title: "农场监测",
  71. content: "实时监测农场环境和作物生长情况",
  72. route: "/monitor",
  73. },
  74. right: [
  75. {
  76. title: "病虫识别",
  77. content: "智能识别病虫害,提供防治建议",
  78. route: "/pest",
  79. },
  80. {
  81. title: "专家咨询",
  82. content: "专业农技专家在线解答疑问",
  83. route: "/chat_frame?userId=81881&name=专家1",
  84. },
  85. ],
  86. });
  87. // 卡片点击事件
  88. const handleCardClick = (card) => {
  89. // showFarmPopup.value = true;
  90. if(card.route === "/pest"){
  91. const dropdownGardenItem = ref({
  92. organId:766,
  93. periodId:1,
  94. wktVal:'wktVal',
  95. address:'address',
  96. district:'district',
  97. name:'荔博园',
  98. });
  99. wx.miniProgram.navigateTo({
  100. url: `/pages/subPages/new_recognize/index?gardenData=${JSON.stringify(dropdownGardenItem.value)}`,
  101. });
  102. }else{
  103. router.push(card.route);
  104. }
  105. };
  106. const handleBtn = () => {
  107. if(farmPopupType.value === 'create'){
  108. router.push("/create_farm?isReload=true&from=home");
  109. }
  110. showFarmPopup.value = false;
  111. }
  112. onActivated(() => {
  113. // 检测是否从创建农场页面成功返回
  114. if (route.query.showSuccess === 'true') {
  115. farmPopupType.value = 'success';
  116. showFarmPopup.value = true;
  117. // 清除URL参数,避免刷新页面时再次显示弹窗
  118. router.replace({
  119. path: '/home',
  120. query: { reload: route.query.reload }
  121. });
  122. }
  123. });
  124. const isExpanded = ref(false);
  125. const weatherExpanded = (isExpandedValue) => {
  126. isExpanded.value = isExpandedValue;
  127. };
  128. </script>
  129. <style scoped lang="scss">
  130. .home-index {
  131. width: 100%;
  132. height: 100vh;
  133. overflow: auto;
  134. position: relative;
  135. .banner {
  136. width: 100%;
  137. height: 200px;
  138. position: relative;
  139. z-index: 1;
  140. }
  141. .weather-mask {
  142. position: fixed;
  143. top: 0;
  144. left: 0;
  145. width: 100%;
  146. height: 100%;
  147. background-color: rgba(0, 0, 0, 0.52);
  148. z-index: 2;
  149. }
  150. .weather-info {
  151. width: calc(100% - 20px);
  152. position: absolute;
  153. top: calc(200px - 28px);
  154. left: 10px;
  155. z-index: 3;
  156. }
  157. .farm-monitor-container {
  158. padding-top: 60px;
  159. display: flex;
  160. align-items: center;
  161. gap: 7px;
  162. margin: 10px;
  163. height: 170px;
  164. .farm-monitor-left,
  165. .farm-monitor-right {
  166. .title {
  167. font-size: 16px;
  168. color: #1d2129;
  169. font-weight: 500;
  170. .icon {
  171. font-size: 12px;
  172. margin-left: 2px;
  173. }
  174. }
  175. .content {
  176. margin-top: 6px;
  177. font-size: 12px;
  178. color: rgba(29, 33, 41, 0.5);
  179. line-height: 1.5;
  180. }
  181. .arrow {
  182. border-radius: 5px;
  183. background: #fff;
  184. display: flex;
  185. align-items: center;
  186. justify-content: center;
  187. width: 34px;
  188. height: 25px;
  189. margin-top: 10px;
  190. font-size: 11px;
  191. }
  192. }
  193. .farm-monitor-left {
  194. flex: 1;
  195. height: 100%;
  196. padding: 25px 10px;
  197. box-sizing: border-box;
  198. background: url("@/assets/img/home/farm-bg-1.png") no-repeat center center / 100% 100%;
  199. }
  200. .farm-monitor-right {
  201. flex: 1;
  202. height: 100%;
  203. display: flex;
  204. flex-direction: column;
  205. gap: 7px;
  206. .right-item {
  207. padding: 10px;
  208. box-sizing: border-box;
  209. display: flex;
  210. flex-direction: column;
  211. justify-content: center;
  212. flex: 1;
  213. background: url("@/assets/img/home/farm-bg-2.png") no-repeat center center / 100% 100%;
  214. }
  215. .expert {
  216. background: url("@/assets/img/home/farm-bg-3.png") no-repeat center center / 100% 100%;
  217. }
  218. }
  219. }
  220. }
  221. .create-farm-popup {
  222. width: 75%;
  223. padding: 28px 28px 20px;
  224. display: flex;
  225. flex-direction: column;
  226. align-items: center;
  227. justify-content: center;
  228. .create-farm-icon{
  229. width: 40px;
  230. height: 40px;
  231. margin-bottom: 12px;
  232. }
  233. .farm-check-icon{
  234. width: 68px;
  235. height: 68px;
  236. margin-bottom: 12px;
  237. }
  238. .create-farm-text{
  239. font-size: 18px;
  240. font-weight: 500;
  241. margin-bottom: 32px;
  242. text-align: center;
  243. &.success-text{
  244. font-size: 23px;
  245. font-weight: 400;
  246. }
  247. }
  248. .create-farm-btn{
  249. width: 100%;
  250. box-sizing: border-box;
  251. padding: 8px;
  252. border-radius: 25px;
  253. font-size: 16px;
  254. background: #2199F8;
  255. color: #fff;
  256. text-align: center;
  257. }
  258. }
  259. </style>