|
11 | 11 | <uni-section title="左侧滑出" type="line"></uni-section>
|
12 | 12 | <view class="example-body">
|
13 | 13 | <view class="word-btn draw-cotrol-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70"
|
14 |
| - @click="show('left')"><text class="word-btn-white">显示Drawer</text></view> |
15 |
| - <uni-drawer :visible="showLeft" mode="left" :width="320" @close="closeDrawer('left')"> |
| 14 | + @click="showDrawer('showLeft')"><text class="word-btn-white">显示Drawer</text></view> |
| 15 | + <uni-drawer ref="showLeft" mode="left" :width="320" @change="change($event,'showLeft')"> |
16 | 16 | <!-- #ifndef MP-BAIDU || MP-ALIPAY || MP-TOUTIAO -->
|
17 | 17 | <uni-list>
|
18 | 18 | <uni-list-item title="Item1" />
|
|
28 | 28 | </view>
|
29 | 29 | <!-- #endif -->
|
30 | 30 | <view class="close">
|
31 |
| - <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="hide"><text |
| 31 | + <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="closeDrawer('showLeft')"><text |
32 | 32 | class="word-btn-white">关闭Drawer</text></view>
|
33 | 33 | </view>
|
34 | 34 | </uni-drawer>
|
35 | 35 | </view>
|
36 | 36 | <uni-section title="右侧滑出" type="line"></uni-section>
|
37 | 37 | <view class="example-body">
|
38 | 38 | <view class="word-btn draw-cotrol-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70"
|
39 |
| - @click="show('right')"><text class="word-btn-white">显示Drawer</text></view> |
40 |
| - <uni-drawer :visible="showRight" mode="right" @close="closeDrawer('right')"> |
| 39 | + @click="showDrawer('showRight')"><text class="word-btn-white">显示Drawer</text></view> |
| 40 | + <uni-drawer ref="showRight" mode="right" :mask-click="false" @change="change($event,'showRight')"> |
| 41 | + <view class="info"> |
| 42 | + <text class="info-text">右侧遮罩只能通过按钮关闭,不能通过点击遮罩关闭</text> |
| 43 | + </view> |
41 | 44 | <!-- #ifndef MP-BAIDU || MP-ALIPAY || MP-TOUTIAO -->
|
42 | 45 | <uni-list>
|
43 | 46 | <uni-list-item title="Item1" />
|
|
53 | 56 | </view>
|
54 | 57 | <!-- #endif -->
|
55 | 58 | <view class="close">
|
56 |
| - <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="hide"><text |
| 59 | + <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="closeDrawer('showRight')"><text |
57 | 60 | class="word-btn-white">关闭Drawer</text></view>
|
58 | 61 | </view>
|
59 | 62 | </uni-drawer>
|
|
62 | 65 | </view>
|
63 | 66 | </template>
|
64 | 67 | <script>
|
65 |
| - import uniDrawer from '@/components/uni-drawer/uni-drawer.vue' |
66 |
| - import uniList from '@/components/uni-list/uni-list.vue' |
67 |
| - import uniListItem from '@/components/uni-list-item/uni-list-item.vue' |
68 |
| - import uniSection from '@/components/uni-section/uni-section.vue' |
69 |
| - import uniIcons from '@/components/uni-icons/uni-icons.vue' |
70 | 68 | export default {
|
71 |
| - components: {}, |
72 | 69 | data() {
|
73 | 70 | return {
|
74 | 71 | showRight: false,
|
75 | 72 | showLeft: false
|
76 | 73 | }
|
77 | 74 | },
|
78 | 75 | methods: {
|
79 |
| - show(e) { |
80 |
| - console.log("show", e); |
81 |
| - if (e === 'left') { |
82 |
| - this.showLeft = true |
83 |
| - } else { |
84 |
| - this.showRight = true |
85 |
| - } |
86 |
| - }, |
87 |
| - hide() { |
88 |
| - console.log("hide"); |
89 |
| - this.showLeft = false |
90 |
| - this.showRight = false |
| 76 | + // 打开窗口 |
| 77 | + showDrawer(e) { |
| 78 | + this.$refs[e].open() |
91 | 79 | },
|
| 80 | + // 关闭窗口 |
92 | 81 | closeDrawer(e) {
|
93 |
| - if (e === 'left') { |
94 |
| - this.showLeft = false |
95 |
| - } else { |
96 |
| - this.showRight = false |
97 |
| - } |
| 82 | + this.$refs[e].close() |
98 | 83 | },
|
99 |
| - confirm() {} |
| 84 | + // 抽屉状态发生变化触发 |
| 85 | + change(e, type) { |
| 86 | + console.log((type === 'showLeft' ? '左窗口' : '右窗口') + (e ? '打开' : '关闭')); |
| 87 | + this[type] = e |
| 88 | + } |
100 | 89 | },
|
101 | 90 | onNavigationBarButtonTap(e) {
|
102 | 91 | this.showRight = !this.showRight
|
103 | 92 | },
|
| 93 | + // app端拦截返回事件 ,仅app端生效 |
104 | 94 | onBackPress() {
|
105 | 95 | if (this.showRight || this.showLeft) {
|
106 |
| - this.hide() |
| 96 | + this.$refs.showLeft.close() |
| 97 | + this.$refs.showRight.close() |
107 | 98 | return true
|
108 | 99 | }
|
109 | 100 | }
|
|
169 | 160 | /* #ifndef APP-NVUE */
|
170 | 161 | display: flex;
|
171 | 162 | /* #endif */
|
172 |
| - flex-direction: row; |
| 163 | + flex-direction: row; |
173 | 164 | padding: 0;
|
174 | 165 | }
|
175 | 166 |
|
176 | 167 | .draw-cotrol-btn {
|
177 | 168 | flex: 1;
|
178 | 169 | }
|
| 170 | + |
| 171 | + .info { |
| 172 | + padding: 15px; |
| 173 | + color: #666; |
| 174 | + } |
| 175 | + |
| 176 | + .info-text { |
| 177 | + font-size: 14px; |
| 178 | + color: #666; |
| 179 | + } |
179 | 180 | </style>
|
0 commit comments