index.js 6.0 KB

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