layout.vue 4.5 KB

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