index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. return
  33. }
  34. },
  35. methods: {
  36. goBack() {
  37. // 如果为true是最前一页
  38. if(this.isGoBack) {
  39. this.isAndroid ? window.native.backClick() : window.webkit.messageHandlers.appGoBack.postMessage({})
  40. return
  41. }
  42. this.$router.go(-1)
  43. }
  44. }
  45. };
  46. </script>
  47. <style lang="less" scoped>
  48. .go-back{
  49. position: fixed;
  50. width: 42px;
  51. height: 42px;
  52. left: 26px;
  53. bottom: 98px;
  54. }
  55. </style>