Files
client-qgdzs/pages/index/index.vue

206 lines
3.9 KiB
Vue

<template>
<view class="container">
<view class="header">
<view class="welcome">
<text class="welcome-title">趣味答题</text>
</view>
<view v-if="!isNotLoggedIn" class="point-card">
<view class="point-info">
<text class="point-label">学识分</text>
<text class="point-value">{{ point }}</text>
</view>
<view class="point-level">
<text class="level-text">{{ pointLevel }}</text>
</view>
</view>
<view v-else class="login-card" @click="handleLogin">
<text class="login-icon">🔐</text>
<text class="login-title">登录即可累计与查看学识分</text>
<text class="login-subtitle">点击登录</text>
</view>
</view>
</view>
</template>
<script>
import api from '../../utils/api.js'
export default {
data() {
return {
isNotLoggedIn: false,
point: 0,
pointLevel: '',
pointLoading: false
}
},
onLoad() {
this.loadPointInfo()
},
onShow() {
this.loadPointInfo()
},
methods: {
async loadPointInfo() {
this.pointLoading = true
try {
const res = await api.getPointInfo()
if (res.data) {
this.point = parseInt(res.data.point) || 0
this.pointLevel = this.getPointLevel(this.point)
this.isNotLoggedIn = false
}
} catch (error) {
console.error('获取学识分失败:', error)
// 检查是否是401错误
if (error.message && error.message.includes('401')) {
this.isNotLoggedIn = true
}
} finally {
this.pointLoading = false
}
},
getPointLevel(point) {
if (point < 100) return '幼儿园'
if (point < 300) return '小学生'
if (point < 600) return '初中生'
if (point < 1000) return '高中生'
if (point < 1500) return '大学生'
if (point < 2000) return '硕士'
return '博士'
},
handleLogin() {
uni.navigateTo({
url: '/pages/login/login'
})
}
}
}
</script>
<style scoped>
.container {
min-height: 100vh;
width: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 40rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.header {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.welcome {
text-align: center;
margin-bottom: 60rpx;
}
.welcome-title {
display: block;
font-size: 48rpx;
font-weight: bold;
color: #ffffff;
}
.point-card {
background: rgba(255, 255, 255, 0.2);
border-radius: 20rpx;
padding: 30rpx;
margin: 0 auto;
width: 90%;
max-width: 400rpx;
backdrop-filter: blur(10rpx);
border: 2rpx solid rgba(255, 255, 255, 0.3);
}
.point-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
}
.point-label {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.9);
font-weight: bold;
}
.point-value {
font-size: 48rpx;
font-weight: bold;
color: #ffffff;
text-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.2);
}
.point-level {
display: flex;
justify-content: center;
}
.level-text {
font-size: 32rpx;
font-weight: bold;
color: #ffffff;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 10rpx 40rpx;
border-radius: 30rpx;
box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.15);
}
.login-card {
background: rgba(255, 255, 255, 0.2);
border-radius: 20rpx;
padding: 40rpx;
margin: 0 auto;
width: 90%;
max-width: 400rpx;
backdrop-filter: blur(10rpx);
border: 2rpx solid rgba(255, 255, 255, 0.3);
display: flex;
flex-direction: column;
align-items: center;
gap: 20rpx;
transition: all 0.3s;
}
.login-card:active {
transform: scale(0.98);
background: rgba(255, 255, 255, 0.3);
}
.login-icon {
font-size: 80rpx;
}
.login-title {
font-size: 28rpx;
font-weight: bold;
color: #ffffff;
text-align: center;
line-height: 1.4;
}
.login-subtitle {
font-size: 24rpx;
color: rgba(255, 255, 255, 0.9);
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 10rpx 40rpx;
border-radius: 30rpx;
margin-top: 10rpx;
}
</style>