index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <u-navbar :title="title" :bgColor="bgColor" :titleStyle="titleStyle">
  3. <view class="u-nav-slot" slot="left" style="display: flex;background-color: transparent;">
  4. <u-icon v-if="showback" name="arrow-left" size="44" :color="leftIconColor" @tap="toBack(backUrl)"></u-icon>
  5. </view>
  6. </u-navbar>
  7. </template>
  8. <script>
  9. export default {
  10. options: {
  11. styleIsolation: 'shared'
  12. },
  13. props: {
  14. title: {
  15. typeof: String,
  16. default: ''
  17. },
  18. showback: {
  19. typeof: Boolean,
  20. default: true
  21. },
  22. backUrl: {
  23. typeof: String,
  24. default: ''
  25. },
  26. bgColor: {
  27. typeof: String,
  28. default: '#ffffff'
  29. },
  30. leftIconColor: {
  31. typeof: String,
  32. default: '#111111'
  33. },
  34. titleStyle: {
  35. typeof: Object,
  36. default: {
  37. fontSize: '36rpx',
  38. fontWeight: "bold",
  39. color: '#111111'
  40. }
  41. },
  42. backAlert:{
  43. typeof:Boolean,
  44. default:false
  45. }
  46. },
  47. data() {
  48. return {
  49. tabUrls: [
  50. '/pages/index/index',
  51. '/pages/touristMap/index',
  52. '/pages/oneCodePass/index',
  53. '/pages/service/index',
  54. '/pages/my/index'
  55. ]
  56. }
  57. },
  58. methods: {
  59. toBack(url) {
  60. if(this.backAlert){
  61. uni.reLaunch({
  62. url: '/pages/home'
  63. })
  64. }else this.dealBack(url)
  65. },
  66. dealBack(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 uni.reLaunch({
  75. url: '/pages/index/index'
  76. })
  77. } else {
  78. if (this.tabUrls.find(u => u == url)) uni.reLaunch({
  79. url
  80. });
  81. else uni.redirectTo({
  82. url
  83. });
  84. }
  85. },
  86. toHome() {
  87. uni.reLaunch({
  88. url: '/pages/index/index'
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="less" scoped>
  95. .u-navbar--fixed {
  96. z-index: 99999 !important;
  97. }
  98. </style>