手写排班日历

打印 上一主题 下一主题

主题 532|帖子 532|积分 1596

手写排班日历:

结果图:

vue代码如下:

  1. <template>
  2.   <div class="YSPB">
  3.     <div class="title">排班日历</div>
  4.     <div class="banner">
  5.       <span class='iconfont icon-youjiantou ' @click="nextMounth('l')">{{ "{" }}</span>
  6.       <span>{{ y }}年{{ m }}月</span>
  7.       <span class='iconfont icon-youjiantou' @click="nextMounth('r')">{{ "}" }}</span>
  8.     </div>
  9.     <div class="cander" v-show="show">
  10.       <div class="week">
  11.         <span class='box' style='color:#ff0000a1;'>日</span>
  12.         <span class='box'>一</span>
  13.         <span class='box'>二</span>
  14.         <span class='box'>三</span>
  15.         <span class='box'>四</span>
  16.         <span class='box'>五</span>
  17.         <span class='box' style='color:#ff0000a1;'>六</span>
  18.       </div>
  19.       <div class="days">
  20.         <div class="days1" v-for="(obj, i) in dateList" :key="i">
  21.           <div :class="['txt',
  22.             obj.day == today ? (obj.bool ? 'sel' : '') : '',
  23.             obj.bool ? '' : 'old',
  24.             obj.isWork == '上午' ? 'shangwuColor' : obj.isWork == '下午' ? 'xiawuColor' : obj.isWork == '全天' ? 'quantianColor' : '',
  25.             obj.label == '左' ? 'Color_l' : obj.label == '中' ? 'Color_z' : obj.label == '右' ? 'Color_r' : '']"
  26.             @click='selClick(obj.day, obj.bool, obj)'>
  27.             <span v-if="obj.isWork == '上午'" class="t1">{{ obj.day }}</span>
  28.             <span v-if="obj.isWork == '上午'" class="t2">{{ obj.lunar }}</span>
  29.             <!-- <div :class="['t3', obj.isWork == '上午' ? 't4' : '']" v-show="(obj.day != today) && obj.bool && obj.isWork == '上午'">上午</div> -->
  30.             <span v-if="obj.isWork == '下午'" class="t1">{{ obj.day }}</span>
  31.             <span v-if="obj.isWork == '下午'" class="t2">{{ obj.lunar }}</span>
  32.             <!-- <div :class="['t3', obj.isWork == '下午' ? 't4' : '']" v-show="(obj.day != today) && obj.bool && obj.isWork == '下午'">下午</div> -->
  33.             <span v-if="obj.isWork == '全天'" class="t1">{{ obj.day }}</span>
  34.             <span v-if="obj.isWork == '全天'" class="t2">{{ obj.lunar }}</span>
  35.             <!-- <div :class="['t3', obj.isWork == '全天' ? 't4' : '']" v-show="(obj.day != today) && obj.bool && obj.isWork == '全天'">全天</div> -->
  36.             <span v-if="!obj.isWork" class="t1">{{ obj.day }}</span>
  37.             <span v-if="!obj.isWork" class="t2">{{ obj.lunar }}</span>
  38.             <div :class="['t3']" v-show="(obj.day != today) && obj.bool && !obj.isWork">休</div>
  39.           </div>
  40.         </div>
  41.       </div>
  42.     </div>
  43.     <div class="bot">
  44.       注意:所有排班不可自行更改,如需更改排班,请联系医院管理人员进行更改
  45.     </div>
  46.     <div class="forterColor">
  47.       <div class="forterColor1">
  48.         <div class="shangwuColor_qiu"></div> <span>上午班</span>
  49.       </div>
  50.       <div class="forterColor1">
  51.         <div class="xiawuColor_qiu"></div><span>下午班</span>
  52.       </div>
  53.       <div class="forterColor1">
  54.         <div class="quantianColor_qiu"></div><span>全天班</span>
  55.       </div>
  56.     </div>
  57.   </div>
  58. </template>
  59. <script>
  60. export default {
  61.   name: "cu-divClick",
  62.   props: {
  63.     list: {
  64.       type: Array,
  65.       default: () => []
  66.     },
  67.     clickAction: {
  68.       type: Number,
  69.       default: 3
  70.     }
  71.   },
  72.   data() {
  73.     return {
  74.       show: true,
  75.       dateList: [],
  76.       today: new Date().getDate(),
  77.       y: new Date().getFullYear(),
  78.       m: new Date().getMonth() + 1,
  79.       pbList: [], //排班列表
  80.     };
  81.   },
  82.   mounted() {
  83.     this.dateList = this.getTime()
  84.     this.pbList = [
  85.             {
  86.               "doctorCode": "10015",
  87.               "doctorName": "韩辰份",
  88.               "resourcesDate": "2024-09-02",
  89.               "timeType": "全天"
  90.             },
  91.             {
  92.               "doctorCode": "10015",
  93.               "doctorName": "韩辰份",
  94.               "resourcesDate": "2024-09-03",
  95.               "timeType": "全天"
  96.             },
  97.             {
  98.               "doctorCode": "10015",
  99.               "doctorName": "韩辰份",
  100.               "resourcesDate": "2024-09-15",
  101.               "timeType": "上午"
  102.             },
  103.             {
  104.               "doctorCode": "10015",
  105.               "doctorName": "韩辰份",
  106.               "resourcesDate": "2024-09-16",
  107.               "timeType": "上午"
  108.             },
  109.             {
  110.               "doctorCode": "10015",
  111.               "doctorName": "韩辰份",
  112.               "resourcesDate": "2024-09-17",
  113.               "timeType": "上午"
  114.             },
  115.             {
  116.               "doctorCode": "10015",
  117.               "doctorName": "韩辰份",
  118.               "resourcesDate": "2024-09-18",
  119.               "timeType": "下午"
  120.             },
  121.             {
  122.               "doctorCode": "10015",
  123.               "doctorName": "韩辰份",
  124.               "resourcesDate": "2024-09-26",
  125.               "timeType": "全天"
  126.             },
  127.             {
  128.               "doctorCode": "10015",
  129.               "doctorName": "韩辰份",
  130.               "resourcesDate": "2024-09-27",
  131.               "timeType": "全天"
  132.             },
  133.           ];
  134.           this.pbList = this.labelArray(this.pbList);
  135.           console.log("this.pbList:", this.pbList)
  136.           this.isWork()
  137.   },
  138.   watch: {
  139.     dateList: {
  140.       handler(newval) {
  141.         this.isWork()
  142.       },
  143.       deep: true,
  144.       immediate: true
  145.     }
  146.   },
  147.   methods: {
  148.     isWork() {
  149.       this.show = false
  150.       this.dateList.forEach(val => {
  151.         this.pbList.forEach(item => {
  152.           const date = this.y + '-' + this.m + '-' + val.day
  153.           if (val.timeDate == item.resourcesDate && item.timeType == "上午") {
  154.             val.isWork = "上午"
  155.             console.log(date + val.isWork)
  156.             val.label = item.label
  157.           } else if (val.timeDate == item.resourcesDate && item.timeType == "下午") {
  158.             val.isWork = "下午"
  159.             console.log(date + val.isWork)
  160.             val.label = item.label
  161.           } else if (val.timeDate == item.resourcesDate && item.timeType == "全天") {
  162.             val.isWork = "全天"
  163.             console.log(date + val.isWork)
  164.             val.label = item.label
  165.           }
  166.         })
  167.       })
  168.       this.show = true
  169.     },
  170.     areConsecutiveDates(date1, date2) {
  171.       let d1 = new Date(date1);
  172.       let d2 = new Date(date2);
  173.       let oneDay = 24 * 60 * 60 * 1000;
  174.       return Math.round((d2 - d1) / oneDay) === 1;
  175.     },
  176.     labelArray(arr) {
  177.       let result = [];
  178.       let i = 0;
  179.       while (i < arr.length) {
  180.         let start = i;
  181.         let end = i;
  182.         while (end + 1 < arr.length && arr[end].timeType === arr[end + 1].timeType && this.areConsecutiveDates(arr[end].resourcesDate, arr[end + 1].resourcesDate)) {
  183.           end++;
  184.         }
  185.         if (start === end) {
  186.           result.push(arr[start]);
  187.         } else {
  188.           result.push({ ...arr[start], label: '左' });// 上午/下午/全天-左边元素
  189.           for (let j = start + 1; j < end; j++) {
  190.             result.push({ ...arr[j], label: '中' });// 上午/下午/全天-中间元素
  191.           }
  192.           result.push({ ...arr[end], label: '右' });// 上午/下午/全天-右边元素
  193.         }
  194.         i = end + 1;
  195.       }
  196.       return result;
  197.     },
  198.     /* 日历 ----------------------------------*/
  199.     // 选中日期
  200.     selClick(day, flag, obj) {
  201.       console.log(obj)
  202.       if (!flag) return
  203.       this.today = day
  204.     },
  205.     //获取当月天数
  206.     getMounthNum(m) {
  207.       let days = 0
  208.       if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
  209.         days = 31
  210.       } else if (m == 4 || m == 6 || m == 9 || m == 11) {
  211.         days = 30
  212.       } else if (m == 2) {
  213.         if ((this.y % 4 == 0 && this.y % 100 != 0) || (this.y % 400 == 0)) {
  214.           days = 29
  215.         } else {
  216.           days = 28
  217.         }
  218.       }
  219.       return days
  220.     },
  221.     //获取当月每一天对应周几
  222.     getTime() {
  223.       const date = new Date(this.y + '/' + this.m + '/' + '1')
  224.       const arr = []
  225.       const start = date.getDay()
  226.       const end = new Date(this.y + '/' + this.m + '/' + this.getMounthNum(this.m)).getDay()
  227.       for (let i = 1 - start; i <= this.getMounthNum(this.m) + 6 - end; i++) {
  228.         let day = '',
  229.           week = '',
  230.           lunar = '',
  231.           bool = true,
  232.           m = '',
  233.           y = this.y,
  234.           today = this.today;
  235.         if (i < 1) {
  236.           m = this.m - 1
  237.           if (m < 1) {
  238.             y--
  239.             m = 12
  240.           }
  241.           day = this.getMounthNum(m) + i
  242.         } else if (i >= 1 && i <= this.getMounthNum(this.m)) {
  243.           m = this.m
  244.           day = i
  245.         } else if (i > this.getMounthNum(this.m)) {
  246.           m = this.m + 1
  247.           if (m > 12) {
  248.             y++
  249.             m = 1
  250.           }
  251.           day = i - this.getMounthNum(this.m)
  252.         }
  253.         week = this.setWeek(new Date(y + '/' + m + '/' + day).getDay())
  254.         day = day >= 10 ? day.toString() : '0' + day
  255.         const ary = this.$cu.test.getLunar(new Date(y + '/' + m + '/' + day))
  256.         if (day < this.today || i < 1 || i > this.getMounthNum(this.m)) {
  257.           bool = false
  258.         }
  259.         console.log("y")
  260.         m = m >= 10 ? m.toString() : '0' + m
  261.         let timeDate = y + "-" + m + "-" + day
  262.         arr.push({
  263.           day,
  264.           week,
  265.           lunar: ary[1],
  266.           nl: ary[0],
  267.           bool,
  268.           timeDate
  269.         })
  270.       }
  271.       return arr
  272.     },
  273.     setWeek(val) {
  274.       switch (val) {
  275.         case 0:
  276.           val = '周日'
  277.           break;
  278.         case 1:
  279.           val = '周一'
  280.           break;
  281.         case 2:
  282.           val = '周二'
  283.           break;
  284.         case 3:
  285.           val = '周三'
  286.           break;
  287.         case 4:
  288.           val = '周四'
  289.           break;
  290.         case 5:
  291.           val = '周五'
  292.           break;
  293.         case 6:
  294.           val = '周六'
  295.           break;
  296.       }
  297.       return val
  298.     },
  299.     // 下一月或上一月
  300.     nextMounth(val) {
  301.       if (this.y == new Date().getFullYear() && this.m == new Date().getMonth() + 1 && val == 'l') return
  302.       this.show = false
  303.       if (val == 'l') {
  304.         this.m--
  305.         if (this.m < 1) {
  306.           this.y--
  307.           this.m = 12
  308.         }
  309.       } else if (val == 'r') {
  310.         this.m++
  311.         if (this.m > 12) {
  312.           this.y++
  313.           this.m = 1
  314.         }
  315.       }
  316.       if (this.m != new Date().getMonth() + 1) {
  317.         this.today = null
  318.       } else {
  319.         this.today = new Date().getDate()
  320.       }
  321.       this.dateList = this.getTime()
  322.       this.show = true
  323.     }
  324.     /* 日历 ----------------------------------*/
  325.   }
  326. };
  327. </script>
  328. <style lang="less" scoped>
  329. .YSPB {
  330.   width: 100%;
  331.   height: 100%;
  332.   background-color: #f8f8f8;
  333.   .title {
  334.     // line-height: 110px;
  335.     text-align: center;
  336.     background-color: #fff;
  337.     font-size: 24px;
  338.     font-weight: bold;
  339.     color: #000000;
  340.     border-bottom: 1px solid #ddd;
  341.     padding: 10px 0px;
  342.   }
  343.   .banner {
  344.     display: flex;
  345.     align-items: center;
  346.     // line-height: 110px;
  347.     text-align: center;
  348.     background-color: #fff;
  349.     font-size: 24px;
  350.     font-weight: bold;
  351.     padding: 20px 0px;
  352.     .iconfont {
  353.       flex: 1;
  354.       color: #999;
  355.       cursor: pointer;
  356.       -moz-user-select: none;
  357.       /*mozilar*/
  358.       -webkit-user-select: none;
  359.       /*webkit*/
  360.       -ms-user-select: none;
  361.       /*IE*/
  362.       user-select: none;
  363.     }
  364.     .right {
  365.       display: inline-block;
  366.       transform: rotate(180deg);
  367.     }
  368.     span {
  369.       display: inline-block;
  370.       margin: 0 30px;
  371.       color: #000;
  372.     }
  373.   }
  374.   .cander {
  375.     background-color: #fff;
  376.     padding: 0 27px 50px;
  377.     .week {
  378.       height: 62px;
  379.       border-radius: 31px;
  380.       background-color: #f0f0f0;
  381.       display: flex;
  382.       .box {
  383.         /* 每个项占宽度的 14% */
  384.         width: 14.285714285714286%;
  385.         font-size: 20px;
  386.         display: flex;
  387.         align-items: center;
  388.         justify-content: center;
  389.       }
  390.     }
  391.     .days {
  392.       width: 100%;
  393.       margin-top: 30px;
  394.       display: flex;
  395.       flex-wrap: wrap;
  396.       .days1 {
  397.         padding-top: 30px;
  398.         /* 每个项占宽度的 14% */
  399.         width: 14.285714285714286%;
  400.         display: flex;
  401.         align-items: center;
  402.         justify-content: center;
  403.         .txt {
  404.           padding: 10px 14px;
  405.           position: relative;
  406.           text-align: center;
  407.           color: #000;
  408.           display: flex;
  409.           flex-direction: column;
  410.           align-items: center;
  411.           justify-content: center;
  412.           .t1 {
  413.             display: inline-block;
  414.             font-size: 20px;
  415.             color: #333;
  416.             line-height: 20px;
  417.           }
  418.           .t2 {
  419.             display: block;
  420.             font-size: 12px;
  421.             color: #666;
  422.             line-height: 12px;
  423.           }
  424.           .t3 {
  425.             position: absolute;
  426.             top: 0;
  427.             right: 0;
  428.             color: #00AF46;
  429.             font-size: 12px;
  430.           }
  431.           .t4 {
  432.             color: #F8764E;
  433.           }
  434.         }
  435.         /* 设置每一行的第一位和第七位的文字颜色为红色 */
  436.         .old {
  437.           opacity: 0.5;
  438.           /* 淡化子元素背景色 */
  439.           .t1,
  440.           .t2 {
  441.             color: #b3b3b3;
  442.           }
  443.         }
  444.       }
  445.       .days1:nth-child(7n + 1),
  446.       .days1:nth-child(7n) {
  447.         .txt {
  448.           span {
  449.             color: #ff0000a1;
  450.           }
  451.         }
  452.       }
  453.     }
  454.   }
  455.   .forterColor1 {
  456.     display: flex;
  457.     align-items: center;
  458.     span {
  459.       margin-left: 10px;
  460.     }
  461.   }
  462. }
  463. .sel {
  464.   border-radius: 50%;
  465.   border: 1px solid #dddddd;
  466. }
  467. .shangwuColor_qiu {
  468.   margin-top: 4px;
  469.   width: 18px;
  470.   height: 18px;
  471.   background-color: #ed4014;
  472.   border-radius: 50%;
  473. }
  474. .xiawuColor_qiu {
  475.   margin-top: 4px;
  476.   width: 18px;
  477.   height: 18px;
  478.   background-color: #19be6b;
  479.   border-radius: 50%;
  480. }
  481. .quantianColor_qiu {
  482.   margin-top: 4px;
  483.   width: 18px;
  484.   height: 18px;
  485.   background-color: #2d8cf0;
  486.   border-radius: 50%;
  487. }
  488. .bot {
  489.   padding: 10px 30px;
  490.   font-size: 16px;
  491.   color: #999;
  492.   // line-height: 34px;
  493.   text-align: justify;
  494. }
  495. .forterColor {
  496.   display: flex;
  497.   align-items: center;
  498.   justify-content: space-between;
  499.   padding: 10px 30px;
  500.   font-size: 16px;
  501. }
  502. .shangwuColor {
  503.   margin-top: 4px;
  504.   background-color: #ed4014;
  505.   border-radius: 50%;
  506.   .t1,
  507.   .t2 {
  508.     color: #fff !important;
  509.   }
  510. }
  511. .xiawuColor {
  512.   margin-top: 4px;
  513.   background-color: #19be6b;
  514.   border-radius: 50%;
  515.   .t1,
  516.   .t2 {
  517.     color: #fff !important;
  518.   }
  519. }
  520. .quantianColor {
  521.   margin-top: 4px;
  522.   background-color: #2d8cf0;
  523.   border-radius: 50%;
  524.   .t1,
  525.   .t2 {
  526.     color: #fff !important;
  527.   }
  528. }
  529. .Color_l {
  530.   border-radius: 140px 0 0 140px;
  531.   width: 100% !important;
  532. }
  533. .Color_z {
  534.   border-radius: 0 0 0 0;
  535.   width: 100% !important;
  536. }
  537. // .Color_z::before {
  538. //   content: "";
  539. //   position: absolute;
  540. //   top: 0;
  541. //   left: 0;
  542. //   width: 100%;
  543. //   height: 100%;
  544. //   background-color: rgba(0, 0, 0, 0.1);
  545. //   /* 半透明覆盖层 */
  546. //   z-index: 1;
  547. // }
  548. .Color_r {
  549.   border-radius: 0 140px 140px 0;
  550.   width: 100% !important;
  551. }
  552. .t1 {
  553.   font-weight: bold;
  554.   font-size: 20px !important;
  555. }
  556. .t2 {
  557.   font-size: 12px !important;
  558. }</style>
复制代码

学习内容:

提示:这里可以添加要学的内容
例如:

  • 搭建 Java 开发环境
  • 掌握 Java 根本语法
  • 掌握条件语句
  • 掌握循环语句

学习时间:

提示:这里可以添加计划学习的时间
例如:


  • 周一至周五晚上 7 点—晚上9点
  • 周六上午 9 点-上午 11 点
  • 周日下午 3 点-下午 6 点

学习产出:

提示:这里统计学习计划的总量
例如:


  • 技术条记 2 遍
  • CSDN 技术博客 3 篇
  • 习的 vlog 视频 1 个

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

干翻全岛蛙蛙

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表