crossSectionSamplelineData.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div class="map-page">
  3. <!-- 错误提示 -->
  4. <div v-if="error" class="error-message">
  5. <i class="fa fa-exclamation-circle"></i> {{ error }}
  6. </div>
  7. <!-- 加载状态 -->
  8. <div v-if="loading" class="loading-state">
  9. <div class="spinner"></div>
  10. <p>数据加载中...</p>
  11. </div>
  12. <!-- 数据表格容器 -->
  13. <div v-else class="table-container">
  14. <table class="data-table">
  15. <!-- 表头 -->
  16. <thead>
  17. <tr>
  18. <th>断面编号</th>
  19. <th>所属河流</th>
  20. <th>断面位置</th>
  21. <th>所属区县</th>
  22. <th>Cd含量(ug/L)</th>
  23. <th>经度</th>
  24. <th>纬度</th>
  25. </tr>
  26. </thead>
  27. <!-- 表体(遍历数据) -->
  28. <tbody>
  29. <tr v-for="item in state.excelData" :key="item.id">
  30. <td>{{ item.id }}</td>
  31. <td>{{ item.river }}</td>
  32. <td>{{ item.location }}</td>
  33. <td>{{ item.district }}</td>
  34. <td>{{ item.cdValue }}</td>
  35. <td>{{ item.longitude.toFixed(6) }}</td> <!-- 保留6位小数 -->
  36. <td>{{ item.latitude.toFixed(6) }}</td>
  37. </tr>
  38. <!-- 空数据提示 -->
  39. <tr v-if="state.excelData.length === 0">
  40. <td colspan="7" class="empty-state">暂无数据</td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </div>
  45. </div>
  46. </template>
  47. <script setup>
  48. import { ref, reactive, onMounted } from 'vue'
  49. import { wgs84togcj02 } from 'coordtransform';
  50. // 状态管理
  51. const error = ref(null)
  52. const loading = ref(true)
  53. const state = reactive({
  54. excelData: [], // 存储解析后的断面数据
  55. riverAvgData: [] // 存储按河流分组后的平均数据
  56. })
  57. // 从接口获取数据并处理
  58. const fetchData = async () => {
  59. try {
  60. // 接口地址
  61. const apiUrl = 'http://localhost:8000/api/vector/export/all?table_name=cross_section'
  62. // 发起请求
  63. const response = await fetch(apiUrl)
  64. if (!response.ok) {
  65. throw new Error(`接口请求失败: ${response.status}`)
  66. }
  67. // 解析GeoJSON数据
  68. const geoJsonData = await response.json()
  69. // 处理数据
  70. state.excelData = geoJsonData.features
  71. .map(feature => {
  72. const props = feature.properties
  73. // 转换经纬度
  74. const lng = Number(props.longitude)
  75. const lat = Number(props.latitude)
  76. if (isNaN(lat) || isNaN(lng)) {
  77. console.error('无效经纬度数据:', props)
  78. return null
  79. }
  80. // WGS84转GCJ02坐标
  81. const [gcjLng, gcjLat] = wgs84togcj02(lng, lat)
  82. return {
  83. id: props.id,
  84. river: props.river_name || '未知河流',
  85. location: props.position || '未知位置',
  86. district: props.county || '未知区县',
  87. cdValue: props.cd_concentration !== undefined ? props.cd_concentration : '未知',
  88. latitude: gcjLat,
  89. longitude: gcjLng
  90. }
  91. })
  92. .filter(item => item !== null) // 过滤无效数据
  93. } catch (err) {
  94. error.value = `数据加载失败: ${err.message}`
  95. console.error('数据处理错误:', err)
  96. } finally {
  97. loading.value = false
  98. }
  99. }
  100. // 生命周期
  101. onMounted(async () => {
  102. await fetchData()
  103. })
  104. </script>
  105. <style scoped>
  106. .map-page {
  107. width: 100%;
  108. margin: 0 auto 24px;
  109. background-color: white;
  110. border-radius: 12px;
  111. padding: 20px;
  112. box-sizing: border-box;
  113. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  114. }
  115. /* 错误提示样式 */
  116. .error-message {
  117. color: #dc2626;
  118. background-color: #fee2e2;
  119. padding: 12px 16px;
  120. border-radius: 6px;
  121. margin-bottom: 16px;
  122. display: flex;
  123. align-items: center;
  124. font-weight: 500;
  125. }
  126. .error-message i {
  127. margin-right: 8px;
  128. font-size: 18px;
  129. }
  130. /* 加载状态样式 */
  131. .loading-state {
  132. text-align: center;
  133. padding: 40px 0;
  134. color: #6b7280;
  135. }
  136. .spinner {
  137. width: 40px;
  138. height: 40px;
  139. margin: 0 auto 16px;
  140. border: 4px solid #e5e7eb;
  141. border-top: 4px solid #3b82f6;
  142. border-radius: 50%;
  143. animation: spin 1s linear infinite;
  144. }
  145. @keyframes spin {
  146. 0% { transform: rotate(0deg); }
  147. 100% { transform: rotate(360deg); }
  148. }
  149. .data-container {
  150. width: 100%;
  151. overflow-x: auto;
  152. padding: 0;
  153. margin: 0;
  154. }
  155. .data-table {
  156. width: 100%;
  157. border-collapse: collapse;
  158. }
  159. .data-table th, .data-table td {
  160. padding: 12px 15px;
  161. text-align: center;
  162. border: 1px solid #e5e7eb;
  163. background-color: white;
  164. }
  165. .data-table th {
  166. background-color: white;
  167. font-weight: bold;
  168. color: #1f2937;
  169. }
  170. .data-table tr:hover {
  171. background-color: #f3f4f6;
  172. }
  173. /* 空数据状态 */
  174. .empty-state {
  175. padding: 40px 0;
  176. color: #6b7280;
  177. font-style: italic;
  178. }
  179. /* 响应式调整 */
  180. @media (max-width: 768px) {
  181. .map-page {
  182. width: 96%;
  183. }
  184. .table-container {
  185. overflow-x: auto;
  186. }
  187. }
  188. </style>