navbar-lite.uvue 4.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 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 39 40 41 42
    <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>
    <view style="position: relative;bottom: 0;">
      <input placeholder="滚动视图外的居底输入框" adjust-position="true" />
    </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 54
        isLeft: false,
        navigationBarTextColor: '#000',
        indexView: 0
M
mehaotian 已提交
55 56
      }
    },
W
wanganxp 已提交
57 58 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
    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)
          }
        })
98
      },
W
wanganxp 已提交
99 100 101 102 103 104 105 106 107 108 109
      ChangeView(e:UniRadioGroupChangeEvent){
        this.indexView = parseInt(e.detail.value)
      },
      // 自动化测试
      getLifeCycleNum() : number {
        return state.lifeCycleNum
      },
      // 自动化测试
      setLifeCycleNum(num : number) {
        setLifeCycleNum(num)
      },
110
    }
M
mehaotian 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  }
</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 已提交
132 133 134 135 136
  }

  .cell-item {
    display: flex;
    flex-direction: column;
M
mehaotian 已提交
137 138 139 140 141 142 143
  }

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