top-return.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="back" :style="{height: capsuleHeight+ 'px',top:capsuleTop+'px'}">
  3. <view v-if="!refresh">
  4. <u-icon name="arrow-left" v-if="show === 'back'" :color="color" size="24" @click="backIconHandler"></u-icon>
  5. <u-icon name="home-fill" v-if="show === 'home'" :color="color" size="24" @click="backHomeHandler"></u-icon>
  6. </view>
  7. <view v-if="refresh">
  8. <u-icon name="arrow-left" v-if="show === 'back'" :color="color" size="24" @click="backIconHandlerRefresh"></u-icon>
  9. <u-icon name="home-fill" v-if="show === 'home'" :color="color" size="24" @click="backIconHandlerRefresh"></u-icon>
  10. </view>
  11. <view class="back-text" :style="{color: color}">{{ text }}</view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. name: "top-return",
  17. props: {
  18. text: {
  19. type: String,
  20. default: ''
  21. },
  22. color: {
  23. type: String,
  24. default: '#303133'
  25. },
  26. show: {
  27. type: String,
  28. default: 'back'
  29. },
  30. refresh: {
  31. type: Boolean,
  32. default: false
  33. }
  34. },
  35. data() {
  36. return {
  37. //胶囊
  38. capsuleHeight: 0,
  39. capsuleTop: 0,
  40. };
  41. },
  42. created() {
  43. this.getCapsuleSite()
  44. },
  45. methods: {
  46. backIconHandler() {
  47. uni.navigateBack()
  48. },
  49. backIconHandlerRefresh() {
  50. let pages = getCurrentPages(); // 当前页面
  51. let beforePage = pages[pages.length - 2]; // 上一页
  52. uni.navigateBack({
  53. success: function() {
  54. beforePage.onLoad()// 执行上一页的onLoad方法
  55. }
  56. })
  57. },
  58. backHomeHandler() {
  59. uni.switchTab({
  60. url: '/pages/tab_home/tab_home'
  61. })
  62. },
  63. //获取胶囊位置信息
  64. getCapsuleSite() {
  65. let res = uni.getMenuButtonBoundingClientRect()
  66. this.capsuleHeight = res.height
  67. this.capsuleTop = res.top
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss">
  73. .back {
  74. position: relative;
  75. padding: 0 0 0 20rpx;
  76. display: flex;
  77. align-items: center;
  78. z-index: 999;
  79. .back-text {
  80. margin:0 0 5rpx 20rpx;
  81. font-size: 40rpx;
  82. font-weight: bold;
  83. z-index: 999;
  84. }
  85. }
  86. </style>