support Dropdown

support Dropdown
This commit is contained in:
梁灏 2017-03-03 17:46:09 +08:00
parent 1c803cdfb0
commit b1c118d85e
10 changed files with 91 additions and 48 deletions

View file

@ -28,4 +28,9 @@ class 改为了 className
改名为 iCircle 改名为 iCircle
### Tabs ### Tabs
废弃 activeKey改用 value使用 v-modelkey 更名为 name 废弃 activeKey改用 value使用 v-modelkey 更名为 name
### popper.js 将 prop: visible 移至 data 里 ### popper.js 将 prop: visible 移至 data 里
### Slider
支持 v-model
### Dropdown
DropdownItem key 改为 name, Dropdown 的 visible 要使用 @on-visible-change 捕获,不再 sync
DropdownItem 里this.$parent.$parent 与1.0 有区别

View file

@ -26,7 +26,7 @@
- [x] Switch - [x] Switch
- [ ] Table - [ ] Table
- [ ] Select - [ ] Select
- [ ] Slider - [x] Slider
- [ ] DatePicker - [ ] DatePicker
- [ ] TimePicker - [ ] TimePicker
- [ ] Cascader - [ ] Cascader
@ -51,7 +51,7 @@
- [x] Tree - [x] Tree
- [ ] Menu - [ ] Menu
- [x] Tabs - [x] Tabs
- [ ] Dropdown - [x] Dropdown
- [ ] Page - [ ] Page
- [ ] Breadcrumb - [ ] Breadcrumb
- [x] Steps - [x] Steps

View file

@ -5,8 +5,9 @@
const prefixCls = 'ivu-dropdown-item'; const prefixCls = 'ivu-dropdown-item';
export default { export default {
name: 'DropdownItem',
props: { props: {
key: { name: {
type: [String, Number] type: [String, Number]
}, },
disabled: { disabled: {
@ -36,7 +37,7 @@
}, },
methods: { methods: {
handleClick () { handleClick () {
const $parent = this.$parent.$parent; const $parent = this.$parent.$parent.$parent;
const hasChildren = this.$parent && this.$parent.$options.name === 'Dropdown'; const hasChildren = this.$parent && this.$parent.$options.name === 'Dropdown';
if (this.disabled) { if (this.disabled) {
@ -50,7 +51,7 @@
$parent.$emit('on-hover-click'); $parent.$emit('on-hover-click');
} }
} }
$parent.$emit('on-click', this.key); $parent.$emit('on-click', this.name);
} }
} }
}; };

View file

@ -4,8 +4,10 @@
v-clickoutside="handleClose" v-clickoutside="handleClose"
@mouseenter="handleMouseenter" @mouseenter="handleMouseenter"
@mouseleave="handleMouseleave"> @mouseleave="handleMouseleave">
<div :class="[prefixCls-rel]" v-el:reference @click="handleClick"><slot></slot></div> <div :class="[prefixCls + '-rel']" ref="reference" @click="handleClick"><slot></slot></div>
<Drop v-show="visible" :placement="placement" :transition="transition" v-ref:drop><slot name="list"></slot></Drop> <transition :name="transition">
<Drop v-show="currentVisible" :placement="placement" ref="drop"><slot name="list"></slot></Drop>
</transition>
</div> </div>
</template> </template>
<script> <script>
@ -44,16 +46,30 @@
}, },
data () { data () {
return { return {
prefixCls: prefixCls prefixCls: prefixCls,
currentVisible: this.visible
}; };
}, },
watch: {
visible (val) {
this.currentVisible = val;
},
currentVisible (val) {
if (val) {
this.$refs.drop.update();
} else {
this.$refs.drop.destroy();
}
this.$emit('on-visible-change', val);
}
},
methods: { methods: {
handleClick () { handleClick () {
if (this.trigger === 'custom') return false; if (this.trigger === 'custom') return false;
if (this.trigger !== 'click') { if (this.trigger !== 'click') {
return false; return false;
} }
this.visible = !this.visible; this.currentVisible = !this.currentVisible;
}, },
handleMouseenter () { handleMouseenter () {
if (this.trigger === 'custom') return false; if (this.trigger === 'custom') return false;
@ -62,7 +78,7 @@
} }
clearTimeout(this.timeout); clearTimeout(this.timeout);
this.timeout = setTimeout(() => { this.timeout = setTimeout(() => {
this.visible = true; this.currentVisible = true;
}, 250); }, 250);
}, },
handleMouseleave () { handleMouseleave () {
@ -72,7 +88,7 @@
} }
clearTimeout(this.timeout); clearTimeout(this.timeout);
this.timeout = setTimeout(() => { this.timeout = setTimeout(() => {
this.visible = false; this.currentVisible = false;
}, 150); }, 150);
}, },
handleClose () { handleClose () {
@ -80,7 +96,7 @@
if (this.trigger !== 'click') { if (this.trigger !== 'click') {
return false; return false;
} }
this.visible = false; this.currentVisible = false;
}, },
hasParent () { hasParent () {
const $parent = this.$parent.$parent; const $parent = this.$parent.$parent;
@ -91,44 +107,63 @@
} }
} }
}, },
watch: { mounted () {
visible (val) { this.$on('on-click', (key) => {
if (val) {
this.$refs.drop.update();
} else {
this.$refs.drop.destroy();
}
this.$emit('on-visible-change', val);
}
},
events: {
'on-click' (key) {
const $parent = this.hasParent(); const $parent = this.hasParent();
if ($parent ) $parent.$emit('on-click', key); if ($parent) $parent.$emit('on-click', key);
}, });
'on-hover-click' () { this.$on('on-hover-click', () => {
const $parent = this.hasParent(); const $parent = this.hasParent();
if ($parent) { if ($parent) {
this.$nextTick(() => { this.$nextTick(() => {
if (this.trigger === 'custom') return false; if (this.trigger === 'custom') return false;
this.visible = false; this.currentVisible = false;
}); });
$parent.$emit('on-hover-click'); $parent.$emit('on-hover-click');
} else { } else {
this.$nextTick(() => { this.$nextTick(() => {
if (this.trigger === 'custom') return false; if (this.trigger === 'custom') return false;
this.visible = false; this.currentVisible = false;
}); });
} }
}, });
'on-haschild-click' () { this.$on('on-haschild-click', () => {
this.$nextTick(() => { this.$nextTick(() => {
if (this.trigger === 'custom') return false; if (this.trigger === 'custom') return false;
this.visible = true; this.currentVisible = true;
}); });
const $parent = this.hasParent(); const $parent = this.hasParent();
if ($parent) $parent.$emit('on-haschild-click'); if ($parent) $parent.$emit('on-haschild-click');
} });
} },
// events: {
// 'on-click' (key) {
// const $parent = this.hasParent();
// if ($parent ) $parent.$emit('on-click', key);
// },
// 'on-hover-click' () {
// const $parent = this.hasParent();
// if ($parent) {
// this.$nextTick(() => {
// if (this.trigger === 'custom') return false;
// this.currentVisible = false;
// });
// $parent.$emit('on-hover-click');
// } else {
// this.$nextTick(() => {
// if (this.trigger === 'custom') return false;
// this.currentVisible = false;
// });
// }
// },
// 'on-haschild-click' () {
// this.$nextTick(() => {
// if (this.trigger === 'custom') return false;
// this.currentVisible = true;
// });
// const $parent = this.hasParent();
// if ($parent) $parent.$emit('on-haschild-click');
// }
// }
}; };
</script> </script>

