layout.vue 4.6 KB

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