Merge branch '2.0' into 2.0

This commit is contained in:
muei 2017-03-16 11:14:41 +08:00 committed by GitHub
commit c86d77fcef
31 changed files with 804 additions and 726 deletions

View file

@ -1,5 +1,5 @@
<template>
<button :type="htmlType" :class="classes" :disabled="disabled">
<button :type="htmlType" :class="classes" :disabled="disabled" @click="handleClick">
<Icon class="ivu-load-loop" type="load-c" v-if="loading"></Icon>
<Icon :type="icon" v-if="icon && !loading"></Icon>
<span v-if="showSlot" ref="slot"><slot></slot></span>
@ -64,8 +64,13 @@
];
}
},
methods: {
handleClick (event) {
this.$emit('click', event);
}
},
mounted () {
this.showSlot = this.$refs.slot.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== '';
this.showSlot = this.$slots.default !== undefined;
}
};
</script>

View file

@ -25,11 +25,9 @@
}
},
mounted () {
// todo while
this.$parent.slotChange();
},
beforeDestroy () {
// todo while
this.$parent.slotChange();
}
};

View file

@ -4,6 +4,7 @@
</div>
</template>
<script>
import { findComponentsDownward } from '../../utils/assist';
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-checkbox-group';
@ -20,7 +21,8 @@
},
data () {
return {
currentValue: this.value
currentValue: this.value,
childrens: []
};
},
computed: {
@ -34,15 +36,18 @@
methods: {
updateModel (update) {
const value = this.value;
this.childrens = findComponentsDownward(this, 'Checkbox');
this.$children.forEach((child) => {
child.model = value;
if (this.childrens) {
this.childrens.forEach(child => {
child.model = value;
if (update) {
child.currentValue = value.indexOf(child.label) >= 0;
child.group = true;
}
});
if (update) {
child.currentValue = value.indexOf(child.label) >= 0;
child.group = true;
}
});
}
},
change (data) {
this.currentValue = data;

View file

@ -18,10 +18,11 @@
:checked="currentValue"
@change="change">
</span>
<slot v-if="showSlot"><span ref="slot">{{ label }}</span></slot>
<slot><span v-if="showSlot">{{ label }}</span></slot>
</label>
</template>
<script>
import { findComponentUpward } from '../../utils/assist';
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-checkbox';
@ -51,7 +52,8 @@
model: [],
currentValue: this.value,
group: false,
showSlot: true
showSlot: true,
parent: findComponentUpward(this, 'CheckboxGroup')
};
},
computed: {
@ -83,16 +85,11 @@
}
},
mounted () {
// todo 使 while
if (this.$parent && this.$parent.$options.name === 'CheckboxGroup') this.group = true;
this.parent = findComponentUpward(this, 'CheckboxGroup');
if (this.parent) this.group = true;
if (!this.group) {
this.updateModel();
// if (this.$refs.slot && this.$refs.slot.innerHTML === '') {
// this.showSlot = false;
// }
if (this.$slots.default === undefined) {
this.showSlot = false;
}
this.showSlot = this.$slots.default !== undefined;
}
},
methods: {

View file

@ -48,7 +48,6 @@
},
methods: {
toggle () {
// todo while
this.$parent.toggle({
name: this.name || this.index,
isActive: this.isActive

View file

@ -151,8 +151,8 @@
this.$emit('on-focus', event);
},
handleBlur (event) {
this.$emit('on-blur', event);
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader'])) {
this.$emit('on-blur', envent);
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
this.dispatch('FormItem', 'on-form-blur', this.currentValue);
}
},
@ -171,7 +171,7 @@
this.resizeTextarea();
});
this.currentValue = value;
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader'])) {
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
this.dispatch('FormItem', 'on-form-change', value);
}
},

View file

