index.js 4.5 KB

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