channelList.vue 16 KB

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