index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="nav-bar main-center cross-center">
  3. <view
  4. v-for="(item,index) in navItem"
  5. :key="index"
  6. class="item dir-top-wrap cross-center"
  7. @click="handleRedirect(item)"
  8. >
  9. <view
  10. class="icon"
  11. :style="{
  12. backgroundImage: `url(${item.icon})`
  13. }"
  14. />
  15. <text>{{ item.name }}</text>
  16. </view>
  17. <!--充值-->
  18. <recharge :show.sync="recharge.show" />
  19. </view>
  20. </template>
  21. <script>
  22. import Recharge from '../Recharge/index'
  23. export default {
  24. name: 'NavBar',
  25. components: { Recharge },
  26. data() {
  27. return {
  28. types: {
  29. 1: { href: '/pages/index/rank' },
  30. 2: { href: '/pages/index/news' },
  31. 3: { href: '/pages/member/index' },
  32. 4: { href: '/pages/sign/index' },
  33. 5: { type: 'recharge' }
  34. },
  35. navItem: [
  36. { icon: '', name: '排行榜', href: '/pages/index/rank' },
  37. { icon: '', name: '最新', href: '/pages/index/news' },
  38. { icon: '', name: '会员', href: '/pages/member/index' },
  39. { icon: '', name: '签到', href: '/pages/sign/index' },
  40. { icon: '', name: '充值', type: 'recharge' }
  41. ],
  42. recharge: { show: false }
  43. }
  44. },
  45. computed: {},
  46. created() {
  47. this.getData()
  48. },
  49. methods: {
  50. handleRedirect(item) {
  51. if (item.type === 'recharge') {
  52. this.recharge.show = true
  53. } else if (item.href) {
  54. this.$u.route(item.href)
  55. }
  56. },
  57. getData() {
  58. /**
  59. * type 1 -排行榜 2 -最新 3 -会员 4 -签到 5 -充值
  60. */
  61. this.$api.setting.navBar().then(res => {
  62. const data = res.data
  63. data.forEach(obj => {
  64. Object.assign(obj, this.types[obj.type])
  65. })
  66. this.navItem = data
  67. })
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .nav-bar {
  74. .item{
  75. flex: 1;
  76. font-size: 32rpx;
  77. .icon{
  78. width: 100rpx;
  79. height: 100rpx;
  80. background-repeat: no-repeat;
  81. background-size: 100%;
  82. background-position: center;
  83. }
  84. text{
  85. color: #fff;
  86. }
  87. }
  88. }
  89. </style>