index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view>
  3. <u-navbar :title="title" :bgColor="bgColor" :titleStyle="titleStyle">
  4. <view class="u-nav-slot" slot="left" style="display: flex;">
  5. <u-icon v-if="showIcon" name="arrow-left" size="44" :color="leftIconColor" @tap="toBack(backUrl)"></u-icon>
  6. <u-line v-if="showHome&&showIcon" direction="column" :hairline="false" length="0" margin="0 15rpx"></u-line>
  7. <u-icon v-if="showHome&&showIcon" name="home" size="48" :color="leftIconColor" @tap="toHome"></u-icon>
  8. </view>
  9. </u-navbar>
  10. <!-- 底部渐变色 -->
  11. <view class="bottomBg" :style="{'height':mt+'px'}" v-if="bgColor=='transparent'"></view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. options: {
  17. styleIsolation: 'shared'
  18. },
  19. props: {
  20. title: {
  21. typeof: String,
  22. default: ''
  23. },
  24. showIcon: {
  25. typeof: Boolean,
  26. default: true
  27. },
  28. showHome: {
  29. typeof: Boolean,
  30. default: true
  31. },
  32. backUrl: {
  33. typeof: String,
  34. default: ''
  35. },
  36. bgColor: {
  37. typeof: String,
  38. default: '#ffffff'
  39. },
  40. leftIconColor: {
  41. typeof: String,
  42. default: '#111111'
  43. },
  44. titleStyle: {
  45. typeof: Object,
  46. default: {
  47. fontSize: '34rpx',
  48. fontWeight: "bold",
  49. color: '#111111'
  50. }
  51. },
  52. },
  53. data() {
  54. return {
  55. tabUrls: [
  56. '/pages/home/index',
  57. '/pages/house/index',
  58. '/pages/statistics/index',
  59. '/pages/my/index'
  60. ]
  61. }
  62. },
  63. methods: {
  64. toBack(url) {
  65. if (!url) {
  66. if (uni.getStorageSync('options')) {
  67. uni.redirectTo(JSON.parse(decodeURIComponent(uni.getStorageSync('options'))));
  68. return uni.removeStorageSync('options');
  69. }
  70. let canNavBack = getCurrentPages();
  71. if (canNavBack && canNavBack.length > 1) uni.navigateBack();
  72. else{
  73. if(uni.getStorageSync('homestayId')==''){
  74. uni.reLaunch({
  75. url: '/pagesHouse/home/index'
  76. })
  77. }else{
  78. uni.reLaunch({
  79. url: '/pages/home/index'
  80. })
  81. }
  82. }
  83. } else {
  84. if (this.tabUrls.find(u => u == url)) uni.reLaunch({
  85. url
  86. });
  87. else uni.redirectTo({
  88. url
  89. });
  90. }
  91. this.$emit('goBack',url)
  92. },
  93. toHome() {
  94. if(uni.getStorageSync('homestayId')==''){
  95. uni.reLaunch({
  96. url: '/pagesHouse/home/index'
  97. })
  98. }else{
  99. uni.reLaunch({
  100. url: '/pages/home/index'
  101. })
  102. }
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="less" scoped>
  108. ::v-deep .u-nav-slot {
  109. display: flex !important;
  110. }
  111. .u-navbar--fixed {
  112. z-index: 99999 !important;
  113. }
  114. .bottomBg{
  115. background: linear-gradient(to bottom,#E7F1FF,#fff);
  116. position: fixed;
  117. width: 100%;
  118. z-index: 10;
  119. top:0;
  120. }
  121. </style>