index.js 7.0 KB

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