index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. } from 'vue'
  182. import DialogComponent from './dialogComponent'
  183. import checkVideo from './checkVideo'
  184. import * as api from '@/api/siteManage/camera.js'
  185. import { ElMessage } from 'element-plus'
  186. import axios from 'axios'
  187. export default defineComponent({
  188. components: { DialogComponent, checkVideo },
  189. props: {
  190. siteId: Number,
  191. activeName: String,
  192. },
  193. setup(props) {
  194. const store = useStore()
  195. store
  196. const total = ref(0)
  197. const pageSize = ref(15)
  198. const currentPage = ref(1)
  199. const goSiteListParam = ref('')
  200. const platformAreaName = ref('')
  201. const pageShow = ref(false)
  202. const showDialog = ref(false)
  203. const showDialog2 = ref(false)
  204. const deviceData = ref([])
  205. const tableItem = reactive([])
  206. const dialogTitle = ref('')
  207. const fileUrl = ref(window.PLATFROM_CONFIG.baseUrl)
  208. const fileList = ref([])
  209. const accessToken = ref(store.state.user.accessToken)
  210. const labelCom = ref(store.state.siteManageLabelCom)
  211. const onLineVideoList = ref([])
  212. const openId = ref('')
  213. const reCount = ref(0)
  214. const count = ref(0)
  215. const loadingStatus = ref(false)
  216. const timer = ref('')
  217. const deviceCode=ref('')
  218. // 表头样式设置
  219. const headClass = () => {
  220. return 'background:#FAFAFA;'
  221. }
  222. //分页操作
  223. const handleSizeChange = (val) => {
  224. pageSize.value = val
  225. videoMonitoringDeviceList()
  226. }
  227. const handleCurrentChange = (val) => {
  228. currentPage.value = val
  229. videoMonitoringDeviceList()
  230. }
  231. //监控设备列表
  232. function videoMonitoringDeviceList() {
  233. api
  234. .videoMonitoringDeviceList({
  235. siteId: props.siteId,
  236. size: pageSize.value,
  237. current: currentPage.value,
  238. // deviceType:2
  239. })
  240. .then((requset) => {
  241. if (requset.status === 'SUCCESS') {
  242. deviceData.value = requset.data.records
  243. total.value = requset.data.total
  244. console.log('response 接口请求数据')
  245. console.log(deviceData.value)
  246. } else {
  247. ElMessage.error(requset.msg)
  248. }
  249. })
  250. }
  251. // 添加操作
  252. const addItem = () => {
  253. tableItem.value = {
  254. deviceName: '',
  255. deviceCode: '',
  256. floor: 1,
  257. siteId: '',
  258. deviceAddress: '',
  259. deviceType: '',
  260. sim: '',
  261. }
  262. dialogTitle.value = '新增'
  263. showDialog.value = true
  264. }
  265. // 编辑操作
  266. const editRow = (row) => {
  267. console.log
  268. tableItem.value = {
  269. id: row.id,
  270. deviceCode: row.deviceCode,
  271. deviceName: row.deviceName,
  272. floor: row.floor,
  273. siteId: row.siteId,
  274. deviceAddress: row.deviceAddress,
  275. deviceType: Number(row.deviceType),
  276. sim: row.sim,
  277. }
  278. dialogTitle.value = '编辑'
  279. showDialog.value = true
  280. }
  281. // 关闭操作
  282. const closeDialog = () => {
  283. showDialog.value = false
  284. videoMonitoringDeviceList()
  285. chk_video()
  286. }
  287. const closeDialog2 = () => {
  288. showDialog2.value = false
  289. count.value=0
  290. }
  291. //删除 是否删除 ---- 是
  292. const handleDelete = (row) => {
  293. api.correspondDeviceDel({ id: row.id }).then((requset) => {
  294. if (requset.status === 'SUCCESS') {
  295. ElMessage.success({
  296. message: '删除成功',
  297. type: 'success',
  298. })
  299. videoMonitoringDeviceList()
  300. } else {
  301. ElMessage.error(requset.msg)
  302. }
  303. })
  304. }
  305. //是否删除 ---- 否
  306. const cancelEvent = () => {
  307. console.log('cancel!')
  308. }
  309. //导入
  310. const handleProgress = (file, fileList) => {
  311. file
  312. if (
  313. !(
  314. fileList.raw.type ===
  315. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
  316. fileList.raw.type === 'application/vnd.ms-excel'
  317. )
  318. ) {
  319. ElMessage({
  320. message: '上传文件只能是 xls 和 xlsx 格式!',
  321. type: 'error',
  322. })
  323. return false
  324. } else {
  325. return true
  326. }
  327. }
  328. const handleUpAvatar = (res, file) => {
  329. console.log(res, file)
  330. fileList.value = []
  331. ElMessage.success({
  332. message: '导入成功',
  333. type: 'success',
  334. })
  335. videoMonitoringDeviceList()
  336. }
  337. //导出
  338. const DataReportExport = () => {
  339. api
  340. .deviceExport({
  341. siteId: props.siteId,
  342. })
  343. .then((requset) => {
  344. if (requset.status === 'SUCCESS') {
  345. window.location.href = window.PLATFROM_CONFIG.fileUrl + requset.data
  346. ElMessage.success({
  347. message: '导出成功',
  348. type: 'success',
  349. })
  350. } else {
  351. ElMessage.error(requset.msg)
  352. }
  353. })
  354. }
  355. //请求视频cgi数据
  356. const chk_video = () => {
  357. axios
  358. .post(
  359. 'https://fire.usky.cn:8443/YtIoT/cgi-bin/demo2.cgi',
  360. 'queryJson:' +
  361. JSON.stringify({
  362. CMD: 1,
  363. }),
  364. {
  365. headers: {
  366. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  367. },
  368. }
  369. )
  370. .then((response) => {
  371. console.log('response cgi')
  372. console.log(response.data.RESULT.LIST)
  373. console.log(openId.value)
  374. onLineVideoList.value = response.data.RESULT.LIST
  375. if (openId.value.length > 0) {
  376. // start
  377. console.log('doododododododo')
  378. for (var n = 0; n < onLineVideoList.value.length; n++) {
  379. if (openId.value == onLineVideoList.value[n].DEVICE) {
  380. console.log('再次打开摄像头')
  381. console.log(openId.value)
  382. console.log(onLineVideoList.value[n].DEVICE)
  383. console.log(onLineVideoList.value[n].ONAIR)
  384. reCount.value++
  385. console.log(reCount.value)
  386. if (onLineVideoList.value[n].ONAIR) {
  387. if (++count.value > 2) {
  388. loadingStatus.value = false
  389. tableItem.value = {
  390. id: '',
  391. stationName: '',
  392. watchName: '',
  393. watchCode: '',
  394. siteList: [],
  395. done: '',
  396. guaZai: '',
  397. checked: true,
  398. resource: '',
  399. }
  400. dialogTitle.value = '查看视频'
  401. showDialog2.value = true;
  402. } else {
  403. store.state.siteCameraTimer = setTimeout(chk_video, 5000)
  404. }
  405. } else {
  406. if (reCount.value > 7) {
  407. loadingStatus.value = false
  408. alert('远程摄像头链接超时,请稍后再试')
  409. break
  410. }
  411. store.state.siteCameraTimer = setTimeout(chk_video, 5000)
  412. }
  413. }
  414. }
  415. // end
  416. } else {
  417. for (var i = 0; i < onLineVideoList.value.length; i++) {
  418. for (var j = 0; j < deviceData.value.length; j++) {
  419. if (
  420. onLineVideoList.value[i].DEVICE ==
  421. deviceData.value[j].deviceCode
  422. ) {
  423. deviceData.value[j].ALIVEVALUE =
  424. onLineVideoList.value[i].ALIVEVALUE
  425. }
  426. }
  427. }
  428. // console.log('处理后的,deviceData.value')
  429. // console.log(deviceData.value)
  430. }
  431. })
  432. .catch((error) => {
  433. console.log(error)
  434. })
  435. }
  436. // 查看视频
  437. const open_video = (item) => {
  438. deviceCode.value=item.deviceCode
  439. if (openId.value != item.deviceCode) {
  440. openId.value = item.deviceCode
  441. }
  442. for (var n = 0; n < onLineVideoList.value.length; n++) {
  443. if (onLineVideoList.value[n].DEVICE == openId.value) {
  444. console.log('第一次打开时设备及其状态')
  445. console.log(onLineVideoList.value[n].DEVICE)
  446. console.log(openId.value)
  447. console.log(onLineVideoList.value[n].ONAIR)
  448. if (onLineVideoList.value[n].ONAIR) {
  449. tableItem.value = {
  450. id: '',
  451. stationName: '',
  452. watchName: '',
  453. watchCode: '',
  454. siteList: [],
  455. done: '',
  456. guaZai: '',
  457. checked: true,
  458. resource: '',
  459. }
  460. dialogTitle.value = '查看视频'
  461. showDialog2.value = true
  462. return
  463. }
  464. }
  465. }
  466. count.value = 0
  467. reCount.value = 0
  468. loadingStatus.value = true
  469. axios
  470. .post(
  471. 'https://fire.usky.cn:8443/YtIoT/cgi-bin/demo2.cgi',
  472. 'queryJson:' +
  473. JSON.stringify({
  474. CMD: 3,
  475. BODY: {
  476. DEVICE: item.deviceCode,
  477. ACTION: 1,
  478. IDX: 7,
  479. },
  480. }),
  481. {
  482. headers: {
  483. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  484. },
  485. }
  486. )
  487. .then((response) => {
  488. response
  489. store.state.siteCameraTimer = window.setTimeout(function () {
  490. chk_video()
  491. }, 5000)
  492. })
  493. // end
  494. }
  495. //监听变化
  496. watch(
  497. () => props.siteId,
  498. (newVal) => {
  499. console.log('newVal')
  500. console.log(newVal)
  501. labelCom.value = store.state.siteManageLabelCom
  502. if (props.activeName == 'five') {
  503. // window.clearTimeOut() //关闭定时器
  504. reCount.value = 0
  505. openId.value = ''
  506. loadingStatus.value = false
  507. videoMonitoringDeviceList()
  508. chk_video()
  509. }
  510. }
  511. )
  512. watch(
  513. () => props.activeName,
  514. (newVal) => {
  515. if (newVal == 'five') {
  516. // clearTimeOut(timer.value)
  517. // window.clearTimeOut() //关闭定时器// alert('关闭定时器?')
  518. reCount.value = 0
  519. openId.value = ''
  520. loadingStatus.value = false
  521. videoMonitoringDeviceList()
  522. chk_video()
  523. }
  524. }
  525. )
  526. onMounted(() => {})
  527. return {
  528. deviceData,
  529. showDialog,
  530. showDialog2,
  531. platformAreaName,
  532. pageShow,
  533. dialogTitle,
  534. props,
  535. tableItem,
  536. goSiteListParam,
  537. total,
  538. pageSize,
  539. currentPage,
  540. chk_video,
  541. videoMonitoringDeviceList,
  542. headClass,
  543. addItem,
  544. editRow,
  545. closeDialog,
  546. closeDialog2,
  547. handleDelete,
  548. cancelEvent,
  549. handleSizeChange,
  550. handleCurrentChange,
  551. DataReportExport,
  552. fileList,
  553. fileUrl,
  554. accessToken,
  555. handleProgress,
  556. handleUpAvatar,
  557. labelCom,
  558. openId,
  559. onLineVideoList,
  560. reCount,
  561. count,
  562. loadingStatus,
  563. open_video,
  564. timer,
  565. deviceCode
  566. }
  567. },
  568. })
  569. </script>
  570. <style lang="scss" scoped>
  571. </style>