| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- // pages/mine/mine.js
- import { apple } from "../../config/config";
- import { SendEvent } from "../../utils/util";
- let interstitialAd = null;
- const app = getApp();
- Page({
- data: {
- userInfo: {},
- userCode: "", // 用户id
- },
- onLoad: function (options) {
- this.autoLogin();
- },
- onShow() {},
- onTabItemTap(item) {
- setTimeout(() => {
- this.interstitalPlayFn();
- }, 1000);
- console.log(item.index);
- },
- // 自动登录
- async autoLogin() {
- try {
- // 检查是否已经登录
- if (app.globalData.accessToken) {
- this.setData({
- isLoggedIn: true,
- userCode: app.globalData.userCode,
- });
- // 已经登录
- console.log("已经登录");
- // 页面首次加载时的处理
- this.interstitalLoad();
- return;
- }
- // 未登录,执行登录
- const res = await app.login().then((res) => {
- console.log("用户ID:", app.globalData.userCode);
- this.setData({
- isLoggedIn: true,
- userCode: app.globalData.userCode,
- });
- console.log("重新登录", res);
- this.interstitalLoad();
- });
- } catch (error) {
- console.error("登录失败:", error);
- }
- },
- // 插屏广告加载
- interstitalLoad() {
- let adId = apple.ads.insertAdId;
- interstitialAd = wx.createInterstitialAd({
- adUnitId: adId,
- });
- interstitialAd.onLoad(() => {
- console.log("我的页插屏广告onLoad");
- });
- interstitialAd.onError((err) => {
- console.log("我的页插屏广告onError", err);
- });
- interstitialAd.onClose(() => {
- console.log("我的页插屏广告onClose");
- });
- },
- // 插屏广告展示
- interstitalPlayFn() {
- if (interstitialAd) {
- interstitialAd.show().catch((err) => {
- console.error("我的页插屏显错误", err);
- });
- }
- },
- // onTabItemTap(item) {
- // console.log(item.index)
- // },
- goToReadingHistory() {
- SendEvent("mine_reading_history", { uuid: app.globalData.uuid });
- wx.switchTab({
- url: "/pages/bookshelf/bookshelf",
- });
- },
- });
|