AgriculturalDynamics.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="agricultural-dynamics">
  3. <!-- 标题 -->
  4. <div class="title">农情动态</div>
  5. <!-- 标签页导航 -->
  6. <div class="tab-nav">
  7. <div
  8. v-for="tab in tabs"
  9. :key="tab.value"
  10. class="tab-item"
  11. :class="{ active: activeTab === tab.value }"
  12. @click="handleTabClick(tab.value)"
  13. >
  14. {{ tab.label }}
  15. </div>
  16. </div>
  17. <!-- 内容区域 -->
  18. <div class="content-area">
  19. <!-- 气象预警内容/农事预警内容 -->
  20. <div v-if="activeTab !== 4" class="content-list">
  21. <div v-for="(item, index) in warningList" :key="index" class="content-item" @click="handleItem(item)">
  22. <div class="item-image">
  23. <img :src="item.media[0]" />
  24. </div>
  25. <div class="item-content">
  26. <div class="item-text van-ellipsis" v-html="item.content"></div>
  27. <div class="item-date">{{ item.createTime.slice(0, 10) }}</div>
  28. </div>
  29. </div>
  30. </div>
  31. <!-- 专家问答内容 -->
  32. <div v-else class="content-list expert-qa">
  33. <div v-for="(item, index) in expertQAList" :key="index" class="qa-item" @click="handleItem(item)">
  34. <div class="question-header">
  35. <img class="question-icon" src="@/assets/img/home/ask-icon.png" alt="" />
  36. <div class="question-title">{{ item.title }}</div>
  37. </div>
  38. <div class="expert-info">
  39. <el-avatar class="expert-avatar" :size="16" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
  40. <div class="expert-details">
  41. <span class="expert-name">{{ item.name }}</span>
  42. <span class="expert-title">{{ item.expertTitle }}</span>
  43. <span class="qa-date">{{ item.createTime.slice(0, 10) }}</span>
  44. </div>
  45. </div>
  46. <div class="answer-content">
  47. {{ item.content }}
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </template>
  54. <script setup>
  55. import { ref, onMounted } from "vue";
  56. import { useRouter } from "vue-router";
  57. const router = useRouter();
  58. const activeTab = ref(2);
  59. const tabs = [
  60. { label: "气象预警", value: 2 },
  61. { label: "农事预警", value: 3 },
  62. { label: "专家问答", value: 4 },
  63. ];
  64. // 气象/农事预警数据
  65. const warningList = ref([]);
  66. // 专家问答数据
  67. const expertQAList = ref([]);
  68. const handleTabClick = (value) => {
  69. activeTab.value = value;
  70. getWarningList();
  71. };
  72. const handleItem = () => {
  73. if (activeTab.value === 4) {
  74. router.push("/expert_detail");
  75. } else {
  76. router.push("/warning_detail");
  77. }
  78. };
  79. onMounted(() => {
  80. getWarningList();
  81. });
  82. const getWarningList = () => {
  83. const params = {
  84. page: 1,
  85. limit: 10,
  86. topicId: activeTab.value,
  87. };
  88. VE_API.home.warningPageList(params).then((res) => {
  89. if(activeTab.value === 4){
  90. expertQAList.value = res.data || [];
  91. }else{
  92. warningList.value = res.data || [];
  93. }
  94. });
  95. };
  96. </script>
  97. <style scoped lang="scss">
  98. .agricultural-dynamics {
  99. padding: 0 10px;
  100. .title {
  101. font-size: 16px;
  102. font-weight: bold;
  103. color: #1d2129;
  104. margin-bottom: 16px;
  105. }
  106. .tab-nav {
  107. display: flex;
  108. margin-bottom: 16px;
  109. .tab-item {
  110. margin-right: 20px;
  111. padding-bottom: 6px;
  112. &.active {
  113. color: #2199f8;
  114. border-bottom: 2px solid #2199f8;
  115. }
  116. }
  117. }
  118. .content-area {
  119. .content-list {
  120. .content-item {
  121. display: flex;
  122. align-items: center;
  123. overflow-x: hidden;
  124. .item-image {
  125. width: 114px;
  126. height: 74px;
  127. margin-right: 12px;
  128. flex-shrink: 0;
  129. img {
  130. width: 100%;
  131. height: 100%;
  132. object-fit: cover;
  133. border-radius: 8px;
  134. }
  135. }
  136. .item-content {
  137. flex: 1;
  138. display: flex;
  139. flex-direction: column;
  140. justify-content: space-between;
  141. height: 68px;
  142. max-width: calc(100% - 130px);
  143. .item-text {
  144. color: #1d2129;
  145. ::v-deep {
  146. p{
  147. margin: 0;
  148. }
  149. }
  150. }
  151. .item-date {
  152. color: #86909c;
  153. font-size: 13px;
  154. }
  155. }
  156. }
  157. .content-item + .content-item {
  158. margin-top: 12px;
  159. }
  160. // 专家问答样式
  161. &.expert-qa {
  162. .qa-item {
  163. padding: 0 12px;
  164. .question-header {
  165. display: flex;
  166. align-items: center;
  167. margin-bottom: 6px;
  168. gap: 8px;
  169. .question-icon {
  170. width: 20px;
  171. height: 20px;
  172. }
  173. .question-title {
  174. font-size: 16px;
  175. font-weight: 600;
  176. }
  177. }
  178. .expert-info {
  179. display: flex;
  180. align-items: center;
  181. gap: 6px;
  182. margin-bottom: 8px;
  183. .expert-details {
  184. display: flex;
  185. align-items: center;
  186. gap: 6px;
  187. font-size: 13px;
  188. color: #666666;
  189. }
  190. }
  191. .answer-content {
  192. color: #333333;
  193. .font-bold {
  194. font-weight: 500;
  195. }
  196. }
  197. }
  198. .qa-item + .qa-item {
  199. margin-top: 16px;
  200. }
  201. }
  202. }
  203. }
  204. }
  205. </style>