channelList.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <div id="channelList" style="width: 100%">
  3. <div class="page-header">
  4. <div class="page-title">
  5. <el-button icon="el-icon-back" size="mini" style="font-size: 20px; color: #000;" type="text" @click="showDevice" ></el-button>
  6. <el-divider direction="vertical"></el-divider>
  7. 通道列表
  8. </div>
  9. <div class="page-header-btn">
  10. <div v-if="!showTree" style="display: inline;">
  11. <el-button size="medium" type="text" @click="switchUsePs()">{{isUsePs?'启用ps':'不启用ps'}}</el-button>
  12. 搜索:
  13. <el-input @input="search" style="margin-right: 1rem; width: auto;" size="mini" placeholder="关键字"
  14. prefix-icon="el-icon-search" v-model="searchSrt" clearable></el-input>
  15. 通道类型:
  16. <el-select size="mini" @change="search" style="margin-right: 1rem;" v-model="channelType" placeholder="请选择"
  17. default-first-option>
  18. <el-option label="全部" value=""></el-option>
  19. <el-option label="设备" value="false"></el-option>
  20. <el-option label="子目录" value="true"></el-option>
  21. </el-select>
  22. 在线状态:
  23. <el-select size="mini" style="margin-right: 1rem;" @change="search" v-model="online" placeholder="请选择"
  24. default-first-option>
  25. <el-option label="全部" value=""></el-option>
  26. <el-option label="在线" value="true"></el-option>
  27. <el-option label="离线" value="false"></el-option>
  28. </el-select>
  29. </div>
  30. <el-button icon="el-icon-refresh-right" circle size="mini" @click="refresh()"></el-button>
  31. <el-button v-if="showTree" icon="iconfont icon-list" circle size="mini" @click="switchList()"></el-button>
  32. <el-button v-if="!showTree" icon="iconfont icon-tree" circle size="mini" @click="switchTree()"></el-button>
  33. </div>
  34. </div>
  35. <ptz-control ref="ptzControl"/>
  36. <!-- <devicePlayer ref="devicePlayer" ></devicePlayer>-->
  37. <custom-player ref="devicePlayer" @close="closeHandle()"></custom-player>
  38. <el-container v-loading="isLoging" style="height: 82vh;">
  39. <el-aside width="auto" style="height: 82vh; background-color: #ffffff; overflow: auto" v-if="showTree" >
  40. <DeviceTree ref="deviceTree" :device="device" :onlyCatalog="true" :clickEvent="treeNodeClickEvent" ></DeviceTree>
  41. </el-aside>
  42. <el-main style="padding: 5px;">
  43. <el-table ref="channelListTable" :data="deviceChannelList" :height="winHeight" style="width: 100%" header-row-class-name="table-header">
  44. <el-table-column prop="channelId" label="通道编号" min-width="200">
  45. </el-table-column>
  46. <el-table-column prop="deviceId" label="设备编号" min-width="200">
  47. </el-table-column>
  48. <el-table-column prop="name" label="通道名称" min-width="200">
  49. </el-table-column>
  50. <el-table-column label="快照" min-width="120">
  51. <template v-slot:default="scope">
  52. <el-image
  53. :src="getSnap(scope.row)"
  54. :preview-src-list="getBigSnap(scope.row)"
  55. @error="getSnapErrorEvent(scope.row.deviceId, scope.row.channelId)"
  56. :fit="'contain'"
  57. style="width: 60px">
  58. <div slot="error" class="image-slot">
  59. <i class="el-icon-picture-outline"></i>
  60. </div>
  61. </el-image>
  62. </template>
  63. </el-table-column>
  64. <el-table-column prop="subCount" label="子节点数" min-width="120">
  65. </el-table-column>
  66. <el-table-column prop="manufacture" label="厂家" min-width="120">
  67. </el-table-column>
  68. <el-table-column label="位置信息" min-width="200">
  69. <template slot-scope="scope">
  70. <span v-if="scope.row.longitude*scope.row.latitude > 0">{{ scope.row.longitude }},<br>{{ scope.row.latitude }}</span>
  71. <span v-if="scope.row.longitude*scope.row.latitude === 0">无</span>
  72. </template>
  73. </el-table-column>
  74. <el-table-column prop="ptztypeText" label="云台类型" min-width="120"/>
  75. <el-table-column label="开启音频" min-width="120">
  76. <template slot-scope="scope">
  77. <el-switch @change="updateChannel(scope.row)" v-model="scope.row.hasAudio" active-color="#409EFF">
  78. </el-switch>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="状态" min-width="120">
  82. <template slot-scope="scope">
  83. <div slot="reference" class="name-wrapper">
  84. <el-tag size="medium" v-if="scope.row.status === 1">在线</el-tag>
  85. <el-tag size="medium" type="info" v-if="scope.row.status === 0">离线</el-tag>
  86. </div>
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="操作" min-width="280" fixed="right">
  90. <template slot-scope="scope">
  91. <el-button size="medium" icon="el-icon-coordinate" type="text" @click="showPtzControl(scope.row)">云台</el-button>
  92. <el-button size="medium" v-bind:disabled="device == null || device.online === 0" icon="el-icon-video-play" type="text" @click="sendDevicePush(scope.row)">播放</el-button>
  93. <el-button size="medium" v-bind:disabled="device == null || device.online === 0" icon="el-icon-switch-button" type="text" style="color: #f56c6c" v-if="!!scope.row.streamId"
  94. @click="stopDevicePush(scope.row)">停止
  95. </el-button>
  96. <el-divider direction="vertical"></el-divider>
  97. <el-button size="medium" icon="el-icon-s-open" type="text" v-if="scope.row.subCount > 0 || scope.row.parental === 1"
  98. @click="changeSubchannel(scope.row)">查看
  99. </el-button>
  100. <el-divider v-if="scope.row.subCount > 0 || scope.row.parental === 1" direction="vertical"></el-divider>
  101. <el-button size="medium" v-bind:disabled="device == null || device.online === 0" icon="el-icon-video-camera" type="text" @click="queryRecords(scope.row)">设备录像
  102. </el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. <el-pagination
  107. style="float: right"
  108. @size-change="handleSizeChange"
  109. @current-change="currentChange"
  110. :current-page="currentPage"
  111. :page-size="count"
  112. :page-sizes="[15, 25, 35, 50]"
  113. layout="total, sizes, prev, pager, next"
  114. :total="total">
  115. </el-pagination>
  116. </el-main>
  117. </el-container>
  118. <!--设备列表-->
  119. </div>
  120. </template>
  121. <script>
  122. import devicePlayer from './dialog/devicePlayer.vue'
  123. import uiHeader from '../layout/UiHeader.vue'
  124. import moment from "moment";
  125. import DeviceService from "./service/DeviceService";
  126. import DeviceTree from "./common/DeviceTree";
  127. import PtzControl from "./dialog/dialogPtzControl";
  128. import CustomPlayer from "@/components/dialog/customPlayer";
  129. export default {
  130. name: 'channelList',
  131. components: {
  132. CustomPlayer,
  133. PtzControl,
  134. devicePlayer,
  135. uiHeader,
  136. DeviceTree
  137. },
  138. data() {
  139. return {
  140. deviceService: new DeviceService(),
  141. device: null,
  142. deviceId: this.$route.params.deviceId,
  143. parentChannelId: this.$route.params.parentChannelId,
  144. deviceChannelList: [],
  145. videoComponentList: [],
  146. currentPlayerInfo: {}, //当前播放对象
  147. updateLooper: 0, //数据刷新轮训标志
  148. searchSrt: "",
  149. channelType: "",
  150. online: "",
  151. winHeight: window.innerHeight - 200,
  152. currentPage: 1,
  153. count: 15,
  154. total: 0,
  155. beforeUrl: "/deviceList",
  156. isLoging: false,
  157. showTree: false,
  158. loadSnap: {},
  159. isUsePs: true,
  160. };
  161. },
  162. mounted() {
  163. if (this.deviceId) {
  164. this.deviceService.getDevice(this.deviceId, (result)=>{
  165. this.device = result;
  166. }, (error)=>{
  167. console.log("获取设备信息失败")
  168. console.error(error)
  169. })
  170. }
  171. this.initData();
  172. },
  173. destroyed() {
  174. this.$destroy('videojs');
  175. clearTimeout(this.updateLooper);
  176. },
  177. methods: {
  178. initData: function () {
  179. if (typeof (this.parentChannelId) == "undefined" || this.parentChannelId == 0) {
  180. this.getDeviceChannelList();
  181. } else {
  182. this.showSubchannels();
  183. }
  184. },
  185. initParam: function () {
  186. this.deviceId = this.$route.params.deviceId;
  187. this.parentChannelId = this.$route.params.parentChannelId;
  188. this.currentPage = 1;
  189. this.count = 15;
  190. if (this.parentChannelId == "" || this.parentChannelId == 0) {
  191. this.beforeUrl = "/deviceList"
  192. }
  193. },
  194. currentChange: function (val) {
  195. this.currentPage = val;
  196. this.initData();
  197. },
  198. handleSizeChange: function (val) {
  199. this.count = val;
  200. this.getDeviceChannelList();
  201. },
  202. getDeviceChannelList: function () {
  203. let that = this;
  204. if (typeof (this.$route.params.deviceId) == "undefined") return;
  205. this.$axios.axios({
  206. method: 'get',
  207. url: `/api/device/query/devices/${this.$route.params.deviceId}/channels`,
  208. params: {
  209. page: that.currentPage,
  210. count: that.count,
  211. query: that.searchSrt,
  212. online: that.online,
  213. channelType: that.channelType
  214. }
  215. }).then(function (res) {
  216. if (res.data.code === 0) {
  217. that.total = res.data.data.total;
  218. that.deviceChannelList = res.data.data.list;
  219. // 防止出现表格错位
  220. that.$nextTick(() => {
  221. that.$refs.channelListTable.doLayout();
  222. })
  223. }
  224. }).catch(function (error) {
  225. console.log(error);
  226. });
  227. },
  228. showPtzControl(itemData){
  229. let deviceId = this.deviceId;
  230. let channelId = itemData.channelId;
  231. this.isLoging = true;
  232. this.isLoging = false;
  233. this.$refs.ptzControl.showPtzControl(deviceId,channelId);
  234. },
  235. switchUsePs(){
  236. this.isUsePs = !this.isUsePs;
  237. },
  238. //通知设备上传媒体流
  239. sendDevicePush: function (itemData) {
  240. let deviceId = this.deviceId;
  241. this.isLoging = true;
  242. let channelId = itemData.channelId;
  243. let isUsePs = this.isUsePs?1:0;
  244. let pushUrl = `/api/play/start/${deviceId}/${channelId}?isUsePs=${isUsePs}`
  245. console.log(pushUrl);
  246. console.log("通知设备推流1:" + deviceId + " : " + channelId);
  247. let that = this;
  248. this.$axios.axios({
  249. method: 'get',
  250. url: pushUrl
  251. }).then(function (res) {
  252. console.log(res)
  253. that.isLoging = false;
  254. if (res.data.code === 0) {
  255. setTimeout(() => {
  256. let snapId = deviceId + "_" + channelId;
  257. that.loadSnap[deviceId + channelId] = 0;
  258. that.getSnapErrorEvent(snapId)
  259. }, 5000)
  260. itemData.streamId = res.data.data.stream;
  261. that.$refs.devicePlayer.openDialog("media", deviceId, channelId, {
  262. streamInfo: res.data.data,
  263. hasAudio: itemData.hasAudio
  264. });
  265. setTimeout(() => {
  266. that.initData();
  267. }, 1000)
  268. }else{
  269. that.$message.error(res.data.msg);
  270. }
  271. }).catch(function (e) {
  272. console.error(e)
  273. that.isLoging = false;
  274. // that.$message.error("请求超时");
  275. });
  276. },
  277. queryRecords: function (itemData) {
  278. let deviceId = this.deviceId;
  279. let channelId = itemData.channelId;
  280. this.$router.push(`/gbRecordDetail/${deviceId}/${channelId}`)
  281. },
  282. stopDevicePush: function (itemData) {
  283. var that = this;
  284. this.$axios.axios({
  285. method: 'get',
  286. url: '/api/play/stop/' + this.deviceId + "/" + itemData.channelId
  287. }).then(function (res) {
  288. that.initData();
  289. }).catch(function (error) {
  290. if (error.response.status === 402) { // 已经停止过
  291. that.initData();
  292. } else {
  293. console.log(error)
  294. }
  295. });
  296. },
  297. getSnap: function (row) {
  298. let url = (process.env.NODE_ENV === 'development'? "debug": "") + '/api/device/query/snap/' + row.deviceId + '/' + row.channelId
  299. return url
  300. },
  301. getBigSnap: function (row) {
  302. return [this.getSnap(row)]
  303. },
  304. getSnapErrorEvent: function (deviceId, channelId) {
  305. if (typeof (this.loadSnap[deviceId + channelId]) != "undefined") {
  306. console.log("下载截图" + this.loadSnap[deviceId + channelId])
  307. if (this.loadSnap[deviceId + channelId] > 5) {
  308. delete this.loadSnap[deviceId + channelId];
  309. return;
  310. }
  311. setTimeout(() => {
  312. let url = (process.env.NODE_ENV === 'development'? "debug": "") + '/api/device/query/snap/' + deviceId + '/' + channelId
  313. this.loadSnap[deviceId + channelId]++
  314. document.getElementById(deviceId + channelId).setAttribute("src", url + '?' + new Date().getTime())
  315. }, 1000)
  316. }
  317. },
  318. showDevice: function () {
  319. this.$router.push(this.beforeUrl).then(() => {
  320. this.initParam();
  321. this.initData();
  322. })
  323. },
  324. changeSubchannel(itemData) {
  325. this.beforeUrl = this.$router.currentRoute.path;
  326. var url = `/${this.$router.currentRoute.name}/${this.$router.currentRoute.params.deviceId}/${itemData.channelId}`
  327. this.$router.push(url).then(() => {
  328. this.searchSrt = "";
  329. this.channelType = "";
  330. this.online = "";
  331. this.initParam();
  332. this.initData();
  333. })
  334. },
  335. showSubchannels: function (channelId) {
  336. if (!this.showTree) {
  337. this.$axios.axios({
  338. method: 'get',
  339. url: `/api/device/query/sub_channels/${this.deviceId}/${this.parentChannelId}/channels`,
  340. params: {
  341. page: this.currentPage,
  342. count: this.count,
  343. query: this.searchSrt,
  344. online: this.online,
  345. channelType: this.channelType
  346. }
  347. }).then( (res) =>{
  348. if (res.data.code === 0) {
  349. this.total = res.data.data.total;
  350. this.deviceChannelList = res.data.data.list;
  351. // 防止出现表格错位
  352. this.$nextTick(() => {
  353. this.$refs.channelListTable.doLayout();
  354. })
  355. }
  356. }).catch(function (error) {
  357. console.log(error);
  358. });
  359. }else {
  360. this.$axios.axios({
  361. method: 'get',
  362. url: `/api/device/query/tree/channel/${this.deviceId}`,
  363. params: {
  364. parentId: this.parentChannelId,
  365. page: this.currentPage,
  366. count: this.count,
  367. }
  368. }).then((res)=> {
  369. if (res.data.code === 0) {
  370. this.total = res.data.total;
  371. this.deviceChannelList = res.data.list;
  372. // 防止出现表格错位
  373. this.$nextTick(() => {
  374. this.$refs.channelListTable.doLayout();
  375. })
  376. }
  377. }).catch(function (error) {
  378. console.log(error);
  379. });
  380. }
  381. },
  382. search: function () {
  383. this.currentPage = 1;
  384. this.total = 0;
  385. this.initData();
  386. },
  387. updateChannel: function (row) {
  388. this.$axios.axios({
  389. method: 'post',
  390. url: `/api/device/query/channel/update/${this.deviceId}`,
  391. params: row
  392. }).then(function (res) {
  393. console.log(JSON.stringify(res));
  394. });
  395. },
  396. refresh: function () {
  397. this.initData();
  398. },
  399. switchTree: function (){
  400. this.showTree = true;
  401. this.deviceChannelList = [];
  402. this.parentChannelId = 0;
  403. this.currentPage = 1;
  404. },
  405. switchList: function (){
  406. this.showTree = false;
  407. this.deviceChannelList = [];
  408. this.parentChannelId = 0;
  409. this.currentPage = 1;
  410. this.initData();
  411. },
  412. treeNodeClickEvent: function (device, data, isCatalog) {
  413. console.log(device)
  414. if (!!!data.channelId) {
  415. this.parentChannelId = device.deviceId;
  416. }else {
  417. this.parentChannelId = data.channelId;
  418. }
  419. this.initData();
  420. },
  421. closeHandle(){
  422. // 刷新页面
  423. this.refresh();
  424. }
  425. }
  426. };
  427. </script>
  428. <style>
  429. .videoList {
  430. display: flex;
  431. flex-wrap: wrap;
  432. align-content: flex-start;
  433. }
  434. .video-item {
  435. position: relative;
  436. width: 15rem;
  437. height: 10rem;
  438. margin-right: 1rem;
  439. background-color: #000000;
  440. }
  441. .video-item-img {
  442. position: absolute;
  443. top: 0;
  444. bottom: 0;
  445. left: 0;
  446. right: 0;
  447. margin: auto;
  448. width: 100%;
  449. height: 100%;
  450. }
  451. .video-item-img:after {
  452. content: "";
  453. display: inline-block;
  454. position: absolute;
  455. z-index: 2;
  456. top: 0;
  457. bottom: 0;
  458. left: 0;
  459. right: 0;
  460. margin: auto;
  461. width: 3rem;
  462. height: 3rem;
  463. background-image: url("../assets/loading.png");
  464. background-size: cover;
  465. background-color: #000000;
  466. }
  467. .video-item-title {
  468. position: absolute;
  469. bottom: 0;
  470. color: #000000;
  471. background-color: #ffffff;
  472. line-height: 1.5rem;
  473. padding: 0.3rem;
  474. width: 14.4rem;
  475. }
  476. </style>