layout.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. },
  45. data() {
  46. return {};
  47. },
  48. mounted() {},
  49. computed: {
  50. containerStyle() {
  51. return {
  52. backgroundImage: this.bgImgName ? `url(${require(`@/assets/image/claimCloudPhone/${this.bgImgName}.png`)})` : '',
  53. backgroundRepeat: 'no-repeat',
  54. backgroundSize: this.bgHeight ? `100% ${this.bgHeight}px` : '',
  55. backgroundColor: this.bgColor,
  56. backgroundPosition: '0 0',
  57. };
  58. },
  59. isShowNavBar() {
  60. // 是否是APP
  61. const isApp = this.$userAgent.isSzx || this.$userAgent.isSzxBrowser;
  62. const isAndroid = this.$userAgent.isAndroid;
  63. const isIos = this.$userAgent.isIos;
  64. const isWx = this.$userAgent.isWx;
  65. // 如果是App并且是安卓,就不显示头部, ios显示
  66. // 如果微信小程序环境的,也不显示头部
  67. // 如果是h5 就显示头部
  68. let bool = false;
  69. bool = isApp ? (isAndroid ? !isAndroid : isIos) : (isWx ? !isWx : !isWx) ;
  70. return bool && this.isNavBar || this.forceShowNavBar;
  71. },
  72. },
  73. methods: {
  74. goBackFun() {
  75. if (this.$listeners.goBack) {
  76. this.$emit('goBack');
  77. return;
  78. }
  79. this.$router.go(-1);
  80. },
  81. },
  82. };
  83. </script>
  84. <style lang="less" scoped>
  85. .layout {
  86. height: 100%;
  87. display: flex;
  88. flex-direction: column;
  89. .layout-container {
  90. flex: 1;
  91. overflow-y: auto;
  92. padding: 16px;
  93. }
  94. ::v-deep .van-nav-bar__arrow {
  95. color: #000000;
  96. font-size: 24px;
  97. }
  98. ::v-deep .van-nav-bar__title {
  99. font-weight: bold !important;
  100. font-size: 17px !important;
  101. color: #0a132b !important;
  102. line-height: 24px !important;
  103. }
  104. .van-nav-bar {
  105. z-index: 1000;
  106. }
  107. }
  108. </style>