channelList.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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"
  6. @click="showDevice"></el-button>
  7. <el-divider direction="vertical"></el-divider>
  8. {{ $t('device.channelList') }}
  9. </div>
  10. <div class="page-header-btn">
  11. <div v-if="!showTree" style="display: inline;">
  12. <el-button size="medium" type="text" @click="switchUsePs()">{{ isUsePs ? $t('device.enablePs') : $t('device.disablePs') }}</el-button>
  13. {{ $t('search') }}:
  14. <el-input @input="search" style="margin-right: 1rem; width: auto;" size="mini" :placeholder="$t('keyword')"
  15. prefix-icon="el-icon-search" v-model="searchSrt" clearable></el-input>
  16. {{ $t('device.channelType') }}:
  17. <el-select size="mini" @change="search" style="margin-right: 1rem;" v-model="channelType" :placeholder="$t('pleaseSelect')"
  18. default-first-option>
  19. <el-option :label="$t('all')" value=""></el-option>
  20. <el-option :label="$t('device.title')" value="false"></el-option>
  21. <el-option :label="$t('device.subDir')" value="true"></el-option>
  22. </el-select>
  23. {{ $t('device.onlineState') }}:
  24. <el-select size="mini" style="margin-right: 1rem;" @change="search" v-model="online" :placeholder="$t('pleaseSelect')"
  25. default-first-option>
  26. <el-option :label="$t('all')" value=""></el-option>
  27. <el-option :label="$t('device.online')" value="true"></el-option>
  28. <el-option :label="$t('device.offline')" value="false"></el-option>
  29. </el-select>
  30. </div>
  31. <el-button icon="el-icon-refresh-right" circle size="mini" @click="refresh()"></el-button>
  32. <el-button v-if="showTree" icon="iconfont icon-list" circle size="mini" @click="switchList()"></el-button>
  33. <el-button v-if="!showTree" icon="iconfont icon-tree" circle size="mini" @click="switchTree()"></el-button>
  34. </div>
  35. </div>
  36. <ptz-control ref="ptzControl"/>
  37. <!-- <devicePlayer ref="devicePlayer" ></devicePlayer>-->
  38. <!-- <custom-player ref="devicePlayer" @close="closeHandle()"></custom-player>-->
  39. <new-play
  40. :show.sync="showPlayDialog"
  41. :enableDebug="false"
  42. :info="streamInfo"
  43. :device-id="deviceId"
  44. :channel-id="playChannelId"
  45. :shareUrl="shareUrl"
  46. @repush="rePushHandle()"
  47. @sharePlay="sharePlayHandle"
  48. ref="devicePlayer"
  49. @close="closeHandle()"></new-play>
  50. <el-container v-loading="isLoging" style="height: 82vh;">
  51. <el-aside width="auto" style="height: 82vh; background-color: #ffffff; overflow: auto" v-if="showTree">
  52. <DeviceTree ref="deviceTree" :device="device" :onlyCatalog="true" :clickEvent="treeNodeClickEvent"></DeviceTree>
  53. </el-aside>
  54. <el-main style="padding: 5px;">
  55. <el-table ref="channelListTable" :data="deviceChannelList"
  56. :height="winHeight" style="width: 100%"
  57. :row-key="record=>record.id"
  58. header-row-class-name="table-header">
  59. <el-table-column prop="channelId" :label="$t('device.channelId')" min-width="200">
  60. </el-table-column>
  61. <el-table-column prop="deviceId" :label="$t('device.id')" min-width="200">
  62. </el-table-column>
  63. <el-table-column prop="name" :label="$t('device.channelName')" min-width="200">
  64. <template slot-scope="scope">
  65. <div v-if="scope.row.isEdit">
  66. <el-input size="mini" v-model="editName" clearable></el-input>
  67. <el-button size="mini" type="text" @click="saveEditName(scope.row)">{{ $t('save') }}</el-button>
  68. <el-button size="mini" type="text" @click="exitEditName(scope.row)">{{ $t('cancel') }}</el-button>
  69. </div>
  70. <span v-else @click="toEditMode(scope.row)">{{ scope.row.name }}</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column prop="subCount" :label="$t('device.channelCount')" min-width="120">
  74. </el-table-column>
  75. <el-table-column prop="manufacture" :label="$t('device.manufacturer')" min-width="120">
  76. </el-table-column>
  77. <el-table-column :label="$t('device.position')" min-width="200">
  78. <template slot-scope="scope">
  79. <span v-if="scope.row.longitude*scope.row.latitude > 0">
  80. {{scope.row.longitude}},
  81. <br>
  82. {{ scope.row.latitude }}
  83. </span>
  84. <span v-if="scope.row.longitude*scope.row.latitude === 0">
  85. {{ $t('unknown') }}
  86. </span>
  87. </template>
  88. </el-table-column>
  89. <el-table-column prop="ptztypeText" :label="$t('device.ptzType')" min-width="120"/>
  90. <el-table-column :label="$t('device.enableAudio')" min-width="120">
  91. <template slot-scope="scope">
  92. <el-switch @change="updateChannel(scope.row)" v-model="scope.row.hasAudio" active-color="#409EFF">
  93. </el-switch>
  94. </template>
  95. </el-table-column>
  96. <el-table-column :label="$t('state')" min-width="120">
  97. <template slot-scope="scope">
  98. <div slot="reference" class="name-wrapper">
  99. <el-tag size="medium" v-if="scope.row.status === 1">{{ $t('device.online') }}</el-tag>
  100. <el-tag size="medium" type="info" v-if="scope.row.status === 0">{{ $t('device.offline') }}</el-tag>
  101. </div>
  102. </template>
  103. </el-table-column>
  104. <el-table-column :label="$t('operation')" min-width="280" fixed="right">
  105. <template slot-scope="scope">
  106. <el-button size="medium" icon="el-icon-coordinate" type="text" @click="showPtzControl(scope.row)">
  107. {{ $t('device.ptz') }}
  108. </el-button>
  109. <el-button size="medium" v-bind:disabled="device == null || device.online === 0" icon="el-icon-video-play"
  110. type="text" @click="sendDevicePush(scope.row)">
  111. {{ $t('device.play') }}
  112. </el-button>
  113. <el-button size="medium" v-bind:disabled="device == null || device.online === 0"
  114. icon="el-icon-switch-button" type="text" style="color: #f56c6c" v-if="!!scope.row.streamId"
  115. @click="stopDevicePush(scope.row)">
  116. {{ $t('device.stop') }}
  117. </el-button>
  118. <el-divider direction="vertical"></el-divider>
  119. <el-button size="medium" icon="el-icon-s-open" type="text"
  120. v-if="scope.row.subCount > 0 || scope.row.parental === 1"
  121. @click="changeSubchannel(scope.row)">
  122. {{ $t('view') }}
  123. </el-button>
  124. <el-divider v-if="scope.row.subCount > 0 || scope.row.parental === 1" direction="vertical"></el-divider>
  125. <el-button size="medium" v-bind:disabled="device == null || device.online === 0"
  126. icon="el-icon-video-camera" type="text" @click="queryRecords(scope.row)">
  127. {{ $t('device.record') }}
  128. </el-button>
  129. </template>
  130. </el-table-column>
  131. </el-table>
  132. <el-pagination
  133. style="float: right"
  134. @size-change="handleSizeChange"
  135. @current-change="currentChange"
  136. :current-page="currentPage"
  137. :page-size="count"
  138. :page-sizes="[15, 25, 35, 50]"
  139. layout="total, sizes, prev, pager, next"
  140. :total="total">
  141. </el-pagination>
  142. </el-main>
  143. </el-container>
  144. <!--设备列表-->
  145. </div>
  146. </template>
  147. <script>
  148. import devicePlayer from './dialog/devicePlayer.vue'
  149. import uiHeader from '../layout/UiHeader.vue'
  150. import DeviceService from "./service/DeviceService";
  151. import DeviceTree from "./common/DeviceTree";
  152. import PtzControl from "./dialog/dialogPtzControl";
  153. import CustomPlayer from "@/components/dialog/customPlayer";
  154. import newPlay from "@/components/dialog/newPlay.vue";
  155. import handle from "@/until/handle";
  156. import copy from "@/until/copy";
  157. export default {
  158. name: 'channelList',
  159. components: {
  160. CustomPlayer,
  161. PtzControl,
  162. devicePlayer,
  163. uiHeader,
  164. DeviceTree,
  165. newPlay
  166. },
  167. data() {
  168. return {
  169. showPlayDialog: false,
  170. deviceService: new DeviceService(),
  171. device: null,
  172. deviceId: this.$route.params.deviceId,
  173. parentChannelId: this.$route.params.parentChannelId,
  174. playChannelId: '',
  175. deviceChannelList: [],
  176. videoComponentList: [],
  177. currentPlayerInfo: {}, //当前播放对象
  178. updateLooper: 0, //数据刷新轮训标志
  179. searchSrt: "",
  180. channelType: "",
  181. online: "",
  182. winHeight: window.innerHeight - 200,
  183. currentPage: 1,
  184. count: 15,
  185. total: 0,
  186. beforeUrl: "/deviceList",
  187. isLoging: false,
  188. showTree: false,
  189. loadSnap: {},
  190. isUsePs: true,
  191. editName: '',
  192. streamInfo: {},
  193. shareUrl: ""
  194. };
  195. },
  196. mounted() {
  197. if (this.deviceId) {
  198. this.deviceService.getDevice(this.deviceId, (result) => {
  199. this.device = result;
  200. }, (error) => {
  201. console.log("获取设备信息失败")
  202. console.error(error)
  203. })
  204. }
  205. this.initData();
  206. },
  207. destroyed() {
  208. this.$destroy('videojs');
  209. clearTimeout(this.updateLooper);
  210. },
  211. methods: {
  212. async copy(str) {
  213. let [err, res] = await handle(copy(str))
  214. if (err) {
  215. return this.$message.error(err.message);
  216. }
  217. this.$message.success('复制播放地址成功');
  218. },
  219. initData: function () {
  220. if (typeof (this.parentChannelId) == "undefined" || this.parentChannelId == 0) {
  221. this.getDeviceChannelList();
  222. } else {
  223. this.showSubchannels();
  224. }
  225. },
  226. initParam: function () {
  227. this.deviceId = this.$route.params.deviceId;
  228. this.parentChannelId = this.$route.params.parentChannelId;
  229. this.currentPage = 1;
  230. this.count = 15;
  231. if (this.parentChannelId == "" || this.parentChannelId == 0) {
  232. this.beforeUrl = "/deviceList"
  233. }
  234. },
  235. currentChange: function (val) {
  236. this.currentPage = val;
  237. this.initData();
  238. },
  239. handleSizeChange: function (val) {
  240. this.count = val;
  241. this.getDeviceChannelList();
  242. },
  243. getDeviceChannelList: function () {
  244. let that = this;
  245. if (typeof (this.$route.params.deviceId) == "undefined") return;
  246. this.$axios.axios({
  247. method: 'get',
  248. url: `/api/device/query/devices/${this.$route.params.deviceId}/channels`,
  249. params: {
  250. page: that.currentPage,
  251. count: that.count,
  252. query: that.searchSrt,
  253. online: that.online,
  254. channelType: that.channelType
  255. }
  256. }).then(function (res) {
  257. if (res.data.code === 0) {
  258. let list = res.data.data.list;
  259. that.total = res.data.data.total;
  260. list.forEach(item => {
  261. // 是否为编辑状态
  262. item.isEdit = false;
  263. });
  264. that.deviceChannelList = list;
  265. // 防止出现表格错位
  266. that.$nextTick(() => {
  267. that.$refs.channelListTable.doLayout();
  268. })
  269. }
  270. }).catch(function (error) {
  271. console.log(error);
  272. });
  273. },
  274. showPtzControl(itemData) {
  275. let deviceId = this.deviceId;
  276. let channelId = itemData.channelId;
  277. this.isLoging = true;
  278. this.isLoging = false;
  279. this.$refs.ptzControl.showPtzControl(deviceId, channelId);
  280. },
  281. switchUsePs() {
  282. this.isUsePs = !this.isUsePs;
  283. },
  284. //通知设备上传媒体流
  285. async sendDevicePush(itemData) {
  286. let deviceId = this.deviceId;
  287. this.showPlayDialog = false;
  288. this.isLoging = true;
  289. let channelId = itemData.channelId;
  290. let isUsePs = this.isUsePs ? 1 : 0;
  291. let pushUrl = `/api/play/start/${deviceId}/${channelId}?isUsePs=${isUsePs}`
  292. console.log(pushUrl);
  293. console.log("通知设备推流1:" + deviceId + " : " + channelId);
  294. let [err, res] = await handle(this.$axios.axios({
  295. method: 'get',
  296. url: pushUrl
  297. }));
  298. if (err) {
  299. console.log(err);
  300. this.isLoging = false;
  301. this.$message.error(`请求失败,${err.message}`);
  302. return;
  303. }
  304. console.log(res);
  305. this.isLoging = false;
  306. let msg = ''
  307. if (res.data.code !== 0) {
  308. msg = this.$t(`video.pushFailCode.${res.data.code}`, { msg: res.data.msg })
  309. if (!msg) {
  310. msg = this.$t("notification.pushFail", { msg: res.data.msg })
  311. }
  312. console.log(msg)
  313. this.$message.error(msg);
  314. return;
  315. }
  316. setTimeout(() => {
  317. this.loadSnap[deviceId + channelId] = 0;
  318. this.getSnapErrorEvent(`${deviceId}_${channelId}`)
  319. }, 5000);
  320. this.showPlayDialog = true;
  321. itemData.streamId = res.data.data.stream;
  322. // 强制更新 this.streamInfo
  323. console.log(res.data.data)
  324. this.$set(this, 'streamInfo', res.data.data);
  325. this.$nextTick(() => {
  326. this.$set(this, 'streamInfo', res.data.data);
  327. })
  328. this.playChannelId = channelId;
  329. console.log("streamInfo:");
  330. console.log(this.streamInfo);
  331. setTimeout(() => {
  332. this.initData();
  333. }, 1000)
  334. },
  335. queryRecords: function (itemData) {
  336. let deviceId = this.deviceId;
  337. let channelId = itemData.channelId;
  338. this.$router.push(`/gbRecordDetail/${deviceId}/${channelId}`)
  339. },
  340. stopDevicePush: function (itemData) {
  341. var that = this;
  342. this.$axios.axios({
  343. method: 'get',
  344. url: '/api/play/stop/' + this.deviceId + "/" + itemData.channelId
  345. }).then(function (res) {
  346. that.initData();
  347. }).catch(function (error) {
  348. if (error.response.status === 402) { // 已经停止过
  349. that.initData();
  350. } else {
  351. console.log(error)
  352. }
  353. });
  354. },
  355. getSnap: function (row) {
  356. let url = (process.env.NODE_ENV === 'development' ? "debug" : "") + '/api/device/query/snap/' + row.deviceId + '/' + row.channelId
  357. return url
  358. },
  359. getBigSnap: function (row) {
  360. return [this.getSnap(row)]
  361. },
  362. getSnapErrorEvent: function (deviceId, channelId) {
  363. if (typeof (this.loadSnap[deviceId + channelId]) != "undefined") {
  364. console.log("下载截图" + this.loadSnap[deviceId + channelId])
  365. if (this.loadSnap[deviceId + channelId] > 5) {
  366. delete this.loadSnap[deviceId + channelId];
  367. return;
  368. }
  369. setTimeout(() => {
  370. let url = (process.env.NODE_ENV === 'development' ? "debug" : "") + '/api/device/query/snap/' + deviceId + '/' + channelId
  371. this.loadSnap[deviceId + channelId]++
  372. document.getElementById(deviceId + channelId).setAttribute("src", url + '?' + new Date().getTime())
  373. }, 1000)
  374. }
  375. },
  376. showDevice: function () {
  377. this.$router.push(this.beforeUrl).then(() => {
  378. this.initParam();
  379. this.initData();
  380. })
  381. },
  382. changeSubchannel(itemData) {
  383. this.beforeUrl = this.$router.currentRoute.path;
  384. var url = `/${this.$router.currentRoute.name}/${this.$router.currentRoute.params.deviceId}/${itemData.channelId}`
  385. this.$router.push(url).then(() => {
  386. this.searchSrt = "";
  387. this.channelType = "";
  388. this.online = "";
  389. this.initParam();
  390. this.initData();
  391. })
  392. },
  393. showSubchannels: function (channelId) {
  394. if (!this.showTree) {
  395. this.$axios.axios({
  396. method: 'get',
  397. url: `/api/device/query/sub_channels/${this.deviceId}/${this.parentChannelId}/channels`,
  398. params: {
  399. page: this.currentPage,
  400. count: this.count,
  401. query: this.searchSrt,
  402. online: this.online,
  403. channelType: this.channelType
  404. }
  405. }).then((res) => {
  406. if (res.data.code === 0) {
  407. this.total = res.data.data.total;
  408. this.deviceChannelList = res.data.data.list;
  409. // 防止出现表格错位
  410. this.$nextTick(() => {
  411. this.$refs.channelListTable.doLayout();
  412. })
  413. }
  414. }).catch(function (error) {
  415. console.log(error);
  416. });
  417. } else {
  418. this.$axios.axios({
  419. method: 'get',
  420. url: `/api/device/query/tree/channel/${this.deviceId}`,
  421. params: {
  422. parentId: this.parentChannelId,
  423. page: this.currentPage,
  424. count: this.count,
  425. }
  426. }).then((res) => {
  427. if (res.data.code === 0) {
  428. this.total = res.data.total;
  429. this.deviceChannelList = res.data.list;
  430. // 防止出现表格错位
  431. this.$nextTick(() => {
  432. this.$refs.channelListTable.doLayout();
  433. })
  434. }
  435. }).catch(function (error) {
  436. console.log(error);
  437. });
  438. }
  439. },
  440. search: function () {
  441. this.currentPage = 1;
  442. this.total = 0;
  443. this.initData();
  444. },
  445. updateChannel: function (row) {
  446. this.$axios.axios({
  447. method: 'post',
  448. url: `/api/device/query/channel/update/${this.deviceId}`,
  449. params: row
  450. }).then(function (res) {
  451. console.log(JSON.stringify(res));
  452. });
  453. },
  454. refresh: function () {
  455. this.initData();
  456. },
  457. switchTree: function () {
  458. this.showTree = true;
  459. this.deviceChannelList = [];
  460. this.parentChannelId = 0;
  461. this.currentPage = 1;
  462. },
  463. switchList: function () {
  464. this.showTree = false;
  465. this.deviceChannelList = [];
  466. this.parentChannelId = 0;
  467. this.currentPage = 1;
  468. this.initData();
  469. },
  470. treeNodeClickEvent: function (device, data, isCatalog) {
  471. console.log(device)
  472. if (!!!data.channelId) {
  473. this.parentChannelId = device.deviceId;
  474. } else {
  475. this.parentChannelId = data.channelId;
  476. }
  477. this.initData();
  478. },
  479. closeHandle() {
  480. // 刷新页面
  481. this.refresh();
  482. },
  483. saveEditName(row) {
  484. if (this.editName === "") {
  485. this.$message({
  486. message: '名称不能为空',
  487. type: 'warning'
  488. });
  489. return;
  490. }
  491. row.name = this.editName;
  492. this.updateChannel(row);
  493. row.isEdit = false;
  494. this.editName = "";
  495. this.$notify.info({
  496. title: 'Tips',
  497. message: '在编辑通道名称后,请前往设备编辑界面选择不跟随sip更新数据,用以持久化数据',
  498. })
  499. },
  500. exitEditName(row) {
  501. row.isEdit = false;
  502. this.editName = "";
  503. },
  504. toEditMode(row) {
  505. row.isEdit = true;
  506. this.editName = row.name;
  507. },
  508. // 播放器重新拉流
  509. rePushHandle(){
  510. // 获取对应的 item ;
  511. let channelItem = this.deviceChannelList.find(item => item.channelId === this.playChannelId)
  512. if (channelItem) {
  513. this.sendDevicePush(channelItem);
  514. } else {
  515. this.$message.error('重新拉流失败,无法找到对应的通道信息');
  516. }
  517. },
  518. sharePlayHandle(){
  519. this.$message.info("尝试开启分享中...");
  520. this.queryOpenShare(this.deviceId, this.playChannelId);
  521. },
  522. async queryOpenShare(deviceId, channelId){
  523. let err,res;
  524. let url = `/api/device/query/share/open`;
  525. url += `?deviceId=${deviceId}&channelId=${channelId}`;
  526. this.loading = true;
  527. [err, res] = await handle(this.$axios.get(url));
  528. this.loading = false;
  529. if(err){
  530. this.$message.error("开启分享失败,请稍后重试");
  531. console.error(err);
  532. return;
  533. }
  534. if(res.data.code !== 0){
  535. this.$message.error("开启分享失败,请稍后重试");
  536. return;
  537. }
  538. this.$message.success("开启分享成功");
  539. let shareCode = res.data.data;
  540. console.log(shareCode);
  541. this.shareUrl = `${window.location.origin}/share?shareCode=${shareCode}`;
  542. await this.copy(this.shareUrl);
  543. },
  544. async queryCloseShare(deviceId){
  545. let err,res;
  546. let url = `/api/device/query/share/close`;
  547. url += `?deviceId=${deviceId}`;
  548. [err, res] = await handle(this.$axios.get(url));
  549. this.loading = false;
  550. if(err){
  551. this.$message.error("关闭分享失败,请稍后重试");
  552. console.error(err);
  553. return;
  554. }
  555. if(res.data.code !== 0){
  556. this.$message.error("关闭分享失败,请稍后重试");
  557. return;
  558. }
  559. this.$message.success("关闭分享成功");
  560. }
  561. }
  562. };
  563. </script>
  564. <style>
  565. .videoList {
  566. display: flex;
  567. flex-wrap: wrap;
  568. align-content: flex-start;
  569. }
  570. .video-item {
  571. position: relative;
  572. width: 15rem;
  573. height: 10rem;
  574. margin-right: 1rem;
  575. background-color: #000000;
  576. }
  577. .video-item-img {
  578. position: absolute;
  579. top: 0;
  580. bottom: 0;
  581. left: 0;
  582. right: 0;
  583. margin: auto;
  584. width: 100%;
  585. height: 100%;
  586. }
  587. .video-item-img:after {
  588. content: "";
  589. display: inline-block;
  590. position: absolute;
  591. z-index: 2;
  592. top: 0;
  593. bottom: 0;
  594. left: 0;
  595. right: 0;
  596. margin: auto;
  597. width: 3rem;
  598. height: 3rem;
  599. background-image: url("../assets/loading.png");
  600. background-size: cover;
  601. background-color: #000000;
  602. }
  603. .video-item-title {
  604. position: absolute;
  605. bottom: 0;
  606. color: #000000;
  607. background-color: #ffffff;
  608. line-height: 1.5rem;
  609. padding: 0.3rem;
  610. width: 14.4rem;
  611. }
  612. </style>