index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div class="spatiotemporal-distribution">
  3. <!-- 筛选条件 -->
  4. <el-card class="filter-card">
  5. <el-form :inline="true" :model="form" size="small">
  6. <el-form-item label="病原体名称">
  7. <!-- <el-input
  8. v-model="form.bytName"
  9. placeholder="请输入病原体名称"
  10. style="width: 180px"
  11. @keyup.enter="fetchAllData"
  12. /> -->
  13. <el-select
  14. v-model="form.bytName"
  15. filterable
  16. remote
  17. reserve-keyword
  18. placeholder="请输入病原体名称"
  19. :remote-method="queryInfo"
  20. :loading="loading"
  21. @change="handleSelect"
  22. style="flex: 1"
  23. >
  24. <el-option
  25. v-for="item in Assoptions"
  26. :key="item.id"
  27. :label="item.asmName"
  28. :value="item.asmName"
  29. >
  30. </el-option>
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="时间">
  34. <el-date-picker
  35. v-model="form.dateRange"
  36. type="daterange"
  37. range-separator="至"
  38. start-placeholder="开始日期"
  39. end-placeholder="结束日期"
  40. style="width: 240px"
  41. value-format="yyyy-MM-dd"
  42. />
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button type="primary" @click="fetchAllData">查询</el-button>
  46. </el-form-item>
  47. </el-form>
  48. </el-card>
  49. <div class="charts-container">
  50. <!-- 子图二:分区条形图 -->
  51. <el-card class="chart-card">
  52. <div slot="header">地区分布条形图</div>
  53. <div ref="barChart" style="height: 320px"></div>
  54. </el-card>
  55. </div>
  56. <!-- 地图容器 -->
  57. <el-row :gutter="20">
  58. <el-col :span="12">
  59. <el-card class="map-card">
  60. <div slot="header">世界地图</div>
  61. <div ref="worldMapContainer" style="width: 100%; height: 600px"></div>
  62. </el-card>
  63. </el-col>
  64. <el-col :span="12">
  65. <el-card class="map-card">
  66. <div slot="header">中国地图</div>
  67. <div ref="chinaMapContainer" style="width: 100%; height: 600px"></div>
  68. </el-card>
  69. </el-col>
  70. </el-row>
  71. </div>
  72. </template>
  73. <script>
  74. import * as echarts from "echarts";
  75. import chinaJson from "echarts/map/json/china.json";
  76. import worldJson from "echarts/map/json/world.json";
  77. import {
  78. getbytzbInfo,
  79. getbytzzfbnfo,
  80. getsjbytztqkInfo,
  81. getzgbytztqkInfo,
  82. getAssemblyAccessionList,
  83. } from "@/api/statistics/report";
  84. echarts.registerMap("china", chinaJson);
  85. echarts.registerMap("world", worldJson);
  86. export default {
  87. name: "SpatiotemporalDistribution",
  88. data() {
  89. return {
  90. filters: {
  91. disease: "",
  92. subtype: "",
  93. branch: "",
  94. dateRange: [],
  95. region: [],
  96. },
  97. diseaseOptions: [],
  98. diseaseLoading: false,
  99. subtypeOptions: [],
  100. branchOptions: [],
  101. regionOptions: [],
  102. growthData: [],
  103. barData: [],
  104. pieData: [],
  105. worldMapData: [],
  106. chinaMapData: [],
  107. description: "",
  108. barChart: null,
  109. worldMapChart: null,
  110. chinaMapChart: null,
  111. form: {
  112. bytName: "",
  113. endDate: "",
  114. province: "",
  115. startDate: "",
  116. dateRange: [],
  117. },
  118. Assoptions: [],
  119. AssTimer: null,
  120. loading: false,
  121. };
  122. },
  123. mounted() {
  124. // this.fetchAllData();
  125. // 延迟初始化,确保容器尺寸正确
  126. this.$nextTick(() => {
  127. this.initCharts();
  128. });
  129. },
  130. methods: {
  131. // 搜索
  132. queryInfo(queryString) {
  133. if (this.ASSTimer) {
  134. clearTimeout(this.ASSTimer);
  135. }
  136. this.ASSTimer = setTimeout(() => {
  137. if (queryString.length > 0) {
  138. this.loading = true;
  139. getAssemblyAccessionList(queryString)
  140. .then((res) => {
  141. console.log("查询基因组序列编号", res);
  142. if (res.data && res.data.length > 0) {
  143. this.Assoptions = res.data;
  144. }
  145. this.loading = false;
  146. })
  147. .finally(() => {
  148. this.loading = false;
  149. });
  150. }
  151. }, 500);
  152. },
  153. handleSelect() {
  154. if (this.form.bytName) {
  155. this.fetchAllData();
  156. }
  157. },
  158. async fetchAllData() {
  159. if (this.form.dateRange.length > 0) {
  160. const [startDate, endDate] = this.form.dateRange;
  161. this.form.startDate = startDate;
  162. this.form.endDate = endDate;
  163. }
  164. // 获取数据
  165. try {
  166. const response2 = await getbytzzfbnfo(this.form);
  167. const response3 = await getsjbytztqkInfo(this.form);
  168. const response4 = await getzgbytztqkInfo(this.form);
  169. this.barData = response2.data;
  170. this.worldMapData = response3.data;
  171. this.chinaMapData = response4.data;
  172. } catch (error) {
  173. console.error("获取数据失败:", error);
  174. this.$message.error("获取数据失败,请稍后重试");
  175. }
  176. this.renderCharts();
  177. },
  178. initCharts() {
  179. this.barChart = echarts.init(this.$refs.barChart);
  180. this.worldMapChart = echarts.init(this.$refs.worldMapContainer);
  181. this.chinaMapChart = echarts.init(this.$refs.chinaMapContainer);
  182. window.addEventListener("resize", () => {
  183. this.barChart.resize();
  184. this.worldMapChart.resize();
  185. this.chinaMapChart.resize();
  186. });
  187. },
  188. renderCharts() {
  189. // 子图二:分区条形图
  190. const regions =
  191. this.barData.length > 0
  192. ? Object.keys(this.barData[0]).filter((key) => key !== "day")
  193. : [];
  194. const dates = this.barData.map((item) => item.day);
  195. const seriesData = regions.map((region) => ({
  196. name: region,
  197. type: "bar",
  198. data: this.barData.map((item) => item[region]),
  199. }));
  200. this.barChart.setOption({
  201. // 添加动画效果
  202. animationDuration: 1000,
  203. tooltip: {
  204. trigger: "axis",
  205. axisPointer: {
  206. type: "cross",
  207. crossStyle: {
  208. color: "#999",
  209. },
  210. },
  211. },
  212. legend: {
  213. data: regions,
  214. },
  215. xAxis: {
  216. type: "category",
  217. data: dates,
  218. // 优化 x 轴线样式
  219. axisLine: {
  220. lineStyle: {
  221. color: "#999",
  222. },
  223. },
  224. // 优化 x 轴刻度线样式
  225. axisTick: {
  226. show: false,
  227. },
  228. },
  229. yAxis: {
  230. type: "value",
  231. name: "数量",
  232. },
  233. series: seriesData,
  234. });
  235. // 处理世界地图数据
  236. const processedWorldMapData = this.worldMapData.map((item) => {
  237. // const name = worldRegionMap[item.area] || item.area;
  238. const value = item.num || 0;
  239. return {
  240. name: item.eng,
  241. value,
  242. cnName: item.area,
  243. };
  244. });
  245. // 处理中国地图数据
  246. const processedChinaMapData = this.chinaMapData.map((item) => {
  247. // const name = chinaRegionMap[item.area] || item.area;
  248. const value = item.num || 0;
  249. return {
  250. name: item.area,
  251. value,
  252. };
  253. });
  254. // 检查数据是否为空
  255. if (processedWorldMapData.every((item) => item.value === 0)) {
  256. console.warn("世界地图数据值全部为 0");
  257. }
  258. if (processedChinaMapData.every((item) => item.value === 0)) {
  259. console.warn("中国地图数据值全部为 0");
  260. }
  261. // 世界地图配置
  262. this.worldMapChart.setOption({
  263. title: { text: "全球病毒分布", left: "center" },
  264. tooltip: {
  265. trigger: "item",
  266. formatter: (p) =>
  267. `${p.data?.cnName || p.data?.name}<br/>数量: ${p.value || "-"}`,
  268. },
  269. visualMap: {
  270. min: Math.min(...processedWorldMapData.map((item) => item.value)),
  271. max: Math.max(...processedWorldMapData.map((item) => item.value)),
  272. left: "left",
  273. top: "bottom",
  274. text: ["高", "低"],
  275. calculable: true,
  276. inRange: {
  277. color: ["#ffeeee", "#ffcccc", "#ff9999", "#ff6666", "#ff3333"],
  278. },
  279. },
  280. // geo: {
  281. // map: 'world',
  282. // roam: true,
  283. // label: { show: false },
  284. // itemStyle: {
  285. // areaColor: '#f0f0f0',
  286. // borderColor: '#999'
  287. // },
  288. // emphasis: {
  289. // itemStyle: {
  290. // areaColor: '#e0e0e0'
  291. // }
  292. // }
  293. // },
  294. series: [
  295. {
  296. type: "map",
  297. map: "world",
  298. data: processedWorldMapData,
  299. label: {
  300. show: false,
  301. },
  302. emphasis: {
  303. itemStyle: {
  304. areaColor: "#e0e0e0",
  305. },
  306. },
  307. },
  308. ],
  309. });
  310. // 中国地图配置
  311. this.chinaMapChart.setOption({
  312. title: { text: "中国病毒分布", left: "center" },
  313. tooltip: {
  314. trigger: "item",
  315. formatter: (p) => `${p.name}<br/>数量: ${p.value || "-"}`,
  316. },
  317. visualMap: {
  318. min: Math.min(...processedChinaMapData.map((item) => item.value)),
  319. max: Math.max(...processedChinaMapData.map((item) => item.value)),
  320. left: "left",
  321. top: "bottom",
  322. text: ["高", "低"],
  323. calculable: true,
  324. inRange: {
  325. color: ["#ffeeee", "#ffcccc", "#ff9999", "#ff6666", "#ff3333"],
  326. },
  327. },
  328. // geo: {
  329. // map: 'china',
  330. // roam: true,
  331. // label: { show: false },
  332. // itemStyle: {
  333. // areaColor: '#f0f0f0',
  334. // borderColor: '#999'
  335. // },
  336. // emphasis: {
  337. // itemStyle: {
  338. // areaColor: '#e0e0e0'
  339. // }
  340. // }
  341. // },
  342. series: [
  343. {
  344. type: "map",
  345. map: "china",
  346. data: processedChinaMapData,
  347. label: {
  348. show: false,
  349. },
  350. emphasis: {
  351. itemStyle: {
  352. areaColor: "#e0e0e0",
  353. },
  354. },
  355. },
  356. ],
  357. });
  358. },
  359. },
  360. };
  361. </script>
  362. <style scoped>
  363. .spatiotemporal-distribution {
  364. padding: 16px;
  365. }
  366. .filter-card {
  367. margin-bottom: 16px;
  368. }
  369. .charts-container {
  370. display: flex;
  371. gap: 16px;
  372. margin-bottom: 16px;
  373. }
  374. .chart-card {
  375. flex: 1;
  376. min-width: 0;
  377. }
  378. .map-card {
  379. margin-bottom: 16px;
  380. }
  381. .desc-card {
  382. margin-bottom: 16px;
  383. }
  384. .desc-text {
  385. font-size: 15px;
  386. line-height: 1.8;
  387. color: #333;
  388. }
  389. </style>