CloudRecordDetail.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <template>
  2. <div id="recordDetail">
  3. <el-container>
  4. <el-aside width="260px">
  5. <div class="record-list-box-box">
  6. <div style="margin-top: 20px">
  7. <el-date-picker size="mini" style="width: 160px" v-model="chooseDate" :picker-options="pickerOptions" type="date" value-format="yyyy-MM-dd" placeholder="日期" @change="dateChange()"></el-date-picker>
  8. <el-button size="mini" type="primary" icon="fa fa-cloud-download" style="margin: auto; margin-left: 12px " title="裁剪合并" @click="drawerOpen"></el-button>
  9. </div>
  10. <div class="record-list-box" :style="recordListStyle">
  11. <ul v-if="detailFiles.length >0" class="infinite-list record-list" v-infinite-scroll="infiniteScroll" >
  12. <li v-for="(item,index) in detailFiles" :key="index" class="infinite-list-item record-list-item" >
  13. <el-tag v-if="choosedFile != item" @click="chooseFile(item)">
  14. <i class="el-icon-video-camera" ></i>
  15. {{ item.substring(0,17)}}
  16. </el-tag>
  17. <el-tag type="danger" v-if="choosedFile == item">
  18. <i class="el-icon-video-camera" ></i>
  19. {{ item.substring(0,17)}}
  20. </el-tag>
  21. <a class="el-icon-download" style="color: #409EFF;font-weight: 600;margin-left: 10px;" :href="`${getFileBasePath()}/download.html?url=download/${recordFile.app}/${recordFile.stream}/${chooseDate}/${item}`" target="_blank" />
  22. </li>
  23. </ul>
  24. </div>
  25. <div v-if="detailFiles.length ==0" class="record-list-no-val" >暂无数据</div>
  26. </div>
  27. </el-aside>
  28. <el-main style="padding: 22px">
  29. <div class="playBox" :style="playerStyle">
  30. <player ref="recordVideoPlayer" :videoUrl="videoUrl" :height="true" style="width: 100%" ></player>
  31. </div>
  32. <div class="player-option-box" >
  33. <el-slider
  34. class="playtime-slider"
  35. v-model="playTime"
  36. id="playtimeSlider"
  37. :disabled="detailFiles.length === 0"
  38. :min="sliderMIn"
  39. :max="sliderMax"
  40. :format-tooltip="playTimeFormat"
  41. @change="playTimeChange"
  42. :marks="playTimeSliderMarks">
  43. </el-slider>
  44. <div class="slider-val-box">
  45. <div class="slider-val" v-for="(item,index) of detailFiles" :key="index" :style="'width:' + getDataWidth(item) + '%; left:' + getDataLeft(item) + '%'"></div>
  46. </div>
  47. </div>
  48. </el-main>
  49. </el-container>
  50. <el-drawer
  51. title="录像下载"
  52. :visible.sync="drawer"
  53. :direction="direction"
  54. :before-close="drawerClose">
  55. <div class="drawer-box">
  56. <el-button icon="el-icon-plus" size="mini" type="primary" @click="addTask"></el-button>
  57. <el-tabs type="border-card" style="height: 100%" v-model="tabVal" @tab-click="tabClick">
  58. <el-tab-pane name="running">
  59. <span slot="label"><i class="el-icon-scissors"></i>进行中</span>
  60. <ul class="task-list">
  61. <li class="task-list-item" v-for="(item,index) in taskListForRuning" :key="index">
  62. <div class="task-list-item-box">
  63. <span>{{ item.startTime.substr(10) }}-{{item.endTime.substr(10)}}</span>
  64. <el-progress :percentage="(parseFloat(item.percentage)*100).toFixed(1)"></el-progress>
  65. </div>
  66. </li>
  67. </ul>
  68. </el-tab-pane>
  69. <el-tab-pane name="ended">
  70. <span slot="label"><i class="el-icon-finished"></i>已完成</span>
  71. <ul class="task-list">
  72. <li class="task-list-item" v-for="(item, index) in taskListEnded" :key="index">
  73. <div class="task-list-item-box" style="height: 2rem;line-height: 2rem;">
  74. <span>{{ item.startTime.substr(10) }}-{{item.endTime.substr(10)}}</span>
  75. <a class="el-icon-download download-btn" :href="getFileBasePath() + '/download.html?url=download/' + item.recordFile" target="_blank">
  76. </a>
  77. </div>
  78. </li>
  79. </ul>
  80. </el-tab-pane>
  81. </el-tabs>
  82. </div>
  83. </el-drawer>
  84. <el-dialog title="选择时间段" :visible.sync="showTaskBox">
  85. <el-date-picker
  86. type="datetimerange"
  87. v-model="taskTimeRange"
  88. range-separator="至"
  89. start-placeholder="开始时间"
  90. end-placeholder="结束时间"
  91. format="HH:mm:ss"
  92. placeholder="选择时间范围">
  93. </el-date-picker>
  94. <el-button size="mini" type="primary" @click="addTaskToServer">确认</el-button>
  95. </el-dialog>
  96. </div>
  97. </template>
  98. <script>
  99. // TODO 根据查询的时间列表设置滑轨的最大值与最小值,
  100. import uiHeader from '../layout/UiHeader.vue'
  101. import player from './dialog/easyPlayer.vue'
  102. import moment from 'moment'
  103. import axios from "axios";
  104. export default {
  105. name: 'app',
  106. components: {
  107. uiHeader, player
  108. },
  109. props: ['recordFile', 'mediaServerId', 'dateFiles'],
  110. data() {
  111. return {
  112. dateFilesObj: [],
  113. detailFiles: [],
  114. chooseDate: null,
  115. videoUrl: null,
  116. choosedFile: null,
  117. queryDate: new Date(),
  118. currentPage: 1,
  119. count: 1000000, // TODO 分页导致滑轨视频有效值无法获取完全
  120. total: 0,
  121. direction: "ltr",
  122. drawer: false,
  123. showTaskBox: false,
  124. taskTimeRange: [],
  125. taskListEnded: [],
  126. taskListForRuning: [],
  127. sliderMIn: 0,
  128. sliderMax: 86400,
  129. autoPlay: true,
  130. taskUpdate: null,
  131. tabVal: "running",
  132. recordListStyle: {
  133. height: this.winHeight + "px",
  134. overflow: "auto",
  135. margin: "10px auto 10px auto"
  136. },
  137. playerStyle: {
  138. "margin": "auto",
  139. "margin-bottom": "20px",
  140. "height": this.winHeight + "px",
  141. },
  142. timeFormat:'00:00:00',
  143. winHeight: window.innerHeight - 240,
  144. playTime: 0,
  145. playTimeSliderMarks: {
  146. 0: "00:00",
  147. 3600: "01:00",
  148. 7200: "02:00",
  149. 10800: "03:00",
  150. 14400: "04:00",
  151. 18000: "05:00",
  152. 21600: "06:00",
  153. 25200: "07:00",
  154. 28800: "08:00",
  155. 32400: "09:00",
  156. 36000: "10:00",
  157. 39600: "11:00",
  158. 43200: "12:00",
  159. 46800: "13:00",
  160. 50400: "14:00",
  161. 54000: "15:00",
  162. 57600: "16:00",
  163. 61200: "17:00",
  164. 64800: "18:00",
  165. 68400: "19:00",
  166. 72000: "20:00",
  167. 75600: "21:00",
  168. 79200: "22:00",
  169. 82800: "23:00",
  170. 86400: "24:00",
  171. },
  172. pickerOptions:{
  173. cellClassName:(date) =>{
  174. // 通过显示一个点标识这一天有录像
  175. let time = moment(date).format('YYYY-MM-DD')
  176. if (this.dateFilesObj[time]){
  177. return "data-picker-true"
  178. }else {
  179. return "data-picker-false"
  180. }
  181. }
  182. }
  183. };
  184. },
  185. computed: {
  186. },
  187. mounted() {
  188. this.recordListStyle.height = this.winHeight + "px";
  189. this.playerStyle["height"] = this.winHeight + "px";
  190. // 查询当年有视频的日期
  191. this.getDateInYear(()=>{
  192. if (Object.values(this.dateFilesObj).length > 0){
  193. this.chooseDate = Object.values(this.dateFilesObj)[Object.values(this.dateFilesObj).length -1];
  194. this.dateChange();
  195. }
  196. })
  197. },
  198. destroyed() {
  199. this.$destroy('recordVideoPlayer');
  200. },
  201. methods: {
  202. dateChange(){
  203. this.playTime = 0;
  204. this.detailFiles = [];
  205. this.currentPage = 1;
  206. this.sliderMIn= 0;
  207. this.sliderMax= 86400;
  208. let chooseFullDate = new Date(this.chooseDate +" " + this.timeFormat);
  209. if (chooseFullDate.getFullYear() !== this.queryDate.getFullYear()
  210. || chooseFullDate.getMonth() !== this.queryDate.getMonth()){
  211. // this.getDateInYear()
  212. }
  213. this.queryRecordDetails(()=>{
  214. if (this.detailFiles.length > 0){
  215. let timeForFile = this.getTimeForFile(this.detailFiles[0]);
  216. let lastTimeForFile = this.getTimeForFile(this.detailFiles[this.detailFiles.length - 1]);
  217. let timeNum = timeForFile[0].getTime() - new Date(this.chooseDate + " " + this.timeFormat).getTime()
  218. let lastTimeNum = lastTimeForFile[1].getTime() - new Date(this.chooseDate + " " + this.timeFormat).getTime()
  219. this.playTime = parseInt(timeNum/1000)
  220. this.sliderMIn = parseInt(timeNum/1000 - timeNum/1000%(60*60))
  221. this.sliderMax = parseInt(lastTimeNum/1000 - lastTimeNum/1000%(60*60)) + 60*60
  222. }
  223. });
  224. },
  225. infiniteScroll(){
  226. if (this.total > this.detailFiles.length) {
  227. this.currentPage ++;
  228. this.queryRecordDetails();
  229. }
  230. },
  231. queryRecordDetails: function (callback){
  232. let that = this;
  233. that.$axios({
  234. method: 'get',
  235. url:`/record_proxy/${that.mediaServerId}/api/record/file/list`,
  236. params: {
  237. app: that.recordFile.app,
  238. stream: that.recordFile.stream,
  239. startTime: that.chooseDate + " 00:00:00",
  240. endTime: that.chooseDate + " 23:59:59",
  241. page: that.currentPage,
  242. count: that.count
  243. }
  244. }).then(function (res) {
  245. if (res.data.code === 0) {
  246. that.total = res.data.data.total;
  247. that.detailFiles = that.detailFiles.concat(res.data.data.list);
  248. }
  249. that.loading = false;
  250. if (callback) callback();
  251. }).catch(function (error) {
  252. console.log(error);
  253. that.loading = false;
  254. });
  255. },
  256. chooseFile(file){
  257. this.choosedFile = file;
  258. if (file == null) {
  259. this.videoUrl = "";
  260. }else {
  261. this.videoUrl = `${this.getFileBasePath()}/download/${this.recordFile.app}/${this.recordFile.stream}/${this.chooseDate}/${this.choosedFile}`
  262. console.log(this.videoUrl)
  263. }
  264. },
  265. getFileBasePath(){
  266. let basePath = ""
  267. if (axios.defaults.baseURL.startsWith("http")) {
  268. basePath = `${axios.defaults.baseURL}/record_proxy/${this.mediaServerId}`
  269. }else {
  270. basePath = `${window.location.origin}${axios.defaults.baseURL}/record_proxy/${this.mediaServerId}`
  271. }
  272. return basePath;
  273. },
  274. getDataWidth(item){
  275. let timeForFile = this.getTimeForFile(item);
  276. let result = (timeForFile[2])/((this.sliderMax - this.sliderMIn)*1000)
  277. return result*100
  278. },
  279. getDataLeft(item){
  280. let timeForFile = this.getTimeForFile(item);
  281. let differenceTime = timeForFile[0].getTime() - new Date(this.chooseDate + " " + this.timeFormat).getTime()
  282. return parseFloat((differenceTime - this.sliderMIn * 1000)/((this.sliderMax - this.sliderMIn)*1000))*100 ;
  283. },
  284. playTimeChange(val){
  285. let minTime = this.getTimeForFile(this.detailFiles[0])[0]
  286. let maxTime = this.getTimeForFile(this.detailFiles[this.detailFiles.length - 1])[1];
  287. this.chooseFile(null);
  288. let timeMilli = new Date(this.chooseDate + " " + this.timeFormat).getTime() + val*1000
  289. if (timeMilli >= minTime.getTime() && timeMilli <= maxTime.getTime()){
  290. for (let i = 0; i < this.detailFiles.length; i++) {
  291. let timeForFile = this.getTimeForFile(this.detailFiles[i]);
  292. if (timeMilli >= timeForFile[0].getTime() && timeMilli <= timeForFile[1].getTime()){
  293. // TODO 当前未按照实际时间偏移,仅仅是找到对应的文静播放
  294. this.chooseFile(this.detailFiles[i])
  295. return;
  296. }
  297. }
  298. }
  299. },
  300. getTimeForFile(file){
  301. let timeStr = file.substring(0,17);
  302. if(timeStr.indexOf("~") > 0){
  303. timeStr = timeStr.replaceAll("-",":")
  304. }
  305. let timeArr = timeStr.split("~");
  306. let starTime = new Date(this.chooseDate + " " + timeArr[0]);
  307. let endTime = new Date(this.chooseDate + " " + timeArr[1]);
  308. if(this.checkIsOver24h(starTime,endTime)){
  309. endTime = new Date(this.chooseDate + " " + "23:59:59");
  310. }
  311. return [starTime, endTime, endTime.getTime() - starTime.getTime()];
  312. },
  313. checkIsOver24h(starTime,endTime){
  314. return starTime > endTime;
  315. },
  316. playTimeFormat(val){
  317. let h = parseInt(val/3600);
  318. let m = parseInt((val - h*3600)/60);
  319. let s = parseInt(val - h*3600 - m*60);
  320. let hStr = h;
  321. let mStr = m;
  322. let sStr = s;
  323. if (h < 10) {
  324. hStr = "0" + hStr;
  325. }
  326. if (m < 10) {
  327. mStr = "0" + mStr;s
  328. }
  329. if (s < 10) {
  330. sStr = "0" + sStr;
  331. }
  332. return hStr + ":" + mStr + ":" + sStr
  333. },
  334. deleteRecord(){
  335. // TODO
  336. let that = this;
  337. this.$axios({
  338. method: 'delete',
  339. url:`/record_proxy/${that.mediaServerId}/api/record/delete`,
  340. params: {
  341. page: that.currentPage,
  342. count: that.count
  343. }
  344. }).then(function (res) {
  345. if (res.data.code === 0) {
  346. that.total = res.data.data.total;
  347. that.recordList = res.data.data.list;
  348. }
  349. }).catch(function (error) {
  350. console.log(error);
  351. });
  352. },
  353. getDateInYear(callback){
  354. let that = this;
  355. that.dateFilesObj = {};
  356. this.$axios({
  357. method: 'get',
  358. url:`/record_proxy/${that.mediaServerId}/api/record/date/list`,
  359. params: {
  360. app: that.recordFile.app,
  361. stream: that.recordFile.stream
  362. }
  363. }).then(function (res) {
  364. if (res.data.code === 0) {
  365. if (res.data.data.length > 0) {
  366. for (let i = 0; i < res.data.data.length; i++) {
  367. that.dateFilesObj[res.data.data[i]] = res.data.data[i]
  368. }
  369. console.log(that.dateFilesObj)
  370. }
  371. }
  372. if(callback)callback();
  373. }).catch(function (error) {
  374. console.log(error);
  375. });
  376. },
  377. tabClick(){
  378. this.getTaskList(this.tabVal === "ended")
  379. },
  380. drawerClose(){
  381. this.drawer = false;
  382. if (this.taskUpdate != null) {
  383. window.clearInterval(this.taskUpdate)
  384. }
  385. },
  386. drawerOpen(){
  387. this.drawer = true;
  388. if (this.taskUpdate != null) {
  389. window.clearInterval(this.taskUpdate)
  390. }
  391. this.taskUpdate = setInterval(()=>{
  392. this.getTaskList(this.tabVal === "ended")
  393. }, 1000)
  394. },
  395. addTask(){
  396. this.showTaskBox = true;
  397. let startTimeStr = this.chooseDate + " " + this.detailFiles[0].substring(0,8);
  398. let endTimeStr = this.chooseDate + " " + this.detailFiles[this.detailFiles.length - 1].substring(9,17);
  399. this.taskTimeRange[0] = new Date(startTimeStr)
  400. this.taskTimeRange[1] = new Date(endTimeStr)
  401. },
  402. addTaskToServer(){
  403. let that = this;
  404. this.$axios({
  405. method: 'get',
  406. url:`/record_proxy/${that.mediaServerId}/api/record/file/download/task/add`,
  407. params: {
  408. app: that.recordFile.app,
  409. stream: that.recordFile.stream,
  410. startTime: moment(this.taskTimeRange[0]).format('YYYY-MM-DD HH:mm:ss'),
  411. endTime: moment(this.taskTimeRange[1]).format('YYYY-MM-DD HH:mm:ss'),
  412. }
  413. }).then(function (res) {
  414. if (res.data.code === 0 ) {
  415. that.showTaskBox = false
  416. that.getTaskList(false);
  417. }else {
  418. that.$message.error(res.data.msg);
  419. }
  420. }).catch(function (error) {
  421. console.log(error);
  422. });
  423. },
  424. handleTabClick() {
  425. this.getTaskList(this.tabVal === "ended")
  426. },
  427. getTaskList(isEnd){
  428. let that = this;
  429. this.$axios({
  430. method: 'get',
  431. url:`/record_proxy/${that.mediaServerId}/api/record/file/download/task/list`,
  432. params: {
  433. isEnd: isEnd,
  434. }
  435. }).then(function (res) {
  436. if (res.data.code === 0) {
  437. if (isEnd){
  438. that.taskListEnded = res.data.data;
  439. }else {
  440. that.taskListForRuning = res.data.data;
  441. }
  442. }
  443. }).catch(function (error) {
  444. console.log(error);
  445. });
  446. },
  447. goBack(){
  448. this.$router.push('/cloudRecord');
  449. }
  450. }
  451. };
  452. </script>
  453. <style>
  454. .el-slider__runway {
  455. background-color:rgba(206, 206, 206, 0.47) !important;
  456. }
  457. .el-slider__bar {
  458. background-color: rgba(153, 153, 153, 0) !important;
  459. }
  460. .playtime-slider {
  461. position: relative;
  462. z-index: 100;
  463. }
  464. .data-picker-true{
  465. }
  466. .data-picker-true:after{
  467. content: "";
  468. position: absolute;
  469. width: 4px;
  470. height: 4px;
  471. background-color: #606060;
  472. border-radius: 4px;
  473. left: 45%;
  474. top: 74%;
  475. }
  476. .data-picker-false{
  477. }
  478. .slider-val-box{
  479. height: 6px;
  480. position: relative;
  481. top: -22px;
  482. }
  483. .slider-val{
  484. height: 6px;
  485. background-color: #007CFF;
  486. position: absolute;
  487. }
  488. .record-list-box-box{
  489. width: 250px;
  490. float: left;
  491. }
  492. .record-list-box{
  493. overflow: auto;
  494. width: 220px;
  495. list-style: none;
  496. padding: 0;
  497. margin: 0;
  498. margin-top: 0px;
  499. padding: 1rem 0;
  500. background-color: #FFF;
  501. margin-top: 10px;
  502. }
  503. .record-list{
  504. list-style: none;
  505. padding: 0;
  506. margin: 0;
  507. background-color: #FFF;
  508. }
  509. .record-list-no-val {
  510. position: absolute;
  511. color: #9f9f9f;
  512. top: 50%;
  513. left: 110px;
  514. }
  515. .record-list-item{
  516. padding: 0;
  517. margin: 0;
  518. margin: 0.5rem 0;
  519. cursor: pointer;
  520. }
  521. .record-list-option {
  522. width: 10px;
  523. float: left;
  524. margin-top: 39px;
  525. }
  526. .drawer-box{
  527. height: 100%;
  528. }
  529. .task-list{
  530. list-style: none;
  531. padding: 0;
  532. margin: 0;
  533. background-color: #FFF;
  534. }
  535. .task-list-item{
  536. padding: 0;
  537. margin: 0;
  538. margin: 1.5rem 0;
  539. }
  540. .task-list-item-box{
  541. text-align: left;
  542. font-size: 13px;
  543. color: #555;
  544. }
  545. .download-btn{
  546. display: inline-block;
  547. line-height: 1;
  548. white-space: nowrap;
  549. cursor: pointer;
  550. background: #FFF;
  551. background-color: rgb(255, 255, 255);
  552. border: 1px solid #DCDFE6;
  553. border-top-color: rgb(220, 223, 230);
  554. border-right-color: rgb(220, 223, 230);
  555. border-bottom-color: rgb(220, 223, 230);
  556. border-left-color: rgb(220, 223, 230);
  557. border-top-color: rgb(220, 223, 230);
  558. border-right-color: rgb(220, 223, 230);
  559. border-bottom-color: rgb(220, 223, 230);
  560. border-left-color: rgb(220, 223, 230);
  561. -webkit-appearance: none;
  562. text-align: center;
  563. -webkit-box-sizing: border-box;
  564. box-sizing: border-box;
  565. outline: 0;
  566. margin: 0;
  567. -webkit-transition: .1s;
  568. transition: .1s;
  569. font-weight: 500;
  570. padding: 7px 14px;
  571. font-size: 0.875rem;
  572. border-radius: 4px;
  573. font-size: 0.75rem;
  574. border-radius: 3px;
  575. color: #FFF;
  576. background-color: #409EFF;
  577. border-color: #409EFF;
  578. float: right;
  579. }
  580. .download-btn:hover{
  581. background: #66b1ff;
  582. border-color: #66b1ff;
  583. color: #FFF;
  584. }
  585. .time-box{
  586. }
  587. </style>