forked from nsjcy/frontEnd/nsjcy

liyj
2020-02-11 e60e253cb3ce0597ded89b56a414c731e28c4ff1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var webrtcroom = require('../../../utils/webrtcroom.js');
 
Page({
 
    /**
     * 页面的初始数据
     */
    data: {
        roomName: '',
        roomList: [],
        userName: '',
        firstshow: true, // 第一次显示页面
        tapTime: '',
        tapJoinRoom: false
    },
 
    // 拉取房间列表
    getRoomList: function (callback) {
        var self = this;
        webrtcroom.getRoomList(0, 20, function (res) {
            console.log('拉取房间列表成功:', res);
            if (res.data && res.data.rooms) {
                self.setData({
                    roomList: res.data.rooms
                });
            }
        }, function (res) {});
    },
 
    // 进入webrtcroom页面
    goRoom: function (e) {
        // 防止两次点击操作间隔太快
        var nowTime = new Date();
        if (nowTime - this.data.tapTime < 1000) {
            return;
        }
        var url = '../room/room?roomID=' + e.currentTarget.dataset.roomid + '&roomName=' + e.currentTarget.dataset.roomname + '&userName=' + this.data.userName + '&roomCreator=' + e.currentTarget.dataset.roomcreator;
        if (!this.data.tapJoinRoom) { // 如果没有点击进入房间
            this.data.tapJoinRoom = true;
            wx.navigateTo({
                url: url,
                complete: () => {
                    this.data.tapJoinRoom = false; // 不管成功还是失败,重置tapJoinRoom
                }
            });
        }
        this.setData({
            'tapTime': nowTime
        });
    },
 
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        var self = this;
        console.log(this.data);
        var systemInfo = wx.getSystemInfoSync();
        console.log('系统消息:', systemInfo);
    this.getRoomList();
    },
 
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.getRoomList(function () {});
        wx.stopPullDownRefresh();
    },
})