navbar-lite.uvue 5.1 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 22 23 24 25 26
    <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>
    <scroll-view v-if="indexView==0" class="scroll-view">
      <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 38
    <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>
    <web-view v-if="indexView==2" src="/hybrid/html/local.html" id="webv" style="height:380px"></web-view>
39
    <view style="position:relative;background-color:white;" :style="{bottom: inputBottom}">
40
      <input placeholder="滚动视图外的居底输入框" 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
        inputBottom: '0px'
M
mehaotian 已提交
57 58
      }
    },
W
wanganxp 已提交
59 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
    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)
          }
        })
100
      },
W
wanganxp 已提交
101 102
      ChangeView(e:UniRadioGroupChangeEvent){
        this.indexView = parseInt(e.detail.value)
103
      },
104
      onInputBlur(_:UniInputBlurEvent) {
105
        this.inputBottom = '0px';
106 107 108 109 110 111
      },
      onInputKeyboardChange(e:UniInputKeyboardHeightChangeEvent) {
        let inputBottom = e.target?.getBoundingClientRect()?.bottom??this.windowHeight;
        let remainHeight = this.windowHeight - inputBottom;
        let bottom = (remainHeight > e.detail.height)?0:(e.detail.height-remainHeight);
        this.inputBottom = `${bottom}px`;
W
wanganxp 已提交
112 113 114 115 116 117 118 119 120
      },
      // 自动化测试
      getLifeCycleNum() : number {
        return state.lifeCycleNum
      },
      // 自动化测试
      setLifeCycleNum(num : number) {
        setLifeCycleNum(num)
      },
121 122 123 124 125 126
    },
    onReady() {
      this.windowHeight = uni.getWindowInfo().windowHeight;
    },
    onResize() {
      this.windowHeight = uni.getWindowInfo().windowHeight;
127
    }
M
mehaotian 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  }
</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 已提交
149 150 151 152 153
  }

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

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