custom-tab-bar2.uvue 4.0 KB
Newer Older
H
hdx 已提交
1 2 3 4 5 6 7
<template>
  <view class="tabs">
    <view class="tab-view">
      <tab1 ref="tab1" v-if="tabList[0].init" v-show="selectedIndex==0"></tab1>
      <tab2 ref="tab2" v-if="tabList[1].init" v-show="selectedIndex==1"></tab2>
    </view>
    <view ref="tabbar" class="tab-bar">
8 9
      <view class="tab-item" @click="onTabClick(0)">
        <view ref="tab-item1" class="tab-item-content">
H
hdx 已提交
10 11 12 13 14 15 16
          <text class="tab-item-icon uni-icon"
            :class="selectedIndex==0 ? 'tab-item-text-active' : ''">{{'\ue644'}}</text>
          <text class="tab-item-text" :class="selectedIndex==0 ? 'tab-item-text-active' : ''">
            列表
          </text>
        </view>
      </view>
17 18
      <view>
        <image class="concave-image" src="/static/template/custom-tab-bar2/concave.png"></image>
19
        <view class="btn-plus" @click="onPlusClick">
H
hdx 已提交
20 21 22
          <text class="btn-plus-text">+</text>
        </view>
      </view>
23 24
      <view class="tab-item" @click="onTabClick(1)">
        <view ref="tab-item2" class="tab-item-content">
H
hdx 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
          <text class="tab-item-icon uni-icon"
            :class="selectedIndex==1 ? 'tab-item-text-active' : ''">{{'\ue699'}}</text>
          <text class="tab-item-text" :class="selectedIndex==1 ? 'tab-item-text-active' : ''">
            我的
          </text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import tab1 from './custom-tab-bar2-tab1.uvue';
  import tab2 from './custom-tab-bar2-tab2.uvue';

  type TabItem = {
    init : boolean,
    preload : boolean,
  }

  export default {
    components: {
      tab1,
      tab2
    },
    data() {
      return {
        tabList: [
          {
            init: false
          } as TabItem,
          {
            init: false
          } as TabItem,
        ] as TabItem[],
60
        selectedIndex: -1
H
hdx 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
      }
    },
    onReady() {
      this.setSelectedIndex(0)
    },
    methods: {
      onTabClick(index : number) {
        this.setSelectedIndex(index);
        if (index == 0) {
          (this.$refs["tab1"]! as ComponentPublicInstance).$callMethod('scrollTop', 0)
        }
      },
      onTabPageEvent(top : number) {
        const tabItem1 = this.$refs["tabs-item1"] as Element
        const angle = top < 50 ? '0deg' : '180deg'
        tabItem1.style.setProperty('transform', `rotate(${angle})`)
      },
      setSelectedIndex(index : number) {
        if (this.selectedIndex === index) {
          return
        }
        if (!this.tabList[index].init) {
          this.tabList[index].init = true
        }
        this.selectedIndex = index
86 87 88 89 90 91 92
      },
      onPlusClick() {
        uni.showModal({
          title: "提示",
          content: "你点击了 +",
          showCancel: false
        })
H
hdx 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
      }
    }
  }
</script>

<style>
  @font-face {
    font-family: "UniIcon";
    src: url('@/static/fonts/uni-icon.ttf');
  }

  .uni-icon {
    font-family: "UniIcon";
    font-size: 16px;
    font-style: normal;
  }

  .tabs {
    flex: 1;
    background-color: #fff;
    overflow: visible;
  }

  .tab-view {
    flex: 1;
  }

  .tab-view-item {
    flex: 1;
  }

  .tab-bar {
    flex-direction: row;
    height: 56px;
    overflow: visible;
  }

  .tab-item {
    flex: 1;
    position: relative;
133
    background-color: #1e90ff;
H
hdx 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    overflow: visible;
  }

  .tab-item-content {
    margin: auto;
  }

  .tab-item-icon {
    color: #ccc;
    font-size: 12px;
    text-align: center;
    margin-bottom: 4px;
  }

  .tab-item-text {
    color: #ccc;
    font-size: 12px;
    text-align: center;
  }

  .tab-item-text-active {
    color: #fff;
  }

158 159 160 161 162
  .concave-image {
    width: 115px;
    height: 56px;
  }

H
hdx 已提交
163
  .btn-plus {
164 165
    position: absolute;
    left: 23px;
H
hdx 已提交
166 167 168 169 170
    width: 70px;
    height: 70px;
    border-radius: 50px;
    background-color: #FE5722;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
171 172
    /* margin-left: auto;
    margin-right: auto; */
H
hdx 已提交
173 174 175 176 177 178 179 180 181 182
    margin-top: -35px;
    align-items: center;
    justify-content: center;
    overflow: visible;
  }

  .btn-plus-text {
    color: #fff;
    font-size: 32px;
  }
183
</style>