代码拉取完成,页面将自动刷新
同步操作将从 夏日里的一把阳光/open-tally-app 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// app.js
App({
onLaunch() {
this.getMenuRect()
},
globalData: {
// api_base_url: 'http://dev.tally.com', // 开发环境
api_base_url: 'https://xxxxxxx', // 生产环境
menuRect: {}
},
// 获取导航信息
getMenuRect() {
const info = wx.getMenuButtonBoundingClientRect()
const winodwConfig = wx.getWindowInfo()
info.borderWidth = winodwConfig.windowWidth - info.right
this.globalData.menuRect = info
},
// 显示失败提示框
appShowError(msg, callback) {
wx.showModal({
title: '提示',
content: msg,
showCancel: false,
success(res) {
callback && callback();
}
});
},
// app 静默登陆
appSetLogin() {
const _this = this
wx.login({
success (res) {
if (res.code) {
_this.ajaxPost('/api/auth-login', {
code: res.code,
}, (res)=>{
if(res.code === 200){
wx.setStorageSync('token', res.data.token)
wx.reLaunch({
url: "/pages/tally/index"
});
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
// post请求
ajaxPost(url, data, success, fail, complete) {
const _this = this;
// 请求动画
wx.showNavigationBarLoading();
wx.showLoading({
mask: true,
title: '正在请求...',
})
wx.request({
url: _this.globalData.api_base_url + url,
header: {
'content-type': 'application/x-www-form-urlencoded',
'token': wx.getStorageSync('token') || ''
},
method: 'POST',
data: data,
success(res) {
if (res.statusCode !== 200) {
_this.appShowError('服务异常!');
return false;
} else {
if(res.data.code === 4000){
// 登录失效
wx.reLaunch({
url: "/pages/views/login"
});
return false
} else if (res.data.code !== 200 && res.data.code !== 4000) {
_this.appShowError(res.data.message, () => {
fail && fail(res);
});
return false;
}
}
success && success(res.data);
},
fail(res) {
_this.appShowError(res.errMsg, () => {
fail && fail(res);
});
},
complete(res) {
wx.hideNavigationBarLoading();
wx.hideLoading();
complete && complete(res);
}
});
},
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。