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