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

vue實現動態(tài)課程表(TimeTable)

這篇具有很好參考價值的文章主要介紹了vue實現動態(tài)課程表(TimeTable)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

效果圖

vue實現課程表,vue2-功能,vue.js,javascript,前端

?

功能:

(1)動態(tài)生成課程節(jié)數、時間周期? ? ? ?

(2)遇到學科相等的可進行行合并、已解決合并后表格變形問題

使用到的插件:

(1)moment文章來源地址http://www.zghlxwxcb.cn/news/detail-756497.html

Timetable.js

let weekCourse = [
  {
    week: 0,
    courses: [
      {
        index: 1,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "高等數學", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 3,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "語文", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
    ],
  },
  {
    week: 1,
    courses: [
      {
        index: 1,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "物理", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 2,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "高等數學", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 3,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "語文", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 4,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "大學英語", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 5,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "Vue", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 6,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "Vue", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 7,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "Java", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 8,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "數據結構與算法", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 9,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "React", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 10,
        startTime: "09:30", //開始時間
        endTime: "09:30", //結束時間
        subject: "Php", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 11,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "Php", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
    ],
  },
  {
    week: 2,
    courses: [
      {
        index: 5,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "物理", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 8,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "語文", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
    ]
  },
  {
    week: 3,
    courses: [
      {
        index: 1,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "物理", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 2,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "物理", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 3,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "語文", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
    ],
  },
  {
    week: 4,
    courses: [
      {
        index: 1,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "物理", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 3,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "語文", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
    ],
  },
  {
    week: 5,
    courses: [
      {
        index: 4,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "物理", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 3,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "語文", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
    ],
  },
  {
    week: 6,
    courses: [
      {
        index: 2,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "物理", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
      {
        index: 11,
        startTime: "08:00", //開始時間
        endTime: "09:30", //結束時間
        subject: "語文", //學科
        major: "計算機科學與技術", //專業(yè)
        class: "1702班", //班級
      },
    ],
  },

]//課程詳細信息
let colorList = [
  "#4BBDEE",
  "#E86EEB",
  "#4BBDEE",
  "#13DAC2",
  "#7464FB",
  "#F18141",
  "#57C946",
  "#E8BE2A",
  "#508AFA",
]
export {
  weekCourse, colorList
}

Timetable.vue

<template>
  <div class="timetable w100 h100">
    <div class="time-b w100">
      <div class="time-detail">{{ startTime }} - {{ endTime }}</div>
      <div class="time-controller">
        <el-button-group>
          <el-button
            type="primary"
            icon="el-icon-arrow-left"
            @click="changeCount(1), getWeek(count)"
          ></el-button>
          <el-button round class="date-btn">本周</el-button>
          <el-button
            type="primary"
            icon="el-icon-arrow-right"
            @click="changeCount(-1), getWeek(count)"
          ></el-button>
        </el-button-group>
      </div>
    </div>
    <div class="timetable-b w100">
      <table class="timetable-content w100">
        <thead>
          <tr>
            <th></th>
            <!-- <th>周一</th>
            <th>周二</th>
            <th>周三</th>
            <th>周四</th>
            <th>周五</th>
            <th>周六</th>
            <th>周日</th> -->
            <th v-for="(item1, index1) in weeks" :key="index1">
              {{ "周" + numberToChinease(item1 + 1, "week") }}
            </th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item2, index2) in maxCourseLength" :key="index2">
            <td>
              <p>{{ "第" + numberToChinease(item2) + "節(jié)" }}</p>
            </td>
            <template v-for="(item3, index3) in weeks">
              <td
                :key="index3"
                :rowspan="
                  showData(index3, index2 + 1).subject &&
                  showData(index3, index2).subject ===
                    showData(index3, index2 + 1).subject
                    ? 2
                    : ''
                "
                :style="[
                  {
                    display:
                      showData(index3, index2 - 1).subject &&
                      showData(index3, index2 - 1).subject ===
                        showData(index3, index2).subject
                        ? 'none'
                        : '',
                  },
                ]"
              >
                <div
                  class="dmsjandjs-b"
                  :style="[
                    {
                      background: showData(index3, index2).index
                        ? getRandomColor()
                        : '#FFFFFF',
                    },
                    { color: '#fff' },
                    { borderRadius: '15px' },
                    { padding: '12px' },
                    { height: '100%' },
                  ]"
                >
                  <p>
                    {{ showData(index3, index2).startTime }}
                    {{ showData(index3, index2).startTime ? "-" : "" }}
                    {{ showData(index3, index2).endTime }}
                  </p>
                  <p>{{ showData(index3, index2).subject }}</p>
                  <p>{{ showData(index3, index2).major }}</p>
                  <p>{{ showData(index3, index2).class }}</p>
                </div>
              </td>
            </template>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import { weekCourse, colorList } from "./Timetable";
export default {
  data() {
    return {
      startTime: "2022.10.17",
      endTime: "2022.10.23",
      colorList: [], //隨機顏色
      weekCourse: [], // 課程詳細課程、數量
      weeks: [], //頭部周期
      maxCourseLength: 0, //最大課節(jié)數,
      count: 0, //上周、下周、本周選擇器flag
    };
  },
  created() {
    this.weekCourse = weekCourse;
    this.colorList = colorList;
    this.sortData();
    this.init();
    this.getWeek(0);
  },
  methods: {
    //改變選擇器次數
    changeCount(i) {
      this.count += i;
      return this.count;
    },
    // 排序周期和課數
    sortData() {
      //周期
      this.weekCourse.sort((a, b) => {
        return a.week - b.week;
      });
      this.weekCourse.forEach((item) => {
        for (const key in item) {
          if (key === "courses") {
            item[key].sort((a, b) => {
              return a.index - b.index;
            });
          }
        }
      });
    },
    // 初始化課數(courses)與天數(week)
    init() {
      this.weeks = []; //周集合
      this.maxCourseLength = 0;
      this.weeks = this.weekCourse.map((item, index) => {
        for (const key in item) {
          if (key === "courses") {
            let max = 0; //
            //取出一周中最大的課節(jié)數及當天的最大課節(jié)數
            for (let j of item[key]) {
              j.index > this.maxCourseLength &&
                (this.maxCourseLength = j.index); //取所有一周里最大課節(jié)值
              j.index > max && (max = j.index); //取當天最大課節(jié)值
            }
            // console.log("max:", max);

            //如果當天的課節(jié)總數小于當天的最大課節(jié)值
            if (item[key].length < max) {
              //以最大課節(jié)值為終點遍歷當天課節(jié)
              for (let i = 0; i < max; i++) {
                //如果下標課節(jié)不存在或著與循環(huán)的下標不匹配
                if (!item[key][i] || item[key][i].index != i + 1) {
                  item[key].splice(i, 0, " "); //填充空課節(jié)
                }
              }
            }
          }
        }
        return item.week;
      });
    },

    /**
     * 處理數據
     * @param { Number } weekIndex 周幾對應的下標
     * @param { Number }  courseNum  第幾節(jié)課對應的下標
     * @returns { String }   返回對應字符
     */
    showData(weekIndex, courseNum) {
      if (
        this.weekCourse[weekIndex] &&
        this.weekCourse[weekIndex].courses[courseNum] &&
        this.weekCourse[weekIndex].courses[courseNum].index === courseNum + 1
      ) {
        // this.getRandomColor();
        return this.weekCourse[weekIndex].courses[courseNum];
      }
      return false;
    },

    /**
     * 數字轉中文
     * @param { Number } n 需轉換的數字
     * @param { Boolean }  identifier  標識符
     * @returns { String }  identifier  轉換后的中文
     */
    numberToChinease(n, identifier) {
      const chnArr = [
        "零",
        "一",
        "二",
        "三",
        "四",
        "五",
        "六",
        "七",
        "八",
        "九",
        "十",
        "十一",
        "十二",
      ];
      return identifier === "week" && (n === 0 || n === 7) ? "日" : chnArr[n];
    },

    //隨機獲取顏色
    getRandomColor() {
      let colorList = this.colorList;
      let colorRandom = Math.floor(Math.random() * colorList.length + 1) - 1;
      let color;
      for (let i = 0; colorList.length > i; i++) {
        if (i == colorRandom) {
          color = colorList[i];
        }
      }
      return color;
    },

    //隨機上、本、下周 日期
    getWeek(i) {
      let weekOfDay = parseInt(moment().format("E")); //計算今天是這周第幾天
      let last_monday = moment()
        .subtract(weekOfDay + 7 * i - 1, "days")
        .format("YYYY-MM-DD"); //周一日期
      let last_sunday = moment()
        .subtract(weekOfDay + 7 * (i - 1), "days")
        .format("YYYY-MM-DD"); //周日日期
      this.startTime = last_monday;
      this.endTime = last_sunday;
    },
  },
};
</script>

<style scoped lang="scss">
.timetable {
  background-color: #f1f7ff;
  .w100 {
    width: 100% !important;
  }
  .h100 {
    height: 100% !important;
  }
  .time-b {
    height: 46px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .time-detail {
      color: #333333;
      font-weight: 700;
      font-size: 20px;
      font-family: "Microsoft YaHei";
    }
  }
  .timetable-b {
    height: 1207px;
    background-color: #fff;
    overflow: auto;
    .timetable-content {
      height: 100%;
      table-layout: fixed;
      border-collapse: collapse; //設置表格的邊框是否被合并為一個單一的邊框
      text-align: center;
      color: #333333;
      font-weight: 400;
      font-size: 18px;

      thead {
        height: 100px;

        th {
          border: 2px solid rgba(27, 100, 240, 0.1);
        }
      }
      tbody {
        height: calc(100% - 2px) / 7;

        td {
          padding: 12px;
          border: 2px solid rgba(27, 100, 240, 0.1);
          .dmsjandjs-b {
            display: flex;
            flex-direction: column;
            justify-content: center;
          }
        }
      }
    }
  }
}
::v-deep {
  .time-controller {
    .el-button-group {
      .el-button {
        height: 46px;
        background: #ffffff;
        font-size: 18px;
        font-weight: 600;
        border: 1px solid rgba(27, 100, 240, 0.1);
        border-radius: 55px;
        color: #1b64f0;
      }
      :nth-child(2) {
        margin: 0px 12px;
      }
    }
  }
}
</style>

到了這里,關于vue實現動態(tài)課程表(TimeTable)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 自制課程表小程序

    自制課程表小程序

    微信開發(fā)者工具:穩(wěn)定版 Stable Build 根據自己電腦的系統(tǒng)下載對應的版本 完整代碼連接: https://pan.baidu.com/s/1VbgPOS6CUOae8vg2axhGIg?pwd=hk9e 提取碼:hk9e 先把完整代碼的壓縮包解壓,并記住這個路徑,后面要用 1.打開下載好的微信開發(fā)工具, 注意不要用游客登錄 ,我一開始就是游客

    2024年02月09日
    瀏覽(37)
  • leetcode207. 課程表

    你這個學期必須選修 numCourses 門課程,記為 0 到 numCourses - 1 。 在選修某些課程之前需要一些先修課程。 先修課程按數組 prerequisites 給出,其中 prerequisites[i] = [ai, bi] ,表示如果要學習課程 ai 則 必須 先學習課程 bi 。 例如,先修課程對 [0, 1] 表示:想要學習課程 0 ,你需要先

    2023年04月24日
    瀏覽(21)
  • 210. 課程表 II Python

    現在你總共有 numCourses 門課需要選,記為 0 到 numCourses - 1 。給你一個數組 prerequisites ,其中 prerequisites[i] = [ai, bi] ,表示在選修課程 ai 前 必須 先選修 bi 。 返回你為了學完所有課程所安排的學習順序。可能會有多個正確的順序,你只要返回 任意一種 就可以了。如果不可能完

    2024年02月14日
    瀏覽(17)
  • leetcode 630. 課程表 III

    這里有 n 門不同的在線課程,按從 1 到 n 編號。給你一個數組 courses ,其中 courses[i] = [durationi, lastDayi] 表示第 i 門課將會 持續(xù) 上 durationi 天課,并且必須在不晚于 lastDayi 的時候完成。 你的學期從第 1 天開始。且不能同時修讀兩門及兩門以上的課程。 返回你最多可以修讀的課

    2024年02月16日
    瀏覽(12)
  • 【圖論】Leetcode 207. 課程表【中等】

    你這個學期必須選修 numCourses 門課程,記為 0 到 numCourses - 1 。 在選修某些課程之前需要一些先修課程。 先修課程按數組 prerequisites 給出,其中 prerequisites[i] = [ai, bi] ,表示如果要學習課程 ai 則 必須 先學習課程 bi 。 例如,先修課程對 [0, 1] 表示:想要學習課程 0 ,你需要先

    2024年04月14日
    瀏覽(24)
  • 刷題筆記25——圖論課程表

    為了最終理解你所不理解的,你必須經歷一條愚昧無知的道路。為了占有你從未占有的東西,你必須經歷被剝奪的道路。為了達到你現在所不在的名位,你必須經歷那條你不在其中的道路?!蕴?非常奇妙,我最初的錯誤是如下,在找到目標節(jié)點后直接加入到res中,但是

    2024年02月07日
    瀏覽(12)
  • HTML入門用標簽寫一個課程表

    HTML入門用標簽寫一個課程表

    完成樣式 相關筆記

    2024年01月19日
    瀏覽(21)
  • 【LeetCode】210. 課程表 II——拓撲排序

    【LeetCode】210. 課程表 II——拓撲排序

    題目鏈接:210. 課程表 II 題目描述: 現在你總共有 numCourses 門課需要選,記為 0 到 numCourses - 1。給你一個數組 prerequisites ,其中 prerequisites[i] = [ai, bi] ,表示在選修課程 ai 前 必須 先選修 bi 。 例如,想要學習課程 0 ,你需要先完成課程 1 ,我們用一個匹配來表示:[0,1] 。 返

    2024年02月09日
    瀏覽(21)
  • 前端drag api課程表demo

    HTML CSS JS

    2024年02月07日
    瀏覽(15)
  • 【LeetCode: 210. 課程表 II:拓撲排序+圖】

    【LeetCode: 210. 課程表 II:拓撲排序+圖】

    ?? 算法題 ?? ?? 算法刷題專欄 | 面試必備算法 | 面試高頻算法 ?? ?? 越難的東西,越要努力堅持,因為它具有很高的價值,算法就是這樣? ?? 作者簡介:碩風和煒,CSDN-Java領域優(yōu)質創(chuàng)作者??,保研|國家獎學金|高中學習JAVA|大學完善JAVA開發(fā)技術棧|面試刷題|面經八股文

    2024年02月09日
    瀏覽(28)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領取紅包

二維碼2

領紅包