navbar-lite.uvue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="content">
  3. <uni-navbar-lite :status-bar="true" stat :title="title" :is-left="isLeft" :text-color="navigationBarTextColor"></uni-navbar-lite>
  4. <view class="content-item" @click="onClick">
  5. <text>点击此处,将标题切换为{{isLeft?'居中':'左侧'}}显示</text>
  6. </view>
  7. <view class="content-item" @tap="setNavigationBarColor1">
  8. <text>设置自定义导航栏前景色白色</text>
  9. </view>
  10. <view class="content-item" @tap="setNavigationBarColor2">
  11. <text>设置自定义导航栏前景色黑色</text>
  12. </view>
  13. <view style="align-items: center;height: 60px;">
  14. <text>测试输入框上推页面</text>
  15. <radio-group @change="ChangeView" style="flex-direction: row;">
  16. <radio value="0" :checked="true"><text>scroll-view</text></radio>
  17. <radio value="1"><text>list-view</text></radio>
  18. <!-- #ifndef MP -->
  19. <radio value="2"><text>web-view</text></radio>
  20. <!-- #endif -->
  21. </radio-group>
  22. </view>
  23. <scroll-view v-if="indexView==0" class="scroll-view" :scroll-y="true" :refresher-enabled="false">
  24. <view class="content-item" v-for="item in 10">
  25. <view class="cell-item">
  26. <text class="text">内容:{{item}}</text>
  27. <input class="text" style="margin-top: 8px;" placeholder="备注输入框:" />
  28. </view>
  29. </view>
  30. </scroll-view>
  31. <list-view v-if="indexView==1" class="scroll-view">
  32. <list-item class="content-item" v-for="item in 10">
  33. <view class="cell-item">
  34. <text class="text">列表项内容:{{item}}</text>
  35. <input class="text" style="margin-top: 8px;" placeholder="备注输入框:" />
  36. </view>
  37. </list-item>
  38. </list-view>
  39. <web-view v-if="indexView==2" src="/hybrid/html/local.html" id="webv" class="scroll-view"></web-view>
  40. <view class="bottomInput" :style="{bottom: inputBottom}">
  41. <input id="input" style="background-color: white;" placeholder="滚动视图外底部输入框,焦点时手动控制显示位置" :adjust-position="false" @blur="onInputBlur" @keyboardheightchange="onInputKeyboardChange" />
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import { state, setLifeCycleNum } from '@/store/index.uts'
  47. export default {
  48. data() {
  49. return {
  50. title: 'Hello uni-app',
  51. isLeft: false,
  52. navigationBarTextColor: '#000',
  53. indexView: 0,
  54. inputBottom: '0px'
  55. }
  56. },
  57. methods: {
  58. onClick() {
  59. this.isLeft = !this.isLeft
  60. },
  61. setNavigationBarColor1() {
  62. uni.setNavigationBarColor({
  63. frontColor: '#ffffff',
  64. backgroundColor: '#0000',
  65. success: () => {
  66. this.navigationBarTextColor = '#fff'
  67. console.log('setNavigationBarColor success')
  68. this.setLifeCycleNum(state.lifeCycleNum + 1)
  69. },
  70. fail: () => {
  71. console.log('setNavigationBarColor fail')
  72. this.setLifeCycleNum(state.lifeCycleNum - 1)
  73. },
  74. complete: () => {
  75. console.log('setNavigationBarColor complete')
  76. this.setLifeCycleNum(state.lifeCycleNum + 1)
  77. }
  78. })
  79. },
  80. setNavigationBarColor2() {
  81. uni.setNavigationBarColor({
  82. frontColor: '#000000',
  83. backgroundColor: '#0000',
  84. success: () => {
  85. this.navigationBarTextColor = '#000'
  86. console.log('setNavigationBarColor success')
  87. this.setLifeCycleNum(state.lifeCycleNum + 1)
  88. },
  89. fail: () => {
  90. console.log('setNavigationBarColor fail')
  91. this.setLifeCycleNum(state.lifeCycleNum - 1)
  92. },
  93. complete: () => {
  94. console.log('setNavigationBarColor complete')
  95. this.setLifeCycleNum(state.lifeCycleNum + 1)
  96. }
  97. })
  98. },
  99. ChangeView(e:UniRadioGroupChangeEvent){
  100. this.indexView = parseInt(e.detail.value)
  101. },
  102. onInputBlur(_:UniInputBlurEvent) {
  103. this.inputBottom = '0px';
  104. },
  105. onInputKeyboardChange(e:UniInputKeyboardHeightChangeEvent) {
  106. let height = e.detail.height;
  107. // #ifdef APP-IOS
  108. if(height>0){ //iOS平台软键盘的高度已经包含了安全区域高度,这里需要减掉
  109. height -= this.$page.safeAreaInsets.bottom;
  110. }
  111. // #endif
  112. this.inputBottom = `${height}px`;
  113. },
  114. // 自动化测试
  115. getLifeCycleNum() : number {
  116. return state.lifeCycleNum
  117. },
  118. // 自动化测试
  119. setLifeCycleNum(num : number) {
  120. setLifeCycleNum(num)
  121. }
  122. },
  123. onReady() {
  124. },
  125. onResize() {
  126. }
  127. }
  128. </script>
  129. <style>
  130. .content {
  131. display: flex;
  132. flex-direction: column;
  133. flex: 1;
  134. }
  135. .scroll-view {
  136. flex: 1;
  137. background-color: #f5f5f5;
  138. padding: 5px 0;
  139. }
  140. .content-item {
  141. padding: 15px;
  142. margin: 5px 10px;
  143. background-color: #fff;
  144. border-radius: 5px;
  145. }
  146. .cell-item {
  147. display: flex;
  148. flex-direction: column;
  149. }
  150. .text {
  151. font-size: 14px;
  152. color: #666;
  153. }
  154. .bottomInput {
  155. position: relative;
  156. z-index: 1000;
  157. padding: 0 5px;
  158. margin-bottom: var(--uni-safe-area-inset-bottom);
  159. }
  160. </style>