Merge remote-tracking branch 'upstream/2.0' into popper

This commit is contained in:
huanghong 2018-04-10 12:42:32 +08:00
commit 586bf3fc1b
16 changed files with 191 additions and 100 deletions

View file

@ -1,6 +1,11 @@
<template>
<div :class="classes">
<div :class="headClasses" v-if="showHead"><slot name="title"></slot></div>
<div :class="headClasses" v-if="showHead"><slot name="title">
<p v-if="title">
<Icon v-if="icon" :type="icon"></Icon>
{{title}}
</p>
</slot></div>
<div :class="extraClasses" v-if="showExtra"><slot name="extra"></slot></div>
<div :class="bodyClasses" :style="bodyStyles"><slot></slot></div>
</div>
@ -8,10 +13,11 @@
<script>
const prefixCls = 'ivu-card';
const defaultPadding = 16;
import Icon from '../icon/icon.vue';
export default {
name: 'Card',
components: { Icon },
props: {
bordered: {
type: Boolean,
@ -28,6 +34,12 @@
padding: {
type: Number,
default: defaultPadding
},
title: {
type: String,
},
icon: {
type: String,
}
},
data () {
@ -67,7 +79,7 @@
}
},
mounted () {
this.showHead = this.$slots.title !== undefined;
this.showHead = this.title || this.$slots.title !== undefined;
this.showExtra = this.$slots.extra !== undefined;
}
};

View file

