Files
youlegames/codes/minipro/calculation/miniprogram/pages/index/index.ts

136 lines
3.4 KiB
TypeScript
Raw 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.
// index.ts
import { config } from '../../config';
const app = getApp<IAppOption>()
const MATH_QUOTES = [
"万物皆数 — 毕达哥拉斯",
"数学是科学的女皇 — 高斯",
"几何无王者之道 — 欧几里得",
"数统治着宇宙 — 毕达哥拉斯",
"上帝是一位算术家 — 雅可比"
];
const COMMON_FORMULAS = [
{ title: "圆周率", value: "π ≈ 3.14159", icon: "🔴", desc: "无限不循环小数" },
{ title: "黄金分割", value: "φ ≈ 0.618", icon: "✨", desc: "美的比例" },
{ title: "自然常数", value: "e ≈ 2.718", icon: "📈", desc: "成长的极限" },
{ title: "勾股定理", value: "a² + b² = c²", icon: "📐", desc: "直角三角形" },
{ title: "欧拉公式", value: "e^(iπ) + 1 = 0", icon: "💫", desc: "最美公式" },
{ title: "光速", value: "c ≈ 3×10⁸ m/s", icon: "⚡", desc: "宇宙速度极限" }
];
Component({
data: {
userInfo: {
avatarUrl: config.defaultAvatarUrl,
nickName: '未登录'
},
hasUserInfo: false,
currentDate: '',
currentWeekday: '',
dailyQuote: '',
formulas: COMMON_FORMULAS
},
pageLifetimes: {
show() {
this.updateDateDisplay();
// 每次显示页面时,重新获取最新的用户信息
const session = wx.getStorageSync('USER_SESSION');
if (session && session.userInfo) {
this.setData({
userInfo: session.userInfo,
hasUserInfo: true
});
} else {
this.setData({
userInfo: {
avatarUrl: config.defaultAvatarUrl,
nickName: '未登录'
},
hasUserInfo: false
});
}
}
},
methods: {
onLoad() {
wx.showShareMenu({
withShareTicket: false,
menus: ['shareAppMessage', 'shareTimeline'] // 需要在 Component 中定义 onShareAppMessage
});
this.selectDailyQuote();
},
onShareAppMessage() {
return config.share;
},
onShareTimeline() {
return config.share;
},
updateDateDisplay() {
const now = new Date();
const month = now.getMonth() + 1;
const day = now.getDate();
const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
const weekday = weekdays[now.getDay()];
this.setData({
currentDate: `${month}${day}`,
currentWeekday: weekday
});
},
selectDailyQuote() {
// 简单的随机选择
const idx = Math.floor(Math.random() * MATH_QUOTES.length);
this.setData({ dailyQuote: MATH_QUOTES[idx] });
},
goToProfile() {
wx.switchTab({
url: '/pages/profile/profile'
});
},
goToCalculator() {
wx.navigateTo({
url: '/pages/calculator/calculator'
});
},
goToUnitConverter() {
wx.navigateTo({
url: '/pages/unit-converter/unit-converter'
});
},
goToDiscount() {
wx.navigateTo({
url: '/pages/discount/discount',
});
},
goToHistory() {
wx.navigateTo({
url: '/pages/history/history',
});
},
goToAbout() {
wx.navigateTo({
url: '/pages/about/about',
});
},
goToPrivacy() {
wx.navigateTo({
url: '/pages/privacy/privacy',
});
}
}
})