channelList.vue 21 KB

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