index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 {
  71. url: base,
  72. obj: m
  73. } = await new Promise(r => this.getBrandDetail(options.id, (url, obj) => r({
  74. url,
  75. obj
  76. })))
  77. this.getBrand(options.id, m)
  78. this.mcode = m
  79. let socketOptions = await this.socketStart({
  80. sceneId: this.mcode,
  81. roomId: options.roomId
  82. })
  83. let url = this.getUrl(base, socketOptions, this.data.join) + this.urlPj
  84. this.base = base
  85. this.setData({
  86. urlTemp: url.split('').join(' ')
  87. })
  88. // socketOptions.nickname = socketOptions.nickname.replace(/[^\u4E00-\u9FA5A-Za-z0-9]/g, '')
  89. console.error(socketOptions)
  90. this.setData({
  91. url,
  92. loadUrl: true,
  93. socketOptions,
  94. reload: true,
  95. hideWebView: false
  96. })
  97. this.recorderManager = wx.getRecorderManager()
  98. this.brandId = options.id
  99. this.joinUrl()
  100. // this.mic()
  101. },
  102. hideInvitation() {
  103. this.setData({
  104. showInvitation: false
  105. })
  106. this.exit()
  107. },
  108. hideGuide() {
  109. this.setData({
  110. showGuide: false
  111. })
  112. },
  113. hideEnd() {
  114. this.setData({
  115. showEnd: false
  116. })
  117. },
  118. hideAlert() {
  119. this.setData({
  120. showAlert: false
  121. })
  122. },
  123. // exit() {
  124. // this.stopCall()
  125. // this.socketStop && this.socketStop()
  126. // wx.navigateBack()
  127. // },
  128. hidePacked() {
  129. this.setData({
  130. showPacked: false
  131. })
  132. },
  133. hideIsEnd() {
  134. this.setData({
  135. showIsEnd: false
  136. })
  137. },
  138. /**
  139. * 生命周期函数--监听页面初次渲染完成
  140. */
  141. onReady: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面显示
  145. */
  146. onShow: async function () {
  147. getApp().updateCardCount()
  148. // this.options.join = true
  149. // this.getCartList()
  150. let userInfo = wx.getStorageSync('userInfo');
  151. let token = wx.getStorageSync('token');
  152. if (!(userInfo && userInfo.userId && token)) {
  153. return;
  154. // return wx.navigateTo({
  155. // url: '/pages/auth/btnAuth/btnAuth',
  156. // })
  157. if (this.options.join) {
  158. getApp().setLoginProps(false)
  159. } else {
  160. this.socketStop && this.socketStop()
  161. this.init()
  162. }
  163. } else if (this.token !== wx.getStorageSync('token')) {
  164. if (this.data.join) {
  165. let res = await util.request(api.UserInfo)
  166. if (res.errno === 401) {
  167. return getApp().setLoginProps(false)
  168. }
  169. }
  170. this.token = wx.getStorageSync('token')
  171. if (this.socketStop) {
  172. this.socketStop()
  173. this.setData({
  174. hideWebView: true,
  175. webviewUrl: null
  176. })
  177. setTimeout(() => {
  178. this.setData({
  179. hideWebView: false
  180. })
  181. this.init()
  182. }, 500)
  183. } else {
  184. this.init()
  185. }
  186. } else {
  187. socketApi.onShow.call(this)
  188. }
  189. },
  190. /**
  191. * 生命周期函数--监听页面隐藏
  192. */
  193. onHide: function () {
  194. socketApi.onHide.call(this)
  195. },
  196. /**
  197. * 页面相关事件处理函数--监听用户下拉动作
  198. */
  199. onPullDownRefresh: function () {
  200. getApp().onPullDownRefresh()
  201. },
  202. /**
  203. * 页面上拉触底事件的处理函数
  204. */
  205. onReachBottom: function () {
  206. }
  207. })