TrafficCamera.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <box
  3. componentkey="TrafficCamera"
  4. title="人流量监测"
  5. >
  6. <div
  7. class="wrapper"
  8. :class="{ full }"
  9. >
  10. <div class="o-detail">
  11. <div class="choosedate">
  12. <div class="timeBtn">
  13. <div class="timeType">
  14. <div
  15. class="type__hour type"
  16. :class="{ active: active === 'hour' }"
  17. @click="timeType('hour')"
  18. >
  19. 1小时
  20. </div>
  21. <div
  22. class="type__day type"
  23. :class="{ active: active === 'day' }"
  24. @click="timeType('day')"
  25. >
  26. 1天
  27. </div>
  28. </div>
  29. <el-date-picker
  30. v-model="datevalue"
  31. class="datePicker"
  32. type="datetime"
  33. placeholder="选择日期时间"
  34. prefix-icon="el-icon-date"
  35. format="yyyy-MM-dd HH:mm"
  36. value-format="yyyy-MM-dd HH:mm:ss"
  37. size="mini"
  38. :picker-options="pickerOptions"
  39. @change="onDateTimeChange()"
  40. />
  41. </div>
  42. </div>
  43. <div
  44. :id="'main' + key"
  45. class="charts"
  46. />
  47. </div></div></box>
  48. </template>
  49. <script>
  50. import Box from './Box'
  51. import * as echarts from 'echarts'
  52. import { getCameras } from '@/api/external'
  53. import { getStatistic } from '@/api/camera'
  54. export default {
  55. components: {
  56. Box
  57. },
  58. props: {
  59. device: {
  60. type: Object,
  61. required: true
  62. },
  63. full: {
  64. type: Boolean,
  65. default: false
  66. }
  67. },
  68. data () {
  69. return {
  70. cameraType: 2,
  71. datevalue: new Date(),
  72. active: 'hour', // hour是小时,day是天
  73. imgUrl: {
  74. setting: require('@/assets/icon_setting.png'),
  75. stop: require('@/assets/icon_stop.png'),
  76. start: require('@/assets/icon_start.png'),
  77. refresh: require('@/assets/icon_refresh.png')
  78. },
  79. settingActive: 0,
  80. setData: ['分辨率', '帧率', '码流'],
  81. settingData: [[], [], []],
  82. settingTab: true,
  83. settingBshow: false,
  84. echartsData: [],
  85. player: null,
  86. availableParam: {},
  87. infoData: {},
  88. videoLoading: false,
  89. settingDatacopy: [],
  90. camera: {},
  91. key: this.full ? 1 : 0,
  92. pickerOptions: {
  93. disabledDate (time) {
  94. return time.getTime() > Date.now()
  95. }
  96. }
  97. }
  98. },
  99. mounted () {
  100. this.timeType(this.active)
  101. // this.getCameras()
  102. },
  103. methods: {
  104. getCameras () {
  105. const key = Date.now()
  106. this.$key = key
  107. getCameras({
  108. deviceId: this.device.id,
  109. cameraType: this.cameraType
  110. }).then(({ data }) => {
  111. if (!data.length) {
  112. return
  113. }
  114. if (key === this.$key) {
  115. data = data.map(({ thirdPartyDevice }) => thirdPartyDevice)
  116. }
  117. this.camera = data[0] // 取一个
  118. this.timeType(this.active)
  119. // this.getStatistic(
  120. // this.getStarttime(new Date(), 'now'),
  121. // this.getStarttime(new Date())
  122. // )
  123. })
  124. },
  125. // getxdata (data) {
  126. // const arr = []
  127. // data.forEach(item => {
  128. // const time = item.eventTime.slice(11, 16)
  129. // arr.push(time)
  130. // })
  131. // return arr
  132. // },
  133. // getydata (data) {
  134. // const arr = []
  135. // data.forEach(item => {
  136. // arr.push(item.insidePeopleNum)
  137. // })
  138. // return arr
  139. // },
  140. // mock
  141. getxdata () {
  142. if (this.active === 'day') {
  143. return Array.from({ length: 24 }, (item, index) => `${index + 1}:00`)
  144. }
  145. const hour = new Date(this.datevalue).getHours()
  146. return [`${hour}:15`, `${hour}:30`, `${hour}:45`, `${hour + 1}:00`]
  147. },
  148. getydata () {
  149. if (this.active === 'day') {
  150. return Array.from({ length: 24 }, () => Math.floor(Math.random() * 100))
  151. }
  152. return Array.from({ length: 4 }, () => Math.floor(Math.random() * 100))
  153. },
  154. getStatistic (endTime, startTime) {
  155. getStatistic({
  156. deviceId: this.camera.identifier,
  157. startTime,
  158. endTime,
  159. pageIndex: 1,
  160. pageSize: 10000
  161. }).then(({ data }) => {
  162. this.echartsData = data
  163. this.initEchart()
  164. })
  165. },
  166. initEchart () {
  167. const data = this.echartsData.filter(
  168. item => item.insidePeopleNum !== 0
  169. )
  170. const xdata = this.getxdata(data)
  171. const ydata = this.getydata(data)
  172. console.log('initEchart')
  173. const chartDom = document.getElementById(`main${this.key}`)
  174. const myChart = echarts.init(chartDom)
  175. myChart.setOption({
  176. title: {
  177. text: '',
  178. textStyle: {
  179. color: '#fff',
  180. fontWeight: 'bold'
  181. }
  182. // padding: [0, 30],
  183. },
  184. xAxis: {
  185. type: 'category',
  186. data: xdata,
  187. splitLine: {
  188. show: false
  189. },
  190. axisLine: {
  191. lineStyle: {
  192. color: '#4779BC'
  193. }
  194. },
  195. axisLabel: {
  196. color: '#A9CEFF'
  197. }
  198. },
  199. yAxis: {
  200. type: 'value',
  201. minInterval: 1,
  202. splitLine: {
  203. lineStyle: {
  204. color: '#4779BC',
  205. type: 'dashed'
  206. }
  207. },
  208. axisLine: {
  209. show: false,
  210. lineStyle: {
  211. color: '#4779BC'
  212. }
  213. },
  214. axisLabel: {
  215. color: '#A9CEFF'
  216. }
  217. },
  218. grid: {
  219. left: '30',
  220. right: '20',
  221. top: '40',
  222. bottom: '20'
  223. },
  224. series: [
  225. {
  226. data: ydata,
  227. type: 'bar',
  228. showBackground: true,
  229. backgroundStyle: {
  230. color: 'transparent'
  231. },
  232. itemStyle: {
  233. color: '#2956F0'
  234. },
  235. select: {
  236. itemStyle: {
  237. color: 'rgb(0, 234, 255)'
  238. }
  239. }
  240. }
  241. ],
  242. emphasis: {
  243. itemStyle: {
  244. color: '#FFCA1A', // hover时改变柱子颜色
  245. // shadowColor: 'rgba(102,102,102,0.50)',
  246. // shadowOffsetX: 0,
  247. // shadowOffsetY: 2,
  248. // shadowBlur: 6,
  249. borderWidth: 1,
  250. borderColor: '#FF2222',
  251. borderType: 'solid'
  252. }
  253. },
  254. tooltip: {
  255. formatter: '时间:{b}<br />人流量:{c}'
  256. }
  257. })
  258. },
  259. timeType (type) {
  260. this.active = type
  261. // let startTime
  262. // if (this.datevalue.length) {
  263. // startTime = this.datevalue
  264. // } else {
  265. // this.datevalue = new Date()
  266. // startTime = this.getStarttime(new Date(), 'now')
  267. // }
  268. // this.getStatistic(startTime, this.getStarttime(startTime, type))
  269. this.initEchart()
  270. },
  271. onDateTimeChange () {
  272. // if (this.datevalue) {
  273. // this.getStatistic(
  274. // this.datevalue,
  275. // this.getStarttime(this.datevalue, this.active)
  276. // )
  277. // }
  278. if (this.datevalue.getTime() > Date.now()) {
  279. this.datevalue = Date.now()
  280. }
  281. this.initEchart()
  282. },
  283. getStarttime (time, type) {
  284. let onehour = 60 * 60 * 1000
  285. if (type === 'day') {
  286. onehour = 60 * 60 * 1000 * 24
  287. } else if (type === 'now') {
  288. onehour = 0
  289. }
  290. const startTime = new Date(new Date(time).getTime() - onehour)
  291. .toLocaleString('zh', { hour12: false })
  292. .split('/')
  293. .join('-')
  294. const arr = startTime.split(' ')[0].split('-')
  295. for (let i = 0; i < arr.length; i++) {
  296. if (arr[i].length < 2) {
  297. arr[i] = `0${arr[i]}`
  298. }
  299. }
  300. return `${arr.join('-')} ${startTime.split(' ')[1]}`
  301. }
  302. }
  303. }
  304. </script>
  305. <style lang="scss" scoped>
  306. .wrapper {
  307. display: flex;
  308. justify-content: center;
  309. align-items: center;
  310. width: 100%;
  311. height: 100%;
  312. }
  313. .o-detail {
  314. width: 100%;
  315. height: 100%;
  316. }
  317. .timeBtn {
  318. display: flex;
  319. align-items: center;
  320. justify-content: space-around;
  321. margin-top: 20px;
  322. .timeType {
  323. display: flex;
  324. .type {
  325. width: 60px;
  326. height: 24px;
  327. cursor: pointer;
  328. font-size: 12px;
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. background-color: #2e3756;
  333. &.active {
  334. background-color: #2956f0;
  335. }
  336. }
  337. }
  338. .datePicker {
  339. width: 170px;
  340. ::v-deep>.el-input__inner{
  341. background-color: transparent;
  342. color: #fff;
  343. }
  344. }
  345. }
  346. .charts {
  347. width: 100%;
  348. height: 100%;
  349. }
  350. .full {
  351. .charts {
  352. width: 750px;
  353. height: 400px;
  354. margin-bottom: 30px;
  355. }
  356. }
  357. </style>