<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);
|
}
|
},
|
getLocationFn() {
|
const _this = this
|
uni.getLocation({
|
type: 'gcj02', // <map> 组件默认为国测局坐标gcj02
|
altitude: true,
|
success(res) {
|
console.log('返回的位置信息', res, _this)
|
_this.globalData.userInfo = {
|
latitude: res.latitude,
|
longitude: res.longitude
|
}
|
}
|
})
|
},
|
handleAuthorize() {
|
const _this = this // 下边this 为undefined
|
uni.authorize({
|
scope: 'scope.userLocation', // 获取地理信息必填的参数,其它参数见文档
|
success(res) {
|
_this.getLocationFn()
|
},
|
// 授权失败
|
fail(err) {
|
err = err['errMsg']
|
uni.showModal({
|
title: '温馨提示',
|
content: '为获取位置信息,您必须授权!',
|
showCancel: false,
|
confirmText: '确认授权'
|
})
|
// 这里只设置了确认按钮,没有取消按钮
|
.then(res => {
|
//res : [null, {cancel: false, confirm: true, errMsg: 'showModal: ok'}]
|
if (res[1]['confirm']) { // 点击了确认按钮时
|
// 调用下边方法时,会弹出 【使用我的地理位置】界面, 未设置直接返回,还是会走fail授权失败的函数,
|
// 还是会弹出上边的温馨提示!!!
|
// 如果设置, scope.userLocation: true
|
uni.openSetting({
|
success(res) {
|
// 如果不设置,res结果:
|
// {errMsg: "openSetting:ok", authSetting: {scope.userLocation: false}}
|
// 如果设置, res结果:
|
// {errMsg: "openSetting:ok", authSetting: {scope.userLocation: true}}
|
// console.log('小程序设置界面:', res)
|
}
|
})
|
}
|
})
|
}
|
})
|
}
|
},
|
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();
|
// this.handleAuthorize()
|
},
|
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>
|