index.js 7.1 KB

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