index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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 types, devicetype
  114. if (node.itemValue.indexOf('&') != -1) {
  115. types = node.itemValue.substring(node.itemValue.indexOf('&') + 1)
  116. devicetype = node.itemValue.substring(0, node.itemValue.indexOf('&'))
  117. } else {
  118. types = ''
  119. devicetype = ''
  120. }
  121. let res = await getDevice({ ids: types, devicetype: devicetype })
  122. if (res.msgTxt.length != 0) {
  123. res.msgTxt[0].datalist.forEach(el => {
  124. el.pid = node.id
  125. el.isFolder = false
  126. el.title = el.strinstallpos
  127. el.id = el.deviceID
  128. })
  129. listArr[0].children.forEach(v => {
  130. if (v.id == node.id) {
  131. v.children = res.msgTxt[0].datalist
  132. }
  133. })
  134. }
  135. searchParam.devKind = node.itemValue
  136. searchParam.strType = ''
  137. await getVideoAddrs()
  138. getVideo()
  139. } else {
  140. await getVideoAddrsSon(node.deviceID)
  141. getVideo()
  142. }
  143. } else {
  144. searchParam.devKind = ''
  145. searchParam.strType = ''
  146. await getVideoAddrs()
  147. getVideo()
  148. }
  149. };
  150. //点击详情跳转
  151. function onDetail(node) {
  152. let str = listArr[0].children.filter(v => v.id == node.pid)[0].itemValue
  153. let type = str.indexOf('&') != -1 ? str.substring(0, str.indexOf('&')) : ''
  154. console.log(type, 'type--------')
  155. switch (type) {
  156. case 'pulping'://注浆
  157. router.push('/grout-home')
  158. break;
  159. case 'window'://自动风窗
  160. router.push('/monitorChannel/monitor-window?id=' + node.deviceID)
  161. break;
  162. case 'gate'://自动风门
  163. router.push('/monitorChannel/monitor-gate?id=' + node.deviceID + '&deviceType=' + node.deviceType)
  164. break;
  165. case 'fanlocal'://局部风机
  166. router.push('/monitorChannel/monitor-fanlocal?id=' + node.deviceID + '&deviceType=fanlocal')
  167. break;
  168. case 'fanmain'://主风机
  169. router.push('/monitorChannel/monitor-fanmain?id=' + node.deviceID)
  170. break;
  171. case 'forcFan'://压风机
  172. router.push('/forcFan/home')
  173. break;
  174. case 'pump'://瓦斯抽采泵
  175. router.push('/monitorChannel/gasPump-home')
  176. break;
  177. case 'nitrogen'://制氮
  178. router.push('/nitrogen-home')
  179. break;
  180. }
  181. }
  182. async function getVideoAddrs() {
  183. clearCamera();
  184. playerList.value = []
  185. let paramKind = searchParam.devKind.substring(0, searchParam.devKind.indexOf('&'))
  186. let res = await list({ devKind: paramKind, strType: searchParam.strType, pageSize: pageSize.value, pageNo: current.value })
  187. total.value = res['total'] || 0
  188. if (res.records.length != 0) {
  189. const cameraList = <{ name: string, addr: string }[]>[]
  190. const cameras = res.records
  191. for (let i = 0; i < cameras.length; i++) {
  192. const item = cameras[i];
  193. if (item['devicekind'] === 'toHKRtsp') {
  194. // 从海康平台接口获取视频流
  195. try {
  196. const data = await cameraAddr({ cameraCode: item['addr'] });
  197. if (data) {
  198. cameraList.push({ name: item['name'], addr: data['url'] });
  199. }
  200. // cameraList.push({
  201. // name: item['name'],
  202. // // addr: 'http://219.151.31.38/liveplay-kk.rtxapp.com/live/program/live/hnwshd/4000000/mnf.m3u8'
  203. // addr: 'https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.mp4/.m3u8',
  204. // });
  205. } catch (error) {
  206. }
  207. } else {
  208. if (item['addr'].includes('0.0.0.0')) {
  209. item['addr'] = item['addr'].replace('0.0.0.0', window.location.hostname)
  210. }
  211. cameraList.push({ name: item['name'], addr: item['addr'] });
  212. }
  213. }
  214. addrList.value = cameraList
  215. }
  216. }
  217. async function getVideoAddrsSon(Id) {
  218. clearCamera();
  219. playerList.value = []
  220. let res = await getVentanalyCamera({ deviceid: Id })
  221. if (res.records.length != 0) {
  222. const cameraList = <{ name: string, addr: string }[]>[]
  223. const cameras = res.records
  224. for (let i = 0; i < cameras.length; i++) {
  225. const item = cameras[i];
  226. if (item['devicekind'] === 'toHKRtsp') {
  227. // 从海康平台接口获取视频流
  228. try {
  229. const data = await cameraAddr({ cameraCode: item['addr'] });
  230. if (data && data['url']) {
  231. cameraList.push({ name: item['name'], addr: data['url'] });
  232. }
  233. // cameraList.push({
  234. // name: item['name'],
  235. // // addr: 'http://219.151.31.38/liveplay-kk.rtxapp.com/live/program/live/hnwshd/4000000/mnf.m3u8'
  236. // addr: 'https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.mp4/.m3u8',
  237. // });
  238. } catch (error) {
  239. }
  240. } else {
  241. if (item['addr'].includes('0.0.0.0')) {
  242. item['addr'] = item['addr'].replace('0.0.0.0', window.location.hostname)
  243. }
  244. cameraList.push({ name: item['name'], addr: item['addr'] });
  245. }
  246. }
  247. addrList.value = cameraList
  248. }
  249. }
  250. function onChange(page) {
  251. current.value = page;
  252. getVideoAddrs().then(() => {
  253. getVideo()
  254. })
  255. }
  256. function getVideo() {
  257. const ip = VUE_APP_URL.webRtcUrl;
  258. for (let i = 0; i < addrList.value.length; i++) {
  259. const item = addrList.value[i]
  260. if (item.addr.startsWith('rtsp://')) {
  261. const dom = document.getElementById('video' + i) as HTMLVideoElement
  262. dom.muted = true;
  263. dom.volume = 0
  264. const webRtcServer = new window['WebRtcStreamer'](dom, location.protocol + ip)
  265. webRtcServerList.push(webRtcServer)
  266. webRtcServer.connect(item.addr)
  267. } else {
  268. setNoRtspVideo('player' + i, item.addr)
  269. }
  270. }
  271. }
  272. function setNoRtspVideo(id, videoAddr) {
  273. const fileExtension = videoAddr.split('.').pop();
  274. if (fileExtension === 'flv') {
  275. const player = new Player({
  276. lang: 'zh',
  277. id: id,
  278. url: videoAddr,
  279. width: 589,
  280. height: 330,
  281. poster: '/src/assets/images/vent/noSinge.png',
  282. plugins: [FlvPlugin],
  283. fluid: true,
  284. autoplay: true,
  285. isLive: true,
  286. playsinline: true,
  287. screenShot: true,
  288. whitelist: [''],
  289. ignores: ['time'],
  290. closeVideoClick: true,
  291. customConfig: {
  292. isClickPlayBack: false
  293. },
  294. flv: {
  295. retryCount: 3, // 重试 3 次,默认值
  296. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  297. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  298. fetchOptions: {
  299. // 该参数会透传给 fetch,默认值为 undefined
  300. mode: 'cors'
  301. },
  302. targetLatency: 10, // 直播目标延迟,默认 10 秒
  303. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  304. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  305. maxJumpDistance: 10,
  306. }
  307. });
  308. playerList.value.push(player)
  309. }
  310. if (fileExtension === 'm3u8') {
  311. let player
  312. if (document.createElement('video').canPlayType('application/vnd.apple.mpegurl')) {
  313. // 原生支持 hls 播放
  314. player = new Player({
  315. lang: 'zh',
  316. id: id,
  317. url: videoAddr,
  318. width: 589,
  319. height: 330,
  320. isLive: true,
  321. autoplay: true,
  322. autoplayMuted: true,
  323. cors: true,
  324. poster: '/src/assets/images/vent/noSinge.png',
  325. hls: {
  326. retryCount: 3, // 重试 3 次,默认值
  327. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  328. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  329. fetchOptions: {
  330. // 该参数会透传给 fetch,默认值为 undefined
  331. mode: 'cors'
  332. },
  333. targetLatency: 10, // 直播目标延迟,默认 10 秒
  334. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  335. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  336. maxJumpDistance: 10,
  337. }
  338. })
  339. } else if (HlsPlugin.isSupported()) { // 第一步
  340. player = new Player({
  341. lang: 'zh',
  342. id: id,
  343. url: videoAddr,
  344. width: 589,
  345. height: 330,
  346. isLive: true,
  347. autoplay: true,
  348. autoplayMuted: true,
  349. plugins: [HlsPlugin], // 第二步
  350. poster: '/src/assets/images/vent/noSinge.png',
  351. hls: {
  352. retryCount: 3, // 重试 3 次,默认值
  353. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  354. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  355. fetchOptions: {
  356. // 该参数会透传给 fetch,默认值为 undefined
  357. mode: 'cors'
  358. },
  359. targetLatency: 10, // 直播目标延迟,默认 10 秒
  360. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  361. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  362. maxJumpDistance: 10,
  363. }
  364. })
  365. }
  366. playerList.value.push(player)
  367. }
  368. }
  369. function goFullScreen(domId) {
  370. const videoDom = document.getElementById(domId) as HTMLVideoElement
  371. if (videoDom.requestFullscreen) {
  372. videoDom.requestFullscreen()
  373. videoDom.play()
  374. } else if (videoDom.mozRequestFullscreen) {
  375. videoDom.mozRequestFullscreen()
  376. videoDom.play()
  377. } else if (videoDom.webkitRequestFullscreen) {
  378. videoDom.webkitRequestFullscreen()
  379. videoDom.play()
  380. } else if (videoDom.msRequestFullscreen) {
  381. videoDom.msRequestFullscreen()
  382. videoDom.play()
  383. }
  384. }
  385. function clearCamera() {
  386. const num = webRtcServerList.length
  387. for (let i = 0; i < num; i++) {
  388. if(webRtcServerList[i]){
  389. webRtcServerList[i].disconnect()
  390. webRtcServerList[i] = null
  391. }
  392. }
  393. for (let i = 0; i < playerList.value.length; i++) {
  394. const player = playerList.value[i]
  395. if (player.destroy) player.destroy()
  396. }
  397. playerList.value = []
  398. }
  399. onMounted(async () => {
  400. await getVideoAddrs()
  401. // getTreeList()
  402. getCameraDevKindList()
  403. getVideo()
  404. })
  405. onUnmounted(() => {
  406. clearCamera()
  407. })
  408. </script>
  409. <style lang="less">
  410. .camera-container {
  411. position: relative;
  412. width: calc(100% - 30px);
  413. height: calc(100% - 84px);
  414. display: flex;
  415. margin: 15px;
  416. justify-content: space-between;
  417. align-items: center;
  418. .left-area {
  419. width: 15%;
  420. height: 100%;
  421. padding: 20px;
  422. border: 1px solid #99e8ff66;
  423. background: #27546e1a;
  424. box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  425. -moz-box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  426. -webkit-box-shadow: 0px 0px 50px 1px rgb(149 235 255 / 5%) inset;
  427. box-sizing: border-box;
  428. // lxh
  429. .iconfont {
  430. color: #fff;
  431. font-size: 12px;
  432. margin-left: 5px;
  433. }
  434. }
  435. .right-area {
  436. width: 85%;
  437. height: 100%;
  438. padding: 0px 0px 0px 15px;
  439. box-sizing: border-box;
  440. .camera-box {
  441. width: 100%;
  442. height: calc(100% - 60px);
  443. display: flex;
  444. justify-content: space-around;
  445. align-items: flex-start;
  446. flex-wrap: wrap;
  447. overflow-y: auto;
  448. }
  449. .camera-box1 {
  450. width: 100%;
  451. height: calc(100% - 60px);
  452. display: flex;
  453. justify-content: flex-start;
  454. align-items: flex-start;
  455. flex-wrap: wrap;
  456. overflow-y: auto;
  457. }
  458. .player-box {
  459. width: 626px;
  460. height: 370px;
  461. padding: 17px 18px;
  462. background: url('/@/assets/images/vent/camera_bg.png');
  463. background-size: 100% 100%;
  464. position: relative;
  465. margin: 10px;
  466. .player-name {
  467. font-size: 14px;
  468. position: absolute;
  469. top: 15px;
  470. right: 15px;
  471. color: #fff;
  472. background-color: hsla(0, 0%, 50%, .5);
  473. border-radius: 2px;
  474. padding: 1px 5px;
  475. max-width: 120px;
  476. overflow: hidden;
  477. white-space: nowrap;
  478. text-overflow: ellipsis;
  479. z-index: 999;
  480. }
  481. .click-box {
  482. position: absolute;
  483. width: 100%;
  484. height: 100%;
  485. top: 0;
  486. left: 0;
  487. }
  488. }
  489. .pagination {
  490. width: 100%;
  491. height: 60px;
  492. display: flex;
  493. justify-content: center;
  494. align-items: center;
  495. }
  496. }
  497. }
  498. :deep(video) {
  499. width: 100% !important;
  500. height: 100% !important;
  501. object-fit: cover !important;
  502. }
  503. </style>