layout.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div class="layout">
  3. <div style="height: 12.2666666667vw" v-if="isShowNavBar">
  4. <van-nav-bar
  5. title="0元购机,尽情享受"
  6. left-arrow
  7. fixed
  8. @click-left="goBackFun"
  9. />
  10. </div>
  11. <div class="layout-container" :style="containerStyle">
  12. <slot></slot>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'layout',
  19. props: {
  20. // 是否显示头部
  21. isNavBar: {
  22. type: Boolean,
  23. default: true,
  24. },
  25. // 背景图片
  26. bgImgName: {
  27. type: String,
  28. default: 'bg-1',
  29. },
  30. // 背景图片高度
  31. bgHeight: {
  32. type: [Number, String],
  33. default: 300,
  34. },
  35. bgColor: {
  36. type: String,
  37. default: '#F3F4F6',
  38. },
  39. // 是否强制像是头部
  40. forceShowNavBar: {
  41. type: Boolean,
  42. default: false
  43. },
  44. padding: {
  45. type: String,
  46. default: ''
  47. }
  48. },
  49. data() {
  50. return {};
  51. },
  52. mounted() {},
  53. computed: {
  54. containerStyle() {
  55. return {
  56. backgroundImage: this.bgImgName ? `url(${require(`@/assets/image/claimCloudPhone/${this.bgImgName}.png`)})` : '',
  57. backgroundRepeat: 'no-repeat',
  58. backgroundSize: this.bgHeight ? `100% ${this.bgHeight}px` : '',
  59. backgroundColor: this.bgColor,
  60. backgroundPosition: '0 0',
  61. padding: this.padding ? this.padding : '16px'
  62. };
  63. },
  64. isShowNavBar() {
  65. // 是否是APP
  66. const isApp = this.$userAgent.isSzx || this.$userAgent.isSzxBrowser;
  67. const isAndroid = this.$userAgent.isAndroid;
  68. const isIos = this.$userAgent.isIos;
  69. const isWx = this.$userAgent.isWx;
  70. // 如果是App并且是安卓,就不显示头部, ios显示
  71. // 如果微信小程序环境的,也不显示头部
  72. // 如果是h5 就显示头部
  73. let bool = false;
  74. bool = isApp ? (isAndroid ? !isAndroid : isIos) : (isWx ? !isWx : !isWx) ;
  75. return bool && this.isNavBar || 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. position: relative;
  94. z-index: 0;
  95. flex-direction: column;
  96. .layout-container {
  97. position: relative;
  98. z-index: -1;
  99. flex: 1;
  100. overflow-y: auto;
  101. }
  102. ::v-deep .van-nav-bar__arrow {
  103. color: #000000;
  104. font-size: 24px;
  105. }
  106. ::v-deep .van-nav-bar__title {
  107. font-weight: bold !important;
  108. font-size: 17px !important;
  109. color: #0a132b !important;
  110. line-height: 24px !important;
  111. }
  112. .van-nav-bar {
  113. z-index: 0;
  114. }
  115. }
  116. </style>