Files
edu_mp/app.js
panw 8fc4630bb5 refactor(app): 移除分类和详情模块,新增云开发测试页
- 从项目中删除分类页及相关代码和样式文件
- 从项目中删除详情页及相关代码和样式文件
- 首页简化为欢迎界面并添加跳转云开发测试页入口
- 更新自定义底部栏移除分类入口
- 更新app.js初始化云开发环境
- 修改app.json移除分类页面配置
- 调整首页样式和交互,提高简洁度
- 配置云函数目录路径cloudfunctionRoot为cloudfunctions/
2025-12-05 15:58:08 +08:00

66 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// app.js
App({
onLaunch() {
// 初始化云开发环境
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力');
} else {
wx.cloud.init({
// 环境ID请替换为你的云开发环境ID
env: 'your-env-id',
traceUser: true
});
}
this.initApp();
},
globalData: {
userInfo: null,
baseUrl: 'https://api.example.com', // API基础地址
token: ''
},
// 初始化应用
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');
}
});