channelList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <div id="channelList">
  3. <el-container>
  4. <el-header>
  5. <uiHeader></uiHeader>
  6. </el-header>
  7. <el-main>
  8. <div style="background-color: #FFFFFF; position: relative; padding: 1rem 0.5rem 0.5rem 0.5rem; text-align: center;">
  9. <span style="font-size: 1rem; font-weight: 500; ">通道列表({{parentChannelId ==0 ? deviceId:parentChannelId}})</span>
  10. </div>
  11. <div style="background-color: #FFFFFF; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left;font-size: 14px;">
  12. <el-button icon="el-icon-arrow-left" size="mini" style="margin-right: 1rem;" type="primary" @click="showDevice">返回</el-button>
  13. 搜索: <el-input @input="search" style="margin-right: 1rem; width: auto;" size="mini" placeholder="关键字" prefix-icon="el-icon-search" v-model="searchSrt" clearable> </el-input>
  14. 通道类型: <el-select size="mini" @change="search" style="margin-right: 1rem;" v-model="channelType" placeholder="请选择" default-first-option>
  15. <el-option label="全部" value=""></el-option>
  16. <el-option label="设备" value="false"></el-option>
  17. <el-option label="子目录" value="true"></el-option>
  18. </el-select>
  19. 在线状态: <el-select size="mini" style="margin-right: 1rem;" @change="search" v-model="online" placeholder="请选择" default-first-option>
  20. <el-option label="全部" value=""></el-option>
  21. <el-option label="在线" value="true"></el-option>
  22. <el-option label="离线" value="false"></el-option>
  23. </el-select>
  24. <el-checkbox size="mini" style="margin-right: 1rem; float: right;" v-model="autoList" @change="autoListChange">自动刷新</el-checkbox>
  25. </div>
  26. <devicePlayer ref="devicePlayer" v-loading="isLoging"></devicePlayer>
  27. <!--设备列表-->
  28. <el-table ref="channelListTable" :data="deviceChannelList" :height="winHeight" border style="width: 100%">
  29. <el-table-column prop="channelId" label="通道编号" width="210">
  30. </el-table-column>
  31. <el-table-column prop="deviceId" label="设备编号" width="210">
  32. </el-table-column>
  33. <el-table-column prop="name" label="通道名称">
  34. </el-table-column>
  35. <el-table-column label="快照" width="80" align="center">
  36. <template slot-scope="scope">
  37. <img style="max-height: 3rem;max-width: 4rem;"
  38. :id="scope.row.deviceId + '_' + scope.row.channelId"
  39. :src="getSnap(scope.row)"
  40. @error="getSnapErrorEvent($event.target.id)"
  41. alt="">
  42. <!-- <el-image-->
  43. <!-- :id="'snapImg_' + scope.row.deviceId + '_' + scope.row.channelId"-->
  44. <!-- :src="getSnap(scope.row)"-->
  45. <!-- @error="getSnapErrorEvent($event, scope.row)"-->
  46. <!-- :fit="'contain'">-->
  47. <!-- <div slot="error" class="image-slot">-->
  48. <!-- <i class="el-icon-picture-outline"></i>-->
  49. <!-- </div>-->
  50. <!-- </el-image>-->
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="subCount" label="子节点数">
  54. </el-table-column>
  55. <el-table-column label="开启音频" align="center">
  56. <template slot-scope="scope">
  57. <el-switch @change="updateChannel(scope.row)" v-model="scope.row.hasAudio" active-color="#409EFF">
  58. </el-switch>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="状态" width="180" align="center">
  62. <template slot-scope="scope">
  63. <div slot="reference" class="name-wrapper">
  64. <el-tag size="medium" v-if="scope.row.status == 1">开启</el-tag>
  65. <el-tag size="medium" type="info" v-if="scope.row.status == 0">关闭</el-tag>
  66. </div>
  67. </template>
  68. </el-table-column>
  69. <el-table-column prop="ptztypeText" label="云台类型">
  70. </el-table-column>
  71. <el-table-column label="操作" width="280" align="center" fixed="right">
  72. <template slot-scope="scope">
  73. <el-button-group>
  74. <!-- <el-button size="mini" icon="el-icon-video-play" v-if="scope.row.parental == 0" @click="sendDevicePush(scope.row)">播放</el-button> -->
  75. <el-button size="mini" icon="el-icon-video-play" @click="sendDevicePush(scope.row)">播放</el-button>
  76. <el-button size="mini" icon="el-icon-switch-button" type="danger" v-if="!!scope.row.streamId" @click="stopDevicePush(scope.row)">停止</el-button>
  77. <el-button size="mini" icon="el-icon-s-open" type="primary" v-if="scope.row.parental == 1" @click="changeSubchannel(scope.row)">查看</el-button>
  78. <el-button size="mini" icon="el-icon-video-camera" type="primary" @click="queryRecords(scope.row)">设备录象</el-button>
  79. <!-- <el-button size="mini" @click="sendDevicePush(scope.row)">录像查询</el-button> -->
  80. </el-button-group>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <el-pagination style="float: right" @size-change="handleSizeChange" @current-change="currentChange" :current-page="currentPage" :page-size="count" :page-sizes="[15, 20, 30, 50]" layout="total, sizes, prev, pager, next" :total="total">
  85. </el-pagination>
  86. </el-main>
  87. </el-container>
  88. </div>
  89. </template>
  90. <script>
  91. import devicePlayer from './dialog/devicePlayer.vue'
  92. import uiHeader from './UiHeader.vue'
  93. import moment from "moment";
  94. export default {
  95. name: 'channelList',
  96. components: {
  97. devicePlayer,
  98. uiHeader
  99. },
  100. data() {
  101. return {
  102. deviceId: this.$route.params.deviceId,
  103. parentChannelId: this.$route.params.parentChannelId,
  104. deviceChannelList: [],
  105. videoComponentList: [],
  106. currentPlayerInfo: {}, //当前播放对象
  107. updateLooper: 0, //数据刷新轮训标志
  108. searchSrt: "",
  109. channelType: "",
  110. online: "",
  111. winHeight: window.innerHeight - 250,
  112. currentPage: parseInt(this.$route.params.page),
  113. count: parseInt(this.$route.params.count),
  114. total: 0,
  115. beforeUrl: "/deviceList",
  116. isLoging: false,
  117. autoList: true,
  118. loadSnap:{}
  119. };
  120. },
  121. mounted() {
  122. this.initData();
  123. if (this.autoList) {
  124. this.updateLooper = setInterval(this.initData, 5000);
  125. }
  126. },
  127. destroyed() {
  128. this.$destroy('videojs');
  129. clearTimeout(this.updateLooper);
  130. },
  131. methods: {
  132. initData: function () {
  133. if (typeof (this.parentChannelId) == "undefined" || this.parentChannelId == 0) {
  134. this.getDeviceChannelList();
  135. } else {
  136. this.showSubchannels();
  137. }
  138. },
  139. initParam: function () {
  140. this.deviceId = this.$route.params.deviceId;
  141. this.parentChannelId = this.$route.params.parentChannelId;
  142. this.currentPage = parseInt(this.$route.params.page);
  143. this.count = parseInt(this.$route.params.count);
  144. if (this.parentChannelId == "" || this.parentChannelId == 0) {
  145. this.beforeUrl = "/deviceList"
  146. }
  147. },
  148. currentChange: function (val) {
  149. var url = `/${this.$router.currentRoute.name}/${this.deviceId}/${this.parentChannelId}/${this.count}/${val}`
  150. this.$router.push(url).then(() => {
  151. this.initParam();
  152. this.initData();
  153. })
  154. },
  155. handleSizeChange: function (val) {
  156. var url = `/${this.$router.currentRoute.name}/${this.$router.params.deviceId}/${this.$router.params.parentChannelId}/${val}/1`
  157. this.$router.push(url).then(() => {
  158. this.initParam();
  159. this.initData();
  160. })
  161. },
  162. getDeviceChannelList: function () {
  163. let that = this;
  164. if (typeof (this.$route.params.deviceId) == "undefined") return;
  165. this.$axios({
  166. method: 'get',
  167. url: `/api/device/query/devices/${this.$route.params.deviceId}/channels`,
  168. params:{
  169. page: that.currentPage,
  170. count: that.count,
  171. query: that.searchSrt,
  172. online: that.online,
  173. channelType: that.channelType
  174. }
  175. }).then(function (res) {
  176. that.total = res.data.total;
  177. that.deviceChannelList = res.data.list;
  178. // 防止出现表格错位
  179. that.$nextTick(() => {
  180. that.$refs.channelListTable.doLayout();
  181. })
  182. }).catch(function (error) {
  183. console.log(error);
  184. });
  185. },
  186. //通知设备上传媒体流
  187. sendDevicePush: function (itemData) {
  188. let deviceId = this.deviceId;
  189. this.isLoging = true;
  190. let channelId = itemData.channelId;
  191. console.log("通知设备推流1:" + deviceId + " : " + channelId );
  192. let that = this;
  193. this.$axios({
  194. method: 'get',
  195. url: '/api/play/start/' + deviceId + '/' + channelId
  196. }).then(function (res) {
  197. that.isLoging = false;
  198. if (res.data.code == 0) {
  199. setTimeout(()=>{
  200. console.log("下载截图")
  201. let snapId = deviceId + "_" + channelId;
  202. that.loadSnap[snapId] = 0;
  203. that.getSnapErrorEvent(snapId)
  204. },5000)
  205. that.$refs.devicePlayer.openDialog("media", deviceId, channelId, {
  206. streamInfo: res.data.data,
  207. hasAudio: itemData.hasAudio
  208. });
  209. that.initData();
  210. }else {
  211. that.$message.error(res.data.msg);
  212. }
  213. }).catch(function (e) {});
  214. },
  215. queryRecords: function (itemData) {
  216. var format = moment().format("YYYY-M-D");
  217. let deviceId = this.deviceId;
  218. let channelId = itemData.channelId;
  219. this.$refs.devicePlayer.openDialog("record", deviceId, channelId, {date: format})
  220. },
  221. stopDevicePush: function (itemData) {
  222. var that = this;
  223. this.$axios({
  224. method: 'get',
  225. url: '/api/play/stop/' + this.deviceId + "/" + itemData.channelId
  226. }).then(function (res) {
  227. that.initData();
  228. }).catch(function (error) {
  229. if (error.response.status === 402) { // 已经停止过
  230. that.initData();
  231. }else {
  232. console.log(error)
  233. }
  234. });
  235. },
  236. getSnap: function (row){
  237. return '/static/snap/' + row.deviceId + '_' + row.channelId + '.jpg'
  238. },
  239. getSnapErrorEvent: function (id){
  240. if (typeof (this.loadSnap[id]) != "undefined") {
  241. console.log("下载截图" + this.loadSnap[id])
  242. if (this.loadSnap[id] > 5) {
  243. delete this.loadSnap[id];
  244. return;
  245. }
  246. setTimeout(()=>{
  247. this.loadSnap[id] ++
  248. document.getElementById(id).setAttribute("src", '/static/snap/' + id + '.jpg?' + new Date().getTime())
  249. },1000)
  250. }
  251. },
  252. showDevice: function () {
  253. this.$router.push(this.beforeUrl).then(() => {
  254. this.initParam();
  255. this.initData();
  256. })
  257. },
  258. changeSubchannel(itemData) {
  259. this.beforeUrl = this.$router.currentRoute.path;
  260. var url = `/${this.$router.currentRoute.name}/${this.$router.currentRoute.params.deviceId}/${itemData.channelId}/${this.$router.currentRoute.params.count}/1`
  261. this.$router.push(url).then(() => {
  262. this.searchSrt = "";
  263. this.channelType = "";
  264. this.online = "";
  265. this.initParam();
  266. this.initData();
  267. })
  268. },
  269. showSubchannels: function (channelId) {
  270. let that = this;
  271. this.$axios({
  272. method: 'get',
  273. url:`/api/device/query/sub_channels/${this.deviceId}/${this.parentChannelId}/channels`,
  274. params: {
  275. page: that.currentPage,
  276. count: that.count,
  277. query: that.searchSrt,
  278. online: that.online,
  279. channelType: that.channelType
  280. }
  281. }).then(function (res) {
  282. that.total = res.data.total;
  283. that.deviceChannelList = res.data.list;
  284. // 防止出现表格错位
  285. that.$nextTick(() => {
  286. that.$refs.channelListTable.doLayout();
  287. })
  288. }).catch(function (error) {
  289. console.log(error);
  290. });
  291. },
  292. search: function () {
  293. this.currentPage = 1;
  294. this.total = 0;
  295. this.initData();
  296. },
  297. updateChannel: function (row) {
  298. this.$axios({
  299. method: 'post',
  300. url: `/api/device/query/channel/update/${this.deviceId}`,
  301. params: row
  302. }).then(function (res) {
  303. console.log(JSON.stringify(res));
  304. });
  305. },
  306. autoListChange: function () {
  307. if (this.autoList) {
  308. this.updateLooper = setInterval(this.initData, 1500);
  309. }else{
  310. window.clearInterval(this.updateLooper);
  311. }
  312. }
  313. }
  314. };
  315. </script>
  316. <style>
  317. .videoList {
  318. display: flex;
  319. flex-wrap: wrap;
  320. align-content: flex-start;
  321. }
  322. .video-item {
  323. position: relative;
  324. width: 15rem;
  325. height: 10rem;
  326. margin-right: 1rem;
  327. background-color: #000000;
  328. }
  329. .video-item-img {
  330. position: absolute;
  331. top: 0;
  332. bottom: 0;
  333. left: 0;
  334. right: 0;
  335. margin: auto;
  336. width: 100%;
  337. height: 100%;
  338. }
  339. .video-item-img:after {
  340. content: "";
  341. display: inline-block;
  342. position: absolute;
  343. z-index: 2;
  344. top: 0;
  345. bottom: 0;
  346. left: 0;
  347. right: 0;
  348. margin: auto;
  349. width: 3rem;
  350. height: 3rem;
  351. background-image: url("../assets/loading.png");
  352. background-size: cover;
  353. background-color: #000000;
  354. }
  355. .video-item-title {
  356. position: absolute;
  357. bottom: 0;
  358. color: #000000;
  359. background-color: #ffffff;
  360. line-height: 1.5rem;
  361. padding: 0.3rem;
  362. width: 14.4rem;
  363. }
  364. </style>