layout.vue 4.9 KB

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