d-rili.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view>
  3. <!-- -->
  4. <view class="riliWrapper">
  5. <view class="riliWrapperBox">
  6. <!-- 日历 -->
  7. <view class="signWrapperCalendar" v-if="true">
  8. <view class="signWrapperCalendarBox">
  9. <!-- -->
  10. <swiper @change="_onClickSlideApi" duration="200" :current="slideDataListIndex" circular style="height:550rpx">
  11. <swiper-item class="swiper-item" v-for="(calendar,indexa) in 3" :key="indexa" >
  12. <view class="signWrapperCalendarBoxTop" >
  13. {{year}}年{{month<10?'0'+month:month}}月
  14. </view>
  15. <view class="signWrapperCalendarBoxCenter">
  16. <view class="signWrapperCalendarBoxCenterBox">
  17. <view class="signWrapperCalendarBoxCenterBoxTop">
  18. <div class="week-number">
  19. <span v-for="(item,index) in weekList" :style="{color:(index==0||index==weekList.length-1)&&themeColor}" :key="index">{{item}}</span>
  20. </div>
  21. </view>
  22. <view class="signWrapperCalendarBoxCenterBoxFooter">
  23. <view class="each-day" v-for="(dayTime,idx) in dayList" :key="idx" >
  24. <view :class="dayTime!=day+2 ?'eachDayBox':'eachDayBoxCheck'" v-if="day">
  25. <view class="eachDayBoxBox" :style="dayTime==day?'border-bottom: 1rpx solid #4E6EF2;':''">
  26. {{dayTime?dayTime:''}}
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </swiper-item>
  34. </swiper>
  35. <!-- -->
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- -->
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. weekList: ['日', '一', '二', '三', '四', '五', '六'],
  48. // 月份数组【2020-08-01 2020-09-01 2020-10-01】
  49. slideDataList:[],
  50. // 月份数组的索引
  51. slideDataListIndex:1,
  52. year:2020,
  53. month:10,
  54. day:10,
  55. dayList:[],
  56. start_time:'', // 月初的时间戳
  57. end_time:'', // 月末的时间戳
  58. };
  59. },
  60. created() {
  61. console.log('created')
  62. this._onLoad()
  63. },
  64. methods:{
  65. async _onLoad() {
  66. // 获取当前时间 赋值年,月
  67. await this.initTime()
  68. // 更新日历
  69. await this._runMonth()
  70. },
  71. // 初始化时间
  72. initTime() {
  73. var nowTimeData = this._getTimeNowApi()
  74. this.year = nowTimeData.year
  75. this.month = nowTimeData.month
  76. this.day = nowTimeData.day
  77. // 今日时间为:2020-9-16
  78. console.log('今日时间为:'+this.year+'-'+this.month+'-'+this.day)
  79. },
  80. async _runMonth() {
  81. console.log('==============================================================')
  82. // 获取当前月的每一天的数据 1~31
  83. await this.initApi()
  84. // 根据当前选择的年月,更新start_time end_time
  85. await this._timeApi()
  86. console.log(this.start_time)
  87. console.log(this.end_time)
  88. // 更新记录
  89. // await this.onClickSignLog()
  90. let dataWeek = await this.getweek(this._getNowApi());
  91. // console.log(this._getNowApi())
  92. this.slideDataList[0] = []
  93. this.slideDataList[1] = dataWeek
  94. this.slideDataList[2] = []
  95. console.log(this.slideDataList)
  96. console.log('==============================================================')
  97. },
  98. _getTimeNowApi() {
  99. // 初始化时间
  100. var date = new Date();
  101. var year = date.getFullYear();
  102. var month = parseInt(date.getMonth()+1);
  103. var day = date.getDate();
  104. if (month < 10) {
  105. month = '0' + month
  106. }
  107. if (day < 10) {
  108. day = '0' + day
  109. }
  110. let returnData = {
  111. year: year,
  112. month:parseInt(month),
  113. day:day,
  114. }
  115. return returnData
  116. },
  117. // 滑动日历触发(左右滑动)
  118. _onClickSlideApi(e) {
  119. let current = e.detail.current
  120. let oldIndex = this.slideDataListIndex
  121. this.slideDataListIndex = current
  122. if(oldIndex - current == -1 || oldIndex - current == 2){
  123. console.log('向右滑动前一个月')
  124. if (this.month == 12) {
  125. this.year = this.year + 1
  126. this.month = 1
  127. } else {
  128. this.month = this.month+1
  129. }
  130. } else {
  131. console.log('向左滑动后退一个月')
  132. if (this.month == 1) {
  133. this.year = this.year - 1
  134. this.month = 12
  135. } else {
  136. this.month = this.month - 1
  137. }
  138. }
  139. this._runMonth()
  140. },
  141. _getNowApi() {
  142. console.log('当前日期:'+this.year+'-'+this.month+'-'+this.day)
  143. let data = {
  144. Day: 1,
  145. Month: this.month,
  146. Year: this.year
  147. }
  148. console.log(data)
  149. return data
  150. },
  151. // 获取当前月的每一天的数据
  152. initApi() {
  153. this.dayList = this.createDayList(this.month, this.year);
  154. },
  155. //创建每个月日历数据,传入月份1号前面用null填充
  156. createDayList(month, year) {
  157. const count = this.getDayNum(month, year),
  158. _week = new Date(year + '/' + month + '/1').getDay();
  159. let list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]
  160. for (let i = 29; i <= count; i++) {
  161. list.push(i)
  162. }
  163. for (let i = 0; i < _week; i++) {
  164. list.unshift(null)
  165. }
  166. return list;
  167. },
  168. //计算传入月份有多少天
  169. getDayNum(month, year) {
  170. let dayNum = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  171. if ((year % 4 === 0) && (year % 100 !== 0) || (year % 400 === 0)) {
  172. dayNum[1] = 29;
  173. }
  174. return dayNum[month - 1]
  175. },
  176. // 传时间获取月初月末时间
  177. _timeApi() {
  178. let startDate = this.year+'-'+this.month+'-'+this.day
  179. let startData = this._timeMonthStartApi(startDate+' 00:00:00')
  180. this.start_time = startData.time_int
  181. let endData = this._timeMonthEndApi(startDate+' 00:00:00')
  182. this.end_time = endData.time_int
  183. },
  184. _timeMonthStartApi(timeDate) {
  185. var date = new Date(timeDate);
  186. date.setDate(1);
  187. var month = parseInt(date.getMonth()+1);
  188. var day = date.getDate();
  189. if (month < 10) {
  190. month = '0' + month
  191. }
  192. if (day < 10) {
  193. day = '0' + day
  194. }
  195. let timeDateStart = date.getFullYear() + '-' + month + '-' + day;
  196. let returnData = {
  197. time_type:'start_time',
  198. time_int: Date.parse(timeDateStart+' 00:00:00')/1000,
  199. time_date: timeDateStart,
  200. year:date.getFullYear(),
  201. month:month,
  202. day:day,
  203. }
  204. return returnData
  205. },
  206. _timeMonthEndApi(timeDate) {
  207. var endDate=new Date(timeDate);
  208. var currentMonth=endDate.getMonth();
  209. var nextMonth=++currentMonth;
  210. var nextMonthFirstDay=new Date(endDate.getFullYear(),nextMonth,1);
  211. var oneDay=1000*60*60*24;
  212. var lastTime = new Date(nextMonthFirstDay-oneDay);
  213. var endMonth = parseInt(lastTime.getMonth()+1);
  214. var endDay = lastTime.getDate();
  215. if (endMonth < 10) {
  216. endMonth = '0' + endMonth
  217. }
  218. if (endDay < 10) {
  219. endDay = '0' + endDay
  220. }
  221. let timeDateEnd = endDate.getFullYear() + '-' + endMonth + '-' + endDay
  222. let returnData = {
  223. time_type:'end_time',
  224. time_int: Date.parse(timeDateEnd+' 00:00:00')/1000,
  225. time_date: timeDateEnd,
  226. year:endDate.getFullYear(),
  227. month:endMonth,
  228. day:endDay,
  229. }
  230. return returnData
  231. },
  232. // 2020-08-01
  233. getweek(date) {
  234. let weeks = [];
  235. let dates = this.getDates(date);
  236. // let len = Math.ceil(dates.weeks.length / 7);
  237. // for (let i = 0; i < len; i++) {
  238. // weeks.push(dates.weeks.slice(i * 7, 7 + (i * 7)));
  239. // }
  240. // dates.weeks = weeks
  241. return dates;
  242. },
  243. getDates(date) {
  244. let dates = {
  245. year: date.Year,
  246. month: date.Month,
  247. firstDay: new Date(date.Year, date.Month, 1).getDay(),
  248. lastDay: new Date(date.Year, date.Month + 1, 0).getDay(),
  249. endDate: new Date(date.Year, date.Month + 1, 0).getDate(),
  250. weeks: []
  251. }
  252. //计算上月日期
  253. for (let i = dates.firstDay; i > 0; i--) {
  254. let dateinfo = {};
  255. dateinfo.date = new Date(date.Year, date.Month, -i + 1).getDate();
  256. dateinfo.isClick = false;
  257. dates.weeks.push(dateinfo);
  258. }
  259. //计算本月日期
  260. for (let i = 1; i <= new Date(date.Year, date.Month + 1, 0).getDate(); i++) {
  261. let nowisClick = true;
  262. let dateinfo = {};
  263. dateinfo.date = i;
  264. if (this.dateType == 'dateCustom') {
  265. nowisClick = false;
  266. if (this.dateCustom[dates.year] && this.dateCustom[dates.year][dates.month]) {
  267. for (let j = 0; j < this.dateCustom[dates.year][dates.month].length; j++) {
  268. if (this.dateCustom[dates.year][dates.month][j] == i) {
  269. nowisClick = true;
  270. }
  271. }
  272. }
  273. }
  274. dateinfo.isClick = nowisClick;
  275. dates.weeks.push(dateinfo);
  276. }
  277. //计算下月日期
  278. let len = 7 - dates.lastDay;
  279. if ((42 - dates.weeks.length) >= 7) {
  280. len += 7;
  281. }
  282. for (let i = 1; i < len; i++) {
  283. let dateinfo = {};
  284. dateinfo.date = i;
  285. dateinfo.isClick = false;
  286. dates.weeks.push(dateinfo);
  287. }
  288. return dates;
  289. },
  290. }
  291. }
  292. </script>
  293. <style lang="scss">
  294. .riliWrapper {
  295. width: 100%;
  296. // height: 499rpx;
  297. // background-color: #9bf;
  298. // padding: 0 5%;
  299. display: flex;
  300. justify-content: center;
  301. .riliWrapperBox {
  302. width: 90%;
  303. // height: 499rpx;
  304. // background-color: #9bf;
  305. }
  306. // 日历
  307. .signWrapperCalendar {
  308. margin-top: 30rpx;
  309. width: 100%;
  310. border: 3rpx solid #9bf;
  311. .signWrapperCalendarBox {
  312. width: 100%;
  313. // height: 499rpx;
  314. background: #FFFFFF;
  315. border-radius: 10rpx;
  316. // background-color: #9bf;
  317. .signWrapperCalendarBoxTop {
  318. width: 100%;
  319. height: 72rpx;
  320. // background-color: red;
  321. display: flex;
  322. align-items: center;
  323. justify-content: center;
  324. border-bottom: 2rpx solid #EFEFEF;
  325. }
  326. .signWrapperCalendarBoxBit {
  327. width: 100%;
  328. height: 2rpx;
  329. border: 2rpx solid #EFEFEF;
  330. }
  331. .signWrapperCalendarBoxCenter {
  332. width: 100%;
  333. height: 425rpx;
  334. // background-color: #fff;
  335. // padding: 30rpx 30rpx;
  336. padding: 30rpx 0rpx;
  337. display: flex;
  338. justify-content: center;
  339. .signWrapperCalendarBoxCenterBox {
  340. width: 90%;
  341. height: 100%;
  342. // background-color: #9000FF;
  343. .signWrapperCalendarBoxCenterBoxTop {
  344. .week-number {
  345. background: #fff;
  346. padding: 0 1%;
  347. span {
  348. display: inline-block;
  349. text-align: center;
  350. height: 40px;
  351. line-height: 40px;
  352. width: 14.2857143%;
  353. color: #333333;
  354. }
  355. }
  356. }
  357. .signWrapperCalendarBoxCenterBoxFooter {
  358. width: 100%;
  359. // hei
  360. // background-color: red;
  361. .each-day {
  362. position: relative;
  363. display: inline-block;
  364. // display: flex;
  365. // justify-content: flex-start;
  366. text-align: center;
  367. vertical-align: middle;
  368. width: 14.28%;
  369. font-size: 25rpx;
  370. height: 50rpx;
  371. margin-top:4rpx;
  372. padding-top:4rpx;
  373. .eachDayBox {
  374. width: 100%;
  375. height: 100%;
  376. display: flex;
  377. align-items: center;
  378. justify-content: center;
  379. .eachDayBoxBox {
  380. width: 36rpx;
  381. height: 36rpx;
  382. // background: #FCEEE0;
  383. border-radius: 50%;
  384. display: flex;
  385. align-items: center;
  386. justify-content: center;
  387. }
  388. }
  389. //
  390. .eachDayBoxCheck {
  391. width: 100%;
  392. height: 100%;
  393. display: flex;
  394. align-items: center;
  395. justify-content: center;
  396. .eachDayBoxBox {
  397. width: 36rpx;
  398. height: 36rpx;
  399. background: #FCEEE0;
  400. border-radius: 50%;
  401. display: flex;
  402. align-items: center;
  403. justify-content: center;
  404. color: red;
  405. }
  406. }
  407. //
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415. </style>