index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. import {
  6. setUserInfo
  7. } from '../../utils/getUserInfo';
  8. const handleScenes = ['t-9EtLj36', 'tSrGwEa0n']
  9. const URL = 'https://www.4dkankan.com/mallscene.html?m='
  10. Page({
  11. ...socketApi,
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. show: !wx.getStorageSync('saveUserInfo'),
  17. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  18. handleScenes,
  19. sendShare: false,
  20. loadUrl: false,
  21. goodsCount: 0,
  22. bottom: 0,
  23. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  24. rnd: '',
  25. temp: '',
  26. live_base_url: 'rtmp://120.24.85.77:1935/hls'
  27. // url: 'https://www.4dkankan.com/showProPC.html?m=vroMUXdx&origin=4Dplaza&sid=1046051&room_id=1596785144930&user_id=44'
  28. },
  29. getCode: function () {
  30. return new Promise(r => {
  31. wx.login({
  32. success: function (res) {
  33. if (res.code) {
  34. r(res.code)
  35. }
  36. }
  37. });
  38. })
  39. },
  40. bindGetUserInfo: function (e) {
  41. // let code = await this.getCode()
  42. console.log(e)
  43. if (this.data.loginNew) {
  44. wx.getUserProfile && wx.getUserProfile({
  45. desc: '获取用户昵称头像用作共享',
  46. success: e => {
  47. setUserInfo(e.userInfo)
  48. this.setData({
  49. show: false
  50. })
  51. this.onLoad(this.options)
  52. this.onShow()
  53. },
  54. fail(e) {
  55. console.error(e)
  56. }
  57. })
  58. } else {
  59. setUserInfo(e.detail)
  60. this.setData({
  61. show: false
  62. })
  63. this.onLoad(this.options)
  64. this.onShow()
  65. }
  66. // let res = await util.request(api.axLogin, {
  67. // code: code,
  68. // userInfo: e.detail
  69. // }, 'POST', 'application/json')
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. onLoad: async function (options) {
  75. this.urlPj = '&id=' + this.options.id
  76. this.setData(({ loginNew: wx.getUserProfile}))
  77. if (this.data.show) return;
  78. var app = getApp();
  79. clearTimeout(this.timeout)
  80. app.appHideCb = () => {
  81. this.socketSendMessage('changeOnlineStatus', {
  82. status: false
  83. })
  84. this.timeout = setTimeout(() => {
  85. this.onUnload()
  86. }, 2 * 60 * 1000)
  87. }
  88. wx.setStorageSync('testSocket', 'onload')
  89. this.setData({
  90. imgServer: util.imgServer,
  91. showGuide: false,
  92. showCommodity: false,
  93. showInvitation: false,
  94. showEnd: false,
  95. showAlert: false,
  96. sendShare: false,
  97. showPacked: false,
  98. showIsEnd: false,
  99. showCoupon: false,
  100. showContact: false,
  101. showCommodityCtrl: false,
  102. recordStatus: 0,
  103. commoditys: [],
  104. coupons: [],
  105. userAuth: false,
  106. count: 0,
  107. goodsList: [],
  108. page: 1,
  109. size: 1000
  110. })
  111. this.options = options
  112. if (options.join) {
  113. this.role = 'customer'
  114. } else {
  115. this.role = 'leader'
  116. }
  117. socketApi.onShow.call(this)
  118. },
  119. async init() {
  120. let options = this.options
  121. let {
  122. url: base,
  123. obj: m
  124. } = await new Promise(r => this.getBrandDetail(options.id, (url, obj) => r({
  125. url,
  126. obj
  127. })))
  128. console.error(base, m)
  129. this.setData({
  130. sceneNumber: m
  131. })
  132. this.setData({
  133. isGreve: !!~this.data.handleScenes.indexOf(this.data.sceneNumber)
  134. })
  135. this.getBrand(options.id, m)
  136. this.mcode = m
  137. let socketOptions = await this.socketStart({
  138. sceneId: this.mcode,
  139. roomId: options.roomId
  140. })
  141. // options.join = true
  142. let url = this.getUrl(base, socketOptions, options.join) + this.urlPj
  143. this.base = base
  144. this.setData({
  145. urlTemp: url.split('').join(' ')
  146. })
  147. this.setData({
  148. url,
  149. loadUrl: true,
  150. socketOptions,
  151. reload: true,
  152. hideWebView: false
  153. })
  154. this.recorderManager = wx.getRecorderManager()
  155. this.brandId = options.id
  156. this.joinUrl()
  157. // this.mic()
  158. },
  159. hideInvitation() {
  160. this.setData({
  161. showInvitation: false
  162. })
  163. this.exit()
  164. },
  165. hideGuide() {
  166. this.setData({
  167. showGuide: false
  168. })
  169. },
  170. hideEnd() {
  171. this.setData({
  172. showEnd: false
  173. })
  174. },
  175. hideAlert() {
  176. this.setData({
  177. showAlert: false
  178. })
  179. },
  180. // exit() {
  181. // this.stopCall()
  182. // this.socketStop && this.socketStop()
  183. // wx.navigateBack()
  184. // },
  185. hidePacked() {
  186. this.setData({
  187. showPacked: false
  188. })
  189. },
  190. hideIsEnd() {
  191. this.setData({
  192. showIsEnd: false
  193. })
  194. },
  195. /**
  196. * 生命周期函数--监听页面初次渲染完成
  197. */
  198. onReady: function () {
  199. },
  200. /**
  201. * 生命周期函数--监听页面显示
  202. */
  203. onShow: async function () {
  204. this.setData({show: !wx.getStorageSync('saveUserInfo')})
  205. if (this.data.show) return;
  206. // this.show =
  207. clearTimeout(this.timeout)
  208. socketApi.onShow.call(this)
  209. let userInfo = await this.getUserInfo()
  210. let token = userInfo.token
  211. if (!(userInfo && userInfo.userId && token)) {
  212. console.log(userInfo)
  213. return;
  214. } else {
  215. this.token = userInfo.token
  216. if (this.socketStop) {
  217. // if (this.data.socketStatus === -1) {
  218. // this.socketStop()
  219. // this.setData({
  220. // hideWebView: true,
  221. // webviewUrl: null
  222. // })
  223. // setTimeout(() => {
  224. // this.setData({
  225. // hideWebView: false
  226. // })
  227. // this.init()
  228. // }, 500)
  229. // }
  230. } else {
  231. // wx.showToast({
  232. // title: '重新加载socket',
  233. // })
  234. this.init()
  235. }
  236. }
  237. },
  238. /**
  239. * 生命周期函数--监听页面隐藏
  240. */
  241. onHide: function () {
  242. socketApi.onHide.call(this)
  243. },
  244. /**
  245. * 页面相关事件处理函数--监听用户下拉动作
  246. */
  247. onPullDownRefresh: function () {
  248. getApp().onPullDownRefresh()
  249. },
  250. /**
  251. * 页面上拉触底事件的处理函数
  252. */
  253. onReachBottom: function () {
  254. }
  255. })