index.vue 1.9 KB

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