国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue+elementui實(shí)現(xiàn)12個(gè)日歷平鋪,初始化工作日,并且可點(diǎn)擊

這篇具有很好參考價(jià)值的文章主要介紹了vue+elementui實(shí)現(xiàn)12個(gè)日歷平鋪,初始化工作日,并且可點(diǎn)擊。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="年份" prop="holidayYear">
        <el-date-picker
          v-model="queryParams.holidayYear"
          type="year"
          :clearable="false"
          placeholder="選擇年"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row>
      <el-button type="primary" @click="submitClickedDates">提交</el-button>

      <div v-for="(cal, index) in defaultCals" :key="index">
        <el-col :span="6">
          <el-calendar :value="cal" class="holiday">
            <template slot="dateCell" slot-scope="{ date, data }">
              <div
                class="holiday-cell"
                v-show="data.type === 'current-month'"
                :id="cal.getMonth() + '-' + data.day"
                @click="selectCalendarDate(cal, data)"
                :style="{ backgroundColor: getCellBackgroundColor(cal, data) }"
              >
                {{ data.day.split("-")[2] }}
              </div>
            </template>
          </el-calendar>
        </el-col>
      </div>
    </el-row>
  </div>
</template>

<script>
export default {
  // name: "temp",
  data() {
    return {
      queryParams: {
        holidayYear: new Date(),
      },
      //設(shè)置的月份
      defaultCals: [],
      // 全年已選中的日期
      holidayDate: [],
      clickedDates: [], // 記錄點(diǎn)擊的日期
      selectedDates: [], // 初始選中的日期數(shù)組
    };
  },
  created() {
    //初始化日歷
    let nowYear = new Date().getFullYear();
    this.initCalendar(nowYear + 1);

    // 初始化日歷
    // let nowYear = new Date().getFullYear();
    // this.currentMonth = new Date(); // 明確初始化this.currentMonth
    // this.initCalendar(nowYear + 1);
  },
  methods: {
    // 根據(jù)給定的年份獲取一年中周一到周五的日期數(shù)組
    getWeekdays(year) {
      const weekdays = [];
      const currentDate = new Date(year, 0, 1); // 設(shè)置為給定年份的第一天

      // 遍歷一年中的每一天
      while (currentDate.getFullYear() === year) {
        const dayOfWeek = currentDate.getDay();

        // 如果是周一到周五,將日期格式化并添加到數(shù)組中
        if (dayOfWeek >= 1 && dayOfWeek <= 5) {
          const formattedDate = `${currentDate.getFullYear()}-${(
            currentDate.getMonth() + 1
          )
            .toString()
            .padStart(2, "0")}-${currentDate
            .getDate()
            .toString()
            .padStart(2, "0")}`;
          weekdays.push(formattedDate);
        }

        // 將日期增加一天
        currentDate.setDate(currentDate.getDate() + 1);
      }

      return weekdays;
    },
    //初始化日歷
    initCalendar(year) {
      this.defaultCals = [
        new Date(year, 0, 1),
        new Date(year, 1, 1),
        new Date(year, 2, 1),
        new Date(year, 3, 1),
        new Date(year, 4, 1),
        new Date(year, 5, 1),
        new Date(year, 6, 1),
        new Date(year, 7, 1),
        new Date(year, 8, 1),
        new Date(year, 9, 1),
        new Date(year, 10, 1),
        new Date(year, 11, 1),
      ];

      //調(diào)接口獲取
      this.holidayDate = this.getWeekdays(year);
      console.log(this.holidayDate);
      // 轉(zhuǎn)化為對(duì)象數(shù)組
      const formattedDates = this.holidayDate.map((date) => {
        const dateObj = new Date(date);
        return {
          cal: dateObj,
          data: {
            day: date,
            isSelected: false,
            type: "current-month",
          },
        };
      });
      console.log(formattedDates);
      console.log("chushihua");
      this.clickedDates = formattedDates;

      this.$nextTick(() => {
        let holidayCell = document.getElementsByClassName("holiday-cell");
        for (let i in holidayCell) {
          if (undefined != holidayCell[i].style) {
            holidayCell[i].style.backgroundColor = "#FFFFFF";
          }
        }
        //給已選中的日期加背景色
        for (let i in this.holidayDate) {
          const month = parseInt(this.holidayDate[i].split("-")[1]) - 1;
          let span = document.getElementById(month + "-" + this.holidayDate[i]);
          span.style.backgroundColor = "#F56C6C";
        }
      });
    },
    /** 搜索按鈕操作 */
    handleQuery() {
      let year = this.queryParams.holidayYear.getFullYear();
      this.initCalendar(year);
    },
    /** 重置按鈕操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.holidayYear = new Date();
      this.handleQuery();
    },

    // 獲取日期單元格的背景顏色
    getCellBackgroundColor(cal, data) {
      console.log("獲取日期單元格的背景顏色");
      const clickedDate = this.clickedDates.find((clickedDate) => {
        return (
          clickedDate.cal.getFullYear() === cal.getFullYear() &&
          clickedDate.cal.getMonth() === cal.getMonth() &&
          clickedDate.data.day === data.day
        );
      });

      return clickedDate ? "#F56C6C" : "#FFFFFF";
    },

    // 點(diǎn)擊日期單元格的事件
    selectCalendarDate(cal, data) {
      const clickedDateIndex = this.clickedDates.findIndex((clickedDate) => {
        console.log(clickedDate);

        return (
          clickedDate.cal.getFullYear() === cal.getFullYear() &&
          clickedDate.cal.getMonth() === cal.getMonth() &&
          clickedDate.data.day === data.day
        );
      });
      if (clickedDateIndex !== -1) {
        // 如果日期已經(jīng)被點(diǎn)擊過,移除記錄并取消背景色
        this.clickedDates.splice(clickedDateIndex, 1);
      } else {
        // 否則,記錄點(diǎn)擊的日期
        this.clickedDates.push({ cal, data });
      }
      console.log(this.clickedDates);
    },
    // 提交按鈕點(diǎn)擊事件
    submitClickedDates() {
      const formattedDates = this.clickedDates.map((clickedDate) => {
        const date = clickedDate.data.day;
        const formattedDate = `${clickedDate.cal.getFullYear()}-${
          date.split("-")[1]
        }-${date.split("-")[2]}`;
        return formattedDate;
      });

      // 在這里處理格式化后的日期數(shù)組
      console.log("Formatted Dates:", formattedDates);

      // let dates = ['2025-01-01', '2025-01-06', '2025-01-07', '2025-01-08', '2025-01-10'];

      // 將日期字符串轉(zhuǎn)換為 Date 對(duì)象
      // let dateObjects = dates.map(dateString => new Date(dateString));

      // // 按照 Date 對(duì)象進(jìn)行排序
      // dateObjects.sort((a, b) => a - b);

      // // 將排序后的 Date 對(duì)象轉(zhuǎn)換回日期字符串
      // let sortedDates = dateObjects.map(date => date.toISOString().split('T')[0]);

      // console.log(sortedDates);
    },
  },
};
</script>

<style>
.holiday .el-calendar__button-group {
  display: none;
}

.select-month .el-calendar__button-group {
  display: none;
}

.holiday .el-calendar-day {
  padding: 1px;
  width: 100%;
  height: 34px;
}

.select-month .el-calendar-day {
  padding: 1px;
  width: 100%;
}

.holiday-cell {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>


vue+elementui實(shí)現(xiàn)12個(gè)日歷平鋪,初始化工作日,并且可點(diǎn)擊,vue.js,elementui,前端文章來源地址http://www.zghlxwxcb.cn/news/detail-804607.html

到了這里,關(guān)于vue+elementui實(shí)現(xiàn)12個(gè)日歷平鋪,初始化工作日,并且可點(diǎn)擊的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue中初始化

    主要是掛載一些全局方法 響應(yīng)數(shù)據(jù)相關(guān)的Vue.set, Vue.delete, Vue.nextTick以及Vue.observable 插件相關(guān)的Vue.use 對(duì)象合并相關(guān)Vue.mixin 類繼承相關(guān)的Vue.extend 資源相關(guān),如組件,過濾器,自定義指令Vue.component, Vue.filter, Vue.directive 配置相關(guān)Vue.config以及Vue.options中的components,filters,directives 定

    2023年04月22日
    瀏覽(37)
  • 一、D3D12學(xué)習(xí)筆記——初始化Direct3D

    工廠類IDXGIFactory4,這個(gè)類有兩個(gè)作用: 1.枚舉適配器(顯卡); 2.創(chuàng)建交換鏈 這個(gè)類對(duì)象的創(chuàng)建如下: 用這個(gè)對(duì)象mdxgiFactory枚舉我們可以使用的顯卡等適配器: 對(duì)于一個(gè)選定的適配器pIAdapter,拿著它去創(chuàng)建設(shè)備 IID_PPV_ARGS這個(gè)宏實(shí)際包含了兩個(gè)東西,uuid的COM ID和對(duì)象的指針

    2024年02月10日
    瀏覽(20)
  • Vue初始化項(xiàng)目加載邏輯

    Vue初始化項(xiàng)目加載邏輯

    項(xiàng)目創(chuàng)建 我們只需要?jiǎng)?chuàng)建項(xiàng)目即可,剩余的依賴都沒必要安裝 我們先來看main.js,咱們加了一行備注 通過備注可知,我們首先加載的是App.vue 我們?cè)賮砜匆幌翧pp.vue 里都有啥 也就是下面這個(gè)紅框里的內(nèi)容才是 那下面的內(nèi)容是哪里來的呢 那就需要看一下路由設(shè)置了 我們看到/目

    2024年02月08日
    瀏覽(24)
  • d3d12龍書閱讀----Direct3D的初始化

    使用d3d我們可以對(duì)gpu進(jìn)行控制與編程,以硬件加速的方式來完成3d場(chǎng)景的渲染,d3d層與硬件驅(qū)動(dòng)會(huì)將相應(yīng)的代碼轉(zhuǎn)換成gpu可以執(zhí)行的機(jī)器指令,與之前的版本相比,d3d12大大減少了cpu的開銷,同時(shí)也改進(jìn)了對(duì)多線程的支持,但是使用的api也更加復(fù)雜。 接下來,我們將先介紹在

    2024年03月12日
    瀏覽(19)
  • DirectX12_Windows_GameDevelop_3:Direct3D的初始化

    DirectX12_Windows_GameDevelop_3:Direct3D的初始化

    查看龍書時(shí)發(fā)現(xiàn), 第四章介紹預(yù)備知識(shí)的代碼不太利于學(xué)習(xí) 。因?yàn)樗幌袷荓earnOpenGL那樣從頭開始一步一步教你敲代碼,導(dǎo)致你沒有一種整體感。 如果你把它當(dāng)作某一塊的代碼進(jìn)行學(xué)習(xí),你跟著敲會(huì)發(fā)現(xiàn),總有幾個(gè)變量是沒有定義的。這是因?yàn)闀系拇a都是把框架里的某

    2024年02月08日
    瀏覽(28)
  • 國(guó)民技術(shù)N32G430開發(fā)筆記(12)- IAP升級(jí) Settings區(qū)域數(shù)據(jù)初始化

    國(guó)民技術(shù)N32G430開發(fā)筆記(12)- IAP升級(jí) Settings區(qū)域數(shù)據(jù)初始化

    1、假如,有兩個(gè)產(chǎn)品,A產(chǎn)品跟B產(chǎn)品,硬件都一樣,要求一個(gè)軟件里的board_name為N32G430C8L7_STB_A,另一個(gè)軟件里的board_name為N32G430C8L7_STB_B。 那我們?nèi)绾卧诓桓腷oot程序跟App程序的基礎(chǔ)上,快速的使兩個(gè)軟件看上去不同呢? 這里我們將setting區(qū)域的數(shù)據(jù)提前初始化,通過c語言的文

    2024年02月01日
    瀏覽(27)
  • Vue 新版 腳手架 初始化 筆記

    Vue2/Vue3 修改 node 更新源 將默認(rèn)的 更新源修改為 淘寶的 下載地址 安裝 一般 新版 Vue 腳手架不可以共存 所以如果有 舊版的腳手架 會(huì)提示你 需要卸載 原來的腳手架 然后重新執(zhí)行上面的安裝 安裝好之后 就可以去初始化項(xiàng)目了 值得一提的是我在官方的文檔中找到了一個(gè) 在使

    2024年02月20日
    瀏覽(45)
  • 1、前端項(xiàng)目初始化(vue3)

    1、前端項(xiàng)目初始化(vue3)

    安裝npm,(可以用nvm管理npm版本)npm安裝需要安裝node.js(綁定銷售?)而使用nvm就可以很方便的下載不同版本的node,這里是常用命令 配置npm源 命令: 設(shè)置鏡像源: npm config set registry https://registry.npm.taobao.org 查看當(dāng)前使用的鏡像地址: npm config get registry 參考 :https://www.cnbl

    2024年01月20日
    瀏覽(26)
  • 初始化vue中data中的數(shù)據(jù)

    初始化vue中data中的數(shù)據(jù)

    當(dāng)組件的根元素使用了v-if的時(shí)候, 并不會(huì)初始化data中的數(shù)據(jù) 如果想完全銷毀該組件并且初始化數(shù)據(jù),需要在使用該組件的本身添加v-if 或者是手動(dòng)初始化該組件中的數(shù)據(jù) 下面詳細(xì)說說Object.assign的用法: ES6的官方文檔的解釋是:Object.assign() 方法用于將所有可枚舉屬性的值從一

    2024年02月05日
    瀏覽(18)
  • Vue3+Vite 初始化Cesium

    git

    2024年02月11日
    瀏覽(16)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包