123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- // pages/discover/discover.js
- import socketApi from '../..//socket'
- import api from '../../config/api'
- const util = require('../../utils/util.js');
- import remote from '../../config.js'
- const initData = {
- showGuide: false,
- showCommodity: false,
- showInvitation: false,
- showEnd: false,
- showAlert: false,
- sendShare: false,
- showPacked: false,
- showIsEnd: false,
- showCoupon: false,
- showContact: false,
- showCommodityCtrl: false,
- goodsCount: 0,
- url: '',
- currTab: 'webview',
- showTab: true,
- }
- Page({
- ...socketApi,
- /**
- * 页面的初始数据
- */
- data: {
- live_base_url: 'rtmp://120.24.85.77:1935/hls',
- page: 1,
- size: 1000,
- roomList: [],
- bottom: 50,
- ...initData
- },
-
- loadWeb() {
- this.setData({
- ...initData, url: this.data.url,
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- async onLoad () {
- getApp().checkNetStatu();
- this.getRoomList()
-
- this.socketOptions = await this.socketStart({sceneId: ''})
- this.base = remote.viewChildHost + '/discover.html?appname=shop&origin=4Dplaza'
- console.log(this.base)
- // this.base = 'https://test.4dkankan.com/discover.html?appname=shop'
- const url = this.getUrl(this.base, this.socketOptions, false)
- this.setData({ url, loadUrl: true, socketOptions: this.socketOptions })
- this.refers = false
- this.data.reload = true
- this.joinUrl()
- },
- async getRoomList() {
- let {data} = await util.request(api.RoomList + '?pageNum=1&pageSize=1000', {}, 'GET')
- // let aaa = true
- data.list.forEach(item => {
- // 101:直播中,102:未开始,103已结束,104禁播,105:暂停,106:异常,107:已过期
- item.state = item.liveStatus === 101
- // item.state = aaa
- // aaa = !aaa
- })
- this.setData({roomList: data.list})
- },
- async scene(data) {
- this.cacheData = data
- if (data.data.cmd === 'enter') {
- let {data: {brand}} = await util.request(api.BrandDetailByScene + '?sceneNum=' + data.data.num)
- if (brand) {
- this.options.id = brand.id
- this.setData({
- id: brand.id,
- newPicUrl: brand.listPicUrl,
- showCommodityCtrl: true
- })
- this.mcode = data.data.num
- this.setData({numCode: data.data.num})
- this.getBrand(brand.id, data.data.num)
- this.joinUrl()
- }
- } else if (data.data.cmd === 'exit') {
- this.data.navList = null
- this.setData({ ...initData, url: this.data.url, numCode: null, showTab: false })
- }
- wx.setStorageSync('lastSceneNum', data.data.num)
- },
- exit() {
- this.setData({webviewUrl: null})
- socketApi.exit.bind(this)()
- },
- onShareAppMessage: function (res) {
- let { id, newPicUrl } = this.data
- if (res.from === 'button') {
- this.setData({ sendShare: false })
- return {
- imageUrl: newPicUrl,
- path: `/pages/webview/index?id=${id}&join=true&roomId=${this.data.socketOptions.roomId}`,
- }
- }
- },
- gotoGood(ev) {
- let {goodsId} = ev.target.dataset.item
- wx.navigateTo({
- url: '/pages/goods/goods?id=' + goodsId,
- })
- },
- showTabs(data) {
- this.setData( {showTab: data.data} )
- },
- changeTab(ev) {
- this.setData({ showTab: false })
- wx.nextTick(() => {
- if (ev.target.dataset.tab === 'live') {
- // this.setData({ ...initData, showTab: true, currTab: ev.target.dataset.tab })
- this.setData({ showTab: true, currTab: ev.target.dataset.tab })
- this.pauseVideo = true
- this.joinUrl()
- } else {
- this.setData({ showTab: true, currTab: ev.target.dataset.tab })
- this.pauseVideo = false
- this.joinUrl()
- }
- })
- },
- gotoLive(ev) {
- let item = ev.currentTarget.dataset.item
- const goodPath = item.liveRoomGoodsVos.length ?
- encodeURIComponent(JSON.stringify({ path: 'pages/goods/goods', id: item.liveRoomGoodsVos[0].goodsId })) : null
- wx.navigateTo({
- url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${item.roomId}${goodPath ? `&custom_params=${goodPath}` : ''}`,
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: async function (refer) {
- getApp().updateCardCount()
- if (this.cccache && this.cacheToken !== wx.getStorageSync('token')) {
- refer = true
- }
- this.cacheToken = wx.getStorageSync('token');
- this.cccache = true
- if (this.refers || refer) {
- this.socketOptions = await this.socketStart({sceneId: ''})
- this.base = remote.viewChildHost + '/discover.html?appname=shop&origin=4Dplaza'
- const url = this.getUrl(this.base, this.socketOptions, false)
- this.setData({ url, loadUrl: true, socketOptions: this.socketOptions, reload: true })
- this.refers = false
- if (refer) {
- console.error('激活视频?1')
- this.setData({ webviewUrl: null })
- setTimeout(() => {
- this.joinUrl()
- }, 500)
- } else {
- console.error('激活视频?2')
- this.joinUrl()
- socketApi.onShow.call(this)
- }
- } else {
- console.error('激活视频?3')
- socketApi.onShow.call(this)
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- setTimeout(() => {
- let refers = ['pages/index/index', 'pages/catalog/catalog', 'pages/cart/cart', 'pages/ucenter/index/index']
- // let refers = []
- let pages = getCurrentPages()
- let route = pages[pages.length - 1].route
- if (~refers.indexOf(route)) {
- this.refers = true
- this.setData({...initData})
- wx.nextTick(() => {
- this.socketSendMessage('stopCall', {})
- this.stopCall()
- this.socketStop()
- this.setData({ webviewUrl: null })
- })
- } else {
- socketApi.onHide.call(this)
- }
- }, 100)
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- getUrl(...args) {
- let url = socketApi.getUrl.call(this, ...args)
- let num = wx.getStorageSync('lastSceneNum')
- url += num ? `&lastSceneNum=${num}` : ''
- return url
- },
- webMessage(e) {
- console.error('接收', e)
- let msgs = e.detail.data.filter(item => item.type === 'lastSceneNum')
- let msg = msgs[msgs.length - 1]
- if (msg) {
-
- wx.setStorageSync('lastSceneNum', msg.num)
- }
- }
- })
|