index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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, computed } 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; cameraRate: number; devicekind: 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; cameraRate: number; devicekind: 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' || item['devicekind'] === 'toHKHLs' || item['devicekind'] === 'HLL') {
  194. // 从海康平台接口获取视频流
  195. const videoType = item['devicekind'] === 'toHKRtsp' ? 'rtsp' : '';
  196. try {
  197. const data = await cameraAddr({ cameraCode: item['addr'], videoType });
  198. if (data && data['url']) {
  199. cameraList.push({ name: item['name'], addr: data['url'], cameraRate: item['cameraRate'], devicekind: item['devicekind'] });
  200. }
  201. // cameraList.push({
  202. // name: item['name'],
  203. // // addr: 'http://219.151.31.38/liveplay-kk.rtxapp.com/live/program/live/hnwshd/4000000/mnf.m3u8'
  204. // addr: 'https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.mp4/.m3u8',
  205. // });
  206. } catch (error) {}
  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'], cameraRate: item['cameraRate'], devicekind: item['devicekind'] });
  212. }
  213. }
  214. addrList.value = cameraList;
  215. console.log(addrList.value, ' addrList.value-------------');
  216. }
  217. }
  218. async function getVideoAddrsSon(Id) {
  219. clearCamera();
  220. playerList.value = [];
  221. let res = await getVentanalyCamera({ deviceid: Id });
  222. if (res.records.length != 0) {
  223. const cameraList = <{ name: string; addr: string; cameraRate: number; devicekind: string }[]>[];
  224. const cameras = res.records;
  225. for (let i = 0; i < cameras.length; i++) {
  226. const item = cameras[i];
  227. if (item['devicekind'] === 'toHKRtsp' || item['devicekind'] === 'toHKHLs' || item['devicekind'] === 'HLL') {
  228. // 从海康平台接口获取视频流
  229. const videoType = item['devicekind'] === 'toHKRtsp' ? 'rtsp' : '';
  230. try {
  231. const data = await cameraAddr({ cameraCode: item['addr'], videoType });
  232. if (data && data['url']) {
  233. cameraList.push({ name: item['name'], addr: data['url'], cameraRate: item['cameraRate'], devicekind: item['devicekind'] });
  234. }
  235. // cameraList.push({
  236. // name: item['name'],
  237. // // addr: 'http://219.151.31.38/liveplay-kk.rtxapp.com/live/program/live/hnwshd/4000000/mnf.m3u8'
  238. // addr: 'https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.mp4/.m3u8',
  239. // });
  240. } catch (error) {}
  241. } else {
  242. if (item['addr'].includes('0.0.0.0')) {
  243. item['addr'] = item['addr'].replace('0.0.0.0', window.location.hostname);
  244. }
  245. cameraList.push({ name: item['name'], addr: item['addr'], cameraRate: item['cameraRate'], devicekind: item['devicekind'] });
  246. }
  247. }
  248. addrList.value = cameraList;
  249. }
  250. }
  251. async function onChange(page) {
  252. current.value = page;
  253. await getVideoAddrs();
  254. getVideo();
  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, item.cameraRate, item.devicekind);
  269. }
  270. }
  271. }
  272. function setNoRtspVideo(id, videoAddr, cameraRate, devicekind) {
  273. const fileExtension = videoAddr.split('.').pop();
  274. if (fileExtension === 'flv' || devicekind == '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', 'progress', 'play', 'i18n', 'volume', 'fullscreen', 'screenShot', 'playbackRate'],
  290. closeVideoClick: true,
  291. customConfig: {
  292. isClickPlayBack: false,
  293. },
  294. defaultPlaybackRate: cameraRate || 1,
  295. controls: false,
  296. flv: {
  297. retryCount: 3, // 重试 3 次,默认值
  298. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  299. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  300. fetchOptions: {
  301. // 该参数会透传给 fetch,默认值为 undefined
  302. mode: 'cors',
  303. },
  304. targetLatency: 10, // 直播目标延迟,默认 10 秒
  305. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  306. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  307. maxJumpDistance: 10,
  308. },
  309. });
  310. playerList.value.push(player);
  311. }
  312. if (fileExtension === 'm3u8' || devicekind == 'm3u8') {
  313. let player;
  314. if (document.createElement('video').canPlayType('application/vnd.apple.mpegurl')) {
  315. // 原生支持 hls 播放
  316. player = new Player({
  317. lang: 'zh',
  318. id: id,
  319. url: videoAddr,
  320. width: 589,
  321. height: 330,
  322. isLive: true,
  323. autoplay: true,
  324. autoplayMuted: true,
  325. cors: true,
  326. ignores: ['time', 'progress', 'play', 'i18n', 'volume', 'fullscreen', 'screenShot', 'playbackRate'],
  327. poster: '/src/assets/images/vent/noSinge.png',
  328. defaultPlaybackRate: cameraRate || 1,
  329. controls: false,
  330. hls: {
  331. retryCount: 3, // 重试 3 次,默认值
  332. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  333. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  334. fetchOptions: {
  335. // 该参数会透传给 fetch,默认值为 undefined
  336. mode: 'cors',
  337. },
  338. targetLatency: 10, // 直播目标延迟,默认 10 秒
  339. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  340. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  341. maxJumpDistance: 10,
  342. },
  343. });
  344. } else if (HlsPlugin.isSupported()) {
  345. // 第一步
  346. player = new Player({
  347. lang: 'zh',
  348. id: id,
  349. url: videoAddr,
  350. width: 589,
  351. height: 330,
  352. isLive: true,
  353. autoplay: true,
  354. autoplayMuted: true,
  355. plugins: [HlsPlugin], // 第二步
  356. poster: '/src/assets/images/vent/noSinge.png',
  357. ignores: ['time', 'progress', 'play', 'i18n', 'volume', 'fullscreen', 'screenShot', 'playbackRate'],
  358. defaultPlaybackRate: cameraRate || 1,
  359. controls: false,
  360. hls: {
  361. retryCount: 3, // 重试 3 次,默认值
  362. retryDelay: 1000, // 每次重试间隔 1 秒,默认值
  363. loadTimeout: 10000, // 请求超时时间为 10 秒,默认值
  364. fetchOptions: {
  365. // 该参数会透传给 fetch,默认值为 undefined
  366. mode: 'cors',
  367. },
  368. targetLatency: 10, // 直播目标延迟,默认 10 秒
  369. maxLatency: 20, // 直播允许的最大延迟,默认 20 秒
  370. disconnectTime: 10, // 直播断流时间,默认 0 秒,(独立使用时等于 maxLatency)
  371. maxJumpDistance: 10,
  372. },
  373. });
  374. }
  375. playerList.value.push(player);
  376. }
  377. }
  378. function goFullScreen(domId) {
  379. const videoDom = document.getElementById(domId) as HTMLVideoElement;
  380. if (videoDom.requestFullscreen) {
  381. videoDom.requestFullscreen();
  382. videoDom.play();
  383. } else if (videoDom.mozRequestFullscreen) {
  384. videoDom.mozRequestFullscreen();
  385. videoDom.play();
  386. } else if (videoDom.webkitRequestFullscreen) {
  387. videoDom.webkitRequestFullscreen();
  388. videoDom.play();
  389. } else if (videoDom.msRequestFullscreen) {
  390. videoDom.msRequestFullscreen();
  391. videoDom.play();
  392. }
  393. }
  394. function clearCamera() {
  395. const num = webRtcServerList.length;
  396. for (let i = 0; i < num; i++) {
  397. if (webRtcServerList[i]) {
  398. webRtcServerList[i].disconnect();
  399. webRtcServerList[i] = null;
  400. }
  401. }
  402. for (let i = 0; i < playerList.value.length; i++) {
  403. const player = playerList.value[i];
  404. if (player.destroy) player.destroy();
  405. }
  406. playerList.value = [];
  407. }
  408. onMounted(async () => {
  409. await getCameraDevKindList();
  410. await getVideoAddrs();
  411. getVideo();
  412. });
  413. onUnmounted(() => {
  414. clearCamera();
  415. });
  416. </script>
  417. <style lang="less">
  418. @import '/@/design/theme.less';
  419. @{theme-deepblue} {
  420. .camera-container {
  421. --image-camera_bg: url('/@/assets/images/themify/deepblue/vent/camera_bg.png');
  422. }
  423. }
  424. .camera-container {
  425. --image-camera_bg: url('/@/assets/images/vent/camera_bg.png');
  426. position: relative;
  427. width: calc(100% - 30px);
  428. height: calc(100% - 84px);
  429. display: flex;
  430. margin: 15px;
  431. justify-content: space-between;
  432. align-items: center;
  433. .left-area {
  434. width: 15%;
  435. height: 100%;
  436. padding: 20px;
  437. border: 1px solid #99e8ff66;
  438. background: #27546e1a;
  439. box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  440. -moz-box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  441. -webkit-box-shadow: 0px 0px 50px 1px rgb(149 235 255 / 5%) inset;
  442. box-sizing: border-box;
  443. // lxh
  444. .iconfont {
  445. color: #fff;
  446. font-size: 12px;
  447. margin-left: 5px;
  448. }
  449. }
  450. .right-area {
  451. width: 85%;
  452. height: 100%;
  453. padding: 0px 0px 0px 15px;
  454. box-sizing: border-box;
  455. .camera-box {
  456. width: 100%;
  457. height: calc(100% - 60px);
  458. display: flex;
  459. justify-content: space-around;
  460. align-items: flex-start;
  461. flex-wrap: wrap;
  462. overflow-y: auto;
  463. }
  464. .camera-box1 {
  465. width: 100%;
  466. height: calc(100% - 60px);
  467. display: flex;
  468. justify-content: flex-start;
  469. align-items: flex-start;
  470. flex-wrap: wrap;
  471. overflow-y: auto;
  472. }
  473. .player-box {
  474. width: 626px;
  475. height: 370px;
  476. padding: 17px 18px;
  477. background: var(--image-camera_bg);
  478. background-size: 100% 100%;
  479. position: relative;
  480. margin: 10px;
  481. .player-name {
  482. font-size: 14px;
  483. position: absolute;
  484. top: 35px;
  485. right: 15px;
  486. color: #fff;
  487. background-color: hsla(0, 0%, 50%, 0.5);
  488. border-radius: 2px;
  489. padding: 1px 5px;
  490. max-width: 120px;
  491. overflow: hidden;
  492. white-space: nowrap;
  493. text-overflow: ellipsis;
  494. z-index: 999;
  495. }
  496. .click-box {
  497. position: absolute;
  498. width: 100%;
  499. height: 100%;
  500. top: 0;
  501. left: 0;
  502. }
  503. }
  504. .pagination {
  505. width: 100%;
  506. height: 60px;
  507. display: flex;
  508. justify-content: center;
  509. align-items: center;
  510. }
  511. }
  512. }
  513. :deep(video) {
  514. width: 100% !important;
  515. height: 100% !important;
  516. object-fit: cover !important;
  517. }
  518. </style>