index.js 6.5 KB

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