index.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="layout">
  3. <slot></slot>
  4. <img src="@/assets/image/goBack-cion.png" alt="" class="go-back" @click="goBack" v-if="visible">
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'layout',
  10. props: {
  11. isGoBack: {
  12. type: Boolean,
  13. default: false
  14. }
  15. },
  16. data() {
  17. return {
  18. visible: true,
  19. isApp: null,
  20. isAndroid: null
  21. };
  22. },
  23. mounted() {
  24. // 如果是安卓的需要判断一下是否显示h5内置的返回按钮
  25. // 如果是H5、微信小程序,不需要显示次按钮
  26. // 如果是苹果就显示,不需要做任何处理
  27. this.isApp = this.$userAgent.isSzx || this.$userAgent.isSzxBrowser
  28. this.isAndroid = this.$userAgent.isAndroid;
  29. if (!this.isApp) return this.visible = false
  30. if (this.isApp && this.isAndroid) {
  31. this.visible = !!window.native.goneBack
  32. this.visible && window.native.goneBack()
  33. return
  34. }
  35. },
  36. methods: {
  37. goBack() {
  38. // 如果为true是最前一页
  39. if (this.isGoBack) {
  40. this.isAndroid ? window.native.backClick() : window.webkit.messageHandlers.appGoBack.postMessage({})
  41. return
  42. }
  43. this.$router.go(-1)
  44. }
  45. }
  46. };
  47. </script>
  48. <style lang="less" scoped>
  49. .layout {
  50. height: 100%;
  51. }
  52. .go-back {
  53. position: fixed;
  54. width: 42px;
  55. height: 42px;
  56. left: 26px;
  57. bottom: 98px;
  58. }
  59. </style>