fab.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="container">
  3. <uni-card :is-shadow="false" is-full>
  4. <text class="uni-h6">uni-ui 规范颜色色板,通过内置样式快速指定元素前景和背景色。</text>
  5. </uni-card>
  6. <uni-section title="基本功能" subTitle="点击按钮,切换 fab 不同状态" type="line">
  7. <view class="warp">
  8. <button class="button" type="primary" @click="switchBtn(0)">切换菜单方向({{ directionStr }})</button>
  9. <button class="button" type="primary" @click="switchBtn('left', 'bottom')">左下角显示</button>
  10. <button class="button" type="primary" @click="switchBtn('right', 'bottom')">右下角显示</button>
  11. <button class="button" type="primary" @click="switchBtn('left', 'top')">左上角显示</button>
  12. <button class="button" type="primary" @click="switchBtn('left', 'top')">左上角显示</button>
  13. <button class="button" type="primary" @click="switchBtn('right', 'top')">右上角显示</button>
  14. <button class="button" type="primary" @click="switchColor">修改颜色</button>
  15. </view>
  16. </uni-section>
  17. <uni-fab ref="fab" :pattern="pattern" :content="content" :horizontal="horizontal" :vertical="vertical"
  18. :direction="direction" @trigger="trigger" @fabClick="fabClick" />
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. components: {},
  24. data() {
  25. return {
  26. title: 'uni-fab',
  27. directionStr: '垂直',
  28. horizontal: 'left',
  29. vertical: 'bottom',
  30. direction: 'horizontal',
  31. pattern: {
  32. color: '#7A7E83',
  33. backgroundColor: '#fff',
  34. selectedColor: '#007AFF',
  35. buttonColor: '#007AFF',
  36. iconColor: '#fff'
  37. },
  38. is_color_type:false,
  39. content: [{
  40. iconPath: '/static/image.png',
  41. selectedIconPath: '/static/image-active.png',
  42. text: '相册',
  43. active: false
  44. },
  45. {
  46. iconPath: '/static/home.png',
  47. selectedIconPath: '/static/home-active.png',
  48. text: '首页',
  49. active: false
  50. },
  51. {
  52. iconPath: '/static/star.png',
  53. selectedIconPath: '/static/star-active.png',
  54. text: '收藏',
  55. active: false
  56. }]
  57. }
  58. },
  59. onBackPress() {
  60. if (this.$refs.fab.isShow) {
  61. this.$refs.fab.close()
  62. return true
  63. }
  64. return false
  65. },
  66. methods: {
  67. trigger(e) {
  68. console.log(e)
  69. this.content[e.index].active = !e.item.active
  70. uni.showModal({
  71. title: '提示',
  72. content: `您${this.content[e.index].active ? '选中了' : '取消了'}${e.item.text}`,
  73. success: function(res) {
  74. if (res.confirm) {
  75. console.log('用户点击确定')
  76. } else if (res.cancel) {
  77. console.log('用户点击取消')
  78. }
  79. }
  80. })
  81. },
  82. fabClick() {
  83. uni.showToast({
  84. title: '点击了悬浮按钮',
  85. icon: 'none'
  86. })
  87. },
  88. switchBtn(hor, ver) {
  89. if (hor === 0) {
  90. this.direction = this.direction === 'horizontal' ? 'vertical' : 'horizontal'
  91. this.directionStr = this.direction === 'horizontal' ? '垂直' : '水平'
  92. } else {
  93. this.horizontal = hor
  94. this.vertical = ver
  95. }
  96. this.$forceUpdate()
  97. },
  98. switchColor(){
  99. this.is_color_type = !this.is_color_type
  100. if(this.is_color_type) {
  101. this.pattern.iconColor = '#aaa'
  102. this.pattern.buttonColor = '#fff'
  103. }else{
  104. this.pattern.iconColor = '#fff'
  105. this.pattern.buttonColor = '#007AFF'
  106. }
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss">
  112. .warp {
  113. padding: 10px;
  114. }
  115. .button {
  116. margin-bottom: 10px;
  117. }
  118. </style>