index.js 7.2 KB

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