index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 uni.reLaunch({
  73. url: '/pages/home/index'
  74. })
  75. } else {
  76. if (this.tabUrls.find(u => u == url)) uni.reLaunch({
  77. url
  78. });
  79. else uni.redirectTo({
  80. url
  81. });
  82. }
  83. this.$emit('goBack',url)
  84. },
  85. toHome() {
  86. uni.reLaunch({
  87. url: '/pages/home/index'
  88. })
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="less" scoped>
  94. ::v-deep .u-nav-slot {
  95. display: flex !important;
  96. }
  97. .u-navbar--fixed {
  98. z-index: 99999 !important;
  99. }
  100. .bottomBg{
  101. background: linear-gradient(to bottom,#E7F1FF,#fff);
  102. position: fixed;
  103. width: 100%;
  104. z-index: 10;
  105. top:0;
  106. }
  107. </style>