index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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="NCBI基因组序列编号">
  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.assemblyAccession"
  15. filterable
  16. remote
  17. reserve-keyword
  18. placeholder="请输入NCBI基因组序列编号"
  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-col :span="24">
  71. <el-card class="map-card">
  72. <div slot="header">全球流行病学监测数据</div>
  73. <div v-html="qqlxbxjcsjtxt"></div>
  74. </el-card>
  75. </el-col>
  76. </el-row>
  77. </div>
  78. </template>
  79. <script>
  80. import * as echarts from "echarts";
  81. import chinaJson from "echarts/map/json/china.json";
  82. import worldJson from "echarts/map/json/world.json";
  83. import {
  84. getbytzbInfo,
  85. getbytzzfbnfo,
  86. getsjbytztqkInfo,
  87. getzgbytztqkInfo,
  88. getAssemblyAccessionList,qqlxbxjcsj} from "@/api/statistics/report";
  89. echarts.registerMap("china", chinaJson);
  90. echarts.registerMap("world", worldJson);
  91. export default {
  92. name: "SpatiotemporalDistribution",
  93. data() {
  94. return {
  95. filters: {
  96. disease: "",
  97. subtype: "",
  98. branch: "",
  99. dateRange: [],
  100. region: [],
  101. },
  102. diseaseOptions: [],
  103. diseaseLoading: false,
  104. subtypeOptions: [],
  105. branchOptions: [],
  106. regionOptions: [],
  107. growthData: [],
  108. barData: [],
  109. pieData: [],
  110. worldMapData: [],
  111. chinaMapData: [],
  112. description: "",
  113. barChart: null,
  114. worldMapChart: null,
  115. chinaMapChart: null,
  116. form: {
  117. assemblyAccession: "",
  118. endDate: "",
  119. startDate: "",
  120. dateRange: [],
  121. },
  122. Assoptions: [],
  123. AssTimer: null,
  124. loading: false,
  125. qqlxbxjcsjtxt:''
  126. };
  127. },
  128. mounted() {
  129. // this.fetchAllData();
  130. // 延迟初始化,确保容器尺寸正确
  131. this.$nextTick(() => {
  132. this.initCharts();
  133. });
  134. },
  135. methods: {
  136. // 搜索
  137. queryInfo(queryString) {
  138. if (this.ASSTimer) {
  139. clearTimeout(this.ASSTimer);
  140. }
  141. this.ASSTimer = setTimeout(() => {
  142. if (queryString.length > 0) {
  143. this.loading = true;
  144. getAssemblyAccessionList(queryString)
  145. .then((res) => {
  146. console.log("查询基因组序列编号", res);
  147. if (res.data && res.data.length > 0) {
  148. this.Assoptions = res.data;
  149. }
  150. this.loading = false;
  151. })
  152. .finally(() => {
  153. this.loading = false;
  154. });
  155. }
  156. }, 500);
  157. },
  158. handleSelect() {
  159. if (this.form.assemblyAccession) {
  160. this.fetchAllData();
  161. }
  162. },
  163. async fetchAllData() {
  164. if (!this.form.assemblyAccession) {
  165. this.$message.info('请输入NCBI基因组序列编号');
  166. return;
  167. }
  168. if (this.form.dateRange.length > 0) {
  169. const [startDate, endDate] = this.form.dateRange;
  170. this.form.startDate = startDate;
  171. this.form.endDate = endDate;
  172. } else {
  173. this.$message.info('请输入时间');
  174. return;
  175. }
  176. // 获取数据
  177. try {
  178. const response2 = await getbytzzfbnfo(this.form);
  179. const response3 = await getsjbytztqkInfo(this.form);
  180. const response4 = await getzgbytztqkInfo(this.form);
  181. const response5 = await qqlxbxjcsj(this.form);
  182. this.barData = response2.data;
  183. this.worldMapData = response3.data;
  184. this.chinaMapData = response4.data;
  185. this.qqlxbxjcsjtxt = response5.msg
  186. console.log(response5)
  187. } catch (error) {
  188. console.error("获取数据失败:", error);
  189. this.$message.error("获取数据失败,请稍后重试");
  190. }
  191. this.renderCharts();
  192. },
  193. initCharts() {
  194. this.barChart = echarts.init(this.$refs.barChart);
  195. this.worldMapChart = echarts.init(this.$refs.worldMapContainer);
  196. this.chinaMapChart = echarts.init(this.$refs.chinaMapContainer);
  197. window.addEventListener("resize", () => {
  198. this.barChart.resize();
  199. this.worldMapChart.resize();
  200. this.chinaMapChart.resize();
  201. });
  202. },
  203. renderCharts() {
  204. // 子图二:分区条形图
  205. const regions =
  206. this.barData.length > 0
  207. ? Object.keys(this.barData[0]).filter((key) => key !== "day")
  208. : [];
  209. const dates = this.barData.map((item) => item.day);
  210. const seriesData = regions.map((region, index) => ({
  211. name: region,
  212. type: "bar",
  213. data: this.barData.map((item) => item[region]),
  214. itemStyle: {
  215. color: ["#DEECF6", "#86DAA7", "#F9D5D5", "#EF98A1", "#FBC99A", "#C2B1D7"][index % 6]
  216. }
  217. }));
  218. this.barChart.setOption({
  219. // 添加动画效果
  220. animationDuration: 1000,
  221. tooltip: {
  222. trigger: "axis",
  223. axisPointer: {
  224. type: "cross",
  225. crossStyle: {
  226. color: "#999",
  227. },
  228. },
  229. },
  230. legend: {
  231. data: regions,
  232. },
  233. xAxis: {
  234. type: "category",
  235. data: dates,
  236. // 优化 x 轴线样式
  237. axisLine: {
  238. lineStyle: {
  239. color: "#999",
  240. },
  241. },
  242. // 优化 x 轴刻度线样式
  243. axisTick: {
  244. show: false,
  245. },
  246. },
  247. yAxis: {
  248. type: "value",
  249. name: "数量",
  250. },
  251. series: seriesData,
  252. });
  253. // 处理世界地图数据
  254. const processedWorldMapData = this.worldMapData.map((item) => {
  255. // const name = worldRegionMap[item.area] || item.area;
  256. const value = item.num || 0;
  257. return {
  258. name: item.eng,
  259. value,
  260. cnName: item.area,
  261. };
  262. });
  263. // 处理中国地图数据
  264. const processedChinaMapData = this.chinaMapData.map((item) => {
  265. // const name = chinaRegionMap[item.area] || item.area;
  266. const value = item.num || 0;
  267. return {
  268. name: item.area,
  269. value,
  270. };
  271. });
  272. // 检查数据是否为空
  273. if (processedWorldMapData.every((item) => item.value === 0)) {
  274. console.warn("世界地图数据值全部为 0");
  275. }
  276. if (processedChinaMapData.every((item) => item.value === 0)) {
  277. console.warn("中国地图数据值全部为 0");
  278. }
  279. // 世界地图配置
  280. this.worldMapChart.setOption({
  281. title: { text: "全球病毒分布", left: "center" },
  282. tooltip: {
  283. trigger: "item",
  284. formatter: (p) =>
  285. `${p.data?.cnName || p.data?.name}<br/>数量: ${p.value || "-"}`,
  286. },
  287. visualMap: {
  288. min: Math.min(...processedWorldMapData.map((item) => item.value)),
  289. max: Math.max(...processedWorldMapData.map((item) => item.value)),
  290. left: "left",
  291. top: "bottom",
  292. text: ["高", "低"],
  293. calculable: true,
  294. inRange: {
  295. // 替换为指定的 RGB 颜色
  296. color: [
  297. 'rgb(255,155,153)',
  298. 'rgb(255,211,127)',
  299. 'rgb(245,245,122)',
  300. 'rgb(255,255,190)',
  301. 'rgb(233,255,190)',
  302. 'rgb(190,255,232)',
  303. 'rgb(196,235,255)',
  304. 'rgb(126,226,250)',
  305. 'rgb(0,197,255)' // 修正 000 为 0
  306. ]
  307. },
  308. },
  309. series: [
  310. {
  311. type: "map",
  312. map: "world",
  313. data: processedWorldMapData,
  314. label: {
  315. show: false,
  316. },
  317. emphasis: {
  318. itemStyle: {
  319. areaColor: "#e0e0e0",
  320. },
  321. },
  322. },
  323. ],
  324. });
  325. // 中国地图配置
  326. this.chinaMapChart.setOption({
  327. title: { text: "中国病毒分布", left: "center" },
  328. tooltip: {
  329. trigger: "item",
  330. formatter: (p) => `${p.name}<br/>数量: ${p.value || "-"}`,
  331. },
  332. visualMap: {
  333. min: Math.min(...processedChinaMapData.map((item) => item.value)),
  334. max: Math.max(...processedChinaMapData.map((item) => item.value)),
  335. left: "left",
  336. top: "bottom",
  337. text: ["高", "低"],
  338. calculable: true,
  339. inRange: {
  340. // 替换为指定的 RGB 颜色
  341. color: [
  342. 'rgb(255,155,153)',
  343. 'rgb(255,211,127)',
  344. 'rgb(245,245,122)',
  345. 'rgb(255,255,190)',
  346. 'rgb(233,255,190)',
  347. 'rgb(190,255,232)',
  348. 'rgb(196,235,255)',
  349. 'rgb(126,226,250)',
  350. 'rgb(0,197,255)' // 修正 000 为 0
  351. ]
  352. },
  353. },
  354. series: [
  355. {
  356. type: "map",
  357. map: "china",
  358. data: processedChinaMapData,
  359. label: {
  360. show: false,
  361. },
  362. emphasis: {
  363. itemStyle: {
  364. areaColor: "#e0e0e0",
  365. },
  366. },
  367. },
  368. ],
  369. });
  370. },
  371. },
  372. };
  373. </script>
  374. <style scoped>
  375. .spatiotemporal-distribution {
  376. padding: 24px;
  377. }
  378. .filter-card {
  379. margin-bottom: 16px;
  380. }
  381. .charts-container {
  382. display: flex;
  383. gap: 16px;
  384. margin-bottom: 16px;
  385. }
  386. .chart-card {
  387. flex: 1;
  388. min-width: 0;
  389. }
  390. .map-card {
  391. margin-bottom: 16px;
  392. }
  393. .desc-card {
  394. margin-bottom: 16px;
  395. }
  396. .desc-text {
  397. font-size: 15px;
  398. line-height: 1.8;
  399. color: #333;
  400. }
  401. </style>