index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="">
  3. <u-navbar title-color="#fff" back-icon-color="#ffffff"
  4. :is-fixed="isFixed" :is-back="isBack"
  5. :background="background"
  6. :back-text-style="{color: '#fff'}" :title="title"
  7. :back-icon-name="backIconName" :back-text="backText"
  8. >
  9. <view class="slot-wrap" v-if="useSlot">
  10. <view class="search-wrap" v-if="search">
  11. <!-- 如果使用u-search组件,必须要给v-model绑定一个变量 -->
  12. <u-search v-model="keyword" :show-action="showAction" height="56" :action-style="{color: '#fff'}"></u-search>
  13. </view>
  14. <view class="navbar-right" v-if="rightSlot">
  15. <view class="message-box right-item">
  16. <u-icon name="chat" size="38"></u-icon>
  17. <u-badge count="18" size="mini" :offset="[-15, -15]"></u-badge>
  18. </view>
  19. <view class="dot-box right-item">
  20. <u-icon name="calendar-fill" size="38"></u-icon>
  21. <u-badge size="mini" :is-dot="true" :offset="[-6, -6]"></u-badge>
  22. </view>
  23. </view>
  24. <view class="map-wrap" v-if="custom">
  25. <u-icon name="map" color="#ffffff" size="24"></u-icon>
  26. <text class="map-wrap-text">轻舟已过万重山</text>
  27. <u-icon name="arrow-down-fill" color="#ffffff" size="22"></u-icon>
  28. </view>
  29. </view>
  30. <view class="navbar-right" slot="right" v-if="slotRight">
  31. <view class="message-box right-item">
  32. <u-icon name="chat" size="38"></u-icon>
  33. <u-badge count="18" size="mini" :offset="[-15, -15]"></u-badge>
  34. </view>
  35. <view class="dot-box right-item">
  36. <u-icon name="calendar-fill" size="38"></u-icon>
  37. <u-badge size="mini" :is-dot="true" :offset="[-6, -6]"></u-badge>
  38. </view>
  39. </view>
  40. </u-navbar>
  41. <view class="u-demo">
  42. <view class="u-demo-wrap">
  43. <view class="u-demo-title">演示效果</view>
  44. <view class="u-demo-area">
  45. <u-toast ref="uToast"></u-toast>
  46. <view class="u-no-demo-here">查看顶部导航栏效果</view>
  47. </view>
  48. </view>
  49. <view class="u-config-wrap">
  50. <view class="u-config-title u-border-bottom">
  51. 参数配置
  52. </view>
  53. <view class="u-config-item">
  54. <view class="u-item-title">标题长度</view>
  55. <u-subsection :list="['短', '中', '长']" @change="titleChange"></u-subsection>
  56. </view>
  57. <view class="u-config-item">
  58. <view class="u-item-title">隐藏左侧返回区域</view>
  59. <u-subsection current="1" :list="['是', '否']" @change="backChange"></u-subsection>
  60. </view>
  61. <view class="u-config-item">
  62. <view class="u-item-title">自定义左侧内容</view>
  63. <u-subsection current="1" :list="['是', '否']" @change="leftChange"></u-subsection>
  64. </view>
  65. <view class="u-config-item">
  66. <view class="u-item-title">自定义右侧内容</view>
  67. <u-subsection :current="slotRightCurrent" :list="['是', '否']" @change="rightChange"></u-subsection>
  68. </view>
  69. <view class="u-config-item">
  70. <view class="u-item-title">传入整体slot</view>
  71. <u-subsection :list="['无', '搜索框', '搜索+按钮', '搜索+图标']" @change="searchChange"></u-subsection>
  72. </view>
  73. <view class="u-config-item">
  74. <view class="u-item-title">完全自定义传入内容</view>
  75. <u-subsection current="1" :list="['是', '否']" @change="customChange"></u-subsection>
  76. </view>
  77. <view class="u-config-item">
  78. <view class="u-item-title">背景色</view>
  79. <u-subsection :list="['渐变', '#39CCCC', '#B471CC', '#001f3f']" @change="bgColorChange"></u-subsection>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <script>
  86. export default {
  87. data() {
  88. return {
  89. title: '新闻',
  90. backText: '返回',
  91. backIconName: 'nav-back',
  92. right: false,
  93. showAction: false,
  94. rightSlot: false,
  95. useSlot: false,
  96. background: {
  97. 'background-image': 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
  98. },
  99. isBack: true,
  100. search: false,
  101. custom: false,
  102. isFixed: true,
  103. keyword: '',
  104. // #ifdef MP
  105. slotRight: false,
  106. // #endif
  107. // #ifndef MP
  108. slotRight: true
  109. // #endif
  110. }
  111. },
  112. computed: {
  113. slotRightCurrent() {
  114. return this.slotRight ? 0 : 1;
  115. }
  116. },
  117. methods: {
  118. titleChange(index) {
  119. this.useSlot = false;
  120. this.title = index == 0 ? '新闻' : index == 1 ? '新闻列表' : '雨打梨花深闭门,忘了青春,误了青春';
  121. },
  122. leftChange(index) {
  123. if(index == 0) {
  124. this.backText = '';
  125. this.backIconName = 'arrow-leftward';
  126. } else {
  127. this.backText = '返回';
  128. this.backIconName = 'arrow-left';
  129. }
  130. },
  131. searchChange(index) {
  132. this.title = null;
  133. this.useSlot = true;
  134. this.search = false;
  135. this.custom = false;
  136. if(index == 0) {
  137. this.title = '新闻';
  138. this.useSlot = false;
  139. this.rightSlot = false;
  140. } else if(index == 1) {
  141. this.showAction = false;
  142. this.useSlot = true;
  143. this.rightSlot = false;
  144. this.search = true;
  145. this.slotRight = false;
  146. } else if(index == 2) {
  147. this.useSlot = true;
  148. this.showAction = true;
  149. this.rightSlot = false;
  150. this.search = true;
  151. this.slotRight = false;
  152. } else {
  153. this.useSlot = true;
  154. this.search = true;
  155. this.showAction = false;
  156. this.rightSlot = true;
  157. this.slotRight = false;
  158. }
  159. },
  160. backChange(index) {
  161. this.isBack = !!index;
  162. },
  163. bgColorChange(index) {
  164. this.background = {};
  165. if(index == 0) {
  166. this.background = {
  167. 'background-image': 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
  168. }
  169. } else {
  170. let color = index == 1 ? '#39CCCC' : index == 2 ? '#B471CC' : '#001f3f';
  171. this.background = {
  172. background: color
  173. }
  174. }
  175. },
  176. rightChange(index) {
  177. if(index == 0) {
  178. this.slotRight = true;
  179. this.useSlot = false;
  180. } else {
  181. this.slotRight = false;
  182. }
  183. },
  184. customChange(index) {
  185. this.search = false;
  186. this.rightSlot = false;
  187. if(index == 0) {
  188. this.custom = true;
  189. this.title = null;
  190. this.isBack = false;
  191. this.useSlot = true;
  192. } else {
  193. this.useSlot = false;
  194. this.title = '新闻';
  195. this.isBack = true;
  196. }
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .u-demo {
  203. //height: 200vh;
  204. height: calc(100% - 44px);
  205. height: calc(100% - 44px - constant(safe-area-inset-top));
  206. height: calc(100% - 44px - env(safe-area-inset-top));
  207. }
  208. .wrap {
  209. padding: 24rpx;
  210. }
  211. .navbar-right {
  212. margin-right: 24rpx;
  213. display: flex;
  214. }
  215. .search-wrap {
  216. margin: 0 20rpx;
  217. flex: 1;
  218. }
  219. .right-item {
  220. margin: 0 12rpx;
  221. position: relative;
  222. color: #ffffff;
  223. display: flex;
  224. }
  225. .message-box {
  226. }
  227. .slot-wrap {
  228. display: flex;
  229. align-items: center;
  230. flex: 1;
  231. }
  232. .map-wrap {
  233. display: flex;
  234. align-items: center;
  235. padding: 4px 6px;
  236. background-color: rgba(240,240, 240, 0.35);
  237. color: #fff;
  238. font-size: 22rpx;
  239. border-radius: 100rpx;
  240. margin-left: 30rpx;
  241. }
  242. .map-wrap-text {
  243. padding: 0 6rpx;
  244. }
  245. </style>