# pc端個性化日曆實現

来源:https://www.cnblogs.com/status404/archive/2019/04/15/10711053.html
-Advertisement-
Play Games

pc端個性化日曆實現 技術:vue = v for、slot scop 插槽域 需求:需要實現日曆上每一天動態顯示不同的信息 思路:運用vue 中 slot scop 插槽域的知識點,將個性化的代碼樣式放到slot中 再通過slot scop 獲取這個插槽中的所需數據 一、實現日曆組件 思路:佈局上 ...


pc端個性化日曆實現

技術:vue => v-for、slot-scop 插槽域
需求:需要實現日曆上每一天動態顯示不同的信息
思路:運用vue 中 slot-scop 插槽域的知識點,將個性化的代碼樣式放到slot中 再通過slot-scop 獲取這個插槽中的所需數據

一、實現日曆組件

思路:佈局上就是一個7列,行數不確定的表格。只不過,日曆的表格是寬和高相等,隨著瀏覽器的大小變化,表格大大小也要變化,所以要用padding佈局,難點在日期數組的生成上面。
1.佈局的實現
<div class="calendar">
    <div class="calendar-operation">
        <span class="calendar-title">{{title}}</span>
        <div class="calendar-YearMonth">
           <Icon type="ios-arrow-back" style="margin-right:30px;" @click="prev" />
           <div class="calendar-YearMonth-content">{{YearMonth}}</div>
           <Icon type="ios-arrow-forward" style="margin-left:30px;color:" @click="next" />
        </div>****
    </div>
    <div class="calendar-head">
        <div class="calendar-head-item">星期日</div>
        <div class="calendar-head-item">星期一</div>
        <div class="calendar-head-item">星期二</div>
        <div class="calendar-head-item">星期三</div>
        <div class="calendar-head-item">星期四</div>
        <div class="calendar-head-item">星期五</div>
        <div class="calendar-head-item">星期六</div>
    </div>
    <div class="calendar-content">
        <div v-for="(item,index) in dateArray" :key="index" class="calendar-row">
            <div v-for="(val,key) in item" :key="key" :class="{'calendar-cols':true,'calendar-enable':!val.enable}">
                <span class="calendar-cols-content">{{val.value}}</span>
                <div class="calendar-cols-opera" >
                    <div style="height:100%;">
                        <slot :oper = 'val.oper'></slot>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<style scoped lang="less">
.calendar{
    width:100%;
    border:1px solid #e8eaec;
    border-left: 0;
    border-radius: 8px;
    background: #fff;
    .calendar-operation {
        height: 60px;
        border-bottom: 1px solid #e8eaec;
        border-left:1px solid #e8eaec;
        .calendar-title{
            display:block;
            font-size:12px;
            color:#fb9153;
            float: left;
            height: 100%;
            line-height:60px;
            padding-left: 40px;
        }
        .calendar-YearMonth{
            display: flex;
            height: 100%;
            justify-content: center;
            align-items: center;
            font-size:17px;
            color: #fb9153;
        }
    }
    .calendar-head {
        display: flex;
        height:40px;
        border-bottom: 1px solid #e8eaec;
        border-left:1px solid #e8eaec;
        .calendar-head-item {
            flex: 1;
            height:100%;
            line-height:40px;
            font-size: 12px;
            text-align: center;
            border-left: 1px solid #e8eaec;
        }
    }
    .calendar-content {
        width: 100%;
        .calendar-row{
            width:100%;
            display: flex;
            .calendar-cols {
                position: relative;
                flex: 1;
                height: 0;
                padding-bottom: 14%;
                border-bottom: 1px solid #e8eaec;
                border-left: 1px solid #e8eaec;
                .calendar-cols-content{
                    display:block;
                    text-align: right;
                    height:0;
                    padding-bottom: 15%;
                    box-sizing: border-box;
                    padding: 0 10px;
                    margin-bottom: 15%;
                }
                .calendar-cols-opera{
                    width:100%;
                    height: 0;
                    padding-bottom: 84%;
                    box-sizing: border-box;
                    overflow-y: auto;
                }
            }  
        }
        .calendar-enable{
            color: #e8eaec;
        }
    }
}
</style>
2.日曆數組的實現
 思路:獲取當前月有多少天,當月第一天對應的星期。
 實現:如何獲取這個月的天數,通過下一個月的第一天 減去一天時間就是這個月的最後一天,進而能知道這個月的天數
 //獲取當月最後一天
 function getLastDate(year,month) {
    let currentMonth = month - 1
    let nextMonth = currentMonth + 1
    if(nextMonth > 11 ) {
        nextMonth = 0
        year++
    }
    //let nextMonthFisrtDate = new Date(year,nextMonth,1).getDate()
    let lastDate = new Date(new Date(year,nextMonth,1).getTime() - 1000*60*60*24).getDate()
    return lastDate
}
//獲取當月第一天對應的星期
function getFirstDay(year,month) {
    let currentMonth = month - 1
    return new Date(year,currentMonth,1).getDay()
}
//獲取最後一天的星期
function getLastDay(year,month) {
    let currentMonth = month - 1
    return new Date(year,currentMonth,getLastDate(year,month)).getDay()
}
//獲取當月 日期數據 
function getDateArray(yearMonth) {
    let year = parseInt(yearMonth.split('-')[0])
    let month = parseInt(yearMonth.split('-')[1])
    let dateArray = []
    let firstDay =  getFirstDay(year,month,1)
    let lastDate = getLastDate(year,month)
    let lastDateDay = getLastDay(year,month)
    let prevLastDate = getLastDate(year,month - 1)
    //緩存每一行數據
    let newArr = []
    //獲取第一行數據
    for(let i=1;i<=7;i++){
        if(i<=firstDay){
            newArr.push({
                date:'',
                value: prevLastDate - (firstDay-i),
                enable: false,
                oper:{}
            })
            
        }
        else{
            newArr.push({
                date:new Date(year,month-1,i-firstDay).getTime(),
                value:i-firstDay,
                enable: true,
                oper:{}
            })
        }
    }
    dateArray.push(newArr) 
    newArr = [] //清空
    let count = 0
    for (let i=(7-firstDay+1);i<=lastDate;i++){
        if ( count < 7){
            newArr.push({
                date:new Date(year,month-1,i).getTime(),
                value:i,
                enable:true,
                oper:[]
            })
        }
        else{
            dateArray.push(newArr)
            newArr = []
            newArr.push({
                date:new Date(year,month-1,i).getTime(),
                value:i,
                enable:true,
                oper:[]
            })
            count = 0
        }
        if (i == lastDate && count == 6) {
            dateArray.push(newArr)
        }
        count++
    }
    //獲取最後一行
    newArr = []
    if(lastDateDay<6){
        for(let i=0;i<=6;i++){
            if(i<=lastDateDay){
                newArr.push({
                    date:new Date(year,month-1,lastDate-(lastDateDay-i)).getTime(),
                    value:lastDate-(lastDateDay-i),
                    enable:true,
                    oper:[]
                })
            }
            else{
                newArr.push({
                    date:'',
                    value:i-lastDateDay,
                    enable:false,
                    oper:[]
                })
            }
        }
        dateArray.push(newArr) 
    }
    return dateArray;
}

