layout.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="layout" :class="{'layout-white': !false}">
  3. <div style="height: 12.2666666667vw" v-if="isShowNavBar">
  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. // 是否强制像是头部
  25. forceShowNavBar: {
  26. type: Boolean,
  27. default: false
  28. },
  29. padding: {
  30. type: String,
  31. default: '16px'
  32. },
  33. background: {
  34. type: String,
  35. default: '#F2F4F7'
  36. },
  37. isRouterBack: {
  38. type: Boolean,
  39. default: false
  40. },
  41. // 用于内嵌页面,标识为最后一页
  42. isGoBack: {
  43. type: Boolean,
  44. default: false
  45. }
  46. },
  47. data() {
  48. return {
  49. isApp: null,
  50. isAndroid: null,
  51. };
  52. },
  53. mounted() {
  54. // 如果是安卓的需要判断一下是否显示h5内置的返回按钮
  55. // 如果是H5、微信小程序,不需要显示次按钮
  56. this.isApp = this.$userAgent.isSzx || this.$userAgent.isSzxBrowser
  57. this.isAndroid = this.$userAgent.isAndroid;
  58. // if (!this.isApp) return this.visible = false
  59. // if (this.isApp && this.isAndroid) {
  60. // this.visible = !!window.native.goneBack
  61. // // 判断是否有注册goneBack方法,有就调用
  62. // if(!!window.native.goneBack){
  63. // console.log('this.visible', this.visible)
  64. // window.native.goneBack() // 安卓隐藏返回按钮
  65. // }
  66. // }
  67. },
  68. computed: {
  69. containerStyle() {
  70. return { background: this.background, padding: this.padding};
  71. },
  72. isShowApp() {
  73. // 是否是APP
  74. const isApp = this.$userAgent.isSzx || this.$userAgent.isSzxBrowser;
  75. const isAndroid = this.$userAgent.isAndroid;
  76. const isIos = this.$userAgent.isIos;
  77. const isWx = this.$userAgent.isWx;
  78. console.log('isApp:' + isApp)
  79. console.log('isAndroid:' + isAndroid)
  80. console.log('isIos:' + isIos)
  81. console.log('isWx:' + isWx)
  82. // 如果是App并且是安卓,就不显示头部, ios显示
  83. // 如果微信小程序环境的,也不显示头部
  84. // 如果是h5 就显示头部
  85. let bool = false;
  86. bool = isApp && (isAndroid || isIos) ? true : false;
  87. return bool;
  88. },
  89. isShowNavBar() {
  90. // 是否是APP
  91. const isApp = this.isApp;
  92. const isAndroid = this.isAndroid;
  93. const isIos = this.$userAgent.isIos;
  94. const isWx = this.$userAgent.isWx;
  95. // 如果是App并且是安卓,就不显示头部, ios显示
  96. // 如果微信小程序环境的,也不显示头部
  97. // 如果是h5 就显示头部
  98. let bool = false;
  99. // bool = isApp ? (isAndroid ? !isAndroid : isIos) : (isWx ? !isWx : !isWx);
  100. bool = (isApp && (isAndroid || !isIos)) || isWx ? false : true;
  101. // bool = isWx ? false : true;
  102. return bool || this.forceShowNavBar;
  103. },
  104. },
  105. methods: {
  106. goBackFun() {
  107. if (this.$listeners.goBack) {
  108. this.$emit('goBack');
  109. return;
  110. }
  111. // 如果为true是最前一页
  112. if (this.isGoBack) {
  113. this.isAndroid ? window.native.backClick() : window.webkit.messageHandlers.appGoBack.postMessage({})
  114. return
  115. }
  116. this.$router.go(-1)
  117. },// 退出相关逻辑
  118. },
  119. };
  120. </script>
  121. <style lang="less" scoped>
  122. .layout {
  123. height: 100%;
  124. display: flex;
  125. flex-direction: column;
  126. .layout-container {
  127. flex: 1;
  128. overflow-y: auto;
  129. }
  130. ::v-deep .van-nav-bar__arrow {
  131. color: #000000;
  132. font-size: 24px;
  133. }
  134. ::v-deep .van-nav-bar__title {
  135. font-weight: bold !important;
  136. font-size: 17px !important;
  137. color: #0a132b !important;
  138. line-height: 24px !important;
  139. }
  140. .van-nav-bar {
  141. z-index: 0;
  142. }
  143. .floating-back {
  144. position: fixed; /* 设定定位为固定 */
  145. left: 26px; /* 距离右侧10像素 */
  146. bottom: 98px; /* 距离底部10像素 */
  147. background-color: transparent; /* 背景颜色 */
  148. z-index: 1000; /* 确保悬浮在其他内容之上 */
  149. }
  150. }
  151. .layout-white {
  152. .van-nav-bar {
  153. background-color: #f2f4f7;
  154. }
  155. ::v-deep [class*='van-hairline']::after {
  156. border: 0px;
  157. }
  158. }
  159. </style>