├── demo ├── 01.png ├── 02.png ├── 03.png ├── 04.png ├── 05.png ├── 06.png ├── 07.png └── 08.png ├── src ├── img │ ├── left-icon.png │ └── right-icon.png ├── dist │ ├── zane-calendar.min.css │ └── zane-calendar.min.js ├── sass │ └── zane-calendar.scss ├── css │ └── zane-calendar.css ├── index.html └── es6 │ └── zane-calendar.js ├── .gitignore ├── package.json ├── gulpfile.js ├── README.md └── dist ├── zane-calendar.min.css └── zane-calendar.min.js /demo/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/demo/01.png -------------------------------------------------------------------------------- /demo/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/demo/02.png -------------------------------------------------------------------------------- /demo/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/demo/03.png -------------------------------------------------------------------------------- /demo/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/demo/04.png -------------------------------------------------------------------------------- /demo/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/demo/05.png -------------------------------------------------------------------------------- /demo/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/demo/06.png -------------------------------------------------------------------------------- /demo/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/demo/07.png -------------------------------------------------------------------------------- /demo/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/demo/08.png -------------------------------------------------------------------------------- /src/img/left-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/src/img/left-icon.png -------------------------------------------------------------------------------- /src/img/right-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangweianger/zane-data-time-calendar/HEAD/src/img/right-icon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | .idea/ 3 | .DS_Store 4 | src/.DS_Store 5 | src/assets/.DS_Store 6 | */.DS_Store 7 | */*/.DS_Store 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zane-calendar", 3 | "version": "2.2.6", 4 | "description": "很全面的时间日历插件选择器", 5 | "homepage": "http://blog.seosiwei.com/detail/8", 6 | "repository": "wangweianger/zane-data-time-calendar", 7 | "author": "zane <752636052@qq.com> (http://blog.seosiwei.com/)", 8 | "main": "index.js", 9 | "scripts": { 10 | "dev": "gulp", 11 | "build": "gulp build" 12 | }, 13 | "keywords": [ 14 | "zane", 15 | "date", 16 | "zane-calendar" 17 | ], 18 | "license": "ISC", 19 | "devDependencies": { 20 | "babel-core": "^6.26.0", 21 | "babel-preset-env": "^1.6.0", 22 | "gulp": "^3.9.1", 23 | "gulp-babel": "^7.0.0", 24 | "gulp-clean": "^0.3.2", 25 | "gulp-clean-css": "^3.8.0", 26 | "gulp-connect": "^5.0.0", 27 | "gulp-rename": "^1.2.2", 28 | "gulp-sass": "^3.1.0", 29 | "gulp-sequence": "^0.4.6", 30 | "gulp-uglify": "^3.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | const gulp = require('gulp') 2 | const babel = require('gulp-babel'); 3 | const sass = require('gulp-sass') 4 | const uglify = require('gulp-uglify') 5 | const minifyCss = require('gulp-clean-css') 6 | const clean = require('gulp-clean') 7 | const connect = require('gulp-connect') 8 | const rename = require('gulp-rename') 9 | const gulpSequence = require('gulp-sequence') 10 | 11 | let baseRrl = './src/' 12 | 13 | gulp.task('connect', function() { 14 | connect.server({ 15 | port: 8888, 16 | root: baseRrl, 17 | livereload: true 18 | }); 19 | }); 20 | 21 | gulp.task('html', function () { 22 | gulp.src(baseRrl+'*.html') 23 | .pipe(connect.reload()); 24 | }); 25 | 26 | gulp.task('watch', function () { 27 | gulp.watch([baseRrl+'*.html'], ['html']); 28 | gulp.watch([baseRrl+'sass/*.scss'], ['sass','html']); 29 | gulp.watch([baseRrl+'es6/*.js'], ['babel','html']); 30 | }); 31 | 32 | gulp.task('sass', function () { 33 | return gulp.src(baseRrl+'sass/*.scss') 34 | .pipe(sass().on('error', sass.logError)) 35 | .pipe(gulp.dest(baseRrl+'css')); 36 | }); 37 | 38 | gulp.task('babel', () => 39 | gulp.src(baseRrl+'es6/*.js') 40 | .pipe(babel({ 41 | presets: ['env'] 42 | })) 43 | .pipe(gulp.dest(baseRrl+'js')) 44 | ); 45 | 46 | gulp.task('default', ['connect', 'watch','sass','babel']); 47 | 48 | 49 | // build 50 | gulp.task('clean', function() { 51 | return gulp.src(['./dist/*.*'], { 52 | read: false 53 | }) 54 | .pipe(clean()); 55 | }); 56 | 57 | gulp.task('minCss',()=>{ 58 | return gulp.src([baseRrl+'css/*.css']) 59 | .pipe(minifyCss()) 60 | .pipe(rename('zane-calendar.min.css')) 61 | .pipe(gulp.dest('dist')); 62 | }) 63 | gulp.task('miJS',()=>{ 64 | return gulp.src([baseRrl+'js/*.js']) 65 | .pipe(uglify()) 66 | .pipe(rename('zane-calendar.min.js')) 67 | .pipe(gulp.dest('dist')); 68 | }) 69 | 70 | gulp.task('build', gulpSequence(['clean','minCss', 'miJS'])); 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/dist/zane-calendar.min.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8";*{padding:0;margin:0}li,ul{list-style:none}.zane-calendar{position:absolute;left:0;top:0;font-size:14px;width:280px;border:solid 1px #ddd;border-left:none;background:#fff;overflow:hidden;-moz-user-select:none;-o-user-select:none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}.zane-calendar .main-color{color:#34a9da}.zane-calendar .zane-date-left{float:left}.zane-calendar .zane-calendar-one{width:280px}.zane-calendar .zane-calendar-one .zane-date-top{height:40px;line-height:40px;position:relative;text-align:center;border-bottom:solid 1px #ddd;border-left:solid 1px #ddd;font-size:16px}.zane-calendar .zane-calendar-one .zane-date-top .zane-date-icom{width:40px;height:40px;position:absolute}.zane-calendar .zane-calendar-one .zane-date-top .zane-icon-left{left:0;top:0;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA6ElEQVRYR9XXXQ7CIAwHcDiBeAN5oM8eSW+mJ9Fz8FIPQlJDshjnPigbLXGvI/x/oaHdrOn82M755n8BiHjKp+e9f+05xU0nEGM8W2sfOTiEcFQFfIU7IroDwEUN0Do8w9klkAhnA6TCWQDJ8CJAOnwVoBG+CNAKnwVohk8A2uEjACK6lBIaY5p0OG53/DSiAZAHy4GIbgBw5W6yZ92oEw4leGoiJq1YGzE7CzQRi8NIC7E6DTUQxXEsjSgC8hWTRLAAkgg2QApRBZBAVAN+EPmz3DVrxTUbdf0xqYGW1m4qQWnTmvfdAW+Xz8YhHJFj1gAAAABJRU5ErkJggg==) no-repeat center center;background-size:70%}.zane-calendar .zane-calendar-one .zane-date-top .zane-icon-right{position:absolute;top:0;right:0;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA2klEQVRYR+XXwQ3CMAxAUWeY+MwIjFI2gElgA2ASVuBsDxMUCaTSQ2s7NlFLj1Wl/+RISZqg85M692EbACLaIeLTMs3mCTDzEQDOpZQbIh60CA/AHgAeNWxBNANqmIiGlNLVgnABtCDcAFaEK8CCcAdoESEADSIMIEWEAiSIcMAS4ieAKQIATjnnS33/H4DJVn1HxOFzaIVPYC4evgRL8VCAJB4GkMZDAJq4O0AbdwVY4m4Aa9wFwMzjS+nXJiO5ITdvRKNruTruMoH3QdPvx0Qy5rlvmpdg9YAX88PCIUoA0kEAAAAASUVORK5CYII=) no-repeat center center;background-size:70%}.zane-calendar .zane-calendar-one .zane-date-top .zane-icon-center span:hover{color:#34a9da;cursor:pointer}.zane-calendar .zane-calendar-one .zane-date-top .zane-icon-center span:nth-child(1){margin-right:8px}.zane-calendar .zane-calendar-one .zane-date-main{overflow:hidden;height:220px;border-left:solid 1px #ddd}.zane-calendar .zane-calendar-one .zane-date-main .week-day table.day{width:100%}.zane-calendar .zane-calendar-one .zane-date-main .week-day td,.zane-calendar .zane-calendar-one .zane-date-main .week-day th{text-align:center}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.light,.zane-calendar .zane-calendar-one .zane-date-main .week-day th.light{color:#cacaca}.zane-calendar .zane-calendar-one .zane-date-main .week-day td{cursor:pointer}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.calendar-disabled{cursor:not-allowed;color:#ccc}.zane-calendar .zane-calendar-one .zane-date-main .week-day td:hover{background:#f4f4f4}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.active{background:#34a9da;color:#fff}.zane-calendar .zane-calendar-one .zane-date-main .main-check-month .week-day td{width:33.333%}.zane-calendar .zane-calendar-one .zane-date-main .main-check-month .week-day td.calendar-disabled{cursor:not-allowed;color:#ccc}.zane-calendar .zane-calendar-one .zane-date-main .main-check-year .week-day td{width:33.333%}.zane-calendar .zane-calendar-one .zane-date-main .main-check-year .week-day td.calendar-disabled{cursor:not-allowed;color:#ccc}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day{padding:5px}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .nav{overflow:hidden;height:30px;line-height:30px}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .nav li{width:33.333%;float:left;text-align:center}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time{overflow:hidden;text-align:center}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul{height:176px;display:inline-block;overflow-y:scroll;width:28%;margin:0 2%;float:left;border:solid 1px #ccc}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li{height:25px;line-height:25px;cursor:pointer}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li:hover{background:#f4f4f4}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li.active{background:#34a9da;color:#fff}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar{width:4px;height:4px}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar-thumb{border-radius:5px;-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,.2);background:rgba(0,0,0,.6)}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar-track{-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,.2);border-radius:0;background:rgba(0,0,0,.1)}.zane-calendar .zane-calendar-one .zane-date-bottom{border-top:solid 1px #ddd;border-left:solid 1px #ddd;overflow:hidden;height:43px;padding:0 8px;font-size:12px}.zane-calendar .zane-calendar-one .zane-date-bottom .zane-date-right{float:right}.zane-calendar .zane-calendar-one .zane-date-bottom .zane-date-right .button.no-right-line{border-right:none}.zane-calendar .zane-calendar-one .zane-date-bottom .button{margin-top:8px;cursor:pointer;border:solid 1px #ddd;padding:6px 8px;float:left;background:#fff;color:#999}.zane-calendar .zane-calendar-one .zane-date-bottom .button:hover{color:#34a9da} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zane-data-time-calendar 2 | PC端时间日历插件 3 | 4 | ### 说明: 5 | 此插件不依赖任何第三方插件,因此可以在任何地方单独使用 6 | 7 | ### images 8 | ![输入图片说明](https://github.com/wangweianger/zane-data-time-calendar/blob/master/demo/01.png "在这里输入图片标题") 9 | ![输入图片说明](https://github.com/wangweianger/zane-data-time-calendar/blob/master/demo/02.png "在这里输入图片标题") 10 | ![输入图片说明](https://github.com/wangweianger/zane-data-time-calendar/blob/master/demo/03.png "在这里输入图片标题") 11 | ![输入图片说明](https://github.com/wangweianger/zane-data-time-calendar/blob/master/demo/04.png "在这里输入图片标题") 12 | ![输入图片说明](https://github.com/wangweianger/zane-data-time-calendar/blob/master/demo/05.png "在这里输入图片标题") 13 | ![输入图片说明](https://github.com/wangweianger/zane-data-time-calendar/blob/master/demo/06.png "在这里输入图片标题") 14 | ![输入图片说明](https://github.com/wangweianger/zane-data-time-calendar/blob/master/demo/07.png "在这里输入图片标题") 15 | ![输入图片说明](https://github.com/wangweianger/zane-data-time-calendar/blob/master/demo/08.png "在这里输入图片标题") 16 | 17 | ### API文档及DEMO地址 :http://www.seosiwei.com/zaneDate/index.html 18 | 19 | ### npm地址:https://www.npmjs.com/package/zane-calendar 20 | 21 | ### vue组件npm地址 支持vue1.0,vue2.0: https://www.npmjs.com/package/vue-date-calendar 22 | 23 | ### 使用方式 24 | 25 | 26 | ### 浏览器端使用 27 | ```js 28 | 29 | 30 | 31 | 32 | 33 | 34 | Initialization. 35 | zaneDate({ 36 | elem:'#zane-calendar', 37 | }) 38 | ``` 39 | 40 | 41 | ### Webpack 使用 42 | 43 | ```js 44 | 45 | npm install zane-calendar --save | yarn add zane-calendar 46 | 47 | 48 | const zaneDate = require('zane-calendar') 或 49 | import zaneDate from 'zane-calendar' 50 | 51 | 52 | 53 | 54 | 55 | 56 | Initialization. 57 | zaneDate({ 58 | elem:'#zane-calendar', 59 | }) 60 | 61 | ``` 62 | 63 | ### 参数说明 64 | 65 | 参数配置(参数可灵活配置) 66 | ```js 67 | { 68 | 69 | elem:'#zane-calendar', 控件的原生dom 注意:仅限制于id选择器 70 | type:'day', 可选类型 day year month time doubleday doubleyear doublemonth doubletime 71 | lang:'cn', 可选择语言类型 cn , en 72 | width:250, 插件宽度配置 220 <= X <= 500 73 | height:280, 插件高度配置 240 <= X <= 350 74 | behindTop:10, 插件与输入框的高度 75 | format:'yyyy-MM-dd HH:mm:ss', 时间格式化 76 | begintime:'', 开始时间 (单选择可选项) 77 | endtime:'', 结束时间 (double选择器可选项) 78 | min:'', 可选取时间最小范围 1900-10-01 79 | max: '', 可选取时间最大范围 2099-12-31 80 | position:'fixed', 定位方式,暂时只支持 fixed 81 | event:'click', 事件方式,暂时只支持 click 82 | zindex:100, z-index值 83 | showtime:true, 是否显示选择时间 84 | showclean:true, 是否显示清除按钮 85 | shownow:true, 是否显示当前按钮 86 | showsubmit:true, 是否显示提交按钮 87 | haveBotBtns:true, 是否有底部按钮列表 88 | showsecond:true, type='time|doubletime'时是否支持选择秒单位 89 | calendarName:'', 此参数勿动 表示当前时间插件实例化对象 90 | mounted:()=>{}, 插件加载完成之后调用 91 | change:(fulltime,begintime,endtime)=>{}, 时间变更之后调用 92 | done:(fulltime,begintime,endtime)=>{}, 选择完成之后调用 93 | } 94 | 95 | 96 | ``` 97 | ### 案例调用方式 98 | 99 | ```js 100 | 默认完整选项 101 | zaneDate({ 102 | elem:'#zane-calendar', 103 | }) 104 | 105 | 只选择年月日 106 | zaneDate({ 107 | elem:'#zane-calendar', 108 | showtime:false, 109 | }) 110 | 111 | 使用英文 112 | zaneDate({ 113 | elem:'#zane-calendar', 114 | lang:'en', 115 | }) 116 | 117 | 只选择年 118 | zaneDate({ 119 | elem:'#zane-calendar', 120 | type:'year', 121 | }) 122 | 123 | 只选择月 124 | zaneDate({ 125 | elem:'#zane-calendar', 126 | type:'month', 127 | }) 128 | 129 | 只选择时间 130 | zaneDate({ 131 | elem:'#zane-calendar', 132 | type:'time', 133 | }) 134 | 135 | 格式化方式 136 | zaneDate({ 137 | elem:'#zane-calendar', 138 | format:'yyyy年MM月dd日 HH时mm分ss秒', 139 | }) 140 | 141 | 限定能选择的最小最大区间 142 | zaneDate({ 143 | elem:'#zane-calendar', 144 | min:'2017-08-01', 145 | max:'2017-08-20', 146 | }) 147 | 148 | ...... 149 | 150 | 具体的请查看demo 151 | 152 | ``` 153 | 154 | ### 1.1.0 版本新增 double选择器 155 | 156 | ```js 157 | config.type 新增double类型 可选类型如下:day year month time doubleday doubleyear doublemonth doubletime 158 | 159 | 双日期范围选择 160 | zaneDate({ 161 | elem:'#demo21', 162 | type:'doubleday' 163 | }) 164 | 165 | 双年范围选择 166 | zaneDate({ 167 | elem:'#demo22', 168 | type:'doubleyear', 169 | }) 170 | 171 | 双月范围选择 172 | zaneDate({ 173 | elem:'#demo23', 174 | type:'doublemonth', 175 | }) 176 | 177 | 双时间选择 178 | zaneDate({ 179 | elem:'#demo24', 180 | type:'doubletime', 181 | }) 182 | 183 | 184 | ``` 185 | 186 | ### 1.2.0 版本 187 | ### 1.doubleday类型新增选择时间,支持时分秒选择 188 | ### 2.double类型检测距离右边window边线的距离,若不足,自动排列为上下两个日期 189 | 190 | ```js 191 | config.type doubleday支持选择时间范围 192 | 193 | 双日期范围选择 194 | zaneDate({ 195 | elem:'#demo25', 196 | format:'yyyy-MM-dd HH:mm:ss', 197 | type:'doubleday', 198 | showtime:true 199 | }) 200 | 201 | ``` 202 | 203 | ### 1.2.1 版本 新增z-index 参数 204 | ```js 205 | zaneDate({ 206 | elem:'#zane-calendar', 207 | zindex:500, 208 | }) 209 | 210 | ``` 211 | 212 | ### 1.2.2 版本 完善日历插件文档 213 | 214 | ### 2.0.9 版本 修复单页面BUG,修复safair苹果信息 相关BUG 215 | 216 | ### 2.1.0 版本 修复双选择器有默认值的bug,更新demo图片 217 | 218 | ### 2.2.0 版本 修复上一月下一月跳月问题 219 | 220 | ### 2.2.3 版本 修复点击多次重复生成日历问题 221 | 222 | ### 2.2.4 版本 增加结束时间大于开始时间的判断 223 | 224 | ### 2.2.5 版本 增加双选择器区间选中样式效果 225 | 226 | ### 2.2.6 版本 修复双选择器默认选中颜色相关bug 227 | 228 | ### 2.2.7 版本 type='time|doubletime'时是否支持选择秒单位 229 | ```js 230 | zaneDate({ 231 | elem:'#demo25', 232 | type:'time', 233 | showsecond:false 234 | }) 235 | 236 | ``` 237 | 238 | -------------------------------------------------------------------------------- /dist/zane-calendar.min.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8";*{padding:0;margin:0}li,ul{list-style:none}.zane-calendar{box-sizing:initial;position:absolute;left:0;top:0;font-size:14px;width:280px;border:solid 1px #eee;border-left:none;background:#fff;overflow:hidden;-moz-user-select:none;-o-user-select:none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}.zane-calendar .zane-model-miss{position:absolute;left:0;top:0;width:100%;height:100%;display:none}.zane-calendar .zane-model-miss .zane-model-mask{position:absolute;left:0;top:0;width:100%;height:100%;z-index:99}.zane-calendar .zane-model-miss .zane-model-content{position:absolute;left:50%;top:50%;z-index:100;width:auto;text-align:center;padding:10px 15px;border-radius:20px;transform:translate(-50%,-50%);font-size:12px;background:rgba(0,0,0,.8);color:#fff;min-width:180px}.zane-calendar .main-color{color:#46d7a2}.zane-calendar .zane-date-left{float:left}.zane-calendar .zane-calendar-one{width:280px}.zane-calendar .zane-calendar-one .zane-date-top{height:40px;line-height:40px;position:relative;text-align:center;border-bottom:solid 1px #eee;border-left:solid 1px #eee;font-size:16px}.zane-calendar .zane-calendar-one .zane-date-top .zane-date-icom{width:40px;height:40px;position:absolute}.zane-calendar .zane-calendar-one .zane-date-top .zane-icon-left{left:0;top:0;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA6ElEQVRYR9XXXQ7CIAwHcDiBeAN5oM8eSW+mJ9Fz8FIPQlJDshjnPigbLXGvI/x/oaHdrOn82M755n8BiHjKp+e9f+05xU0nEGM8W2sfOTiEcFQFfIU7IroDwEUN0Do8w9klkAhnA6TCWQDJ8CJAOnwVoBG+CNAKnwVohk8A2uEjACK6lBIaY5p0OG53/DSiAZAHy4GIbgBw5W6yZ92oEw4leGoiJq1YGzE7CzQRi8NIC7E6DTUQxXEsjSgC8hWTRLAAkgg2QApRBZBAVAN+EPmz3DVrxTUbdf0xqYGW1m4qQWnTmvfdAW+Xz8YhHJFj1gAAAABJRU5ErkJggg==) no-repeat center center;background-size:55%}.zane-calendar .zane-calendar-one .zane-date-top .zane-icon-right{position:absolute;top:0;right:0;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA2klEQVRYR+XXwQ3CMAxAUWeY+MwIjFI2gElgA2ASVuBsDxMUCaTSQ2s7NlFLj1Wl/+RISZqg85M692EbACLaIeLTMs3mCTDzEQDOpZQbIh60CA/AHgAeNWxBNANqmIiGlNLVgnABtCDcAFaEK8CCcAdoESEADSIMIEWEAiSIcMAS4ieAKQIATjnnS33/H4DJVn1HxOFzaIVPYC4evgRL8VCAJB4GkMZDAJq4O0AbdwVY4m4Aa9wFwMzjS+nXJiO5ITdvRKNruTruMoH3QdPvx0Qy5rlvmpdg9YAX88PCIUoA0kEAAAAASUVORK5CYII=) no-repeat center center;background-size:55%}.zane-calendar .zane-calendar-one .zane-date-top .zane-icon-center span:hover{color:#46d7a2;cursor:pointer}.zane-calendar .zane-calendar-one .zane-date-top .zane-icon-center span:nth-child(1){margin-right:8px}.zane-calendar .zane-calendar-one .zane-date-main{overflow:hidden;height:220px;border-left:solid 1px #eee}.zane-calendar .zane-calendar-one .zane-date-main .week-day table.day{width:100%}.zane-calendar .zane-calendar-one .zane-date-main .week-day th{font-size:13px}.zane-calendar .zane-calendar-one .zane-date-main .week-day td,.zane-calendar .zane-calendar-one .zane-date-main .week-day th{text-align:center}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.light,.zane-calendar .zane-calendar-one .zane-date-main .week-day th.light{color:#aaa}.zane-calendar .zane-calendar-one .zane-date-main .week-day td{font-size:12px;cursor:pointer}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.calendar-disabled{cursor:not-allowed;color:#ddd}.zane-calendar .zane-calendar-one .zane-date-main .week-day td span{box-sizing:initial;display:inline-block;width:10px;height:10px;padding:9px;padding-left:8px;padding-right:10px;text-align:center;line-height:10px;border-radius:100%}.zane-calendar .zane-calendar-one .zane-date-main .week-day td:hover span{background:#f4f4f4}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.active{color:#fff}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.active span{background:#46d7a2}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.sele_act{background:#8cffd4}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.act_block{background:#46d7a2;color:#fff}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.act_block:hover,.zane-calendar .zane-calendar-one .zane-date-main .week-day td.sele_act:hover{background:#46d7a2;color:#fff}.zane-calendar .zane-calendar-one .zane-date-main .week-day td.act_block:hover span,.zane-calendar .zane-calendar-one .zane-date-main .week-day td.sele_act:hover span{background:0 0}.zane-calendar .zane-calendar-one .zane-date-main .week-day .border-day td span{width:auto;border-radius:15px}.zane-calendar .zane-calendar-one .zane-date-main .main-check-month .week-day td{width:33.333%}.zane-calendar .zane-calendar-one .zane-date-main .main-check-month .week-day td.calendar-disabled{cursor:not-allowed;color:#ccc}.zane-calendar .zane-calendar-one .zane-date-main .main-check-year .week-day td{width:33.333%}.zane-calendar .zane-calendar-one .zane-date-main .main-check-year .week-day td.calendar-disabled{cursor:not-allowed;color:#ccc}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day{padding:5px}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .nav{overflow:hidden;height:25px;line-height:25px}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .nav li{width:33.333%;float:left;text-align:center}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .nav-1 li{width:50%}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time{overflow:hidden;text-align:center;height:176px}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul{height:99%;display:inline-block;overflow-y:scroll;width:28%;margin:0 2%;float:left;border:solid 1px #eee}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li{height:25px;line-height:25px;cursor:pointer}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li:hover{background:#f4f4f4}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li.active{background:#46d7a2;color:#fff}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar{width:4px;height:4px}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar-thumb{border-radius:5px;-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,.2);background:rgba(0,0,0,.6)}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar-track{-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,.2);border-radius:0;background:rgba(0,0,0,.1)}.zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time-1 ul{width:45%;margin:0 1%}.zane-calendar .zane-calendar-one .zane-date-bottom{border-top:solid 1px #eee;border-left:solid 1px #eee;overflow:hidden;height:40px;padding:0 8px;font-size:12px}.zane-calendar .zane-calendar-one .zane-date-bottom .zane-date-right{float:right}.zane-calendar .zane-calendar-one .zane-date-bottom .zane-date-right .button.no-right-line{border-right:none}.zane-calendar .zane-calendar-one .zane-date-bottom .button{margin-top:6px;cursor:pointer;padding:6px 8px;float:left;background:#fff;color:#999}.zane-calendar .zane-calendar-one .zane-date-bottom .button:hover{color:#46d7a2} -------------------------------------------------------------------------------- /src/sass/zane-calendar.scss: -------------------------------------------------------------------------------- 1 | *{ 2 | padding:0; 3 | margin:0; 4 | } 5 | ul,li{ 6 | list-style:none; 7 | } 8 | .zane-calendar{ 9 | box-sizing: initial; 10 | position:absolute; 11 | left:0; 12 | top:0; 13 | font-size:14px; 14 | width:280px; 15 | border:solid 1px #eee; 16 | border-left:none; 17 | background:#fff; 18 | overflow:hidden; 19 | -moz-user-select: none; 20 | -o-user-select:none; 21 | -khtml-user-select:none; 22 | -webkit-user-select:none; 23 | -ms-user-select:none; 24 | user-select:none; 25 | .zane-model-miss{ 26 | position: absolute; 27 | left:0; 28 | top:0; 29 | width:100%; 30 | height:100%; 31 | display: none; 32 | .zane-model-mask{ 33 | position: absolute; 34 | left:0; 35 | top:0; 36 | width:100%; 37 | height:100%; 38 | z-index:99; 39 | } 40 | .zane-model-content{ 41 | position: absolute; 42 | left:50%; 43 | top:50%; 44 | z-index:100; 45 | width:auto; 46 | text-align:center; 47 | padding:10px 15px; 48 | border-radius:20px; 49 | transform: translate(-50%,-50%); 50 | font-size:12px; 51 | background:rgba(0,0,0,.8); 52 | color:#fff; 53 | min-width:180px; 54 | } 55 | } 56 | .main-color{ 57 | color:#46d7a2; 58 | } 59 | .zane-date-left{ 60 | float:left; 61 | } 62 | .zane-calendar-one{ 63 | width:280px; 64 | .zane-date-top{ 65 | height:40px; 66 | line-height:40px; 67 | position:relative; 68 | text-align:center; 69 | border-bottom:solid 1px #eee; 70 | border-left:solid 1px #eee; 71 | font-size:16px; 72 | .zane-date-icom{ 73 | width:40px; 74 | height:40px; 75 | position:absolute; 76 | } 77 | .zane-icon-left{ 78 | left:0; 79 | top:0; 80 | background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA6ElEQVRYR9XXXQ7CIAwHcDiBeAN5oM8eSW+mJ9Fz8FIPQlJDshjnPigbLXGvI/x/oaHdrOn82M755n8BiHjKp+e9f+05xU0nEGM8W2sfOTiEcFQFfIU7IroDwEUN0Do8w9klkAhnA6TCWQDJ8CJAOnwVoBG+CNAKnwVohk8A2uEjACK6lBIaY5p0OG53/DSiAZAHy4GIbgBw5W6yZ92oEw4leGoiJq1YGzE7CzQRi8NIC7E6DTUQxXEsjSgC8hWTRLAAkgg2QApRBZBAVAN+EPmz3DVrxTUbdf0xqYGW1m4qQWnTmvfdAW+Xz8YhHJFj1gAAAABJRU5ErkJggg==') no-repeat center center; 81 | background-size:55%; 82 | } 83 | .zane-icon-right{ 84 | position:absolute; 85 | top:0; 86 | right:0; 87 | background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA2klEQVRYR+XXwQ3CMAxAUWeY+MwIjFI2gElgA2ASVuBsDxMUCaTSQ2s7NlFLj1Wl/+RISZqg85M692EbACLaIeLTMs3mCTDzEQDOpZQbIh60CA/AHgAeNWxBNANqmIiGlNLVgnABtCDcAFaEK8CCcAdoESEADSIMIEWEAiSIcMAS4ieAKQIATjnnS33/H4DJVn1HxOFzaIVPYC4evgRL8VCAJB4GkMZDAJq4O0AbdwVY4m4Aa9wFwMzjS+nXJiO5ITdvRKNruTruMoH3QdPvx0Qy5rlvmpdg9YAX88PCIUoA0kEAAAAASUVORK5CYII=') no-repeat center center; 88 | background-size:55%; 89 | } 90 | .zane-icon-center{ 91 | span:hover{ 92 | color:#46d7a2; 93 | cursor:pointer; 94 | } 95 | span:nth-child(1){ 96 | margin-right:8px; 97 | } 98 | } 99 | } 100 | .zane-date-main{ 101 | overflow:hidden; 102 | height:220px; 103 | border-left:solid 1px #eee; 104 | .week-day{ 105 | table.day{ 106 | width:100%; 107 | } 108 | th{ 109 | font-size:13px; 110 | } 111 | th,td{ 112 | text-align:center; 113 | } 114 | th.light,td.light{ 115 | color:#aaa 116 | } 117 | td{ 118 | font-size:12px; 119 | cursor:pointer; 120 | &.calendar-disabled{ 121 | cursor:not-allowed; 122 | color: #ddd; 123 | } 124 | span{ 125 | box-sizing: initial; 126 | display:inline-block; 127 | width:10px; 128 | height:10px; 129 | padding:9px; 130 | padding-left:8px; 131 | padding-right:10px; 132 | text-align:center; 133 | line-height:10px; 134 | border-radius:100%; 135 | } 136 | } 137 | td:hover{ 138 | span{ 139 | background:#f4f4f4; 140 | } 141 | } 142 | td.active{ 143 | span{ 144 | background:#46d7a2; 145 | } 146 | color:#fff; 147 | } 148 | td.sele_act{ 149 | background:#8cffd4; 150 | } 151 | td.act_block{ 152 | background:#46d7a2; 153 | color:#fff; 154 | } 155 | td.act_block:hover,td.sele_act:hover{ 156 | background:#46d7a2; 157 | color:#fff; 158 | span{ 159 | background:none; 160 | } 161 | } 162 | .border-day{ 163 | td{ 164 | span{ 165 | width:auto; 166 | border-radius:15px; 167 | } 168 | } 169 | } 170 | } 171 | .main-check-month{ 172 | .week-day{ 173 | td{ 174 | width: 33.333%; 175 | &.calendar-disabled{ 176 | cursor:not-allowed; 177 | color: #ccc; 178 | } 179 | } 180 | } 181 | } 182 | .main-check-year{ 183 | .week-day{ 184 | td{ 185 | width: 33.333%; 186 | &.calendar-disabled{ 187 | cursor:not-allowed; 188 | color: #ccc; 189 | } 190 | } 191 | } 192 | } 193 | .main-check-time{ 194 | .week-day{ 195 | padding:5px; 196 | .nav{ 197 | overflow:hidden; 198 | height: 25px; 199 | line-height:25px; 200 | li{ 201 | width:33.333%; 202 | float:left; 203 | text-align:center; 204 | } 205 | } 206 | .nav-1{ 207 | li{ 208 | width:50%; 209 | } 210 | } 211 | .select-time{ 212 | overflow:hidden; 213 | text-align:center; 214 | height:176px; 215 | ul{ 216 | height:99%; 217 | display:inline-block; 218 | overflow-y:scroll; 219 | width:28%; 220 | margin:0 2%; 221 | float:left; 222 | border:solid 1px #eee; 223 | li{ 224 | height:25px; 225 | line-height:25px; 226 | cursor:pointer; 227 | &:hover{ 228 | background:#f4f4f4; 229 | } 230 | &.active{ 231 | background:#46d7a2; 232 | color:#fff; 233 | } 234 | } 235 | } 236 | /*滚动条样式*/ 237 | ul::-webkit-scrollbar { 238 | width: 4px; 239 | height: 4px; 240 | } 241 | ul::-webkit-scrollbar-thumb { 242 | border-radius: 5px; 243 | -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2); 244 | background: rgba(0,0,0,0.6); 245 | } 246 | ul::-webkit-scrollbar-track { 247 | -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2); 248 | border-radius: 0; 249 | background: rgba(0,0,0,.1); 250 | } 251 | } 252 | .select-time-1{ 253 | ul{ 254 | width:45%; 255 | margin:0 1%; 256 | } 257 | } 258 | } 259 | } 260 | 261 | } 262 | .zane-date-bottom{ 263 | border-top:solid 1px #eee; 264 | border-left:solid 1px #eee; 265 | overflow:hidden; 266 | height:40px; 267 | padding:0 8px; 268 | font-size:12px; 269 | .zane-date-right{ 270 | float:right; 271 | .button.no-right-line{ 272 | border-right:none; 273 | } 274 | } 275 | .button{ 276 | margin-top:6px; 277 | cursor:pointer; 278 | padding:6px 8px; 279 | float:left; 280 | background:#fff; 281 | color:#999; 282 | &:hover{ 283 | color:#46d7a2; 284 | } 285 | } 286 | } 287 | } 288 | } -------------------------------------------------------------------------------- /src/css/zane-calendar.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | * { 3 | padding: 0; 4 | margin: 0; } 5 | 6 | ul, li { 7 | list-style: none; } 8 | 9 | .zane-calendar { 10 | box-sizing: initial; 11 | position: absolute; 12 | left: 0; 13 | top: 0; 14 | font-size: 14px; 15 | width: 280px; 16 | border: solid 1px #eee; 17 | border-left: none; 18 | background: #fff; 19 | overflow: hidden; 20 | -moz-user-select: none; 21 | -o-user-select: none; 22 | -khtml-user-select: none; 23 | -webkit-user-select: none; 24 | -ms-user-select: none; 25 | user-select: none; } 26 | .zane-calendar .zane-model-miss { 27 | position: absolute; 28 | left: 0; 29 | top: 0; 30 | width: 100%; 31 | height: 100%; 32 | display: none; } 33 | .zane-calendar .zane-model-miss .zane-model-mask { 34 | position: absolute; 35 | left: 0; 36 | top: 0; 37 | width: 100%; 38 | height: 100%; 39 | z-index: 99; } 40 | .zane-calendar .zane-model-miss .zane-model-content { 41 | position: absolute; 42 | left: 50%; 43 | top: 50%; 44 | z-index: 100; 45 | width: auto; 46 | text-align: center; 47 | padding: 10px 15px; 48 | border-radius: 20px; 49 | transform: translate(-50%, -50%); 50 | font-size: 12px; 51 | background: rgba(0, 0, 0, 0.8); 52 | color: #fff; 53 | min-width: 180px; } 54 | .zane-calendar .main-color { 55 | color: #46d7a2; } 56 | .zane-calendar .zane-date-left { 57 | float: left; } 58 | .zane-calendar .zane-calendar-one { 59 | width: 280px; } 60 | .zane-calendar .zane-calendar-one .zane-date-top { 61 | height: 40px; 62 | line-height: 40px; 63 | position: relative; 64 | text-align: center; 65 | border-bottom: solid 1px #eee; 66 | border-left: solid 1px #eee; 67 | font-size: 16px; } 68 | .zane-calendar .zane-calendar-one .zane-date-top .zane-date-icom { 69 | width: 40px; 70 | height: 40px; 71 | position: absolute; } 72 | .zane-calendar .zane-calendar-one .zane-date-top .zane-icon-left { 73 | left: 0; 74 | top: 0; 75 | background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA6ElEQVRYR9XXXQ7CIAwHcDiBeAN5oM8eSW+mJ9Fz8FIPQlJDshjnPigbLXGvI/x/oaHdrOn82M755n8BiHjKp+e9f+05xU0nEGM8W2sfOTiEcFQFfIU7IroDwEUN0Do8w9klkAhnA6TCWQDJ8CJAOnwVoBG+CNAKnwVohk8A2uEjACK6lBIaY5p0OG53/DSiAZAHy4GIbgBw5W6yZ92oEw4leGoiJq1YGzE7CzQRi8NIC7E6DTUQxXEsjSgC8hWTRLAAkgg2QApRBZBAVAN+EPmz3DVrxTUbdf0xqYGW1m4qQWnTmvfdAW+Xz8YhHJFj1gAAAABJRU5ErkJggg==") no-repeat center center; 76 | background-size: 55%; } 77 | .zane-calendar .zane-calendar-one .zane-date-top .zane-icon-right { 78 | position: absolute; 79 | top: 0; 80 | right: 0; 81 | background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA2klEQVRYR+XXwQ3CMAxAUWeY+MwIjFI2gElgA2ASVuBsDxMUCaTSQ2s7NlFLj1Wl/+RISZqg85M692EbACLaIeLTMs3mCTDzEQDOpZQbIh60CA/AHgAeNWxBNANqmIiGlNLVgnABtCDcAFaEK8CCcAdoESEADSIMIEWEAiSIcMAS4ieAKQIATjnnS33/H4DJVn1HxOFzaIVPYC4evgRL8VCAJB4GkMZDAJq4O0AbdwVY4m4Aa9wFwMzjS+nXJiO5ITdvRKNruTruMoH3QdPvx0Qy5rlvmpdg9YAX88PCIUoA0kEAAAAASUVORK5CYII=") no-repeat center center; 82 | background-size: 55%; } 83 | .zane-calendar .zane-calendar-one .zane-date-top .zane-icon-center span:hover { 84 | color: #46d7a2; 85 | cursor: pointer; } 86 | .zane-calendar .zane-calendar-one .zane-date-top .zane-icon-center span:nth-child(1) { 87 | margin-right: 8px; } 88 | .zane-calendar .zane-calendar-one .zane-date-main { 89 | overflow: hidden; 90 | height: 220px; 91 | border-left: solid 1px #eee; } 92 | .zane-calendar .zane-calendar-one .zane-date-main .week-day table.day { 93 | width: 100%; } 94 | .zane-calendar .zane-calendar-one .zane-date-main .week-day th { 95 | font-size: 13px; } 96 | .zane-calendar .zane-calendar-one .zane-date-main .week-day th, .zane-calendar .zane-calendar-one .zane-date-main .week-day td { 97 | text-align: center; } 98 | .zane-calendar .zane-calendar-one .zane-date-main .week-day th.light, .zane-calendar .zane-calendar-one .zane-date-main .week-day td.light { 99 | color: #aaa; } 100 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td { 101 | font-size: 12px; 102 | cursor: pointer; } 103 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td.calendar-disabled { 104 | cursor: not-allowed; 105 | color: #ddd; } 106 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td span { 107 | box-sizing: initial; 108 | display: inline-block; 109 | width: 10px; 110 | height: 10px; 111 | padding: 9px; 112 | padding-left: 8px; 113 | padding-right: 10px; 114 | text-align: center; 115 | line-height: 10px; 116 | border-radius: 100%; } 117 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td:hover span { 118 | background: #f4f4f4; } 119 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td.active { 120 | color: #fff; } 121 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td.active span { 122 | background: #46d7a2; } 123 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td.sele_act { 124 | background: #8cffd4; } 125 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td.act_block { 126 | background: #46d7a2; 127 | color: #fff; } 128 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td.act_block:hover, .zane-calendar .zane-calendar-one .zane-date-main .week-day td.sele_act:hover { 129 | background: #46d7a2; 130 | color: #fff; } 131 | .zane-calendar .zane-calendar-one .zane-date-main .week-day td.act_block:hover span, .zane-calendar .zane-calendar-one .zane-date-main .week-day td.sele_act:hover span { 132 | background: none; } 133 | .zane-calendar .zane-calendar-one .zane-date-main .week-day .border-day td span { 134 | width: auto; 135 | border-radius: 15px; } 136 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-month .week-day td { 137 | width: 33.333%; } 138 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-month .week-day td.calendar-disabled { 139 | cursor: not-allowed; 140 | color: #ccc; } 141 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-year .week-day td { 142 | width: 33.333%; } 143 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-year .week-day td.calendar-disabled { 144 | cursor: not-allowed; 145 | color: #ccc; } 146 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day { 147 | padding: 5px; } 148 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .nav { 149 | overflow: hidden; 150 | height: 25px; 151 | line-height: 25px; } 152 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .nav li { 153 | width: 33.333%; 154 | float: left; 155 | text-align: center; } 156 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .nav-1 li { 157 | width: 50%; } 158 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time { 159 | overflow: hidden; 160 | text-align: center; 161 | height: 176px; 162 | /*滚动条样式*/ } 163 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul { 164 | height: 99%; 165 | display: inline-block; 166 | overflow-y: scroll; 167 | width: 28%; 168 | margin: 0 2%; 169 | float: left; 170 | border: solid 1px #eee; } 171 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li { 172 | height: 25px; 173 | line-height: 25px; 174 | cursor: pointer; } 175 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li:hover { 176 | background: #f4f4f4; } 177 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul li.active { 178 | background: #46d7a2; 179 | color: #fff; } 180 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar { 181 | width: 4px; 182 | height: 4px; } 183 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar-thumb { 184 | border-radius: 5px; 185 | -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); 186 | background: rgba(0, 0, 0, 0.6); } 187 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time ul::-webkit-scrollbar-track { 188 | -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); 189 | border-radius: 0; 190 | background: rgba(0, 0, 0, 0.1); } 191 | .zane-calendar .zane-calendar-one .zane-date-main .main-check-time .week-day .select-time-1 ul { 192 | width: 45%; 193 | margin: 0 1%; } 194 | .zane-calendar .zane-calendar-one .zane-date-bottom { 195 | border-top: solid 1px #eee; 196 | border-left: solid 1px #eee; 197 | overflow: hidden; 198 | height: 40px; 199 | padding: 0 8px; 200 | font-size: 12px; } 201 | .zane-calendar .zane-calendar-one .zane-date-bottom .zane-date-right { 202 | float: right; } 203 | .zane-calendar .zane-calendar-one .zane-date-bottom .zane-date-right .button.no-right-line { 204 | border-right: none; } 205 | .zane-calendar .zane-calendar-one .zane-date-bottom .button { 206 | margin-top: 6px; 207 | cursor: pointer; 208 | padding: 6px 8px; 209 | float: left; 210 | background: #fff; 211 | color: #999; } 212 | .zane-calendar .zane-calendar-one .zane-date-bottom .button:hover { 213 | color: #46d7a2; } 214 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | zane 的日历插件 5 | 6 | 7 | 113 | 122 | 123 | 124 | 125 | 126 | 127 | 134 |
135 |
zaneData是一个完全由原生javascript封装的PC端日历插件,不依赖任何第三方插件,功能全面,使用简单.
136 |
137 |
使用方式
138 |
浏览器端使用
139 |
140 | <!-- 引入相应的js和css -->
141 | <link href="./dist/zane-calendar.min.css">
142 | <script src="./dist/zane-calendar.min.js"></script>
143 | 
144 | <!-- 需要加时间插件的输入框 -->
145 | <input type="" name="" id="zane-calendar">
146 | 
147 | 初始化
148 | zaneDate({
149 | 	elem:'#zane-calendar',
150 | })
151 | 
152 |
Webpack 使用
153 |
154 | <!-- 安装依赖 -->
155 | npm install zane-calendar --save-dev
156 | 
157 | const zaneDate = require('zane-calendar') 或
158 | import zaneDate from 'zane-calendar'
159 | 
160 | <!-- 需要加时间插件的输入框 -->
161 | <input type="" name="" id="zane-calendar">
162 | 
163 | 初始化
164 | zaneDate({
165 | 	elem:'#zane-calendar',
166 | })
167 | 
168 | 169 |
所有参数说明(组合随意)
170 |
171 | {
172 | 	elem:'#zane-calendar',  控件的dom原生 注意:仅限制于id选择器(必填参,其他参数皆为可选参)
173 | 	type:'day',   			可选类型 day year month time doubleday doubleyear doublemonth doubletime
174 | 	lang:'cn',   			可选择语言类型 cn , en 
175 | 	width:280,  			插件宽度配置   250 <= X <= 500
176 | 	height:300, 			插件高度配置   250 <= X <= 350
177 | 	behindTop:10,   		插件与输入框的距离
178 | 	format:'yyyy-MM-dd HH:mm:ss',  时间格式化
179 | 	begintime:'',  			开始时间  (单选择器默认选择此项)
180 | 	endtime:'',             结束时间  (double选择器需要)
181 | 	min:'',  				可选取时间最小范围 1900-10-01
182 | 	max: '',  				可选取时间最大范围 2099-12-31
183 | 	position:'fixed',  		定位方式  暂时只支持 fixed
184 | 	event:'click',   		事件方式 暂时只支持 click 
185 | 	zindex:100,   			z-index值
186 | 	showtime:true,  		是否显示选择时间
187 | 	showclean:true,  		是否显示清除按钮
188 | 	shownow:true,  			是否显示当前按钮
189 | 	showsubmit:true, 		是否显示提交按钮
190 | 	haveBotBtns:true, 		是否有底部按钮列表
191 | 	mounted:()=>{}, 		插件加载完成之后调用
192 | 	change:(fulltime,begintime,endtime)=>{}, 时间变更之后调用
193 | 	done:(fulltime,begintime,endtime)=>{},   选择完成之后调用
194 | }
195 | 196 |
承载元素
197 |
198 |
199 | INPUT框: 200 | 代码 201 |
zaneDate({ 
202 | 	elem:'#demo20', 
203 | 	showtime:false, 
204 | })
205 |
206 |
207 | DIV框:
我是div框
208 | 代码 209 |
zaneDate({
210 | 	elem:'#demo19',
211 | 	showtime:false,
212 | 	begintime:'2018-01-01',
213 | })
214 |
215 |
216 | 217 |
绝对定位
218 |
显示绝对定位日期
219 |
220 |
221 |
fixed绝对定位:
222 | 223 | 代码 224 |
zaneDate({
225 | 	elem:'#demo28',
226 | 	type:'doubleday',
227 | 	format:'yyyy-MM-dd HH:mm:ss',
228 | 	showtime:true,
229 | })
230 |
231 |
232 |
绝对定位中的absolute定位:
233 | 234 | 代码 235 |
zaneDate({
236 | 	elem:'#demo29',
237 | })
238 |
239 |
x
240 |
241 | 242 |
中文版案例 (以下所有功能均适用于英文版)
243 |
244 |
245 | 完整版: 246 | 247 | 代码 248 |
zaneDate({
249 | 	elem:'#demo3',
250 | 	begintime:'2018-01-01 12:12:12',
251 | 	format:'yyyy-MM-dd HH:mm:ss',
252 | 	showtime:true
253 | })
254 |
255 |
256 | 选择年: 257 | 258 | 代码 259 |
zaneDate({
260 | 	elem:'#demo4',
261 | 	type:'year'
262 | })
263 |
264 |
265 |
266 |
267 | 选择月: 268 | 269 | 代码 270 |
zaneDate({
271 | 	elem:'#demo5',
272 | 	type:'month'
273 | })
274 |
275 |
276 | 选择时间: 277 | 278 | 代码 279 |
zaneDate({
280 | 	elem:'#demo6',
281 | 	type:'time'
282 | })
283 |
284 |
285 |
286 |
287 | 选择时间(只选择时和分): 288 | 289 | 代码 290 |
zaneDate({
291 | 	elem:'#demo56',
292 | 	type:'time',
293 | 	showsecond:false,
294 | })
295 |
296 |
297 | 改变宽度: 298 | 代码 299 |
zaneDate({
300 | 	elem:'#demo7',
301 | 	width:350,
302 | })
303 |
304 |
305 |
306 |
307 | 格式化: 308 | 代码 309 |
zaneDate({
310 | 	elem:'#demo8',
311 | 	format:'yyyy年MM月dd日 HH时mm分ss秒',
312 | 	showtime:true
313 | })
314 |
315 |
316 | 初始默认值: 317 | 代码 318 |
zaneDate({
319 | 	elem:'#demo9',
320 | 	begintime:'2018-01-01',
321 | })
322 |
323 |
324 |
325 |
326 | 时间范围min,max: 327 | 代码 328 |
zaneDate({
329 | 	elem:'#demo10',
330 | 	min:'2018-06-01',
331 | 	max:'2019-01-01'
332 | })
333 |
334 |
335 | 不显示时分秒: 336 | 代码 337 |
zaneDate({
338 | 	elem:'#demo11',
339 | 	showtime:false
340 | })
341 |
342 |
343 |
344 |
345 | 不显示清除按钮: 346 | 代码 347 |
zaneDate({
348 | 	elem:'#demo12',
349 | 	showclean:false
350 | })
351 |
352 |
353 | 不显示今天按钮: 354 | 代码 355 |
zaneDate({
356 | 	elem:'#demo13',
357 | 	shownow:false
358 | })
359 |
360 |
361 |
362 |
363 | 不显示确定按钮: 364 | 代码 365 |
zaneDate({
366 | 	elem:'#demo14',
367 | 	showsubmit:false
368 | })
369 |
370 |
371 | 不显所有按钮: 372 | 代码 373 |
zaneDate({
374 | 	elem:'#demo15',
375 | 	format:'yyyy-MM-dd',
376 | 	showtime:false,
377 | 	haveBotBtns:false
378 | })
379 |
380 |
381 |
382 |
383 | 初始化回调: 384 | 代码 385 |
zaneDate({
386 | 	elem:'#demo16',
387 | 	mounted:function(){
388 | 		document.getElementById('demo16').value="初始化完成!"
389 | 	}
390 | })
391 |
392 |
393 | 改变值回调: 394 | 代码 395 |
zaneDate({
396 | 	elem:'#demo17',
397 | 	change:function(fulltime,begintime,endtime){
398 | 		alert('fulltime:'+fulltime+'\r\nbegintime:'+begintime+'\r\nendtime:'+endtime)
399 | 	}
400 | })
401 |
402 |
403 |
404 |
405 | 完成回调: 406 | 代码 407 |
zaneDate({
408 | 	elem:'#demo18',
409 | 	done:function(fulltime,begintime,endtime){
410 | 		alert('fulltime:'+fulltime+'\r\nbegintime:'+begintime+'\r\nendtime:'+endtime)
411 | 	}
412 | })
413 |
414 |
415 | double完成回调: 416 | 代码 417 |
zaneDate({
418 | 	elem:'#demo27',
419 | 	type:'doubleday',
420 | 	done:function(fulltime,begintime,endtime){
421 | 		alert('fulltime:'+fulltime+'\r\nbegintime:'+begintime+'\r\nendtime:'+endtime)
422 | 	}
423 | })
424 |
425 |
426 |
427 |
428 | z-index值: 429 | 430 | 代码 431 |
zaneDate({
432 | 	elem:'#demo26',
433 | 	zindex:500
434 | })
435 |
436 |
437 |
双选择器案例
438 |
439 |
440 | doubleday: 441 | 442 | 代码 443 |
zaneDate({
444 | 	elem:'#demo21',
445 | 	begintime:'2017-10-15',
446 | 	endtime:'2017-10-25',
447 | 	type:'doubleday',
448 | })
449 |
450 |
451 | doubleyear: 452 | 453 | 代码 454 |
zaneDate({
455 | 	elem:'#demo22',
456 | 	begintime:'2020',
457 | 	endtime:'2025',
458 | 	type:'doubleyear',
459 | })
460 |
461 |
462 |
463 |
464 | doublemonth: 465 | 466 | 代码 467 |
zaneDate({
468 | 	elem:'#demo23',
469 | 	begintime:'2',
470 | 	endtime:'5',
471 | 	type:'doublemonth',
472 | })
473 |
474 |
475 | doubletime: 476 | 477 | 代码 478 |
zaneDate({
479 | 	elem:'#demo24',
480 | 	begintime:'12:10:10',
481 | 	endtime:'15:16:16',
482 | 	type:'doubletime',
483 | })
484 |
485 |
486 |
487 |
488 | doubleday支持时分秒: 489 | 490 | 代码 491 |
zaneDate({
492 | 	elem:'#demo25',
493 | 	format:'yyyy-MM-dd HH:mm:ss',
494 | 	type:'doubleday',
495 | 	begintime:'2017-09-20 12:10:10',
496 | 	endtime:'2017-10-01 15:16:16',
497 | 	showtime:true
498 | })
499 |
500 |
501 | doubletime 只选择时分: 502 | 503 | 代码 504 |
zaneDate({
505 | 	elem:'#demo24',
506 | 	begintime:'12:10',
507 | 	endtime:'15:16',
508 | 	type:'doubletime',
509 | 	showsecond:false
510 | })
511 |
512 |
513 |
英文版本案例
514 |
515 |
516 | 完整版: 517 | 518 | 代码 519 |
zaneDate({
520 | 	elem:'#demo30',
521 | 	lang:'cn',
522 | 	begintime:'2018-01-01 12:12:12',
523 | 	format:'yyyy-MM-dd HH:mm:ss',
524 | 	showtime:true
525 | })
526 |
527 |
528 | doubleday支持时分秒: 529 | 530 | 代码 531 |
zaneDate({
532 | 	elem:'#demo31',
533 | 	lang:'en',
534 | 	format:'yyyy-MM-dd HH:mm:ss',
535 | 	type:'doubleday',
536 | 	begintime:'2017-09-20 12:10:10',
537 | 	endtime:'2017-10-01 15:16:16',
538 | 	showtime:true,
539 | 	done:function(fulltime,begintime,endtime){
540 | 		alert('fulltime:'+fulltime+'\r\nbegintime:'+begintime+'\r\nendtime:'+endtime)
541 | 	}
542 | })
543 |
544 |
545 |
546 | 547 | 548 | 549 | 721 | 735 | 736 | -------------------------------------------------------------------------------- /src/dist/zane-calendar.min.js: -------------------------------------------------------------------------------- 1 | "use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,e){for(var a=0;a12?this.getHours()-12:this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"q+":Math.floor((this.getMonth()+3)/3),S:this.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length)));for(var a in e)new RegExp("("+a+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[a]:("00"+e[a]).substr((""+e[a]).length)));return t});var a=document,i="querySelector",n="querySelectorAll",o=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,e),this.config={elem:"#zane-calendar",type:"day",position:"fixed",lang:"cn",width:280,format:"yyyy-MM-dd",value:"",min:"",max:"",event:"click",showtime:!1,showclean:!0,shownow:!0,showsubmit:!0,haveBotBtns:!0,calendarName:"",isDouble:!1,mounted:function(){},change:function(){},done:function(){}},this.config=this.extend(this.config,t),isNaN(new Date(this.config.value))&&(this.config.value=""),isNaN(new Date(this.config.min))&&(this.config.min=""),isNaN(new Date(this.config.max))&&(this.config.max=""),this.obj={input:a[i](this.config.elem),calendar:null,id:"#zane-calendar-"+this.config.calendarName,$obj:null,fulldatas:{},$noDoubleObj:null,isDoubleOne:!1,handleType:"date",initVal:"",behindTop:10,calendarHeight:307,totalYear:18,cn:{weeks:["日","一","二","三","四","五","六"],time:["时","分","秒"],timeTips:"选择时间",startTime:"开始时间",endTime:"结束时间",dateTips:"返回日期",month:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],tools:{confirm:"确定",clear:"清空",now:"现在"}},en:{weeks:["Su","Mo","Tu","We","Th","Fr","Sa"],time:["Hours","Minutes","Seconds"],timeTips:"Select Time",startTime:"Start Time",endTime:"End Time",dateTips:"Select Date",month:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],tools:{confirm:"Confirm",clear:"Clear",now:"Now"}}},this.vision="1.2.0",this.auther="zane",this.obj.lang=this.obj[this.config.lang],"year"!=this.config.type&&"month"!=this.config.type||(this.config.haveBotBtns=!1),"time"==this.config.type&&(this.config.showtime=!1),this.init()}return _createClass(e,[{key:"init",value:function(){var e=this;this.on(this.obj.input,this.config.event,function(o){if(o.preventDefault(),o.stopPropagation(),e.obj.calendar)e.elemEventPoint(o);else{if(e.obj.isDoubleOne=-1!=e.config.calendarName.indexOf("DOUBLE"),e.obj.isDoubleOne){var s=e.config.calendarName.replace(/DOUBLE/,"");e.obj.$noDoubleObj=t[s],t[s].obj.$noDoubleObj=e}var l=e.objHTML(),c=a.createElement("div");switch(c.innerHTML=l,a.body.appendChild(c),e.$obj=a[i](e.obj.id),e.config.type){case"day":e.judgeCalendarRender("day",e.config.value);break;case"year":e.getYearHtml();break;case"month":e.getMonthHtml();break;case"time":e.getTimeHtml()}e.elemEventPoint(o),e.documentClick(),e.calendarClick()}e.obj.initVal=e.obj.input.value;var h=a[n](".zane-calendar");e.forEach(h,function(t,a){("#"+a.getAttribute("id")).replace(/DOUBLE/,"")!==e.obj.id.replace(/DOUBLE/,"")&&(a.style.display="none")})}),this.config.mounted&&this.config.mounted()}},{key:"objHTML",value:function(t){return'
\n\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\t\n\t\t\t\t\t\t\t
\t\n\t\t\t\t\t\t\t
\t\t\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t
'+this.obj.lang.timeTips+'
\n\t\t\t\t\t\t\t
\t\n\t\t\t\t \t\t\t
\n\t\t\t\t\t\t\t\t
'+this.obj.lang.tools.clear+'
\n\t\t\t\t\t\t\t\t
'+this.obj.lang.tools.now+'
\n\t\t\t\t\t\t\t\t
'+this.obj.lang.tools.confirm+"
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t
"}},{key:"topCheckDayHTML",value:function(t){var e='\t\n\t\t
';return"cn"==this.config.lang?e+='
\n\t\t\t\t'+t.year+'年\n\t\t\t\t'+t.month+"月\n\t\t\t
":e+='
\n\t\t\t\t'+this.weekToEn(t.month)+'\n\t\t\t\t'+t.year+"\n\t\t\t
",e+='
'}},{key:"mainCheckDayHTML",value:function(t){for(var e='\n\t\t
\n\t\t\t',a=0;a<7;a++)e+="";e+="";for(var i=0,n=t.datalist.length;inew Date(this.config.max).getTime())&&(o+=" calendar-disabled"),e+=0==i?'":i==n-1?'":(i+1)%7==0?'":'"}return e+="
"+this.obj.lang.weeks[a]+"
'+t.datalist[i].day+"'+t.datalist[i].day+"
'+t.datalist[i].day+"
'+t.datalist[i].day+"
"}},{key:"topCheckYearHTML",value:function(t){return'\n\t\t
\n\t\t
\n\t\t\t'+t.firstYear+("cn"==this.config.lang?"年":"")+"-\n\t\t\t"+t.lastYear+("cn"==this.config.lang?"年":"")+'\n\t\t
\n\t\t
'}},{key:"mainCheckYearHTML",value:function(t){for(var e='
\n\t\t\t',a=0,i=t.datalist.length;a":a==i-1?'":(a+1)%3==0?'":'"}return e+="
'+t.datalist[a].year+("cn"==this.config.lang?"年":"")+"'+t.datalist[a].year+("cn"==this.config.lang?"年":"")+"
'+t.datalist[a].year+("cn"==this.config.lang?"年":"")+"
'+t.datalist[a].year+("cn"==this.config.lang?"年":"")+"
\n\t\t
"}},{key:"topCheckMonthHTML",value:function(t){return'\n\t\t
\n\t\t
\n\t\t\t'+t.year+'年\n\t\t
\n\t\t
'}},{key:"mainCheckMonthHTML",value:function(t){for(var e='
\n\t\t\t',a=0,i=t.datalist.length;a":a==i-1?'":(a+1)%3==0?'":'"}return e+="
'+t.datalist[a]+"'+t.datalist[a]+"
'+t.datalist[a]+"
'+t.datalist[a]+"
\n\t\t
"}},{key:"topCheckTimeHTML",value:function(){return'
'+this.obj.lang.timeTips+"
"}},{key:"mainCheckTimeHTML",value:function(t){for(var e='
\n\t\t\t\t
    ',a=0,i=t.hours.length;a'+t.hours[a]+""}e+='
    ';for(var o=0,s=t.minutes.length;o'+t.minutes[o]+""}e+='
    ';for(var c=0,h=t.seconds.length;c'+t.seconds[c]+""}return e+="
