index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="siteManage-main watchDog">
  3. <!-- 筛选start -->
  4. <div class="filter-container mb-20">
  5. <div class="left">
  6. <span class="" style="margin-right: 30px"> 【{{ labelCom }}】站点的所有摄像头设备 </span>
  7. <el-button icon="Plus" type="success" @click="addItem()" :disabled="store.state.authorities.indexOf('新增') == -1">
  8. 新增
  9. </el-button>
  10. <a href="./static/伍继摄像头导入模板.xlsx" download class="downloadMb">
  11. 模板下载
  12. </a>
  13. </div>
  14. <el-upload class="upload-demo" :action="fileUrl + '/device/deviceImport'" :on-progress="handleProgress"
  15. :on-success="handleUpAvatar" :on-error="handleError" multiple :limit="1" :headers="{
  16. accessToken: [accessToken],
  17. }" :file-list="fileList" style="margin:0 10px 0 auto; display: inline-block"
  18. :disabled="store.state.authorities.indexOf('导入') == -1">
  19. <el-button type="primary" :disabled="store.state.authorities.indexOf('导入') == -1"> 导入 </el-button>
  20. </el-upload>
  21. <el-button type="primary" @click="DataReportExport()" :disabled="store.state.authorities.indexOf('导出') == -1"> 导出
  22. </el-button>
  23. </div>
  24. <!-- 筛选end -->
  25. <!-- 表格start -->
  26. <el-table :data="deviceData" v-loading="loadingStatus" element-loading-text="摄像头打开中...."
  27. element-loading-background="rgba(255, 255, 255, 0.6)"> border stripe
  28. <el-table-column prop="status" align="center" label="状态" width="80">
  29. <template #default="scope">
  30. <el-avatar class="status" :style="scope.row.ALIVEVALUE == 3
  31. ? 'background-color:#04F21C'
  32. : 'background-color:red'
  33. "></el-avatar>
  34. </template>
  35. </el-table-column>
  36. <el-table-column prop="deviceName" label="名称" align="center"></el-table-column>
  37. <el-table-column prop="deviceCode" label="编号" align="center" width=""></el-table-column>
  38. <el-table-column prop="floor" label="楼层" align="center" width="60"></el-table-column>
  39. <el-table-column prop="deviceAddress" label="设备安装位置" align="center" width=""></el-table-column>
  40. <el-table-column prop="deviceType" label="设备类型" align="center">
  41. <template #default="scope">
  42. {{ scope.row.deviceType == '2' ? '视频监控设备' : '其他' }}
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="installTime" label="安装时间" align="center" width="200"></el-table-column>
  46. <el-table-column prop="creator" label="创建人" align="center"></el-table-column>
  47. <el-table-column prop="sim" label="sim卡号" align="center"></el-table-column>
  48. <el-table-column fixed="right" label="操作" width="140">
  49. <template #default="scope">
  50. <el-button type="primary" size="small" @click.prevent="editRow(scope.row)"
  51. :disabled="store.state.authorities.indexOf('修改') == -1" link>
  52. 编辑
  53. </el-button>
  54. <el-popconfirm confirm-button-text="是" cancel-button-text="否" icon="el-icon-info" icon-color="red" title="确定删除?"
  55. @confirm="handleDelete(scope.row)" @cancel="cancelEvent">
  56. <template #reference>
  57. <el-button type="danger" size="small" :disabled="store.state.authorities.indexOf('删除') == -1" link>
  58. 删除
  59. </el-button>
  60. </template>
  61. </el-popconfirm>
  62. </template>
  63. </el-table-column>
  64. <el-table-column fixed="right" label="视频画面" width="100">
  65. <template #default="scope">
  66. <a v-if="scope.row.ALIVEVALUE == 3" @click="open_video(scope.row)">
  67. 查看
  68. </a>
  69. <span v-else style="color: #aaa">--</span>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <!-- 表格end -->
  74. <!-- 分页start -->
  75. <div class="paginationBlock">
  76. <el-pagination v-model:currentPage="currentPage" :page-sizes="[15, 20, 25, 30]" :page-size="pageSize"
  77. layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
  78. @current-change="handleCurrentChange" background></el-pagination>
  79. </div>
  80. <!-- 分页end -->
  81. <!--弹框组件开始-----------------------start-->
  82. <dialog-component ref="dialogComponent" @handleSelect="searchData()"></dialog-component>
  83. <!--弹框组件开始-----------------------end-->
  84. <!--视频弹框组件开始-----------------------start-->
  85. <check-video ref="checkVideoRef"></check-video>
  86. <!--视频弹框组件结束-----------------------end-->
  87. </div>
  88. </template>
  89. <script setup>
  90. /*----------------------------------依赖引入-----------------------------------*/
  91. import { useStore } from 'vuex'
  92. import { ref, onMounted, watch, getCurrentInstance } from 'vue'
  93. import { ElMessage } from 'element-plus'
  94. /*----------------------------------接口引入-----------------------------------*/
  95. /*----------------------------------组件引入-----------------------------------*/
  96. import DialogComponent from './dialogComponent'
  97. import checkVideo from './checkVideo'
  98. /*----------------------------------store引入-----------------------------------*/
  99. /*----------------------------------公共方法引入-----------------------------------*/
  100. import axios from 'axios'
  101. import * as api from '@/api/siteManage/camera.js'
  102. /*----------------------------------公共变量-----------------------------------*/
  103. const store = useStore()
  104. const props = defineProps({
  105. siteId: Number,
  106. activeName: String,
  107. }) //数据双向绑定
  108. const emit = defineEmits([]); emit
  109. const { proxy } = getCurrentInstance();
  110. /*----------------------------------变量声明-----------------------------------*/
  111. const total = ref(0)
  112. const pageSize = ref(15)
  113. const currentPage = ref(1)
  114. const deviceData = ref([])
  115. const fileUrl = ref(window.PLATFROM_CONFIG.baseUrl)
  116. const fileList = ref([])
  117. const accessToken = ref(store.state.user.accessToken)
  118. const labelCom = ref(store.state.siteManageLabelCom)
  119. const onLineVideoList = ref([])
  120. const reCount = ref(0)
  121. const loadingStatus = ref(false)
  122. //分页操作
  123. const handleSizeChange = (val) => {
  124. pageSize.value = val
  125. videoMonitoringDeviceList()
  126. }
  127. const handleCurrentChange = (val) => {
  128. currentPage.value = val
  129. videoMonitoringDeviceList()
  130. }
  131. //监控设备列表
  132. function videoMonitoringDeviceList() {
  133. api
  134. .videoMonitoringDeviceList({
  135. siteId: props.siteId,
  136. size: pageSize.value,
  137. current: currentPage.value,
  138. // deviceType:2
  139. })
  140. .then((requset) => {
  141. if (requset.status === 'SUCCESS') {
  142. deviceData.value = requset.data.records
  143. total.value = requset.data.total
  144. } else {
  145. ElMessage.error(requset.msg)
  146. }
  147. })
  148. }
  149. // 添加操作
  150. const addItem = () => {
  151. proxy.$refs["dialogComponent"].openDialog({
  152. dialogTitle: '新增',
  153. dialogArray: {
  154. deviceName: '',
  155. deviceCode: '',
  156. floor: '',
  157. siteId: '',
  158. deviceAddress: '',
  159. deviceType: '',
  160. sim: '',
  161. },
  162. })
  163. }
  164. // 编辑操作
  165. const editRow = (row) => {
  166. proxy.$refs["dialogComponent"].openDialog({
  167. dialogTitle: '编辑',
  168. dialogArray: {
  169. id: row.id,
  170. deviceCode: row.deviceCode,
  171. deviceName: row.deviceName,
  172. floor: row.floor,
  173. siteId: row.siteId,
  174. deviceAddress: row.deviceAddress,
  175. deviceType: Number(row.deviceType),
  176. sim: row.sim,
  177. },
  178. })
  179. }
  180. //删除 是否删除 ---- 是
  181. const handleDelete = (row) => {
  182. api.correspondDeviceDel({ id: row.id }).then((requset) => {
  183. if (requset.status === 'SUCCESS') {
  184. ElMessage.success({
  185. message: '删除成功',
  186. type: 'success',
  187. })
  188. videoMonitoringDeviceList()
  189. } else {
  190. ElMessage.error(requset.msg)
  191. }
  192. })
  193. }
  194. //是否删除 ---- 否
  195. const cancelEvent = () => {
  196. console.log('cancel!')
  197. }
  198. //导入
  199. const handleProgress = (file, fileList) => {
  200. if (!(fileList.raw.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || fileList.raw.type === 'application/vnd.ms-excel')) {
  201. ElMessage({
  202. message: '上传文件只能是 xls 和 xlsx 格式!',
  203. type: 'error',
  204. })
  205. return false
  206. } else {
  207. return true
  208. }
  209. }
  210. const handleUpAvatar = (res, file) => {
  211. console.log(res, file)
  212. fileList.value = []
  213. ElMessage.success({
  214. message: '导入成功',
  215. type: 'success',
  216. })
  217. videoMonitoringDeviceList()
  218. }
  219. function handleError(res) {
  220. let myError = res.toString() //转字符串
  221. myError = myError.replace('Error: ', '') //去掉前面的
  222. myError = JSON.parse(myError) //转对象
  223. ElMessage.error({
  224. message: myError.msg,
  225. type: 'error',
  226. })
  227. }
  228. //导出
  229. function DataReportExport() {
  230. api
  231. .deviceExport({
  232. siteId: props.siteId,
  233. })
  234. .then((requset) => {
  235. if (requset.status === 'SUCCESS') {
  236. window.location.href = window.PLATFROM_CONFIG.fileUrl + requset.data
  237. ElMessage.success({
  238. message: '导出成功',
  239. type: 'success',
  240. })
  241. } else {
  242. ElMessage.error(requset.msg)
  243. }
  244. })
  245. }
  246. // 初始化cgj
  247. function initCgi() {
  248. axios
  249. .post(
  250. 'https://fire.usky.cn:8443/YtIoT/cgi-bin/demo2.cgi',
  251. 'queryJson:' +
  252. JSON.stringify({ CMD: 1, }),
  253. {
  254. headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', },
  255. }
  256. )
  257. .then((response) => {
  258. onLineVideoList.value = response.data.RESULT.LIST
  259. for (var n = 0; n < onLineVideoList.value.length; n++) {
  260. for (var j = 0; j < deviceData.value.length; j++) {
  261. if (onLineVideoList.value[n].DEVICE == deviceData.value[j].deviceCode) {
  262. deviceData.value[j].ALIVEVALUE = onLineVideoList.value[n].ALIVEVALUE
  263. }
  264. }
  265. }
  266. })
  267. .catch((error) => {
  268. console.log(error)
  269. })
  270. }
  271. // 查看视频
  272. function open_video(item) {
  273. loadingStatus.value = true
  274. axios
  275. .post(
  276. 'https://fire.usky.cn:8443/YtIoT/cgi-bin/demo2.cgi',
  277. 'queryJson:' +
  278. JSON.stringify({
  279. CMD: 3,
  280. BODY: { DEVICE: item.deviceCode, ACTION: 1, IDX: 7, },
  281. }),
  282. {
  283. headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', },
  284. }
  285. )
  286. .then((response) => {
  287. response
  288. for (var n = 0; n < onLineVideoList.value.length; n++) {
  289. if (onLineVideoList.value[n].DEVICE == item.deviceCode) {
  290. // console.log('第一次打开时设备及其状态')
  291. if (onLineVideoList.value[n].ONAIR) {
  292. proxy.$refs["checkVideoRef"].openDialog({
  293. dialogTitle: '查看视频',
  294. dialogArray: item,
  295. onLineVideoList: onLineVideoList.value,
  296. })
  297. loadingStatus.value = false
  298. return
  299. } else {
  300. if (reCount.value >= 7) {
  301. reCount.value = 0
  302. loadingStatus.value = false
  303. alert('远程摄像头链接超时,请稍后再试')
  304. break
  305. }
  306. store.state.siteCameraTimer = setTimeout(() => {
  307. initCgi();
  308. open_video(item);
  309. reCount.value++
  310. }, 2000)
  311. }
  312. }
  313. }
  314. })
  315. }
  316. function searchData() {
  317. reCount.value = 0
  318. loadingStatus.value = false
  319. initCgi();
  320. videoMonitoringDeviceList()
  321. }
  322. watch(
  323. () => props.activeName,
  324. (newVal) => {
  325. if (newVal == 'five' && props.siteId) {
  326. searchData()
  327. }
  328. }
  329. )
  330. onMounted(() => {
  331. searchData()
  332. })
  333. </script>
  334. <style lang="scss" scoped></style>