二、個性化日曆使用

<Calendar :operData="operData" @change="calendarChange" :title="title">
        <template slot-scope="slotScope">
            <div v-for="(item,index) in slotScope.oper " :key="index" class="calendar-oper">
               <div class="calendar-oper-tag" :style="{background:tagType[item.type].color}">
                   <span>{{item.visitTypeCode}}</span>
               </div>
               <div class="calendar-oper-time">{{item.time}}</div>
               <div class="calendar-oper-content">{{item.content}}</div>
            </div>
        </template>
    </Calendar>

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 得益於 HTML5 WebGL 技術的成熟,從技術上對工控管理的可視化,數據可視化變得簡單易行!完成對工控設備的管理效率,資源管理,風險管理等的大幅度提高,同時也對國家工業4.0計劃作出有力響應! 如本案例所示,是一個基於 HTML5 WebGL 技術實現的計量站三維可視化監控系統,在本案例中,具... ...
  • JavaScript基礎系列 JavaScript是一種基於對象和事件驅動的客戶端腳本語言。 JavaScript的註釋 JavaScript變數,函數名和操作符都是區分大小寫的。 標識符是變數,函數,屬性的名稱,函數里的參數。 命名規則: 字母,數字,下劃線,美元符號,不能以數字開頭 變數的聲明與 ...
  • 博客園css定製 選擇模板SimplClear 代碼如下: 自學第一周前端,可能有許多不到位之處。請各位大佬指正。。。 參考文獻 1. https://www.cnblogs.com/Penn000/p/6947472.html 2. https://blog.csdn.net/siwuxie095 ...
  • 註:以下屬於個人學習中的理解不能保證全部正確,如果有錯誤以後修正。 1.javascript和c#語言一樣嚴格區分大小寫,有沒有類的概念。 2.所有的變數聲明都使用var,雖然能打出藍色int,但卻不能使用,應該是系統的保留字吧。 3.局部變數有塊域(即花括弧{}),這個域不包含if、for、swi ...
  • function Slider(id){ //屬性 // 1. 通過id獲取元素對象(大盒子) this.bigBox = document.getElementById(id); //2. 獲取出大盒子中的所有圖片(數組) this.ullis = this.bigBox.children[0]. ...
  • [開發技巧]·HTML檢測輸入已完成自動填寫下一個內容 個人網站 --> http://www.yansongsong.cn 在上一個博客中簡易實現檢測輸入已完成,我們實現了檢測輸入已完成,現在我們再進一步,在此基礎上,實現檢測輸入已完成自動填寫下一個內容。當我們需要自動填寫的內容,不希望被更改的時 ...
  • 錯誤原因: 子組件 props -> list 要求接收的數據類型是 Array, 然而實際接收到的是 Undefined。 子組件代碼: 所以檢查父組件傳過來的值,保證傳過來的值是子組件所期望的數據類型即可。 ...
  • //HTML部分 <div class="wrap"></div> <div class="popUpBox"> <div class="layer-head"><div class="layer-head-text">彈出框</div><div class="layer-close"></div> ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...