"}},{key:"bottomCheckTimeHTML",value:function(){var t="";return"time"===this.obj.handleType?t+='
'+this.obj.lang.dateTips+"
":t+='
'+this.obj.lang.timeTips+"
",t}},{key:"elemEventPoint",value:function(t){this.obj.calendar=this.$obj;var e=a.documentElement.clientWidth,i=a.documentElement.clientHeight,n=a.documentElement.scrollTop,o=t.target.offsetTop,s=t.target.offsetLeft,l=t.target.offsetHeight,c=i-(o+l+this.obj.behindTop-n),h=e-s-this.config.width;this.obj.calendar.style.display="block",this.obj.calendarHeight=this.$obj.offsetHeight,this.obj.isDoubleOne&&h>=this.config.width?this.obj.calendar.style.left=s+this.config.width+"px":this.obj.calendar.style.left=s+"px",c>this.obj.calendarHeight?this.config.isDouble&&this.obj.isDoubleOne&&h=12?(n+=1,o=1):o+=1:this.config.isDouble&&!this.obj.isDoubleOne&&"pre"==e&&(o<=1?(n-=1,o=12):o-=1),o=(o+"").length<2?"0"+o:o,s=(s+"").length<2?"0"+s:s,l=(l+"").length<2?"0"+l:l,c=(c+"").length<2?"0"+c:c,h=(h+"").length<2?"0"+h:h;var r=new Date(n,o,0).getDate(),d=new Date(n+"/"+o+"/1").getDay(),u=(new Date(n+"/"+o+"/"+r).getDay(),null);if(d>0){var f=new Date(n,o-1,0).getDate(),m=n,b=o-1;0===b&&(m=n-1,b=12);for(var y=0,g=d;y1&&void 0!==arguments[1])||arguments[1],n=null;if(t&&-1!=t.indexOf("|")){var o=t.split("|"),s=null,l=null;e?(s=new Date(o[0]).Format(this.config.format),l=new Date(o[1]).Format(this.config.format)):(s=o[0],l=o[1]),n=s+" - "+l}else n=e?new Date(t).Format(this.config.format):t;"INPUT"!==this.obj.input.nodeName?this.obj.input.textContent=n:this.obj.input.value=n,this.$obj.style.display="none",this.obj.isDoubleOne&&(a[i](this.obj.$noDoubleObj.obj.id).style.display="none"),this.config.done&&this.config.done(n),this.obj.initVal!=n&&this.config.change&&this.config.change(n)}},{key:"judgeCalendarRender",value:function(t,e,a,n){var o=void 0,s=void 0,l=void 0;switch(t){case"day":this.obj.handleType="day";var c=this.getTimeDates(e,n);this.obj.fulldatas=c,this.compareSize(a,n),s=this.topCheckDayHTML(c),o=this.mainCheckDayHTML(c),this.renderCommonHtml("day",s,o),this.countHeight(".main-check-day",7),this.getDay();break;case"year":this.obj.handleType="year",this.compareSize(a,n),o=this.mainCheckYearHTML(e),s=this.topCheckYearHTML(e),this.renderCommonHtml("year",s,o),this.countHeight(".main-check-year",6),this.getYear();break;case"month":this.obj.handleType="month",o=this.mainCheckMonthHTML(e),s=this.topCheckMonthHTML(e),this.renderCommonHtml("month",s,o),this.countHeight(".main-check-month",4),this.getMonth();break;case"time":this.obj.handleType="time",o=this.mainCheckTimeHTML(e),s=this.topCheckTimeHTML(),l=this.bottomCheckTimeHTML(),this.renderCommonHtml("time",s,o,l);var h=this.$obj[i]("ul.hour")[i]("li.active").offsetTop,r=this.$obj[i]("ul.minute")[i]("li.active").offsetTop,d=this.$obj[i]("ul.second")[i]("li.active").offsetTop;this.$obj[i]("ul.hour").scrollTop=h-150,this.$obj[i]("ul.minute").scrollTop=r-150,this.$obj[i]("ul.second").scrollTop=d-150,this.selectTime()}}},{key:"renderCommonHtml",value:function(t,e,a,o){var s=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];"time"!=t&&s||(this.$obj[i](".btn-select-time").innerHTML=o),s&&(this.$obj[i](".top-check-"+t).innerHTML=e,this.$obj[i](".main-check-"+t).innerHTML=a),this.showOrHide(this.$obj[n](".common-top"),"hide"),this.showOrHide(this.$obj[n](".common-main"),"hide"),this.$obj[i](".main-check-"+t).style.display="block",this.$obj[i](".top-check-"+t).style.display="block"}},{key:"compareSize",value:function(t,e){if(t){var a=this.obj.fulldatas,i=this.obj.$noDoubleObj;this.config.isDouble&&a&&i&&(i=i.obj.fulldatas,this.obj.isDoubleOne?this.getDoubleTime({prev:i,next:a,clickType:e}):this.getDoubleTime({prev:a,next:i,clickType:e}))}}},{key:"getDoubleTime",value:function(t){var e=void 0,a=void 0,i=void 0;switch(this.config.type){case"day":a=t.prev.year+"/"+t.prev.month+"/"+t.prev.today,e=t.next.year+"/"+t.next.month+"/"+t.next.today,new Date(a).getTime()>=(i=new Date(e).getTime())-864e5&&this.obj.$noDoubleObj.judgeCalendarRender("day",i,!1,t.clickType);break;case"year":""+t.prev.year>=(i=""+t.next.year)&&this.obj.$noDoubleObj.getYearHtml(i,!1,t.clickType)}}},{key:"calendarClick",value:function(){this.on(this.obj.calendar,"click",function(t){t.preventDefault(),t.stopPropagation()})}},{key:"extend",value:function(t,e){return Object.assign(t,e)}},{key:"hasClass",value:function(t,e){return t.className.match(new RegExp("(\\s|^)"+e+"(\\s|$)"))}},{key:"addClass",value:function(t,e){this.hasClass(t,e)||(t.className+=" "+e)}},{key:"removeClass",value:function(t,e){if(this.hasClass(t,e)){var a=new RegExp("(\\s|^)"+e+"(\\s|$)");t.className=t.className.replace(a," ")}}},{key:"forEach",value:function(t,e){var a=void 0;if("function"!=typeof e)return this;if(t=t||[],"[object Object]"==Object.prototype.toString.call(t)){for(a in t)if(e.call(t[a],a,t[a]))break}else if("[object NodeList]"==Object.prototype.toString.call(t)||"[object Array]"==Object.prototype.toString.call(t))for(a=0;a0&&void 0!==arguments[0]?arguments[0]:{},n=e.elem.substring(1);n=n.replace(/[_-]/g,"").toUpperCase(),e.calendarName=a&&a.double?n+a.double:n,e.width&&(e.width=e.width<260?260:e.width,e.width=e.width>500?500:e.width);var s=Object.assign(i(e),a);t[e.calendarName]=new o(s)}function i(t,e){e=e||{};for(var a in t)t.hasOwnProperty(a)&&("object"===_typeof(t[a])?(e[a]="[object Array]"===Object.prototype.toString.call(t[a])?[]:{},i(t[a],e[a])):e[a]=t[a]);return e}e.type=e.type||"day",-1!=e.type.indexOf("double")?(e.type=e.type.replace(/double/,""),a({showclean:!1,shownow:!1,showsubmit:!1,isDouble:!0}),a({shownow:!1,showtime:!1,isDouble:!0,double:"DOUBLE"})):a()};return e||(t.zaneDate=s),s}); -------------------------------------------------------------------------------- /dist/zane-calendar.min.js: -------------------------------------------------------------------------------- 1 | "use strict";var _createClass=function(){function a(t,e){for(var i=0;i\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\t\n\t\t\t\t\t\t\t
\t\n\t\t\t\t\t\t\t
\t\t\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t
'+this.obj.lang.timeTips+'
\n\t\t\t\t\t\t\t
\t\n\t\t\t\t \t\t\t
\n\t\t\t\t\t\t\t\t
'+this.obj.lang.tools.clear+'
\n\t\t\t\t\t\t\t\t
'+this.obj.lang.tools.now+'
\n\t\t\t\t\t\t\t\t
'+this.obj.lang.tools.confirm+"
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t"}},{key:"topCheckDayHTML",value:function(t){var e='\t\n\t\t
';return"cn"==this.config.lang?e+='
\n\t\t\t\t'+t.year+'年\n\t\t\t\t'+t.month+"月\n\t\t\t
":e+='
\n\t\t\t\t'+this.weekToEn(t.month)+'\n\t\t\t\t'+t.year+"\n\t\t\t
",e+='
'}},{key:"mainCheckDayHTML",value:function(t){for(var e='\n\t\t
\n\t\t\t',i=0;i<7;i++)e+="";e+="";for(var a=0,n=t.datalist.length;anew Date(this.config.max).getTime())&&(o+=" calendar-disabled"),e+=0==a?'":a==n-1?'":(a+1)%7==0?'":'"}return e+="
"+this.obj.lang.weeks[i]+"
'+t.datalist[a].day+"'+t.datalist[a].day+"
'+t.datalist[a].day+"
'+t.datalist[a].day+"
"}},{key:"topCheckYearHTML",value:function(t){return'\n\t\t
\n\t\t
\n\t\t\t'+t.firstYear+("cn"==this.config.lang?"年":"")+"-\n\t\t\t"+t.lastYear+("cn"==this.config.lang?"年":"")+'\n\t\t
\n\t\t
'}},{key:"mainCheckYearHTML",value:function(t){for(var e='
\n\t\t\t',i=0,a=t.datalist.length;i":i==a-1?'":(i+1)%3==0?'":'"}return e+="
'+t.datalist[i].year+"'+t.datalist[i].year+"
'+t.datalist[i].year+"
'+t.datalist[i].year+"
\n\t\t
"}},{key:"topCheckMonthHTML",value:function(t){return'\n\t\t
\n\t\t
\n\t\t\t'+t.year+'年\n\t\t
\n\t\t
'}},{key:"mainCheckMonthHTML",value:function(t){for(var e='
\n\t\t\t',i=0,a=t.datalist.length;i":i==a-1?'":(i+1)%3==0?'":'"}return e+="
'+t.datalist[i]+"'+t.datalist[i]+"
'+t.datalist[i]+"
'+t.datalist[i]+"
\n\t\t
"}},{key:"topCheckTimeHTML",value:function(){return'
'+this.obj.lang.timeTips+"
"}},{key:"mainCheckTimeHTML",value:function(t){for(var e='
\n\t\t\t\t
    ',i=0,a=t.hours.length;i'+t.hours[i]+""}e+='
    ';for(var o=0,s=t.minutes.length;o'+t.minutes[o]+""}if(this.config.showsecond){e+='
    ';for(var c=0,h=t.seconds.length;c'+t.seconds[c]+""}}return e+="
