const baseUrl = getApp(); const api = require('../../config/api.js'); const util = require('../../config/util.js'); Page({ /** * 页面的初始数据 */ data: { roomId:1, accesstoken:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getroomId(options); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, getroomId:function(ee){ const that = this; let url = baseUrl.globalData.baseUrl + '/user/acctoken'; var param = { pareid: ee }; //此处为使用封装的post请求 util.get(url, param).then((res) => { console.log(res.access_token); wx.setStorageSync('accesstoen', res.access_token) that.setData({ accesstoken: res.access_token }); }).catch((errMsg) => { console.log(errMsg); }); }, getroomlist:function(){ //getroomlist const that = this; let url = baseUrl.globalData.baseUrl + '/user/getroomlist'; var param = { access_token: wx.getStorageSync('accesstoen'), }; //此处为使用封装的post请求 util.post(url, param).then((res) => { console.log(res); // that.setData({ // roomId: res.data.room_info.roomId // }); }).catch((errMsg) => { console.log(errMsg); }); }, getroomreplyvodelist:function(){ const that = this; let url = baseUrl.globalData.baseUrl + '/user/getroomreplyvide'; var param = { access_token: wx.getStorageSync('accesstoen'), "action": "get_replay", "room_id": that.roomId, }; //此处为使用封装的post请求 util.post(url, param).then((res) => { console.log(res); // that.setData({ // roomId: res.data.room_info.roomId // }); }).catch((errMsg) => { console.log(errMsg); }); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getroomlist(this.data.accesstoken); let roomId = this.data.roomId // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取 let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/index/index', pid: 1 })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断) this.setData({ roomId, customParams }), this.getroomreplyvodelist(); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })