fab-custom.nvue 5.0 KB

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