index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div class="home-index" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
  3. <img class="banner" @click="handleBannerClick" :src="bannerObj?.media?.[0]" alt="" />
  4. <!-- 天气遮罩 -->
  5. <div class="weather-mask" v-show="isExpanded" @click="handleMaskClick"></div>
  6. <!-- 天气 -->
  7. <weather-info ref="weatherInfoRef" class="weather-info" @weatherExpanded="weatherExpanded" :isGarden="false" @changeGarden="changeGarden"></weather-info>
  8. <div class="farm-monitor-container" :class="{ 'container-role': curRole == 2 }">
  9. <div class="farm-monitor-left" @click="handleCardClick(monitorCards.left)">
  10. <div class="title">
  11. <span>{{ monitorCards.left.title }}</span>
  12. <el-icon v-if="curRole == 2" class="icon"><ArrowRightBold /></el-icon>
  13. </div>
  14. <div class="content">{{ monitorCards.left.content }}</div>
  15. <div class="arrow" v-if="curRole != 2">
  16. <el-icon class="icon"><ArrowRightBold /></el-icon>
  17. </div>
  18. </div>
  19. <div class="farm-monitor-right">
  20. <div
  21. v-for="(item, index) in monitorCards.right"
  22. :key="index"
  23. class="right-item"
  24. :class="{ expert: index === 1 }"
  25. @click="handleCardClick(item)"
  26. >
  27. <div class="title">
  28. <span>{{ item.title }}</span>
  29. <el-icon class="icon"><ArrowRightBold /></el-icon>
  30. </div>
  31. <div class="content">{{ item.content }}</div>
  32. </div>
  33. </div>
  34. </div>
  35. <AgriculturalDynamics />
  36. </div>
  37. <!-- 创建农场弹窗 -->
  38. <tip-popup
  39. v-model:show="showFarmPopup"
  40. :type="farmPopupType"
  41. :text="farmPopupType === 'create' ? ['您当前还没有农场', '请先创建农场'] : '农场创建成功'"
  42. @confirm="handleBtn"
  43. />
  44. <!-- 问题提醒 -->
  45. <problem-reminder></problem-reminder>
  46. </template>
  47. <script setup>
  48. import { ref, computed, onActivated } from "vue";
  49. import { useStore } from "vuex";
  50. import weatherInfo from "@/components/weatherInfo.vue";
  51. import AgriculturalDynamics from "./components/AgriculturalDynamics.vue";
  52. import { useRouter, useRoute } from "vue-router";
  53. import wx from "weixin-js-sdk";
  54. import problemReminder from "./components/problemReminder.vue";
  55. import { ElMessage } from "element-plus";
  56. import tipPopup from "@/components/popup/tipPopup.vue";
  57. const curRole = localStorage.getItem("SET_USER_CUR_ROLE");
  58. const store = useStore();
  59. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  60. const router = useRouter();
  61. const route = useRoute();
  62. const showFarmPopup = ref(false);
  63. const farmPopupType = ref("create");
  64. const gardenId = ref(null);
  65. const isGarden = ref(false);
  66. const changeGarden = ({id}) => {
  67. gardenId.value = id;
  68. getExpertByFarmId();
  69. }
  70. const expertInfo = ref({});
  71. const getExpertByFarmId = () => {
  72. VE_API.home.getExpertByFarmId({ farmId: gardenId.value }).then(({ data }) => {
  73. expertInfo.value = data || {};
  74. sessionStorage.setItem('expertId',data.appUserId);
  75. });
  76. }
  77. // 监测卡片数据
  78. const monitorCards = ref({
  79. left: {
  80. title: "农场监测",
  81. content: "实时监测农场状态",
  82. route: "/monitor",
  83. },
  84. right: [
  85. {
  86. title: "病虫识别",
  87. content: "精准识别病虫",
  88. route: "/pest",
  89. },
  90. {
  91. title: "专家咨询",
  92. content: "专家多年经验指导",
  93. route: "/chat_frame",
  94. },
  95. ],
  96. });
  97. // 卡片点击事件
  98. const handleCardClick = (card) => {
  99. if(curRole == 0){
  100. if(!isGarden.value){
  101. showFarmPopup.value = true;
  102. return;
  103. }
  104. }
  105. if (card.route === "/pest") {
  106. if(curRole == 2){
  107. ElMessage.warning("该功能正在升级中,敬请期待");
  108. }else{
  109. const dropdownGardenItem = ref({
  110. organId: 766,
  111. periodId: 1,
  112. wktVal: "wktVal",
  113. address: "address",
  114. district: "district",
  115. name: "荔博园",
  116. });
  117. wx.miniProgram.navigateTo({
  118. url: `/pages/subPages/new_recognize/index?gardenData=${JSON.stringify(dropdownGardenItem.value)}`,
  119. });
  120. }
  121. } else {
  122. if (card.route === "/chat_frame") {
  123. router.push(`/chat_frame?userId=${expertInfo.value.appUserId}`);
  124. } else {
  125. router.push(card.route);
  126. }
  127. }
  128. };
  129. const handleBtn = () => {
  130. if (farmPopupType.value === "create") {
  131. router.push("/create_farm?isReload=true&from=home");
  132. }
  133. };
  134. onActivated(() => {
  135. getBannerList();
  136. isGarden.value = Boolean(localStorage.getItem('isGarden'));
  137. // 检测是否从创建农场页面成功返回
  138. if (route.query.showSuccess === "true") {
  139. farmPopupType.value = "success";
  140. showFarmPopup.value = true;
  141. // 清除URL参数,避免刷新页面时再次显示弹窗
  142. router.replace({
  143. path: "/home",
  144. query: { reload: route.query.reload },
  145. });
  146. }
  147. if (curRole == 2) {
  148. monitorCards.value.left = {
  149. title: "新增客户",
  150. content: "实时监测农场状态",
  151. route: "/create_farm?type=client&isReload=true&from=home",
  152. };
  153. monitorCards.value.right = [
  154. {
  155. title: "病虫识别",
  156. content: "精准识别病虫",
  157. route: "/pest",
  158. },
  159. ];
  160. }
  161. });
  162. const bannerObj = ref({});
  163. const getBannerList = () => {
  164. const params = {
  165. page: 1,
  166. limit: 1,
  167. topicId: 5,
  168. };
  169. VE_API.home.warningPageList(params).then(({ data }) => {
  170. bannerObj.value = data[0] || {};
  171. });
  172. }
  173. const isExpanded = ref(false);
  174. const weatherInfoRef = ref(null);
  175. const weatherExpanded = (isExpandedValue) => {
  176. isExpanded.value = isExpandedValue;
  177. };
  178. // 点击遮罩时收起天气
  179. const handleMaskClick = () => {
  180. if (weatherInfoRef.value && weatherInfoRef.value.toggleExpand) {
  181. weatherInfoRef.value.toggleExpand();
  182. }
  183. };
  184. const handleBannerClick = () => {
  185. router.push(`/warning_detail?id=${bannerObj.value.id}`);
  186. }
  187. </script>
  188. <style scoped lang="scss">
  189. .home-index {
  190. width: 100%;
  191. height: 100vh;
  192. overflow: auto;
  193. position: relative;
  194. .banner {
  195. width: 100%;
  196. height: 200px;
  197. object-fit: cover;
  198. position: relative;
  199. z-index: 1;
  200. }
  201. .weather-mask {
  202. position: fixed;
  203. top: 0;
  204. left: 0;
  205. width: 100%;
  206. height: 100%;
  207. background-color: rgba(0, 0, 0, 0.52);
  208. z-index: 2;
  209. }
  210. .weather-info {
  211. width: calc(100% - 20px);
  212. position: absolute;
  213. top: calc(200px - 28px);
  214. left: 10px;
  215. z-index: 3;
  216. }
  217. .farm-monitor-container {
  218. padding-top: 60px;
  219. display: flex;
  220. align-items: center;
  221. gap: 7px;
  222. margin: 10px;
  223. height: 170px;
  224. .farm-monitor-left,
  225. .farm-monitor-right {
  226. .title {
  227. font-size: 16px;
  228. color: #1d2129;
  229. font-weight: 500;
  230. .icon {
  231. font-size: 12px;
  232. margin-left: 2px;
  233. }
  234. }
  235. .content {
  236. margin-top: 6px;
  237. font-size: 12px;
  238. color: rgba(29, 33, 41, 0.5);
  239. line-height: 1.5;
  240. }
  241. .arrow {
  242. border-radius: 5px;
  243. background: #fff;
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. width: 34px;
  248. height: 25px;
  249. margin-top: 10px;
  250. font-size: 11px;
  251. }
  252. }
  253. .farm-monitor-left {
  254. flex: 1;
  255. height: 100%;
  256. padding: 25px 10px;
  257. box-sizing: border-box;
  258. background: url("@/assets/img/home/farm-bg-1.png") no-repeat center center / 100% 100%;
  259. }
  260. .farm-monitor-right {
  261. flex: 1;
  262. height: 100%;
  263. display: flex;
  264. flex-direction: column;
  265. gap: 7px;
  266. .right-item {
  267. padding: 10px;
  268. box-sizing: border-box;
  269. display: flex;
  270. flex-direction: column;
  271. justify-content: center;
  272. flex: 1;
  273. background: url("@/assets/img/home/farm-bg-2.png") no-repeat center center / 100% 100%;
  274. }
  275. .expert {
  276. background: url("@/assets/img/home/farm-bg-3.png") no-repeat center center / 100% 100%;
  277. }
  278. }
  279. &.container-role{
  280. height: 104px;
  281. .farm-monitor-left{
  282. background: url("@/assets/img/home/farm-bg-4.png") no-repeat center center / 100% 100%;
  283. }
  284. .farm-monitor-right {
  285. .right-item {
  286. background: url("@/assets/img/home/farm-bg-5.png") no-repeat center center / 100% 100%;
  287. }
  288. }
  289. }
  290. }
  291. }
  292. </style>