DiskCam.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div>
  3. <el-row style="padding: 5px">
  4. <el-col :md="16" style="padding: 5px">
  5. <el-card v-if="camDetail !== null" class="box-card">
  6. <div slot="header" class="clearfix">
  7. <span>{{ camDetail.camName }}</span>
  8. </div>
  9. <div class="text item">
  10. <span v-if="camDetail.onLive">
  11. <video
  12. :src="camDetail.pullUrl"
  13. controls
  14. autoplay
  15. class="video"
  16. width="100%"
  17. height="480px"
  18. />
  19. </span>
  20. <span v-else>
  21. <video
  22. v-if="camRecordDetail !== null"
  23. :src="camRecordDetail.url"
  24. controls
  25. autoplay
  26. class="video"
  27. width="100%"
  28. height="480px"
  29. />
  30. <span v-else>
  31. 无实时监控(选择日期查看历史监控录像)
  32. </span>
  33. </span>
  34. </div>
  35. </el-card>
  36. <el-card v-else class="box-card">
  37. <div slot="header" class="clearfix">
  38. <span>选择摄像头查看监控</span>
  39. </div>
  40. </el-card>
  41. </el-col>
  42. <el-col :md="8" style="padding: 5px">
  43. <el-card class="box-card">
  44. <div slot="header" class="clearfix">
  45. <el-select
  46. v-model="selectedOption"
  47. style="margin: 5px;"
  48. clearable
  49. placeholder="选择摄像头"
  50. @change="onSelectChange"
  51. >
  52. <el-option v-for="item in selectOptions" :key="item.value" :label="item.label" :value="item.value" />
  53. </el-select>
  54. <el-button type="plain" icon="el-icon-date" style="margin: 5px" @click="onSelectDate">选择日期</el-button>
  55. <el-button type="plain" icon="el-icon-magic-stick" style="margin: 5px" @click="onButtonSubmit">提交</el-button>
  56. </div>
  57. <div class="text item">
  58. <span style="color: red">
  59. {{ getYearMonthDay(calendarDate) }} 的监控录像
  60. </span>
  61. <el-divider />
  62. <el-table
  63. :data="dataList"
  64. :show-header="true"
  65. style="width: 100%"
  66. >
  67. <el-table-column
  68. prop="startTime"
  69. label="开始时间"
  70. />
  71. <el-table-column
  72. prop="duration"
  73. label="时长(秒)"
  74. />
  75. <el-table-column label="操作">
  76. <template slot-scope="scope">
  77. <el-button
  78. size="mini"
  79. icon="el-icon-video-play"
  80. @click="handlePlay(scope.row.recordId)"
  81. >播放</el-button>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. </div>
  86. </el-card>
  87. </el-col>
  88. </el-row>
  89. <el-dialog
  90. title="日历"
  91. append-to-body
  92. :visible.sync="showCalenderDialog"
  93. width="50%"
  94. center
  95. >
  96. <div style="padding: 5px; text-align: center">
  97. <span>
  98. <span style="color: red">红色 ✔</span>标记的日期表示当天有监控录像
  99. </span>
  100. <el-calendar v-model="calendarDate">
  101. <div
  102. slot="dateCell"
  103. slot-scope="{ date, data }"
  104. @click="handleCellClick(date, data)"
  105. >
  106. <p v-if="dealMyDate(data.day)" style="color: red">
  107. {{ data.day.split("-").slice(2).join() }} {{ '✔' }}
  108. </p>
  109. <p v-else>{{ data.day.split("-").slice(2).join() }}</p>
  110. </div>
  111. </el-calendar>
  112. </div>
  113. </el-dialog>
  114. </div>
  115. </template>
  116. <script>
  117. import { getCamDetail, getCamKeyValue, getRecordByMonth, getRecordUrl, submitActivity } from '@/api/disk'
  118. export default {
  119. name: 'DiskCam',
  120. data() {
  121. return {
  122. selectOptions: [],
  123. selectedOption: '',
  124. calendarDate: new Date(),
  125. dateMap: new Map(),
  126. query: {
  127. camId: '',
  128. yearMonth: '',
  129. yearMonthDay: ''
  130. },
  131. dataList: [],
  132. showCalenderDialog: false,
  133. camDetail: null,
  134. camRecordDetail: null
  135. }
  136. },
  137. watch: {
  138. $route() {
  139. this.$router.go()
  140. },
  141. calendarDate: {
  142. handler(newValue, oldValue) {
  143. const oldMonth = this.getYearMonth(oldValue)
  144. const newMonth = this.getYearMonth(newValue)
  145. if (oldMonth !== newMonth) {
  146. this.query.yearMonth = this.getYearMonth(newValue)
  147. getRecordByMonth(this.query).then(resp => {
  148. if (resp.code === 0) {
  149. this.dateMap.clear()
  150. for (const item of resp.data) {
  151. const date1 = new Date(item)
  152. const dayStr = this.getYearMonthDay(date1)
  153. this.dateMap.set(dayStr, date1)
  154. }
  155. // 对 calendarDate 赋值重新渲染日历, 目的是调用 dealMyDate 处理当月的日期
  156. this.calendarDate = new Date(newMonth)
  157. }
  158. }).catch(error => {
  159. this.$message.error(error.message)
  160. })
  161. }
  162. }
  163. }
  164. },
  165. created() {
  166. document.title = '监控'
  167. getCamKeyValue().then(resp => {
  168. if (resp.code === 0) {
  169. this.selectOptions = resp.data
  170. }
  171. })
  172. },
  173. methods: {
  174. getData() {
  175. getCamDetail(this.query).then(resp => {
  176. if (resp.code === 0) {
  177. this.camDetail = resp.data
  178. }
  179. })
  180. },
  181. onSelectChange() {
  182. if (this.selectedOption === '') {
  183. this.query.camId = ''
  184. this.query.yearMonth = ''
  185. this.query.yearMonthDay = ''
  186. this.camDetail = null
  187. this.camRecordDetail = null
  188. return
  189. }
  190. this.query.camId = this.selectedOption
  191. this.query.yearMonth = ''
  192. this.query.yearMonthDay = ''
  193. this.getData()
  194. },
  195. handleCellClick(date, data) {
  196. this.showCalenderDialog = false
  197. this.query.yearMonthDay = this.getYearMonthDay(date)
  198. getCamDetail(this.query).then(resp => {
  199. if (resp.code === 0) {
  200. const respData = resp.data
  201. this.camDetail = respData
  202. this.dataList = respData.dayRecords
  203. }
  204. })
  205. },
  206. // 渲染日历时会处理每个日期
  207. dealMyDate(val) {
  208. return this.dateMap.get(val) !== undefined
  209. },
  210. getYearMonth(date) {
  211. const year = date.getFullYear().toString().padStart(4, '0')
  212. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  213. // const day = date.getDate().toString().padStart(2, '0')
  214. // const hour = date.getHours().toString().padStart(2, '0')
  215. // const minute = date.getMinutes().toString().padStart(2, '0')
  216. // const second = date.getSeconds().toString().padStart(2, '0')
  217. // 2023-02-16 08:25:05
  218. // console.log(`${year}-${month}-${day} ${hour}:${minute}:${second}`)
  219. return year + '-' + month
  220. },
  221. getYearMonthDay(date) {
  222. const year = date.getFullYear().toString().padStart(4, '0')
  223. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  224. const day = date.getDate().toString().padStart(2, '0')
  225. return year + '-' + month + '-' + day
  226. },
  227. handlePlay(recordId) {
  228. getRecordUrl(recordId).then(resp => {
  229. if (resp.code === 0) {
  230. this.camRecordDetail = resp.data
  231. } else {
  232. this.$message.error(resp.msg)
  233. }
  234. })
  235. },
  236. onSelectDate() {
  237. if (this.selectedOption === '') {
  238. this.$message.info('请先选择摄像头')
  239. } else {
  240. this.showCalenderDialog = true
  241. }
  242. },
  243. onButtonSubmit() {
  244. this.$confirm('确认提交?', '提示', {
  245. confirmButtonText: '确定',
  246. cancelButtonText: '取消',
  247. type: 'warning'
  248. }).then(() => {
  249. submitActivity().then(resp => {
  250. this.$message.info(resp.msg)
  251. }).catch(error => {
  252. this.$message.error(error.message)
  253. })
  254. }).catch(() => {
  255. this.$message({
  256. type: 'info',
  257. message: '已取消'
  258. })
  259. })
  260. }
  261. }
  262. }
  263. </script>
  264. <style>
  265. </style>