1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
| <template>
| <uni-shadow-root class="vant-dropdown-item-index"><view v-if="showWrapper" :class="utils.bem('dropdown-item', direction)" :style="wrapperStyle">
| <van-popup :show="showPopup" :custom-style="'position: absolute;'+(popupStyle)" overlay-style="position: absolute;" :overlay="overlay" :position="direction === 'down' ? 'top' : 'bottom'" :duration="transition ? duration : 0" :close-on-click-overlay="closeOnClickOverlay" @enter="onOpen" @leave="onClose" @close="toggle" @after-enter="onOpened" @after-leave="onClosed">
| <van-cell v-for="(item,index) in (options)" :key="item.value" :data-option="item" :class="utils.bem('dropdown-item__option', { active: item.value === value } )" clickable :icon="item.icon" @click.native="onOptionTap">
| <view slot="title" class="van-dropdown-item__title" :style="item.value === value ? 'color:' + activeColor : ''">
| {{ item.text }}
| </view>
| <van-icon v-if="item.value === value" name="success" class="van-dropdown-item__icon" :color="activeColor"></van-icon>
| </van-cell>
|
| <slot></slot>
| </van-popup>
| </view></uni-shadow-root>
| </template>
| <wxs src="../wxs/utils.wxs" module="utils"></wxs>
| <script>
| import VanPopup from '../popup/index.vue'
| import VanCell from '../cell/index.vue'
| import VanIcon from '../icon/index.vue'
| global['__wxVueOptions'] = {components:{'van-popup': VanPopup,'van-cell': VanCell,'van-icon': VanIcon}}
|
| global['__wxRoute'] = 'vant/dropdown-item/index'
| import { VantComponent } from '../common/component';
| VantComponent({
| field: true,
| relation: {
| name: 'dropdown-menu',
| type: 'ancestor',
| current: 'dropdown-item',
| linked() {
| this.updateDataFromParent();
| },
| },
| props: {
| value: {
| type: null,
| observer: 'rerender',
| },
| title: {
| type: String,
| observer: 'rerender',
| },
| disabled: Boolean,
| titleClass: {
| type: String,
| observer: 'rerender',
| },
| options: {
| type: Array,
| value: [],
| observer: 'rerender',
| },
| popupStyle: String,
| },
| data: {
| transition: true,
| showPopup: false,
| showWrapper: false,
| displayTitle: '',
| },
| methods: {
| rerender() {
| wx.nextTick(() => {
| this.parent && this.parent.updateItemListData();
| });
| },
| updateDataFromParent() {
| if (this.parent) {
| const {
| overlay,
| duration,
| activeColor,
| closeOnClickOverlay,
| direction,
| } = this.parent.data;
| this.setData({
| overlay,
| duration,
| activeColor,
| closeOnClickOverlay,
| direction,
| });
| }
| },
| onOpen() {
| this.$emit('open');
| },
| onOpened() {
| this.$emit('opened');
| },
| onClose() {
| this.$emit('close');
| },
| onClosed() {
| this.$emit('closed');
| this.setData({ showWrapper: false });
| },
| onOptionTap(event) {
| const { option } = event.currentTarget.dataset;
| const { value } = option;
| const shouldEmitChange = this.data.value !== value;
| this.setData({ showPopup: false, value });
| this.$emit('close');
| this.rerender();
| if (shouldEmitChange) {
| this.$emit('change', value);
| }
| },
| toggle(show, options = {}) {
| const { showPopup } = this.data;
| if (typeof show !== 'boolean') {
| show = !showPopup;
| }
| if (show === showPopup) {
| return;
| }
| this.setData({
| transition: !options.immediate,
| showPopup: show,
| });
| if (show) {
| this.parent.getChildWrapperStyle().then((wrapperStyle) => {
| this.setData({ wrapperStyle, showWrapper: true });
| this.rerender();
| });
| } else {
| this.rerender();
| }
| },
| },
| });
| export default global['__wxComponents']['vant/dropdown-item/index']
| </script>
| <style platform="mp-weixin">
| @import '../common/index.css';.van-dropdown-item{position:fixed;right:0;left:0;overflow:hidden}.van-dropdown-item__option{text-align:left}.van-dropdown-item__option--active .van-dropdown-item__icon,.van-dropdown-item__option--active .van-dropdown-item__title{color:#1989fa;color:var(--dropdown-menu-option-active-color,#1989fa)}.van-dropdown-item--up{top:0}.van-dropdown-item--down{bottom:0}.van-dropdown-item__icon{display:block;line-height:inherit}
| </style>
|
|