"}},{key:"bottomCheckTimeHTML",value:function(){var t="";return"time"===this.obj.handleType?t+='
'+this.obj.lang.dateTips+"
":t+='
'+this.obj.lang.timeTips+"
",t}},{key:"elemEventPoint",value:function(t){var e=t.srcElement||t.target;this.obj.calendar=this.$obj;var i=e.getBoundingClientRect(),a=i.left,n=i.top,o=m.documentElement.clientWidth,s=m.documentElement.clientHeight,l=document.documentElement.scrollTop||u.pageYOffset||document.body.scrollTop,c=t.target.offsetHeight,h=s-(n+c+this.config.behindTop),r=o-a-this.config.width,d=this.$obj.offsetHeight;this.obj.calendar.style.display="block",this.obj.isDoubleOne&&r>=this.config.width?this.obj.calendar.style.left=a+this.config.width+"px":this.obj.calendar.style.left=a+"px",d12?this.getHours()-12:this.getHours(), //小时 32 | "H+": this.getHours(), 33 | "m+": this.getMinutes(), //分 34 | "s+": this.getSeconds(), //秒 35 | "q+": Math.floor((this.getMonth() + 3) / 3), //季度 36 | "S": this.getMilliseconds() //毫秒 37 | }; 38 | if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 39 | for (var k in o) 40 | if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); 41 | return fmt; 42 | } 43 | }; 44 | 45 | let doc = document, 46 | query = 'querySelector', 47 | quall = 'querySelectorAll'; 48 | 49 | // 日期插件 50 | class calendar{ 51 | constructor(json={}){ 52 | this.config={ 53 | //控件的dom原生仅限制于id 54 | elem:'#zane-calendar', 55 | //可选 day year month time doubleday doubleyear doublemonth doubletime 56 | type:'day', 57 | //absolute , fixed 58 | position:'fixed', 59 | //cn , en 60 | lang:'cn', 61 | // 宽度 62 | width:250, 63 | // 插件高度配置 64 | height:280, 65 | //插件于输入框的高度 66 | behindTop:10, 67 | // 格式化 68 | format:'yyyy/MM/dd', //'yyyy-MM-dd HH:mm:ss' 69 | // 初始默认值 70 | value:'', 71 | // 可选取时间最小范围 72 | min:'', //'1900-10-01', 73 | // 可选取时间最大范围 74 | max: '', //'2099-12-31', 75 | //事件方式 click 76 | event:'click', 77 | // z-index的值 78 | zindex:100, 79 | //是否显示选择时间 80 | showtime:false, 81 | //是否显示清除按钮 82 | showclean:true, 83 | //是否显示当前按钮 84 | shownow:true, 85 | //是否显示提交按钮 86 | showsubmit:true, 87 | // 是否有底部按钮列表 88 | haveBotBtns:true, 89 | // type='time'时是否显示秒单位 90 | showsecond:true, 91 | 92 | calendarName:'', 93 | isDouble:false, 94 | // 插件加载完成之后调用 95 | mounted:()=>{}, 96 | //时间变更之后调用 97 | change:()=>{}, 98 | //选择完成之后调用 99 | done:()=>{}, 100 | } 101 | this.config = this.extend(this.config,json); 102 | //校验时间格式 103 | if(!this.config.value)this.config.value = '' 104 | if(!this.config.min)this.config.min = '' 105 | if(!this.config.max)this.config.max = '' 106 | 107 | // 初始化 108 | this.init(); 109 | } 110 | 111 | // 生成对象obj 112 | generateCalendarObj(){ 113 | this.obj={ 114 | input:doc[query](this.config.elem), 115 | calendar:null, 116 | id:`#zane-calendar-${this.config.calendarName}`, 117 | $obj:null, 118 | fulldatas:{}, 119 | $noDoubleObj:null, 120 | isDoubleOne:false, 121 | handleType:'date', 122 | initVal:'',//每次进来的初始值 123 | // 选择年时展示的数量 124 | totalYear:18, 125 | cn:{ 126 | weeks: ['日', '一', '二', '三', '四', '五', '六'], 127 | time: ['时', '分', '秒'], 128 | timeTips: '选择时间', 129 | startTime: '开始时间', 130 | endTime: '结束时间', 131 | dateTips: '返回日期', 132 | month: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], 133 | tools: { 134 | confirm: '确定', 135 | clear: '清空', 136 | now: '现在' 137 | } 138 | }, 139 | en:{ 140 | weeks: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], 141 | time: ['Hours', 'Minutes', 'Seconds'], 142 | timeTips: 'Select Time', 143 | startTime: 'Start Time', 144 | endTime: 'End Time', 145 | dateTips: 'Select Date', 146 | month: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 147 | tools: { 148 | confirm: 'Confirm', 149 | clear: 'Clear', 150 | now: 'Now' 151 | } 152 | } 153 | } 154 | 155 | this.vision = '2.0.9' 156 | this.auther = 'zane' 157 | 158 | this.obj.lang = this.obj[this.config.lang]; 159 | 160 | if(this.config.type == 'year' || this.config.type == 'month'){ 161 | this.config.haveBotBtns = false; 162 | } 163 | 164 | if(this.config.type == 'time'){ 165 | this.config.showtime =false; 166 | } 167 | 168 | // double 处理 169 | if(this.config.isDouble){ 170 | this.obj.input.nodeName !== 'INPUT'? 171 | this.obj.input.textContent = this.config.doublevalue : 172 | this.obj.input.value = this.config.doublevalue; 173 | }else if(!this.config.isDouble){ 174 | this.obj.input.nodeName !== 'INPUT'? 175 | this.obj.input.textContent = this.config.value : 176 | this.obj.input.value = this.config.value; 177 | } 178 | } 179 | 180 | init(){ 181 | this.generateCalendarObj() 182 | this.on(this.obj.input,this.config.event, (e)=>{ 183 | e.preventDefault(); 184 | e.stopPropagation(); 185 | 186 | // 隐藏其他时间插件框 187 | let objs = doc[quall]('.zane-calendar'); 188 | this.forEach(objs,(index,item)=>{ 189 | let itemId = item.getAttribute('id') 190 | if (('#' + itemId).replace(/DOUBLE/,'') !== this.obj.id.replace(/DOUBLE/,'') ){ 191 | itemId = itemId.replace('zane-calendar-','') 192 | this.removeCalendar() 193 | } 194 | }) 195 | 196 | let obj = doc[query](this.obj.id); 197 | 198 | if(obj){ 199 | this.obj.calendar = obj; 200 | this.$obj = obj; 201 | }; 202 | 203 | 204 | // double 赋值 205 | this.obj.isDoubleOne = this.config.calendarName.indexOf('DOUBLE') != -1?true:false; 206 | if(this.obj.isDoubleOne ){ 207 | let noDoubleObj = this.config.calendarName.replace(/DOUBLE/,'') 208 | this.obj.$noDoubleObj = window[noDoubleObj]; 209 | window[noDoubleObj].obj.$noDoubleObj = this; 210 | }; 211 | 212 | // 设置默认值 213 | let defaultValue,inpValue; 214 | defaultValue = this.obj.input.nodeName === 'INPUT'?this.obj.input.value.trim():this.obj.input.textContent.trim() 215 | if(defaultValue){ 216 | // 中文处理 217 | defaultValue = defaultValue.replace(/[\u4e00-\u9fa5]+/g,function($a,$b){ 218 | if($a=='年'||$a=='月'){ 219 | return '/' 220 | }else if($a=='时'||$a=='分'){ 221 | return ':' 222 | }else if($a=='秒'||$a=='日'){ 223 | return '' 224 | } 225 | }) 226 | if(this.config.isDouble){ 227 | let arr = defaultValue.split('-') 228 | let begintime = arr[1].trim() 229 | let endtime = arr[0].trim() 230 | this.config.value = this.obj.isDoubleOne ? begintime : endtime 231 | this.config.begintime = endtime 232 | this.config.endtime = begintime 233 | }else{ 234 | this.config.value = defaultValue 235 | } 236 | 237 | } 238 | 239 | // 过滤重复生成 240 | if (doc[query](this.obj.id)) return; 241 | 242 | // 获得年月日 243 | let html = this.objHTML();//生成时间选择器HTML 244 | var divElement = doc.createElement("div"); 245 | divElement.innerHTML = html 246 | doc.body.appendChild(divElement) 247 | 248 | this.$obj = doc[query](this.obj.id); 249 | 250 | switch(this.config.type){ 251 | case 'day': 252 | this.judgeCalendarRender('day',this.config.value) 253 | break; 254 | case 'year': 255 | this.getYearHtml(this.config.value); 256 | break; 257 | case 'month': 258 | this.getMonthHtml(this.config.value); 259 | break; 260 | case 'time': 261 | this.getTimeHtml(this.config.value); 262 | break; 263 | } 264 | 265 | //定位并显示选择器 266 | this.elemEventPoint(e); 267 | this.documentClick(); 268 | this.calendarClick(); 269 | 270 | this.obj.initVal = this.obj.input.value; 271 | }); 272 | this.config.mounted&&this.config.mounted(); 273 | } 274 | 275 | //生成时间选择器区域 276 | objHTML(json){ 277 | let html =`
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
294 |
295 |
${this.obj.lang.timeTips}
296 |
297 |
298 |
${this.obj.lang.tools.clear}
301 |
${this.obj.lang.tools.now}
304 |
${this.obj.lang.tools.confirm}
307 |
308 |
309 |
310 |
` 311 | return html 312 | } 313 | // day - top html 时间选择器选择年月块 314 | topCheckDayHTML(json){ 315 | let html =` 316 |
` 317 | if (this.config.lang == 'cn'){ 318 | html += `
319 | ${json.year}年 320 | ${json.month}月 321 |
` 322 | }else{ 323 | html += `
324 | ${this.weekToEn(json.month)} 325 | ${json.year} 326 |
` 327 | } 328 | html +=`
` 329 | return html; 330 | } 331 | 332 | // day - main html 时间选择器选择日期块 333 | mainCheckDayHTML(json){ 334 | let html =` 335 |
336 | ` 337 | for (let j = 0,len = 7; j${this.obj.lang.weeks[j]}` 339 | } 340 | html +=`` 341 | for (let i = 0,len=json.datalist.length; i < len; i++) { 342 | let className = json.datalist[i].class||""; 343 | let sele_act = json.datalist[i].sele_act || ''; 344 | if(json.datalist[i].day === parseInt(json.today)&&json.datalist[i].daytype==='now'){ 345 | className += this.config.isDouble ? ` act_block` : ` active` 346 | } 347 | //如果超出min时间或者max时间的,给禁止选中样式 348 | if((this.config.min!='' && new Date(json.datalist[i].fullday).getTime()new Date(this.config.max).getTime())){ 349 | className+=` calendar-disabled` 350 | } 351 | if(i == 0){ 352 | html += ``; 353 | }else if(i == len-1){ 354 | html += ``; 355 | }else{ 356 | if((i+1)%7 == 0){ 357 | html += ``; 358 | }else{ 359 | html += ``; 360 | } 361 | } 362 | } 363 | 364 | html+=`
${json.datalist[i].day}${json.datalist[i].day}
${json.datalist[i].day}
${json.datalist[i].day}
` 365 | return html; 366 | } 367 | 368 | // year - top html 时间选择器选择年份状态头部 369 | topCheckYearHTML(json){ 370 | let html=` 371 |
372 |
373 | ${json.firstYear}${this.config.lang=='cn'?'年':''}- 374 | ${json.lastYear}${this.config.lang=='cn'?'年':''} 375 |
376 |
` 377 | return html; 378 | } 379 | // year - main html 时间选择器选择年份状态内容块 380 | mainCheckYearHTML(json){ 381 | let html=`
382 | ` 383 | for (let i = 0,len=json.datalist.length; i < len; i++) { 384 | let className = json.datalist[i].class||""; 385 | if(json.datalist[i].year === json.nowyear){ 386 | className+=` active` 387 | } 388 | if(i == 0){ 389 | html+=``; 390 | }else if(i == len-1){ 391 | html+=``; 392 | }else{ 393 | if((i+1)%3 == 0){ 394 | html+=``; 395 | }else{ 396 | html+=``; 397 | } 398 | } 399 | } 400 | html+=`
${json.datalist[i].year}${json.datalist[i].year}
${json.datalist[i].year}
${json.datalist[i].year}
401 |
` 402 | return html; 403 | } 404 | 405 | // month -top html 时间选择器选择月份头部 406 | topCheckMonthHTML(json){ 407 | let html=` 408 |
409 |
410 | ${json.year}年 411 |
412 |
` 413 | return html; 414 | } 415 | // month -main html 时间选择器选择月份状态内容块 416 | mainCheckMonthHTML(json){ 417 | let html=`
418 | ` 419 | for (let i = 0,len=json.datalist.length; i < len; i++) { 420 | let className = json.datalist[i].class||""; 421 | if((i+1) === parseInt(json.nowmonth)){ 422 | className+=` active` 423 | } 424 | if(i == 0){ 425 | html+=``; 426 | }else if(i == len-1){ 427 | html+=``; 428 | }else{ 429 | if((i+1)%3 == 0){ 430 | html+=``; 431 | }else{ 432 | html+=``; 433 | } 434 | } 435 | } 436 | html+=`
${json.datalist[i]}${json.datalist[i]}
${json.datalist[i]}
${json.datalist[i]}
437 |
` 438 | return html; 439 | } 440 | 441 | // time -top html 时间选择器选择时间状态头部 442 | topCheckTimeHTML(){ 443 | let html=`
${this.obj.lang.timeTips}
` 444 | return html; 445 | } 446 | // time -main html 时间选择器选择时间状态内容块 447 | mainCheckTimeHTML(json){ 448 | let html = `
453 |
    ` 454 | for (let i = 0,len=json.hours.length; i < len; i++) { 455 | let className=''; 456 | if(json.hours[i] == json.hour) className='active'; 457 | html +=`
  • ${json.hours[i]}
  • ` 458 | } 459 | html+=`
    ` 460 | for (let i = 0,len=json.minutes.length; i < len; i++) { 461 | let className=''; 462 | if(json.minutes[i] == json.minute) className='active'; 463 | html +=`
  • ${json.minutes[i]}
  • ` 464 | } 465 | if(this.config.showsecond){ 466 | html+=`
    ` 467 | for (let i = 0,len=json.seconds.length; i < len; i++) { 468 | let className=''; 469 | if(json.seconds[i] == json.second) className='active'; 470 | html +=`
  • ${json.seconds[i]}
  • ` 471 | } 472 | } 473 | html+=`
` 474 | return html; 475 | } 476 | 477 | // time -bottom html 时间选择器日期/时间切换块 478 | bottomCheckTimeHTML(){ 479 | let html = ''; 480 | if(this.obj.handleType === 'time'){ 481 | html+= `
${this.obj.lang.dateTips}
` 482 | }else{ 483 | html+= `
${this.obj.lang.timeTips}
` 484 | } 485 | return html; 486 | } 487 | 488 | // 插件位置定位并显示 489 | elemEventPoint(e){ 490 | let secElement = e.srcElement || e.target 491 | this.obj.calendar = this.$obj; 492 | let rectObject = secElement.getBoundingClientRect() 493 | let objOffsetLeft = rectObject.left 494 | let objOffsetTop = rectObject.top 495 | let winWidth = doc.documentElement.clientWidth 496 | let screenClientHeight = doc.documentElement.clientHeight 497 | let screenScrolTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; 498 | let objOffsetHeight = e.target.offsetHeight 499 | let objBotton = screenClientHeight-(objOffsetTop+objOffsetHeight+this.config.behindTop) 500 | let betweenRight = winWidth-objOffsetLeft-this.config.width 501 | let calendHeight = this.$obj.offsetHeight 502 | this.obj.calendar.style.display = 'block'; 503 | 504 | // 设置插件point位置 505 | if(this.obj.isDoubleOne&&betweenRight>=this.config.width){ 506 | this.obj.calendar.style.left = objOffsetLeft+this.config.width+'px'; 507 | }else{ 508 | this.obj.calendar.style.left = objOffsetLeft+'px'; 509 | }; 510 | //double 处理 511 | if(objBotton > calendHeight){ 512 | //插件在input框之下 513 | this.config.isDouble&&this.obj.isDoubleOne&&betweenRight 12){ 538 | year = year + 1; 539 | month = 1; 540 | } 541 | }else if(this.config.isDouble&&!this.obj.isDoubleOne&&clickType=='pre'){ 542 | if(month < 1){ 543 | year = year - 1; 544 | month = 12; 545 | } 546 | } 547 | month = (month+'').length<2? '0'+month : month; 548 | toDate = (toDate+'').length<2? '0'+toDate : toDate; 549 | hour = (hour+'').length<2? '0'+hour : hour; 550 | minute = (minute+'').length<2? '0'+minute:minute; 551 | second = (second+'').length<2? '0'+second:second; 552 | // 计算当前这个月的天数 553 | let monTotalDay = new Date(year,month,0).getDate() 554 | // 计算第一天是周几 555 | let firstDayMeek = new Date(`${year}/${month}/1`).getDay() 556 | let lastDayMeek = new Date(`${year}/${month}/${monTotalDay}`).getDay() 557 | let preweek = null; 558 | let preday = null; 559 | // 计算需要补充的时间 560 | if(firstDayMeek>0){ 561 | let preMonTotalDay = new Date(year,month-1,0).getDate() 562 | let preyear = year; 563 | let premonth = month-1; 564 | if(premonth === 0){ 565 | preyear = year-1; 566 | premonth = 12; 567 | } 568 | for (var i = 0,len=firstDayMeek; i < len; i++) { 569 | let day = preMonTotalDay-i; 570 | premonth = (premonth+'').length<2?'0'+premonth:premonth; 571 | day = (day+'').length<2?'0'+day:day; 572 | let fullday = `${preyear}/${premonth}/${day}`; 573 | let sele_act = this.hasSelectAct(fullday, this.config.begintime, this.config.endtime) ? 'sele_act' : ''; 574 | 575 | timeDatas.push({ 576 | day:preMonTotalDay-i, 577 | week:len-1-i, 578 | class:'light', 579 | sele_act: sele_act, 580 | daytype:`pre`, 581 | fullday: fullday 582 | }) 583 | } 584 | } 585 | timeDatas = timeDatas.reverse(); 586 | for (let i = 0,len=monTotalDay; i < len; i++) { 587 | let weekday = (firstDayMeek+i)%7; 588 | let premonth = month; 589 | let day = i+1 590 | premonth = (premonth+'').length<2?'0'+premonth:premonth; 591 | day = (day+'').length<2?'0'+day:day; 592 | let fullday = `${year}/${premonth}/${day}`; 593 | let sele_act = this.hasSelectAct(fullday, this.config.begintime, this.config.endtime) ? 'sele_act' : ''; 594 | 595 | timeDatas.push({ 596 | day:i+1, 597 | week:weekday, 598 | daytype:`now`, 599 | sele_act: sele_act, 600 | fullday: fullday 601 | }) 602 | if(i === len-1){ 603 | preweek = weekday; 604 | preday = i+1; 605 | } 606 | } 607 | 608 | let totalLength = timeDatas.length; 609 | let haveNeedLength = 42-totalLength; 610 | 611 | let preyear = year; 612 | let premonth = parseInt(month)+1; 613 | if(premonth === 13){ 614 | preyear = year+1; 615 | premonth = 1; 616 | } 617 | 618 | for (var i = 0; i < haveNeedLength; i++) { 619 | let weekday = (preweek+1+i)%7; 620 | let day = i+1; 621 | premonth = (premonth+'').length<2?'0'+premonth:premonth; 622 | day = (day+'').length<2?'0'+day:day; 623 | let fullday = `${preyear}/${premonth}/${day}`; 624 | let sele_act = this.hasSelectAct(fullday, this.config.begintime, this.config.endtime) ? 'sele_act' : ''; 625 | 626 | timeDatas.push({ 627 | day:i+1, 628 | week:weekday, 629 | class:'light', 630 | sele_act: sele_act, 631 | daytype:`next`, 632 | fullday: fullday 633 | }) 634 | } 635 | setTimeout(()=>{if (!this.config.begintime && !this.config.endtime) this.setBeginEndTime(`${year}/${month}/${toDate}`);},1000); 636 | return { 637 | year:year, 638 | month:month, 639 | today:toDate, 640 | hour:hour, 641 | minute:minute, 642 | second:second, 643 | datalist:timeDatas 644 | } 645 | } 646 | 647 | hasSelectAct(nowTime,beginTime,endTime){ 648 | let result = false; 649 | if (this.config.isDouble && this.config.begintime && this.config.endtime) { 650 | nowTime = typeof (nowTime) === 'number' ? nowTime : new Date(nowTime).getTime() 651 | beginTime = typeof (beginTime) === 'number' ? beginTime : new Date(beginTime.replace(/-/g, '/')).getTime(); 652 | endTime = typeof (endTime) === 'number' ? endTime : new Date(endTime.replace(/-/g, '/')).getTime(); 653 | if (nowTime >= beginTime && nowTime <= endTime) result = true; 654 | } 655 | return result; 656 | } 657 | 658 | // 选择上一月 659 | preMonth(year,month){ 660 | month = month-1 661 | if(month == 0) { 662 | month = 12; 663 | year = year-1 664 | } 665 | let today = this.obj.fulldatas.today 666 | let totalday = new Date(year, month, 0).getDate() 667 | if (today > totalday) today = totalday 668 | let fulldate = `${year}/${month}/${today}` 669 | let isreset = this.config.isDouble&&this.obj.isDoubleOne?true:false 670 | this.setBeginEndTime(fulldate); 671 | this.judgeCalendarRender('day',fulldate,isreset,'pre') 672 | } 673 | 674 | // 选择下一月 675 | nextMonth(year,month){ 676 | month = month+1 677 | if(month == 13) { 678 | month = 1; 679 | year = year+1 680 | } 681 | let today = this.obj.fulldatas.today 682 | let totalday = new Date(year, month, 0).getDate() 683 | if (today > totalday) today = totalday 684 | let fulldate = `${year}/${month}/${today}` 685 | let isreset = this.config.isDouble&&!this.obj.isDoubleOne?true:false 686 | this.setBeginEndTime(fulldate); 687 | this.judgeCalendarRender('day',fulldate,isreset,'next') 688 | } 689 | 690 | setBeginEndTime(dataTime){ 691 | if (this.config.isDouble) { 692 | if (!this.obj.isDoubleOne) { 693 | this.config.begintime = dataTime; 694 | this.obj.$noDoubleObj.config.begintime = dataTime; 695 | } else { 696 | this.config.endtime = dataTime; 697 | this.obj.$noDoubleObj.config.endtime = dataTime; 698 | } 699 | } 700 | } 701 | 702 | // 获得年月日,如果showtime=true,日期加样式,如果为false,直接设置当前选择的日期 703 | getDay(){ 704 | let _this=this; 705 | let objs = this.$obj 706 | [query]('.main-check-day')[quall]('td'); 707 | // 绑定单击 708 | this.on(objs,'click',function(e){ 709 | let node = e.target.nodeName=='SPAN'?e.target.parentNode:e.target 710 | if(!_this.hasClass(node,'calendar-disabled')){//有calendar-disabled样式的不赋予事件 711 | let dataTime = this.getAttribute('data-time'); 712 | let arr = dataTime.split('/') 713 | let fulldatas = { 714 | year: arr[0], 715 | month: arr[1], 716 | today: arr[2], 717 | hour: _this.obj.fulldatas.hour, 718 | minute: _this.obj.fulldatas.minute, 719 | second: _this.obj.fulldatas.second 720 | } 721 | _this.setBeginEndTime(dataTime) 722 | if (_this.config.isDouble) { 723 | const result = _this.compareTimes('getDay', _this.obj.$noDoubleObj.obj.fulldatas, fulldatas); 724 | if (result) return; 725 | } 726 | _this.obj.fulldatas.year = arr[0] 727 | _this.obj.fulldatas.month = arr[1] 728 | _this.obj.fulldatas.today = arr[2] 729 | //选择具体日期添加样式 730 | _this.addOrRemoveClass(this); 731 | // double 处理 732 | if(!_this.config.showtime && !_this.config.isDouble){ 733 | let value = `${_this.obj.fulldatas.year}/${_this.obj.fulldatas.month}/${_this.obj.fulldatas.today}` 734 | _this.getYearMonthAndDay(value,true) 735 | } 736 | } 737 | }) 738 | // 绑定双击 739 | !this.config.isDouble&&this.on(objs,'dblclick',function(e){ 740 | let node = e.target.nodeName=='SPAN'?e.target.parentNode:e.target 741 | if(e.type === 'dblclick'&&!_this.hasClass(node,'calendar-disabled')) _this.makeSureSelectTime(); 742 | }) 743 | } 744 | 745 | addOrRemoveClass(that){ 746 | const _this = this; 747 | let objs = this.$obj[query]('.main-check-day')[quall]('td'); 748 | if (_this.config.isDouble) { 749 | let otherobjs = _this.obj.$noDoubleObj.$obj[query]('.main-check-day')[quall]('td'); 750 | _this.forEach(objs, (index, item) => { 751 | let newtime = item.getAttribute('data-time') 752 | let result = _this.hasSelectAct(newtime, _this.config.begintime, _this.config.endtime) 753 | if (that) _this.removeClass(item, 'act_block'); 754 | if (result){ 755 | if (!_this.hasClass(item, 'sele_act')) _this.addClass(item, 'sele_act'); 756 | } else { 757 | _this.removeClass(item, 'sele_act') 758 | } 759 | }) 760 | _this.forEach(otherobjs, (index, item) => { 761 | let newtime = item.getAttribute('data-time') 762 | let result = _this.hasSelectAct(newtime, _this.config.begintime, _this.config.endtime) 763 | if (result) { 764 | if (!_this.hasClass(item, 'sele_act')) _this.addClass(item, 'sele_act'); 765 | }else{ 766 | _this.removeClass(item, 'sele_act'); 767 | } 768 | }) 769 | if (that) _this.addClass(that, 'act_block'); 770 | } else if (that){ 771 | _this.forEach(objs, (index, item) => { 772 | _this.removeClass(item, 'active'); 773 | }) 774 | _this.addClass(that, 'active'); 775 | } 776 | } 777 | 778 | compareTimes(type,preT,nextT){ 779 | let preTimes, nextTimes, modelText; 780 | if (type === 'getDay'){ 781 | preTimes = `${preT.year}/${preT.month}/${preT.today} ${preT.hour}:${preT.minute}:${preT.second}`; 782 | preTimes = new Date(preTimes).getTime(); 783 | nextTimes = `${nextT.year}/${nextT.month}/${nextT.today} ${nextT.hour}:${nextT.minute}:${nextT.second}`; 784 | nextTimes = new Date(nextTimes).getTime(); 785 | modelText = this.config.lang === 'cn' ? '结束时间必须大于开始时间!' : 'The end time must be greater than the start time.'; 786 | } else if (type === 'getYear'){ 787 | preTimes = preT.year; 788 | nextTimes = nextT.year; 789 | modelText = this.config.lang === 'cn' ? '结束年份必须大于开始年份!' : 'The end year must be greater than the beginning year.'; 790 | } else if (type === 'getMonth'){ 791 | preTimes = parseInt(preT.month); 792 | nextTimes = parseInt(nextT.month); 793 | modelText = this.config.lang === 'cn' ? '结束月份必须大于开始月份!' : 'The end month must be greater than the beginning month.'; 794 | } else if (type === 'selectTime'){ 795 | preTimes = `2018/01/01 ${preT.hour}:${preT.minute}:${preT.second}`; 796 | preTimes = new Date(preTimes).getTime(); 797 | nextTimes = `2018/01/01 ${nextT.hour}:${nextT.minute}:${nextT.second}`; 798 | nextTimes = new Date(nextTimes).getTime(); 799 | modelText = this.config.lang === 'cn' ? '结束时间必须大于开始时间!' : 'The end time must be greater than the start time.'; 800 | } 801 | 802 | let result = false; 803 | let isShowTime = this.config.showtime || this.obj.$noDoubleObj.config.showtime; 804 | if ( 805 | (this.obj.isDoubleOne && nextTimes <= preTimes && !isShowTime) || 806 | (this.obj.isDoubleOne && nextTimes < preTimes && isShowTime) 807 | ) result = true; 808 | if ( 809 | (!this.obj.isDoubleOne && nextTimes >= preTimes && !isShowTime) || 810 | (!this.obj.isDoubleOne && nextTimes > preTimes && isShowTime) 811 | ) result = true; 812 | let timer = null; 813 | if (result) { 814 | clearTimeout(timer); 815 | const modelObj = this.$obj[query]('.zane-model-miss') 816 | modelObj.style.display = 'block' 817 | this.$obj[query]('.zane-model-content').innerHTML = modelText; 818 | timer = setTimeout(() => { modelObj.style.display = 'none' }, 1000) 819 | } 820 | return result; 821 | } 822 | 823 | // 获得年html 824 | getYearHtml(year,isreset,clickType){ 825 | year = year || new Date().getFullYear(); 826 | year = parseInt(year) 827 | // double 处理 828 | if(this.config.isDouble&&this.obj.isDoubleOne&&clickType=='next'){ 829 | year = year + this.obj.totalYear; 830 | }else if(this.config.isDouble&&!this.obj.isDoubleOne&&clickType=='pre'){ 831 | year = year - this.obj.totalYear; 832 | } 833 | let yearDatas = { 834 | nowyear:year, 835 | datalist:[] 836 | }; 837 | for (var i = 0; i < this.obj.totalYear; i++) { 838 | let getyear = year-Math.floor(this.obj.totalYear/2)+i 839 | if(i === 0) yearDatas.firstYear = getyear; 840 | if(i === this.obj.totalYear-1) yearDatas.lastYear = getyear; 841 | yearDatas.datalist.push({ 842 | class:'', 843 | year:getyear 844 | }) 845 | } 846 | 847 | this.obj.fulldatas.year = this.config.isDouble?yearDatas.nowyear:'' 848 | this.judgeCalendarRender('year',yearDatas,isreset,clickType); 849 | } 850 | 851 | // 上一年 852 | perYear(year){ 853 | year = year-this.obj.totalYear 854 | let isreset = this.config.isDouble&&this.obj.isDoubleOne?true:false 855 | this.getYearHtml(year,isreset,'pre') 856 | } 857 | 858 | // 下一年 859 | nextYear(year){ 860 | year = year+this.obj.totalYear 861 | let isreset = this.config.isDouble&&!this.obj.isDoubleOne?true:false 862 | this.getYearHtml(year,isreset,'next') 863 | } 864 | 865 | // 获得年 866 | getYear(){ 867 | let _this = this; 868 | let objs = this.$obj 869 | [query]('.main-check-year')[quall]('td'); 870 | this.on(objs,'click',function(e){ 871 | let year = e.target.nodeName === 'TD' ? e.target.children[0].getAttribute('data-year') : e.target.getAttribute('data-year') 872 | let fulldate = `${year}/${_this.obj.fulldatas.month}/${_this.obj.fulldatas.today}` 873 | if(_this.config.type === 'year'){ 874 | if (_this.config.isDouble){ 875 | const result = _this.compareTimes('getYear', _this.obj.$noDoubleObj.obj.fulldatas, { year: year }); 876 | if (result) return; 877 | } 878 | _this.config.isDouble ? _this.obj.fulldatas.year = year : _this.getYearMonthAndDay(year,false) 879 | }else{ 880 | //double 处理 881 | let clickType = _this.obj.isDoubleOne?'pre':''; 882 | _this.setBeginEndTime(fulldate); 883 | _this.judgeCalendarRender('day',fulldate,true,clickType) 884 | } 885 | 886 | //选择具体日期添加样式 887 | _this.forEach(objs, (index, item) => { 888 | _this.removeClass(item, 'active'); 889 | }) 890 | _this.addClass(this, 'active'); 891 | }) 892 | } 893 | 894 | // 获得month html 895 | getMonthHtml(month){ 896 | let date = new Date(); 897 | let year = this.obj.fulldatas.year || date.getFullYear(); 898 | month = month || date.getMonth()+1 899 | let monthDatas = { 900 | nowmonth:month, 901 | year:year, 902 | datalist:this.obj.lang.month 903 | }; 904 | this.obj.fulldatas.month = this.config.isDouble?monthDatas.nowmonth:'' 905 | this.judgeCalendarRender('month',monthDatas); 906 | } 907 | 908 | // 上一月 909 | perMonthYear(year,month){ 910 | let monthDatas = { 911 | nowmonth:month, 912 | year:year-1, 913 | datalist:this.obj.lang.month 914 | }; 915 | this.judgeCalendarRender('month',monthDatas); 916 | } 917 | 918 | // 下一月 919 | nextMonthYear(year,month){ 920 | let monthDatas = { 921 | nowmonth:month, 922 | year:year+1, 923 | datalist:this.obj.lang.month 924 | }; 925 | this.judgeCalendarRender('month',monthDatas); 926 | } 927 | 928 | // 获得月 929 | getMonth(){ 930 | let _this = this; 931 | let objs = this.$obj 932 | [query]('.main-check-month')[quall]('td'); 933 | this.on(objs,'click',function(e){ 934 | let obj = e.target.nodeName === 'TD' ? e.target.children[0] : e.target; 935 | let year = obj.getAttribute('data-year') 936 | let month = obj.getAttribute('data-month') 937 | let fulldate = `${year}/${month}/${_this.obj.fulldatas.today}` 938 | if(_this.config.type === 'month'){ 939 | if (_this.config.isDouble) { 940 | const result = _this.compareTimes('getMonth', _this.obj.$noDoubleObj.obj.fulldatas, { month: month }); 941 | if (result) return; 942 | } 943 | _this.config.isDouble ? _this.obj.fulldatas.month = month : _this.getYearMonthAndDay(month,false) 944 | }else{ 945 | let clickType = _this.obj.isDoubleOne ? 'pre' : ''; 946 | _this.setBeginEndTime(fulldate); 947 | _this.judgeCalendarRender('day', fulldate, true, clickType) 948 | } 949 | //选择具体日期添加样式 950 | _this.forEach(objs, (index, item) => { 951 | _this.removeClass(item, 'active'); 952 | }) 953 | _this.addClass(this, 'active'); 954 | }) 955 | } 956 | 957 | // 获得时间HTML 958 | getTimeHtml(time){ 959 | //double 处理 960 | if(this.config.isDouble&&!this.obj.isDoubleOne&&this.config.type=='day') this.obj.$noDoubleObj.getTimeHtml(); 961 | let nowday = new Date().Format('yyyy/MM/dd') 962 | let date = time?new Date(nowday+' '+time):new Date(); 963 | let hour = date.getHours(); 964 | let minute = date.getMinutes(); 965 | let second = date.getSeconds(); 966 | hour = (hour+'').length<2? '0'+hour : hour; 967 | minute = (minute+'').length<2? '0'+minute:minute; 968 | second = (second+'').length<2? '0'+second:second; 969 | 970 | this.obj.fulldatas.hour = this.obj.fulldatas.hour||hour 971 | this.obj.fulldatas.minute = this.obj.fulldatas.minute||minute 972 | this.obj.fulldatas.second = this.obj.fulldatas.second||second 973 | 974 | let datas ={ 975 | hour:this.obj.fulldatas.hour, 976 | minute:this.obj.fulldatas.minute, 977 | second:this.obj.fulldatas.second, 978 | hours:[], 979 | minutes:[], 980 | seconds:[] 981 | } 982 | for (var i = 0; i < 24; i++) { 983 | if(i<10){ 984 | datas.hours.push('0'+i) 985 | }else{ 986 | datas.hours.push(i+'') 987 | } 988 | } 989 | for (var i = 0; i < 60; i++) { 990 | if(i<10){ 991 | datas.minutes.push('0'+i) 992 | datas.seconds.push('0'+i) 993 | }else{ 994 | datas.minutes.push(i+'') 995 | datas.seconds.push(i+'') 996 | } 997 | } 998 | this.judgeCalendarRender('time',datas); 999 | } 1000 | 1001 | // 选择时间 1002 | selectTime(){ 1003 | let _this = this 1004 | let hourObjs = this.$obj[query]('ul.hour')[quall]('li') 1005 | let minuteObjs = this.$obj[query]('ul.minute')[quall]('li') 1006 | 1007 | let secondObjs = null; 1008 | if(this.config.showsecond){ 1009 | secondObjs = this.$obj[query]('ul.second')[quall]('li') 1010 | } 1011 | 1012 | this.on(hourObjs,'click',function(e){ 1013 | _this.forEach(hourObjs,(index,item)=>{ 1014 | _this.removeClass(item,'active'); 1015 | }) 1016 | _this.addClass(this,'active'); 1017 | _this.obj.fulldatas.hour = this.getAttribute('data-time'); 1018 | }) 1019 | 1020 | this.on(minuteObjs,'click',function(e){ 1021 | if(_this.config.isDouble && !_this.config.showsecond){ 1022 | const result = _this.compareTimes( 1023 | 'selectTime', 1024 | _this.obj.$noDoubleObj.obj.fulldatas, 1025 | Object.assign({}, _this.obj.fulldatas, { minute: this.getAttribute('data-time') }) 1026 | ); 1027 | if (result) return; 1028 | } 1029 | _this.forEach(minuteObjs,(index,item)=>{ 1030 | _this.removeClass(item,'active'); 1031 | }) 1032 | _this.addClass(this,'active'); 1033 | _this.obj.fulldatas.minute = this.getAttribute('data-time'); 1034 | }) 1035 | 1036 | if(this.config.showsecond){ 1037 | this.on(secondObjs,'click',function(e){ 1038 | if (_this.config.isDouble) { 1039 | const result = _this.compareTimes( 1040 | 'selectTime', 1041 | _this.obj.$noDoubleObj.obj.fulldatas, 1042 | Object.assign({}, _this.obj.fulldatas, { second: this.getAttribute('data-time') }) 1043 | ); 1044 | if (result) return; 1045 | } 1046 | _this.forEach(secondObjs,(index,item)=>{ 1047 | _this.removeClass(item,'active'); 1048 | }) 1049 | _this.addClass(this,'active'); 1050 | _this.obj.fulldatas.second = this.getAttribute('data-time'); 1051 | }) 1052 | } 1053 | } 1054 | 1055 | // 返回日期 1056 | backDateHtml(){ 1057 | //double 处理 1058 | if(this.config.isDouble&&!this.obj.isDoubleOne&&this.config.type=='day') this.obj.$noDoubleObj.backDateHtml(); 1059 | this.obj.handleType = 'date'; 1060 | let bottomHTML = this.bottomCheckTimeHTML(); 1061 | this.renderCommonHtml('day','','',bottomHTML,false); 1062 | } 1063 | 1064 | // 今天 1065 | changeToToday(){ 1066 | let json = this.getTimeDates(); 1067 | let value = null; 1068 | let isFormat = true; 1069 | if(this.config.showtime){ 1070 | value = `${json.year}/${json.month}/${json.today} ${json.hour}:${json.minute}:${json.second}` 1071 | }else if(this.config.type == 'time'){ 1072 | isFormat = false; 1073 | value = `${json.hour}:${json.minute}:${json.second}` 1074 | }else{ 1075 | value = `${json.year}/${json.month}/${json.today}` 1076 | } 1077 | this.getYearMonthAndDay(value,isFormat) 1078 | } 1079 | 1080 | // 清空 1081 | cleanInputVal(){ 1082 | let value = "" 1083 | this.getYearMonthAndDay(value,false) 1084 | } 1085 | 1086 | // 确定 1087 | makeSureSelectTime(){ 1088 | let value = null; 1089 | let isFormat = true; 1090 | if(this.config.showtime){ 1091 | value = `${this.obj.fulldatas.year}/${this.obj.fulldatas.month}/${this.obj.fulldatas.today} ${this.obj.fulldatas.hour}:${this.obj.fulldatas.minute}` 1092 | if(this.config.showsecond){ 1093 | value = `${value}:${this.obj.fulldatas.second}` 1094 | } 1095 | }else if(this.config.type == 'time'&&!this.config.isDouble){ 1096 | isFormat = false; 1097 | value = `${this.obj.fulldatas.hour}:${this.obj.fulldatas.minute}` 1098 | if(this.config.showsecond){ 1099 | value = `${value}:${this.obj.fulldatas.second}` 1100 | } 1101 | }else{ 1102 | //doubule 处理 1103 | if(this.config.isDouble){ 1104 | let noDoubleData = this.obj.$noDoubleObj.obj.fulldatas; 1105 | let noDoubleStr,haveDoubleStr 1106 | 1107 | switch(this.config.type){ 1108 | case 'day': 1109 | if(this.obj.$noDoubleObj.config.showtime){ 1110 | noDoubleStr = `${noDoubleData.year}/${noDoubleData.month}/${noDoubleData.today} ${noDoubleData.hour}:${noDoubleData.minute}` 1111 | haveDoubleStr = `${this.obj.fulldatas.year}/${this.obj.fulldatas.month}/${this.obj.fulldatas.today} ${this.obj.fulldatas.hour}:${this.obj.fulldatas.minute}` 1112 | if(this.obj.$noDoubleObj.config.showsecond){ 1113 | noDoubleStr = `${noDoubleStr}:${noDoubleData.second}` 1114 | haveDoubleStr = `${haveDoubleStr}:${this.obj.fulldatas.second}` 1115 | } 1116 | }else{ 1117 | noDoubleStr = `${noDoubleData.year}/${noDoubleData.month}/${noDoubleData.today}` 1118 | haveDoubleStr = `${this.obj.fulldatas.year}/${this.obj.fulldatas.month}/${this.obj.fulldatas.today}` 1119 | }; 1120 | break; 1121 | case 'year': 1122 | isFormat = false 1123 | noDoubleStr = `${noDoubleData.year}` 1124 | haveDoubleStr = `${this.obj.fulldatas.year}` 1125 | break; 1126 | case 'month': 1127 | isFormat = false 1128 | noDoubleStr = `${noDoubleData.month}` 1129 | haveDoubleStr = `${this.obj.fulldatas.month}` 1130 | break; 1131 | case 'time' : 1132 | isFormat = false 1133 | noDoubleStr = `${noDoubleData.hour}:${noDoubleData.minute}` 1134 | haveDoubleStr = `${this.obj.fulldatas.hour}:${this.obj.fulldatas.minute}` 1135 | if(this.config.showsecond){ 1136 | noDoubleStr = `${noDoubleStr}:${noDoubleData.second}` 1137 | haveDoubleStr = `${haveDoubleStr}:${this.obj.fulldatas.second}` 1138 | } 1139 | break; 1140 | }; 1141 | value = noDoubleStr +'|'+ haveDoubleStr 1142 | }else{ 1143 | value = `${this.obj.fulldatas.year}/${this.obj.fulldatas.month}/${this.obj.fulldatas.today}` 1144 | } 1145 | } 1146 | this.getYearMonthAndDay(value,isFormat) 1147 | } 1148 | 1149 | // 确定年月日的值并在input里面显示,时间选择器隐藏 1150 | getYearMonthAndDay(datatime,isFormat=true){ 1151 | let formatTime = null; 1152 | let begintime=''; 1153 | let endtime=''; 1154 | 1155 | //doubule 处理 1156 | if(datatime&&datatime.indexOf('|') != -1){ 1157 | let arr = datatime.split('|'); 1158 | let val1 = null 1159 | let val2 = null 1160 | if(isFormat){ 1161 | val1 = begintime = new Date(arr[0]).Format(this.config.format) 1162 | val2 = endtime = new Date(arr[1]).Format(this.config.format) 1163 | }else{ 1164 | val1 = begintime = arr[0] 1165 | val2 = endtime = arr[1] 1166 | } 1167 | formatTime = val1 +' - '+ val2 1168 | }else{ 1169 | formatTime = begintime = isFormat?new Date(datatime).Format(this.config.format):datatime; 1170 | } 1171 | 1172 | if(this.obj.input.nodeName !== 'INPUT'){ 1173 | this.obj.input.textContent = formatTime; 1174 | }else{ 1175 | this.obj.input.value = formatTime; 1176 | } 1177 | 1178 | // 移除事件插件dom元素 1179 | this.removeCalendar(); 1180 | 1181 | this.config.done&&this.config.done(formatTime,begintime,endtime); 1182 | if(this.obj.initVal!=formatTime&&this.config.change)this.config.change(formatTime,begintime,endtime) 1183 | } 1184 | 1185 | // 判断插件渲染类型 day | year | month | time 1186 | judgeCalendarRender(type,any,isreset,clickType){ 1187 | let mainHTML,topHTML,bottomHTML 1188 | switch(type){ 1189 | case 'day': 1190 | this.obj.handleType = 'day'; 1191 | let json = this.getTimeDates(any,clickType); 1192 | this.obj.fulldatas = json; 1193 | // double 处理 1194 | this.compareSize(isreset,clickType); 1195 | topHTML = this.topCheckDayHTML(json) 1196 | mainHTML = this.mainCheckDayHTML(json); 1197 | this.renderCommonHtml('day',topHTML,mainHTML); 1198 | // 计算表格高度 1199 | this.countHeight('.main-check-day',7); 1200 | this.getDay(); 1201 | setTimeout(()=>{ 1202 | this.addOrRemoveClass(); 1203 | },200) 1204 | 1205 | break; 1206 | case 'year': 1207 | this.obj.handleType = 'year'; 1208 | // double 处理 1209 | this.compareSize(isreset,clickType); 1210 | mainHTML = this.mainCheckYearHTML(any); 1211 | topHTML = this.topCheckYearHTML(any); 1212 | this.renderCommonHtml('year',topHTML,mainHTML); 1213 | // 计算表格高度 1214 | this.countHeight('.main-check-year',6); 1215 | this.getYear(); 1216 | break; 1217 | case 'month': 1218 | this.obj.handleType = 'month'; 1219 | mainHTML = this.mainCheckMonthHTML(any); 1220 | topHTML = this.topCheckMonthHTML(any); 1221 | this.renderCommonHtml('month',topHTML,mainHTML); 1222 | // 计算表格高度 1223 | this.countHeight('.main-check-month',4); 1224 | this.getMonth(); 1225 | break; 1226 | case 'time': 1227 | this.obj.handleType = 'time'; 1228 | mainHTML = this.mainCheckTimeHTML(any); 1229 | topHTML = this.topCheckTimeHTML(); 1230 | bottomHTML = this.bottomCheckTimeHTML(); 1231 | this.renderCommonHtml('time',topHTML,mainHTML,bottomHTML); 1232 | this.$obj[query]('.select-time').style.height = this.config.height-115 +'px' 1233 | let hourScrollTop = this.$obj[query]('ul.hour')[query]('li.active').offsetTop 1234 | let minuteScrollTop = this.$obj[query]('ul.minute')[query]('li.active').offsetTop 1235 | 1236 | this.$obj[query]('ul.hour').scrollTop = hourScrollTop-150 1237 | this.$obj[query]('ul.minute').scrollTop = minuteScrollTop-150 1238 | 1239 | if(this.config.showsecond){ 1240 | let secondScrollTop = this.$obj[query]('ul.second')[query]('li.active').offsetTop 1241 | this.$obj[query]('ul.second').scrollTop = secondScrollTop-150 1242 | } 1243 | 1244 | this.selectTime(); 1245 | break; 1246 | } 1247 | } 1248 | 1249 | renderCommonHtml(type,topHTML,mainHTML,bottomHTML,isrender=true){ 1250 | if(type == 'time'|| !isrender) this.$obj[query](`.btn-select-time`).innerHTML = bottomHTML; 1251 | if(isrender){ 1252 | this.$obj[query](`.top-check-${type}`).innerHTML = topHTML; 1253 | this.$obj[query](`.main-check-${type}`).innerHTML = mainHTML; 1254 | }; 1255 | this.showOrHide(this.$obj[quall]('.common-top'),'hide') 1256 | this.showOrHide(this.$obj[quall]('.common-main'),'hide') 1257 | this.$obj[query](`.main-check-${type}`).style.display = 'block' 1258 | this.$obj[query](`.top-check-${type}`).style.display = 'block' 1259 | } 1260 | 1261 | // 比较double数据之间的大小,并从新赋值 1262 | compareSize(isreset,clickType){ 1263 | if(!isreset) return; 1264 | // double 处理 1265 | let prev = this.obj.fulldatas 1266 | let next = this.obj.$noDoubleObj 1267 | if(this.config.isDouble&&prev&&next){ 1268 | next = next.obj.fulldatas 1269 | if(this.obj.isDoubleOne){ 1270 | this.getDoubleTime({ 1271 | prev:next, 1272 | next:prev, 1273 | clickType:clickType 1274 | }) 1275 | }else{ 1276 | this.getDoubleTime({ 1277 | prev:prev, 1278 | next:next, 1279 | clickType:clickType 1280 | }) 1281 | } 1282 | }; 1283 | } 1284 | 1285 | getDoubleTime(json){ 1286 | let nextfullstr,prefullstr,perTime,nextTime 1287 | switch(this.config.type){ 1288 | case 'day': 1289 | prefullstr = `${json.prev.year}/${json.prev.month}/${json.prev.today}` 1290 | nextfullstr = `${json.next.year}/${json.next.month}/${json.next.today}` 1291 | perTime = new Date(prefullstr).getTime() 1292 | nextTime = new Date(nextfullstr).getTime() 1293 | if(perTime >= nextTime-86400000) { 1294 | const times = this.obj.isDoubleOne ? nextTime - 86400000 : perTime + 86400000; 1295 | this.obj.$noDoubleObj.setBeginEndTime(times) 1296 | this.obj.$noDoubleObj.judgeCalendarRender('day', times,false,json.clickType) 1297 | } 1298 | break; 1299 | case 'year': 1300 | perTime = `${json.prev.year}` 1301 | nextTime = `${json.next.year}` 1302 | if(perTime >= nextTime) { 1303 | this.obj.$noDoubleObj.getYearHtml(nextTime,false,json.clickType) 1304 | } 1305 | break; 1306 | } 1307 | 1308 | } 1309 | 1310 | //插件自身点击阻止冒泡 1311 | calendarClick(){ 1312 | this.on(this.obj.calendar,'click',(e)=>{ 1313 | e.preventDefault(); 1314 | e.stopPropagation(); 1315 | }) 1316 | } 1317 | 1318 | // 继承方法 1319 | extend(obj1,obj2){ 1320 | return Object.assign(obj1,obj2); 1321 | } 1322 | 1323 | hasClass(obj, cls) { 1324 | return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')); 1325 | } 1326 | 1327 | addClass(obj, cls) { 1328 | if (!this.hasClass(obj, cls)) obj.className += " " + cls; 1329 | } 1330 | 1331 | removeClass(obj, cls) { 1332 | if (this.hasClass(obj, cls)) { 1333 | var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)'); 1334 | obj.className = obj.className.replace(reg, ' '); 1335 | } 1336 | } 1337 | 1338 | //对象遍历 1339 | forEach(obj, fn){ 1340 | let key 1341 | if(typeof fn !== 'function') return this; 1342 | obj = obj || []; 1343 | if(Object.prototype.toString.call(obj) == '[object Object]'){ 1344 | for(key in obj){ 1345 | if(fn.call(obj[key], key, obj[key])) break; 1346 | } 1347 | } else if(Object.prototype.toString.call(obj) =='[object NodeList]' || Object.prototype.toString.call(obj) =='[object Array]'){ 1348 | for(key = 0; key < obj.length; key++){ 1349 | if(fn.call(obj[key], key, obj[key])) break; 1350 | } 1351 | }else{ 1352 | fn.call(obj,0,obj); 1353 | } 1354 | return this; 1355 | }; 1356 | 1357 | //事件绑定 1358 | on(obj,eventName, fn){ 1359 | return this.forEach(obj,(index, item)=>{ 1360 | item.attachEvent ? item.attachEvent('on' + eventName, function(e){ 1361 | e.target = e.srcElement; 1362 | fn.call(item, e); 1363 | }) : item.addEventListener(eventName, fn, false); 1364 | }); 1365 | }; 1366 | 1367 | //中英文月份枚举 1368 | weekToEn(val){ 1369 | let num = typeof val == 'string'?parseInt(val):val; 1370 | return this.obj.en.month[num-1]; 1371 | } 1372 | 1373 | // 1374 | showOrHide(obj,type){ 1375 | for (var i = 0,len=obj.length; i < len; i++) { 1376 | if(type==='hide'){ 1377 | obj[i].style.display = 'none' 1378 | }else{ 1379 | obj[i].style.display = 'block' 1380 | } 1381 | } 1382 | } 1383 | 1384 | // 计算table tr高度 1385 | countHeight(elename,length){ 1386 | let mainH = this.$obj[query]('.zane-date-main').offsetHeight; 1387 | let trObj = this.$obj[query](elename)[quall]('tr') 1388 | let itemH = Math.floor(mainH/length) 1389 | this.forEach(trObj,(index,item)=>{ 1390 | item.style.height = itemH + 'px'; 1391 | }) 1392 | } 1393 | 1394 | // document点击隐藏插件 1395 | documentClick(){ 1396 | this.on(doc,'click',(e)=>{ 1397 | this.removeCalendar() 1398 | }) 1399 | } 1400 | 1401 | // 移除事件选择器 1402 | removeCalendar(calobj){ 1403 | let zaneCalendarObjs = doc[quall]('.zane-calendar') 1404 | if(zaneCalendarObjs&&zaneCalendarObjs.length){ 1405 | zaneCalendarObjs.forEach(item=>{ 1406 | let parent = item.parentElement; 1407 | let parents = parent.parentElement; 1408 | let removed = parents.removeChild(parent); 1409 | }) 1410 | } 1411 | } 1412 | 1413 | }; 1414 | 1415 | // 实例化日期插件 双选择器DOUBLE区分 1416 | let zaneDate = function(option){ 1417 | let begintime,endtime,format; 1418 | format = option.format?option.format.replace(/-/g,'/'):'yyyy/MM/dd' 1419 | if(option.type){ 1420 | if(option.type.indexOf('time')!=-1) format = 'HH:mm:ss'; 1421 | if(option.type.indexOf('year')!=-1) format = 'yyyy'; 1422 | if(option.type.indexOf('month')!=-1) format = 'MM'; 1423 | } 1424 | option.type = option.type || 'day' 1425 | 1426 | //处理begintime 1427 | if(option.begintime&&typeof(option.begintime)==='string'){ 1428 | begintime = option.begintime.replace(/-/g,'/') 1429 | if(option.type&&option.type.indexOf('time')==-1 || !option.type){ 1430 | begintime = new Date(begintime).Format(format) 1431 | } 1432 | }else if(option.begintime&&typeof(option.begintime)==='number'){ 1433 | begintime = new Date(option.begintime).Format(format) 1434 | } 1435 | 1436 | // 处理begintime 1437 | if(option.endtime&&typeof(option.endtime)==='string'){ 1438 | endtime = option.endtime.replace(/-/g,'/') 1439 | if(option.type&&option.type.indexOf('time')==-1 || !option.type){ 1440 | endtime = new Date(endtime).Format(format) 1441 | } 1442 | }else if(option.endtime&&typeof(option.endtime)==='number'){ 1443 | endtime = new Date(option.endtime).Format(format) 1444 | } 1445 | 1446 | if(option.type.indexOf('double') != -1){ 1447 | option.type = option.type.replace(/double/,''); 1448 | createCalendar({ 1449 | showclean:false, 1450 | shownow:false, 1451 | showsubmit:false, 1452 | isDouble:true, 1453 | value:begintime, 1454 | format:format, 1455 | doublevalue:begintime&&endtime?begintime+' - '+endtime:'' 1456 | }); 1457 | createCalendar({ 1458 | shownow:false, 1459 | showtime:false, 1460 | isDouble:true, 1461 | double:'DOUBLE', 1462 | value:endtime, 1463 | format:format, 1464 | doublevalue:begintime&&endtime?begintime+' - '+endtime:'' 1465 | }); 1466 | }else{ 1467 | createCalendar({ 1468 | format:format, 1469 | value:begintime, 1470 | }); 1471 | } 1472 | // 新建日期插件 1473 | function createCalendar(json={}){ 1474 | let calendarName = option.elem.substring(1); 1475 | calendarName = calendarName.replace(/[_-]/g,'').toUpperCase(); 1476 | option.calendarName = json&&json.double ?calendarName+json.double:calendarName; 1477 | if(option.width){ 1478 | option.width = option.width<220?220:option.width 1479 | option.width = option.width>500?500:option.width 1480 | } 1481 | if(option.height){ 1482 | option.height = option.height<240?240:option.height 1483 | option.height = option.height>350?350:option.height 1484 | } 1485 | 1486 | let cloneOption = Object.assign(extendDeep(option),json); 1487 | window[option.calendarName] = new calendar(cloneOption) 1488 | } 1489 | //深度复制 1490 | function extendDeep(parent, child) { 1491 | child = child || {}; 1492 | for(var i in parent) { 1493 | if(parent.hasOwnProperty(i)) { 1494 | if(typeof parent[i] === "object") { 1495 | child[i] = (Object.prototype.toString.call(parent[i]) === "[object Array]") ? [] : {}; 1496 | extendDeep(parent[i], child[i]); 1497 | } else { 1498 | child[i] = parent[i]; 1499 | } 1500 | } 1501 | } 1502 | return child; 1503 | }; 1504 | 1505 | } 1506 | if ( !noGlobal ) window.zaneDate = zaneDate; 1507 | 1508 | return zaneDate; 1509 | 1510 | }); 1511 | --------------------------------------------------------------------------------