| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <template>
- <view>
- <index v-if="loadPage.indexOf('home')!=-1" v-show="channel=='home'" ref="home"></index>
- <service v-if="loadPage.indexOf('service')!=-1" v-show="channel=='service'" ref="service"></service>
- <user v-if="loadPage.indexOf('user')!=-1" v-show="channel=='user'" ref="user"></user>
- <cart v-if="loadPage.indexOf('cart')!=-1" v-show="channel=='cart'" ref="cart"></cart>
- <!-- #ifdef H5 -->
- <!-- <wx-share /> -->
- <wx-share ref="wxshare" />
- <!-- #endif -->
- </view>
- </template>
- <script>
- const app = getApp();
- const req = require("../../utils/request.js");
- import index from '../index/index.vue';
- import service from '../../pages/service/index.vue';
- import user from '../../pages/user/user.vue';
- import cart from '../../pages/cart/cart.vue';
- export default {
- components: {
- index,
- service,
- user,
- cart
- },
- props: {},
- data() {
- return {
- channel: '',
- loadPage: [],
- options: {},
- pageScroll: {},
- shareContent: ''
- }
- },
- async onLoad(options) {
- // this.wxOauth();
- // #ifdef H5
- var appId = req.getStorage('appId');
- if (appId && options.appId == appId||options.appId=="undefined"||!options.appId) {
-
- } else {
- console.log('appId》》》》》》',options.appId);
- req.setStorage('appId', options.appId);
- await this.getwxConfig();
- window.location.reload();
- }
- // #endif
- this.options = req.getStorage('optionsPageDate')
- req.removeStorage('optionsPageDate')
- if (this.options && this.options.pageChannel) {
- this.channel = this.options.pageChannel
- } else {
- this.channel = 'home'
- }
- this.init(this.options)
- uni.$on('tabClick', (data) => {
- console.log('onLoad', data)
- this.channel = data
- this.options = req.getStorage('optionsPageDate')
- this.init(this.options)
- })
- },
- onShow() {
- this.options = req.getStorage('optionsPageDate')
- req.removeStorage('optionsPageDate')
- console.log('onShow optionsPageDate', this.options)
- if (this.options && this.options.pageChannel) {
- if (this.channel == this.options.pageChannel) {
- return false
- } else {
- this.channel = this.options.pageChannel
- this.init(this.options)
- }
- }
- try {
- this.$refs[this.channel].onShowPage()
- } catch (e) {
- //TODO handle the exception
- }
- },
- onShareAppMessage: function() {
- try {
- return this.$refs[this.channel].onShareAppMessagePage()
- } catch (e) {
- //TODO handle the exception
- }
- },
- onShareTimeline() {
- try {
- return this.$refs[this.channel].onShareTimelinePage()
- } catch (e) {
- //TODO handle the exception
- }
- },
- onReachBottom(e) {
- this.$nextTick(() => {
- try {
- this.$refs[this.channel].onReachBottomPage(e)
- } catch (e) {
- //TODO handle the exception
- }
- })
- },
- onPageScroll(e) {
- this.pageScroll[this.channel] = e.scrollTop
- this.pageScroll = JSON.parse(JSON.stringify(this.pageScroll))
- try {
- this.$refs[this.channel].onPageScrollPage(e)
- } catch (e) {
- //TODO handle the exception
- }
- },
- onReady() {
- // #ifdef H5
- var that = this;
- //初始化分享内容
- setTimeout(function() {
- that.shareContent = that.$refs[that.channel].onShareAppMessagePage();
- if (that.shareContent) {
- that.shareContent.path = window.location.origin + that.shareContent.path;
- }
- console.log('分享内容》》》》》', that.shareContent);
- that.$refs.wxshare.init(that.shareContent);
- }, 7 * 1000);
- // #endif
- },
- methods: {
- getwxConfig() {
- return new Promise((resolve, reject) => {
- req.getwxConfig(data => {
- resolve();
- });
- });
- },
- init(options) {
- console.log('init', this._data)
- console.log(this.loadPage.indexOf(this.channel))
- //已加载的页面不再调onload
- if (this.loadPage.indexOf(this.channel) == -1) {
- this.loadPage.push(this.channel)
- this.$nextTick(() => {
- //已加载的页面不再调onload
- try {
- this.$refs[this.channel].onLoadPage(options)
- } catch (e) {
- //TODO handle the exception
- }
- })
- // this.$refs[this.channel].onLoadPage(options)
- }
- this.$nextTick(() => {
- try {
- if (this.pageScroll[this.channel]) {
- uni.pageScrollTo({
- duration: 0,
- scrollTop: this.pageScroll[this.channel]
- })
- } else {
- uni.pageScrollTo({
- duration: 0,
- scrollTop: 0
- })
- }
- this.$refs[this.channel].onShowPage()
- } catch (e) {
- //TODO handle the exception
- }
- });
- }
- },
- }
- </script>
- <style>
- </style>
|