@ -3,7 +3,7 @@
</template>
<script>
const prefixCls = 'ivu-dropdown-item';
import { findComponentUpward } from '../../utils/assist';
export default {
name: 'DropdownItem',
props: {
@ -37,7 +37,7 @@
},
methods: {
handleClick () {
const $parent = this.$parent.$parent.$parent;
const $parent = findComponentUpward(this, 'Dropdown');
const hasChildren = this.$parent && this.$parent.$options.name === 'Dropdown';
if (this.disabled) {

View file

@ -92,6 +92,7 @@
this.validateState = val;
}
},
inject: ['form'],
computed: {
classes () {
return [
@ -103,13 +104,13 @@
}
];
},
form() {
let parent = this.$parent;
while (parent.$options.name !== 'iForm') {
parent = parent.$parent;
}
return parent;
},
// form() {
// let parent = this.$parent;
// while (parent.$options.name !== 'iForm') {
// parent = parent.$parent;
// }
// return parent;
// },
fieldValue: {
cache: false,
get() {

View file

@ -40,6 +40,9 @@
default: 'off'
}
},
provide() {
return { form : this };
},
data () {
return {
fields: []

View file

@ -2,7 +2,7 @@
<div :class="wrapClasses">
<template v-if="type !== 'textarea'">
<div :class="[prefixCls + '-group-prepend']" v-if="prepend" v-show="slotReady"><slot name="prepend"></slot></div>
<i class="ivu-icon" :class="['ivu-icon-ios-close', prefixCls + '-icon', prefixCls + '-icon-clear' , prefixCls + '-icon-normal']" v-if="clearable" @click="handleClear"></i>
<i class="ivu-icon" :class="['ivu-icon-ios-close', prefixCls + '-icon', prefixCls + '-icon-clear' , prefixCls + '-icon-normal']" v-if="clearable && currentValue" @click="handleClear"></i>
<i class="ivu-icon" :class="['ivu-icon-' + icon, prefixCls + '-icon', prefixCls + '-icon-normal']" v-else-if="icon" @click="handleIconClick"></i>
<transition name="fade">
<i class="ivu-icon ivu-icon-load-c ivu-load-loop" :class="[prefixCls + '-icon', prefixCls + '-icon-validate']" v-if="!icon"></i>

View file

@ -43,7 +43,8 @@
},
data () {
return {
currentActiveName: this.activeName
currentActiveName: this.activeName,
openedNames: []
};
},
computed: {
@ -76,36 +77,40 @@
this.broadcast('MenuItem', 'on-update-active-name', this.currentActiveName);
},
updateOpenKeys (name) {
const index = this.openNames.indexOf(name);
if (index > -1) {
this.openNames.splice(index, 1);
let names = [...this.openedNames];
const index = names.indexOf(name);
if (index >= 0) {
names.splice(index, 1);
} else {
this.openNames.push(name);
if (this.accordion) {
let currentSubmenu = {};
let currentSubmenu = null;
findComponentsDownward(this, 'Submenu').forEach(item => {
if (item.name === name) currentSubmenu = item;
});
findBrothersComponents(currentSubmenu, 'Submenu').forEach(item => {
let index = this.openNames.indexOf(item.name);
this.openNames.splice(index, index >= 0 ? 1 : 0);
let i = names.indexOf(item.name);
if (i >= 0) names.splice(i, 1);
});
this.openNames.push(name);
names.push(name);
}
}
this.openedNames = names;
this.$emit('on-open-change', this.openedNames);
},
updateOpened () {
const items = findComponentsDownward(this, 'Submenu');
if (items.length) {
items.forEach(item => {
if (this.openNames.indexOf(item.name) > -1) item.opened = true;
if (this.openedNames.indexOf(item.name) > -1) item.opened = true;
else item.opened = false;
});
}
}
},
mounted () {
this.updateActiveName();
this.openedNames = [...this.openNames];
this.updateOpened();
this.$on('on-menu-item-select', (name) => {
this.currentActiveName = name;
@ -113,8 +118,8 @@
});
},
watch: {
openNames () {
this.$emit('on-open-change', this.openNames);
openNames (names) {
this.openedNames = names;
},
activeName (val) {
this.currentActiveName = val;

View file

@ -21,7 +21,8 @@
data () {
return {
popper: null,
width: ''
width: '',
popperStatus: false
};
},
computed: {
@ -37,6 +38,7 @@
if (this.popper) {
this.$nextTick(() => {
this.popper.update();
this.popperStatus = true;
});
} else {
this.$nextTick(() => {
@ -65,10 +67,11 @@
destroy () {
if (this.popper) {
setTimeout(() => {
if (this.popper) {
if (this.popper && !this.popperStatus) {
this.popper.destroy();
this.popper = null;
}
this.popperStatus = false;
}, 300);
}
},

View file

@ -3,6 +3,7 @@
<Input-number
v-if="!range && showInput"
:min="min"
:size="inputSize"
:max="max"
:step="step"
:value="exportValue[0]"
@ -120,6 +121,13 @@
type: Boolean,
default: false
},
inputSize: {
type: String,
default: 'default',
validator (value) {
return oneOf(value, ['small', 'large', 'default']);
}
},
showStops: {
type: Boolean,
default: false
@ -151,7 +159,7 @@
startX: 0,
currentX: 0,
startPos: 0,
oldValue: val,
oldValue: [...val],
valueIndex: {
min: 0,
max: 1,
@ -327,7 +335,7 @@
if (type === 'min') newPos = this.checkLimits([newPos, this.maxPosition])[0];
else newPos = this.checkLimits([this.minPosition, newPos])[1];
const modulus = newPos % this.step;
const modulus = this.handleDecimal(newPos,this.step);
const value = this.currentValue;
value[index] = newPos - modulus;
this.currentValue = [...value];
@ -339,7 +347,20 @@
}
}
},
handleDecimal(pos,step){
if(step<1){
let sl = step.toString(),
multiple = 1,
m;
try {
m = sl.split('.')[1].length;
} catch (e){
m = 0;
}
multiple = Math.pow(10,m);
return (pos * multiple) % (step * multiple) / multiple;
}else return pos % step;
},
emitChange(){
const value = this.range ? this.exportValue : this.exportValue[0];
this.$emit('on-change', value);

View file

@ -17,11 +17,12 @@
<span v-else :class="titleClasses" @click="handleSelect">{{ data.title }}</span>
<Tree-node
v-if="data.expand"
v-for="(item, i) in data.children"
v-for="(item, i) in children"
:key="i"
:data="item"
:multiple="multiple"
:show-checkbox="showCheckbox">
:show-checkbox="showCheckbox"
:children-key="childrenKey">
</Tree-node>
</li>
</ul>
@ -52,6 +53,10 @@
type: Boolean,
default: false
},
childrenKey: {
type: String,
default: 'children'
},
showCheckbox: {
type: Boolean,
default: false
@ -93,7 +98,7 @@
];
},
showArrow () {
return (this.data.children && this.data.children.length) || ('loading' in this.data && !this.data.loading);
return (this.data[this.childrenKey] && this.data[this.childrenKey].length) || ('loading' in this.data && !this.data.loading);
},
showLoading () {
return 'loading' in this.data && this.data.loading;
@ -118,6 +123,9 @@
} else {
return [];
}
},
children () {
return this.data[this.childrenKey];
}
},
methods: {
@ -126,14 +134,14 @@
if (item.disabled) return;
// async loading
if (item.children.length === 0) {
if (item[this.childrenKey].length === 0) {
const tree = findComponentUpward(this, 'Tree');
if (tree && tree.loadData) {
this.$set(this.data, 'loading', true);
tree.loadData(item, children => {
this.$set(this.data, 'loading', false);
if (children.length) {
this.$set(this.data, 'children', children);
this.$set(this.data, this.childrenKey, children);
this.$nextTick(() => this.handleExpand());
}
});
@ -141,7 +149,7 @@
}
}
if (item.children && item.children.length) {
if (item[this.childrenKey] && item[this.childrenKey].length) {
this.$set(this.data, 'expand', !this.data.expand);
this.dispatch('Tree', 'toggle-expand', this.data);
}

View file

@ -6,7 +6,8 @@
:data="item"
visible
:multiple="multiple"
:show-checkbox="showCheckbox">
:show-checkbox="showCheckbox"
:children-key="childrenKey">
</Tree-node>
<div :class="[prefixCls + '-empty']" v-if="!stateTree.length">{{ localeEmptyText }}</div>
</div>
@ -40,6 +41,10 @@
emptyText: {
type: String
},
childrenKey: {
type: String,
default: 'children'
},
loadData: {
type: Function
},
@ -76,18 +81,19 @@
methods: {
compileFlatState () { // so we have always a relation parent/children of each node
let keyCounter = 0;
let childrenKey = this.childrenKey;
const flatTree = [];
function flattenChildren(node, parent) {
node.nodeKey = keyCounter++;
flatTree[node.nodeKey] = { node: node, nodeKey: node.nodeKey };
if (typeof parent != 'undefined') {
flatTree[node.nodeKey].parent = parent.nodeKey;
flatTree[parent.nodeKey].children.push(node.nodeKey);
flatTree[parent.nodeKey][childrenKey].push(node.nodeKey);
}
if (node.children) {
flatTree[node.nodeKey].children = [];
node.children.forEach(child => flattenChildren(child, node));
if (node[childrenKey]) {
flatTree[node.nodeKey][childrenKey] = [];
node[childrenKey].forEach(child => flattenChildren(child, node));
}
}
this.stateTree.forEach(rootNode => {
@ -104,11 +110,11 @@
if (node.checked == parent.checked && node.indeterminate == parent.indeterminate) return; // no need to update upwards
if (node.checked == true) {
this.$set(parent, 'checked', parent.children.every(node => node.checked));
this.$set(parent, 'checked', parent[this.childrenKey].every(node => node.checked));
this.$set(parent, 'indeterminate', !parent.checked);
} else {
this.$set(parent, 'checked', false);
this.$set(parent, 'indeterminate', parent.children.some(node => node.checked || node.indeterminate));
this.$set(parent, 'indeterminate', parent[this.childrenKey].some(node => node.checked || node.indeterminate));
}
this.updateTreeUp(parentKey);
},
@ -139,8 +145,8 @@
for (let key in changes) {
this.$set(node, key, changes[key]);
}
if (node.children) {
node.children.forEach(child => {
if (node[this.childrenKey]) {
node[this.childrenKey].forEach(child => {
this.updateTreeDown(child, changes);
});
}