app-layout.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <view class="app-layout" :style="[layoutStyle]" :class="haveBackground ? 'app-layout-background' : ''" >
  3. <app-prompt-box v-if="promptBox.show" :text="promptBox.text"></app-prompt-box>
  4. <app-user-login v-if="isGuest"></app-user-login>
  5. <!--#ifndef MP_BAIDU-->
  6. <u-iphone-frame v-else-if="!isGuest && is_mobile_auth == 1"></u-iphone-frame>
  7. <!--#endif-->
  8. <app-payment></app-payment>
  9. <app-report-error :content="reportAndError.content" v-if="reportAndError.boolean"></app-report-error>
  10. <app-coupon-modal></app-coupon-modal>
  11. <view>
  12. <slot></slot>
  13. </view>
  14. <app-loading :type="loadingType" :text="loadingText" :color="loadingColor" v-if="loadingIsShow"
  15. :backgroundImage="loadingBackgroundImage"></app-loading>
  16. <template v-if="tabbarbool">
  17. <view class="safe-area-inset-bottom">
  18. <view :style="{height: getNavHei + 'rpx'}" class="nav-margin "
  19. :class="haveBackground ? 'app-layout-background' : ''"></view>
  20. </view>
  21. <app-tab-bar :page-count="page_count"></app-tab-bar>
  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. // #ifndef MP_BAIDU
  36. import uIphoneFrame from './u-authorized-iphone/u-authorized-iphone.vue';
  37. // #endif
  38. export default {
  39. name: "app-layout",
  40. data() {
  41. return {
  42. currentRoute: '',
  43. tabbarbool: true,
  44. navigationBarTitle: '',
  45. page_count: getCurrentPages().length,
  46. };
  47. },
  48. components: {
  49. 'app-tab-bar': appTabBar,
  50. 'app-payment': AppPayment,
  51. 'app-user-login': AppUserLogin,
  52. 'app-loading': appLoading,
  53. 'app-report-error': appRepeatError,
  54. 'app-prompt-box': appPromptBox,
  55. 'app-coupon-modal': appCouponModal,
  56. // #ifndef MP_BAIDU
  57. 'u-iphone-frame': uIphoneFrame,
  58. // #endif
  59. },
  60. props: {
  61. haveBackground: {
  62. type: Boolean,
  63. default() {
  64. return true;
  65. }
  66. },
  67. overflow: {
  68. type: Boolean,
  69. default() {
  70. return true;
  71. }
  72. }
  73. },
  74. computed: {
  75. ...mapState('mallConfig', {
  76. tabBarNavs: state => state.navbar.navs,
  77. bar_title: state => state.bar_title,
  78. top_background_color: state => state.navbar.top_background_color,
  79. top_text_color: state => state.navbar.top_text_color,
  80. bottom_background_color: (state) => {
  81. return state.navbar.bottom_background_color;
  82. },
  83. is_must_login: state => state.mall.setting.is_must_login,
  84. // #ifndef MP_BAIDU
  85. is_mobile_auth: state => state.mall.setting.is_mobile_auth
  86. // #endif
  87. }),
  88. ...mapState('user', {
  89. accessToken: state => state.accessToken,
  90. }),
  91. ...mapState('gConfig', {
  92. reportAndError: state => state.reportAndError,
  93. promptBox: state => state.promptBox,
  94. iphone: (data) => {
  95. return data.iphone;
  96. },
  97. }),
  98. isGuest() {
  99. return this.$store.state.user.accessToken === '' || this.$store.state.user.accessToken === null;
  100. },
  101. ...mapState('loading', {
  102. loadingType: state => state.type,
  103. loadingText: state => state.text,
  104. loadingColor: state => state.color,
  105. loadingBackgroundImage: state => state.backgroundImage,
  106. loadingIsShow: state => state.isShow,
  107. }),
  108. ...mapGetters('iPhoneX', {
  109. BotHeight: 'getBotHeight',
  110. }),
  111. ...mapGetters('iPhoneX', {
  112. getNavHei: 'getNavHei',
  113. }),
  114. layoutStyle() {
  115. if (this.overflow) {
  116. return {
  117. overflow: 'hidden'
  118. }
  119. } else {
  120. return ''
  121. }
  122. }
  123. },
  124. watch: {
  125. tabBarNavs: {
  126. handler: function () {
  127. this.setTabbar();
  128. // #ifndef MP-TOUTIAO
  129. if (this.top_background_color !== undefined) {
  130. uni.setNavigationBarColor({
  131. backgroundColor: this.top_background_color,
  132. // #ifndef MP-ALIPAY
  133. frontColor: this.top_text_color,
  134. // #endif
  135. });
  136. }
  137. // #endif
  138. },
  139. immediate: true,
  140. },
  141. is_must_login: {
  142. handler: function () {
  143. if ((this.$user.isLogin() || this.is_must_login === 1) && this.$platDiff.route() != '/pages/disabled/disabled') {
  144. this.$store.dispatch('user/info');
  145. }
  146. },
  147. immediate: true,
  148. },
  149. accessToken: {
  150. handler: function () {
  151. if (!this.accessToken) {
  152. this.$store.commit('user/info', null);
  153. }
  154. },
  155. immediate: true,
  156. }
  157. },
  158. created() {
  159. this.$store.dispatch('mallConfig/actionGetConfig');
  160. this.$nextTick(() => {
  161. let currentRoute = this.$platDiff.route();
  162. tabBar.setNavigationBarTitle(this.bar_title, currentRoute).then(res => {
  163. if(currentRoute != '/pages/article/article-detail/article-detail') {
  164. this.navigationBarTitle = res;
  165. }
  166. });
  167. });
  168. if ((this.$user.isLogin() || this.is_must_login === 1) && this.$platDiff.route() != '/pages/disabled/disabled') {
  169. this.$store.dispatch('user/info');
  170. }
  171. this.$hideLoading();
  172. },
  173. mounted() {
  174. // #ifdef MP-WEIXIN
  175. // 直播转发绑定分销关系
  176. try {
  177. let pages = getCurrentPages();
  178. if (pages.length) {
  179. let page = pages[pages.length - 1];
  180. let options = page.options;
  181. let customParams = {};
  182. if (typeof options.custom_params !== 'undefined') {
  183. customParams = JSON.parse(decodeURIComponent(options.custom_params));
  184. }
  185. if (typeof options.user_id !== 'undefined') {
  186. this.$store.dispatch('user/setTempParentId', options.user_id)
  187. } else if (typeof customParams.user_id !== 'undefined') {
  188. this.$store.dispatch('user/setTempParentId', customParams.user_id)
  189. }
  190. }
  191. } catch (e) {
  192. }
  193. // #endif
  194. this.currentRoute = this.$platDiff.tabBarUrl(null, this.page_count);
  195. this.setTabbar();
  196. // #ifndef MP-TOUTIAO
  197. if (this.top_background_color !== undefined) {
  198. uni.setNavigationBarColor({
  199. backgroundColor: this.top_background_color,
  200. // #ifndef MP-ALIPAY
  201. frontColor: this.top_text_color,
  202. // #endif
  203. });
  204. }
  205. // #endif
  206. },
  207. beforeDestroy() {
  208. this.$hideLoading();
  209. },
  210. methods: {
  211. touchMove() {
  212. return true;
  213. },
  214. setTabbar() {
  215. let currentRoute = this.currentRoute;
  216. if (
  217. this.$appScene
  218. && [1001, 1045, 1046, 1058, 1067, 1084, 1091].indexOf(this.$appScene) > -1
  219. && (currentRoute.indexOf('appid') > -1 || currentRoute.indexOf('appmsg_compact_url') > -1 || currentRoute .indexOf('wxwork_userid') > -1)
  220. ) {
  221. currentRoute = this.$utils.deleteUrlParam(currentRoute, ['appid', 'appmsg_compact_url', 'wxwork_userid'], true);
  222. }
  223. for (let i = 0; i < this.tabBarNavs.length; i++) {
  224. if (currentRoute == this.tabBarNavs[i].url) {
  225. return this.tabbarbool = true;
  226. }
  227. }
  228. return this.tabbarbool = false;
  229. },
  230. },
  231. }
  232. </script>
  233. <style scoped lang="scss">
  234. .app-layout {
  235. max-width: 100%;
  236. //#ifdef MP-ALIPAY
  237. position: relative;
  238. min-height: 100vh;
  239. z-index: 1;
  240. //#endif
  241. }
  242. .app-layout-background {
  243. background-color: #f7f7f7;
  244. }
  245. .app-scroll-y {
  246. width: 100%;
  247. height: 100%;
  248. }
  249. .app-bottom {
  250. height: #{160rpx};
  251. }
  252. .nav-margin {
  253. width: #{750rpx};
  254. }
  255. .app-tabbar {
  256. height: #{110rpx};
  257. }
  258. .model {
  259. position: fixed;
  260. bottom: 0;
  261. left: 0;
  262. width: #{750rpx};
  263. height: #{50rpx};
  264. z-index: 1600;
  265. }
  266. </style>