index.js 5.7 KB

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