index.vue 2.7 KB

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