index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <template>
  2. <div class="siteManage-main watchDog">
  3. <!-- 筛选start -->
  4. <div class="filter-container mb-20">
  5. <div class="left">
  6. <div>
  7. <a class="" style="margin-right: 30px">
  8. 【{{ labelCom }}】站点的所有摄像头设备
  9. </a>
  10. <el-button icon="el-icon-plus" type="success" @click="addItem()">
  11. 新增
  12. </el-button>
  13. </div>
  14. </div>
  15. <div class="right">
  16. <el-upload
  17. class="upload-demo"
  18. :action="fileUrl + '/device/deviceImport'"
  19. :on-progress="handleProgress"
  20. :on-success="handleUpAvatar"
  21. multiple
  22. :limit="1"
  23. :headers="{
  24. accessToken: [accessToken],
  25. }"
  26. :file-list="fileList"
  27. style="margin-right: 10px; display: inline-block"
  28. >
  29. <el-button size="small" type="primary">导入</el-button>
  30. </el-upload>
  31. <el-button type="primary" @click="DataReportExport()">导出</el-button>
  32. </div>
  33. </div>
  34. <!-- 筛选end -->
  35. <!-- 表格start -->
  36. <!-- <view v-if="loadingStatus" class="loadingMask">Loading...</view> -->
  37. <div></div>
  38. <el-table
  39. :data="deviceData"
  40. border
  41. stripe
  42. :header-cell-style="headClass"
  43. v-loading="loadingStatus"
  44. element-loading-text="摄像头打开中...."
  45. element-loading-background="rgba(255, 255, 255, 0.6)"
  46. >
  47. <el-table-column prop="status" align="center" label="状态" width="50">
  48. <template #default="scope">
  49. <el-avatar
  50. class="status"
  51. :style="
  52. scope.row.ALIVEVALUE == 3
  53. ? 'background-color:#04F21C'
  54. : 'background-color:red'
  55. "
  56. ></el-avatar>
  57. </template>
  58. </el-table-column>
  59. <el-table-column
  60. prop="deviceName"
  61. label="名称"
  62. align="center"
  63. ></el-table-column>
  64. <el-table-column
  65. prop="deviceCode"
  66. label="编号"
  67. align="center"
  68. width=""
  69. ></el-table-column>
  70. <el-table-column
  71. prop="floor"
  72. label="楼层"
  73. align="center"
  74. width="60"
  75. ></el-table-column>
  76. <el-table-column
  77. prop="deviceAddress"
  78. label="设备安装位置"
  79. align="center"
  80. width=""
  81. ></el-table-column>
  82. <el-table-column prop="deviceType" label="设备类型" align="center">
  83. <template #default="scope">
  84. {{ scope.row.deviceType == '2' ? '视频监控设备' : '其他' }}
  85. </template>
  86. </el-table-column>
  87. <el-table-column
  88. prop="installTime"
  89. label="安装时间"
  90. align="center"
  91. width="200"
  92. ></el-table-column>
  93. <el-table-column
  94. prop="creator"
  95. label="创建人"
  96. align="center"
  97. ></el-table-column>
  98. <el-table-column
  99. prop="sim"
  100. label="sim卡号"
  101. align="center"
  102. ></el-table-column>
  103. <el-table-column fixed="right" label="操作" width="140">
  104. <template #default="scope">
  105. <el-button
  106. type="text"
  107. size="small"
  108. @click.prevent="editRow(scope.row)"
  109. >
  110. 编辑
  111. </el-button>
  112. <el-popconfirm
  113. confirm-button-text="是"
  114. cancel-button-text="否"
  115. icon="el-icon-info"
  116. icon-color="red"
  117. title="确定删除?"
  118. @confirm="handleDelete(scope.row)"
  119. @cancel="cancelEvent"
  120. >
  121. <template #reference>
  122. <el-button type="text" size="small" class="delete-text">
  123. 删除
  124. </el-button>
  125. </template>
  126. </el-popconfirm>
  127. </template>
  128. </el-table-column>
  129. <el-table-column fixed="right" label="视频画面" width="100">
  130. <template #default="scope">
  131. <a v-if="scope.row.ALIVEVALUE == 3" @click="open_video(scope.row)">
  132. 查看
  133. </a>
  134. <span v-else style="color: #aaa">--</span>
  135. </template>
  136. </el-table-column>
  137. </el-table>
  138. <!-- 表格end -->
  139. <!-- 分页start -->
  140. <div class="paginationBlock">
  141. <el-pagination
  142. v-model:currentPage="currentPage"
  143. :page-sizes="[15, 20, 25, 30]"
  144. :page-size="pageSize"
  145. layout="total, sizes, prev, pager, next, jumper"
  146. :total="total"
  147. @size-change="handleSizeChange"
  148. @current-change="handleCurrentChange"
  149. background
  150. ></el-pagination>
  151. </div>
  152. <!-- 分页end -->
  153. <!--弹框组件开始-----------------------start-->
  154. <dialog-component
  155. :dialogTitle="dialogTitle"
  156. :itemInfo="tableItem"
  157. @closeDialog="closeDialog"
  158. :flag="showDialog"
  159. ></dialog-component>
  160. <!--弹框组件开始-----------------------end-->
  161. <!--视频弹框组件开始-----------------------start-->
  162. <check-video
  163. :dialogTitle="dialogTitle"
  164. :itemInfo="tableItem"
  165. @closeDialog="closeDialog2"
  166. :flag="showDialog2"
  167. :deviceCode="deviceCode"
  168. ></check-video>
  169. <!--视频弹框组件结束-----------------------end-->
  170. <input type="hidden" v-model="openId" style="opacity: 0" />
  171. </div>
  172. </template>
  173. <script>
  174. import { useStore } from 'vuex'
  175. import {
  176. defineComponent,
  177. ref,
  178. reactive,
  179. onMounted,
  180. watch,
  181. onUnmounted,
  182. } from 'vue'
  183. import DialogComponent from './dialogComponent'
  184. import checkVideo from './checkVideo'
  185. import * as api from '@/api/siteManage/camera.js'
  186. import { ElMessage } from 'element-plus'
  187. import axios from 'axios'
  188. export default defineComponent({
  189. components: { DialogComponent, checkVideo },
  190. props: {
  191. siteId: Number,
  192. activeName: String,
  193. },
  194. setup(props) {
  195. const store = useStore()
  196. store
  197. const total = ref(0)
  198. const pageSize = ref(15)
  199. const currentPage = ref(1)
  200. const goSiteListParam = ref('')
  201. const platformAreaName = ref('')
  202. const pageShow = ref(false)
  203. const showDialog = ref(false)
  204. const showDialog2 = ref(false)
  205. const deviceData = ref([])
  206. const tableItem = reactive([])
  207. const dialogTitle = ref('')
  208. const fileUrl = ref(window.PLATFROM_CONFIG.baseUrl)
  209. const fileList = ref([])
  210. const accessToken = ref(store.state.user.accessToken)
  211. const labelCom = ref(store.state.siteManageLabelCom)
  212. const onLineVideoList = ref([])
  213. const openId = ref('')
  214. const reCount = ref(0)
  215. const count = ref(0)
  216. const loadingStatus = ref(false)
  217. const timer = ref('')
  218. const deviceCode=ref('')
  219. // 表头样式设置
  220. const headClass = () => {
  221. return 'background:#FAFAFA;'
  222. }
  223. //分页操作
  224. const handleSizeChange = (val) => {
  225. pageSize.value = val
  226. videoMonitoringDeviceList()
  227. }
  228. const handleCurrentChange = (val) => {
  229. currentPage.value = val
  230. videoMonitoringDeviceList()
  231. }
  232. //监控设备列表
  233. function videoMonitoringDeviceList() {
  234. api
  235. .videoMonitoringDeviceList({
  236. siteId: props.siteId,
  237. size: pageSize.value,
  238. current: currentPage.value,
  239. // deviceType:2
  240. })
  241. .then((requset) => {
  242. if (requset.status === 'SUCCESS') {
  243. deviceData.value = requset.data.records
  244. total.value = requset.data.total
  245. console.log('response 接口请求数据')
  246. console.log(deviceData.value)
  247. } else {
  248. ElMessage.error(requset.msg)
  249. }
  250. })
  251. }
  252. // 添加操作
  253. const addItem = () => {
  254. tableItem.value = {
  255. deviceName: '',
  256. deviceCode: '',
  257. floor: 1,
  258. siteId: '',
  259. deviceAddress: '',
  260. deviceType: '',
  261. sim: '',
  262. }
  263. dialogTitle.value = '新增'
  264. showDialog.value = true
  265. }
  266. // 编辑操作
  267. const editRow = (row) => {
  268. console.log
  269. tableItem.value = {
  270. id: row.id,
  271. deviceCode: row.deviceCode,
  272. deviceName: row.deviceName,
  273. floor: row.floor,
  274. siteId: row.siteId,
  275. deviceAddress: row.deviceAddress,
  276. deviceType: Number(row.deviceType),
  277. sim: row.sim,
  278. }
  279. dialogTitle.value = '编辑'
  280. showDialog.value = true
  281. }
  282. // 查看视频
  283. // const open_video = (params) => {
  284. // params
  285. // tableItem.value = {
  286. // id: '',
  287. // stationName: '',
  288. // watchName: '',
  289. // watchCode: '',
  290. // siteList: [],
  291. // done: '',
  292. // guaZai: '',
  293. // checked: true,
  294. // resource: '',
  295. // }
  296. // dialogTitle.value = '查看视频'
  297. // showDialog2.value = true
  298. // }
  299. // 关闭操作
  300. const closeDialog = () => {
  301. showDialog.value = false
  302. videoMonitoringDeviceList()
  303. chk_video()
  304. }
  305. const closeDialog2 = () => {
  306. showDialog2.value = false
  307. count.value=0
  308. }
  309. //删除 是否删除 ---- 是
  310. const handleDelete = (row) => {
  311. api.correspondDeviceDel({ id: row.id }).then((requset) => {
  312. if (requset.status === 'SUCCESS') {
  313. ElMessage.success({
  314. message: '删除成功',
  315. type: 'success',
  316. })
  317. videoMonitoringDeviceList()
  318. } else {
  319. ElMessage.error(requset.msg)
  320. }
  321. })
  322. }
  323. //是否删除 ---- 否
  324. const cancelEvent = () => {
  325. console.log('cancel!')
  326. }
  327. //导入
  328. const handleProgress = (file, fileList) => {
  329. file
  330. if (
  331. !(
  332. fileList.raw.type ===
  333. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
  334. fileList.raw.type === 'application/vnd.ms-excel'
  335. )
  336. ) {
  337. ElMessage({
  338. message: '上传文件只能是 xls 和 xlsx 格式!',
  339. type: 'error',
  340. })
  341. return false
  342. } else {
  343. return true
  344. }
  345. }
  346. const handleUpAvatar = (res, file) => {
  347. console.log(res, file)
  348. fileList.value = []
  349. ElMessage.success({
  350. message: '导入成功',
  351. type: 'success',
  352. })
  353. videoMonitoringDeviceList()
  354. }
  355. //导出
  356. const DataReportExport = () => {
  357. api
  358. .deviceExport({
  359. siteId: props.siteId,
  360. })
  361. .then((requset) => {
  362. if (requset.status === 'SUCCESS') {
  363. window.location.href = window.PLATFROM_CONFIG.fileUrl + requset.data
  364. ElMessage.success({
  365. message: '导出成功',
  366. type: 'success',
  367. })
  368. } else {
  369. ElMessage.error(requset.msg)
  370. }
  371. })
  372. }
  373. //请求视频cgi数据
  374. const chk_video = () => {
  375. axios
  376. .post(
  377. 'https://fire.usky.cn:8443/YtIoT/cgi-bin/demo2.cgi',
  378. 'queryJson:' +
  379. JSON.stringify({
  380. CMD: 1,
  381. }),
  382. {
  383. headers: {
  384. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  385. },
  386. }
  387. )
  388. .then((response) => {
  389. console.log('response cgi')
  390. console.log(response.data.RESULT.LIST)
  391. console.log(openId.value)
  392. onLineVideoList.value = response.data.RESULT.LIST
  393. if (openId.value.length > 0) {
  394. // start
  395. console.log('doododododododo')
  396. for (var n = 0; n < onLineVideoList.value.length; n++) {
  397. if (openId.value == onLineVideoList.value[n].DEVICE) {
  398. console.log('再次打开摄像头')
  399. console.log(openId.value)
  400. console.log(onLineVideoList.value[n].DEVICE)
  401. console.log(onLineVideoList.value[n].ONAIR)
  402. reCount.value++
  403. console.log(reCount.value)
  404. if (onLineVideoList.value[n].ONAIR) {
  405. if (++count.value > 2) {
  406. // var mask = document.getElementById('videomask');
  407. // if (mask != undefined) {
  408. // removeDIV('videomask');
  409. // }
  410. loadingStatus.value = false
  411. alert('可以打开视频详情并传参')
  412. // uni.navigateTo({
  413. // url: '/pages/videoDetail/videoDetail?deviceType=2&companyCode=' +
  414. // this.companyCode + '&deviceCode=' +
  415. // onLineVideoList.value[n].DEVICE +
  416. // '',
  417. // });
  418. tableItem.value = {
  419. id: '',
  420. stationName: '',
  421. watchName: '',
  422. watchCode: '',
  423. siteList: [],
  424. done: '',
  425. guaZai: '',
  426. checked: true,
  427. resource: '',
  428. }
  429. dialogTitle.value = '查看视频'
  430. showDialog2.value = true;
  431. } else {
  432. store.state.siteCameraTimer = setTimeout(chk_video, 5000)
  433. }
  434. } else {
  435. if (reCount.value > 20) {
  436. // var mask = document.getElementById('videomask');
  437. // if (mask != undefined) {
  438. // removeDIV('videomask');
  439. // }
  440. loadingStatus.value = false
  441. alert('远程摄像头链接超时,请稍后再试')
  442. // ElMessage({
  443. // duration: 5000,
  444. // showClose: true,
  445. // message: '远程摄像头链接超时,请稍后再试.',
  446. // type: 'warning',
  447. // })
  448. // $("#myPopup").popup("open");
  449. break
  450. }
  451. store.state.siteCameraTimer = setTimeout(chk_video, 5000)
  452. }
  453. }
  454. }
  455. // end
  456. } else {
  457. for (var i = 0; i < onLineVideoList.value.length; i++) {
  458. for (var j = 0; j < deviceData.value.length; j++) {
  459. if (
  460. onLineVideoList.value[i].DEVICE ==
  461. deviceData.value[j].deviceCode
  462. ) {
  463. deviceData.value[j].ALIVEVALUE =
  464. onLineVideoList.value[i].ALIVEVALUE
  465. }
  466. }
  467. }
  468. // console.log('处理后的,deviceData.value')
  469. // console.log(deviceData.value)
  470. }
  471. })
  472. .catch((error) => {
  473. console.log(error)
  474. })
  475. }
  476. // 查看视频
  477. const open_video = (item) => {
  478. deviceCode.value=item.deviceCode
  479. // alert(deviceCode.value)
  480. // console.log(item)
  481. if (openId.value != item.deviceCode) {
  482. openId.value = item.deviceCode
  483. }
  484. // console.log(onLineVideoList.value)
  485. for (var n = 0; n < onLineVideoList.value.length; n++) {
  486. if (onLineVideoList.value[n].DEVICE == openId.value) {
  487. console.log('第一次打开时设备及其状态')
  488. console.log(onLineVideoList.value[n].DEVICE)
  489. console.log(openId.value)
  490. console.log(onLineVideoList.value[n].ONAIR)
  491. if (onLineVideoList.value[n].ONAIR) {
  492. alert('打开详情页并传参')
  493. tableItem.value = {
  494. id: '',
  495. stationName: '',
  496. watchName: '',
  497. watchCode: '',
  498. siteList: [],
  499. done: '',
  500. guaZai: '',
  501. checked: true,
  502. resource: '',
  503. }
  504. dialogTitle.value = '查看视频'
  505. showDialog2.value = true
  506. return
  507. }
  508. }
  509. }
  510. count.value = 0
  511. reCount.value = 0
  512. loadingStatus.value = true
  513. axios
  514. .post(
  515. 'https://fire.usky.cn:8443/YtIoT/cgi-bin/demo2.cgi',
  516. 'queryJson:' +
  517. JSON.stringify({
  518. CMD: 3,
  519. BODY: {
  520. DEVICE: item.DEVICE,
  521. ACTION: 1,
  522. IDX: 7,
  523. },
  524. }),
  525. {
  526. headers: {
  527. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  528. },
  529. }
  530. )
  531. .then((response) => {
  532. response
  533. store.state.siteCameraTimer = window.setTimeout(function () {
  534. chk_video()
  535. }, 5000)
  536. })
  537. // end
  538. }
  539. // window.setInterval(() => {
  540. // setTimeout(() => {
  541. // chk_video()
  542. // }, 0)
  543. // }, 100000)
  544. //监听变化
  545. watch(
  546. () => props.siteId,
  547. (newVal) => {
  548. console.log('newVal')
  549. console.log(newVal)
  550. labelCom.value = store.state.siteManageLabelCom
  551. if (props.activeName == 'five') {
  552. // window.clearTimeOut() //关闭定时器
  553. reCount.value = 0
  554. openId.value = ''
  555. loadingStatus.value = false
  556. videoMonitoringDeviceList()
  557. chk_video()
  558. }
  559. }
  560. )
  561. watch(
  562. () => props.activeName,
  563. (newVal) => {
  564. if (newVal == 'five') {
  565. // clearTimeOut(timer.value)
  566. // window.clearTimeOut() //关闭定时器// alert('关闭定时器?')
  567. reCount.value = 0
  568. openId.value = ''
  569. loadingStatus.value = false
  570. videoMonitoringDeviceList()
  571. chk_video()
  572. }
  573. }
  574. )
  575. onMounted(() => {})
  576. onUnmounted(() => {
  577. // alert('摧毁')
  578. // clearTimeOut(timer.value)
  579. })
  580. return {
  581. deviceData,
  582. showDialog,
  583. showDialog2,
  584. platformAreaName,
  585. pageShow,
  586. dialogTitle,
  587. props,
  588. tableItem,
  589. goSiteListParam,
  590. total,
  591. pageSize,
  592. currentPage,
  593. chk_video,
  594. videoMonitoringDeviceList,
  595. headClass,
  596. addItem,
  597. editRow,
  598. closeDialog,
  599. closeDialog2,
  600. handleDelete,
  601. cancelEvent,
  602. handleSizeChange,
  603. handleCurrentChange,
  604. DataReportExport,
  605. fileList,
  606. fileUrl,
  607. accessToken,
  608. handleProgress,
  609. handleUpAvatar,
  610. labelCom,
  611. openId,
  612. onLineVideoList,
  613. reCount,
  614. count,
  615. loadingStatus,
  616. open_video,
  617. timer,
  618. deviceCode
  619. }
  620. },
  621. })
  622. </script>
  623. <style lang="scss" scoped>
  624. </style>