177 lines
5.6 KiB
JavaScript
177 lines
5.6 KiB
JavaScript
// 引入SDK核心类
|
||
var QQMapWX = require('/lib/qqmap-wx-jssdk.min.js');
|
||
|
||
App({
|
||
onLaunch: function() {
|
||
//设备信息
|
||
this.getUserSystemInfo();
|
||
//登录次数
|
||
this.loginCount();
|
||
//网路状态
|
||
this.userNetType();
|
||
//用户地理位置
|
||
var that = this;
|
||
//查看用户是否有授权地理位置
|
||
wx.getSetting({
|
||
success: function(r) {
|
||
var authSessing = r.authSetting;
|
||
if (authSessing['scope.userLocation']) {
|
||
that.getLocation();
|
||
}
|
||
}
|
||
})
|
||
},
|
||
globalData: {
|
||
//API接口调用路径
|
||
requestUrl: 'http://localhost/',
|
||
wsUrl: 'ws://localhost/message',
|
||
// requestUrl: 'http://39.105.59.232/',
|
||
// wsUrl: 'ws://39.105.59.232/message',
|
||
//登录用户信息
|
||
user: null,
|
||
//用户设备信息
|
||
systemInfo: null,
|
||
//今日登陆次数
|
||
loginCount: 1,
|
||
//用户网络状态
|
||
networkType: '',
|
||
//是否自动播放
|
||
autoPlay: null,
|
||
//用户地理位置
|
||
location: null,
|
||
//宠物列表
|
||
petList: [],
|
||
//聊天记录
|
||
chat: [],
|
||
//购物车
|
||
shoppingCarList:[]
|
||
},
|
||
|
||
|
||
getLocation: function() {
|
||
var that = this;
|
||
wx.getLocation({
|
||
success: function(r) {
|
||
// 调用接口
|
||
// 实例化API核心类
|
||
var map = new QQMapWX({
|
||
key: '7KHBZ-DSTWP-UOCD7-V4ABM-LJH2F-G4BAJ' // 必填
|
||
});
|
||
map.reverseGeocoder({
|
||
location: {
|
||
latitude: r.latitude,
|
||
longitude: r.longitude,
|
||
},
|
||
success: function(r) {
|
||
var location = {
|
||
province: r.result.address_component.province,
|
||
city: r.result.address_component.city,
|
||
district: r.result.address_component.district,
|
||
address: r.result.address
|
||
}
|
||
that.globalData.location = location;
|
||
}
|
||
});
|
||
},
|
||
})
|
||
},
|
||
|
||
/*用户网络情况 */
|
||
|
||
userNetType: function() {
|
||
var that = this;
|
||
wx.getNetworkType({
|
||
success: function(res) {
|
||
that.globalData.networkType = res.networkType;
|
||
}
|
||
})
|
||
},
|
||
|
||
|
||
//判断今日第几次登录
|
||
loginCount: function() {
|
||
var that = this;
|
||
//当前日期
|
||
var nowDate = new Date();
|
||
var year = nowDate.getFullYear();
|
||
var month = nowDate.getMonth() + 1;
|
||
var day = nowDate.getDate();
|
||
var dateStr = year + '' + month + '' + day;
|
||
var setLoginStorage = {
|
||
date: dateStr,
|
||
count: 1
|
||
}
|
||
//获取缓存
|
||
wx.getStorage({
|
||
key: 'loginCount',
|
||
success: function(res) { //找到了
|
||
var getLoginStorage = res.data;
|
||
//缓存的最后登录日期如果是今天则登录次+1
|
||
if (getLoginStorage.date == dateStr) {
|
||
getLoginStorage.count = getLoginStorage.count + 1;
|
||
//刷新缓存
|
||
wx.setStorage({
|
||
key: 'loginCount',
|
||
data: getLoginStorage,
|
||
})
|
||
//刷新全局变量
|
||
that.globalData.loginCount = getLoginStorage.count;
|
||
} else {
|
||
//重置缓存为今天
|
||
wx.setStorage({
|
||
key: 'loginCount',
|
||
data: setLoginStorage,
|
||
})
|
||
//刷新全局变量
|
||
that.globalData.loginCount = 1;
|
||
}
|
||
},
|
||
fail: function(res) {
|
||
//重置缓存为今天
|
||
wx.setStorage({
|
||
key: 'loginCount',
|
||
data: setLoginStorage,
|
||
})
|
||
//刷新全局变量
|
||
that.globalData.loginCount = 1;
|
||
}
|
||
})
|
||
},
|
||
|
||
//获取用户设备信息
|
||
// brand string 设备品牌 1.5.0
|
||
// model string 设备型号
|
||
// pixelRatio number 设备像素比
|
||
// screenWidth number 屏幕宽度,单位px 1.1.0
|
||
// screenHeight number 屏幕高度,单位px 1.1.0
|
||
// windowWidth number 可使用窗口宽度,单位px
|
||
// windowHeight number 可使用窗口高度,单位px
|
||
// statusBarHeight number 状态栏的高度,单位px 1.9.0
|
||
// language string 微信设置的语言
|
||
// version string 微信版本号
|
||
// system string 操作系统及版本
|
||
// platform string 客户端平台
|
||
// fontSizeSetting number 用户字体大小(单位px)。以微信客户端「我 - 设置 - 通用 - 字体大小」中的设置为准 1.5.0
|
||
// SDKVersion string 客户端基础库版本 1.1.0
|
||
// benchmarkLevel number 设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>= 1(设备性能值,该值越高,设备性能越好,目前最高不到50) 1.8.0
|
||
// albumAuthorized boolean 允许微信使用相册的开关(仅 iOS 有效) 2.6.0
|
||
// cameraAuthorized boolean 允许微信使用摄像头的开关 2.6.0
|
||
// locationAuthorized boolean 允许微信使用定位的开关 2.6.0
|
||
// microphoneAuthorized boolean 允许微信使用麦克风的开关 2.6.0
|
||
// notificationAuthorized boolean 允许微信通知的开关 2.6.0
|
||
// notificationAlertAuthorized boolean 允许微信通知带有提醒的开关(仅 iOS 有效) 2.6.0
|
||
// notificationBadgeAuthorized boolean 允许微信通知带有标记的开关(仅 iOS 有效) 2.6.0
|
||
// notificationSoundAuthorized boolean 允许微信通知带有声音的开关(仅 iOS 有效) 2.6.0
|
||
// bluetoothEnabled boolean 蓝牙的系统开关 2.6.0
|
||
// locationEnabled boolean 地理位置的系统开关 2.6.0
|
||
// wifiEnabled boolean Wi - Fi 的系统开关 2.6.0
|
||
// safeArea Object 在竖屏正方向下的安全区域
|
||
getUserSystemInfo: function() {
|
||
var that = this;
|
||
wx.getSystemInfo({
|
||
success: function(res) {
|
||
that.globalData.systemInfo = res;
|
||
},
|
||
})
|
||
}
|
||
}) |