index.js 7.7 KB

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