hkwsCamera.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <HikComp v-if="show" ref="hkws" class="hkws-camera" :playConfig.sync="playConfig"
  3. :nameId="jkInfo.nameId" :cameraIndexCode.sync="jkInfo.cameraIndexCode"/>
  4. </template>
  5. <script>
  6. import apiSecurityCamera from "@/api/security/apiSecurityCamera";
  7. import HikComp from "@/components/hkws/hikComp.vue";
  8. export default {
  9. components: {HikComp},
  10. data() {
  11. return {
  12. show: false,
  13. jkInfo: {
  14. nameId: "playWnd1", // nameId 具有唯一性,否则无效,如果有多个,一定不能重复
  15. cameraIndexCode: "", // 监控点编号
  16. }
  17. }
  18. },
  19. props: {
  20. cameraId: String,
  21. toolButtonIds: String,
  22. showToolbar: Boolean
  23. },
  24. watch: {
  25. cameraId: function (val) {
  26. this.jkInfo.cameraIndexCode = val;
  27. this.$refs.hkws.cameraConfig.cameraIndexCode = val;
  28. this.$refs.hkws.startPreview();
  29. }
  30. },
  31. computed: {
  32. playConfig: function () {
  33. return {
  34. appkey: "test",
  35. secret: "test",
  36. ip: "127.0.0.1",
  37. playMode: 0,
  38. port: 443,
  39. snapDir: "/SnapDir",
  40. videoDir: "/VideoDir",
  41. layout: "1x1",
  42. enableHTTPS: 1,
  43. encryptedFields: 'secret',
  44. showToolbar: this.showToolbar ? 1 : 0,
  45. showSmart: 0,
  46. buttonIDs: "",
  47. toolBarButtonIDs: "4097,4098",
  48. }
  49. }
  50. },
  51. mounted() {
  52. this.show = true;
  53. this.$nextTick(() => {
  54. if (this.cameraId && this.cameraId.length > 0) {
  55. this.jkInfo.cameraIndexCode = this.cameraId
  56. }
  57. if (this.toolButtonIds && this.toolButtonIds.length > 0) {
  58. this.playConfig.toolBarButtonIDs = this.toolButtonIds
  59. }
  60. this.getApiInfo()
  61. })
  62. },
  63. methods: {
  64. getApiInfo() {
  65. let app = this;
  66. apiSecurityCamera.getHkApi().then(res => {
  67. let split = res.host.split(":");
  68. this.playConfig.ip = split[0];
  69. this.playConfig.port = Number(split[1]);
  70. this.playConfig.appkey = res.appKey
  71. this.playConfig.secret = res.appSecret
  72. this.show = false;
  73. setTimeout(function () {
  74. app.show = true;
  75. }, 100)
  76. }).catch(err => {
  77. this.$message.error('摄像头平台初始化失败')
  78. })
  79. },
  80. },
  81. beforeDestroy() {
  82. if (this.$refs.hkws && this.$refs.hkws.oWebControl) {
  83. this.$refs.hkws.oWebControl.JS_StopService('window')
  84. .then(() => {
  85. })
  86. .catch((err) => console.log(err))
  87. this.$refs.hkws.oWebControl.JS_DestroyWnd()
  88. .then(() => {
  89. })
  90. .catch((err) => console.log(err))
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. .hkws-camera {
  97. width: 100%;
  98. height: 100%;
  99. }
  100. </style>