left-bottom.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <div class="left_bottom">
  3. <div class="left_bottom-title flex">
  4. <div class="flex items-center">
  5. <img src="@/assets/img/home/title_arrow.png" alt="">
  6. 高频事项分析
  7. </div>
  8. <el-dropdown @command="handleCommand">
  9. <el-button link class="link-button">
  10. {{ areaText }}
  11. <el-icon class="el-icon--right">
  12. <arrow-down/>
  13. </el-icon>
  14. </el-button>
  15. <template #dropdown>
  16. <el-dropdown-menu>
  17. <el-dropdown-item v-for="item in areaList" :key="item.value" :command="item">{{ item.name }}</el-dropdown-item>
  18. </el-dropdown-menu>
  19. </template>
  20. </el-dropdown>
  21. </div>
  22. <div class="left_bottom-content">
  23. <template v-if="list.length">
  24. <v-chart class="chart" :option="option" :loading="loading" :loading-options="loadingOptions"/>
  25. </template>
  26. <template v-else>
  27. <EmptyCom></EmptyCom>
  28. </template>
  29. </div>
  30. </div>
  31. </template>
  32. <script setup lang="ts">
  33. import {onMounted, ref, watch} from "vue";
  34. import {ArrowDown} from '@element-plus/icons-vue'
  35. import {hotSpot} from "@/api/home";
  36. import dayjs from "dayjs";
  37. import EmptyCom from "@/components/empty-com";
  38. import {loadingOptions} from "@/utils/constants";
  39. import {graphic} from "echarts/core";
  40. import {arraySortByKey} from "@/utils/tools";
  41. const props = defineProps({
  42. dateArray: {
  43. type: Array,
  44. default: () => []
  45. }
  46. })
  47. const areaList = ref([
  48. {
  49. name: '宜宾市',
  50. value: '511500'
  51. },
  52. {
  53. name: '翠屏区',
  54. value: '511502'
  55. },
  56. {
  57. name: '南溪区',
  58. value: '511503'
  59. },
  60. {
  61. name: '叙州区',
  62. value: '511504'
  63. },
  64. {
  65. name: '江安县',
  66. value: '511523'
  67. },
  68. {
  69. name: '长宁县',
  70. value: '511524'
  71. },
  72. {
  73. name: '高县',
  74. value: '511525'
  75. },
  76. {
  77. name: '珙县',
  78. value: '511526'
  79. },
  80. {
  81. name: '筠连县',
  82. value: '511527'
  83. },
  84. {
  85. name: '兴文县',
  86. value: '511528'
  87. },
  88. {
  89. name: '屏山县',
  90. value: '511529'
  91. }
  92. ]);
  93. const date = ref([]);
  94. const loading = ref(false);
  95. const option = ref<any>({});
  96. watch(() => props.dateArray, (val: any) => {
  97. date.value = val;
  98. }, {immediate: true})
  99. watch(() => props.dateArray, () => {
  100. getData();
  101. })
  102. const areaCode = ref('511500');
  103. const areaText = ref('宜宾市');
  104. const list = ref<any>([]);
  105. const getData = async () => {
  106. loading.value = true;
  107. try {
  108. const {result} = await hotSpot({
  109. StartDate: dayjs(date.value[0]).format('YYYY-MM-DD'),
  110. EndDate: dayjs(date.value[1]).format('YYYY-MM-DD'),
  111. AreaCode: areaCode.value
  112. });
  113. list.value = result;
  114. const category = arraySortByKey(result, 'sumCount',);
  115. const charts = { // 按顺序排列从大到小
  116. cityList: category.map((item: any) => item.hotspotName),
  117. cityData: category.map((item: any) => item.sumCount)
  118. };
  119. const top10CityList = charts.cityList;
  120. const top10CityData = charts.cityData;
  121. const color = ['#ff9500', '#02d8f9', '#027fff'];
  122. const color1 = ['#ffb349', '#70e9fc', '#4aa4ff'];
  123. let lineY = []
  124. let lineT = []
  125. for (let i = 0; i < charts.cityList.length; i++) {
  126. let x = i;
  127. if (x > 1) {
  128. x = 2
  129. }
  130. const data = {
  131. name: charts.cityList[i],
  132. color: color[x],
  133. value: top10CityData[i],
  134. barGap: '-100%',
  135. itemStyle: {
  136. show: true,
  137. color: new graphic.LinearGradient(0, 0, 1, 0, [{
  138. offset: 0,
  139. color: color[x]
  140. }, {
  141. offset: 1,
  142. color: color1[x]
  143. }], false),
  144. borderRadius: 10,
  145. },
  146. emphasis: {
  147. itemStyle: {
  148. shadowBlur: 15,
  149. shadowColor: 'rgba(0, 0, 0, 0.1)'
  150. }
  151. }
  152. };
  153. const data1 = {
  154. value: top10CityData[0],
  155. itemStyle: {
  156. color: '#001235',
  157. borderRadius: 10
  158. }
  159. };
  160. lineY.push(data)
  161. lineT.push(data1)
  162. }
  163. option.value = {
  164. backgroundColor: 'rgba(0, 0, 0, 0)',
  165. title: {
  166. show: false
  167. },
  168. tooltip: {},
  169. grid: {
  170. borderWidth: 0,
  171. top: '5%',
  172. left: '5%',
  173. right: '15%',
  174. bottom: '10%'
  175. },
  176. color: color,
  177. yAxis: [{
  178. type: 'category',
  179. inverse: true,
  180. axisTick: {
  181. show: false
  182. },
  183. axisLine: {
  184. show: false
  185. },
  186. axisLabel: {
  187. show: false,
  188. inside: false
  189. },
  190. data: top10CityList
  191. }, {
  192. type: 'category',
  193. inverse: true,
  194. axisLine: {
  195. show: false
  196. },
  197. axisTick: {
  198. show: false
  199. },
  200. axisLabel: {
  201. show: true,
  202. inside: false,
  203. verticalAlign: 'middle',
  204. lineHeight: '40',
  205. color: '#fff',
  206. fontSize: '14',
  207. fontFamily: 'PingFangSC-Regular',
  208. formatter: function (val) {
  209. return `${val}`
  210. }
  211. },
  212. splitArea: {
  213. show: false
  214. },
  215. splitLine: {
  216. show: false
  217. },
  218. data: top10CityData
  219. }],
  220. xAxis: {
  221. type: 'value',
  222. axisTick: {
  223. show: false
  224. },
  225. axisLine: {
  226. show: false
  227. },
  228. splitLine: {
  229. show: false
  230. },
  231. axisLabel: {
  232. show: false
  233. }
  234. },
  235. series: [{
  236. name: 'total',
  237. type: 'bar',
  238. zLevel: 1,
  239. barGap: '-100%',
  240. barWidth: '10px',
  241. data: lineT,
  242. legendHoverLink: false
  243. }, {
  244. type: 'bar',
  245. zLevel: 2,
  246. barWidth: '10px',
  247. data: lineY,
  248. label: {
  249. color: '#b3ccf8',
  250. show: true,
  251. position: [0, '-18px'],
  252. fontSize: 16,
  253. formatter: function (a) {
  254. let num = ''
  255. let str = ''
  256. if (a.dataIndex + 1 < 10) {
  257. num = '0' + (a.dataIndex + 1);
  258. } else {
  259. num = (a.dataIndex + 1);
  260. }
  261. if (a.dataIndex === 0) {
  262. str = `{color1|${num}} {color4|${a.name}}`
  263. } else if (a.dataIndex === 1) {
  264. str = `{color2|${num}} {color4|${a.name}}`
  265. } else {
  266. str = `{color3|${num}} {color4|${a.name}}`
  267. }
  268. return str;
  269. },
  270. rich: {
  271. color1: {
  272. color: '#ff9500',
  273. fontWeight: 700
  274. },
  275. color2: {
  276. color: '#02d8f9',
  277. fontWeight: 700
  278. },
  279. color3: {
  280. color: '#027fff',
  281. fontWeight: 700
  282. },
  283. color4: {
  284. color: '#e5eaff'
  285. }
  286. }
  287. }
  288. }],
  289. }
  290. loading.value = false;
  291. } catch (e) {
  292. console.log(e);
  293. loading.value = false;
  294. }
  295. }
  296. // 选择省市区
  297. const handleCommand = (command: any) => {
  298. areaCode.value = command.value;
  299. areaText.value = command.name;
  300. getData();
  301. }
  302. onMounted(() => {
  303. getData();
  304. });
  305. </script>
  306. <style scoped lang="scss">
  307. .left_bottom {
  308. padding: 0 30px;
  309. &-title {
  310. font-size: 20px;
  311. color: #fff;
  312. justify-content: space-between;
  313. align-items: center;
  314. }
  315. &-content {
  316. height: calc(100% - 30px);
  317. }
  318. }
  319. :deep(.link-button) {
  320. cursor: pointer;
  321. color: #7DBDEC;
  322. display: flex;
  323. align-items: center;
  324. }
  325. </style>