index.js 5.2 KB

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