index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // pages/webview/index.js
  2. const api = require('../../config/api.js');
  3. const util = require('../../utils/util.js');
  4. import socketApi from '../../socket'
  5. const URL = 'https://www.4dkankan.com/mallscene.html?m='
  6. Page({
  7. ...socketApi,
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. sendShare: false,
  13. loadUrl: false,
  14. goodsCount: 0,
  15. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  16. rnd:'',
  17. temp:'',
  18. live_base_url: 'rtmp://120.24.85.77:1935/hls'
  19. // url: 'https://www.4dkankan.com/showProPC.html?m=vroMUXdx&origin=4Dplaza&sid=1046051&room_id=1596785144930&user_id=44'
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: async function (options) {
  25. console.log(options)
  26. getApp().checkNetStatu();
  27. // setTimeout(() => this.login(), 3000)
  28. this.setData({
  29. imgServer: util.imgServer,
  30. showGuide: false,
  31. showCommodity: false,
  32. showInvitation: false,
  33. showEnd: false,
  34. showAlert: false,
  35. sendShare: false,
  36. showPacked: false,
  37. showIsEnd: false,
  38. showCoupon: false,
  39. showContact: false,
  40. showCommodityCtrl: false,
  41. recordStatus: 0,
  42. commoditys: [],
  43. coupons: [],
  44. userAuth: false,
  45. count: 0,
  46. goodsList: [],
  47. page: 1,
  48. size: 1000
  49. })
  50. // console.log(options)
  51. // options.id = '1046098'
  52. this.options = options
  53. if (options.join) {
  54. this.role = 'customer'
  55. } else {
  56. this.role = 'leader'
  57. }
  58. socketApi.onShow.call(this)
  59. this.urlPj = '&brandId=' + this.options.id
  60. },
  61. async init() {
  62. let options = this.options
  63. let {url: base, obj: m } = await new Promise(r => this.getBrandDetail(options.id, (url, obj) => r({url, obj})))
  64. this.getBrand(options.id, m)
  65. this.mcode = m
  66. let socketOptions = await this.socketStart({sceneId: this.mcode, roomId: options.roomId})
  67. // options.join = true
  68. let url = this.getUrl(base, socketOptions, options.join) + this.urlPj
  69. this.base = base
  70. this.setData({urlTemp: url.split('').join(' ')})
  71. this.setData({ url, loadUrl: true, socketOptions, reload: true, hideWebView: false })
  72. this.recorderManager = wx.getRecorderManager()
  73. this.brandId = options.id
  74. this.joinUrl()
  75. // this.mic()
  76. },
  77. hideInvitation() {
  78. this.setData({ showInvitation: false })
  79. this.exit()
  80. },
  81. hideGuide() {
  82. this.setData({ showGuide: false })
  83. },
  84. hideEnd() {
  85. this.setData({ showEnd: false })
  86. },
  87. hideAlert() {
  88. this.setData({ showAlert: false })
  89. },
  90. // exit() {
  91. // this.stopCall()
  92. // this.socketStop && this.socketStop()
  93. // wx.navigateBack()
  94. // },
  95. hidePacked() {
  96. this.setData({ showPacked: false })
  97. },
  98. hideIsEnd() {
  99. this.setData({ showIsEnd: false })
  100. },
  101. /**
  102. * 生命周期函数--监听页面初次渲染完成
  103. */
  104. onReady: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面显示
  108. */
  109. onShow: async function () {
  110. getApp().updateCardCount()
  111. // this.options.join = true
  112. // this.getCartList()
  113. let userInfo = wx.getStorageSync('userInfo');
  114. let token = wx.getStorageSync('token');
  115. if (!(userInfo && userInfo.userId && token)) {
  116. return;
  117. // return wx.navigateTo({
  118. // url: '/pages/auth/btnAuth/btnAuth',
  119. // })
  120. if (this.options.join) {
  121. getApp().setLoginProps(false)
  122. } else {
  123. this.socketStop && this.socketStop()
  124. this.init()
  125. }
  126. } else if (this.token !== wx.getStorageSync('token')) {
  127. if (this.options.join) {
  128. let res = await util.request(api.UserInfo)
  129. if (res.errno === 401) {
  130. return getApp().setLoginProps(false)
  131. }
  132. }
  133. this.token = wx.getStorageSync('token')
  134. if (this.socketStop) {
  135. this.socketStop()
  136. this.setData({
  137. hideWebView: true,
  138. webviewUrl: null
  139. })
  140. setTimeout(() => {
  141. this.setData({ hideWebView: false })
  142. this.init()
  143. }, 500)
  144. } else {
  145. this.init()
  146. }
  147. } else {
  148. socketApi.onShow.call(this)
  149. }
  150. },
  151. /**
  152. * 生命周期函数--监听页面隐藏
  153. */
  154. onHide: function () {
  155. socketApi.onHide.call(this)
  156. },
  157. /**
  158. * 页面相关事件处理函数--监听用户下拉动作
  159. */
  160. onPullDownRefresh: function () {
  161. getApp().onPullDownRefresh()
  162. },
  163. /**
  164. * 页面上拉触底事件的处理函数
  165. */
  166. onReachBottom: function () {
  167. }
  168. })