index.js 6.1 KB

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