Commit a9cd43b39c12722b526ab3face7427e432ab3ff3

Authored by 梁灏
1 parent ecaf8d51

Cascader add transfer prop

examples/routers/cascader.vue
1 <template> 1 <template>
2 - <Cascader v-model="value3" :data="data" filterable></Cascader> 2 + <div style="width: 400px;">
  3 + <Row>
  4 + <i-col span="12">
  5 + <Cascader transfer v-model="value3" :data="data" filterable></Cascader>
  6 + </i-col>
  7 + <i-col span="12">
  8 + <Cascader v-model="value3" :data="data" filterable></Cascader>
  9 + </i-col>
  10 + </Row>
  11 + </div>
3 </template> 12 </template>
4 <script> 13 <script>
5 export default { 14 export default {
examples/routers/modal.vue
@@ -5,10 +5,11 @@ @@ -5,10 +5,11 @@
5 <Modal v-model="showModal" title="弹窗"> 5 <Modal v-model="showModal" title="弹窗">
6 <Tabs> 6 <Tabs>
7 <Tab-pane label="演示" style="height: 80px;"> 7 <Tab-pane label="演示" style="height: 80px;">
8 - <Date-picker transfer type="daterange" placement="bottom-end" placeholder="选择日期" style="width: 200px"></Date-picker>  
9 - <i-select transfer multiple v-model="m1">  
10 - <i-option v-for="item in options" :value="item.value" :key="item.value">{{ item.label }}</i-option>  
11 - </i-select> 8 + <!--<Date-picker transfer type="daterange" placement="bottom-end" placeholder="选择日期" style="width: 200px"></Date-picker>-->
  9 + <!--<i-select transfer multiple v-model="m1">-->
  10 + <!--<i-option v-for="item in options" :value="item.value" :key="item.value">{{ item.label }}</i-option>-->
  11 + <!--</i-select>-->
  12 + <Cascader transfer :data="data4" :load-data="loadData"></Cascader>
12 </Tab-pane> 13 </Tab-pane>
13 </Tabs> 14 </Tabs>
14 </Modal> 15 </Modal>
@@ -51,6 +52,20 @@ @@ -51,6 +52,20 @@
51 value: 'chongqing', 52 value: 'chongqing',
52 label: '重庆市' 53 label: '重庆市'
53 } 54 }
  55 + ],
  56 + data4: [
  57 + {
  58 + value: 'beijing',
  59 + label: '北京',
  60 + children: [],
  61 + loading: false
  62 + },
  63 + {
  64 + value: 'hangzhou',
  65 + label: '杭州',
  66 + children: [],
  67 + loading:false
  68 + }
54 ] 69 ]
55 } 70 }
56 }, 71 },
@@ -74,6 +89,40 @@ @@ -74,6 +89,40 @@
74 this.$refs["formSelect"].clearSingleSelect(); 89 this.$refs["formSelect"].clearSingleSelect();
75 this.options = []; 90 this.options = [];
76 // }, 300) 91 // }, 300)
  92 + },
  93 + loadData (item, callback) {
  94 + item.loading = true;
  95 + setTimeout(() => {
  96 + if (item.value === 'beijing') {
  97 + item.children = [
  98 + {
  99 + value: 'talkingdata',
  100 + label: 'TalkingData'
  101 + },
  102 + {
  103 + value: 'baidu',
  104 + label: '百度'
  105 + },
  106 + {
  107 + value: 'sina',
  108 + label: '新浪'
  109 + }
  110 + ];
  111 + } else if (item.value === 'hangzhou') {
  112 + item.children = [
  113 + {
  114 + value: 'ali',
  115 + label: '阿里巴巴'
  116 + },
  117 + {
  118 + value: '163',
  119 + label: '网易'
  120 + }
  121 + ];
  122 + }
  123 + item.loading = false;
  124 + callback();
  125 + }, 1000);
77 } 126 }
78 } 127 }
79 } 128 }
examples/routers/poptip.vue
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <Poptip trigger="hover" title="提示标题" content="提示内容"> 3 <Poptip trigger="hover" title="提示标题" content="提示内容">
4 <Button>hover 激活</Button> 4 <Button>hover 激活</Button>
5 </Poptip> 5 </Poptip>
6 - <Poptip title="提示标题" content="提示内容"> 6 + <Poptip transfer title="提示标题" content="提示内容">
7 <Button>click 激活</Button> 7 <Button>click 激活</Button>
8 </Poptip> 8 </Poptip>
9 <Poptip trigger="focus" title="提示标题" content="提示内容"> 9 <Poptip trigger="focus" title="提示标题" content="提示内容">
src/components/cascader/cascader.vue
1 <template> 1 <template>
2 <div :class="classes" v-clickoutside="handleClose"> 2 <div :class="classes" v-clickoutside="handleClose">
3 - <div :class="[prefixCls + '-rel']" @click="toggleOpen"> 3 + <div :class="[prefixCls + '-rel']" @click="toggleOpen" ref="reference">
4 <slot> 4 <slot>
5 <i-input 5 <i-input
6 ref="input" 6 ref="input"
@@ -19,7 +19,12 @@ @@ -19,7 +19,12 @@
19 </slot> 19 </slot>
20 </div> 20 </div>
21 <transition name="slide-up"> 21 <transition name="slide-up">
22 - <Drop v-show="visible"> 22 + <Drop
  23 + v-show="visible"
  24 + :class="{ [prefixCls + '-transfer']: transfer }"
  25 + ref="drop"
  26 + :data-transfer="transfer"
  27 + v-transfer-dom>
