增加小程序,修改游戏前端
This commit is contained in:
79
games/minipro/calculation/miniprogram/pages/index/index.ts
Normal file
79
games/minipro/calculation/miniprogram/pages/index/index.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
// index.ts
|
||||
import { config } from '../../config';
|
||||
|
||||
const app = getApp<IAppOption>()
|
||||
|
||||
Component({
|
||||
data: {
|
||||
userInfo: {
|
||||
avatarUrl: config.defaultAvatarUrl,
|
||||
nickName: '未登录'
|
||||
},
|
||||
hasUserInfo: false,
|
||||
greeting: ''
|
||||
},
|
||||
pageLifetimes: {
|
||||
show() {
|
||||
this.updateGreeting();
|
||||
// 每次显示页面时,重新获取最新的用户信息
|
||||
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: {
|
||||
updateGreeting() {
|
||||
const hour = new Date().getHours();
|
||||
let greeting = '';
|
||||
if (hour < 5) greeting = '夜深了,注意休息';
|
||||
else if (hour < 9) greeting = '早上好,新的一天';
|
||||
else if (hour < 12) greeting = '上午好';
|
||||
else if (hour < 14) greeting = '中午好';
|
||||
else if (hour < 19) greeting = '下午好';
|
||||
else greeting = '晚上好';
|
||||
this.setData({ greeting });
|
||||
},
|
||||
|
||||
goToProfile() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/profile/profile'
|
||||
});
|
||||
},
|
||||
|
||||
goToCalculator() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/calculator/calculator'
|
||||
});
|
||||
},
|
||||
|
||||
goToUnitConverter() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/unit-converter/unit-converter'
|
||||
});
|
||||
},
|
||||
|
||||
goToRelativeCalculator() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/relative/relative'
|
||||
});
|
||||
},
|
||||
|
||||
goToRandomDraw() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/random-draw/random-draw'
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user