Merge branch '2.0' of https://github.com/iview/iview into feature-card

This commit is contained in:
huixisheng 2017-03-02 17:45:47 +08:00
commit 49dd45f46f
28 changed files with 190 additions and 69 deletions

View file

@ -21,4 +21,6 @@ class 改为了 className
### Collapse ### Collapse
废弃 activeKey使用 v-modelkey 是保留的,更名为 name 废弃 activeKey使用 v-modelkey 是保留的,更名为 name
### Carousel ### Carousel
废弃 activeIndex使用 v-modelv-for="n in slides.length",Vue2的数字循环是从1开始的 废弃 activeIndex使用 v-modelv-for="n in slides.length",Vue2的数字循环是从1开始的
### Tree
废弃 data改为 value使用 v-modelkey 更名为 name

View file

@ -48,7 +48,7 @@
- [ ] Tooltip - [ ] Tooltip
- [ ] Poptip - [ ] Poptip
- [x] Carousel - [x] Carousel
- [ ] Tree - [x] Tree
- [ ] Menu - [ ] Menu
- [ ] Tabs - [ ] Tabs
- [ ] Dropdown - [ ] Dropdown

View file

@ -23,6 +23,7 @@
const prefixCls = 'ivu-alert'; const prefixCls = 'ivu-alert';
export default { export default {
name: 'Alert',
components: { Icon }, components: { Icon },
props: { props: {
type: { type: {

View file

@ -12,6 +12,7 @@
const prefixCls = 'ivu-badge'; const prefixCls = 'ivu-badge';
export default { export default {
name: 'Badge',
props: { props: {
count: [Number, String], count: [Number, String],
dot: { dot: {

View file

@ -9,7 +9,7 @@
const prefixCls = 'ivu-btn-group'; const prefixCls = 'ivu-btn-group';
export default { export default {
name: 'buttonGroup', name: 'ButtonGroup',
props: { props: {
size: { size: {
validator (value) { validator (value) {

View file

@ -36,6 +36,7 @@
const prefixCls = 'ivu-cascader'; const prefixCls = 'ivu-cascader';
export default { export default {
name: 'Cascader',
components: { iInput, Dropdown, Icon, Caspanel }, components: { iInput, Dropdown, Icon, Caspanel },
directives: { clickoutside }, directives: { clickoutside },
props: { props: {

View file

@ -7,7 +7,7 @@
const prefixCls = 'ivu-checkbox-group'; const prefixCls = 'ivu-checkbox-group';
export default { export default {
name: 'checkboxGroup', name: 'CheckboxGroup',
props: { props: {
value: { value: {
type: Array, type: Array,

View file

@ -15,6 +15,7 @@
const prefixCls = 'ivu-chart-circle'; const prefixCls = 'ivu-chart-circle';
export default { export default {
name: 'Circle',
props: { props: {
percent: { percent: {
type: Number, type: Number,

View file

@ -7,6 +7,7 @@
const prefixCls = 'ivu-collapse'; const prefixCls = 'ivu-collapse';
export default { export default {
name: 'Collapse',
props: { props: {
accordion: { accordion: {
type: Boolean, type: Boolean,

View file

@ -14,6 +14,7 @@
const prefixCls = 'ivu-collapse'; const prefixCls = 'ivu-collapse';
export default { export default {
name: 'Panel',
components: { Icon }, components: { Icon },
props: { props: {
name: { name: {

View file

@ -7,6 +7,7 @@
const prefixCls = 'ivu-col'; const prefixCls = 'ivu-col';
export default { export default {
name: 'iCol',
props: { props: {
span: [Number, String], span: [Number, String],
order: [Number, String], order: [Number, String],

View file

@ -9,6 +9,7 @@
const prefixCls = 'ivu-row'; const prefixCls = 'ivu-row';
export default { export default {
name: 'Row',
props: { props: {
type: { type: {
validator (value) { validator (value) {

View file

@ -61,6 +61,7 @@
} }
export default { export default {
name: 'InputNumber',
props: { props: {
max: { max: {
type: Number, type: Number,

View file

@ -9,7 +9,7 @@
const prefixCls = 'ivu-radio-group'; const prefixCls = 'ivu-radio-group';
export default { export default {
name: 'radioGroup', name: 'RadioGroup',
props: { props: {
value: { value: {
type: [String, Number], type: [String, Number],

View file

@ -20,6 +20,7 @@
const iconPrefixCls = 'ivu-icon'; const iconPrefixCls = 'ivu-icon';
export default { export default {
name: 'Step',
props: { props: {
status: { status: {
validator (value) { validator (value) {

View file

@ -9,6 +9,7 @@
const prefixCls = 'ivu-steps'; const prefixCls = 'ivu-steps';
export default { export default {
name: 'Steps',
props: { props: {
current: { current: {
type: Number, type: Number,

View file

@ -12,6 +12,7 @@
const prefixCls = 'ivu-switch'; const prefixCls = 'ivu-switch';
export default { export default {
name: 'Switch',
props: { props: {
value: { value: {
type: Boolean, type: Boolean,

View file

@ -12,6 +12,7 @@
const prefixCls = 'ivu-tag'; const prefixCls = 'ivu-tag';
export default { export default {
name: 'Tag',
components: { Icon }, components: { Icon },
props: { props: {
closable: { closable: {

View file

@ -11,6 +11,7 @@
const prefixCls = 'ivu-timeline'; const prefixCls = 'ivu-timeline';
export default { export default {
name: 'TimelineItem',
props: { props: {
color: { color: {
type: String, type: String,

View file

@ -7,6 +7,7 @@
const prefixCls = 'ivu-timeline'; const prefixCls = 'ivu-timeline';
export default { export default {
name: 'Timeline',
props: { props: {
pending: { pending: {
type: Boolean, type: Boolean,

View file

@ -1,27 +1,28 @@
<template> <template>
<ul :class="classes"> <ul :class="classes">
<li v-for="item in data" :class="itemCls(item)"> <li v-for="(item, index) in data" :class="itemCls(item)">
<span :class="arrowCls(item)" @click="setExpand(item.disabled, $index)"> <span :class="arrowCls(item)" @click="setExpand(item.disabled, index)">
<Icon type="arrow-right-b"></Icon> <Icon type="arrow-right-b"></Icon>
</span> </span>
<Checkbox <Checkbox
v-if="showCheckbox" v-if="showCheckbox"
:checked="item.checked && item.childrenCheckedStatus == 2" :value="item.checked && item.childrenCheckedStatus == 2"
:disabled="item.disabled || item.disableCheckbox" :disabled="item.disabled || item.disableCheckbox"
:indeterminate="item.checked && item.childrenCheckedStatus == 1" :indeterminate="item.checked && item.childrenCheckedStatus == 1"
@click.prevent="setCheck(item.disabled||item.disableCheckbox,$index)"></Checkbox> @click.prevent="setCheck(item.disabled||item.disableCheckbox, index)"></Checkbox>
<a :class="titleCls(item)" @click="setSelect(item.disabled, $index)"> <a :class="titleCls(item)" @click="setSelect(item.disabled, index)">
<span :class="[prefixCls + '-title']" v-html="item.title"></span> <span :class="[prefixCls + '-title']" v-html="item.title"></span>
</a> </a>
<tree <transition name="slide-up">
v-if="!item.isLeaf" <Tree
v-show="item.expand" v-if="!item.isLeaf"
:class="expandCls(item)" v-show="item.expand"
:data.sync="item.children" :class="expandCls(item)"
:key="this.key+'.'+$index" :value="item.children"
:multiple="multiple" :name="item.name+'.'+index"
:show-checkbox="showCheckbox" :multiple="multiple"
transition="slide-up"></tree> :show-checkbox="showCheckbox"></Tree>
</transition>
</li> </li>
</ul> </ul>
</template> </template>
@ -29,20 +30,22 @@
import Icon from '../icon/icon.vue'; import Icon from '../icon/icon.vue';
import Checkbox from '../checkbox/checkbox.vue'; import Checkbox from '../checkbox/checkbox.vue';
import { t } from '../../locale'; import { t } from '../../locale';
import emitter from '../../mixins/emitter';
const prefixCls = 'ivu-tree'; const prefixCls = 'ivu-tree';
export default { export default {
name: 'tree', name: 'Tree',
components: { Icon, Checkbox }, components: { Icon, Checkbox },
mixins: [ emitter ],
props: { props: {
data: { value: {
type: Array, type: Array,
default () { default () {
return []; return [];
} }
}, },
key: { name: {
type: String, type: String,
default: '0' default: '0'
}, },
@ -63,12 +66,13 @@
}, },
data () { data () {
return { return {
prefixCls: prefixCls prefixCls: prefixCls,
data: this.value
}; };
}, },
computed: { computed: {
classes () { classes () {
if (this.key === '0') { if (this.name === '0') {
return this.prefixCls; return this.prefixCls;
} else { } else {
return `${this.prefixCls}-child-tree`; return `${this.prefixCls}-child-tree`;
@ -76,8 +80,11 @@
} }
}, },
watch: { watch: {
data(){ value (val) {
if (this.key === '0') { this.data = val;
},
data () {
if (this.name === '0') {
this.setKey(); this.setKey();
this.preHandle(); this.preHandle();
} }
@ -118,55 +125,82 @@
}, },
setKey () { setKey () {
for (let i = 0; i < this.data.length; i++) { for (let i = 0; i < this.data.length; i++) {
this.data[i].key = `${this.key}.${i}`; this.data[i].name = `${this.name}.${i}`;
} }
}, },
preHandle () { preHandle () {
for (let [i,item] of this.data.entries()) { for (let [i, item] of this.data.entries()) {
if (!item.children || !item.children.length) { if (!item.children || !item.children.length) {
this.$set(`data[${i}].isLeaf`, true); // this.$set(`data[${i}].isLeaf`, true);
this.$set(`data[${i}].childrenCheckedStatus`, 2); // this.$set(`data[${i}].childrenCheckedStatus`, 2);
this.$set(this.data[i], 'isLeaf', true);
this.$set(this.data[i], 'childrenCheckedStatus', 2);
continue; continue;
} }
if (item.checked && !item.childrenCheckedStatus) { if (item.checked && !item.childrenCheckedStatus) {
this.$set(`data[${i}].childrenCheckedStatus`, 2); // this.$set(`data[${i}].childrenCheckedStatus`, 2);
this.$broadcast('parentChecked', true, `${this.key}.${i}`); this.$set(this.data[i], 'childrenCheckedStatus', 2);
// this.$broadcast('parentChecked', true, `${this.name}.${i}`);
this.broadcast('Tree', 'parentChecked', {
status: true,
name: `${this.name}.${i}`
});
} else { } else {
let status = this.getChildrenCheckedStatus(item.children); let status = this.getChildrenCheckedStatus(item.children);
this.$set(`data[${i}].childrenCheckedStatus`, status); // this.$set(`data[${i}].childrenCheckedStatus`, status);
if (status !== 0) this.$set(`data[${i}].checked`, true); this.$set(this.data[i], 'childrenCheckedStatus', status);
// if (status !== 0) this.$set(`data[${i}].checked`, true);
if (status !== 0) this.$set(this.data[i], 'checked', true);
} }
} }
}, },
setExpand (disabled, index) { setExpand (disabled, index) {
if (!disabled) { if (!disabled) {
this.$set(`data[${index}].expand`, !this.data[index].expand); // this.$set(`data[${index}].expand`, !this.data[index].expand);
this.$set(this.data[index], 'expand', !this.data[index].expand);
} }
}, },
setSelect (disabled, index) { setSelect (disabled, index) {
if (!disabled) { if (!disabled) {
const selected = !this.data[index].selected; const selected = !this.data[index].selected;
if (this.multiple || !selected) { if (this.multiple || !selected) {
this.$set(`data[${index}].selected`, selected); // this.$set(`data[${index}].selected`, selected);
this.$set(this.data[index], 'selected', selected);
} else { } else {
for (let i = 0; i < this.data.length; i++) { for (let i = 0; i < this.data.length; i++) {
if (i == index) { if (i == index) {
this.$set(`data[${i}].selected`, true); // this.$set(`data[${i}].selected`, true);
this.$set(this.data[i], 'selected', true);
} else { } else {
this.$set(`data[${i}].selected`, false); // this.$set(`data[${i}].selected`, false);
this.$set(this.data[i], 'selected', false);
} }
} }
} }
this.$dispatch('nodeSelected', this, selected); // this.$dispatch('nodeSelected', this, selected);
this.dispatch('Tree', 'nodeSelected', {
ori: this,
selected: selected
})
} }
}, },
setCheck (disabled, index) { setCheck (disabled, index) {
if (disabled) return; if (disabled) return;
const checked = !this.data[index].checked; const checked = !this.data[index].checked;
this.$set(`data[${index}].checked`, checked); // this.$set(`data[${index}].checked`, checked);
this.$set(`data[${index}].childrenCheckedStatus`, checked ? 2 : 0); this.$set(this.data[index], 'checked', checked);
this.$dispatch('childChecked', this, this.key); // this.$set(`data[${index}].childrenCheckedStatus`, checked ? 2 : 0);
this.$broadcast('parentChecked', checked, `${this.key}.${index}`); this.$set(this.data[index], 'childrenCheckedStatus', checked ? 2 : 0);
// this.$dispatch('childChecked', this, this.name);
this.dispatch('Tree', 'childChecked', {
ori: this,
name: this.name
});
// this.$broadcast('parentChecked', checked, `${this.name}.${index}`);
this.broadcast('Tree', 'parentChecked', {
status: checked,
name: `${this.name}.${index}`
});
}, },
getNodes (data, opt) { getNodes (data, opt) {
data = data || this.data; data = data || this.data;
@ -215,55 +249,83 @@
} }
} }
}, },
ready(){ mounted () {
this.setKey(); this.setKey();
this.preHandle(); this.preHandle();
this.$on('nodeSelected', (ori, selected) => { // this.$on('nodeSelected', (ori, selected) => {
if (this.key !== '0') return true; this.$on('nodeSelected', (params) => {
const ori = params.ori;
const selected = params.selected;
if (this.name !== '0') return true;
if (!this.multiple && selected) { if (!this.multiple && selected) {
if (this !== ori) { if (this !== ori) {
for (let i = 0; i < this.data.length; i++) { for (let i = 0; i < this.data.length; i++) {
this.$set(`data[${i}].selected`, false); // this.$set(`data[${i}].selected`, false);
this.$set(this.data[i], 'selected', false);
} }
} }
this.$broadcast('cancelSelected', ori); // this.$broadcast('cancelSelected', ori);
this.broadcast('Tree', 'cancelSelected', ori);
} }
this.$nextTick(() => { this.$nextTick(() => {
this.$emit('on-select-change', this.getSelectedNodes()); this.$emit('on-select-change', this.getSelectedNodes());
}); });
}); });
this.$on('cancelSelected', ori => { this.$on('cancelSelected', ori => {
this.$broadcast('cancelSelected', ori); // this.$broadcast('cancelSelected', ori);
this.broadcast('Tree', 'cancelSelected', ori);
if (this !== ori) { if (this !== ori) {
for (let i = 0; i < this.data.length; i++) { for (let i = 0; i < this.data.length; i++) {
this.$set(`data[${i}].selected`, false); // this.$set(`data[${i}].selected`, false);
this.$set(this.data[i], 'selected', false);
} }
} }
}); });
this.$on('parentChecked', (status, key) => { // this.$on('parentChecked', (status, name) => {
if (this.key == key || this.key.startsWith(key + '.')) { this.$on('parentChecked', (params) => {
const status = params.status;
const name = params.name;
if (this.name == name || this.name.startsWith(name + '.')) {
for (let i = 0; i < this.data.length; i++) { for (let i = 0; i < this.data.length; i++) {
this.$set(`data[${i}].checked`, status); // this.$set(`data[${i}].checked`, status);
this.$set(`data[${i}].childrenCheckedStatus`, status ? 2 : 0); this.$set(this.data[i], 'checked', status);
// this.$set(`data[${i}].childrenCheckedStatus`, status ? 2 : 0);
this.$set(this.data[i], 'childrenCheckedStatus', status ? 2 : 0);
} }
this.$broadcast('parentChecked', status, key); // this.$broadcast('parentChecked', status, name);
this.broadcast('Tree', 'parentChecked', {
status: status,
name: name
});
} }
}); });
this.$on('childChecked', (ori, key) => { // this.$on('childChecked', (ori, name) => {
if (this.key === '0') { this.$on('childChecked', (params) => {
const ori = params.ori;
const name = params.name;
if (this.name === '0') {
this.$nextTick(() => { this.$nextTick(() => {
this.$emit('on-check-change', this.getCheckedNodes()); this.$emit('on-check-change', this.getCheckedNodes());
}); });
} }
if (this === ori) return; if (this === ori) return;
for (let [i,item] of this.data.entries()) { for (let [i,item] of this.data.entries()) {
if (this.key + '.' + i == key) { if (this.name + '.' + i == name) {
let temp = this.getChildrenCheckedStatus(item.children); let temp = this.getChildrenCheckedStatus(item.children);
if (temp != item.childrenCheckedStatus) { if (temp != item.childrenCheckedStatus) {
this.$set(`data[${i}].checked`, !!temp); // this.$set(`data[${i}].checked`, !!temp);
this.$set(`data[${i}].childrenCheckedStatus`, temp); this.$set(this.data[i], 'checked', !!temp);
if (this.key !== '0') this.$dispatch('childChecked', this, this.key); // this.$set(`data[${i}].childrenCheckedStatus`, temp);
this.$set(this.data[i], 'childrenCheckedStatus', temp);
// if (this.name !== '0') this.$dispatch('childChecked', this, this.name);
if (this.name !== '0') this.dispatch('Tree', 'childChecked', {
ori: this,
name: this.name
});
} }
} }
} }

View file

@ -28,6 +28,7 @@
const prefixCls = 'ivu-upload'; const prefixCls = 'ivu-upload';
export default { export default {
name: 'UploadList',
components: { Icon, Progress }, components: { Icon, Progress },
props: { props: {
files: { files: {

View file

@ -31,6 +31,7 @@
const prefixCls = 'ivu-upload'; const prefixCls = 'ivu-upload';
export default { export default {
name: 'Upload',
components: { UploadList }, components: { UploadList },
props: { props: {
action: { action: {

View file

@ -40,7 +40,7 @@ import Timeline from './components/timeline';
// import TimePicker from './components/time-picker'; // import TimePicker from './components/time-picker';
// import Tooltip from './components/tooltip'; // import Tooltip from './components/tooltip';
// import Transfer from './components/transfer'; // import Transfer from './components/transfer';
// import Tree from './components/tree'; import Tree from './components/tree';
import Upload from './components/upload'; import Upload from './components/upload';
import { Row, Col } from './components/grid'; import { Row, Col } from './components/grid';
// import { Select, Option, OptionGroup } from './components/select'; // import { Select, Option, OptionGroup } from './components/select';
@ -108,7 +108,7 @@ const iview = {
// TimePicker, // TimePicker,
// Tooltip, // Tooltip,
// Transfer, // Transfer,
// Tree, Tree,
Upload Upload
}; };

33
src/mixins/emitter.js Executable file
View file

@ -0,0 +1,33 @@
function broadcast(componentName, eventName, params) {
this.$children.forEach(child => {
const name = child.$options.name;
if (name === componentName) {
child.$emit.apply(child, [eventName].concat(params));
} else {
broadcast.apply(child, [componentName, eventName].concat([params]));
}
});
}
export default {
methods: {
dispatch(componentName, eventName, params) {
let parent = this.$parent || this.$root;
let name = parent.$options.name;
while (parent && (!name || name !== componentName)) {
parent = parent.$parent;
if (parent) {
name = parent.$options.name;
}
}
if (parent) {
parent.$emit.apply(parent, [eventName].concat(params));
}
},
broadcast(componentName, eventName, params) {
broadcast.call(this, componentName, eventName, params);
}
}
};

View file

@ -31,6 +31,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
<li><router-link to="/collapse">Collapse</router-link></li> <li><router-link to="/collapse">Collapse</router-link></li>
<li><router-link to="/carousel">Carousel</router-link></li> <li><router-link to="/carousel">Carousel</router-link></li>
<li><router-link to="/card">Card</router-link></li> <li><router-link to="/card">Card</router-link></li>
<li><router-link to="/tree">Tree</router-link></li>
</ul> </ul>
</nav> </nav>
<router-view></router-view> <router-view></router-view>

View file

@ -88,6 +88,10 @@ const router = new VueRouter({
{ {
path: '/card', path: '/card',
component: require('./routers/card.vue') component: require('./routers/card.vue')
},
{
path: '/tree',
component: require('./routers/tree.vue')
} }
] ]
}); });

View file

@ -1,10 +1,12 @@
<template> <template>
<Tree <div>
:data.sync="treeData" <Tree
:show-checkbox="true" v-model="treeData"
:multiple="true" :show-checkbox="true"
@on-select-change="selectFn" :multiple="true"
@on-check-change="checkFn"></Tree> @on-select-change="selectFn"
@on-check-change="checkFn"></Tree>
</div>
</template> </template>
<script> <script>
export default { export default {