index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.showModal({
  62. title:'温馨提示',
  63. content:'您当前正在填写问卷,返回会清空作答进度,是否确认返回?',
  64. success: (res) => {
  65. if(res.confirm){
  66. this.dealBack(url)
  67. }
  68. }
  69. })
  70. }else this.dealBack(url)
  71. },
  72. dealBack(url){
  73. if (!url) {
  74. if (uni.getStorageSync('options')) {
  75. uni.redirectTo(JSON.parse(decodeURIComponent(uni.getStorageSync('options'))));
  76. return uni.removeStorageSync('options');
  77. }
  78. let canNavBack = getCurrentPages();
  79. if (canNavBack && canNavBack.length > 1) uni.navigateBack();
  80. else uni.reLaunch({
  81. url: '/pages/index/index'
  82. })
  83. } else {
  84. if (this.tabUrls.find(u => u == url)) uni.reLaunch({
  85. url
  86. });
  87. else uni.redirectTo({
  88. url
  89. });
  90. }
  91. },
  92. toHome() {
  93. uni.reLaunch({
  94. url: '/pages/index/index'
  95. })
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="less" scoped>
  101. .u-navbar--fixed {
  102. z-index: 99999 !important;
  103. }
  104. </style>