index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="l-flex--col">
  3. <el-tabs
  4. :value="active"
  5. class="c-tabs has-bottom-padding"
  6. @tab-click="onTabClick"
  7. >
  8. <template v-if="editable">
  9. <el-tab-pane name="TRAFFIC_CAMERA">
  10. <template #label>
  11. <div class="o-tab">
  12. <i
  13. class="o-tab__icon el-icon-circle-plus-outline"
  14. @click.stop="onAdd('TRAFFIC_CAMERA')"
  15. />
  16. 人流量监测
  17. </div>
  18. </template>
  19. </el-tab-pane>
  20. <el-tab-pane name="LED_CAMERA">
  21. <template #label>
  22. <div class="o-tab">
  23. <i
  24. class="o-tab__icon el-icon-circle-plus-outline"
  25. @click.stop="onAdd('LED_CAMERA')"
  26. />
  27. LED屏监测
  28. </div>
  29. </template>
  30. </el-tab-pane>
  31. </template>
  32. <template v-else>
  33. <el-tab-pane
  34. label="人流量监测"
  35. name="TRAFFIC_CAMERA"
  36. />
  37. <el-tab-pane
  38. label="LED屏监测"
  39. name="LED_CAMERA"
  40. />
  41. </template>
  42. </el-tabs>
  43. <grid-table
  44. ref="table"
  45. :schema="schema"
  46. size="large"
  47. >
  48. <grid-table-item v-slot="item">
  49. <camera-player
  50. v-if="isActivated"
  51. :key="item.identifier"
  52. :camera="item"
  53. :autoplay="!editable"
  54. controls
  55. @fullscreen="onFullScreen(item)"
  56. >
  57. <template v-if="editable">
  58. <i
  59. class="c-sibling-item el-icon-delete has-active u-pointer"
  60. @click.stop="onDel(item)"
  61. />
  62. </template>
  63. </camera-player>
  64. </grid-table-item>
  65. </grid-table>
  66. <el-dialog
  67. class="c-dialog--full"
  68. :visible="detailing"
  69. :close-on-click-modal="false"
  70. :close-on-press-escape="false"
  71. fullscreen
  72. >
  73. <camera-detail
  74. v-if="detailing"
  75. :camera="targetCamera"
  76. autoplay
  77. controls
  78. @close="onClose"
  79. />
  80. </el-dialog>
  81. <table-dialog
  82. ref="cameraDialog"
  83. :title="title"
  84. :schema="cameraSchema"
  85. @choosen="onCameraChoosen"
  86. />
  87. </div>
  88. </template>
  89. <script>
  90. import {
  91. getCameras,
  92. getThirdPartyDevices,
  93. bind,
  94. unbind
  95. } from '@/api/external'
  96. import {
  97. Camera,
  98. ThirdPartyDevice
  99. } from '@/constant'
  100. export default {
  101. name: 'DeviceCamera',
  102. props: {
  103. device: {
  104. type: Object,
  105. required: true
  106. },
  107. editable: {
  108. type: [Boolean, String],
  109. default: false
  110. }
  111. },
  112. data () {
  113. return {
  114. active: 'TRAFFIC_CAMERA',
  115. deviceType: ThirdPartyDevice.TRAFFIC_CAMERA,
  116. schema: {
  117. pageSize: 999,
  118. list: this.getCameras
  119. },
  120. detailing: false,
  121. targetCamera: null
  122. }
  123. },
  124. computed: {
  125. isTraffic () {
  126. return this.active === 'TRAFFIC_CAMERA'
  127. },
  128. cameraType () {
  129. return this.isTraffic ? Camera.TRAFFIC : Camera.LED
  130. },
  131. isActivated () {
  132. return !this.detailing
  133. },
  134. title () {
  135. return this.deviceType === ThirdPartyDevice.TRAFFIC_CAMERA ? '绑定人流量监测摄像头' : '绑定LED屏监测摄像头'
  136. },
  137. cameraSchema () {
  138. return {
  139. condition: { deviceType: this.deviceType },
  140. list: getThirdPartyDevices,
  141. cols: [
  142. { prop: 'name', label: '名称' },
  143. { prop: 'remark', label: '备注' }
  144. ]
  145. }
  146. }
  147. },
  148. methods: {
  149. onTabClick ({ name: active }) {
  150. if (this.active !== active) {
  151. this.active = active
  152. this.$refs.table.pageTo(1)
  153. }
  154. },
  155. getCameras () {
  156. return getCameras({
  157. deviceId: this.device.id,
  158. cameraType: this.cameraType
  159. }).then(({ data }) => {
  160. data = data.map(({ id, thirdPartyDevice }) => {
  161. return {
  162. ...thirdPartyDevice,
  163. id
  164. }
  165. })
  166. return { data }
  167. })
  168. },
  169. onFullScreen (camera) {
  170. if (camera.onlineStatus) {
  171. this.targetCamera = camera
  172. this.detailing = true
  173. }
  174. },
  175. onClose () {
  176. this.detailing = false
  177. },
  178. onAdd (deviceType) {
  179. this.deviceType = ThirdPartyDevice[deviceType]
  180. this.$refs.cameraDialog.show()
  181. },
  182. onCameraChoosen ({ value, done }) {
  183. this.$confirm(
  184. `${this.title} ${value.name} ?`,
  185. { type: 'warning' }
  186. ).then(() => {
  187. bind(this.device.id, this.deviceType, value.id).then(() => {
  188. done()
  189. if (this.deviceType === ThirdPartyDevice[this.active]) {
  190. this.$refs.table.pageTo(1)
  191. } else {
  192. this.onTabClick({ name: this.isTraffic ? 'LED_CAMERA' : 'TRAFFIC_CAMERA' })
  193. }
  194. })
  195. })
  196. },
  197. onDel (item) {
  198. this.$confirm(
  199. `解绑摄像头 ${item.name} ?`,
  200. { type: 'warning' }
  201. ).then(() => {
  202. unbind(item.id).then(() => {
  203. this.$refs.table.decrease(1)
  204. })
  205. })
  206. }
  207. }
  208. }
  209. </script>