index.js 5.8 KB

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