• vue 获取上一周和获取下一周的日期时间


    效果图

    代码

    1. <template>
    2. <div>
    3. <div style="padding: 20px 0;">
    4. <div style="margin-left: 10px; border-left: 5px solid #0079fe; font-size: 22px; font-weight: 600; padding-left: 10px">工作计划</div>
    5. <div style="margin-left: 50px; padding-right: 50px; margin-right: 50px">
    6. <div style="display:flex; justify-content: center; margin-top: 5vh; margin-bottom: 5vh; align-items: center">
    7. <div style="cursor: pointer; background-color: #39b54a; padding: 10px 50px 11px; border-radius: 20px; color: #fff; margin-right: 15px" @click="getPreviousWeekDates">上一周</div>
    8. <div style=" cursor: pointer; background-color: #0081ff; padding: 11px 50px 10px; border-radius: 20px; color: #fff" @click="getNextWeekDates">下一周</div>
    9. </div>
    10. <div>
    11. <table id="myTable">
    12. <tr>
    13. <th style="width: 70px; position: relative">
    14. <div class="ss"></div>
    15. </th>
    16. <th v-for="item in nowDate" :key="item.nyr">
    17. <div style="font-size: 18px">{{ item.nyr }}</div>
    18. <div style="font-size: 16px">{{item.xq }}</div>
    19. </th>
    20. </tr>
    21. <tbody>
    22. <tr>
    23. <td rowspan="8" style="background-color: #d7d7d7; width: 50px;">账号姓名</td>
    24. <td rowspan="8" v-for="item in nowDate" :key="item.nyr">
    25. <el-input
    26. type="textarea"
    27. :rows="17"
    28. @blur="fsqq"
    29. placeholder="请输入内容"
    30. v-model="item.content">
    31. </el-input>
    32. </td>
    33. </tr>
    34. </tbody>
    35. </table>
    36. </div>
    37. </div>
    38. </div>
    39. </div>
    40. </template>
    41. <script>
    42. export default {
    43. name: 'index',
    44. data() {
    45. return {
    46. nowDate: [],
    47. i: 0,
    48. y: 0,
    49. syz: [],
    50. xyz: []
    51. }
    52. },
    53. mounted() {
    54. this.getWeekDates();
    55. let width= window.innerWidth;
    56. console.log(width)
    57. },
    58. methods: {
    59. fsqq() {
    60. },
    61. getWeekDates() {
    62. let date = new Date()
    63. let day = date.getDay()
    64. let diff = date.getDate() - day + (day === 0 ? -6 : 1) // 获取所在周的第一天
    65. let weekStart = new Date(date.setDate(diff))
    66. let weekDates = []
    67. for (let i = 0; i < 7; i++) {
    68. let currentDate = new Date(weekStart)
    69. currentDate.setDate(weekStart.getDate() + i)
    70. weekDates.push(currentDate)
    71. }
    72. weekDates.forEach((date) => {
    73. let year = date.getFullYear()
    74. let month = (date.getMonth() + 1).toString().padStart(2, '0')
    75. let day = date.getDate().toString().padStart(2, '0')
    76. let dayOfWeek = new Intl.DateTimeFormat('zh-CN', { weekday: 'long' }).format(date)
    77. console.log(year + '-' + month + '-' + day + ' (' + dayOfWeek + ')')
    78. this.nowDate.push({
    79. nyr: year + '-' + month + '-' + day,
    80. xq: dayOfWeek
    81. })
    82. })
    83. },
    84. getPreviousWeekDates() {
    85. this.nowDate = [];
    86. this.syz = []
    87. if (this.y > 0) {
    88. this.y = this.y - 1
    89. }
    90. this.i = this.i + 1
    91. let weeksAgo = this.i
    92. let today = new Date()
    93. if (this.xyz.length > 0) {
    94. today = new Date(this.xyz[0].nyr)
    95. }
    96. let firstDayOfWeek = today.getDate() - today.getDay() + (today.getDay() === 0 ? -6 : 1) // 获取本周的第一天
    97. let startingDate = new Date(today.setDate(firstDayOfWeek))
    98. let weekDates = []
    99. for (let i = 0; i < weeksAgo; i++) {
    100. startingDate.setDate(startingDate.getDate() - 7) // 递减起始日期
    101. for (let j = 0; j < 7; j++) {
    102. let currentDate = new Date(startingDate)
    103. currentDate.setDate(startingDate.getDate() + j)
    104. weekDates.push(currentDate)
    105. }
    106. }
    107. let remaining = []
    108. if (this.i > 1) {
    109. remaining = weekDates.slice((this.i - 1) * 7)
    110. } else {
    111. remaining = weekDates
    112. }
    113. remaining.forEach((date) => {
    114. let year = date.getFullYear()
    115. let month = (date.getMonth() + 1).toString().padStart(2, '0')
    116. let day = date.getDate().toString().padStart(2, '0')
    117. let dayOfWeek = new Intl.DateTimeFormat('zh-CN', { weekday: 'long' }).format(date)
    118. this.syz.push({
    119. nyr: year + '-' + month + '-' + day,
    120. xq: dayOfWeek
    121. })
    122. this.nowDate.push({
    123. nyr: year + '-' + month + '-' + day,
    124. xq: dayOfWeek
    125. })
    126. console.log(year + '-' + month + '-' + day + ' (' + dayOfWeek + ')')
    127. // console.log(this.syz)
    128. })
    129. return weekDates
    130. },
    131. getNextWeekDates() {
    132. this.xyz = [];
    133. this.nowDate = [];
    134. if (this.i > 0) {
    135. this.i = this.i - 1
    136. }
    137. this.y = this.y + 1 // 将 this.i 的值加 1
    138. let weeksAgo = this.y
    139. let today = new Date()
    140. if (this.syz.length > 0) {
    141. today = new Date(this.syz[6].nyr)
    142. }
    143. let firstDayOfWeek = today.getDate() - today.getDay() + (today.getDay() === 0 ? -6 : 1) // 获取本周的第一天
    144. let startingDate = new Date(today.setDate(firstDayOfWeek))
    145. let weekDates = []
    146. for (let i = 0; i < weeksAgo; i++) {
    147. startingDate.setDate(startingDate.getDate() + 7) // 递增起始日期
    148. for (let j = 0; j < 7; j++) {
    149. let currentDate = new Date(startingDate)
    150. currentDate.setDate(startingDate.getDate() + j)
    151. weekDates.push(currentDate)
    152. }
    153. }
    154. let remaining = []
    155. if (this.y > 1) {
    156. remaining = weekDates.slice((this.y - 1) * 7) // 获取下一周的日期
    157. } else {
    158. remaining = weekDates
    159. }
    160. remaining.forEach((date) => {
    161. let year = date.getFullYear()
    162. let month = (date.getMonth() + 1).toString().padStart(2, '0')
    163. let day = date.getDate().toString().padStart(2, '0')
    164. let dayOfWeek = new Intl.DateTimeFormat('zh-CN', { weekday: 'long' }).format(date)
    165. this.xyz.push({
    166. nyr: year + '-' + month + '-' + day,
    167. xq: dayOfWeek
    168. })
    169. // console.log(this.xyz)
    170. this.nowDate.push({
    171. nyr: year + '-' + month + '-' + day,
    172. xq: dayOfWeek
    173. })
    174. console.log(year + '-' + month + '-' + day + ' (' + dayOfWeek + ')')
    175. })
    176. return weekDates
    177. }
    178. }
    179. }
    180. </script>
    181. <style scoped>
    182. .ss {
    183. content: "";
    184. position: absolute;
    185. width: 1px;
    186. height:164px; 需要手调 ,线的长度
    187. top: 1px; 需要手调 ,线的位置
    188. left: -5px;
    189. background-color: white;
    190. display: block;
    191. transform: rotate(-57deg);
    192. transform-origin: top;
    193. }
    194. table {
    195. width: 80vw;
    196. border-collapse: collapse;
    197. border: 2px #797979 solid;
    198. }
    199. th, td {
    200. padding: 10px;
    201. width: 100px;
    202. border: 2px #797979 solid;
    203. text-align: center;
    204. }
    205. th {
    206. height: 10vh;
    207. background-color: #d7d7d7;
    208. }
    209. td {
    210. height: 40vh;
    211. }
    212. #operButton {
    213. position: absolute;
    214. left: 600px;
    215. top: 100px;
    216. }
    217. #operButton button {
    218. width: 100px;
    219. height: 50px;
    220. }
    221. </style>

  • 相关阅读:
    使用C++界面框架ImGUI开发一个简单程序
    react-redux开发者工具的使用
    Vue3 + TypeSciprt+Vant 项目框架构建
    在vue3项目中使用el-tabs切换标签页时echarts图表显示不正确
    助力汽修企业突破转型瓶颈,S2B2B商城价格管理模块实现采购交易数字化升级
    股票python量化交易011-JQData财务相对估值指标
    云小课|MRS基础原理之MapReduce介绍
    多线程进阶
    2023计算机毕业设计SSM最新选题之java儿童成长记录与分享系统cc35g
    1329: 【C2】【排序】奖学金
  • 原文地址:https://blog.csdn.net/m0_55333789/article/details/134159329