index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <div class="camera-container">
  3. <div class="left-area">
  4. <cameraTree :selected="selected" :list="listArr" :draggable="true" @detail-node="onDetail" @on-click="onClick">
  5. <template #icon="{ item }">
  6. <template v-if="item.isFolder">
  7. <SvgIcon v-if="item.expanded" size="18" name="file-open" />
  8. <SvgIcon v-else size="18" name="file-close" />
  9. </template>
  10. <treeIcon class="iconfont" :title="item.title" v-else />
  11. </template>
  12. <template #operation="{ type }">
  13. <!-- <i class="iconfont icon-eyeoutlined"></i> -->
  14. <span style="color:#ccc;font-size:12px">详情</span>
  15. </template>
  16. </cameraTree>
  17. </div>
  18. <div class="right-area" v-if="addrList.length > 0">
  19. <div class="vent-flex-row-wrap" :class="addrList.length == 1 ? 'camera-box1' : 'camera-box'">
  20. <div v-for="(item, index) in addrList" :key="index" class="player-box">
  21. <div class="player-name">{{ item.name }}</div>
  22. <div style="padding-top:3px">
  23. <template v-if="item.addr.startsWith('rtsp://')">
  24. <video :id="`video${index}`" muted autoplay></video>
  25. <div class="click-box" @dblclick="goFullScreen(`video${index}`)"></div>
  26. </template>
  27. <template v-else>
  28. <div :id="'player' + index"></div>
  29. </template>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="pagination">
  34. <Pagination v-model:current="current" v-model:page-size="pageSize" :total="total" @change="onChange" />
  35. </div>
  36. </div>
  37. <div class="camera-box" v-else>
  38. <Empty />
  39. </div>
  40. </div>
  41. </template>
  42. <script lang="ts" setup>
  43. import { onMounted, onUnmounted, ref, reactive } from 'vue';
  44. import { useRouter } from 'vue-router';
  45. import { Pagination, Empty } from 'ant-design-vue';
  46. import { list, cameraAddr, getCameraDevKind, getDevice, getVentanalyCamera } from './camera.api'
  47. import Player, { I18N } from 'xgplayer';
  48. import ZH from 'xgplayer/es/lang/zh-cn'
  49. import HlsPlugin from 'xgplayer-hls';
  50. import FlvPlugin from 'xgplayer-flv';
  51. import 'xgplayer/dist/index.min.css';
  52. import cameraTree from './common/cameraTree.vue';
  53. import { SvgIcon } from '/@/components/Icon';
  54. import treeIcon from './common/Icon/treeIcon.vue';
  55. //当前选中树节点
  56. let selected = reactive<any>({
  57. id: null,
  58. pid: null,
  59. title: '',
  60. isFolder: false,
  61. });
  62. //tree菜单列表
  63. let listArr = reactive<any[]>([]);
  64. let searchParam = reactive({
  65. devKind: '',
  66. strType: '',
  67. })
  68. I18N.use(ZH)
  69. let router = useRouter(); //路由
  70. const pageSize = ref(4)
  71. const current = ref(1)
  72. const total = ref(0)
  73. const playerList = ref([])
  74. const webRtcServerList = <any[]>[]
  75. let addrList = ref<{ name: string, addr: string }[]>([])
  76. async function getCameraDevKindList() {
  77. let res = await getCameraDevKind()
  78. if (res.length != 0) {
  79. listArr.length = 0
  80. listArr.push({
  81. pid: 'root',
  82. isFolder: true,
  83. expanded: true,
  84. title: '全部',
  85. id: 0,
  86. children: []
  87. })
  88. res.forEach(el => {
  89. el.pid = 0
  90. el.isFolder = true,
  91. el.expanded = false,
  92. el.title = el.itemText
  93. el.id = el.subDictId
  94. el.children = []
  95. listArr[0].children.push(el)
  96. })
  97. selected.id = listArr[0].id;
  98. selected.pid = listArr[0].pid;
  99. selected.title = listArr[0].title;
  100. selected.isFolder = listArr[0].isFolder;
  101. }
  102. }
  103. //点击目录
  104. async function onClick(node) {
  105. if (selected.title === node.title && selected.id === node.id) return
  106. current.value = 1
  107. selected.id = node.id;
  108. selected.pid = node.pid;
  109. selected.title = node.title;
  110. selected.isFolder = node.isFolder;
  111. if (node.pid != 'root') {
  112. if (node.isFolder) {
  113. let res = await getDevice({ devicetype: node.itemValue })
  114. if (res.msgTxt.length != 0) {
  115. res.msgTxt[0].datalist.forEach(el => {
  116. el.pid = node.id
  117. el.isFolder = false
  118. el.title = el.strinstallpos
  119. el.id = el.deviceID
  120. })
  121. listArr[0].children.forEach(v => {
  122. if (v.id == node.id) {
  123. v.children = res.msgTxt[0].datalist
  124. }
  125. })
  126. }
  127. searchParam.devKind = node.itemValue
  128. searchParam.strType = ''
  129. await getVideoAddrs()
  130. } else {
  131. getVideoAddrsSon(node.deviceID)
  132. }
  133. } else {
  134. searchParam.devKind = ''
  135. searchParam.strType = ''
  136. await getVideoAddrs()
  137. }
  138. getVideo()
  139. };
  140. //点击详情跳转
  141. function onDetail(node) {
  142. let type=listArr[0].children.filter(v=>v.id==node.pid)[0].itemValue
  143. console.log(type,'type--------')
  144. switch (type) {
  145. case 'pulping'://注浆
  146. router.push('/grout-home')
  147. break;
  148. case 'window'://自动风窗
  149. router.push('/micro-vent-3dModal/dashboard/analysis?type=tunMonitor&deviceType=window')
  150. break;
  151. case 'gate'://自动风门
  152. router.push('/micro-vent-3dModal/dashboard/analysis?type=tunMonitor&deviceType=gate')
  153. break;
  154. case 'fanlocal'://局部风机
  155. router.push('/micro-vent-3dModal/dashboard/analysis?type=tunMonitor&deviceType=fanlocal')
  156. break;
  157. case 'fanmain'://主风机
  158. router.push('/micro-vent-3dModal/dashboard/analysis?type=tunMonitor&deviceType=fanmain')
  159. break;
  160. case 'forcFan'://压风机
  161. router.push('/forcFan/home')
  162. break;
  163. case 'pump'://瓦斯抽采泵
  164. router.push('/monitorChannel/gasPump-home')
  165. break;
  166. case 'nitrogen'://制氮
  167. router.push('/nitrogen-home')
  168. break;
  169. }
  170. }
  171. async function getVideoAddrs() {
  172. clearCamera();
  173. playerList.value = []
  174. let res = await list({ ...searchParam, pageSize: pageSize.value, pageNo: current.value })
  175. total.value = res['total'] || 0
  176. if (res.records.length != 0) {
  177. const cameraList = <{ name: string, addr: string }[]>[]
  178. const cameras = res.records
  179. for (let i = 0; i < cameras.length; i++) {
  180. const item = cameras[i];
  181. if (item['devicekind'] === 'toHKRtsp') {
  182. // 从海康平台接口获取视频流
  183. try {
  184. const data = await cameraAddr({ cameraCode: item['addr'] });
  185. if (data) {
  186. cameraList.push({ name: item['name'], addr: data['url'] });
  187. }
  188. // cameraList.push({
  189. // name: item['name'],
  190. // // addr: 'http://219.151.31.38/liveplay-kk.rtxapp.com/live/program/live/hnwshd/4000000/mnf.m3u8'
  191. // addr: 'https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.mp4/.m3u8',
  192. // });
  193. } catch (error) {
  194. }
  195. } else {
  196. if (item['addr'].includes('0.0.0.0')) {
  197. item['addr'] = item['addr'].replace('0.0.0.0', window.location.hostname)
  198. }
  199. cameraList.push({ name: item['name'], addr: item['addr'] });
  200. }
  201. }
  202. addrList.value = cameraList
  203. }
  204. }
  205. async function getVideoAddrsSon(Id) {
  206. clearCamera();
  207. playerList.value = []
  208. let res = await getVentanalyCamera({ deviceid: Id })
  209. if (res.records.length != 0) {
  210. const cameraList = <{ name: string, addr: string }[]>[]
  211. const cameras = res.records
  212. for (let i = 0; i < cameras.length; i++) {
  213. const item = cameras[i];
  214. if (item['devicekind'] === 'toHKRtsp') {
  215. // 从海康平台接口获取视频流
  216. try {
  217. const data = await cameraAddr({ cameraCode: item['addr'] });
  218. if (data && data['url']) {
  219. cameraList.push({ name: item['name'], addr: data['url'] });
  220. }
  221. // cameraList.push({
  222. // name: item['name'],
  223. // // addr: 'http://219.151.31.38/liveplay-kk.rtxapp.com/live/program/live/hnwshd/4000000/mnf.m3u8'
  224. // addr: 'https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.mp4/.m3u8',
  225. // });
  226. } catch (error) {
  227. }
  228. } else {
  229. if (item['addr'].includes('0.0.0.0')) {
  230. item['addr'] = item['addr'].replace('0.0.0.0', window.location.hostname)
  231. }
  232. cameraList.push({ name: item['name'], addr: item['addr'] });
  233. }
  234. }
  235. addrList.value = cameraList
  236. }
  237. }
  238. function onChange(page) {
  239. current.value = page;
  240. getVideoAddrs().then(() => {
  241. getVideo()
  242. })
  243. }
  244. function getVideo() {
  245. const ip = VUE_APP_URL.webRtcUrl;
  246. for (let i = 0; i < addrList.value.length; i++) {
  247. const item = addrList.value[i]
  248. if (item.addr.startsWith('rtsp://')) {
  249. const dom = document.getElementById('video' + i) as HTMLVideoElement
  250. dom.muted = true;
  251. dom.volume = 0
  252. const webRtcServer = new window['WebRtcStreamer'](dom, location.protocol + ip)
  253. webRtcServerList.push(webRtcServer)
  254. webRtcServer.connect(item.addr)
  255. } else {
  256. setNoRtspVideo('player' + i, item.addr)
  257. }
  258. }
  259. }
  260. function setNoRtspVideo(id, videoAddr) {
  261. const fileExtension = videoAddr.split('.').pop();
  262. if (fileExtension === 'flv') {
  263. const player = new Player({
  264. lang: 'zh',
  265. id: id,
  266. url: videoAddr,
  267. width: 589,
  268. height: 330,
  269. poster: '/src/assets/images/vent/noSinge.png',
  270. plugins: [FlvPlugin],
  271. fluid: true,
  272. autoplay: true,
  273. isLive: true,
  274. playsinline: true,
  275. screenShot: true,
  276. whitelist: [''],
  277. ignores: ['time'],
  278. closeVideoClick: true,
  279. customConfig: {
  280. isClickPlayBack: false
  281. },
  282. flv: {
  283. retryCount: 3, // 重试 3 次,默认值
  284. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  285. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  286. fetchOptions: {
  287. // 该参数会透传给 fetch,默认值为 undefined
  288. mode: 'cors'
  289. },
  290. targetLatency: 10, // 直播目标延迟,默认 10 秒
  291. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  292. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  293. maxJumpDistance: 10,
  294. }
  295. });
  296. playerList.value.push(player)
  297. }
  298. if (fileExtension === 'm3u8') {
  299. let player
  300. if (document.createElement('video').canPlayType('application/vnd.apple.mpegurl')) {
  301. // 原生支持 hls 播放
  302. player = new Player({
  303. lang: 'zh',
  304. id: id,
  305. url: videoAddr,
  306. width: 589,
  307. height: 330,
  308. isLive: true,
  309. autoplay: true,
  310. autoplayMuted: true,
  311. cors: true,
  312. poster: '/src/assets/images/vent/noSinge.png',
  313. hls: {
  314. retryCount: 3, // 重试 3 次,默认值
  315. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  316. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  317. fetchOptions: {
  318. // 该参数会透传给 fetch,默认值为 undefined
  319. mode: 'cors'
  320. },
  321. targetLatency: 10, // 直播目标延迟,默认 10 秒
  322. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  323. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  324. maxJumpDistance: 10,
  325. }
  326. })
  327. } else if (HlsPlugin.isSupported()) { // 第一步
  328. player = new Player({
  329. lang: 'zh',
  330. id: id,
  331. url: videoAddr,
  332. width: 589,
  333. height: 330,
  334. isLive: true,
  335. autoplay: true,
  336. autoplayMuted: true,
  337. plugins: [HlsPlugin], // 第二步
  338. poster: '/src/assets/images/vent/noSinge.png',
  339. hls: {
  340. retryCount: 3, // 重试 3 次,默认值
  341. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  342. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  343. fetchOptions: {
  344. // 该参数会透传给 fetch,默认值为 undefined
  345. mode: 'cors'
  346. },
  347. targetLatency: 10, // 直播目标延迟,默认 10 秒
  348. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  349. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  350. maxJumpDistance: 10,
  351. }
  352. })
  353. }
  354. playerList.value.push(player)
  355. }
  356. }
  357. function goFullScreen(domId) {
  358. const videoDom = document.getElementById(domId) as HTMLVideoElement
  359. if (videoDom.requestFullscreen) {
  360. videoDom.requestFullscreen()
  361. videoDom.play()
  362. } else if (videoDom.mozRequestFullscreen) {
  363. videoDom.mozRequestFullscreen()
  364. videoDom.play()
  365. } else if (videoDom.webkitRequestFullscreen) {
  366. videoDom.webkitRequestFullscreen()
  367. videoDom.play()
  368. } else if (videoDom.msRequestFullscreen) {
  369. videoDom.msRequestFullscreen()
  370. videoDom.play()
  371. }
  372. }
  373. function clearCamera() {
  374. const num = webRtcServerList.length
  375. for (let i = 0; i < num; i++) {
  376. webRtcServerList[i].disconnect()
  377. webRtcServerList[i] = null
  378. }
  379. for (let i = 0; i < playerList.value.length; i++) {
  380. const player = playerList.value[i]
  381. if (player.destroy) player.destroy()
  382. }
  383. playerList.value = []
  384. }
  385. onMounted(async () => {
  386. await getVideoAddrs()
  387. // getTreeList()
  388. getCameraDevKindList()
  389. getVideo()
  390. })
  391. onUnmounted(() => {
  392. clearCamera()
  393. })
  394. </script>
  395. <style lang="less">
  396. .camera-container {
  397. position: relative;
  398. width: calc(100% - 30px);
  399. height: calc(100% - 84px);
  400. display: flex;
  401. margin: 15px;
  402. justify-content: space-between;
  403. align-items: center;
  404. .left-area {
  405. width: 15%;
  406. height: 100%;
  407. padding: 20px;
  408. border: 1px solid #99e8ff66;
  409. background: #27546e1a;
  410. box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  411. -moz-box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  412. -webkit-box-shadow: 0px 0px 50px 1px rgb(149 235 255 / 5%) inset;
  413. box-sizing: border-box;
  414. // lxh
  415. .iconfont {
  416. color: #fff;
  417. font-size: 12px;
  418. margin-left: 5px;
  419. }
  420. }
  421. .right-area {
  422. width: 85%;
  423. height: 100%;
  424. padding: 0px 0px 0px 15px;
  425. box-sizing: border-box;
  426. .camera-box {
  427. width: 100%;
  428. height: calc(100% - 60px);
  429. display: flex;
  430. justify-content: space-around;
  431. align-items: flex-start;
  432. flex-wrap: wrap;
  433. overflow-y: auto;
  434. }
  435. .camera-box1 {
  436. width: 100%;
  437. height: calc(100% - 60px);
  438. display: flex;
  439. justify-content: flex-start;
  440. align-items: flex-start;
  441. flex-wrap: wrap;
  442. overflow-y: auto;
  443. }
  444. .player-box {
  445. width: 626px;
  446. height: 370px;
  447. padding: 17px 18px;
  448. background: url('/@/assets/images/vent/camera_bg.png');
  449. background-size: 100% 100%;
  450. position: relative;
  451. margin: 10px;
  452. .player-name {
  453. font-size: 14px;
  454. position: absolute;
  455. top: 15px;
  456. right: 15px;
  457. color: #fff;
  458. background-color: hsla(0, 0%, 50%, .5);
  459. border-radius: 2px;
  460. padding: 1px 5px;
  461. max-width: 120px;
  462. overflow: hidden;
  463. white-space: nowrap;
  464. text-overflow: ellipsis;
  465. z-index: 999;
  466. }
  467. .click-box {
  468. position: absolute;
  469. width: 100%;
  470. height: 100%;
  471. top: 0;
  472. left: 0;
  473. }
  474. }
  475. .pagination {
  476. width: 100%;
  477. height: 60px;
  478. display: flex;
  479. justify-content: center;
  480. align-items: center;
  481. }
  482. }
  483. }
  484. :deep(video) {
  485. width: 100% !important;
  486. height: 100% !important;
  487. object-fit: cover !important;
  488. }
  489. </style>