channelList.vue 16 KB

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