fab.nvue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="uni-fab-box">
  3. <view class="uni-padding-wrap">
  4. <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn(0)"><text class="word-btn-white">切换菜单({{ directionStr }}显示)</text></view>
  5. <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn('left', 'bottom')"><text class="word-btn-white">左下角显示</text></view>
  6. <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn('right', 'bottom')"><text class="word-btn-white">右下角显示</text></view>
  7. <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn('left', 'top')"><text class="word-btn-white">左上角显示</text></view>
  8. <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn('right', 'top')"><text class="word-btn-white">右上角显示</text></view>
  9. </view>
  10. <uni-fab ref="fab" :pattern="pattern" :content="content" :horizontal="horizontal" :vertical="vertical" :direction="direction" @trigger="trigger" @fabClick="fabClick" />
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. components: {},
  16. data() {
  17. return {
  18. title: 'uni-fab',
  19. directionStr: '垂直',
  20. horizontal: 'left',
  21. vertical: 'bottom',
  22. direction: 'horizontal',
  23. pattern: {
  24. color: '#7A7E83',
  25. backgroundColor: '#fff',
  26. selectedColor: '#007AFF',
  27. },
  28. content: [{
  29. iconPath: '/static/component.png',
  30. selectedIconPath: '/static/componentHL.png',
  31. text: '组件',
  32. active: false
  33. },
  34. {
  35. iconPath: '/static/api.png',
  36. selectedIconPath: '/static/apiHL.png',
  37. text: 'API',
  38. active: false
  39. },
  40. {
  41. iconPath: '/static/template.png',
  42. selectedIconPath: '/static/templateHL.png',
  43. text: '模版',
  44. active: false
  45. }
  46. ]
  47. }
  48. },
  49. onBackPress() {
  50. if (this.$refs.fab.isShow) {
  51. this.$refs.fab.close()
  52. return true
  53. }
  54. return false
  55. },
  56. methods: {
  57. trigger(e) {
  58. console.log(e)
  59. this.content[e.index].active = !e.item.active
  60. uni.showModal({
  61. title: '提示',
  62. content: `您${this.content[e.index].active ? '选中了' : '取消了'}${e.item.text}`,
  63. success: function(res) {
  64. if (res.confirm) {
  65. console.log('用户点击确定')
  66. } else if (res.cancel) {
  67. console.log('用户点击取消')
  68. }
  69. }
  70. })
  71. },
  72. fabClick() {
  73. uni.showToast({
  74. title: '点击了悬浮按钮',
  75. icon: 'none'
  76. })
  77. },
  78. switchBtn(hor, ver) {
  79. if (hor === 0) {
  80. this.direction = this.direction === 'horizontal' ? 'vertical' : 'horizontal'
  81. this.directionStr = this.direction === 'horizontal' ? '垂直' : '水平'
  82. } else {
  83. this.horizontal = hor
  84. this.vertical = ver
  85. }
  86. this.$forceUpdate()
  87. }
  88. }
  89. }
  90. </script>
  91. <style>
  92. @charset "UTF-8";
  93. /* 头条小程序组件内不能引入字体 */
  94. /* #ifdef MP-TOUTIAO */
  95. @font-face {
  96. font-family: uniicons;
  97. font-weight: normal;
  98. font-style: normal;
  99. src: url("~@/static/uni.ttf") format("truetype");
  100. }
  101. /* #endif */
  102. /* #ifndef APP-NVUE */
  103. page {
  104. display: flex;
  105. flex-direction: column;
  106. box-sizing: border-box;
  107. background-color: #efeff4;
  108. min-height: 100%;
  109. height: auto;
  110. }
  111. view {
  112. font-size: 14px;
  113. line-height: inherit;
  114. }
  115. .example {
  116. padding: 0 15px 15px;
  117. }
  118. .example-info {
  119. padding: 15px;
  120. color: #3b4144;
  121. background: #ffffff;
  122. }
  123. .example-body {
  124. /* #ifndef APP-NVUE */
  125. display: flex;
  126. /* #endif */
  127. flex-direction: row;
  128. flex-wrap: wrap;
  129. justify-content: center;
  130. padding: 0;
  131. font-size: 14px;
  132. background-color: #ffffff;
  133. }
  134. /* #endif */
  135. .example {
  136. padding: 0 15px;
  137. }
  138. .example-info {
  139. /* #ifndef APP-NVUE */
  140. display: block;
  141. /* #endif */
  142. padding: 15px;
  143. color: #3b4144;
  144. background-color: #ffffff;
  145. font-size: 14px;
  146. line-height: 20px;
  147. }
  148. .example-info-text {
  149. font-size: 14px;
  150. line-height: 20px;
  151. color: #3b4144;
  152. }
  153. .example-body {
  154. flex-direction: column;
  155. padding: 15px;
  156. background-color: #ffffff;
  157. }
  158. .word-btn-white {
  159. font-size: 18px;
  160. color: #FFFFFF;
  161. }
  162. .word-btn {
  163. /* #ifndef APP-NVUE */
  164. display: flex;
  165. /* #endif */
  166. flex-direction: row;
  167. align-items: center;
  168. justify-content: center;
  169. border-radius: 6px;
  170. height: 48px;
  171. margin: 15px;
  172. background-color: #007AFF;
  173. }
  174. .word-btn--hover {
  175. background-color: #4ca2ff;
  176. }
  177. /* #ifndef APP-NVUE */
  178. page {
  179. height: 100vh;
  180. }
  181. /* #endif */
  182. .uni-fab-box {
  183. /* #ifndef APP-NVUE */
  184. display: flex;
  185. /* #endif */
  186. flex-direction: row;
  187. justify-content: center;
  188. position: absolute;
  189. top: 0;
  190. bottom: 0;
  191. left: 0;
  192. right: 0;
  193. }
  194. .uni-padding-wrap {
  195. /* #ifndef APP-NVUE */
  196. display: flex;
  197. /* #endif */
  198. flex-direction: column;
  199. justify-content: center;
  200. align-items: center;
  201. }
  202. .word-btn {
  203. width: 250px;
  204. }
  205. </style>