// pages/webview/index.js const api = require('../../config/api.js'); const util = require('../../utils/util.js'); import socketApi from '../../socket' import { setUserInfo } from '../../utils/getUserInfo'; const handleScenes = ['t-9EtLj36', 'tSrGwEa0n'] const URL = 'https://www.4dkankan.com/mallscene.html?m=' Page({ ...socketApi, /** * 页面的初始数据 */ data: { show: !wx.getStorageSync('saveUserInfo'), canIUse: wx.canIUse('button.open-type.getUserInfo'), handleScenes, sendShare: false, loadUrl: false, goodsCount: 0, bottom: 0, canIUse: wx.canIUse('button.open-type.getUserInfo'), rnd: '', temp: '', live_base_url: 'rtmp://120.24.85.77:1935/hls' // url: 'https://www.4dkankan.com/showProPC.html?m=vroMUXdx&origin=4Dplaza&sid=1046051&room_id=1596785144930&user_id=44' }, getCode: function () { return new Promise(r => { wx.login({ success: function (res) { if (res.code) { r(res.code) } } }); }) }, bindGetUserInfo: function (e) { // let code = await this.getCode() console.log(e) if (this.data.loginNew) { wx.getUserProfile && wx.getUserProfile({ desc: '获取用户昵称头像用作共享', success: e => { setUserInfo(e.userInfo) this.setData({ show: false }) this.onLoad(this.options) this.onShow() }, fail(e) { console.error(e) } }) } else { setUserInfo(e.detail) this.setData({ show: false }) this.onLoad(this.options) this.onShow() } // let res = await util.request(api.axLogin, { // code: code, // userInfo: e.detail // }, 'POST', 'application/json') }, /** * 生命周期函数--监听页面加载 */ onLoad: async function (options) { this.urlPj = '&id=' + this.options.id this.setData(({ loginNew: wx.getUserProfile})) if (this.data.show) return; var app = getApp(); clearTimeout(this.timeout) app.appHideCb = () => { this.socketSendMessage('changeOnlineStatus', { status: false }) this.timeout = setTimeout(() => { this.onUnload() }, 2 * 60 * 1000) } wx.setStorageSync('testSocket', 'onload') this.setData({ imgServer: util.imgServer, showGuide: false, showCommodity: false, showInvitation: false, showEnd: false, showAlert: false, sendShare: false, showPacked: false, showIsEnd: false, showCoupon: false, showContact: false, showCommodityCtrl: false, recordStatus: 0, commoditys: [], coupons: [], userAuth: false, count: 0, goodsList: [], page: 1, size: 1000 }) this.options = options if (options.join) { this.role = 'customer' } else { this.role = 'leader' } socketApi.onShow.call(this) }, async init() { let options = this.options let { url: base, obj: m } = await new Promise(r => this.getBrandDetail(options.id, (url, obj) => r({ url, obj }))) console.error(base, m) this.setData({ sceneNumber: m }) this.setData({ isGreve: !!~this.data.handleScenes.indexOf(this.data.sceneNumber) }) this.getBrand(options.id, m) this.mcode = m let socketOptions = await this.socketStart({ sceneId: this.mcode, roomId: options.roomId }) // options.join = true let url = this.getUrl(base, socketOptions, options.join) + this.urlPj this.base = base this.setData({ urlTemp: url.split('').join(' ') }) this.setData({ url, loadUrl: true, socketOptions, reload: true, hideWebView: false }) this.recorderManager = wx.getRecorderManager() this.brandId = options.id this.joinUrl() // this.mic() }, hideInvitation() { this.setData({ showInvitation: false }) this.exit() }, hideGuide() { this.setData({ showGuide: false }) }, hideEnd() { this.setData({ showEnd: false }) }, hideAlert() { this.setData({ showAlert: false }) }, // exit() { // this.stopCall() // this.socketStop && this.socketStop() // wx.navigateBack() // }, hidePacked() { this.setData({ showPacked: false }) }, hideIsEnd() { this.setData({ showIsEnd: false }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: async function () { this.setData({show: !wx.getStorageSync('saveUserInfo')}) if (this.data.show) return; // this.show = clearTimeout(this.timeout) socketApi.onShow.call(this) let userInfo = await this.getUserInfo() let token = userInfo.token if (!(userInfo && userInfo.userId && token)) { console.log(userInfo) return; } else { this.token = userInfo.token if (this.socketStop) { // if (this.data.socketStatus === -1) { // this.socketStop() // this.setData({ // hideWebView: true, // webviewUrl: null // }) // setTimeout(() => { // this.setData({ // hideWebView: false // }) // this.init() // }, 500) // } } else { // wx.showToast({ // title: '重新加载socket', // }) this.init() } } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { socketApi.onHide.call(this) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { getApp().onPullDownRefresh() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { } })