index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. const hideWebView = this.data.isNotPersonalfullpack ? Boolean(true) : Boolean(false);
  158. console.log('hideWebView', hideWebView)
  159. this.setData({
  160. url,
  161. loadUrl: true,
  162. socketOptions,
  163. reload: true,
  164. hideWebView: hideWebView,
  165. })
  166. this.recorderManager = wx.getRecorderManager()
  167. this.brandId = options.id
  168. this.joinUrl()
  169. // this.mic()
  170. },
  171. // 新登录强制
  172. handleProfilePatch() {
  173. // debugger
  174. this.setData({
  175. reload: true,
  176. hideWebView: false,
  177. isNotPersonalfullpack: false,
  178. }, () => {
  179. setTimeout(() => {
  180. this.init();
  181. }, 200)
  182. });
  183. },
  184. hideInvitation() {
  185. this.setData({
  186. showInvitation: false
  187. })
  188. this.exit()
  189. },
  190. hideGuide() {
  191. this.setData({
  192. showGuide: false
  193. })
  194. },
  195. hideEnd() {
  196. this.setData({
  197. showEnd: false
  198. })
  199. },
  200. hideAlert() {
  201. this.setData({
  202. showAlert: false
  203. })
  204. },
  205. // exit() {
  206. // this.stopCall()
  207. // this.socketStop && this.socketStop()
  208. // wx.navigateBack()
  209. // },
  210. hidePacked() {
  211. this.setData({
  212. showPacked: false
  213. })
  214. },
  215. handleRoomMaximum() {
  216. wx.switchTab({
  217. url: '/pages/index/index',
  218. })
  219. },
  220. hideIsEnd() {
  221. this.setData({
  222. showIsEnd: false
  223. })
  224. },
  225. goToRoomList() {
  226. wx.redirectTo({
  227. url: '/pages/roomManger/roomManger',
  228. });
  229. },
  230. /**
  231. * 生命周期函数--监听页面初次渲染完成
  232. */
  233. onReady: function () {
  234. },
  235. /**
  236. * 生命周期函数--监听页面显示
  237. */
  238. onShow: async function () {
  239. getApp().updateCardCount()
  240. // this.options.join = true
  241. // this.getCartList()
  242. let userInfo = wx.getStorageSync('userInfo');
  243. let token = wx.getStorageSync('token');
  244. if (!(userInfo && userInfo.userId && token)) {
  245. return;
  246. } else if (this.token !== wx.getStorageSync('token')) {
  247. if (this.data.join) {
  248. let res = await util.request(api.UserInfo)
  249. if (res.errno === 401) {
  250. return getApp().setLoginProps(false)
  251. }
  252. }
  253. this.token = wx.getStorageSync('token')
  254. if (this.socketStop) {
  255. this.socketStop()
  256. this.setData({
  257. hideWebView: true,
  258. webviewUrl: null
  259. })
  260. setTimeout(() => {
  261. const hideWebView = this.data.isNotPersonalfullpack ? Boolean(true) : Boolean(false);
  262. this.setData({
  263. hideWebView: hideWebView
  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. })