index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view>
  3. <index v-if="loadPage.indexOf('home')!=-1" v-show="channel=='home'" ref="home"></index>
  4. <service v-if="loadPage.indexOf('service')!=-1" v-show="channel=='service'" ref="service"></service>
  5. <user v-if="loadPage.indexOf('user')!=-1" v-show="channel=='user'" ref="user"></user>
  6. <cart v-if="loadPage.indexOf('cart')!=-1" v-show="channel=='cart'" ref="cart"></cart>
  7. <!-- #ifdef H5 -->
  8. <!-- <wx-share /> -->
  9. <wx-share ref="wxshare" />
  10. <!-- #endif -->
  11. </view>
  12. </template>
  13. <script>
  14. const app = getApp();
  15. const req = require("../../utils/request.js");
  16. import index from '../index/index.vue';
  17. import service from '../../pages/service/index.vue';
  18. import user from '../../pages/user/user.vue';
  19. import cart from '../../pages/cart/cart.vue';
  20. export default {
  21. components: {
  22. index,
  23. service,
  24. user,
  25. cart
  26. },
  27. props: {},
  28. data() {
  29. return {
  30. channel: '',
  31. loadPage: [],
  32. options: {},
  33. pageScroll: {},
  34. shareContent: ''
  35. }
  36. },
  37. async onLoad(options) {
  38. // this.wxOauth();
  39. // #ifdef H5
  40. var appId = req.getStorage('appId');
  41. if (appId && options.appId == appId||options.appId=="undefined"||!options.appId) {
  42. } else {
  43. console.log('appId》》》》》》',options.appId);
  44. req.setStorage('appId', options.appId);
  45. await this.getwxConfig();
  46. window.location.reload();
  47. }
  48. // #endif
  49. this.options = req.getStorage('optionsPageDate')
  50. req.removeStorage('optionsPageDate')
  51. if (this.options && this.options.pageChannel) {
  52. this.channel = this.options.pageChannel
  53. } else {
  54. this.channel = 'home'
  55. }
  56. this.init(this.options)
  57. uni.$on('tabClick', (data) => {
  58. console.log('onLoad', data)
  59. this.channel = data
  60. this.options = req.getStorage('optionsPageDate')
  61. this.init(this.options)
  62. })
  63. },
  64. onShow() {
  65. this.options = req.getStorage('optionsPageDate')
  66. req.removeStorage('optionsPageDate')
  67. console.log('onShow optionsPageDate', this.options)
  68. if (this.options && this.options.pageChannel) {
  69. if (this.channel == this.options.pageChannel) {
  70. return false
  71. } else {
  72. this.channel = this.options.pageChannel
  73. this.init(this.options)
  74. }
  75. }
  76. try {
  77. this.$refs[this.channel].onShowPage()
  78. } catch (e) {
  79. //TODO handle the exception
  80. }
  81. },
  82. onShareAppMessage: function() {
  83. try {
  84. return this.$refs[this.channel].onShareAppMessagePage()
  85. } catch (e) {
  86. //TODO handle the exception
  87. }
  88. },
  89. onShareTimeline() {
  90. try {
  91. return this.$refs[this.channel].onShareTimelinePage()
  92. } catch (e) {
  93. //TODO handle the exception
  94. }
  95. },
  96. onReachBottom(e) {
  97. this.$nextTick(() => {
  98. try {
  99. this.$refs[this.channel].onReachBottomPage(e)
  100. } catch (e) {
  101. //TODO handle the exception
  102. }
  103. })
  104. },
  105. onPageScroll(e) {
  106. this.pageScroll[this.channel] = e.scrollTop
  107. this.pageScroll = JSON.parse(JSON.stringify(this.pageScroll))
  108. try {
  109. this.$refs[this.channel].onPageScrollPage(e)
  110. } catch (e) {
  111. //TODO handle the exception
  112. }
  113. },
  114. onReady() {
  115. // #ifdef H5
  116. var that = this;
  117. //初始化分享内容
  118. setTimeout(function() {
  119. that.shareContent = that.$refs[that.channel].onShareAppMessagePage();
  120. if (that.shareContent) {
  121. that.shareContent.path = window.location.origin + that.shareContent.path;
  122. }
  123. console.log('分享内容》》》》》', that.shareContent);
  124. that.$refs.wxshare.init(that.shareContent);
  125. }, 7 * 1000);
  126. // #endif
  127. },
  128. methods: {
  129. getwxConfig() {
  130. return new Promise((resolve, reject) => {
  131. req.getwxConfig(data => {
  132. resolve();
  133. });
  134. });
  135. },
  136. init(options) {
  137. console.log('init', this._data)
  138. console.log(this.loadPage.indexOf(this.channel))
  139. //已加载的页面不再调onload
  140. if (this.loadPage.indexOf(this.channel) == -1) {
  141. this.loadPage.push(this.channel)
  142. this.$nextTick(() => {
  143. //已加载的页面不再调onload
  144. try {
  145. this.$refs[this.channel].onLoadPage(options)
  146. } catch (e) {
  147. //TODO handle the exception
  148. }
  149. })
  150. // this.$refs[this.channel].onLoadPage(options)
  151. }
  152. this.$nextTick(() => {
  153. try {
  154. if (this.pageScroll[this.channel]) {
  155. uni.pageScrollTo({
  156. duration: 0,
  157. scrollTop: this.pageScroll[this.channel]
  158. })
  159. } else {
  160. uni.pageScrollTo({
  161. duration: 0,
  162. scrollTop: 0
  163. })
  164. }
  165. this.$refs[this.channel].onShowPage()
  166. } catch (e) {
  167. //TODO handle the exception
  168. }
  169. });
  170. }
  171. },
  172. }
  173. </script>
  174. <style>
  175. </style>