index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. },
  80. toHome() {
  81. uni.reLaunch({
  82. url: '/pages/home/index'
  83. })
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="less" scoped>
  89. ::v-deep .u-nav-slot {
  90. display: flex !important;
  91. }
  92. .u-navbar--fixed {
  93. z-index: 99999 !important;
  94. }
  95. </style>