租房掌柜微信小程序Api以及小程序前端模板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
2.9 KiB

//app.js
var netUtil = require("/utils/requestUtil.js"); //require引入
App({
onLaunch: function() {
this.getConfig('housingAllocation,vip_level,pay_type,sex');
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
//如果存在user_id 拉取一下用户信息
var userInfo = wx.getStorageSync('userInfo')
if (userInfo.id > 0) {
//请求api
var url = this.globalData.requestUrl + 'index/member/getInfo/' + userInfo.id;
netUtil.sendGet(url)
.then((res) => {
if (res.statusCode == 200 && res.data.code == 200) {
//存储本地
wx.setStorageSync('userInfo', res.data.data)
} else {
console.log('获取用户信息异常')
}
})
}
// 登录
wx.login({
success: res => {
console.log(res)
//判断本地是否有用户信息,如果没有,则请求code去拿openid
// 发送 res.code 到后台换取 openId, sessionKey, unionId
this.globalData.code = res.code
}
})
// 获取用户信息
// wx.getSetting({
// success: res => {
// if (res.authSetting['scope.userInfo']) {
// // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
// wx.getUserInfo({
// success: res => {
// console.log(res,'a')
// // 可以将 res 发送给后台解码出 unionId
// this.globalData.userInfo = res.userInfo
// // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// // 所以此处加入 callback 以防止这种情况
// if (this.userInfoReadyCallback) {
// this.userInfoReadyCallback(res)
// }
// }
// })
// }
// }
// })
// 获取系统状态栏信息
wx.getSystemInfo({
success: e => {
this.globalData.StatusBar = e.statusBarHeight;
let custom = wx.getMenuButtonBoundingClientRect();
this.globalData.Custom = custom;
this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
}
})
},
//获取服务端配置信息
getConfig: function(name) {
var self = this;
var url = this.globalData.requestUrl + 'index/config/index/' + name;
netUtil.sendGet(url)
.then((res) => {
if (res.statusCode == 200 && res.data.code == 200) {
//设置全局变量信息
wx.setStorageSync('global_config', res.data.data);
} else {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 3000
})
}
})
},
globalData: {
userInfo: '',
code: null,
requestUrl: 'https://xunxibaoapi.yaoyz.com/' //接口url
},
})