123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- // pages/webview/index.js
- const api = require('../../config/api.js');
- const util = require('../../utils/util.js');
- import socketApi from '../../socket'
- const URL = 'https://www.4dkankan.com/mallscene.html?m='
- Page({
- ...socketApi,
- /**
- * 页面的初始数据
- */
- data: {
- sendShare: false,
- loadUrl: false,
- goodsCount: 0,
- canIUse: wx.canIUse('button.open-type.getUserInfo'),
- rnd: '',
- temp: '',
- live_base_url: 'rtmp://120.24.85.77:1935/hls',
- peopleCount: 5,
- surplus: 50,
- type: '',
- shareStatus: 0,
- showInvitation: false,
- roomMaximum: false,
- roomDisMiss: false,
- unKnowError: false, // 未知错误重进
- // url: 'https://www.4dkankan.com/showProPC.html?m=vroMUXdx&origin=4Dplaza&sid=1046051&room_id=1596785144930&user_id=44'
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- // console.log(this.options.a)
- if (options.scene) {
- // [id_type_join_roomId_many]
- const scene = decodeURIComponent(options.scene)
- let arr = scene.split('_')
- console.log('分拆的', arr)
- this.options.id = options.id || arr[0]
- this.options.type = options.type || arr[1]
- this.options.join = "true"
- this.options.roomId = options.roomId || arr[3]
- this.options.many = "true"
- }
- // debugger
- console.log(this.options)
- getApp().checkNetStatu();
- // setTimeout(() => this.login(), 3000)
- this.setData({
- type: options.type || this.options.type,
- join: false,
- 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
- })
- // console.log(options)
- // options.id = '1046098'
- if (this.options.roomId) {
- this.data.join = true
- }
- if (this.data.join) {
- this.role = 'customer'
- } else {
- this.role = 'leader'
- }
- if (options.many !== void 0) {
- this.data.many = options.many
- }
- if (this.options.many) {
- this.data.many = this.options.many
- }
- console.log(this.options.many)
- console.log(this.data.many)
- socketApi.onShow.call(this)
- this.urlPj = '&brandId=' + this.options.id
- },
- // copy() {
- // var dataT =this.data.webviewUrl
- // wx.setClipboardData({
- // data: dataT,
- // success: function (res) {
- // wx.getClipboardData({
- // success: function (res) {
- // console.log(res.data) // data
- // }
- // })
- // }
- // })
- // },
- async init() {
- let options = this.options
- console.log('webview-option', options)
- let base, m
- // 只catch getBrandDetail 是因为分享进来的会出现问题
- try {
- let {
- url,
- obj
- } = await new Promise(r => this.getBrandDetail(options.id, options.type, (url, obj) => r({
- url,
- obj
- })))
- base = url
- m = obj
- } catch (error) {
- this.setData({
- hideWebView: true,
- })
- console.log(error)
- // debugger
- wx.showModal({
- title: '提示',
- content: '场景初始化有误,请稍后重试',
- showCancel: false,
- confirmColor: '#0075DC',
- success: function (res) {
- wx.switchTab({
- url: '/pages/index/index'
- });
- }
- })
- }
- this.getBrand(options.id, m)
- this.mcode = m
- //TODO 有问题, 其他模式的房间号如何处理?
- let socketOptions = await this.socketStart({
- sceneId: this.mcode,
- roomId: options.roomId || '888888'
- })
- let url = this.getUrl(base, socketOptions, this.data.join) + this.urlPj
- this.base = base
- // socketOptions.nickname = socketOptions.nickname.replace(/[^\u4E00-\u9FA5A-Za-z0-9]/g, '')
- this.setData({
- urlTemp: url.split('').join(' ')
- })
- this.setData({
- url,
- loadUrl: true,
- socketOptions,
- reload: true,
- hideWebView: false,
- // debugerInfo: JSON.stringify({
- // userId: socketOptions.userId,
- // roomId: socketOptions.roomId,
- // num: socketOptions.sceneNumber,
- // userLimitNum: socketOptions.userLimitNum,
- // isAssistant: socketOptions.isAssistant,
- // role: socketOptions.role,
- // assistantId: socketOptions.assistantId
- // })
- })
- 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
- })
- },
- handleRoomMaximum() {
- wx.switchTab({
- url: '/pages/index/index',
- })
- },
- hideIsEnd() {
- this.setData({
- showIsEnd: false
- })
- },
- goToRoomList() {
- wx.redirectTo({
- url: '/pages/roomManger/roomManger',
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: async function () {
- getApp().updateCardCount()
- // this.options.join = true
- // this.getCartList()
- let userInfo = wx.getStorageSync('userInfo');
- let token = wx.getStorageSync('token');
- if (!(userInfo && userInfo.userId && token)) {
- return;
- // return wx.navigateTo({
- // url: '/pages/auth/btnAuth/btnAuth',
- // })
- if (this.options.join) {
- getApp().setLoginProps(false)
- } else {
- this.socketStop && this.socketStop()
- this.init()
- }
- } else if (this.token !== wx.getStorageSync('token')) {
- if (this.data.join) {
- let res = await util.request(api.UserInfo)
- if (res.errno === 401) {
- return getApp().setLoginProps(false)
- }
- }
- this.token = wx.getStorageSync('token')
- if (this.socketStop) {
- this.socketStop()
- this.setData({
- hideWebView: true,
- webviewUrl: null
- })
- setTimeout(() => {
- this.setData({
- hideWebView: false
- })
- this.init()
- }, 500)
- } else {
- this.init()
- }
- } else {
- socketApi.onShow.call(this)
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- socketApi.onHide.call(this)
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- getApp().onPullDownRefresh()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- }
- })
|