smart.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <div class="smart-door">
  3. <!-- 标题 -->
  4. <div class="module-title">
  5. <img src="@/assets/images/xlzb.png" class="title-icon" />
  6. 智能门禁
  7. </div>
  8. <!-- 数据卡片 -->
  9. <div class="data-cards">
  10. <div class="data-card">
  11. <div class="data-value">{{ state.count }}</div>
  12. <div class="data-label">门禁设备</div>
  13. </div>
  14. <div class="data-card">
  15. <div class="data-value">{{ state.accessControlProjectCount }}</div>
  16. <div class="data-label">开通项目</div>
  17. </div>
  18. <div class="data-card">
  19. <div class="data-value">{{ state.openCount }}</div>
  20. <div class="data-label">出入次数</div>
  21. </div>
  22. </div>
  23. <!-- 通行流量趋势图 -->
  24. <div class="chart-section">
  25. <div class="chart-title">日通行流量趋势</div>
  26. <div ref="trafficChart" class="traffic-chart"></div>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import { huiJiaApi } from "@/api"
  32. export default {
  33. name: 'SmartDoor',
  34. data () {
  35. return {
  36. state: {
  37. count: '921',
  38. accessControlProjectCount: '92',
  39. openCount: '900000',
  40. chartInstance: null,
  41. // 模拟的通行流量数据
  42. list: [
  43. { statData: '01:00', count: 150 },
  44. { statData: '04:00', count: 250 },
  45. { statData: '07:00', count: 420 },
  46. { statData: '10:00', count: 380 },
  47. { statData: '13:00', count: 320 },
  48. { statData: '16:00', count: 230 },
  49. { statData: '19:00', count: 220 },
  50. { statData: '22:00', count: 300 }
  51. ]
  52. }
  53. }
  54. },
  55. mounted () {
  56. this.initChart()
  57. window.addEventListener('resize', this.handleResize)
  58. this.getData()
  59. },
  60. beforeDestroy () {
  61. window.removeEventListener('resize', this.handleResize)
  62. if (this.chartInstance) {
  63. this.chartInstance.dispose()
  64. }
  65. },
  66. methods: {
  67. getData () {
  68. huiJiaApi.getFaceDeviceData().then((res) => {
  69. if (res && res.data) {
  70. this.state = res.data.data
  71. }
  72. console.log("业务数据----", res.data.data)
  73. })
  74. },
  75. initChart () {
  76. const echarts = require('echarts')
  77. this.chartInstance = echarts.init(this.$refs.trafficChart)
  78. const option = {
  79. tooltip: {
  80. trigger: 'axis',
  81. backgroundColor: 'rgba(0, 0, 0, 0.8)',
  82. borderColor: 'rgba(64, 158, 255, 0.3)',
  83. textStyle: {
  84. color: '#fff'
  85. },
  86. formatter: (params) => {
  87. return `${params[0].name}<br/>${params[0].seriesName}: ${params[0].value}`
  88. }
  89. },
  90. legend: {
  91. data: ['开门次数'],
  92. textStyle: {
  93. color: '#fff'
  94. },
  95. top: '0%',
  96. right: '0%'
  97. },
  98. grid: {
  99. left: '3%',
  100. right: '4%',
  101. bottom: '10%',
  102. top: '20%',
  103. containLabel: true
  104. },
  105. xAxis: {
  106. type: 'category',
  107. data: this.state.list.map((item) => item.statData),
  108. axisLine: {
  109. lineStyle: {
  110. color: 'rgba(160, 179, 214, 0.6)'
  111. }
  112. },
  113. axisLabel: {
  114. color: 'rgba(160, 179, 214, 0.7)',
  115. fontSize: 14
  116. },
  117. axisTick: {
  118. show: false
  119. },
  120. splitLine: {
  121. show: true,
  122. // 将坐标轴内的线设置为虚线
  123. lineStyle: {
  124. color: 'rgba(160, 179, 214, 0.3)',
  125. type: 'dashed'
  126. }
  127. }
  128. },
  129. yAxis: {
  130. type: 'value',
  131. axisLine: {
  132. show: false
  133. },
  134. axisLabel: {
  135. color: 'rgba(160, 179, 214, 0.7)',
  136. fontSize: 12
  137. },
  138. axisTick: {
  139. show: false
  140. },
  141. splitLine: {
  142. // 将坐标轴内的线设置为虚线
  143. lineStyle: {
  144. color: 'rgba(160, 179, 214, 0.3)',
  145. type: 'dashed'
  146. }
  147. }
  148. },
  149. series: [
  150. {
  151. name: '开门次数',
  152. type: 'bar',
  153. data: this.state.list.map((item) => item.count),
  154. barWidth: '30%',
  155. // 添加标签配置,设置颜色为白色
  156. label: {
  157. show: true,
  158. position: 'top',
  159. color: '#fff',
  160. fontSize: 14
  161. },
  162. itemStyle: {
  163. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
  164. { offset: 0, color: '#F6688B' },
  165. { offset: 1, color: '#F89877' }
  166. ])
  167. }
  168. }
  169. ]
  170. }
  171. this.chartInstance.setOption(option)
  172. },
  173. handleResize () {
  174. if (this.chartInstance) {
  175. this.chartInstance.resize()
  176. }
  177. },
  178. // 模拟数据更新方法
  179. updateData () {
  180. // 这里可以根据实际需求从API获取数据
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. @import "@/assets/css/theme.scss";
  187. .smart-door {
  188. background: var(--content-bg);
  189. border-radius: halfW(4);
  190. height: 100%;
  191. }
  192. .module-title {
  193. display: flex;
  194. border-radius: halfW(4);
  195. font-size: halfW(16);
  196. align-items: center;
  197. color: var(--title-primary);
  198. background: var(--title-bg);
  199. padding: halfH(4) halfW(10);
  200. }
  201. .data-cards {
  202. display: flex;
  203. gap: halfW(12);
  204. flex-wrap: nowrap;
  205. margin: halfH(20) halfW(10);
  206. background: var(--title-bg);
  207. border: 1px solid rgba(64, 158, 255, 0.1);
  208. border-radius: halfW(4);
  209. }
  210. .data-card {
  211. flex: 1;
  212. padding: halfH(10) halfW(6);
  213. display: flex;
  214. flex-direction: column;
  215. justify-content: space-between;
  216. align-items: center;
  217. gap: halfW(10);
  218. &:nth-child(1) {
  219. border-right: 1px solid rgba(64, 158, 255, 0.1);
  220. }
  221. &:nth-child(2) {
  222. border-right: 1px solid rgba(64, 158, 255, 0.1);
  223. }
  224. .data-label {
  225. font-weight: 500;
  226. font-size: halfW(14);
  227. color: var(--primary);
  228. }
  229. .data-value {
  230. font-size: halfW(18);
  231. font-weight: 500;
  232. color: #fff;
  233. }
  234. }
  235. .chart-section {
  236. flex: 1;
  237. display: flex;
  238. flex-direction: column;
  239. padding: halfH(10);
  240. height: calc(100% - halfH(200));
  241. }
  242. .chart-title {
  243. position: absolute;
  244. font-size: halfW(14);
  245. font-weight: 500;
  246. color: #fff;
  247. margin-top: halfH(10);
  248. }
  249. .traffic-chart {
  250. flex: 1;
  251. width: 100%;
  252. // min-height: halfH(250);
  253. }
  254. </style>