index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. type: '',
  22. shareStatus: 0
  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. console.log(this.options.a)
  30. if (this.options.a) {
  31. // [id_type_join_roomId_many]
  32. let arr = this.options.a.split(',')
  33. this.options.id = arr[0]
  34. this.options.type = arr[1]
  35. this.options.join = true
  36. this.options.roomId = arr[3]
  37. this.options.many = true
  38. }
  39. console.log(this.options)
  40. getApp().checkNetStatu();
  41. // setTimeout(() => this.login(), 3000)
  42. this.setData({
  43. type: options.type,
  44. join: false,
  45. imgServer: util.imgServer,
  46. showGuide: false,
  47. showCommodity: false,
  48. showInvitation: false,
  49. showEnd: false,
  50. showAlert: false,
  51. sendShare: false,
  52. showPacked: false,
  53. showIsEnd: false,
  54. showCoupon: false,
  55. showContact: false,
  56. showCommodityCtrl: false,
  57. recordStatus: 0,
  58. commoditys: [],
  59. coupons: [],
  60. userAuth: false,
  61. count: 0,
  62. goodsList: [],
  63. page: 1,
  64. size: 1000
  65. })
  66. // console.log(options)
  67. // options.id = '1046098'
  68. if (this.options.roomId) {
  69. this.data.join = true
  70. }
  71. if (this.data.join) {
  72. this.role = 'customer'
  73. } else {
  74. this.role = 'leader'
  75. }
  76. if (options.many !== void 0) {
  77. this.data.many = options.many
  78. }
  79. socketApi.onShow.call(this)
  80. this.urlPj = '&brandId=' + this.options.id
  81. },
  82. // copy() {
  83. // var dataT =this.data.webviewUrl
  84. // wx.setClipboardData({
  85. // data: dataT,
  86. // success: function (res) {
  87. // wx.getClipboardData({
  88. // success: function (res) {
  89. // console.log(res.data) // data
  90. // }
  91. // })
  92. // }
  93. // })
  94. // },
  95. async init() {
  96. let options = this.options
  97. console.log('********')
  98. console.log(options)
  99. let {
  100. url: base,
  101. obj: m
  102. } = await new Promise(r => this.getBrandDetail(options.id, options.type, (url, obj) => r({
  103. url,
  104. obj
  105. })))
  106. this.getBrand(options.id, m)
  107. this.mcode = m
  108. let socketOptions = await this.socketStart({
  109. sceneId: this.mcode,
  110. roomId: options.roomId
  111. })
  112. let url = this.getUrl(base, socketOptions, this.data.join) + this.urlPj
  113. this.base = base
  114. this.setData({
  115. urlTemp: url.split('').join(' ')
  116. })
  117. this.setData({
  118. url,
  119. loadUrl: true,
  120. socketOptions,
  121. reload: true,
  122. hideWebView: false
  123. })
  124. this.recorderManager = wx.getRecorderManager()
  125. this.brandId = options.id
  126. this.joinUrl()
  127. // this.mic()
  128. },
  129. hideInvitation() {
  130. this.setData({
  131. showInvitation: false
  132. })
  133. this.exit()
  134. },
  135. hideGuide() {
  136. this.setData({
  137. showGuide: false
  138. })
  139. },
  140. hideEnd() {
  141. this.setData({
  142. showEnd: false
  143. })
  144. },
  145. hideAlert() {
  146. this.setData({
  147. showAlert: false
  148. })
  149. },
  150. // exit() {
  151. // this.stopCall()
  152. // this.socketStop && this.socketStop()
  153. // wx.navigateBack()
  154. // },
  155. hidePacked() {
  156. this.setData({
  157. showPacked: false
  158. })
  159. },
  160. hideIsEnd() {
  161. this.setData({
  162. showIsEnd: false
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面初次渲染完成
  167. */
  168. onReady: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面显示
  172. */
  173. onShow: async function () {
  174. getApp().updateCardCount()
  175. // this.options.join = true
  176. // this.getCartList()
  177. let userInfo = wx.getStorageSync('userInfo');
  178. let token = wx.getStorageSync('token');
  179. if (!(userInfo && userInfo.userId && token)) {
  180. return;
  181. // return wx.navigateTo({
  182. // url: '/pages/auth/btnAuth/btnAuth',
  183. // })
  184. if (this.options.join) {
  185. getApp().setLoginProps(false)
  186. } else {
  187. this.socketStop && this.socketStop()
  188. this.init()
  189. }
  190. } else if (this.token !== wx.getStorageSync('token')) {
  191. if (this.data.join) {
  192. let res = await util.request(api.UserInfo)
  193. if (res.errno === 401) {
  194. return getApp().setLoginProps(false)
  195. }
  196. }
  197. this.token = wx.getStorageSync('token')
  198. if (this.socketStop) {
  199. this.socketStop()
  200. this.setData({
  201. hideWebView: true,
  202. webviewUrl: null
  203. })
  204. setTimeout(() => {
  205. this.setData({
  206. hideWebView: false
  207. })
  208. this.init()
  209. }, 500)
  210. } else {
  211. this.init()
  212. }
  213. } else {
  214. socketApi.onShow.call(this)
  215. }
  216. },
  217. /**
  218. * 生命周期函数--监听页面隐藏
  219. */
  220. onHide: function () {
  221. socketApi.onHide.call(this)
  222. },
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh: function () {
  227. getApp().onPullDownRefresh()
  228. },
  229. /**
  230. * 页面上拉触底事件的处理函数
  231. */
  232. onReachBottom: function () {
  233. }
  234. })