当前位置:   article > 正文

uniapp会议预约顶部横向滑动日历和时间线_uniapp 时间轴会议预约

uniapp 时间轴会议预约
  1. <template>
  2. <view class="container">
  3. <view class="swiper" >
  4. <view
  5. v-for="(item, index) in dateList"
  6. :key="index"
  7. @click ="ClickDateCheng(item.id, index)"
  8. :class="{'selected': selectedIndex === index}"
  9. class="box">
  10. <text style="padding-bottom: 4rpx;">{{ item.label }}</text>
  11. <text >{{ item.day}}</text>
  12. </view>
  13. </view>
  14. <view class="all">
  15. <text>{{ year }}年</text>
  16. <view @click="show = true">{{month }}月</view>
  17. </view>
  18. <u-calendar :show="show" @close="show = !show" @confirm="confirm"></u-calendar>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. show: false,
  26. single: '',
  27. dateList: [],
  28. dateListArray: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
  29. maxCount: 15, // 横向日期默认显示的日期数量
  30. clientWidthCount: 0, // 每行显示的数量
  31. selectedIndex: 0,
  32. year: new Date().getFullYear(),
  33. month: new Date().getMonth() + 1,
  34. };
  35. },
  36. methods: {
  37. // 初始化日期数组
  38. initDates() {
  39. // { label:"周一",'day':"22", value:"2023-12-22"}
  40. this.dateList.push(this.formatData(new Date()))
  41. for (let i = 1; i <= this.maxCount; i++) {
  42. let now = new Date();
  43. this.dateList.push(this.formatData(new Date(now.setDate(now.getDate()+i))))
  44. }
  45. },
  46. formatData(date){
  47. let nowStr=this.$u.timeFormat(date.getTime(), 'yyyy-mm-dd')
  48. let label=this.dateListArray[date.getDay()]
  49. return {
  50. label:label,
  51. day:date.getDate(),
  52. value:nowStr
  53. }
  54. },
  55. confirm(e) {
  56. const date = new Date(e[0]);
  57. this.year = date.getFullYear();
  58. this.month = date.getMonth() + 1;
  59. const selectedIndex = this.dateList.findIndex(item => item.value === this.$u.timeFormat(date.getTime(), 'yyyy-mm-dd'));
  60. if (selectedIndex !== -1) {
  61. this.selectedIndex = selectedIndex;
  62. }
  63. this.show = false;
  64. },
  65. // 添加日期到数组
  66. addDate(date, txt) {
  67. let year = date.getFullYear();
  68. let mon = (date.getMonth() + 1 < 10 ? '0' : '') + (date.getMonth() + 1);
  69. let day = (date.getDate() < 10 ? '0' : '') + date.getDate();
  70. let week = txt !== "" ? txt : this.dateListArray[date.getDay()];
  71. let newObj = {
  72. id: year + '-' + mon + '-' + day,
  73. text: week,
  74. mon: mon,
  75. day: day
  76. };
  77. this.Dates.push(newObj);
  78. },
  79. // 点击日期事件
  80. ClickDateCheng(id, index) {
  81. this.selectedIndex = index;
  82. this.dateCurrentStr = id;
  83. // uni.showToast({
  84. // title: '加载中...',
  85. // icon: 'loading',
  86. // duration: 1000
  87. // });
  88. }
  89. },
  90. created() {
  91. // 初始化日期数组
  92. this.initDates();
  93. },
  94. };
  95. </script>
  96. <style lang="scss" scoped>
  97. .container {
  98. display: flex;
  99. flex-direction: row;
  100. width: 100vw;
  101. .swiper {
  102. background: #4b9efc;
  103. color: white;
  104. display: flex;
  105. flex-direction: row;
  106. overflow-x: scroll;
  107. white-space: nowrap;
  108. padding: 8rpx 0;
  109. .box {
  110. width: calc(100% / 6 - 50rpx);
  111. display: flex;
  112. flex-direction: column;
  113. justify-content: center;
  114. align-items: center;
  115. font-size: 12px;
  116. //width: calc( 100% / 7 - 270rpx );
  117. padding: 8rpx 15rpx;
  118. margin: 0 10rpx;
  119. }
  120. .selected {
  121. background-color: #fff;
  122. color: #54a6f8;
  123. border-radius: 10rpx;
  124. }
  125. }
  126. .all {
  127. width: 180rpx;
  128. font-size: 12px;
  129. display: flex;
  130. padding: 10rpx;
  131. align-items: center;
  132. flex-direction: column;
  133. justify-content: center;
  134. background: #2e8ff1;
  135. color: #FFFFFF;
  136. }
  137. }
  138. </style>

时间线

  1. <template>
  2. <view>
  3. <view class="item">
  4. <view v-for="(item,index) in nums" :key="index" >
  5. <view>
  6. {{item}}
  7. </view>
  8. </view>
  9. </view>
  10. <view style="display: flex;">
  11. <view v-for="(item,index) in nums" :key="index"
  12. :style="{width:100/nums.length + '%'}" style="background:#fac7c7;height:30rpx">
  13. <view v-for="(deepitem,dindex) in colorDeeps"
  14. :key="dindex">
  15. <view v-if="item>= deepitem.start && item <deepitem.end" class="deep">
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. nums: [
  27. 7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
  28. ],
  29. colorDeeps:[
  30. { start: 12, end: 14},
  31. { start: 8, end: 9 }
  32. ],
  33. }
  34. },
  35. methods: {
  36. }
  37. }
  38. </script>
  39. <style lang="scss" scoped>
  40. .item{
  41. font-size: 14px;
  42. display: flex;
  43. justify-content: space-around;
  44. align-items: center;
  45. color: #999999;
  46. margin-bottom: 6rpx;
  47. }
  48. .deep{
  49. background: #fc5967;
  50. height:30rpx;
  51. }
  52. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/969833
推荐阅读
相关标签
  

闽ICP备14008679号