初始
This commit is contained in:
54
app.js
Normal file
54
app.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// app.js
|
||||
App({
|
||||
globalData: {
|
||||
userInfo: null,
|
||||
baseUrl: 'https://api.example.com', // API基础地址
|
||||
token: ''
|
||||
},
|
||||
|
||||
onLaunch() {
|
||||
// 小程序启动时执行
|
||||
this.initApp();
|
||||
},
|
||||
|
||||
// 初始化应用
|
||||
initApp() {
|
||||
// 获取本地存储的token
|
||||
const token = wx.getStorageSync('token');
|
||||
if (token) {
|
||||
this.globalData.token = token;
|
||||
}
|
||||
|
||||
// 获取系统信息
|
||||
this.getSystemInfo();
|
||||
},
|
||||
|
||||
// 获取系统信息
|
||||
getSystemInfo() {
|
||||
try {
|
||||
const systemInfo = wx.getSystemInfoSync();
|
||||
this.globalData.systemInfo = systemInfo;
|
||||
this.globalData.statusBarHeight = systemInfo.statusBarHeight;
|
||||
this.globalData.navBarHeight = systemInfo.platform === 'ios' ? 44 : 48;
|
||||
} catch (e) {
|
||||
console.error('获取系统信息失败', e);
|
||||
}
|
||||
},
|
||||
|
||||
// 检查登录状态
|
||||
checkLogin() {
|
||||
return !!this.globalData.token;
|
||||
},
|
||||
|
||||
// 设置Token
|
||||
setToken(token) {
|
||||
this.globalData.token = token;
|
||||
wx.setStorageSync('token', token);
|
||||
},
|
||||
|
||||
// 清除Token
|
||||
clearToken() {
|
||||
this.globalData.token = '';
|
||||
wx.removeStorageSync('token');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user