index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. role: socketOptions.role,
  136. assistantId: socketOptions.assistantId
  137. })
  138. })
  139. this.recorderManager = wx.getRecorderManager()
  140. this.brandId = options.id
  141. this.joinUrl()
  142. // this.mic()
  143. },
  144. hideInvitation() {
  145. this.setData({
  146. showInvitation: false
  147. })
  148. this.exit()
  149. },
  150. hideGuide() {
  151. this.setData({
  152. showGuide: false
  153. })
  154. },
  155. hideEnd() {
  156. this.setData({
  157. showEnd: false
  158. })
  159. },
  160. hideAlert() {
  161. this.setData({
  162. showAlert: false
  163. })
  164. },
  165. // exit() {
  166. // this.stopCall()
  167. // this.socketStop && this.socketStop()
  168. // wx.navigateBack()
  169. // },
  170. hidePacked() {
  171. this.setData({
  172. showPacked: false
  173. })
  174. },
  175. hideIsEnd() {
  176. this.setData({
  177. showIsEnd: false
  178. })
  179. },
  180. /**
  181. * 生命周期函数--监听页面初次渲染完成
  182. */
  183. onReady: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面显示
  187. */
  188. onShow: async function () {
  189. getApp().updateCardCount()
  190. // this.options.join = true
  191. // this.getCartList()
  192. let userInfo = wx.getStorageSync('userInfo');
  193. let token = wx.getStorageSync('token');
  194. if (!(userInfo && userInfo.userId && token)) {
  195. return;
  196. // return wx.navigateTo({
  197. // url: '/pages/auth/btnAuth/btnAuth',
  198. // })
  199. if (this.options.join) {
  200. getApp().setLoginProps(false)
  201. } else {
  202. this.socketStop && this.socketStop()
  203. this.init()
  204. }
  205. } else if (this.token !== wx.getStorageSync('token')) {
  206. if (this.data.join) {
  207. let res = await util.request(api.UserInfo)
  208. if (res.errno === 401) {
  209. return getApp().setLoginProps(false)
  210. }
  211. }
  212. this.token = wx.getStorageSync('token')
  213. if (this.socketStop) {
  214. this.socketStop()
  215. this.setData({
  216. hideWebView: true,
  217. webviewUrl: null
  218. })
  219. setTimeout(() => {
  220. this.setData({
  221. hideWebView: false
  222. })
  223. this.init()
  224. }, 500)
  225. } else {
  226. this.init()
  227. }
  228. } else {
  229. socketApi.onShow.call(this)
  230. }
  231. },
  232. /**
  233. * 生命周期函数--监听页面隐藏
  234. */
  235. onHide: function () {
  236. socketApi.onHide.call(this)
  237. },
  238. /**
  239. * 页面相关事件处理函数--监听用户下拉动作
  240. */
  241. onPullDownRefresh: function () {
  242. getApp().onPullDownRefresh()
  243. },
  244. /**
  245. * 页面上拉触底事件的处理函数
  246. */
  247. onReachBottom: function () {
  248. }
  249. })