|
|
@@ -10,37 +10,29 @@ import {
|
|
|
} from '../../config/config'
|
|
|
|
|
|
let interstitialAd = null
|
|
|
-const app = getApp()
|
|
|
|
|
|
Page({
|
|
|
data: {
|
|
|
- gender: 'male', // 当前性别选择
|
|
|
- currentCategory: '', // 当前选中的分类
|
|
|
- categories: [],
|
|
|
- bookList: [],
|
|
|
- loading: false,
|
|
|
- keyword: '',
|
|
|
- page: 1,
|
|
|
- size: 10,
|
|
|
- hasMore: true, // 是否还有更多数据,
|
|
|
- isLoggedIn: false, //是否登录
|
|
|
+ gender: 'male', // 当前性别选择
|
|
|
+ currentCategory: '', // 当前选中的分类
|
|
|
+ categories: [],
|
|
|
+ bookList: [],
|
|
|
+ loading: false,
|
|
|
+ keyword: '',
|
|
|
+ page: 1,
|
|
|
+ size: 10,
|
|
|
+ hasMore: true, // 是否还有更多数据,
|
|
|
+ isLoggedIn: false, //是否登录
|
|
|
},
|
|
|
|
|
|
onLoad: function (options) {
|
|
|
- app.autoLogin();
|
|
|
- if (app.globalData.isLogin) {
|
|
|
- setTimeout(() => {
|
|
|
- console.log('加载分类列表')
|
|
|
- // 页面首次加载时的处理
|
|
|
- this.syncGenderState();
|
|
|
- this.interstitalLoad();
|
|
|
- }, 1500);
|
|
|
- }
|
|
|
+ this.autoLogin();
|
|
|
},
|
|
|
|
|
|
onShow: function () {
|
|
|
- // 每次页面显示时同步性别状态
|
|
|
+ if (this.data.isLoggedIn) {
|
|
|
this.syncGenderState();
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
onTabItemTap: function (item) {
|
|
|
@@ -48,37 +40,39 @@ Page({
|
|
|
setTimeout(() => {
|
|
|
this.interstitalPlayFn()
|
|
|
}, 1000)
|
|
|
- // tabBar 点击时同步性别状态
|
|
|
- this.syncGenderState();
|
|
|
+ if (this.data.isLoggedIn) {
|
|
|
+ this.syncGenderState();
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// 自动登录
|
|
|
async autoLogin() {
|
|
|
- try {
|
|
|
- // 检查是否已经登录
|
|
|
- const token = wx.getStorageSync('accessToken');
|
|
|
- if (token) {
|
|
|
- this.setData({
|
|
|
- isLoggedIn: true
|
|
|
- });
|
|
|
- // 已经登录
|
|
|
- console.log('已经登录')
|
|
|
- // 页面首次加载时的处理
|
|
|
- this.syncGenderState();
|
|
|
- this.interstitalLoad();
|
|
|
- return;
|
|
|
- }
|
|
|
- // 未登录,执行登录
|
|
|
- const res = this.login(promotionid);
|
|
|
- this.setData({
|
|
|
- isLoggedIn: true
|
|
|
- });
|
|
|
- // 页面首次加载时的处理
|
|
|
- this.syncGenderState();
|
|
|
- this.interstitalLoad();
|
|
|
- } catch (error) {
|
|
|
- console.error('登录失败:', error);
|
|
|
+ try {
|
|
|
+ // 检查是否已经登录
|
|
|
+ const token = wx.getStorageSync('accessToken');
|
|
|
+ if (token) {
|
|
|
+ this.setData({
|
|
|
+ isLoggedIn: true
|
|
|
+ });
|
|
|
+ // 已经登录
|
|
|
+ console.log('已经登录')
|
|
|
+ // 页面首次加载时的处理
|
|
|
+ this.syncGenderState();
|
|
|
+ this.interstitalLoad();
|
|
|
+ return;
|
|
|
}
|
|
|
+ // 未登录,执行登录
|
|
|
+ getApp().login().then(res => {
|
|
|
+ this.setData({
|
|
|
+ isLoggedIn: true
|
|
|
+ });
|
|
|
+ this.syncGenderState();
|
|
|
+ this.interstitalLoad();
|
|
|
+ console.log('重新登录', res)
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('登录失败:', error);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// 插屏广告加载
|
|
|
@@ -115,6 +109,8 @@ Page({
|
|
|
gender
|
|
|
});
|
|
|
await this.loadCategories();
|
|
|
+ } else {
|
|
|
+ await this.loadCategories();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -130,7 +126,9 @@ Page({
|
|
|
page: 1,
|
|
|
hasMore: true
|
|
|
});
|
|
|
- await this.loadCategories();
|
|
|
+ if (this.data.isLoggedIn) {
|
|
|
+ await this.loadCategories();
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// 加载分类列表
|