app-layout.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="app-layout" :class="haveBackground ? 'app-layout-background' : ''">
  3. <app-prompt-box v-if="promptBox.show" :text="promptBox.text" @click="confirmNegative"></app-prompt-box>
  4. <app-user-login v-if="isGuest"></app-user-login>
  5. <app-user-phone v-else></app-user-phone>
  6. <app-payment></app-payment>
  7. <app-report-error :content="reportAndError.content" v-if="reportAndError.boolean"></app-report-error>
  8. <app-coupon-modal></app-coupon-modal>
  9. <view>
  10. <slot></slot>
  11. </view>
  12. <app-loading :type="loadingType" :text="loadingText" :color="loadingColor" v-if="loadingIsShow"
  13. :backgroundImage="loadingBackgroundImage"></app-loading>
  14. <template v-if="tabbarbool">
  15. <view :style="{height: BotHeight + 'rpx'}" class="nav-margin"
  16. :class="haveBackground ? 'app-layout-background' : ''"></view>
  17. <app-iphone-x :backgroundColor="bottom_background_color">
  18. <view slot="empty-area">
  19. <app-tab-bar :page-count="page_count"></app-tab-bar>
  20. </view>
  21. </app-iphone-x>
  22. </template>
  23. </view>
  24. </template>
  25. <script>
  26. import {mapState, mapGetters} from 'vuex';
  27. import appTabBar from '../../../components/basic-component/app-tab-bar/app-tab-bar.vue';
  28. import AppPayment from './app-payment/app-payment';
  29. import tabBar from '../../../core/tabbar.js';
  30. import AppUserLogin from './app-user-login/app-user-login';
  31. import appLoading from '../app-loading/app-loading.vue';
  32. import appRepeatError from '../app-report-error/app-report-error.vue';
  33. import appPromptBox from '../app-prompt-box/app-prompt-box.vue';
  34. import appCouponModal from "./app-coupon-modal/app-coupon-modal.vue";
  35. import appIphoneX from '../../../components/basic-component/app-iphone-x/app-iphone-x.vue';
  36. import appUserPhone from './app-user-phone/app-user-phone';
  37. export default {
  38. name: "app-layout",
  39. data() {
  40. return {
  41. currentRoute: '',
  42. tabbarbool: true,
  43. navigationBarTitle: '',
  44. page_count: getCurrentPages().length,
  45. };
  46. },
  47. components: {
  48. 'app-tab-bar': appTabBar,
  49. 'app-payment': AppPayment,
  50. 'app-user-login': AppUserLogin,
  51. 'app-loading': appLoading,
  52. 'app-report-error': appRepeatError,
  53. 'app-prompt-box': appPromptBox,
  54. 'app-coupon-modal': appCouponModal,
  55. 'app-iphone-x': appIphoneX,
  56. 'app-user-phone': appUserPhone,
  57. },
  58. props: {
  59. haveBackground: {
  60. type: Boolean,
  61. default() {
  62. return true;
  63. }
  64. }
  65. },
  66. computed: {
  67. ...mapState('mallConfig', {
  68. tabBarNavs: state => state.navbar.navs,
  69. bar_title: state => state.bar_title,
  70. top_background_color: state => state.navbar.top_background_color,
  71. top_text_color: state => state.navbar.top_text_color,
  72. bottom_background_color: (state) => {
  73. return state.navbar.bottom_background_color;
  74. },
  75. }),
  76. ...mapState('user', {
  77. accessToken: state => state.accessToken,
  78. }),
  79. ...mapState('gConfig', {
  80. reportAndError: state => state.reportAndError,
  81. promptBox: state => state.promptBox,
  82. iphone: (data) => {
  83. return data.iphone;
  84. },
  85. }),
  86. isGuest() {
  87. return this.$store.state.user.accessToken === '' || this.$store.state.user.accessToken === null;
  88. },
  89. ...mapState('loading', {
  90. loadingType: state => state.type,
  91. loadingText: state => state.text,
  92. loadingColor: state => state.color,
  93. loadingBackgroundImage: state => state.backgroundImage,
  94. loadingIsShow: state => state.isShow,
  95. }),
  96. ...mapGetters('iPhoneX', {
  97. BotHeight: 'getBotHeight',
  98. }),
  99. },
  100. watch: {
  101. tabBarNavs: {
  102. handler: function () {
  103. this.setTabbar();
  104. // #ifndef MP-TOUTIAO
  105. if (this.top_background_color !== undefined) {
  106. uni.setNavigationBarColor({
  107. backgroundColor: this.top_background_color,
  108. // #ifndef MP-ALIPAY
  109. frontColor: this.top_text_color,
  110. // #endif
  111. });
  112. }
  113. // #endif
  114. },
  115. immediate: true,
  116. }
  117. },
  118. created() {
  119. this.$store.dispatch('mallConfig/actionGetConfig');
  120. this.$nextTick(() => {
  121. let currentRoute = this.$platDiff.route();
  122. tabBar.setNavigationBarTitle(this.bar_title, currentRoute).then(res => {
  123. this.navigationBarTitle = res;
  124. });
  125. });
  126. if (this.$user.isLogin() && this.$platDiff.route() != '/pages/disabled/disabled') {
  127. this.$store.dispatch('user/info');
  128. }
  129. this.$hideLoading();
  130. },
  131. mounted() {
  132. // #ifdef MP-WEIXIN
  133. // 直播转发绑定分销关系
  134. try {
  135. let pages = getCurrentPages();
  136. if (pages.length) {
  137. let page = pages[pages.length - 1];
  138. let options = page.options;
  139. let customParams = {};
  140. if (typeof options.custom_params !== 'undefined') {
  141. customParams = JSON.parse(decodeURIComponent(options.custom_params));
  142. }
  143. if (typeof options.user_id !== 'undefined') {
  144. this.$store.dispatch('user/setTempParentId', options.user_id)
  145. } else if (typeof customParams.user_id !== 'undefined') {
  146. this.$store.dispatch('user/setTempParentId', customParams.user_id)
  147. }
  148. }
  149. } catch (e) {
  150. console.log(e)
  151. }
  152. // #endif
  153. this.currentRoute = this.$platDiff.tabBarUrl(null, this.page_count);
  154. this.setTabbar();
  155. // #ifndef MP-TOUTIAO
  156. if (this.top_background_color !== undefined) {
  157. uni.setNavigationBarColor({
  158. backgroundColor: this.top_background_color,
  159. // #ifndef MP-ALIPAY
  160. frontColor: this.top_text_color,
  161. // #endif
  162. });
  163. }
  164. // #endif
  165. },
  166. beforeDestroy() {
  167. this.$hideLoading();
  168. },
  169. methods: {
  170. setTabbar() {
  171. let currentRoute = this.currentRoute;
  172. const specialScene = [1001, 1045, 1046, 1058, 1067, 1084, 1091]; // 小程序特殊场景列表
  173. if (
  174. this.$appScene
  175. && specialScene.indexOf(this.$appScene) > -1
  176. && (currentRoute.indexOf('appid') > -1 || currentRoute.indexOf('appmsg_compact_url') > -1)
  177. ) {
  178. console.log('deleteUrlParam-->', currentRoute);
  179. currentRoute = this.$utils.deleteUrlParam(currentRoute, ['appid', 'appmsg_compact_url'], true);
  180. }
  181. console.log('setTabbar $appScene-->', this.$appScene);
  182. console.log('setTabbar currentRoute-->', currentRoute);
  183. for (let i = 0; i < this.tabBarNavs.length; i++) {
  184. if (currentRoute == this.tabBarNavs[i].url) {
  185. return this.tabbarbool = true;
  186. }
  187. }
  188. return this.tabbarbool = false;
  189. },
  190. },
  191. }
  192. </script>
  193. <style scoped lang="scss">
  194. .app-layout {
  195. max-width: 100%;
  196. overflow: hidden;
  197. }
  198. .app-layout-background {
  199. background-color: #f7f7f7;
  200. }
  201. .app-scroll-y {
  202. width: 100%;
  203. height: 100%;
  204. }
  205. .app-bottom {
  206. height: #{160rpx};
  207. }
  208. .nav-margin {
  209. width: #{750rpx};
  210. }
  211. .app-tabbar {
  212. height: #{110rpx};
  213. }
  214. .model {
  215. position: fixed;
  216. bottom: 0;
  217. left: 0;
  218. width: #{750rpx};
  219. height: #{50rpx};
  220. z-index: 1600;
  221. }
  222. </style>