23 <div> 28 <div>
24 <Caspanel 29 <Caspanel
25 v-show="!filterable || (filterable && query === '')" 30 v-show="!filterable || (filterable && query === '')"
@@ -51,6 +56,7 @@ @@ -51,6 +56,7 @@
51 import Icon from '../icon/icon.vue'; 56 import Icon from '../icon/icon.vue';
52 import Caspanel from './caspanel.vue'; 57 import Caspanel from './caspanel.vue';
53 import clickoutside from '../../directives/clickoutside'; 58 import clickoutside from '../../directives/clickoutside';
  59 + import TransferDom from '../../directives/transfer-dom';
54 import { oneOf } from '../../utils/assist'; 60 import { oneOf } from '../../utils/assist';
55 import Emitter from '../../mixins/emitter'; 61 import Emitter from '../../mixins/emitter';
56 import Locale from '../../mixins/locale'; 62 import Locale from '../../mixins/locale';
@@ -62,7 +68,7 @@ @@ -62,7 +68,7 @@
62 name: 'Cascader', 68 name: 'Cascader',
63 mixins: [ Emitter, Locale ], 69 mixins: [ Emitter, Locale ],
64 components: { iInput, Drop, Icon, Caspanel }, 70 components: { iInput, Drop, Icon, Caspanel },
65 - directives: { clickoutside }, 71 + directives: { clickoutside, TransferDom },
66 props: { 72 props: {
67 data: { 73 data: {
68 type: Array, 74 type: Array,
@@ -117,6 +123,10 @@ @@ -117,6 +123,10 @@
117 }, 123 },
118 notFoundText: { 124 notFoundText: {
119 type: String 125 type: String
  126 + },
  127 + transfer: {
  128 + type: Boolean,
  129 + default: false
120 } 130 }
121 }, 131 },
122 data () { 132 data () {
@@ -333,11 +343,17 @@ @@ -333,11 +343,17 @@
333 if (this.currentValue.length) { 343 if (this.currentValue.length) {
334 this.updateSelected(); 344 this.updateSelected();
335 } 345 }
  346 + if (this.transfer) {
  347 + this.$refs.drop.update();
  348 + }
336 } else { 349 } else {
337 if (this.filterable) { 350 if (this.filterable) {
338 this.query = ''; 351 this.query = '';
339 this.$refs.input.currentValue = ''; 352 this.$refs.input.currentValue = '';
340 } 353 }
  354 + if (this.transfer) {
  355 + this.$refs.drop.destroy();
  356 + }
341 } 357 }
342 this.$emit('on-visible-change', val); 358 this.$emit('on-visible-change', val);
343 }, 359 },
src/styles/components/cascader.less
1 @cascader-prefix-cls: ~"@{css-prefix}cascader"; 1 @cascader-prefix-cls: ~"@{css-prefix}cascader";
2 @cascader-item-prefix-cls: ~"@{css-prefix}cascader-menu-item"; 2 @cascader-item-prefix-cls: ~"@{css-prefix}cascader-menu-item";
3 3
  4 +.selectDropDown{
  5 + width: auto;
  6 + padding: 0;
  7 + white-space: nowrap;
  8 + overflow: visible;
  9 +}
  10 +
4 .@{cascader-prefix-cls} { 11 .@{cascader-prefix-cls} {
5 //position: relative; 12 //position: relative;
6 line-height: normal; 13 line-height: normal;
@@ -64,10 +71,7 @@ @@ -64,10 +71,7 @@
64 } 71 }
65 72
66 .@{select-dropdown-prefix-cls} { 73 .@{select-dropdown-prefix-cls} {
67 - width: auto;  
68 - padding: 0;  
69 - white-space: nowrap;  
70 - overflow: visible; 74 + .selectDropDown();
71 } 75 }
72 76
73 .select-item(@cascader-prefix-cls, @cascader-item-prefix-cls); 77 .select-item(@cascader-prefix-cls, @cascader-item-prefix-cls);
@@ -138,6 +142,14 @@ @@ -138,6 +142,14 @@
138 } 142 }
139 } 143 }
140 } 144 }
  145 +.@{cascader-prefix-cls}-transfer{
  146 + z-index: @zindex-transfer;
  147 + .selectDropDown();
  148 + .select-item(@cascader-prefix-cls, @cascader-item-prefix-cls);
  149 + .ivu-select-item span{
  150 + color: @error-color;
  151 + }
  152 +}
141 153
142 .@{form-item-prefix-cls}-error{ 154 .@{form-item-prefix-cls}-error{
143 .@{cascader-prefix-cls} { 155 .@{cascader-prefix-cls} {