navbar-lite.uvue 5.8 KB
Newer Older
M
mehaotian 已提交
1 2
<template>
  <view class="content">
3
    <uni-navbar-lite :status-bar="true" :title="title" :is-left="isLeft" :text-color="navigationBarTextColor"></uni-navbar-lite>
4

W
wanganxp 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17
    <view class="content-item" @click="onClick">
      <text>点击此处,将标题切换为{{isLeft?'居中':'左侧'}}显示</text>
    </view>
    <view class="content-item" @tap="setNavigationBarColor1">
      <text>设置自定义导航栏前景色白色</text>
    </view>
    <view class="content-item" @tap="setNavigationBarColor2">
      <text>设置自定义导航栏前景色黑色</text>
    </view>
    <view style="align-items: center;height: 60px;">
      <text>测试输入框上推页面</text>
      <radio-group @change="ChangeView" style="flex-direction: row;">
        <radio value="0" :checked="true"><text>scroll-view</text></radio>
18 19 20 21
        <radio value="1"><text>list-view</text></radio>
        <!-- #ifndef MP -->
        <radio value="2"><text>web-view</text></radio>
        <!-- #endif -->
W
wanganxp 已提交
22 23
      </radio-group>
    </view>
24
    <scroll-view v-if="indexView==0" class="scroll-view" :scroll-y="true" :refresher-enabled="false">
W
wanganxp 已提交
25 26 27 28
      <view class="content-item" v-for="item in 10">
        <view class="cell-item">
          <text class="text">内容:{{item}}</text>
          <input class="text" style="margin-top: 8px;" placeholder="备注输入框:" />
29
        </view>
W
wanganxp 已提交
30
      </view>
M
mehaotian 已提交
31
    </scroll-view>
W
wanganxp 已提交
32 33 34 35 36 37 38 39
    <list-view v-if="indexView==1" class="scroll-view">
      <list-item class="content-item" v-for="item in 10">
        <view class="cell-item">
          <text class="text">列表项内容:{{item}}</text>
          <input class="text" style="margin-top: 8px;" placeholder="备注输入框:" />
        </view>
      </list-item>
    </list-view>
40 41
    <web-view v-if="indexView==2" src="/hybrid/html/local.html" id="webv" class="scroll-view"></web-view>
    <view style="position:relative;background-color:white;z-index:1000;" :style="{bottom: inputBottom}">
42
      <input id="input" placeholder="滚动视图外的居底输入框,不上推,手动控制输入框top" adjust-position="false" @blur="onInputBlur" @keyboardheightchange="onInputKeyboardChange" />
W
wanganxp 已提交
43 44
    </view>

M
mehaotian 已提交
45 46 47
  </view>
</template>

W
wanganxp 已提交
48
<script>
49
  import { state, setLifeCycleNum } from '@/store/index.uts'
M
mehaotian 已提交
50 51 52
  export default {
    data() {
      return {
53
        title: 'Hello uni-app',
W
wanganxp 已提交
54 55
        isLeft: false,
        navigationBarTextColor: '#000',
56
        indexView: 0,
57
        windowHeight: 0,
58
        inputRemainHeight: 0,  //输入框距离底部的距离
59
        inputBottom: '0px'
M
mehaotian 已提交
60 61
      }
    },
W
wanganxp 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    methods: {
      onClick() {
        this.isLeft = !this.isLeft
      },
      setNavigationBarColor1() {
        uni.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: '#0000',
          success: () => {
            this.navigationBarTextColor = '#fff'
            console.log('setNavigationBarColor success')
            this.setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail: () => {
            console.log('setNavigationBarColor fail')
            this.setLifeCycleNum(state.lifeCycleNum - 1)
          },
          complete: () => {
            console.log('setNavigationBarColor complete')
            this.setLifeCycleNum(state.lifeCycleNum + 1)
          }
        })
      },
      setNavigationBarColor2() {
        uni.setNavigationBarColor({
          frontColor: '#000000',
          backgroundColor: '#0000',
          success: () => {
            this.navigationBarTextColor = '#000'
            console.log('setNavigationBarColor success')
            this.setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail: () => {
            console.log('setNavigationBarColor fail')
            this.setLifeCycleNum(state.lifeCycleNum - 1)
          },
          complete: () => {
            console.log('setNavigationBarColor complete')
            this.setLifeCycleNum(state.lifeCycleNum + 1)
          }
        })
103
      },
W
wanganxp 已提交
104 105
      ChangeView(e:UniRadioGroupChangeEvent){
        this.indexView = parseInt(e.detail.value)
106
      },
107
      onInputBlur(_:UniInputBlurEvent) {
108
        this.inputBottom = '0px';
109 110
      },
      onInputKeyboardChange(e:UniInputKeyboardHeightChangeEvent) {
111
        let bottom = (this.inputRemainHeight > e.detail.height)?0:(e.detail.height-this.inputRemainHeight);
112
        this.inputBottom = `${bottom}px`;
W
wanganxp 已提交
113 114 115 116 117 118 119 120
      },
      // 自动化测试
      getLifeCycleNum() : number {
        return state.lifeCycleNum
      },
      // 自动化测试
      setLifeCycleNum(num : number) {
        setLifeCycleNum(num)
121 122 123
      },
      async calcInputRemainHeight() {
        let windowHeight = uni.getWindowInfo().windowHeight
124
        const rect = await uni.getElementById('input')!.getBoundingClientRectAsync()!
125
        this.inputRemainHeight = windowHeight - rect.bottom
126
      }
127 128
    },
    onReady() {
129 130 131
      this.calcInputRemainHeight()
      // let windowHeight = uni.getWindowInfo().windowHeight;
      // this.inputRemainHeight = windowHeight - (uni.getElementById('input')?.getBoundingClientRect()?.bottom??windowHeight);
132 133
    },
    onResize() {
134 135 136
      this.calcInputRemainHeight()
      // let windowHeight = uni.getWindowInfo().windowHeight;
      // this.inputRemainHeight = windowHeight - (uni.getElementById('input')?.getBoundingClientRect()?.bottom??windowHeight);
137
    }
M
mehaotian 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
  }
</script>

<style>
  .content {
    display: flex;
    flex-direction: column;
    flex: 1;
  }

  .scroll-view {
    flex: 1;
    background-color: #f5f5f5;
    padding: 5px 0;
  }

  .content-item {
    padding: 15px;
    margin: 5px 10px;
    background-color: #fff;
    border-radius: 5px;
W
wanganxp 已提交
159 160 161 162 163
  }

  .cell-item {
    display: flex;
    flex-direction: column;
M
mehaotian 已提交
164 165 166 167 168 169 170
  }

  .text {
    font-size: 14px;
    color: #666;
  }
</style>