channelList.vue 16 KB

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