Skip to content

fix: calendar year select bug and change evnet bug #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ typings/
.idea
.DS_Store
dist
lib
es
# lib
# es
site-dist
yarn.lock
package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion components/calendar/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default {
const suffix = locale.year === '年' ? '年' : ''

const options = []
for (let index = start; index < end; index++) {
for (let index = start; index <= end; index++) {
options.push(<Option key={`${index}`}>{index + suffix}</Option>)
}
return (
Expand Down
2 changes: 1 addition & 1 deletion components/calendar/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ customize the progress dot by setting a scoped slot
| --- | --- | --- |
| panelChange | Callback for when panel changes | function(date: moment, mode: string) | - |
| select | Callback for when a date is selected | function(date: moment) | - |
| change | Callback for when value change | function(date: moment) | - |
| onChange | Callback for when value change | function(date: moment) | - |
4 changes: 2 additions & 2 deletions components/calendar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default {
}
if (way === 'select') {
this.$emit('select', value)
this.$emit('change', value)
this.$emit('onChange', value)
} else if (way === 'changePanel') {
this.onPanelChange(value, this.sMode)
}
Expand All @@ -147,7 +147,7 @@ export default {
onPanelChange (value, mode) {
this.$emit('panelChange', value, mode)
if (value !== this.sValue) {
this.$emit('change', value)
this.$emit('onChange', value)
}
},

Expand Down
2 changes: 1 addition & 1 deletion components/calendar/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
| --- | --- | --- |
| panelChange | 日期面板变化回调 | function(date: moment, mode: string) | 无 |
| select | 点击选择日期回调 | function(date: moment) | 无 |
| change | 日期变化时的回调, 面板变化有可能导致日期变化| function(date: moment) | 无 |
| onChange | 日期变化时的回调, 面板变化有可能导致日期变化| function(date: moment) | 无 |
27 changes: 27 additions & 0 deletions es/_util/BaseMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray';
import _extends from 'babel-runtime/helpers/extends';
export default {
methods: {
setState: function setState(state, callback) {
_extends(this.$data, typeof state === 'function' ? state(this.$data) : state);
this.$nextTick(function () {
callback && callback();
});
},
__emit: function __emit() {
// 直接调用listeners,底层组件不需要vueTool记录events
var args = [].slice.call(arguments, 0);
var filterEvent = [];
var eventName = args[0];
if (args.length && this.$listeners[eventName]) {
if (filterEvent.includes(eventName)) {
this.$emit.apply(this, [eventName].concat(_toConsumableArray(args.slice(1))));
} else {
var _$listeners;

(_$listeners = this.$listeners)[eventName].apply(_$listeners, _toConsumableArray(args.slice(1)));
}
}
}
}
};
98 changes: 98 additions & 0 deletions es/_util/ContainerRender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

import Vue from 'vue';
import PropTypes from './vue-types';

export default {
props: {
autoMount: PropTypes.bool.def(true),
autoDestroy: PropTypes.bool.def(true),
visible: PropTypes.bool,
forceRender: PropTypes.bool.def(false),
parent: PropTypes.any,
getComponent: PropTypes.func.isRequired,
getContainer: PropTypes.func.isRequired,
children: PropTypes.func.isRequired
},

mounted: function mounted() {
if (this.autoMount) {
this.renderComponent();
}
},
updated: function updated() {
if (this.autoMount) {
this.renderComponent();
}
},
beforeDestroy: function beforeDestroy() {
if (this.autoDestroy) {
this.removeContainer();
}
},

methods: {
removeContainer: function removeContainer() {
if (this.container) {
this._component && this._component.$destroy();
this.container.parentNode.removeChild(this.container);
this.container = null;
}
},
renderComponent: function renderComponent() {
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var ready = arguments[1];
var visible = this.visible,
getComponent = this.getComponent,
forceRender = this.forceRender,
getContainer = this.getContainer,
parent = this.parent;

var self = this;
if (visible || parent.$refs._component || forceRender) {
var el = this.componentEl;
if (!this.container) {
this.container = getContainer();
el = document.createElement('div');
this.componentEl = el;
this.container.appendChild(el);
}

if (!this._component) {
this._component = new Vue({
data: {
comProps: props
},
parent: self.parent,
el: el,
mounted: function mounted() {
this.$nextTick(function () {
if (ready) {
ready.call(self);
}
});
},
updated: function updated() {
this.$nextTick(function () {
if (ready) {
ready.call(self);
}
});
},
render: function render() {
return getComponent(this.comProps);
}
});
} else {
this._component.comProps = props;
}
}
}
},

render: function render() {
return this.children({
renderComponent: this.renderComponent,
removeContainer: this.removeContainer
});
}
};
5 changes: 5 additions & 0 deletions es/_util/Dom/addEventListener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import addDOMEventListener from 'add-dom-event-listener';

export default function addEventListenerWrap(target, eventType, cb) {
return addDOMEventListener(target, eventType, cb);
}
65 changes: 65 additions & 0 deletions es/_util/Dom/class-util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* @flow */

/**
* Add class with compatibility for SVG since classList is not supported on
* SVG elements in IE
*/
export function addClass(el, cls) {
/* istanbul ignore if */
if (!cls || !(cls = cls.trim())) {
return;
}

/* istanbul ignore else */
if (el.classList) {
if (cls.indexOf(' ') > -1) {
cls.split(/\s+/).forEach(function (c) {
return el.classList.add(c);
});
} else {
el.classList.add(cls);
}
} else {
var cur = ' ' + (el.getAttribute('class') || '') + ' ';
if (cur.indexOf(' ' + cls + ' ') < 0) {
el.setAttribute('class', (cur + cls).trim());
}
}
}

/**
* Remove class with compatibility for SVG since classList is not supported on
* SVG elements in IE
*/
export function removeClass(el, cls) {
/* istanbul ignore if */
if (!cls || !(cls = cls.trim())) {
return;
}

/* istanbul ignore else */
if (el.classList) {
if (cls.indexOf(' ') > -1) {
cls.split(/\s+/).forEach(function (c) {
return el.classList.remove(c);
});
} else {
el.classList.remove(cls);
}
if (!el.classList.length) {
el.removeAttribute('class');
}
} else {
var cur = ' ' + (el.getAttribute('class') || '') + ' ';
var tar = ' ' + cls + ' ';
while (cur.indexOf(tar) >= 0) {
cur = cur.replace(tar, ' ');
}
cur = cur.trim();
if (cur) {
el.setAttribute('class', cur);
} else {
el.removeAttribute('class');
}
}
}
11 changes: 11 additions & 0 deletions es/_util/Dom/contains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function contains(root, n) {
var node = n;
while (node) {
if (node === root) {
return true;
}
node = node.parentNode;
}

return false;
}
Loading