layout.vue 3.4 KB

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