Files
YelayMaths/yelaymaths/pages/wode/wode.js
T
2026-09-30 03:38:10 +08:00

91 lines
2.4 KiB
JavaScript

// pages/wode/wode.js
const api = require('../../utils/api');
const store = require('../../utils/store');
const config = require('../../config/index');
const app = getApp();
Page({
data: {
showCode: false,
headiconUrl: '',
isLoggedIn: false,
userNameText: '未登录',
loginBtnText: '登录注册',
version: '',
qrcodeUrl: '',
text2: '',
text3: '',
text4: '',
text5: '',
text6: '',
},
onLoad() {
app.ready().then(() => {
this.applyConfig();
this.applyUser();
});
},
onShow() {
if (store.getSiteConfig() && Object.keys(store.getSiteConfig()).length) this.applyConfig();
this.applyUser();
},
applyConfig() {
const qrcodeName = store.cfg('profile.qrcode_image');
this.setData({
version: store.cfg('site.version'),
text2: store.cfg('profile.menu.change_info'),
text3: store.cfg('profile.menu.share'),
text4: store.cfg('profile.menu.contact'),
text5: store.cfg('profile.menu.wechat'),
text6: store.cfg('profile.qrcode_caption'),
qrcodeUrl: qrcodeName ? config.STATIC_BASE_URL + '/Images/WXCode/' + qrcodeName + '.png' : '',
});
},
applyUser() {
const user = store.getUser();
// 「已登录」看的是用户主动登录过没有(服务端记着这一位),不是有没有 token
const registered = !!(user && user.isLogin === 1);
this.setData({
isLoggedIn: registered,
userNameText: registered ? user.nickname : '未登录',
loginBtnText: registered ? '退出登录' : '登录注册',
// 未登录一律用默认头像:静默登录仍会带回上次设置的头像,
// 不挡住的话退出登录后还会显示用户自己的头像。
headiconUrl:
registered && user.headiconUrl
? user.headiconUrl
: config.STATIC_BASE_URL + config.PLACEHOLDER.USER,
});
},
toLoginOrOut() {
wx.navigateTo({ url: '/pages/LoginOrOutDetails/LoginOrOutDetails' });
},
toChangeUserInfo() {
if (!this.data.isLoggedIn) {
wx.showToast({ mask: true, icon: 'error', title: '请先登录' });
return;
}
wx.navigateTo({ url: '/pages/ChangeUserInfo/ChangeUserInfo' });
},
showQrcode() {
this.setData({ showCode: true });
},
onCodeClose() {
this.setData({ showCode: false });
},
onShareAppMessage() {
return { title: '叶雷讲数学', path: '/pages/index/index' };
},
});