推拿小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
2.8 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <template>
  2. <!-- <view class="navbar"
  3. :style="{backgroundColor : bgColor}"> -->
  4. <!-- #ifdef MP-WEIXIN -->
  5. <view class="title nav-bar__view"
  6. :style="{backgroundColor : bgColor,color}">
  7. <view class="left">
  8. <uv-icon name="home"
  9. v-if="leftClick && length == 1"
  10. @click="toHome"
  11. :color="color" size="46rpx"></uv-icon>
  12. <uv-icon name="arrow-left"
  13. v-else-if="leftClick"
  14. @click="$emit('leftClick')"
  15. :color="color" size="46rpx"></uv-icon>
  16. </view>
  17. <view>{{ title }}</view>
  18. <view class="icon">
  19. <uv-icon name="search"
  20. v-if="isSearch"
  21. :color="color" size="58rpx"></uv-icon>
  22. <uv-icon name="plus-circle" :color="color"
  23. v-if="isPlus"
  24. @click="plusCircleShow = true"
  25. size="46rpx" style="margin-left: 30rpx;"></uv-icon>
  26. <view v-if="moreClick" style="margin-left: 30rpx;">
  27. <uv-icon name="more-dot-fill" :color="color"
  28. v-if="!moreText"
  29. @click="moreClick()"
  30. size="46rpx"></uv-icon>
  31. <view v-else @click="moreClick"
  32. style="font-weight: 400;font-size: 30rpx;">
  33. {{ moreText }}
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- #endif -->
  39. <!-- </view> -->
  40. </template>
  41. <script>
  42. export default {
  43. name:"navbar",
  44. props : {
  45. title : {
  46. type : String,
  47. default : ''
  48. },
  49. leftClick : {
  50. type : Boolean,
  51. },
  52. moreClick : {
  53. type : Function,
  54. },
  55. isSearch : {
  56. type : Boolean,
  57. default : false,
  58. },
  59. isPlus : {
  60. type : Boolean,
  61. default : false,
  62. },
  63. moreText : {
  64. },
  65. bgColor : {
  66. default : '#fff'
  67. },
  68. color : {
  69. default : '#333'
  70. }
  71. },
  72. created() {
  73. if(typeof document != 'undefined'){
  74. document.title = this.title
  75. }
  76. },
  77. beforeDestroy() {
  78. },
  79. data() {
  80. return {
  81. length : this.getPageLength()
  82. };
  83. },
  84. methods : {
  85. getPageLength() {
  86. try {
  87. const pages = getCurrentPages();
  88. return pages ? pages.length : 1;
  89. } catch(e) {
  90. // H5 环境下可能获取失败,默认返回 1
  91. console.warn('获取页面栈长度失败:', e);
  92. return 1;
  93. }
  94. },
  95. toHome(){
  96. if(this.length != 1){
  97. return
  98. }
  99. uni.reLaunch({
  100. url: '/pages/index/index'
  101. })
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. // .navbar{
  108. // width: 100%;
  109. // height: 120rpx;
  110. // padding-top: var(--status-bar-height);
  111. // }
  112. .title{
  113. position: sticky;
  114. top: 0;
  115. left: 0;
  116. padding-top: calc(var(--status-bar-height) + 20rpx);
  117. width: 100%;
  118. height: $navbar-height;
  119. background-color: #fff;
  120. display: flex;
  121. justify-content: center;
  122. font-size: 32rpx;
  123. align-items: center;
  124. z-index: 999;
  125. .left{
  126. position: absolute;
  127. left: 40rpx;
  128. display: flex;
  129. justify-content: flex-start;
  130. }
  131. .icon{
  132. position: absolute;
  133. right: 40rpx;
  134. display: flex;
  135. justify-content: flex-end;
  136. }
  137. }
  138. @keyframes fade-in {
  139. 0% {
  140. opacity: 0;
  141. }
  142. 100% {
  143. opacity: 1;
  144. }
  145. }
  146. </style>