app-layout.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <!-- #ifdef MP -->
  3. <view class="app-layout" :style="[layoutStyle]" :class="haveBackground ? 'app-layout-background' : ''" >
  4. <app-prompt-box v-if="promptBox.show" :text="promptBox.text"></app-prompt-box>
  5. <app-user-login v-if="isGuest"></app-user-login>
  6. <!--#ifndef MP_BAIDU-->
  7. <u-iphone-frame v-else-if="!isGuest && is_mobile_auth == 1"></u-iphone-frame>
  8. <!--#endif-->
  9. <app-payment></app-payment>
  10. <app-report-error :content="reportAndError.content" v-if="reportAndError.boolean"></app-report-error>
  11. <app-coupon-modal></app-coupon-modal>
  12. <view>
  13. <slot></slot>
  14. </view>
  15. <app-loading :type="loadingType" :text="loadingText" :color="loadingColor" v-if="loadingIsShow"
  16. :backgroundImage="loadingBackgroundImage"></app-loading>
  17. <template v-if="tabbarbool">
  18. <view class="safe-area-inset-bottom">
  19. <view :style="{height: '110rpx'}" class="nav-margin "
  20. :class="haveBackground ? 'app-layout-background' : ''"></view>
  21. </view>
  22. <app-tab-bar :page-count="page_count"></app-tab-bar>
  23. </template>
  24. </view>
  25. <!-- #endif-->
  26. <!-- #ifdef H5 -->
  27. <view class="app-layout" :style="[layoutStyle]" :class="haveBackground ? 'app-layout-background' : ''" v-if="isSign">
  28. <app-prompt-box v-if="promptBox.show" :text="promptBox.text"></app-prompt-box>
  29. <app-user-login v-if="isGuest"></app-user-login>
  30. <bd-mandatory-attention v-if="attention"></bd-mandatory-attention>
  31. <app-payment></app-payment>
  32. <app-wechat-share></app-wechat-share>
  33. <app-report-error :content="reportAndError.content" v-if="reportAndError.boolean"></app-report-error>
  34. <app-coupon-modal></app-coupon-modal>
  35. <view>
  36. <slot></slot>
  37. </view>
  38. <app-loading :type="loadingType" :text="loadingText" :color="loadingColor" v-if="loadingIsShow"
  39. :backgroundImage="loadingBackgroundImage"></app-loading>
  40. <template v-if="tabbarbool">
  41. <view class="safe-area-inset-bottom">
  42. <view :style="{height: '110rpx'}" class="nav-margin "
  43. :class="haveBackground ? 'app-layout-background' : ''"></view>
  44. </view>
  45. <app-tab-bar :page-count="page_count"></app-tab-bar>
  46. </template>
  47. </view>
  48. <!-- #endif-->
  49. </template>
  50. <script>
  51. import {mapState, mapGetters} from 'vuex';
  52. import appTabBar from '../../../components/basic-component/app-tab-bar/app-tab-bar.vue';
  53. import AppPayment from './app-payment/app-payment';
  54. import tabBar from '../../../core/tabbar.js';
  55. import AppUserLogin from './app-user-login/app-user-login';
  56. import appLoading from '../app-loading/app-loading.vue';
  57. import appRepeatError from '../app-report-error/app-report-error.vue';
  58. import appPromptBox from '../app-prompt-box/app-prompt-box.vue';
  59. import appCouponModal from "./app-coupon-modal/app-coupon-modal.vue";
  60. // #ifndef MP_BAIDU
  61. import uIphoneFrame from './u-authorized-iphone/u-authorized-iphone.vue';
  62. // #endif
  63. // #ifdef H5
  64. import bdMandatoryAttention from './bd-mandatory-attention/bd-mandatory-attention.vue';
  65. import appWechatShare from "../../page-component/app-common/app-wechat-share.vue";
  66. // #endif
  67. export default {
  68. name: "app-layout",
  69. data() {
  70. return {
  71. currentRoute: '',
  72. tabbarbool: true,
  73. navigationBarTitle: '',
  74. page_count: getCurrentPages().length,
  75. isAttention:false
  76. };
  77. },
  78. components: {
  79. 'app-tab-bar': appTabBar,
  80. 'app-payment': AppPayment,
  81. 'app-user-login': AppUserLogin,
  82. 'app-loading': appLoading,
  83. 'app-report-error': appRepeatError,
  84. 'app-prompt-box': appPromptBox,
  85. 'app-coupon-modal': appCouponModal,
  86. // #ifndef MP_BAIDU
  87. 'u-iphone-frame': uIphoneFrame,
  88. // #endif
  89. // #ifdef H5
  90. 'bd-mandatory-attention': bdMandatoryAttention,
  91. appWechatShare,
  92. // #endif
  93. },
  94. props: {
  95. haveBackground: {
  96. type: Boolean,
  97. default() {
  98. return true;
  99. }
  100. },
  101. overflow: {
  102. type: Boolean,
  103. default() {
  104. return true;
  105. }
  106. }
  107. },
  108. computed: {
  109. ...mapState('mallConfig', {
  110. tabBarNavs: state => state.navbar.navs,
  111. bar_title: state => state.bar_title,
  112. top_background_color: state => state.navbar.top_background_color,
  113. top_text_color: state => state.navbar.top_text_color,
  114. bottom_background_color: (state) => {
  115. return state.navbar.bottom_background_color;
  116. },
  117. is_must_login: state => state.mall.setting.is_must_login,
  118. // #ifndef MP_BAIDU
  119. is_mobile_auth: state => state.mall.setting.is_mobile_auth
  120. // #endif
  121. }),
  122. ...mapState('user', {
  123. accessToken: state => state.accessToken,
  124. }),
  125. ...mapState('gConfig', {
  126. reportAndError: state => state.reportAndError,
  127. promptBox: state => state.promptBox,
  128. iphone: (data) => {
  129. return data.iphone;
  130. },
  131. }),
  132. isGuest() {
  133. if ((this.$store.state.user.accessToken === '' || this.$store.state.user.accessToken === null) && 1) {
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. },
  139. ...mapState('loading', {
  140. loadingType: state => state.type,
  141. loadingText: state => state.text,
  142. loadingColor: state => state.color,
  143. loadingBackgroundImage: state => state.backgroundImage,
  144. loadingIsShow: state => state.isShow,
  145. }),
  146. ...mapGetters('iPhoneX', {
  147. BotHeight: 'getBotHeight',
  148. getNavHei: 'getNavHei',
  149. }),
  150. // #ifdef H5
  151. ...mapGetters({
  152. userInfo: 'user/info',
  153. showAttention: 'user/showAttention'
  154. }),
  155. isSign: function() {
  156. return this.$storage.getStorageSync('isSign');
  157. },
  158. // #endif
  159. layoutStyle() {
  160. if (this.overflow) {
  161. return {
  162. overflow: 'hidden'
  163. }
  164. } else {
  165. return ''
  166. }
  167. },
  168. // #ifdef H5
  169. attention: function() {
  170. return this.showAttention && this.$jwx.isWechat();
  171. }
  172. // #endif
  173. },
  174. watch: {
  175. tabBarNavs: {
  176. handler: function () {
  177. this.setTabbar();
  178. // #ifndef MP-TOUTIAO
  179. if (this.top_background_color !== undefined) {
  180. uni.setNavigationBarColor({
  181. backgroundColor: this.top_background_color,
  182. // #ifndef MP-ALIPAY
  183. frontColor: this.top_text_color,
  184. // #endif
  185. });
  186. }
  187. // #endif
  188. },
  189. immediate: true,
  190. },
  191. is_must_login: {
  192. handler: function () {
  193. if ((this.$user.isLogin() || this.is_must_login === 1) && this.$platDiff.route() != '/pages/disabled/disabled') {
  194. this.$store.dispatch('user/info');
  195. }
  196. },
  197. immediate: true,
  198. },
  199. accessToken: {
  200. handler: function () {
  201. if (!this.accessToken) {
  202. this.$store.commit('user/info', null);
  203. }
  204. },
  205. immediate: true,
  206. },
  207. // #ifdef H5
  208. '$route': {
  209. handler: function(data) {
  210. let { query, meta } = data;
  211. let str = '?';
  212. for (let key in query) {
  213. str += `${key}=${query[key]}&`
  214. }
  215. str.slice(0, str.length - 1);
  216. },
  217. deep: true
  218. },
  219. isSign: {
  220. handler(newVal) {
  221. if (newVal) {
  222. // #ifndef H5
  223. if (this.top_background_color !== undefined) {
  224. uni.setNavigationBarColor({
  225. backgroundColor: this.top_background_color,
  226. frontColor: this.top_text_color,
  227. });
  228. }
  229. // #endif
  230. }
  231. },
  232. deep: true,
  233. immediate: true
  234. }
  235. // #endif
  236. },
  237. created() {
  238. this.$store.dispatch('mallConfig/actionGetConfig');
  239. this.$nextTick(() => {
  240. // #ifdef MP
  241. let currentRoute = this.$platDiff.route();
  242. // #endif
  243. // #ifdef H5
  244. let hash = window.location.hash;
  245. if (hash.split('#')[1] === '/' || hash.split('#')[1].indexOf('/?id') > -1) {
  246. hash = '/pages/index/index';
  247. }
  248. let currentRoute = hash;
  249. // #endif
  250. tabBar.setNavigationBarTitle(this.bar_title, currentRoute).then(res => {
  251. if(currentRoute != '/pages/article/article-detail/article-detail') {
  252. this.navigationBarTitle = res;
  253. }
  254. });
  255. });
  256. if ((this.$user.isLogin() || this.is_must_login === 1) && this.$platDiff.route() != '/pages/disabled/disabled') {
  257. this.$store.dispatch('user/info');
  258. }
  259. this.$hideLoading();
  260. },
  261. mounted() {
  262. // #ifdef MP-WEIXIN
  263. // 直播转发绑定分销关系
  264. try {
  265. let pages = getCurrentPages();
  266. if (pages.length) {
  267. let page = pages[pages.length - 1];
  268. let options = page.options;
  269. let customParams = {};
  270. if (typeof options.custom_params !== 'undefined') {
  271. customParams = JSON.parse(decodeURIComponent(options.custom_params));
  272. }
  273. if (typeof options.user_id !== 'undefined') {
  274. this.$store.dispatch('user/setTempParentId', options.user_id)
  275. } else if (typeof customParams.user_id !== 'undefined') {
  276. this.$store.dispatch('user/setTempParentId', customParams.user_id)
  277. }
  278. }
  279. } catch (e) {
  280. }
  281. // #endif
  282. this.currentRoute = this.$platDiff.tabBarUrl(null, this.page_count);
  283. this.setTabbar();
  284. // #ifdef MP
  285. // #ifndef MP-TOUTIAO
  286. if (this.top_background_color !== undefined) {
  287. uni.setNavigationBarColor({
  288. backgroundColor: this.top_background_color,
  289. // #ifndef MP-ALIPAY
  290. frontColor: this.top_text_color,
  291. // #endif
  292. });
  293. }
  294. // #endif
  295. // #endif
  296. },
  297. beforeDestroy() {
  298. this.$hideLoading();
  299. },
  300. methods: {
  301. touchMove() {
  302. return true;
  303. },
  304. setTabbar() {
  305. let currentRoute = this.currentRoute;
  306. if (
  307. this.$appScene
  308. && [1001, 1045, 1046, 1058, 1067, 1084, 1091].indexOf(this.$appScene) > -1
  309. && (currentRoute.indexOf('appid') > -1 || currentRoute.indexOf('appmsg_compact_url') > -1 || currentRoute .indexOf('wxwork_userid') > -1 || currentRoute .indexOf('weixinadinfo') > -1 || currentRoute .indexOf('gdt_vid') > -1)
  310. ) {
  311. currentRoute = this.$utils.deleteUrlParam(currentRoute, ['appid', 'appmsg_compact_url', 'wxwork_userid', 'weixinadinfo', 'gdt_vid'], true);
  312. }
  313. console.log(currentRoute,"--------=========")
  314. console.log(this.tabBarNavs,"---------=========")
  315. for (let i = 0; i < this.tabBarNavs.length; i++) {
  316. if (currentRoute == this.tabBarNavs[i].url) {
  317. return this.tabbarbool = true;
  318. }
  319. }
  320. console.log(this.tabbarbool)
  321. return this.tabbarbool = false;
  322. },
  323. // #ifdef H5
  324. getUrlParam(name) {
  325. let url = window.location.href.split('#')[0];
  326. let search = url.split('?')[1]
  327. if (search) {
  328. let r = search.substr(0).match(new RegExp('(^|&)' + name + '=([^&]*)(&|$)'))
  329. if (r !== null) return unescape(r[2])
  330. return null
  331. } else {
  332. return null
  333. }
  334. }
  335. // #endif
  336. }
  337. }
  338. </script>
  339. <style scoped lang="scss">
  340. .app-layout {
  341. max-width: 100%;
  342. //#ifdef MP-ALIPAY
  343. position: relative;
  344. min-height: 100vh;
  345. z-index: 1;
  346. //#endif
  347. }
  348. .app-layout-background {
  349. background-color: #f7f7f7;
  350. }
  351. .app-scroll-y {
  352. width: 100%;
  353. height: 100%;
  354. }
  355. .app-bottom {
  356. height: #{160rpx};
  357. }
  358. .nav-margin {
  359. width: #{750rpx};
  360. }
  361. .app-tabbar {
  362. height: #{110rpx};
  363. }
  364. .model {
  365. position: fixed;
  366. bottom: 0;
  367. left: 0;
  368. width: #{750rpx};
  369. height: #{50rpx};
  370. z-index: 1600;
  371. }
  372. </style>