摘要:基于事件操作的价格日历,适用于端和移动端
基于事件操作的价格日历,适用于PC端和移动端
https://github.com/Fi2zz/date...
Base on event
Easy to display data on html element by using data event
Support double views,flat view and single view
Disabled date can be selected as end date while using setData function
Support Multi selection
RUN DEMOyarn dev or npm run devOPTIONS
OPTION | RERUIRED | TYPE | DESC | DEFAULT VALUE |
---|---|---|---|---|
el | YES | string,HTMLElement | Element or selector to mount DatePcker | |
startDate | NO | Date | Start date of DatePicker | new Date |
endDate | NO | Date | End date of DatePicker | new Date() + 6 months |
doubleSelect | NO | boolean | Enable pick two dates | false |
limit | NO | number | Limitation between two dates while doubleSelect is on | |
views | NO | number,string | Display views of DatePicker | auto,1,2 |
selection | NO | number | Size of dates can be picked ,value must be not less than 2 | 1 |
when `selection` is greater than 2, `bindData` and `doubleSelect` will be set to `false`, and `option.limit` will be set the same as `selection`API
setDates([dates]:tuple); //Set dates to DatePicker //dates acceptUSAGEand setLanguage(language:any); //set DatePicker"s language setData(callback) //set data to DatePicker //more detail see [USAGE] setDisabled({ days?:Array [5], dates?:Array , from?: , to?: }) //Set disabled dates to DataPicker //dates =>dates accept and , all dates in [dates] will be disabled //days => days accept number of [0~6], all days in [days] will be disabled //from => from accept or , all dates after [from] date will be disabled, // eg: from = 2018-3-31 => disabled from 2018-4-1 //to => to accept or all dates before [to] date will be disabled, // eg: to =2018-3-4 => all dates before 2018-3-5 will be disabled parse(formattedDate:string,dateFormat:string) //Transform date string into date object,return Date object //eg: formattedDate ="2018-3-4",format="YYYY-M-D" => new Date(2018,2,4) format(date:Date,format:string) //Transform date object into string,return string //eg: date =new Date(),format="YYYY-MM-DD" => 2018-03-04 on(event:string,fn:Function) //Event listener //eg: datePicker.on("event",(result)=>{ //your logic // })
//es module import DatePicker from "/dist/datepicker.esm.js" import "/dist/style.css" //cjs const DatePicker =require("/dist/datepicker.js"); require("/dist/style.css"); //umd const date = new Date(); const dist = { year: date.getFullYear(), month: date.getMonth(), date: date.getDate() }; const from = new Date(dist.year, dist.month, dist.date) const to = new Date(dist.year, dist.month + 9, 0); const currDate = new Date(dist.year, dist.month, dist.date); //setup DatePicker instance const app = new DatePicker({ el: document.getElementById("datepicker"), endDate:to, startDate:from, limit: 7, format: "YYYY-M-D", doubleSelect: true, views: 1, selection:4 // if selection not less than 2, doubleSelect will be disabled, //and `data` event and `setData` will not work }); //`update` event fired by click on date cell and DatePicker init app.on("update", (result) => { // result contains two keys, `value` and `type` // value => selected dates // type => two types => `init` and `selected` // place your logic here //eg: // document.getElementById("dates").innerText = value }); // `disabled`event fired by `setDisabled` app.on("disabled", (result) => { // result contains two keys, `dateList` and `nodeList` const {dateList, nodeList} = result; for (let n = 0; n < nodeList.length; n++) { let node = nodeList[n]; if (dateList[node.getAttribute("data-date")]) { node.classList.add("disabled") } } }); // "data" event fired by `setData` app.on("data", (result) => { //set HTML nodes states // result contains two keys, `data:any` and `nodeList:Array` const data = result.data; const nodeList = result.nodeList; for (let i = 0; i < nodeList.length; i++) { let node = nodeList[i]; let date = node.getAttribute("data-date"); if (date in data) { if (!node.classList.contains("disabled")) { let itemData = source[date]; if (itemData.highlight) { addClass(node, "highlight") } let placeholder = node.querySelector(".placeholder"); placeholder.innerHTML = itemData.value } } else { addClass(node, "disabled") } } }); //tuple type,accept and const selected=["2018-2-21",new Date()]; //use `setDates` to set init dates to DatePicker instance app.setDates(selected); // use `setDisabled` to set specified date or day to disabled, // `setDisabled` accept an object => {dates,days}, // dates,accept and // >days accept 0,1,2,3,4,5,6 app.setDisabled({ dates: [ "2018-2-18", "2018-2-19", "2018-2-22", new Date ], days: [1, 5, 2, 6], from:new Date(2018,2,10) to:"2018-7-15" }); // To display your data,like price info on date cell, // use `setData` to pass data to `DatePicker` instance // `setData` function will dispatch `data` event // setup a listener to handle it app.setData(() => { const data ={}; /*data accept Object like { "2018-1-31":{/*your codes * }, "2018-2-21":123, } */ //your logic here //return data when your logic done return data }); //set DatePicker"s language //language options const language={ days: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], months: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], year: "" }; app.setLanguage(language)
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/89726.html
摘要:默认可选回调函数,绑定业务数据。例如某天有日程,则会在对应日期上标识出一个小红点或者其他标识,默认传入数据格式必选回调函数,当你点击或轻触某日期后执行。 文档维护者:孙尊路 喜欢的话,记得star 一下噢! 适用场景 该组件目前仅适用于移动端H5页面展示,后期高级用法中会讲述到如何基于日历基类实现自定义模板传入。(即:开发者只需要传入自己的模板即可实现出自己的优美的日历出来。) 本篇...
摘要:百度前端技术学院上有一个任务,要实现一个日期选择组件,本文由此而来看看需求组件默认一直呈显示状态通过某种方式选择年月,选择了年月后,日期列表做相应切换通过单击某个具体的日期进行日期选择组件初始化时,可配置可选日期的上下限。 百度前端技术学院上有一个任务,要实现一个日期选择组件,本文由此而来~ 看看需求 组件默认一直呈显示状态 通过某种方式选择年、月,选择了年月后,日期列表做相应切换 ...
摘要:百度前端技术学院上有一个任务,要实现一个日期选择组件,本文由此而来看看需求组件默认一直呈显示状态通过某种方式选择年月,选择了年月后,日期列表做相应切换通过单击某个具体的日期进行日期选择组件初始化时,可配置可选日期的上下限。 百度前端技术学院上有一个任务,要实现一个日期选择组件,本文由此而来~ 看看需求 组件默认一直呈显示状态 通过某种方式选择年、月,选择了年月后,日期列表做相应切换 ...
摘要:实现代码于文章末尾处构思页面结构组件由输入框和日历面板组成,写好页面主体结构。输入框点击显示或隐藏日历面板方法改变布尔值控制日历面板的显示隐藏。同时,当组件销毁时,也要及时清除该监听器。 最近研究了 DatePicker 的实现原理后做了一个 vue 的 DatePicker 组件,今天带大家一步一步实现 DatePicker 的 vue 组件。 原理 DatePicker 的原理是—...
阅读 1813·2021-10-20 13:49
阅读 1356·2019-08-30 15:52
阅读 2862·2019-08-29 16:37
阅读 1032·2019-08-29 10:55
阅读 3063·2019-08-26 12:14
阅读 1648·2019-08-23 17:06
阅读 3234·2019-08-23 16:59
阅读 2542·2019-08-23 15:42