1
This commit is contained in:
150
pages/gpa/gpa.js
Normal file
150
pages/gpa/gpa.js
Normal file
@@ -0,0 +1,150 @@
|
||||
// pages/gpa/gpa.js
|
||||
const { calculateGPA, showSuccess, showError } = require('../../utils/util.js')
|
||||
const learningTracker = require('../../utils/learningTracker.js')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
courses: [],
|
||||
courseName: '',
|
||||
courseScore: '',
|
||||
courseCredit: '',
|
||||
totalGPA: 0,
|
||||
totalCredits: 0
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadCourses()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
// 开始跟踪学习时间
|
||||
learningTracker.onPageShow('tools')
|
||||
},
|
||||
|
||||
onHide() {
|
||||
// 停止跟踪学习时间
|
||||
learningTracker.onPageHide()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
// 记录学习时长
|
||||
learningTracker.onPageUnload()
|
||||
},
|
||||
|
||||
// 加载已保存的课程
|
||||
loadCourses() {
|
||||
const courses = wx.getStorageSync('gpaCourses') || []
|
||||
this.setData({ courses })
|
||||
this.calculateTotal()
|
||||
},
|
||||
|
||||
// 课程名称输入
|
||||
onNameInput(e) {
|
||||
this.setData({ courseName: e.detail.value })
|
||||
},
|
||||
|
||||
// 成绩输入
|
||||
onScoreInput(e) {
|
||||
this.setData({ courseScore: e.detail.value })
|
||||
},
|
||||
|
||||
// 学分输入
|
||||
onCreditInput(e) {
|
||||
this.setData({ courseCredit: e.detail.value })
|
||||
},
|
||||
|
||||
// 添加课程
|
||||
onAddCourse() {
|
||||
const { courseName, courseScore, courseCredit, courses } = this.data
|
||||
|
||||
if (!courseName.trim()) {
|
||||
showError('请输入课程名称')
|
||||
return
|
||||
}
|
||||
|
||||
const score = parseFloat(courseScore)
|
||||
const credit = parseFloat(courseCredit)
|
||||
|
||||
if (isNaN(score) || score < 0 || score > 100) {
|
||||
showError('请输入有效的成绩(0-100)')
|
||||
return
|
||||
}
|
||||
|
||||
if (isNaN(credit) || credit <= 0) {
|
||||
showError('请输入有效的学分')
|
||||
return
|
||||
}
|
||||
|
||||
const newCourse = {
|
||||
id: Date.now(),
|
||||
name: courseName.trim(),
|
||||
score: score,
|
||||
credit: credit
|
||||
}
|
||||
|
||||
courses.push(newCourse)
|
||||
wx.setStorageSync('gpaCourses', courses)
|
||||
|
||||
this.setData({
|
||||
courses,
|
||||
courseName: '',
|
||||
courseScore: '',
|
||||
courseCredit: ''
|
||||
})
|
||||
|
||||
this.calculateTotal()
|
||||
showSuccess('添加成功')
|
||||
},
|
||||
|
||||
// 删除课程
|
||||
onDeleteCourse(e) {
|
||||
const { id } = e.currentTarget.dataset
|
||||
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除这门课程吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
let { courses } = this.data
|
||||
courses = courses.filter(course => course.id !== id)
|
||||
wx.setStorageSync('gpaCourses', courses)
|
||||
|
||||
this.setData({ courses })
|
||||
this.calculateTotal()
|
||||
showSuccess('删除成功')
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 计算总GPA
|
||||
calculateTotal() {
|
||||
const { courses } = this.data
|
||||
const gpa = calculateGPA(courses)
|
||||
const totalCredits = courses.reduce((sum, course) => sum + course.credit, 0)
|
||||
|
||||
this.setData({
|
||||
totalGPA: gpa,
|
||||
totalCredits: totalCredits
|
||||
})
|
||||
},
|
||||
|
||||
// 清空所有
|
||||
onClearAll() {
|
||||
wx.showModal({
|
||||
title: '确认清空',
|
||||
content: '确定要清空所有课程吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.removeStorageSync('gpaCourses')
|
||||
this.setData({
|
||||
courses: [],
|
||||
totalGPA: 0,
|
||||
totalCredits: 0
|
||||
})
|
||||
showSuccess('已清空')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
3
pages/gpa/gpa.json
Normal file
3
pages/gpa/gpa.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "GPA计算器"
|
||||
}
|
||||
72
pages/gpa/gpa.wxml
Normal file
72
pages/gpa/gpa.wxml
Normal file
@@ -0,0 +1,72 @@
|
||||
<!--pages/gpa/gpa.wxml-->
|
||||
<view class="container">
|
||||
<!-- GPA显示卡片 -->
|
||||
<view class="gpa-card">
|
||||
<view class="gpa-label">当前GPA</view>
|
||||
<view class="gpa-value">{{totalGPA}}</view>
|
||||
<view class="credits-info">总学分:{{totalCredits}}</view>
|
||||
</view>
|
||||
|
||||
<!-- 添加课程表单 -->
|
||||
<view class="form-card">
|
||||
<view class="form-title">添加课程</view>
|
||||
|
||||
<view class="form-row">
|
||||
<input
|
||||
class="form-input"
|
||||
placeholder="课程名称"
|
||||
value="{{courseName}}"
|
||||
bindinput="onNameInput"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="form-row-group">
|
||||
<view class="form-row half">
|
||||
<input
|
||||
class="form-input"
|
||||
type="digit"
|
||||
placeholder="成绩"
|
||||
value="{{courseScore}}"
|
||||
bindinput="onScoreInput"
|
||||
/>
|
||||
</view>
|
||||
<view class="form-row half">
|
||||
<input
|
||||
class="form-input"
|
||||
type="digit"
|
||||
placeholder="学分"
|
||||
value="{{courseCredit}}"
|
||||
bindinput="onCreditInput"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button class="add-btn" bindtap="onAddCourse">添加课程</button>
|
||||
</view>
|
||||
|
||||
<!-- 课程列表 -->
|
||||
<view class="courses-section" wx:if="{{courses.length > 0}}">
|
||||
<view class="section-header">
|
||||
<text class="section-title">课程列表</text>
|
||||
<text class="clear-btn" bindtap="onClearAll">清空</text>
|
||||
</view>
|
||||
|
||||
<view class="course-item" wx:for="{{courses}}" wx:key="id">
|
||||
<view class="course-info">
|
||||
<view class="course-name">{{item.name}}</view>
|
||||
<view class="course-details">
|
||||
<text class="detail-item">成绩:{{item.score}}</text>
|
||||
<text class="detail-item">学分:{{item.credit}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
class="delete-btn"
|
||||
data-id="{{item.id}}"
|
||||
bindtap="onDeleteCourse"
|
||||
>
|
||||
🗑️
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
328
pages/gpa/gpa.wxss
Normal file
328
pages/gpa/gpa.wxss
Normal file
@@ -0,0 +1,328 @@
|
||||
/* pages/gpa/gpa.wxss */
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
|
||||
padding: 30rpx;
|
||||
animation: fadeIn 0.5s ease-out;
|
||||
}
|
||||
|
||||
/* GPA卡片 */
|
||||
.gpa-card {
|
||||
background: linear-gradient(135deg, #FF6B6B 0%, #FF8E8E 100%);
|
||||
border-radius: 24rpx;
|
||||
padding: 50rpx 30rpx;
|
||||
text-align: center;
|
||||
color: #ffffff;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 12rpx 32rpx rgba(255, 107, 107, 0.4);
|
||||
animation: scaleIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.gpa-card::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -50%;
|
||||
left: -50%;
|
||||
width: 200%;
|
||||
height: 200%;
|
||||
background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 70%);
|
||||
animation: float 6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% { transform: translate(0, 0); }
|
||||
50% { transform: translate(30rpx, 30rpx); }
|
||||
}
|
||||
|
||||
.gpa-label {
|
||||
font-size: 28rpx;
|
||||
opacity: 0.95;
|
||||
margin-bottom: 15rpx;
|
||||
position: relative;
|
||||
letter-spacing: 2rpx;
|
||||
}
|
||||
|
||||
.gpa-value {
|
||||
font-size: 96rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 15rpx;
|
||||
position: relative;
|
||||
text-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
|
||||
animation: pulse 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.credits-info {
|
||||
font-size: 26rpx;
|
||||
opacity: 0.9;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* 表单卡片 */
|
||||
.form-card {
|
||||
background: linear-gradient(135deg, #ffffff 0%, #fafbfc 100%);
|
||||
border-radius: 20rpx;
|
||||
padding: 35rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
|
||||
animation: slideInUp 0.6s ease-out 0.2s both;
|
||||
}
|
||||
|
||||
.form-title {
|
||||
font-size: 34rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
margin-bottom: 30rpx;
|
||||
position: relative;
|
||||
padding-bottom: 15rpx;
|
||||
}
|
||||
|
||||
.form-title::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 60rpx;
|
||||
height: 4rpx;
|
||||
background: linear-gradient(to right, #FF6B6B, #FF8E8E);
|
||||
border-radius: 2rpx;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
margin-bottom: 25rpx;
|
||||
}
|
||||
|
||||
.form-row-group {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 25rpx;
|
||||
}
|
||||
|
||||
.form-row.half {
|
||||
flex: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
padding: 0 28rpx;
|
||||
background-color: #f8f9fa;
|
||||
border: 2rpx solid #e9ecef;
|
||||
border-radius: 16rpx;
|
||||
font-size: 28rpx;
|
||||
box-sizing: border-box;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.form-input:focus {
|
||||
background-color: #ffffff;
|
||||
border-color: #FF6B6B;
|
||||
box-shadow: 0 0 0 4rpx rgba(255, 107, 107, 0.1);
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
width: 100%;
|
||||
height: 96rpx;
|
||||
line-height: 96rpx;
|
||||
background: linear-gradient(135deg, #FF6B6B 0%, #FF8E8E 100%);
|
||||
color: #ffffff;
|
||||
border-radius: 48rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
box-shadow: 0 8rpx 20rpx rgba(255, 107, 107, 0.3);
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.add-btn:active {
|
||||
transform: scale(0.98);
|
||||
box-shadow: 0 4rpx 12rpx rgba(255, 107, 107, 0.3);
|
||||
}
|
||||
|
||||
/* 课程列表 */
|
||||
.courses-section {
|
||||
background: linear-gradient(135deg, #ffffff 0%, #fafbfc 100%);
|
||||
border-radius: 20rpx;
|
||||
padding: 35rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
|
||||
animation: slideInUp 0.6s ease-out 0.3s both;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 34rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
position: relative;
|
||||
padding-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.section-title::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 50rpx;
|
||||
height: 3rpx;
|
||||
background: linear-gradient(to right, #FF6B6B, #FF8E8E);
|
||||
border-radius: 2rpx;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
font-size: 26rpx;
|
||||
color: #FF6B6B;
|
||||
padding: 12rpx 24rpx;
|
||||
background-color: rgba(255, 107, 107, 0.1);
|
||||
border-radius: 20rpx;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.clear-btn:active {
|
||||
background-color: rgba(255, 107, 107, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
.course-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 30rpx;
|
||||
background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
|
||||
border-radius: 16rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
animation: slideInLeft 0.5s ease-out;
|
||||
}
|
||||
|
||||
.course-item::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 6rpx;
|
||||
background: linear-gradient(to bottom, #FF6B6B, #FF8E8E);
|
||||
transform: scaleY(0);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.course-item:active::before {
|
||||
transform: scaleY(1);
|
||||
}
|
||||
|
||||
.course-item:active {
|
||||
transform: translateX(8rpx);
|
||||
box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.course-item:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.course-item:nth-child(1) { animation-delay: 0.1s; }
|
||||
.course-item:nth-child(2) { animation-delay: 0.15s; }
|
||||
.course-item:nth-child(3) { animation-delay: 0.2s; }
|
||||
.course-item:nth-child(4) { animation-delay: 0.25s; }
|
||||
.course-item:nth-child(5) { animation-delay: 0.3s; }
|
||||
|
||||
.course-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.course-name {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.course-details {
|
||||
display: flex;
|
||||
gap: 30rpx;
|
||||
}
|
||||
|
||||
.detail-item {
|
||||
font-size: 24rpx;
|
||||
color: #666666;
|
||||
padding: 6rpx 16rpx;
|
||||
background-color: rgba(255, 107, 107, 0.08);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
font-size: 44rpx;
|
||||
padding: 12rpx;
|
||||
color: #ff4757;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.delete-btn:active {
|
||||
transform: scale(1.2) rotate(90deg);
|
||||
color: #ff6b6b;
|
||||
}
|
||||
|
||||
/* 提示卡片 */
|
||||
.tips-card {
|
||||
background: linear-gradient(135deg, #ffffff 0%, #fafbfc 100%);
|
||||
border-radius: 20rpx;
|
||||
padding: 35rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
|
||||
animation: slideInUp 0.6s ease-out 0.4s both;
|
||||
}
|
||||
|
||||
.tips-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
margin-bottom: 24rpx;
|
||||
position: relative;
|
||||
padding-left: 20rpx;
|
||||
}
|
||||
|
||||
.tips-title::before {
|
||||
content: '💡';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: -2rpx;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.tips-content {
|
||||
font-size: 26rpx;
|
||||
color: #666666;
|
||||
line-height: 2.2;
|
||||
padding-left: 20rpx;
|
||||
}
|
||||
|
||||
.tip-item {
|
||||
margin-bottom: 12rpx;
|
||||
position: relative;
|
||||
padding-left: 24rpx;
|
||||
animation: fadeIn 0.8s ease-out;
|
||||
}
|
||||
|
||||
.tip-item::before {
|
||||
content: '•';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
color: #FF6B6B;
|
||||
font-weight: bold;
|
||||
font-size: 32rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.tip-item:nth-child(1) { animation-delay: 0.5s; }
|
||||
.tip-item:nth-child(2) { animation-delay: 0.6s; }
|
||||
.tip-item:nth-child(3) { animation-delay: 0.7s; }
|
||||
.tip-item:nth-child(4) { animation-delay: 0.8s; }
|
||||
.tip-item:nth-child(5) { animation-delay: 0.9s; }
|
||||
Reference in New Issue
Block a user