channelList.vue 21 KB

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