MyCalendar1.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <el-row class="movie-list">
  3. <el-row v-for="(item, index) in [1, 2, 3, 4]" :key="index">
  4. <el-col v-for="(item, index) in [1, 2, 3]" :key="index" :md="8">
  5. <el-row v-if="showCalender" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  6. <el-card class="box-card">
  7. <div class="text item">
  8. <el-calendar v-model="calendarDate">
  9. <div
  10. slot="dateCell"
  11. slot-scope="{ date, data }"
  12. @click="handleCellClick(date, data)"
  13. >
  14. <p>{{ data.day.split("-").slice(2).join() }}</p>
  15. <p v-if="dealMyDate(data.day)" class="blue budge" />
  16. </div>
  17. </el-calendar>
  18. </div>
  19. </el-card>
  20. </el-row>
  21. </el-col>
  22. </el-row>
  23. </el-row>
  24. </template>
  25. <script>
  26. import {
  27. getCamDetail,
  28. getCamList,
  29. getCamRecord,
  30. getCamRecordByDay,
  31. getCamRecordByMonth,
  32. getLatestRecord
  33. } from '@/api/cam'
  34. export default {
  35. name: 'MyCalendar',
  36. data() {
  37. return {
  38. user: {
  39. userId: 1,
  40. screenName: '浩',
  41. avatarUrl: '//pic1.zhimg.com/v2-c755e7ec5510b0638c2d1bead712544a_r.jpg',
  42. following: 1024,
  43. follower: 1024
  44. },
  45. camId: null,
  46. calendarDate: new Date(),
  47. dateMap: new Map(),
  48. showCalender: true,
  49. showRecordList: false,
  50. camList: [],
  51. cam: null,
  52. camDetail: null,
  53. form: {},
  54. recordList: [],
  55. camRecord: null
  56. }
  57. },
  58. watch: {
  59. $route() {
  60. this.$router.go()
  61. },
  62. calendarDate: {
  63. handler(newValue, oldValue) {
  64. const oldMonth = this.getYearMonth(oldValue)
  65. const newMonth = this.getYearMonth(newValue)
  66. if (oldMonth !== newMonth) {
  67. this.showCalender = false
  68. this.form.yearMonth = this.getYearMonth(newValue)
  69. getCamRecordByMonth(this.form).then(resp => {
  70. if (resp.code === 0) {
  71. this.dateMap.clear()
  72. for (const item of resp.data) {
  73. const date1 = new Date(item)
  74. const dayStr = this.getYearMonthDay(date1)
  75. this.dateMap.set(dayStr, date1)
  76. }
  77. }
  78. this.showCalender = true
  79. })
  80. }
  81. }
  82. }
  83. },
  84. created() {
  85. document.title = '我的日历'
  86. const camId = this.$route.params.camId
  87. this.camId = camId
  88. getCamDetail(camId).then(resp => {
  89. if (resp.code === 0) {
  90. var camDetail = resp.data
  91. this.camDetail = camDetail
  92. }
  93. })
  94. this.form.camId = camId
  95. this.form.yearMonth = this.getYearMonth(new Date())
  96. getCamRecordByMonth(this.form).then(resp => {
  97. if (resp.code === 0) {
  98. this.dateMap.clear()
  99. for (const item of resp.data) {
  100. const date1 = new Date(item)
  101. const dayStr = this.getYearMonthDay(date1)
  102. this.dateMap.set(dayStr, date1)
  103. }
  104. this.showCalender = true
  105. }
  106. })
  107. getCamList().then(resp => {
  108. if (resp.code === 0) {
  109. this.camList = resp.data
  110. }
  111. })
  112. // const today = new Date()
  113. getLatestRecord(camId).then(resp => {
  114. if (resp.code === 0) {
  115. const respData = resp.data
  116. this.initMp4Player(respData.coverUrl, respData.videoUrl)
  117. }
  118. }).catch(error => {
  119. console.log(error)
  120. var ele = document.querySelector('#dplayer')
  121. ele.innerHTML = '<h5>没有今天的录像记录</h5>'
  122. })
  123. },
  124. methods: {
  125. onSelect(value) {
  126. const path = '/cam/record/' + value
  127. if (this.$route.path === path) {
  128. this.$router.go(0)
  129. return
  130. }
  131. this.$router.push(path)
  132. },
  133. handleCellClick(date, data) {
  134. this.form.yearMonthDay = this.getYearMonthDay(date)
  135. },
  136. dealMyDate(val) {
  137. let res = ''
  138. if (this.dateMap.get(val) != null) {
  139. res = true
  140. }
  141. return res
  142. },
  143. getYearMonth(date) {
  144. const year = date.getFullYear().toString().padStart(4, '0')
  145. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  146. // const day = date.getDate().toString().padStart(2, '0')
  147. // const hour = date.getHours().toString().padStart(2, '0')
  148. // const minute = date.getMinutes().toString().padStart(2, '0')
  149. // const second = date.getSeconds().toString().padStart(2, '0')
  150. // 2023-02-16 08:25:05
  151. // console.log(`${year}-${month}-${day} ${hour}:${minute}:${second}`)
  152. return year + '-' + month
  153. },
  154. getYearMonthDay(date) {
  155. const year = date.getFullYear().toString().padStart(4, '0')
  156. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  157. const day = date.getDate().toString().padStart(2, '0')
  158. return year + '-' + month + '-' + day
  159. },
  160. onClickRow(row) {
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped>
  166. .clearfix:before,
  167. .clearfix:after {
  168. display: table;
  169. content: "";
  170. }
  171. .clearfix:after {
  172. clear: both;
  173. }
  174. .is-selected {
  175. color: #1989FA;
  176. }
  177. ::v-deep.el-calendar{
  178. height: calc(100% - 35px);
  179. }
  180. ::v-deep.el-calendar .el-calendar__body{
  181. padding-bottom: 16px;
  182. height: calc(100% - 80px);
  183. }
  184. ::v-deep.el-calendar .el-calendar-table{
  185. height: 100%;
  186. }
  187. .el-backtop, ::v-deep.el-calendar .el-calendar-table td.is-today .date{
  188. background: #DCE9FF;
  189. color: rgba(0,0,0,0.45);
  190. }
  191. .el-backtop, ::v-deep.el-calendar .el-calendar-table .date:hover{
  192. background: #DCE9FF;
  193. color: rgba(0,0,0,0.45);
  194. }
  195. ::v-deep.el-calendar .el-calendar-table .el-calendar-day:hover{
  196. background: none;
  197. }
  198. ::v-deep.el-calendar .el-calendar-table td.is-selected{
  199. background: none;
  200. }
  201. ::v-deep.el-calendar .el-calendar-table td.is-selected .date{
  202. background: #5E97F9;
  203. box-shadow: 0px 4px 7px 0px rgba(113,208,255,0.5);
  204. color: #fff;
  205. }
  206. ::v-deep.el-calendar .el-calendar__button-group{
  207. display: none;
  208. }
  209. ::v-deep.el-calendar .el-calendar__title{
  210. margin: 0 auto;
  211. }
  212. ::v-deep.el-calendar .el-calendar-table .el-calendar-day{
  213. position: relative;
  214. }
  215. </style>