index.js 6.3 KB

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