index.js 6.3 KB

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