layout.vue 4.2 KB

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