VideoImageWindow copy.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <template>
  2. <div
  3. class="video_container"
  4. :class="largeScreen ? 'large_screen' : 'normal_screen'"
  5. >
  6. <!-- 弹窗内容 -->
  7. <div class="dialog_box">
  8. <!-- 头部 -->
  9. <div class="dialog_header_box">
  10. <div class="dialog_header_title">
  11. {{ cameraData ? cameraData.name : "监控视频" }}
  12. </div>
  13. </div>
  14. <!-- 内容 -->
  15. <div
  16. class="dialog_content_box"
  17. :class="{ large_content: largeScreen }"
  18. v-show="!!cameraId"
  19. >
  20. <div class="content_box">
  21. <div
  22. class="img_box"
  23. :class="{ comm_ptz: largeScreen && cameraData.ptzEnable }"
  24. >
  25. <img :src="url" v-if="url" />
  26. <div class="image_slot" v-else>
  27. <i class="el-icon-video-camera"></i>
  28. <span>无信号</span>
  29. </div>
  30. </div>
  31. <div class="control_box" v-if="largeScreen && cameraData.ptzEnable">
  32. <div class="video-opt">
  33. <div class="comm-panel">
  34. <div
  35. class="btn-box"
  36. v-for="item of commandConfig.direction"
  37. :key="item.type"
  38. >
  39. <el-button
  40. type="primary"
  41. :icon="`el-icon-${item.type}`"
  42. size="mini"
  43. @mousedown.native="changePtzCommParam(item.command, false)"
  44. @mouseup.native="changePtzCommParam(item.command, true)"
  45. ></el-button>
  46. </div>
  47. </div>
  48. <div class="zoom-panel">
  49. <div
  50. class="btn-box"
  51. v-for="item of commandConfig.zoom"
  52. :key="item.type"
  53. >
  54. <el-button
  55. type="primary"
  56. :icon="`el-icon-${item.type}`"
  57. size="mini"
  58. @mousedown.native="changePtzCommParam(item.command, false)"
  59. @mouseup.native="changePtzCommParam(item.command, true)"
  60. ></el-button>
  61. </div>
  62. </div>
  63. <div class="speed-panel">
  64. <span class="form-label">速度:</span>
  65. <el-select
  66. class="myInput"
  67. size="mini"
  68. v-model="speed"
  69. placeholder="请选择速度"
  70. >
  71. <el-option
  72. v-for="item in Array.from(
  73. { length: 7 },
  74. (item, index) => index + 1
  75. )"
  76. :key="item"
  77. :label="item"
  78. :value="item"
  79. ></el-option>
  80. </el-select>
  81. </div>
  82. <div class="preset-panel">
  83. <span class="form-label">预置点:</span>
  84. <el-select
  85. class="myInput"
  86. size="mini"
  87. v-model="presetIndex"
  88. placeholder="请选择预置点"
  89. >
  90. <el-option
  91. v-for="item in Array.from(
  92. { length: 255 },
  93. (item, index) => index + 1
  94. )"
  95. :key="item"
  96. :label="item"
  97. :value="item"
  98. ></el-option>
  99. </el-select>
  100. <el-button
  101. type="primary"
  102. size="mini"
  103. @click="changePtzPresetParam(8)"
  104. >设置</el-button
  105. >
  106. <el-button
  107. type="primary"
  108. size="mini"
  109. @click="changePtzPresetParam(39)"
  110. >转到</el-button
  111. >
  112. </div>
  113. <div class="playback-panel">
  114. <span class="form-label">时间:</span>
  115. <el-date-picker
  116. style="max-width: 170px"
  117. class="myInput"
  118. v-model="startTime"
  119. type="datetime"
  120. placeholder="选择回放开始时间"
  121. size="mini"
  122. ></el-date-picker>
  123. <el-button
  124. type="success"
  125. size="mini"
  126. @click="changePlayTypeParam(true)"
  127. >回放</el-button
  128. >
  129. <el-button
  130. type="primary"
  131. size="mini"
  132. @click="changePlayTypeParam(false)"
  133. >实时</el-button
  134. >
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. <div
  141. class="dialog_content_box"
  142. :class="{ large_content: largeScreen }"
  143. v-show="cameraData && !cameraId"
  144. style="color: #fff"
  145. >
  146. <!-- 暂无数据 -->
  147. <!-- <img :src="require(`@/assets/imgs/maps/video_img_${cameraData.id}.png`)" alt="" /> -->
  148. </div>
  149. <div class="info_box">
  150. <span class="label">浓度</span>
  151. <span class="value">{{ ndValue || 0 }}</span>
  152. <span class="unit">ppm.m</span>
  153. </div>
  154. </div>
  155. </div>
  156. </template>
  157. <script>
  158. import Dayjs from "dayjs";
  159. import { mapGetters } from "vuex";
  160. export default {
  161. name: "VideoImageWindow",
  162. props: {
  163. cameraId: {
  164. type: String,
  165. require: true,
  166. },
  167. cameraData: {
  168. type: Object,
  169. default: () => ({}),
  170. },
  171. },
  172. computed: {
  173. ...mapGetters(["rtData"]),
  174. },
  175. watch: {
  176. rtData: {
  177. handler(newVal) {
  178. console.log(newVal);
  179. if (!!this.cameraData.tags) {
  180. if (!!this.cameraData.dataList) {
  181. this.cameraData.dataList.forEach((item) => {
  182. if (!!item.tag && !!newVal[item.tag]) {
  183. item.value = newVal[item.tag].value + " " + item.unit;
  184. }
  185. if (item.isTag && !!newVal[item.value]) {
  186. }
  187. });
  188. }
  189. }
  190. },
  191. deep: true,
  192. },
  193. },
  194. data() {
  195. return {
  196. largeScreen: false,
  197. ws: null,
  198. url: "",
  199. lastUrl: "",
  200. // 视频控制相关 start
  201. commandConfig: {
  202. //视频控制开关配置
  203. direction: [
  204. //方向
  205. { type: "top-left", name: "左上", command: 25 },
  206. { type: "top", name: "上", command: 21 },
  207. { type: "top-right", name: "右上", command: 26 },
  208. { type: "back", name: "左", command: 23 },
  209. { type: "rank", name: "中", command: 0 },
  210. { type: "right", name: "右", command: 24 },
  211. { type: "bottom-left", name: "左下", command: 27 },
  212. { type: "bottom", name: "下", command: 22 },
  213. { type: "bottom-right", name: "右下", command: 28 },
  214. ],
  215. zoom: [
  216. //放大缩小
  217. { type: "zoom-in", name: "放大", command: 11 },
  218. { type: "zoom-out", name: "缩小", command: 12 },
  219. ],
  220. },
  221. startTime: null,
  222. speed: 4,
  223. presetIndex: 1,
  224. // 视频控制 end
  225. ndValue: "0",
  226. };
  227. },
  228. beforeDestroy() {
  229. this.closeHandler();
  230. },
  231. created() {
  232. this.init(JSON.stringify({ id: this.cameraId }));
  233. },
  234. mounted() {
  235. const ndTopic = "DataCommunication/TagData/" + this.cameraData.tags.ndTag;
  236. const _this = this;
  237. this.$store.dispatch("mqtt/subscribe", {
  238. topic: [ndTopic],
  239. onMessage: (topic, message, packet) => {
  240. // console.log(topic);
  241. const content = message.toString();
  242. if (topic === ndTopic) {
  243. //console.log(new Date(), content);
  244. const data = JSON.parse(content);
  245. _this.ndValue = data.Value;
  246. }
  247. },
  248. });
  249. this.$once("hook:beforeDestroy", () => {
  250. this.$store.dispatch("mqtt/unsubscribe", [ndTopic]);
  251. });
  252. },
  253. methods: {
  254. getTagValue(tag) {
  255. return this.rtData[this.cameraData.tags[tag]]?.Value || 0;
  256. },
  257. // 放大缩小
  258. showVideoPopup(data) {
  259. this.largeScreen = data;
  260. this.$nextTick(() => {
  261. if (data) {
  262. this.baseDialogConfig.width = 937;
  263. this.baseDialogConfig.height = 598;
  264. this.baseDialogConfig.center = true;
  265. } else {
  266. this.baseDialogConfig.width = 420;
  267. this.baseDialogConfig.height = 252;
  268. this.baseDialogConfig.center = false;
  269. }
  270. });
  271. },
  272. init(str) {
  273. // this.socketList[`ws_${this.cameraId}`];
  274. this.ws = new WebSocket(
  275. VUE_APP_BASE_WS() + "/VideoOverWebSocket"
  276. // "wss://" + window.location.host + BASE_URL + "/VideoOverWebSocket"
  277. );
  278. this.ws.onmessage = (evt) => {
  279. if (typeof evt.data === "string") {
  280. console.log(JSON.parse(evt.data).Msg);
  281. } else {
  282. let _this = this;
  283. // const updateUrl = _.debounce(function () {
  284. let currUrl = URL.createObjectURL(evt.data);
  285. if (_this.lastUrl) URL.revokeObjectURL(_this.lastUrl);
  286. _this.lastUrl = currUrl;
  287. _this.url = currUrl;
  288. // }, 500);
  289. // updateUrl();
  290. }
  291. };
  292. this.handleSend(str);
  293. // console.log(window);
  294. },
  295. handleSend(str) {
  296. if (this.ws.readyState === WebSocket.OPEN) {
  297. this.ws.send(str);
  298. } else if (this.ws.readyState == WebSocket.CONNECTING) {
  299. // Wait for the open event, maybe do something with promises
  300. // depending on your use case. I believe in you developer!
  301. this.ws.addEventListener("open", () => this.handleSend(str));
  302. } else {
  303. // etc.
  304. }
  305. },
  306. updateEvent(data, state) {
  307. const param = JSON.stringify(data);
  308. if (this.ws && this.ws.readyState == 1) {
  309. this.handleSend(param);
  310. } else {
  311. this.init(param);
  312. }
  313. if (state) {
  314. setTimeout(() => {
  315. this.url = "";
  316. if (this.lastUrl) URL.revokeObjectURL(this.lastUrl);
  317. this.lastUrl = "";
  318. }, 500);
  319. }
  320. },
  321. closeHandler() {
  322. this.ws && this.ws.close();
  323. setTimeout(() => {
  324. if (this.url) URL.revokeObjectURL(this.url);
  325. this.url = "";
  326. this.lastUrl = "";
  327. this.ws &&
  328. (this.ws.onclose = (evt) => {
  329. // this.ws = null;
  330. console.log("websocket已关闭");
  331. });
  332. }, 500);
  333. },
  334. changePtzCommParam(comm, stop) {
  335. if (!comm) return;
  336. let param = {
  337. id: this.cameraId,
  338. ptzCommand: comm,
  339. ptzStop: stop,
  340. ptzSpeed: this.speed,
  341. };
  342. this.updateEvent(param);
  343. },
  344. changePtzPresetParam(comm) {
  345. if (!comm) return;
  346. let param = {
  347. id: this.cameraId,
  348. ptzPreset: comm,
  349. ptzPresetIndex: this.presetIndex,
  350. };
  351. this.updateEvent(param);
  352. },
  353. /**
  354. * state true代表回放模式
  355. */
  356. changePlayTypeParam(state) {
  357. let param = { id: this.cameraId };
  358. if (state) {
  359. if (!this.startTime) {
  360. this.$message.warning("请选择回放开始时间!");
  361. return;
  362. }
  363. param["startTime"] = Dayjs(this.startTime).format(
  364. "YYYY-MM-DD HH:mm:ss"
  365. );
  366. }
  367. this.updateEvent(param, true);
  368. },
  369. },
  370. };
  371. </script>
  372. <style lang="less" scoped>
  373. .normal_screen {
  374. background: url("~@/assets/imgs/maps/img_SPJK_bg@2x.png") center center
  375. no-repeat;
  376. background-size: 100% 100%;
  377. width: 1.984375rem /* 381/192 */;
  378. height: 1.385417rem /* 266/192 */;
  379. }
  380. .large_screen {
  381. background: url("~@/assets/imgs/dialog/pop_enlarge_TW@2x.png") center center
  382. no-repeat;
  383. background-size: 100% 100%;
  384. width: 4.880208rem /* 937/192 */;
  385. height: 3.114583rem /* 598/192 */;
  386. }
  387. .video_container {
  388. pointer-events: auto;
  389. .dialog_box {
  390. width: 100%;
  391. height: 100%;
  392. .dialog_header_box {
  393. position: relative;
  394. .dialog_header_title {
  395. width: 100%;
  396. height: 35px;
  397. line-height: 40px;
  398. // font-family: 时尚中黑简体;
  399. font-size: 16px;
  400. padding-left: 24px;
  401. color: #fff;
  402. }
  403. .dialog_header_retract {
  404. // line-height: 40px;
  405. position: absolute;
  406. top: -0.041667rem /* 8/192 */;
  407. right: 0.182292rem /* 35/192 */;
  408. cursor: pointer;
  409. img {
  410. width: 20px;
  411. height: 20px;
  412. }
  413. }
  414. .dialog_header_close {
  415. // line-height: 40px;
  416. position: absolute;
  417. top: -0.041667rem /* 8/192 */;
  418. right: 0.052083rem /* 10/192 */;
  419. img {
  420. width: 20px;
  421. height: 20px;
  422. }
  423. cursor: pointer;
  424. }
  425. }
  426. .dialog_content_box {
  427. box-sizing: border-box;
  428. width: 342px;
  429. height: 173px;
  430. margin: 0 auto;
  431. display: flex;
  432. justify-content: center;
  433. align-items: center;
  434. .content_box {
  435. width: 100%;
  436. height: 100%;
  437. display: flex;
  438. .img_box {
  439. width: 100%;
  440. height: 100%;
  441. &.comm_ptz {
  442. width: 75%;
  443. }
  444. }
  445. .control_box {
  446. width: 25%;
  447. height: 100%;
  448. border-left: 1px solid #7bacaa;
  449. }
  450. }
  451. img {
  452. width: 100%;
  453. height: 100%;
  454. object-fit: fill;
  455. // display: block;
  456. }
  457. .image_slot {
  458. width: 100%;
  459. height: 100%;
  460. // background-color: #f5f7fa;
  461. color: #f5f7fa;
  462. font-size: 24px;
  463. display: flex;
  464. flex-direction: column;
  465. justify-content: center;
  466. align-items: center;
  467. font-weight: 500;
  468. span {
  469. font-size: 16px;
  470. }
  471. }
  472. &.large_content {
  473. width: 4.630208rem /* 889/192 */;
  474. height: 2.770833rem /* 532/192 */;
  475. }
  476. }
  477. .info_box {
  478. width: 100%;
  479. height: 32px;
  480. margin-top: 6px;
  481. display: flex;
  482. justify-content: center;
  483. align-items: center;
  484. font-size: 14px;
  485. color: #fff;
  486. .value {
  487. padding: 0 8px;
  488. color: #ffc800;
  489. }
  490. }
  491. }
  492. }
  493. .video-opt {
  494. display: flex;
  495. flex-direction: column;
  496. align-items: center;
  497. padding: 10px;
  498. .comm-panel {
  499. width: 180px;
  500. display: flex;
  501. flex-wrap: wrap;
  502. .el-button {
  503. background: #51c6c1;
  504. border-color: #51c6c1;
  505. }
  506. }
  507. .zoom-panel {
  508. width: 120px;
  509. display: flex;
  510. .el-button {
  511. background: #51c6c1;
  512. border-color: #51c6c1;
  513. }
  514. }
  515. .speed-panel {
  516. margin-top: 10px;
  517. display: flex;
  518. align-items: center;
  519. }
  520. .preset-panel {
  521. margin-top: 10px;
  522. display: flex;
  523. align-items: center;
  524. flex-wrap: wrap;
  525. .el-select {
  526. width: 150px;
  527. }
  528. .el-button {
  529. margin-top: 10px;
  530. background: rgba(0, 60, 57, 0.3);
  531. border: 1px solid #65f1ea;
  532. color: #7cd6dd;
  533. }
  534. }
  535. .playback-panel {
  536. margin-top: 10px;
  537. display: flex;
  538. align-items: center;
  539. flex-wrap: wrap;
  540. .form-label {
  541. margin-bottom: 10px;
  542. }
  543. .el-button {
  544. margin-top: 15px;
  545. background: rgba(0, 60, 57, 0.3);
  546. border: 1px solid #65f1ea;
  547. color: #7cd6dd;
  548. }
  549. }
  550. .btn-box {
  551. flex-shrink: 0;
  552. width: 60px;
  553. height: 40px;
  554. display: flex;
  555. justify-content: center;
  556. align-items: center;
  557. }
  558. .form-label {
  559. color: #7cd6dd;
  560. display: inline-block;
  561. width: 50px;
  562. flex-shrink: 0;
  563. // text-align: right;
  564. }
  565. .myInput {
  566. ::v-deep .el-input__inner {
  567. // width: 110px;
  568. height: 30px;
  569. border-radius: 0;
  570. background: rgba(0, 20, 23, 0.6);
  571. border: 0.5px solid #51c6c1;
  572. color: #7cd6dd;
  573. // padding-right: 35px;
  574. }
  575. ::v-deep .el-input__inner:focus {
  576. border: 0.5px solid #51c6c1 !important;
  577. }
  578. ::v-deep .el-input.is-focus .el-input__inner {
  579. border: 0.5px solid #51c6c1 !important;
  580. }
  581. ::v-deep .el-input__suffix {
  582. right: 5px;
  583. }
  584. ::v-deep .el-input__icon {
  585. line-height: 30px;
  586. }
  587. }
  588. }
  589. </style>