layout.vue 2.3 KB

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