index.vue 2.0 KB

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