| | |
| | | data() { |
| | | return { |
| | | login: '', |
| | | |
| | | show: true, |
| | | name: 'a', |
| | | list: [{ |
| | | "name": 'tip', |
| | | "msg": 'The first content!' |
| | | }], |
| | | content: '123456' |
| | | } |
| | | }, |
| | | methods: { |
| | |
| | | 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() {}, |
| | | 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('第一次进入') |
| | | 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(); |
| | | }, |