index.js 5.8 KB

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