智慧保安互联网APP
liuyg
2021-08-12 734b2d5d9501e167c827b8a2fb6b11dbc7f16d6a
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<script>
    import WxStorage from "./static/lib/wxStorage.js" //微信Storage
    export default {
        data() {
            return {
                login: '',
 
                show: true,
                name: 'a',
                list: [{
                    "name": 'tip',
                    "msg": 'The first content!'
                }],
                content: '123456'
            }
        },
        methods: {
            judgeAdmin() {
                var scss = this.$route.path == "/pages/loging/loging";
                wx.getSystemInfo({
                    success(res) {
                        console.log(res)
                    }
                })
                console.log(this.$store.state.logPath, 'scss')
                if (scss) {
                    return
                }
                this.login = WxStorage.get("init");
                // console.log(this.login, 'login')
                if (this.login == "false") {
                    wx.navigateTo({
                        url: 'pages/loging/loging?id=1',
                    })
                }
            },
            //发送消息
            send: function() {
                if (this.content) {
                    this.list.push({
                        "name": this.name,
                        "msg": this.content
                    })
                    console.log(this.list)
                    this.socket.emit('sendMessage', {
                        "name": this.name,
                        "msg": this.content
                    });
                    this.content = ''
                    uni.pageScrollTo({
                        duration: 0,
                        scrollTop: this.list.length * 100
                    })
                } else {
                    uni.showToast({
                        title: '请输入内容',
                        icon: 'none'
                    })
                }
            },
            //提交姓名
            onSubmitName: function() {
                console.log(this.name)
                if (this.name) {
                    this.show = false
                    this.socket.emit('newPeople', this.name);
                }
            },
        },
        watch: {},
        mounted() {
            // 加载长连接服务器
            // this.socket.on('connect', () => {
            //     console.log('connection created.');
            //     // that.onSubmitName();
            // });
 
 
            
        },
        onLaunch: function() { //初始化完成时触发(全局只触发一次)
            var that = this;
            if (WxStorage.get("init") == '') {
                WxStorage.set("init", 'false');
                console.log('第一次进入');
                
                // uni.connectSocket({
                //     url: 'ws://192.168.0.111:9034/websocket'
                // });
                
                // uni.onSocketOpen(function(res) {
                //     socketOpen = true;
                //     sendSocketMessage();
                // });
                
                // function sendSocketMessage() {
                //     var data = {
                //                 type: that.$store.state.puserName,
                //                 id: that.$store.state.puserID
                //             }
                //     if (socketOpen) {
                //         uni.sendSocketMessage({
                //             data: JSON.stringify(data)
                //         });
                //     }
                // }
 
                // 加载长连接服务器
                // this.socket.on('connect', () => {
                //     console.log('connection created.');
                //     that.onSubmitName();
                // });
 
            }
            // this.judgeAdmin();
        },
        onShow: function() { //当 uni-app 启动,或从后台进入前台显示 //监听用户进入小程序
            // console.log('App Show')
            // this.judgeAdmin();
        },
        onHide: function() {
            // console.log('App Hide')
        }
    }
</script>
 
<style lang="scss">
    // @import '@smallwei/avue/lib/index.css';
    /*uview全局样式*/
    @import "uview-ui/index.scss";
    /*app全局样式*/
    @import 'static/style/app.scss';
 
    uni-page-wrapper {
        width: 100%;
        height: 100%;
    }
 
    uni-page-body {
        width: 100%;
        height: 100%;
    }
 
    /*每个页面公共css */
</style>