top-return.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view class="back" :style="{height: capsuleHeight+ 'px',top:capsuleTop+'px'}">
  3. <u-icon name="arrow-left" v-if="show === 'back'" :color="color" size="24" @click="backIconHandler"></u-icon>
  4. <u-icon name="home-fill" v-if="show === 'home'" :color="color" size="24" @click="backHomeHandler"></u-icon>
  5. <view class="back-text" :style="{color: color}">{{ text }}</view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. name: "top-return",
  11. props: {
  12. text: {
  13. type: String,
  14. default: ''
  15. },
  16. color: {
  17. type: String,
  18. default: '#303133'
  19. },
  20. show: {
  21. type: String,
  22. default: 'back'
  23. }
  24. },
  25. data() {
  26. return {
  27. //胶囊
  28. capsuleHeight: 0,
  29. capsuleTop: 0,
  30. };
  31. },
  32. created() {
  33. this.getCapsuleSite()
  34. },
  35. methods: {
  36. backIconHandler() {
  37. uni.navigateBack()
  38. },
  39. backHomeHandler() {
  40. uni.switchTab({
  41. url: '/pages/tab_home/tab_home'
  42. })
  43. },
  44. //获取胶囊位置信息
  45. getCapsuleSite() {
  46. let res = uni.getMenuButtonBoundingClientRect()
  47. this.capsuleHeight = res.height
  48. this.capsuleTop = res.top
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss">
  54. .back {
  55. position: relative;
  56. padding: 0 0 0 20rpx;
  57. display: flex;
  58. align-items: center;
  59. z-index: 999;
  60. .back-text {
  61. margin:0 0 5rpx 20rpx;
  62. font-size: 40rpx;
  63. font-weight: bold;
  64. z-index: 999;
  65. }
  66. }
  67. </style>