diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..08e4982 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 2d571c5..1c3b18c --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ node_modules/ dist/ *.sublime-project *.sublime-workspace -package-lock.json \ No newline at end of file +package-lock.json +.DS_Store +**/.DS_Store \ No newline at end of file diff --git a/Readme.md b/Readme.md old mode 100644 new mode 100755 diff --git a/build.dev.js b/build.dev.js index 744163d..4017223 100755 --- a/build.dev.js +++ b/build.dev.js @@ -1,15 +1,22 @@ #! /usr/bin/env node +const log = console.log const fs = require('iofs') const path = require('path') const babel = require('babel-core') const scss = require('node-sass') const chokidar = require('chokidar') -const log = console.log +const postcss = require('postcss') +const autoprefixer = require('autoprefixer') const chalk = require('chalk') const sourceDir = path.resolve(__dirname, 'src') const buildDir = path.resolve(__dirname, 'dist') +const prefixer = postcss().use( + autoprefixer({ + browsers: ['ie > 9', 'iOS > 8', 'Android >= 4.4', 'ff > 38', 'Chrome > 38'] + }) +) const jsOpt = { presets: ['es2015'], plugins: ['transform-es2015-modules-amd'] @@ -42,7 +49,9 @@ const compileCss = (entry, output) => { setTimeout(() => { try { const { css } = scss.renderSync({ ...cssOpt, file: entry }) - fs.echo(css, output) + prefixer.process(css, { from: '', to: '' }).then(result => { + fs.echo(result.css, output) + }) } catch (err) { log(err) } diff --git a/build.prod.js b/build.prod.js index c8319ee..8f79a3a 100755 --- a/build.prod.js +++ b/build.prod.js @@ -1,14 +1,21 @@ #! /usr/bin/env node +const log = console.log const fs = require('iofs') const path = require('path') const babel = require('babel-core') const scss = require('node-sass') -const log = console.log +const postcss = require('postcss') +const autoprefixer = require('autoprefixer') const chalk = require('chalk') const sourceDir = path.resolve(__dirname, 'src') const buildDir = path.resolve(__dirname, 'dist') +const prefixer = postcss().use( + autoprefixer({ + browsers: ['ie > 9', 'iOS > 8', 'Android >= 4.4', 'ff > 38', 'Chrome > 38'] + }) +) const jsOpt = { presets: ['es2015', 'minify'], plugins: ['transform-es2015-modules-amd'] @@ -39,12 +46,14 @@ const compileJs = (entry, output) => { const compileCss = (entry, output) => { let t1 = Date.now() const { css } = scss.renderSync({ ...cssOpt, file: entry }) - log( - '编译scss: %s, 耗时 %s ms', - chalk.green(entry), - chalk.yellow(Date.now() - t1) - ) - fs.echo(css, output) + prefixer.process(css, { from: '', to: '' }).then(result => { + log( + '编译scss: %s, 耗时 %s ms', + chalk.green(entry), + chalk.yellow(Date.now() - t1) + ) + fs.echo(result.css, output) + }) } const compileHtm = (entry, output) => { diff --git a/index.js b/index.js old mode 100644 new mode 100755 diff --git a/package-lock.json b/package-lock.json old mode 100644 new mode 100755 index e9a6606..2b5f5fc --- a/package-lock.json +++ b/package-lock.json @@ -111,6 +111,20 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", "dev": true }, + "autoprefixer": { + "version": "7.2.5", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-7.2.5.tgz", + "integrity": "sha512-XqHfo8Ht0VU+T5P+eWEVoXza456KJ4l62BPewu3vpNf3LP9s2+zYXkXBznzYby4XeECXgG3N4i+hGvOhXErZmA==", + "dev": true, + "requires": { + "browserslist": "2.11.3", + "caniuse-lite": "1.0.30000792", + "normalize-range": "0.1.2", + "num2fraction": "1.2.2", + "postcss": "6.0.16", + "postcss-value-parser": "3.3.0" + } + }, "aws-sign2": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz", @@ -971,6 +985,16 @@ "repeat-element": "1.1.2" } }, + "browserslist": { + "version": "2.11.3", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-2.11.3.tgz", + "integrity": "sha512-yWu5cXT7Av6mVwzWc8lMsJMHWn4xyjSuGYi4IozbVTLUOEYPSagUB8kiMDUHA1fS3zjr8nkxkn9jdvug4BBRmA==", + "dev": true, + "requires": { + "caniuse-lite": "1.0.30000792", + "electron-to-chromium": "1.3.31" + } + }, "builtin-modules": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", @@ -993,6 +1017,12 @@ "map-obj": "1.0.1" } }, + "caniuse-lite": { + "version": "1.0.30000792", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000792.tgz", + "integrity": "sha1-0M6pgfgRjzlhRxr7tDyaHlu/AzI=", + "dev": true + }, "caseless": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.11.0.tgz", @@ -1215,6 +1245,12 @@ "jsbn": "0.1.1" } }, + "electron-to-chromium": { + "version": "1.3.31", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.31.tgz", + "integrity": "sha512-XE4CLbswkZgZFn34cKFy1xaX+F5LHxeDLjY1+rsK9asDzknhbrd9g/n/01/acbU25KTsUSiLKwvlLyA+6XLUOA==", + "dev": true + }, "error-ex": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.1.tgz", @@ -3060,6 +3096,12 @@ "remove-trailing-separator": "1.1.0" } }, + "normalize-range": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz", + "integrity": "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI=", + "dev": true + }, "npmlog": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", @@ -3072,6 +3114,12 @@ "set-blocking": "2.0.0" } }, + "num2fraction": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz", + "integrity": "sha1-b2gragJ6Tp3fpFZM0lidHU5mnt4=", + "dev": true + }, "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", @@ -3208,6 +3256,40 @@ "pinkie": "2.0.4" } }, + "postcss": { + "version": "6.0.16", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.16.tgz", + "integrity": "sha512-m758RWPmSjFH/2MyyG3UOW1fgYbR9rtdzz5UNJnlm7OLtu4B2h9C6gi+bE4qFKghsBRFfZT8NzoQBs6JhLotoA==", + "dev": true, + "requires": { + "chalk": "2.3.0", + "source-map": "0.6.1", + "supports-color": "5.1.0" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "supports-color": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.1.0.tgz", + "integrity": "sha512-Ry0AwkoKjDpVKK4sV4h6o3UJmNRbjYm2uXhwfj3J56lMVdvnUNqzQVRztOOMGQ++w1K/TjNDFvpJk0F/LoeBCQ==", + "dev": true, + "requires": { + "has-flag": "2.0.0" + } + } + } + }, + "postcss-value-parser": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.0.tgz", + "integrity": "sha1-h/OPnxj3dKSrTIojL1xc6IcqnRU=", + "dev": true + }, "preserve": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz", diff --git a/package.json b/package.json old mode 100644 new mode 100755 index 3b04c37..8aaf582 --- a/package.json +++ b/package.json @@ -11,16 +11,21 @@ "type": "git", "url": "git+https://github.com/yutent/doui.git" }, - "keywords": ["doui", "yua"], + "keywords": [ + "doui", + "yua" + ], "author": "yutent", "license": "MIT", "devDependencies": { + "autoprefixer": "^7.2.5", "babel-core": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-preset-minify": "^0.2.0", "chalk": "^2.3.0", "chokidar": "^1.7.0", "iofs": "^1.0.3", - "node-sass": "^4.7.2" + "node-sass": "^4.7.2", + "postcss": "^6.0.16" } } diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..b2c13ec Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/css/basic-elem.scss b/src/css/basic-elem.scss old mode 100644 new mode 100755 diff --git a/src/css/reset.scss b/src/css/reset.scss old mode 100644 new mode 100755 diff --git a/src/css/var.scss b/src/css/var.scss old mode 100644 new mode 100755 index a0df148..93efe1d --- a/src/css/var.scss +++ b/src/css/var.scss @@ -7,6 +7,6 @@ $co: #ff9800 #ffa726 #f57c00; $cp: #e7e8eb #ecf0f1 #bdc3c7; $cgr: #546e7a #607d8b #37474f; -@mixin ts($c: all, $t: .1s, $m: ease-in-out){ - transition:$c $t $m; +@mixin ts($c: all, $t: .2s, $m: ease-in-out){ + transition:$c $t $m; } \ No newline at end of file diff --git a/src/font/ui-font.eot b/src/font/ui-font.eot index b295f75..02b3321 100644 Binary files a/src/font/ui-font.eot and b/src/font/ui-font.eot differ diff --git a/src/font/ui-font.js b/src/font/ui-font.js index 39ad8c5..2bb0387 100644 --- a/src/font/ui-font.js +++ b/src/font/ui-font.js @@ -1 +1 @@ -(function(window){var svgSprite='';var script=function(){var scripts=document.getElementsByTagName("script");return scripts[scripts.length-1]}();var shouldInjectCss=script.getAttribute("data-injectcss");var ready=function(fn){if(document.addEventListener){if(~["complete","loaded","interactive"].indexOf(document.readyState)){setTimeout(fn,0)}else{var loadFn=function(){document.removeEventListener("DOMContentLoaded",loadFn,false);fn()};document.addEventListener("DOMContentLoaded",loadFn,false)}}else if(document.attachEvent){IEContentLoaded(window,fn)}function IEContentLoaded(w,fn){var d=w.document,done=false,init=function(){if(!done){done=true;fn()}};var polling=function(){try{d.documentElement.doScroll("left")}catch(e){setTimeout(polling,50);return}init()};polling();d.onreadystatechange=function(){if(d.readyState=="complete"){d.onreadystatechange=null;init()}}}};var before=function(el,target){target.parentNode.insertBefore(el,target)};var prepend=function(el,target){if(target.firstChild){before(el,target.firstChild)}else{target.appendChild(el)}};function appendSvg(){var div,svg;div=document.createElement("div");div.innerHTML=svgSprite;svgSprite=null;svg=div.getElementsByTagName("svg")[0];if(svg){svg.setAttribute("aria-hidden","true");svg.style.position="absolute";svg.style.width=0;svg.style.height=0;svg.style.overflow="hidden";prepend(svg,document.body)}}if(shouldInjectCss&&!window.__iconfont__svg__cssinject__){window.__iconfont__svg__cssinject__=true;try{document.write("")}catch(e){console&&console.log(e)}}ready(appendSvg)})(window) \ No newline at end of file +(function(window){var svgSprite='';var script=function(){var scripts=document.getElementsByTagName("script");return scripts[scripts.length-1]}();var shouldInjectCss=script.getAttribute("data-injectcss");var ready=function(fn){if(document.addEventListener){if(~["complete","loaded","interactive"].indexOf(document.readyState)){setTimeout(fn,0)}else{var loadFn=function(){document.removeEventListener("DOMContentLoaded",loadFn,false);fn()};document.addEventListener("DOMContentLoaded",loadFn,false)}}else if(document.attachEvent){IEContentLoaded(window,fn)}function IEContentLoaded(w,fn){var d=w.document,done=false,init=function(){if(!done){done=true;fn()}};var polling=function(){try{d.documentElement.doScroll("left")}catch(e){setTimeout(polling,50);return}init()};polling();d.onreadystatechange=function(){if(d.readyState=="complete"){d.onreadystatechange=null;init()}}}};var before=function(el,target){target.parentNode.insertBefore(el,target)};var prepend=function(el,target){if(target.firstChild){before(el,target.firstChild)}else{target.appendChild(el)}};function appendSvg(){var div,svg;div=document.createElement("div");div.innerHTML=svgSprite;svgSprite=null;svg=div.getElementsByTagName("svg")[0];if(svg){svg.setAttribute("aria-hidden","true");svg.style.position="absolute";svg.style.width=0;svg.style.height=0;svg.style.overflow="hidden";prepend(svg,document.body)}}if(shouldInjectCss&&!window.__iconfont__svg__cssinject__){window.__iconfont__svg__cssinject__=true;try{document.write("")}catch(e){console&&console.log(e)}}ready(appendSvg)})(window) \ No newline at end of file diff --git a/src/font/ui-font.ttf b/src/font/ui-font.ttf index 49e81a8..b0dcb34 100644 Binary files a/src/font/ui-font.ttf and b/src/font/ui-font.ttf differ diff --git a/src/js/anot-touch.js b/src/js/anot-touch.js old mode 100644 new mode 100755 diff --git a/src/js/anot-touch.shim.js b/src/js/anot-touch.shim.js old mode 100644 new mode 100755 diff --git a/src/js/anot.js b/src/js/anot.js old mode 100644 new mode 100755 diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js old mode 100644 new mode 100755 index 194a5ac..6fac8b9 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -141,7 +141,7 @@ } if (tickObserver) { - var node = document.createTextNode('any') + var node = document.createTextNode('anot') new tickObserver(callback).observe(node, { characterData: true }) // jshint ignore:line var bool = false return function(fn) { @@ -460,7 +460,7 @@ value: function() { var thisYear = this.getFullYear(), that = new Date(thisYear, 0, 1), - firstDay = that.getDay(), + firstDay = that.getDay() || 1, numsOfToday = (this - that) / 86400000 return Math.ceil((numsOfToday + firstDay) / 7) }, @@ -4182,7 +4182,7 @@ if (!this.init) { for (var i in Anot.vmodels) { var v = Anot.vmodels[i] - v.$fire('any-duplex-init', binding) + v.$fire('anot-duplex-init', binding) } var cpipe = binding.pipe || (binding.pipe = pipe) cpipe(null, binding, 'init') @@ -4265,17 +4265,7 @@ if (-val === -number) { return number } - var arr = /strong|medium|weak/.exec( - binding.element.getAttribute('data-duplex-number') - ) || ['medium'] - switch (arr[0]) { - case 'strong': - return 0 - case 'medium': - return val === '' ? '' : 0 - case 'weak': - return val - } + return 0 }, set: fixNull } diff --git a/src/js/avatar/def.jpg b/src/js/avatar/def.jpg old mode 100644 new mode 100755 diff --git a/src/js/avatar/index.js b/src/js/avatar/index.js old mode 100644 new mode 100755 diff --git a/src/js/codemirror/codemirror.js b/src/js/codemirror/codemirror.js old mode 100644 new mode 100755 diff --git a/src/js/codemirror/htmlmixed.js b/src/js/codemirror/htmlmixed.js old mode 100644 new mode 100755 diff --git a/src/js/console/index.js b/src/js/console/index.js old mode 100644 new mode 100755 diff --git a/src/js/console/style.scss b/src/js/console/style.scss old mode 100644 new mode 100755 diff --git a/src/js/count/doui.count.js b/src/js/count/doui.count.js old mode 100644 new mode 100755 diff --git a/src/js/datepicker/Readme.md b/src/js/datepicker/Readme.md old mode 100644 new mode 100755 diff --git a/src/js/datepicker/index.js b/src/js/datepicker/index.js new file mode 100755 index 0000000..7b14fa4 --- /dev/null +++ b/src/js/datepicker/index.js @@ -0,0 +1,365 @@ +/** + * + * @authors yutent (yutent@doui.cc) + * @date 2016-02-14 13:58:39 + * + */ +'use strict' + +import tpl from './main.htm' +import './style.css' + +/**************** 公共函数 *****************/ +//计算日历数组 +function getCalendarTable({ year, month, max, min }, last) { + let nums = getTotalDays(year, month) + let numsFixed = 1 - getFirstDay(year, month) + let isLimitYM = isLimited({ max, min }, { year, month }) + let list = [] + + for (let i = numsFixed; i <= nums; i++) { + let day = { + weeken: !1, + day: i < 1 ? '' : i, + selected: !1, + disabled: !0 + } + if (i > 0) { + let week = getFirstDay(year, month, i) + day.weeken = week === 0 || week === 6 + day.selected = isSelected({ year, month, day: i }, last) + day.disabled = disabledDay({ max, min }, i, isLimitYM) + } + list.push(day) + } + return list +} + +//判断当前年/月是否超出限制 +function isLimited({ max, min }, { year, month }) { + let result = '' + + if ((!max.year && !min.year) || (!max.month && !min.month) || !year) { + return false + } + + if ((min.year && year < min.year) || (max.year && year > max.year)) { + return true + } + + if (month) { + if (year === min.year) { + if (min.month && month < min.month) { + return true + } + + if (month == min.month) { + result += '-' + } + } + + if (year === max.year) { + if (max.month && month > max.month) { + return true + } + + if (month == max.month) { + result += '+' + } + } + } + return result +} + +//判断指定天数是否有效 +function disabledDay({ max, min }, day, limitedYM) { + if (limitedYM === '-') { + return day < min.day + } + + if (limitedYM === '+') { + return max.day && day > max.day + } + + if (limitedYM === '-+') { + return day < min.day || (max.day && day > max.day) + } + + return limitedYM +} + +//判断指定天数是否被选中 +function isSelected({ year, month, day }, last) { + return !(last.year !== year || last.month !== month || last.day !== day) +} + +//修改当前选中日期的样式 +function changeStyle(calendar, day) { + calendar.list.forEach(function(item) { + if (item.day != day) { + item.selected = !1 + } else { + item.selected = !0 + } + }) +} + +//获取今年的年份/月份,返回的是数组 +function getThisYearMonth() { + var oDate = new Date() + return [oDate.getFullYear(), oDate.getMonth() + 1] +} + +//根据年份获取指定月份天数 +function getTotalDays(year, month) { + return new Date(year, month, 0).getDate() +} + +//判断指定年月第一天是星期几 +function getFirstDay(year, month, day) { + return new Date(year, month - 1, day || 1).getDay() +} + +Anot.ui.datepicker = '1.0.0' + +export default Anot.component('datepicker', { + render: function() { + return tpl + }, + construct: function(props, state) { + if (!props.hasOwnProperty('key')) { + return Anot.error('日历组件必须设置key属性') + } + + // 日期格式化, 不显示时间时, 默认会调用过滤器的格式'Y-m-d H:i:s' + if (!props.showTime && !props.format) { + props.format = 'Y-m-d' + } + + //获取初始值 + let defVal = props.value + if (!defVal) { + if (props.minDate) { + defVal = props.minDate + } else if (props.maxDate) { + defVal = props.maxDate + } + } + // 修正默认值, 如果不是Date对象, 则转为Date对象 + if (defVal && !Date.isDate(defVal)) { + defVal += ' GMT+8000' + defVal = new Date(defVal) + } else { + defVal = new Date() + } + + if (props.minDate) { + if (!Date.isDate(props.minDate)) { + props.minDate += ' GMT+8000' + props.minDate = new Date(props.minDate) + } + if (defVal <= props.minDate) { + defVal = props.minDate + } + state.min.year = props.minDate.getFullYear() + state.min.month = props.minDate.getMonth() + 1 + state.min.day = props.minDate.getDate() + } + + if (props.maxDate) { + if (!Date.isDate(props.maxDate)) { + props.maxDate += ' GMT+8000' + props.maxDate = new Date(props.maxDate) + } + if (defVal >= props.maxDate) { + defVal = props.maxDate + } + state.max.year = props.maxDate.getFullYear() + state.max.month = props.maxDate.getMonth() + 1 + state.max.day = props.maxDate.getDate() + } + if (props.value) { + state.last = { + year: defVal.getFullYear(), + month: defVal.getMonth() + 1, + day: defVal.getDate() + } + state.value = defVal.format(props.format) + } + + state.calendar = { + list: [1], + year: defVal.getFullYear(), + month: defVal.getMonth() + 1, + day: defVal.getDate(), + hour: defVal.getHours(), + minute: defVal.getMinutes(), + second: defVal.getSeconds() + } + state.disabled = !!props.disabled + + //移除部分属性 + delete props.minDate + delete props.maxDate + delete props.value + delete props.disabled + }, + componentWillMount: function() { + this.resetCalendarTable() + }, + componentDidMount: function() { + if (typeof this.props.onCreated === 'function') { + this.props.onCreated.call(null, this) + } + document.addEventListener('click', () => { + this.close() + }) + }, + state: { + showCalendar: false, //显示日历对话框 + disabled: false, //是否禁用 + last: { year: 0, month: 0, day: 1 }, + tips: '', + timer: null, + value: '', // 用于显示在输入框里的日期变量 + max: { year: 0, month: 0, day: 1 }, + min: { year: 0, month: 0, day: 1 }, + calendar: { + // list: [1], + // year: '', + // month: '', + // day: '', + // hour: '', + // minute: '', + // second: '' + } + }, + props: { + showTime: false, //对话框上显示时间 + color: 'grey', + format: '', // 日期显示格式 + onCreated: Anot.PropsTypes.isFunction(), + onDateChange: Anot.PropsTypes.isFunction() + }, + skip: ['max', 'min', 'last', 'timer'], + watch: { + tips: function(val) { + clearTimeout(this.timer) + if (!val) { + return + } + this.timer = setTimeout(() => { + this.tips = '' + }, 1500) + }, + 'calendar.hour': function(val) { + if (val > 23) { + val = 23 + } + this.calendar.hour = val + }, + 'calendar.minute': function(val) { + if (val > 59) { + val = 59 + } + this.calendar.minute = val + }, + 'calendar.second': function(val) { + if (val > 59) { + val = 59 + } + this.calendar.second = val + } + }, + methods: { + // 重置日历表格 + resetCalendarTable: function() { + let { max, min, calendar: { year, month }, last } = this + + this.calendar.list.clear() + this.calendar.list.pushArray( + getCalendarTable({ max, min, year, month }, last) + ) + }, + // 数字前面加0 + numberFormat: function(num) { + num += '' + if (num.length > 1) { + return num + } + while (num.length < 2) { + num = '0' + num + } + return num + }, + // 输入框获取焦点时,显示日历 + onFocus: function() { + this.showCalendar = !0 + }, + // 切换上/下 年/月 + turn: function(isYear, step) { + let { calendar: { year, month }, max, min } = this + + if (isYear === 1) { + year += step + } else { + month += step + if (month < 1) { + month = 12 + year-- + } + if (month > 12) { + month = 1 + year++ + } + } + if (isLimited({ max, min }, { year, month }) === true) { + this.tips = '日期超出限制' + return + } + this.calendar.year = year + this.calendar.month = month + this.resetCalendarTable() + }, + pick: function(item) { + if (item.disabled) { + return + } + + this.calendar.day = item.day + changeStyle(this.calendar, item.day) + }, + updateTime: function() { + let { year, month, day, hour, minute, second } = this.calendar + + this.last = { year, month, day } + + if (!this.props.showTime) { + hour = 0 + minute = 0 + second = 0 + } + this.last.pick = new Date(year, month - 1, day, hour, minute, second) + this.value = this.last.pick.format(this.props.format) + }, + now: function() { + let now = new Date() + this.calendar.hour = now.getHours() + this.calendar.minute = now.getMinutes() + this.calendar.second = now.getSeconds() + }, + cancelBubble: function(ev) { + ;(ev.stopPropagation && ev.stopPropagation()) || (ev.cancelBubble = true) + }, + close: function() { + this.showCalendar = false + }, + onConfirm: function() { + this.updateTime() + this.close() + if (typeof this.props.onDateChange === 'function') { + this.props.onDateChange(this.value, this.last.pick) + } + } + } +}) diff --git a/src/js/datepicker/main.htm b/src/js/datepicker/main.htm old mode 100644 new mode 100755 index 7943c02..9c27451 --- a/src/js/datepicker/main.htm +++ b/src/js/datepicker/main.htm @@ -1,50 +1,57 @@ -