index.js 5.9 KB

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