layout.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="layout" :class="{'layout-white': !false}">
  3. <div style="height: 12.2666666667vw">
  4. <van-nav-bar :title="title" left-arrow fixed @click-left="goBackFun">
  5. <template #right>
  6. <slot name="right"></slot>
  7. </template>
  8. </van-nav-bar>
  9. </div>
  10. <div class="layout-container" :style="containerStyle">
  11. <slot></slot>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name: 'layout',
  18. props: {
  19. // 是否显示头部
  20. title: {
  21. type: String,
  22. default: '邀请好友得现金',
  23. },
  24. padding: {
  25. type: String,
  26. default: '16px'
  27. },
  28. background: {
  29. type: String,
  30. default: '#F2F4F7'
  31. },
  32. // 用于内嵌页面,标识为最后一页
  33. isGoBack: {
  34. type: Boolean,
  35. default: false
  36. }
  37. },
  38. data() {
  39. return {
  40. isApp: null,
  41. isAndroid: null,
  42. isIos: null,
  43. };
  44. },
  45. mounted() {
  46. // 判断是否是App, 活动页app不显示头部,直接使用H5头部
  47. this.isApp = this.$userAgent.isSzx || this.$userAgent.isSzxBrowser
  48. this.isAndroid = this.$userAgent.isAndroid;
  49. this.isIos = this.$userAgent.isIos;
  50. // 安卓隐藏返回按钮
  51. if (this.isApp && this.isAndroid && !!window.native.goneBack) {
  52. window.native.goneBack() // 安卓隐藏返回按钮
  53. }
  54. },
  55. computed: {
  56. containerStyle() {
  57. return { background: this.background, padding: this.padding};
  58. },
  59. isShowApp() {
  60. // 是否是APP
  61. const isApp = this.$userAgent.isSzx || this.$userAgent.isSzxBrowser;
  62. const isAndroid = this.$userAgent.isAndroid;
  63. const isIos = this.$userAgent.isIos;
  64. const isWx = this.$userAgent.isWx;
  65. console.log('isApp:' + isApp)
  66. console.log('isAndroid:' + isAndroid)
  67. console.log('isIos:' + isIos)
  68. console.log('isWx:' + isWx)
  69. // 如果是App并且是安卓,就不显示头部, ios显示
  70. // 如果微信小程序环境的,也不显示头部
  71. // 如果是h5 就显示头部
  72. let bool = false;
  73. bool = isApp && (isAndroid || isIos) ? true : false;
  74. return bool;
  75. },
  76. },
  77. methods: {
  78. goBackFun() {
  79. if (this?.$listeners?.goBack) {
  80. this.$emit('goBack');
  81. return;
  82. }
  83. // 如果为true是最前一页
  84. if (this.isGoBack) {
  85. if(this.isApp && this.isAndroid) {
  86. return window.native.backClick();
  87. }else if(this.isApp && this.isIos) {
  88. return window.webkit.messageHandlers.appGoBack.postMessage({});
  89. }
  90. }
  91. // 浏览器返回上一页
  92. this.$router.go(-1);
  93. },
  94. },
  95. };
  96. </script>
  97. <style lang="less" scoped>
  98. .layout {
  99. height: 100%;
  100. display: flex;
  101. flex-direction: column;
  102. .layout-container {
  103. flex: 1;
  104. overflow-y: auto;
  105. }
  106. ::v-deep .van-nav-bar__arrow {
  107. color: #000000;
  108. font-size: 24px;
  109. }
  110. ::v-deep .van-nav-bar__title {
  111. font-weight: bold !important;
  112. font-size: 17px !important;
  113. color: #0a132b !important;
  114. line-height: 24px !important;
  115. }
  116. .van-nav-bar {
  117. z-index: 0;
  118. }
  119. .floating-back {
  120. position: fixed; /* 设定定位为固定 */
  121. left: 26px; /* 距离右侧10像素 */
  122. bottom: 98px; /* 距离底部10像素 */
  123. background-color: transparent; /* 背景颜色 */
  124. z-index: 1000; /* 确保悬浮在其他内容之上 */
  125. }
  126. }
  127. .layout-white {
  128. .van-nav-bar {
  129. background-color: #f2f4f7;
  130. }
  131. ::v-deep [class*='van-hairline']::after {
  132. border: 0px;
  133. }
  134. }
  135. </style>