drawer.nvue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view>
  3. <view class="header">
  4. <view class="input-view">
  5. <uni-icons type="search" size="22" color="#666666" />
  6. <input confirm-type="search" class="input" type="text" placeholder="输入搜索关键词" @confirm="confirm">
  7. </view>
  8. </view>
  9. <text class="example-info">这是抽屉式导航组件使用示例,可以指定菜单左侧或者右侧弹出(仅初始化生效),组件内部可以放置任何内容。点击页面按钮即可显示导航菜单。</text>
  10. <view>
  11. <uni-section title="左侧滑出" type="line"></uni-section>
  12. <view class="example-body">
  13. <view class="word-btn draw-cotrol-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="showDrawer('showLeft')"><text class="word-btn-white">显示Drawer</text></view>
  14. <uni-drawer ref="showLeft" mode="left" :width="320" @change="change($event,'showLeft')">
  15. <view class="close">
  16. <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="closeDrawer('showLeft')"><text class="word-btn-white">关闭Drawer</text></view>
  17. </view>
  18. </uni-drawer>
  19. </view>
  20. <uni-section title="右侧滑出" type="line"></uni-section>
  21. <view class="example-body">
  22. <view class="word-btn draw-cotrol-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="showDrawer('showRight')"><text class="word-btn-white">显示Drawer</text></view>
  23. <uni-drawer ref="showRight" mode="right" :mask-click="false" @change="change($event,'showRight')">
  24. <view class="scroll-view">
  25. <scroll-view class="scroll-view-box" scroll-y="true">
  26. <view class="info">
  27. <text class="info-text">右侧遮罩只能通过按钮关闭,不能通过点击遮罩关闭</text>
  28. </view>
  29. <view class="close">
  30. <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="closeDrawer('showRight')"><text class="word-btn-white">关闭Drawer</text></view>
  31. </view>
  32. <view class="info-content" v-for="item in 100" :key="item">
  33. <text>可滚动内容 {{item}}</text>
  34. </view>
  35. <view class="close">
  36. <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="closeDrawer('showRight')"><text class="word-btn-white">关闭Drawer</text></view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. </uni-drawer>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. showRight: false,
  50. showLeft: false
  51. }
  52. },
  53. methods: {
  54. confirm() {},
  55. // 打开窗口
  56. showDrawer(e) {
  57. this.$refs[e].open()
  58. },
  59. // 关闭窗口
  60. closeDrawer(e) {
  61. this.$refs[e].close()
  62. },
  63. // 抽屉状态发生变化触发
  64. change(e, type) {
  65. console.log((type === 'showLeft' ? '左窗口' : '右窗口') + (e ? '打开' : '关闭'));
  66. this[type] = e
  67. }
  68. },
  69. onNavigationBarButtonTap(e) {
  70. if (this.showLeft) {
  71. this.$refs.showLeft.close()
  72. } else {
  73. this.$refs.showLeft.open()
  74. }
  75. },
  76. // app端拦截返回事件 ,仅app端生效
  77. onBackPress() {
  78. if (this.showRight || this.showLeft) {
  79. this.$refs.showLeft.close()
  80. this.$refs.showRight.close()
  81. return true
  82. }
  83. }
  84. }
  85. </script>
  86. <style>
  87. @charset "UTF-8";
  88. /* 头条小程序组件内不能引入字体 */
  89. /* #ifdef MP-TOUTIAO */
  90. @font-face {
  91. font-family: uniicons;
  92. font-weight: normal;
  93. font-style: normal;
  94. src: url("~@/static/uni.ttf") format("truetype");
  95. }
  96. /* #endif */
  97. /* #ifndef APP-NVUE */
  98. page {
  99. display: flex;
  100. flex-direction: column;
  101. box-sizing: border-box;
  102. background-color: #efeff4;
  103. min-height: 100%;
  104. height: auto;
  105. }
  106. view {
  107. font-size: 14px;
  108. line-height: inherit;
  109. }
  110. .example {
  111. padding: 0 15px 15px;
  112. }
  113. .example-info {
  114. padding: 15px;
  115. color: #3b4144;
  116. background: #ffffff;
  117. }
  118. .example-body {
  119. /* #ifndef APP-NVUE */
  120. display: flex;
  121. /* #endif */
  122. flex-direction: row;
  123. flex-wrap: wrap;
  124. justify-content: center;
  125. padding: 0;
  126. font-size: 14px;
  127. background-color: #ffffff;
  128. }
  129. /* #endif */
  130. .example {
  131. padding: 0 15px;
  132. }
  133. .example-info {
  134. /* #ifndef APP-NVUE */
  135. display: block;
  136. /* #endif */
  137. padding: 15px;
  138. color: #3b4144;
  139. background-color: #ffffff;
  140. font-size: 14px;
  141. line-height: 20px;
  142. }
  143. .example-info-text {
  144. font-size: 14px;
  145. line-height: 20px;
  146. color: #3b4144;
  147. }
  148. .example-body {
  149. flex-direction: column;
  150. padding: 15px;
  151. background-color: #ffffff;
  152. }
  153. .word-btn-white {
  154. font-size: 18px;
  155. color: #FFFFFF;
  156. }
  157. .word-btn {
  158. /* #ifndef APP-NVUE */
  159. display: flex;
  160. /* #endif */
  161. flex-direction: row;
  162. align-items: center;
  163. justify-content: center;
  164. border-radius: 6px;
  165. height: 48px;
  166. margin: 15px;
  167. background-color: #007AFF;
  168. }
  169. .word-btn--hover {
  170. background-color: #4ca2ff;
  171. }
  172. .header {
  173. /* #ifndef APP-NVUE */
  174. display: flex;
  175. /* #endif */
  176. flex-direction: row;
  177. padding: 10px 15px;
  178. align-items: center;
  179. border-top-width: 1px;
  180. border-top-color: #f5f5f5;
  181. border-top-style: solid;
  182. background-color: #ffffff;
  183. }
  184. .input-view {
  185. /* #ifndef APP-NVUE */
  186. display: flex;
  187. /* #endif */
  188. align-items: center;
  189. flex-direction: row;
  190. background-color: #e7e7e7;
  191. height: 30px;
  192. border-radius: 15px;
  193. padding: 0 10px;
  194. flex: 1;
  195. background-color: #f5f5f5;
  196. }
  197. .uni-drawer-info {
  198. background-color: #ffffff;
  199. padding: 15px;
  200. padding-top: 5px;
  201. color: #3b4144;
  202. }
  203. .uni-padding-wrap {
  204. padding: 0 15px;
  205. line-height: 1.8;
  206. }
  207. .input {
  208. flex: 1;
  209. padding: 0 5px;
  210. height: 24px;
  211. line-height: 24px;
  212. font-size: 14px;
  213. background-color: transparent;
  214. }
  215. .close {
  216. padding: 15px;
  217. }
  218. .example-body {
  219. /* #ifndef APP-NVUE */
  220. display: flex;
  221. /* #endif */
  222. flex-direction: row;
  223. padding: 0;
  224. }
  225. .draw-cotrol-btn {
  226. flex: 1;
  227. }
  228. .info {
  229. padding: 15px;
  230. color: #666;
  231. }
  232. .info-text {
  233. font-size: 14px;
  234. color: #666;
  235. }
  236. .scroll-view {
  237. /* #ifndef APP-NVUE */
  238. width: 100%;
  239. height: 100%;
  240. /* #endif */
  241. flex: 1;
  242. }
  243. .scroll-view-box {
  244. flex: 1;
  245. position: absolute;
  246. top: 0;
  247. right: 0;
  248. bottom: 0;
  249. left: 0;
  250. }
  251. .info-content {
  252. padding: 5px 15px;
  253. }
  254. </style>