web123456

vue implements a date selector, showing only dates from Monday to Friday

  • data() {
  • return {
  • timeValue: "",
  • teheadList: ["day", "one", "two", "three", "Four", "five", "six"],
  • year: "",
  • month: 0,
  • day: "",
  • tbodyList: [],
  • currentDay: "",
  • show:false
  • };
  • },
  • mounted() {
  • this.getInitTime();
  • },
  • watch: {
  • month() {
  • if (this.month < 1) {
  • this.month = 12;
  • this.year--;
  • } else if (this.month > 12) {
  • this.month = 1;
  • this.year++;
  • }
  • this.tbodyList = [];
  • this.timeValue = this.year + "Year" + this.month + "moon";
  • this.handleAetCalendar();
  • },
  • },
  • methods: {
  • getInitTime() {
  • let date = new Date();
  • this.year = date.getFullYear(); // Get the year
  • this.month = date.getMonth() + 1; // Get this month
  • this.day = date.getDate(); // Get the day
  • this.timeValue = date.getFullYear() + "Year" + (date.getMonth() + 1) + "moon";
  • this.handleAetCalendar();
  • },
  • // Generate period data
  • handleAetCalendar() {
  • this.tbodyList = [];
  • let days = new Date(this.year, this.month, 0).getDate(); // Total days in the month
  • let week = new Date(this.year, this.month - 1, 1).getDay(); // How many weeks are there in the month
  • let last_month = new Date(this.year, this.month + 1, 0).getDate(); // Last day of the previous month of the month
  • console.log("nn", this.tbodyList);
  • this.tbodyList[0] = [];
  • for (let i = 0; i < Math.ceil((days + week) / 7) * 7; i++) {
  • let nub = Math.floor(i / 7);
  • if (i < week) {
  • // ('nub',nub,[nub]);
  • this.tbodyList[nub].push({
  • class: "default",
  • name: last_month + i - week + 1,
  • month: this.month == 0 ? 12 : this.month - 1,
  • });
  • } else {
  • if (!this.tbodyList[nub]) {
  • this.tbodyList[nub] = [];
  • }
  • let day = i - week + 1;
  • let calssName = "actives";
  • let month = this.month;
  • if (day > days) {
  • day -= days;
  • calssName = "default";
  • month = this.month + 1 > 12 ? 1 : this.month + 1;
  • }
  • this.tbodyList[nub].push({
  • class: calssName,
  • name: day,
  • month: month,
  • });
  • }
  • }
  • let arr = this.tbodyList[Math.floor((week + days) / 7)];
  • if (arr && arr.length !== 7) {
  • this.tbodyList[Math.floor((week + days) / 7)] = arr.concat(
  • new Array(7 - arr.length).fill("")
  • );
  • }
  • },
  • },