|
|
|
//app.js
|
|
|
|
App({
|
|
|
|
onLaunch: function (e) {
|
|
|
|
var that = this;
|
|
|
|
//获取设备信息
|
|
|
|
this.setMenuHeight()
|
|
|
|
this.autoUpdate()
|
|
|
|
},
|
|
|
|
autoUpdate:function(){
|
|
|
|
console.log(new Date())
|
|
|
|
var self=this
|
|
|
|
// 获取小程序更新机制兼容
|
|
|
|
if (wx.canIUse('getUpdateManager')) {
|
|
|
|
const updateManager = wx.getUpdateManager()
|
|
|
|
//1. 检查小程序是否有新版本发布
|
|
|
|
updateManager.onCheckForUpdate(function (res) {
|
|
|
|
// 请求完新版本信息的回调
|
|
|
|
if (res.hasUpdate) {
|
|
|
|
//2. 小程序有新版本,则静默下载新版本,做好更新准备
|
|
|
|
updateManager.onUpdateReady(function () {
|
|
|
|
console.log(new Date())
|
|
|
|
wx.showModal({
|
|
|
|
title: '更新提示',
|
|
|
|
content: '新版本已经准备好,是否重启应用?',
|
|
|
|
success: function (res) {
|
|
|
|
if (res.confirm) {
|
|
|
|
//3. 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
|
|
updateManager.applyUpdate()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
updateManager.onUpdateFailed(function () {
|
|
|
|
// 新的版本下载失败
|
|
|
|
wx.showModal({
|
|
|
|
title: '已经有新版本了哟~',
|
|
|
|
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
|
|
|
|
wx.showModal({
|
|
|
|
title: '提示',
|
|
|
|
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onShow(e){
|
|
|
|
//隐藏系统tabbar
|
|
|
|
wx.hideTabBar();
|
|
|
|
var query = {};
|
|
|
|
if(e.query.q){
|
|
|
|
//通过扫码进来获取二维码上的参数并存入storage
|
|
|
|
let urlSpread = e.query.q;
|
|
|
|
if (urlSpread) {
|
|
|
|
if (urlSpread.indexOf('%3F') != -1) {
|
|
|
|
// 通过扫桌面二维码进来
|
|
|
|
urlSpread = urlSpread.split("%3F")[1].replace(/%3D/g, ":").replace(/%26/g, ",").split(",").map((item, index) => {
|
|
|
|
item = item.split(":");
|
|
|
|
return `"${item[0]}":"${item[1]}"`;
|
|
|
|
}).join(",");
|
|
|
|
query = JSON.parse("{" + urlSpread + "}");
|
|
|
|
}
|
|
|
|
console.log('query1',query)
|
|
|
|
this.globalData.inviterId = query.id
|
|
|
|
}
|
|
|
|
} else{
|
|
|
|
query = e.query
|
|
|
|
console.log('query2',query)
|
|
|
|
this.globalData.inviterId = query.id
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setMenuHeight(){
|
|
|
|
wx.getSystemInfo({
|
|
|
|
success: res => {
|
|
|
|
// console.log(res)
|
|
|
|
this.globalData.navTopHeight = res.statusBarHeight;
|
|
|
|
this.globalData.CustomBar = res.statusBarHeight + 45;
|
|
|
|
this.globalData.systemInfo = res;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let menuButtonObj = wx.getMenuButtonBoundingClientRect();
|
|
|
|
this.globalData.menuTop = menuButtonObj.top;
|
|
|
|
// console.log(menuButtonObj)
|
|
|
|
this.globalData.menuHeight = menuButtonObj.height;
|
|
|
|
this.globalData.navHeight = menuButtonObj.height + (menuButtonObj.top - this.globalData.navTopHeight);
|
|
|
|
|
|
|
|
},
|
|
|
|
editTabbar: function () {
|
|
|
|
var tabbar = this.globalData.tabBar;
|
|
|
|
var currentPages = getCurrentPages();
|
|
|
|
var that = currentPages[currentPages.length - 1];
|
|
|
|
var pagePath = that.route;
|
|
|
|
(pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
|
|
|
|
for (var i in tabbar.list) {
|
|
|
|
tabbar.list[i].selected = false;
|
|
|
|
(tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
|
|
|
|
}
|
|
|
|
that.setData({
|
|
|
|
tabbar: tabbar
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getInfo(){
|
|
|
|
this.http('get','userinfo').then((res)=>{
|
|
|
|
if(res.data.success){
|
|
|
|
// console.log(res.data)
|
|
|
|
wx.setStorageSync('userInfo',res.data.data)
|
|
|
|
var pages = getCurrentPages().pop();//当前页面
|
|
|
|
if (pages.getUser){
|
|
|
|
pages.getUser();
|
|
|
|
}
|
|
|
|
} else{
|
|
|
|
wx.showToast({
|
|
|
|
title: res.data.msg,
|
|
|
|
icon: 'none',
|
|
|
|
duration: 2000
|
|
|
|
})
|
|
|
|
setTimeout(()=>{
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/pages/login/index',
|
|
|
|
})
|
|
|
|
},2000)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
http(mathods,url, params) {
|
|
|
|
var that = this;
|
|
|
|
var header = {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'version': '2.0',
|
|
|
|
'Authorization' : wx.getStorageSync('token') || ''
|
|
|
|
}
|
|
|
|
return new Promise(
|
|
|
|
(resolve,reject) => {
|
|
|
|
wx.showLoading({
|
|
|
|
title: "正在加载中...",
|
|
|
|
})
|
|
|
|
wx.request({
|
|
|
|
url: this.globalData.baseURL + url, //请求地址
|
|
|
|
method: mathods, //请求方法
|
|
|
|
header: header,
|
|
|
|
data: params || {}, //请求参数
|
|
|
|
success: res => {
|
|
|
|
wx.hideLoading();
|
|
|
|
console.log(res)
|
|
|
|
//判断token是否过期 res.data.code == 40001
|
|
|
|
if(!res.data.success && res.data.status == 401){
|
|
|
|
console.log('登陆失效')
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/pages/login/index',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
resolve(res);
|
|
|
|
//成功执行方法,参数值为res.data,直接将返回的数据传入
|
|
|
|
},
|
|
|
|
fail: function() {
|
|
|
|
//请求失败
|
|
|
|
wx.hideLoading();
|
|
|
|
wx.showToast({
|
|
|
|
title: '服务器错误,请稍后再试!',
|
|
|
|
icon : 'none'
|
|
|
|
})
|
|
|
|
reject(err)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
globalData: {
|
|
|
|
// baseURL : 'http://192.168.0.110:8092/api/',
|
|
|
|
baseURL : 'http://192.168.0.114:8092/api/',
|
|
|
|
// baseURL : 'https://www.cyjyyjy.com:8093/api/',
|
|
|
|
userInfo: null,
|
|
|
|
navHeight : 0,
|
|
|
|
navTopHeight: 0,
|
|
|
|
menuTop: 0,
|
|
|
|
menuHeight: 0,
|
|
|
|
CustomBar: 0,
|
|
|
|
inviterId: null , //分享码
|
|
|
|
systemInfo: null, //客户端设备信息
|
|
|
|
tabBar: {
|
|
|
|
"backgroundColor": "#ffffff",
|
|
|
|
"color": "#979795",
|
|
|
|
"selectedColor": "#FF6F34",
|
|
|
|
"list": [
|
|
|
|
{
|
|
|
|
"pagePath": "/pages/index/index",
|
|
|
|
"iconPath": "icon/home.png",
|
|
|
|
"selectedIconPath": "icon/home-a.png",
|
|
|
|
"text": "首页"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pagePath": "/pages/demandHall/index",
|
|
|
|
"iconPath": "icon/tab2.png",
|
|
|
|
"selectedIconPath": "icon/tab2-a.png",
|
|
|
|
"text": "供需大厅"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pagePath": "/pages/release/index",
|
|
|
|
"iconPath": "icon/icon_release.png",
|
|
|
|
"isSpecial": true,
|
|
|
|
"text": "发布"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pagePath": "/pages/life/index",
|
|
|
|
"iconPath": "icon/tab3.png",
|
|
|
|
"selectedIconPath": "icon/tab3-a.png",
|
|
|
|
"text": "生活"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pagePath": "/pages/user/index",
|
|
|
|
"iconPath": "icon/tab4.png",
|
|
|
|
"selectedIconPath": "icon/tab4-a.png",
|
|
|
|
"text": "我的"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|