@ -2,7 +2,7 @@
<ul :class="classes" :style="styles"><slot></slot></ul>
</template>
<script>
import { oneOf } from '../../utils/assist';
import { oneOf, findComponentsDownward } from '../../utils/assist';
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-menu';
@ -84,11 +84,13 @@
}
},
updateOpened () {
this.$children.forEach(item => {
if (item.$options.name === 'Submenu') {
const items = findComponentsDownward(this, 'Submenu');
if (items.length) {
items.forEach(item => {
if (this.openNames.indexOf(item.name) > -1) item.opened = true;
}
});
});
}
}
},
mounted () {

View file

@ -17,7 +17,7 @@
<script>
import Drop from '../select/dropdown.vue';
import Icon from '../icon/icon.vue';
import { getStyle } from '../../utils/assist';
import { getStyle, findComponentUpward } from '../../utils/assist';
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-menu';
@ -41,7 +41,8 @@
prefixCls: prefixCls,
active: false,
opened: false,
dropWidth: parseFloat(getStyle(this.$el, 'width'))
dropWidth: parseFloat(getStyle(this.$el, 'width')),
parent: findComponentUpward(this, 'Menu')
};
},
computed: {
@ -56,12 +57,10 @@
];
},
mode () {
// todo while
return this.$parent.mode;
return this.parent.mode;
},
accordion () {
// todo while
return this.$parent.accordion;
return this.parent.accordion;
},
dropStyle () {
let style = {};
@ -77,8 +76,7 @@
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
// todo while
this.$parent.updateOpenKeys(this.name);
this.parent.updateOpenKeys(this.name);
this.opened = true;
}, 250);
},
@ -88,8 +86,7 @@
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
// todo while
this.$parent.updateOpenKeys(this.name);
this.parent.updateOpenKeys(this.name);
this.opened = false;
}, 150);
},
@ -98,14 +95,12 @@
if (this.mode === 'horizontal') return;
const opened = this.opened;
if (this.accordion) {
// todo while
this.$parent.$children.forEach(item => {
this.parent.$children.forEach(item => {
if (item.$options.name === 'Submenu') item.opened = false;
});
}
this.opened = !opened;
// todo while
this.$parent.updateOpenKeys(this.name);
this.parent.updateOpenKeys(this.name);
}
},
watch: {

View file

@ -198,7 +198,7 @@
let showHead = true;
if (this.$slots.head === undefined && !this.title) {
if (this.$slots.header === undefined && !this.title) {
showHead = false;
}

View file

@ -4,7 +4,7 @@
</div>
</template>
<script>
import { oneOf } from '../../utils/assist';
import { oneOf, findComponentsDownward } from '../../utils/assist';
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-radio-group';
@ -34,7 +34,8 @@
},
data () {
return {
currentValue: this.value
currentValue: this.value,
childrens: []
};
},
computed: {
@ -55,10 +56,14 @@
methods: {
updateValue () {
const value = this.value;
this.$children.forEach((child) => {
child.currentValue = value == child.label;
child.group = true;
});
this.childrens = findComponentsDownward(this, 'Radio');
if (this.childrens) {
this.childrens.forEach(child => {
child.currentValue = value == child.label;
child.group = true;
});
}
},
change (data) {
this.currentValue = data.value;

View file

@ -12,6 +12,7 @@
</label>
</template>
<script>
import { findComponentUpward } from '../../utils/assist';
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-radio';
@ -35,7 +36,8 @@
data () {
return {
currentValue: this.value,
group: false
group: false,
parent: findComponentUpward(this, 'RadioGroup')
};
},
computed: {
@ -66,8 +68,7 @@
}
},
mounted () {
// todo 使 while
if (this.$parent && this.$parent.$options.name === 'RadioGroup') this.group = true;
if (this.parent) this.group = true;
if (!this.group) {
this.updateValue();
}
@ -83,7 +84,7 @@
this.$emit('input', checked);
if (this.group && this.label) {
this.$parent.change({
this.parent.change({
value: this.label,
checked: this.value
});

View file

@ -52,36 +52,32 @@
const template = this.column.render(this.row, this.column, this.index);
const cell = document.createElement('div');
cell.innerHTML = template;
// const _oldParentChildLen = $parent.$children.length;
// const _newParentChildLen = $parent.$children.length;
// if (_oldParentChildLen !== _newParentChildLen) { // if render normal html node, do not tag
// this.uid = $parent.$children[$parent.$children.length - 1]._uid; // tag it, and delete when data or columns update
// }
this.$el.innerHTML = '';
let methods = {};
Object.keys($parent).forEach(key => {
const func = $parent[`${key}`];
const func = $parent[key];
if (typeof(func) === 'function' && func.name === 'boundFn') {
methods[`${key}`] = func;
methods[key] = func;
}
});
const res = Vue.compile(cell.outerHTML);
// todo
const component = new Vue({
render: res.render,
staticRenderFns: res.staticRenderFns,
methods: methods
methods: methods,
data () {
return $parent._data;
}
});
const Cell = component.$mount();
this.$refs.cell.appendChild(Cell.$el);
}
},
destroy () {
const $parent = this.content;
for (let i = 0; i < $parent.$children.length; i++) {
if ($parent.$children[i]._uid === this.uid) {
$parent.$children[i].$destroy();
}
}
},
toggleSelect () {
this.$parent.$parent.toggleSelect(this.index);

View file

@ -173,7 +173,8 @@
bodyHeight: 0,
bodyRealHeight: 0,
scrollBarWidth: getScrollBarSize(),
currentContent: this.content
currentContent: this.content,
cloneData: deepCopy(this.data) // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data
};
},
computed: {
@ -357,16 +358,16 @@
}
}
this.objData[_index]._isHighlight = true;
const oldData = oldIndex < 0 ? null : JSON.parse(JSON.stringify(this.data[oldIndex]));
this.$emit('on-current-change', JSON.parse(JSON.stringify(this.data[_index])), oldData);
const oldData = oldIndex < 0 ? null : JSON.parse(JSON.stringify(this.cloneData[oldIndex]));
this.$emit('on-current-change', JSON.parse(JSON.stringify(this.cloneData[_index])), oldData);
},
clickCurrentRow (_index) {
this.highlightCurrentRow (_index);
this.$emit('on-row-click', JSON.parse(JSON.stringify(this.data[_index])));
this.$emit('on-row-click', JSON.parse(JSON.stringify(this.cloneData[_index])));
},
dblclickCurrentRow (_index) {
this.highlightCurrentRow (_index);
this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.data[_index])));
this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.cloneData[_index])));
},
getSelection () {
let selectionIndexes = [];
@ -663,6 +664,10 @@
this.objData = this.makeObjData();
this.rebuildData = this.makeDataWithSortAndFilter();
this.handleResize();
// here will trigger before clickCurrentRow, so use async
setTimeout(() => {
this.cloneData = deepCopy(this.data);
}, 0);
},
deep: true
},

