index.js 5.2 KB

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