navbar-lite.uvue 5.4 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 18 19 20 21
    <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>
        <radio value="1"><text>list-view</text></radio>
        <radio value="2"><text>web-view</text></radio>
      </radio-group>
    </view>
22
    <scroll-view v-if="indexView==0" class="scroll-view" :refresher-enabled="false">
W
wanganxp 已提交
23 24 25 26
      <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="备注输入框:" />
27
        </view>
W
wanganxp 已提交
28
      </view>
M
mehaotian 已提交
29
    </scroll-view>
W
wanganxp 已提交
30 31 32 33 34 35 36 37
    <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>
38 39
    <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}">
40
      <input id="input" placeholder="滚动视图外的居底输入框,不上推,手动控制输入框top" adjust-position="false" @blur="onInputBlur" @keyboardheightchange="onInputKeyboardChange" />
W
wanganxp 已提交
41 42
    </view>

M
mehaotian 已提交
43 44 45
  </view>
</template>

W
wanganxp 已提交
46
<script>
47
  import { state, setLifeCycleNum } from '@/store/index.uts'
M
mehaotian 已提交
48 49 50
  export default {
    data() {
      return {
51
        title: 'Hello uni-app',
W
wanganxp 已提交
52 53
        isLeft: false,
        navigationBarTextColor: '#000',
54
        indexView: 0,
55
        windowHeight: 0,
56
        inputRemainHeight: 0,  //输入框距离底部的距离
57
        inputBottom: '0px'
M
mehaotian 已提交
58 59
      }
    },
W
wanganxp 已提交
60 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    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)
          }
        })
101
      },
W
wanganxp 已提交
102 103
      ChangeView(e:UniRadioGroupChangeEvent){
        this.indexView = parseInt(e.detail.value)
104
      },
105
      onInputBlur(_:UniInputBlurEvent) {
106
        this.inputBottom = '0px';
107 108
      },
      onInputKeyboardChange(e:UniInputKeyboardHeightChangeEvent) {
109
        let bottom = (this.inputRemainHeight > e.detail.height)?0:(e.detail.height-this.inputRemainHeight);
110
        this.inputBottom = `${bottom}px`;
W
wanganxp 已提交
111 112 113 114 115 116 117 118 119
      },
      // 自动化测试
      getLifeCycleNum() : number {
        return state.lifeCycleNum
      },
      // 自动化测试
      setLifeCycleNum(num : number) {
        setLifeCycleNum(num)
      },
120 121
    },
    onReady() {
122
      let windowHeight = uni.getWindowInfo().windowHeight;
123
      this.inputRemainHeight = windowHeight - (uni.getElementById('input')?.getBoundingClientRect()?.bottom??windowHeight);
124 125
    },
    onResize() {
126
      let windowHeight = uni.getWindowInfo().windowHeight;
127
      this.inputRemainHeight = windowHeight - (uni.getElementById('input')?.getBoundingClientRect()?.bottom??windowHeight);
128
    }
M
mehaotian 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
  }
</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 已提交
150 151 152 153 154
  }

  .cell-item {
    display: flex;
    flex-direction: column;
M
mehaotian 已提交
155 156 157 158 159 160 161
  }

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