View file

@ -44,14 +44,5 @@
this.$emit('on-query-clear');
}
}
// todo
// events: {
// 'on-form-blur' () {
// return false;
// },
// 'on-form-change' () {
// return false;
// }
// }
};
</script>

View file

@ -67,8 +67,8 @@
return cloned;
}
const vNodes = this.$slots.default;
const clonedVNodes = vNodes.map(vnode => cloneVNode(vnode));
const vNodes = this.$slots.default === undefined ? [] : this.$slots.default;
const clonedVNodes = this.$slots.default === undefined ? [] : vNodes.map(vnode => cloneVNode(vnode));
return createElement('div', {
'class': this.classes
@ -120,7 +120,7 @@
on: {
'on-checked-keys-change': this.handleRightCheckedKeysChange
}
}, clonedVNodes),
}, clonedVNodes)
]);
},

View file

@ -58,6 +58,14 @@
.@{input-prefix-cls}-group{
.input-group-error;
}
.@{transfer-prefix-cls} {
.@{input-prefix-cls} {
.input;
&-icon{
color: @subsidiary-color;
}
}
}
}
.@{form-item-prefix-cls}-validating{
.@{input-prefix-cls}{

View file

@ -185,9 +185,9 @@ function findComponentUpward (content, componentName, componentNames) {
}
export {findComponentUpward};
// Find components downward
// Find component downward
function findComponentDownward (content, componentName) {
let childrens = content.$children;
const childrens = content.$children;
let children = null;
if (childrens.length) {
@ -212,4 +212,24 @@ function findComponentDownward (content, componentName) {
}
return children;
}
export {findComponentDownward};
export {findComponentDownward};
// Find components downward
function findComponentsDownward (content, componentName, components = []) {
const childrens = content.$children;
if (childrens.length) {
childrens.forEach(child => {
const name = child.$options.name;
const childs = child.$children;
if (name === componentName) components.push(child);
if (childs.length) {
const findChilds = findComponentsDownward(child, componentName, components);
if (findChilds) components.concat(findChilds);
}
});
}
return components;
}
export {findComponentsDownward};