scenicDetailAnalyse.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <div class="content">
  3. <!-- 标题区域 -->
  4. <div class="header">游客分析</div>
  5. <!-- 内容区域 -->
  6. <div class="box">
  7. <!-- 今日旅游人次区域 -->
  8. <div class="box_left">
  9. <div class="board">
  10. <div class="board_box">
  11. <div class="box_title">今日旅游人次</div>
  12. <div class="box_line"></div>
  13. <div class="box_num">
  14. <div class="num_list">
  15. <div
  16. class="list_item"
  17. ref="itemsNum"
  18. v-for="(item, index) in todayNumList"
  19. :key="index"
  20. :data-value="item"
  21. >
  22. {{ item }}
  23. </div>
  24. </div>
  25. <div class="num_text">人次</div>
  26. </div>
  27. <!-- <div class="box_rate">
  28. <div class="rate_key">较昨日</div>
  29. <div class="rate_value">+10.06%</div>
  30. </div> -->
  31. </div>
  32. </div>
  33. </div>
  34. <!-- 折线图区域 -->
  35. <div class="box_right">
  36. <!-- 选择时间区域 -->
  37. <div class="time">
  38. <div class="time_box">
  39. <div
  40. class="box_item"
  41. :class="{ active: currentIndex === index }"
  42. v-for="(item, index) in timeList"
  43. :key="index"
  44. @click="handleChangeIndex(index)"
  45. >
  46. {{ item }}
  47. </div>
  48. </div>
  49. </div>
  50. <!-- 折线图 -->
  51. <div class="chart" ref="lineChart"></div>
  52. </div>
  53. </div>
  54. </div>
  55. </template>
  56. <script setup lang="ts">
  57. import { ref, onMounted, nextTick } from "vue";
  58. import * as Echarts from "echarts";
  59. import { countUpNum } from "@/utils/countUpNum.ts";
  60. // 引入景区相关的接口
  61. import {
  62. reqGetAllNumToday,
  63. reqGetAllNumByDay,
  64. reqGetAllNumByMonth,
  65. reqGetAllNumByYear,
  66. } from "@/api/scenic/index";
  67. // 选择时间数组
  68. const timeList = ref(["日", "月", "年"]);
  69. // 当前激活索引
  70. const currentIndex = ref<number>(0);
  71. // DOM元素数组
  72. const itemsNum = ref();
  73. // 今日旅游人次
  74. const todayNum = ref(0);
  75. const todayNumList = ref<any>([]);
  76. // 图表x轴数据
  77. const chartXdata = ref<any>([]);
  78. // 图表y轴数据
  79. const chartYdata = ref([]);
  80. // 折线图DOM元素
  81. const lineChart = ref(null);
  82. // 图表实例
  83. let myLineChart: any;
  84. onMounted(() => {
  85. // 获取今日旅游人次数据
  86. getAllNumToday();
  87. // 获取图表数据
  88. getChartData();
  89. });
  90. // 获取今日旅游人次数据
  91. const getAllNumToday = async () => {
  92. const res = await reqGetAllNumToday();
  93. // console.log(res);
  94. todayNum.value = res.data.num * 1;
  95. // 处理人次数据
  96. todayNumList.value = todayNum.value.toString().split("");
  97. // 让数字跳动
  98. getCountUpNum();
  99. };
  100. // 让数字跳动
  101. const getCountUpNum = () => {
  102. nextTick(() => {
  103. itemsNum.value.forEach((ele: any) => {
  104. countUpNum(ele, ele.dataset.value);
  105. });
  106. });
  107. };
  108. // 获取图表数据
  109. const getChartData = () => {
  110. if (currentIndex.value === 0) {
  111. // 近8日
  112. getAllNumByDay();
  113. } else if (currentIndex.value === 1) {
  114. // 近8月
  115. getAllNumByMonth();
  116. } else if (currentIndex.value === 2) {
  117. // 近8年
  118. getAllNumByYear();
  119. }
  120. };
  121. // 获取近8日旅游人次数据
  122. const getAllNumByDay = async () => {
  123. const res = await reqGetAllNumByDay();
  124. // console.log(res);
  125. chartYdata.value = res.data.map((ele: any) => ele.num * 1);
  126. chartXdata.value = res.data.map((ele: any) => ele.dateTime.slice(-2) + "日");
  127. // 初始化折线图
  128. initLineChart();
  129. };
  130. // 获取近8月旅游人次数据
  131. const getAllNumByMonth = async () => {
  132. const res = await reqGetAllNumByMonth();
  133. // console.log(res);
  134. chartYdata.value = res.data.map((ele: any) => ele.num * 1);
  135. chartXdata.value = res.data.map((ele: any) => ele.dateTime.slice(-2) + "月");
  136. // 初始化折线图
  137. initLineChart();
  138. };
  139. // 获取近8年旅游人次数据
  140. const getAllNumByYear = async () => {
  141. const res = await reqGetAllNumByYear();
  142. // console.log(res);
  143. chartYdata.value = res.data.map((ele: any) => ele.num * 1);
  144. chartXdata.value = res.data.map((ele: any) => ele.dateTime + "年");
  145. // 初始化折线图
  146. initLineChart();
  147. };
  148. // 初始化折线图
  149. const initLineChart = () => {
  150. myLineChart = Echarts.init(lineChart.value);
  151. // 折线图配置
  152. const options = {
  153. tooltip: {
  154. trigger: "axis",
  155. axisPointer: {
  156. type: "shadow",
  157. },
  158. },
  159. grid: {
  160. left: "12%",
  161. right: "1%",
  162. top: "10%",
  163. bottom: "20%",
  164. containLabel: true,
  165. },
  166. xAxis: {
  167. type: "category",
  168. boundaryGap: true,
  169. axisLabel: {
  170. color: "#fff",
  171. fontSize: 16,
  172. margin: 20,
  173. },
  174. data: chartXdata.value,
  175. },
  176. yAxis: {
  177. type: "value",
  178. name: "人次",
  179. nameTextStyle: {
  180. color: "#fff",
  181. fontSize: 16,
  182. },
  183. axisLabel: {
  184. color: "#fff",
  185. fontSize: 16,
  186. },
  187. splitLine: {
  188. show: true,
  189. lineStyle: {
  190. color: ["rgba(255, 255, 255, 0.15)"],
  191. },
  192. },
  193. },
  194. series: [
  195. {
  196. data: chartYdata.value,
  197. type: "line",
  198. smooth: true,
  199. color: "#1F92F6",
  200. tooltip: {
  201. valueFormatter: function (value: any) {
  202. return value + "人次";
  203. },
  204. },
  205. areaStyle: {
  206. color: {
  207. type: "linear",
  208. x: 0,
  209. y: 1,
  210. x2: 0,
  211. y2: 0,
  212. colorStops: [
  213. {
  214. offset: 0,
  215. color: "rgba(25, 104, 255, 0.2)",
  216. },
  217. {
  218. offset: 1,
  219. color: "rgba(54, 161, 255, 0.6)",
  220. },
  221. ],
  222. },
  223. },
  224. },
  225. ],
  226. };
  227. myLineChart.setOption(options);
  228. };
  229. // 切换选择时间时的回调
  230. const handleChangeIndex = (index: number) => {
  231. currentIndex.value = index;
  232. // 销毁图表实例重新加载
  233. myLineChart.dispose();
  234. getChartData();
  235. };
  236. </script>
  237. <style lang="scss" scoped>
  238. .content {
  239. width: 986px;
  240. height: 545px;
  241. .header {
  242. padding-left: 44px;
  243. width: 986px;
  244. height: 48px;
  245. font-size: 28px;
  246. font-family: "庞门正道标题体";
  247. background-image: url(@/assets/images/scenicDetail-title-img.png);
  248. background-size: 100% 100%;
  249. }
  250. .box {
  251. display: flex;
  252. width: 986px;
  253. height: 497px;
  254. .box_left {
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. width: 324px;
  259. height: 497px;
  260. .board {
  261. width: 268px;
  262. height: 278px;
  263. background-image: url(@/assets/images/scenicDetail-board.png);
  264. background-size: 100% 100%;
  265. .board_box {
  266. margin: 59px 0 0 37px;
  267. padding-right: 28px;
  268. .box_title {
  269. font-size: 20px;
  270. }
  271. .box_line {
  272. margin: 24px 0;
  273. width: 174px;
  274. height: 4px;
  275. background-image: url(@/assets/images/news-list-bottomLine.png);
  276. background-size: 100% 100%;
  277. }
  278. .box_num {
  279. display: flex;
  280. justify-content: flex-end;
  281. align-items: end;
  282. height: 40px;
  283. .num_list {
  284. display: flex;
  285. overflow: hidden;
  286. .list_item {
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. margin-right: 7px;
  291. width: 29px;
  292. height: 40px;
  293. font-size: 26px;
  294. color: #abd2ff;
  295. background-image: url(@/assets/images/scenicDetail-boardNum.png);
  296. background-size: 100% 100%;
  297. }
  298. }
  299. .num_text {
  300. margin-left: 5px;
  301. font-size: 12px;
  302. }
  303. }
  304. // .box_rate {
  305. // display: flex;
  306. // margin-top: 24px;
  307. // font-size: 14.5px;
  308. // .rate_key {
  309. // margin-right: 8px;
  310. // }
  311. // .rate_value {
  312. // color: #ffd15c;
  313. // font-weight: bold;
  314. // }
  315. // }
  316. }
  317. }
  318. }
  319. .box_right {
  320. width: 662px;
  321. height: 497px;
  322. .time {
  323. display: flex;
  324. justify-content: flex-end;
  325. align-items: center;
  326. width: 662px;
  327. height: 90px;
  328. .time_box {
  329. display: flex;
  330. justify-content: space-evenly;
  331. align-items: center;
  332. width: 232px;
  333. height: 37px;
  334. border: 1px solid #9c9c9c;
  335. .box_item {
  336. display: flex;
  337. justify-content: center;
  338. align-items: center;
  339. width: 71px;
  340. height: 30px;
  341. cursor: pointer;
  342. background-color: rgba(114, 151, 179, 0.5);
  343. }
  344. .active {
  345. background-color: rgba(112, 183, 250, 0.5);
  346. }
  347. }
  348. }
  349. .chart {
  350. width: 662px;
  351. height: 407px;
  352. }
  353. }
  354. }
  355. }
  356. </style>
  357. @/utils/getNearDay