金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
3.9 KiB

  1. <template>
  2. <view class="lb-tabbar">
  3. <view :class="[
  4. 'lb-tabbar-content',
  5. fixed ? 'lb-tabbar--fixed' : ''
  6. ]"
  7. :style="{
  8. backgroundColor: bgColor,
  9. paddingBottom: `${safeAreaHeight}px`
  10. }">
  11. <view v-if="border"
  12. class="lb-tabbar-border"
  13. :style="{
  14. backgroundColor: borderColor,
  15. top: raisedeHeight + 'px'
  16. }">
  17. </view>
  18. <slot></slot>
  19. </view>
  20. <view v-if="placeholder"
  21. class="lb-tabbar-placeholder"
  22. :style="{
  23. height: `${tabbarHeight}px`
  24. }">
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. // git https://github.com/liub1934/uni-lb-tabbar/tree/master/pages/demos
  30. // demo https://github.liubing.me/uni-lb-tabbar/#/
  31. // fileDes https://ext.dcloud.net.cn/plugin?id=4124
  32. const SAFE_AREA_INSET_BOTTOM = 34
  33. import { getPx } from './utils'
  34. export default {
  35. props: {
  36. value: [String, Number],
  37. height: {
  38. type: String,
  39. default: '50px'
  40. },
  41. iconSize: {
  42. type: String,
  43. default: '22px'
  44. },
  45. textSize: {
  46. type: String,
  47. default: '12px'
  48. },
  49. textTop: {
  50. type: String,
  51. default: '5px'
  52. },
  53. dotColor: {
  54. type: String,
  55. default: '#F56C6C'
  56. },
  57. fixed: {
  58. type: Boolean,
  59. default: true
  60. },
  61. placeholder: {
  62. type: Boolean,
  63. default: true
  64. },
  65. animate: {
  66. type: String,
  67. default: 'rubberBand'
  68. },
  69. closeAnimateOnRaisede: {
  70. type: Boolean,
  71. default: true
  72. },
  73. border: {
  74. type: Boolean,
  75. default: true
  76. },
  77. borderColor: {
  78. type: String,
  79. default: '#DCDFE6'
  80. },
  81. bgColor: {
  82. type: String,
  83. default: '#FFF'
  84. },
  85. inactiveColor: {
  86. type: String,
  87. default: '#909399'
  88. },
  89. activeColor: {
  90. type: String,
  91. default: '#186c6b'
  92. },
  93. inactiveTextColor: String,
  94. activeTextColor: String,
  95. safeAreaInsetBottom: {
  96. type: Boolean,
  97. default: true
  98. },
  99. hideTabbar: {
  100. type: Boolean,
  101. default: true
  102. },
  103. raisedeScale: {
  104. type: Number,
  105. default: 2
  106. }
  107. },
  108. data () {
  109. return {
  110. active: this.value,
  111. activeItem: {},
  112. tabbarItems: [],
  113. hasRaisede: false,
  114. isIphoneX: false
  115. }
  116. },
  117. computed: {
  118. tabbarItemsLength () {
  119. return this.tabbarItems.length
  120. },
  121. safeAreaHeight () {
  122. return this.isIphoneX && this.safeAreaInsetBottom ? SAFE_AREA_INSET_BOTTOM : 0 // 苹果X等机型安全区高度
  123. },
  124. iconHeight () {
  125. return getPx(this.iconSize)
  126. },
  127. raisedeHeight () {
  128. return this.hasRaisede ? this.iconHeight * this.raisedeScale / 2 : 0 // 凸起高度
  129. },
  130. tabbarHeight () {
  131. const height = getPx(this.height) // 默认高度
  132. const raisedeHeight = this.hasRaisede ? this.iconHeight * this.raisedeScale / 2 : 0 // 凸起高度
  133. const tabbarHeight = height + this.safeAreaHeight + raisedeHeight // 整体高度
  134. return tabbarHeight
  135. }
  136. },
  137. provide () {
  138. return {
  139. tabbar: this
  140. }
  141. },
  142. created () {
  143. if (this.hideTabbar) {
  144. uni.hideTabBar()
  145. }
  146. const res = uni.getSystemInfoSync()
  147. const { model, statusBarHeight } = res
  148. if (
  149. (model.indexOf('iPhone') > -1 && statusBarHeight > 20) ||
  150. model.indexOf('iPhone X') > -1 ||
  151. model.indexOf('iPhone 1') > -1
  152. ) {
  153. this.isIphoneX = true
  154. }
  155. this.getTabbarHeight()
  156. },
  157. methods: {
  158. getTabbarHeight () {
  159. return this.tabbarHeight
  160. }
  161. },
  162. watch: {
  163. value (newVal) {
  164. this.active = newVal
  165. },
  166. active (newVal) {
  167. this.activeItem = this.tabbarItems.find(item => item.name === newVal)
  168. this.$emit('input', newVal)
  169. this.$emit('change', this.activeItem)
  170. },
  171. tabbarItemsLength () {
  172. this.hasRaisede = !!this.tabbarItems.find(item => item.raisede)
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. @import "./style.scss";
  179. </style>