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. interceptBack:{
  47. type:Boolean,
  48. default:false
  49. }
  50. },
  51. data() {
  52. return {
  53. tabUrls: [
  54. '/pages/home',
  55. '/pages/my'
  56. ]
  57. }
  58. },
  59. methods: {
  60. toBack(url) {
  61. if(this.interceptBack){
  62. this.$emit('back')
  63. return
  64. }
  65. if(this.backAlert){
  66. uni.showModal({
  67. title:'温馨提示',
  68. content:'您正在填写问卷中,系统仅保留当前问卷的作答进度,是否确认返回?',
  69. success: (res) => {
  70. if(res.confirm){
  71. this.dealBack(url)
  72. }
  73. }
  74. })
  75. }else this.dealBack(url)
  76. },
  77. dealBack(url){
  78. if (!url) {
  79. if (uni.getStorageSync('options')) {
  80. uni.redirectTo(JSON.parse(decodeURIComponent(uni.getStorageSync('options'))));
  81. return uni.removeStorageSync('options');
  82. }
  83. let canNavBack = getCurrentPages();
  84. if (canNavBack && canNavBack.length > 1) uni.navigateBack();
  85. else uni.reLaunch({
  86. url: '/pages/home'
  87. })
  88. } else {
  89. if (this.tabUrls.find(u => u == url)) uni.reLaunch({
  90. url
  91. });
  92. else uni.redirectTo({
  93. url
  94. });
  95. }
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="less" scoped>
  101. .u-navbar--fixed {
  102. z-index: 99999 !important;
  103. }
  104. </style>