View file

@ -15,7 +15,7 @@
data () { data () {
return { return {
popper: null, popper: null,
width: '', width: ''
}; };
}, },
computed: { computed: {
@ -33,7 +33,7 @@
}); });
} else { } else {
this.$nextTick(() => { this.$nextTick(() => {
this.popper = new Popper(this.$parent.$els.reference, this.$el, { this.popper = new Popper(this.$parent.$refs.reference, this.$el, {
gpuAcceleration: false, gpuAcceleration: false,
placement: this.placement, placement: this.placement,
boundariesPadding: 0, boundariesPadding: 0,
@ -66,7 +66,7 @@
popper._popper.style.transformOrigin = `center ${ origin }`; popper._popper.style.transformOrigin = `center ${ origin }`;
} }
}, },
compiled () { created () {
this.$on('on-update-popper', this.update); this.$on('on-update-popper', this.update);
this.$on('on-destroy-popper', this.destroy); this.$on('on-destroy-popper', this.destroy);
}, },

View file

@ -52,6 +52,7 @@
const prefixCls = 'ivu-slider'; const prefixCls = 'ivu-slider';
export default { export default {
name: 'Slider',
components: { InputNumber, Tooltip }, components: { InputNumber, Tooltip },
props: { props: {
min: { min: {

View file

@ -14,7 +14,7 @@ import Checkbox from './components/checkbox';
import Circle from './components/circle'; import Circle from './components/circle';
import Collapse from './components/collapse'; import Collapse from './components/collapse';
// import DatePicker from './components/date-picker'; // import DatePicker from './components/date-picker';
// import Dropdown from './components/dropdown'; import Dropdown from './components/dropdown';
// import Form from './components/form'; // import Form from './components/form';
import Icon from './components/icon'; import Icon from './components/icon';
import Input from './components/input'; import Input from './components/input';
@ -64,9 +64,9 @@ const iview = {
CheckboxGroup: Checkbox.Group, CheckboxGroup: Checkbox.Group,
iCircle: Circle, iCircle: Circle,
// DatePicker, // DatePicker,
// Dropdown, Dropdown,
// DropdownItem: Dropdown.Item, DropdownItem: Dropdown.Item,
// DropdownMenu: Dropdown.Menu, DropdownMenu: Dropdown.Menu,
// iForm: Form, // iForm: Form,
// FormItem: Form.Item, // FormItem: Form.Item,
iCol: Col, iCol: Col,

View file

@ -38,6 +38,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
<li><router-link to="/tooltip">Tooltip</router-link></li> <li><router-link to="/tooltip">Tooltip</router-link></li>
<li><router-link to="/poptip">Poptip</router-link></li> <li><router-link to="/poptip">Poptip</router-link></li>
<li><router-link to="/slider">Slider</router-link></li> <li><router-link to="/slider">Slider</router-link></li>
<li><router-link to="/dropdown">Dropdown</router-link></li>
</ul> </ul>
</nav> </nav>
<router-view></router-view> <router-view></router-view>

View file

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

View file

@ -1,5 +1,5 @@
<template> <template>
<Dropdown trigger="click"> <Dropdown>
<a href="javascript:void(0)"> <a href="javascript:void(0)">
北京小吃 北京小吃
<Icon type="arrow-down-b"></Icon> <Icon type="arrow-down-b"></Icon>
@ -24,10 +24,6 @@
</template> </template>
<script> <script>
export default { export default {
methods: {
v (data) {
console.log(data)
}
}
} }
</script> </script>