channelList.vue 13 KB

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