channelList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. that.total = res.data.total;
  208. that.deviceChannelList = res.data.list;
  209. // 防止出现表格错位
  210. that.$nextTick(() => {
  211. that.$refs.channelListTable.doLayout();
  212. })
  213. }).catch(function (error) {
  214. console.log(error);
  215. });
  216. },
  217. //通知设备上传媒体流
  218. sendDevicePush: function (itemData) {
  219. let deviceId = this.deviceId;
  220. this.isLoging = true;
  221. let channelId = itemData.channelId;
  222. console.log("通知设备推流1:" + deviceId + " : " + channelId);
  223. let that = this;
  224. this.$axios({
  225. method: 'get',
  226. url: '/api/play/start/' + deviceId + '/' + channelId
  227. }).then(function (res) {
  228. console.log(res)
  229. that.isLoging = false;
  230. if (res.data.code === 0) {
  231. setTimeout(() => {
  232. let snapId = deviceId + "_" + channelId;
  233. that.loadSnap[deviceId + channelId] = 0;
  234. that.getSnapErrorEvent(snapId)
  235. }, 5000)
  236. that.$refs.devicePlayer.openDialog("media", deviceId, channelId, {
  237. streamInfo: res.data.data,
  238. hasAudio: itemData.hasAudio
  239. });
  240. setTimeout(() => {
  241. that.initData();
  242. }, 1000)
  243. }else{
  244. that.$message.error(res.data.msg);
  245. }
  246. }).catch(function (e) {
  247. console.error(e)
  248. that.isLoging = false;
  249. // that.$message.error("请求超时");
  250. });
  251. },
  252. queryRecords: function (itemData) {
  253. var format = moment().format("yyyy-MM-DD");
  254. let deviceId = this.deviceId;
  255. let channelId = itemData.channelId;
  256. this.$refs.devicePlayer.openDialog("record", deviceId, channelId, {date: format})
  257. },
  258. stopDevicePush: function (itemData) {
  259. var that = this;
  260. this.$axios({
  261. method: 'get',
  262. url: '/api/play/stop/' + this.deviceId + "/" + itemData.channelId
  263. }).then(function (res) {
  264. that.initData();
  265. }).catch(function (error) {
  266. if (error.response.status === 402) { // 已经停止过
  267. that.initData();
  268. } else {
  269. console.log(error)
  270. }
  271. });
  272. },
  273. getSnap: function (row) {
  274. let url = (process.env.NODE_ENV === 'development'? "debug": "") + '/api/device/query/snap/' + row.deviceId + '/' + row.channelId
  275. return url
  276. },
  277. getBigSnap: function (row) {
  278. return [this.getSnap(row)]
  279. },
  280. getSnapErrorEvent: function (deviceId, channelId) {
  281. if (typeof (this.loadSnap[deviceId + channelId]) != "undefined") {
  282. console.log("下载截图" + this.loadSnap[deviceId + channelId])
  283. if (this.loadSnap[deviceId + channelId] > 5) {
  284. delete this.loadSnap[deviceId + channelId];
  285. return;
  286. }
  287. setTimeout(() => {
  288. let url = (process.env.NODE_ENV === 'development'? "debug": "") + '/api/device/query/snap/' + deviceId + '/' + channelId
  289. this.loadSnap[deviceId + channelId]++
  290. document.getElementById(deviceId + channelId).setAttribute("src", url + '?' + new Date().getTime())
  291. }, 1000)
  292. }
  293. },
  294. showDevice: function () {
  295. this.$router.push(this.beforeUrl).then(() => {
  296. this.initParam();
  297. this.initData();
  298. })
  299. },
  300. changeSubchannel(itemData) {
  301. this.beforeUrl = this.$router.currentRoute.path;
  302. var url = `/${this.$router.currentRoute.name}/${this.$router.currentRoute.params.deviceId}/${itemData.channelId}`
  303. this.$router.push(url).then(() => {
  304. this.searchSrt = "";
  305. this.channelType = "";
  306. this.online = "";
  307. this.initParam();
  308. this.initData();
  309. })
  310. },
  311. showSubchannels: function (channelId) {
  312. if (!this.showTree) {
  313. this.$axios({
  314. method: 'get',
  315. url: `/api/device/query/sub_channels/${this.deviceId}/${this.parentChannelId}/channels`,
  316. params: {
  317. page: this.currentPage,
  318. count: this.count,
  319. query: this.searchSrt,
  320. online: this.online,
  321. channelType: this.channelType
  322. }
  323. }).then( (res) =>{
  324. this.total = res.data.total;
  325. this.deviceChannelList = res.data.list;
  326. // 防止出现表格错位
  327. this.$nextTick(() => {
  328. this.$refs.channelListTable.doLayout();
  329. })
  330. }).catch(function (error) {
  331. console.log(error);
  332. });
  333. }else {
  334. this.$axios({
  335. method: 'get',
  336. url: `/api/device/query/tree/channel/${this.deviceId}`,
  337. params: {
  338. parentId: this.parentChannelId,
  339. page: this.currentPage,
  340. count: this.count,
  341. }
  342. }).then((res)=> {
  343. this.total = res.data.total;
  344. this.deviceChannelList = res.data.list;
  345. // 防止出现表格错位
  346. this.$nextTick(() => {
  347. this.$refs.channelListTable.doLayout();
  348. })
  349. }).catch(function (error) {
  350. console.log(error);
  351. });
  352. }
  353. },
  354. search: function () {
  355. this.currentPage = 1;
  356. this.total = 0;
  357. this.initData();
  358. },
  359. updateChannel: function (row) {
  360. this.$axios({
  361. method: 'post',
  362. url: `/api/device/query/channel/update/${this.deviceId}`,
  363. params: row
  364. }).then(function (res) {
  365. console.log(JSON.stringify(res));
  366. });
  367. },
  368. refresh: function () {
  369. this.initData();
  370. },
  371. switchTree: function (){
  372. this.showTree = true;
  373. this.deviceChannelList = [];
  374. this.parentChannelId = 0;
  375. this.currentPage = 1;
  376. },
  377. switchList: function (){
  378. this.showTree = false;
  379. this.deviceChannelList = [];
  380. this.parentChannelId = 0;
  381. this.currentPage = 1;
  382. this.initData();
  383. },
  384. treeNodeClickEvent: function (device, data, isCatalog) {
  385. console.log(device)
  386. if (!!!data.channelId) {
  387. this.parentChannelId = device.deviceId;
  388. }else {
  389. this.parentChannelId = data.channelId;
  390. }
  391. this.initData();
  392. }
  393. }
  394. };
  395. </script>
  396. <style>
  397. .videoList {
  398. display: flex;
  399. flex-wrap: wrap;
  400. align-content: flex-start;
  401. }
  402. .video-item {
  403. position: relative;
  404. width: 15rem;
  405. height: 10rem;
  406. margin-right: 1rem;
  407. background-color: #000000;
  408. }
  409. .video-item-img {
  410. position: absolute;
  411. top: 0;
  412. bottom: 0;
  413. left: 0;
  414. right: 0;
  415. margin: auto;
  416. width: 100%;
  417. height: 100%;
  418. }
  419. .video-item-img:after {
  420. content: "";
  421. display: inline-block;
  422. position: absolute;
  423. z-index: 2;
  424. top: 0;
  425. bottom: 0;
  426. left: 0;
  427. right: 0;
  428. margin: auto;
  429. width: 3rem;
  430. height: 3rem;
  431. background-image: url("../assets/loading.png");
  432. background-size: cover;
  433. background-color: #000000;
  434. }
  435. .video-item-title {
  436. position: absolute;
  437. bottom: 0;
  438. color: #000000;
  439. background-color: #ffffff;
  440. line-height: 1.5rem;
  441. padding: 0.3rem;
  442. width: 14.4rem;
  443. }
  444. </style>