channelList.vue 19 KB

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