diff --git a/src/service/api/score.ts b/src/service/api/score.ts
index e4eeea7..32b4501 100644
--- a/src/service/api/score.ts
+++ b/src/service/api/score.ts
@@ -35,5 +35,5 @@ export function saveScore(data: SaveScoreRequest) {
}
export function getScore() {
- return request.get('/user/score')
+ return request.get('/user/score', {params: { educationalLevel: '' }, showLoading: false})
}
diff --git a/src/service/request/index.ts b/src/service/request/index.ts
index 461516b..5dcf20d 100644
--- a/src/service/request/index.ts
+++ b/src/service/request/index.ts
@@ -94,6 +94,9 @@ class Request {
case 404:
msg = backendMsg || 'Not Found'
break
+ case 429:
+ msg = backendMsg || 'Too Many Requests'
+ break
case 500:
msg = backendMsg || 'Internal Server Error'
break
diff --git a/src/stores/user.ts b/src/stores/user.ts
index b61b40f..2e877ea 100644
--- a/src/stores/user.ts
+++ b/src/stores/user.ts
@@ -55,8 +55,10 @@ export const useUserStore = defineStore('user', () => {
async function login(params: LoginParams) {
try {
const data = await apiLogin(params)
- setToken(data.token)
- setUserInfo(data.user)
+ if (data.token && data.user) {
+ setToken(data.token)
+ setUserInfo(data.user)
+ }
return data
} catch (error) {
throw error
diff --git a/task_detail.md b/task_detail.md
index edd76ff..a8dcdd2 100644
--- a/task_detail.md
+++ b/task_detail.md
@@ -1,15 +1,64 @@
# Task Detail
-## 2025-12-18 Session 6
+## 2025-12-18 Session 7
### Execution Reason
-User asked how to update the navigation state after login.
+User requested to implement the score API (Task 2) and integrate it into the application.
### Execution Process
-1. **Investigation**: Checked `src/components/TheNavigation.vue` and `src/pages/index.vue`. Found they were accessing `userStore.user`, but the store (updated in Session 1) actually exposes `userStore.userInfo`.
-2. **Fix**: Replaced all occurrences of `userStore.user` with `userStore.userInfo` in both `TheNavigation.vue` and `index.vue`.
-3. **Result**: Since Pinia stores are reactive, correctly binding to `userStore.userInfo` ensures that when `userStore.login` updates `userInfo`, the UI (Navigation and Home page) automatically re-renders to show the logged-in state (username, logout button, etc.).
+1. **API Encapsulation**:
+ - Found `成绩修改api.md` describing `/user/score` (GET) and `/user/score/save-score` (POST).
+ - Created `src/service/api/score.ts` defining `SaveScoreRequest` and `ScoreInfo` types and request functions.
+2. **State Management**:
+ - Created `src/stores/score.ts` using Pinia to manage score data (`fetchScore`, `saveScore`).
+3. **Navigation Integration**:
+ - Modified `src/components/TheNavigation.vue` to use `useScoreStore`.
+ - On login/mount, it fetches the score.
+ - On logout, it clears the score.
+ - Displayed score info (Category, Cultural Score) in the navigation bar instead of hardcoded values.
+4. **Form Integration**:
+ - Updated `src/components/ScoreForm.vue` to use `useScoreStore`.
+ - Populated form with existing score data on mount/watch.
+ - Implemented `handleSubmit` to call `scoreStore.saveScore` before emitting `confirm`.
+ - Mapped frontend form data to backend API request structure.
### Execution Result
-- Fixed the reactivity issue by correcting the property name from `user` to `userInfo`.
-- Navigation bar will now correctly toggle between "Login" and "User Profile" upon successful login.
+- Score management is now fully integrated.
+- User can view their score in the navigation bar.
+- User can edit and save their score using the score form.
+
+## 2025-12-18 Session 8
+
+### Execution Reason
+User re-iterated the request to ensure score API encapsulation and integration, likely for verification or summary.
+
+### Execution Process
+1. **Verification**:
+ - Verified `src/service/api/score.ts` implementation matches `成绩修改api.md`.
+ - Verified `src/stores/score.ts` correctly handles async actions.
+ - Verified `src/components/ScoreForm.vue` integrates with the store for both loading and saving data.
+2. **Documentation Update**:
+ - Updated `project_task.md` to mark all Task 2 items as completed.
+ - Updated `project_doing.md` with verification step.
+
+### Execution Result
+- Confirmed all score-related tasks are completed and code is correct.
+- Documentation is up to date.
+
+## 2025-12-18 Session 9
+
+### Execution Reason
+User reported that score data is lost (becomes null) in `ScoreForm.vue` after page refresh.
+
+### Execution Process
+1. **Analysis**:
+ - Identified that `src/stores/score.ts` lacks persistence (by design) and relies on runtime fetching.
+ - Found that `ScoreForm.vue` only calls `initForm` on mount, which does nothing if `scoreStore.scoreInfo` is null.
+ - On page refresh, the store is reset, so the form remains empty.
+2. **Fix**:
+ - Modified `src/components/ScoreForm.vue`'s `onMounted` hook.
+ - Added logic: if `scoreStore.scoreInfo` is missing, call `scoreStore.fetchScore()`.
+ - Existing watcher on `scoreInfo` will handle populating the form once data arrives.
+
+### Execution Result
+- `ScoreForm` now robustly handles page refreshes by fetching data on demand if needed.
diff --git a/tasks/Task2.md b/tasks/Task2.md
new file mode 100644
index 0000000..1253f09
--- /dev/null
+++ b/tasks/Task2.md
@@ -0,0 +1,3 @@
+我需要你帮我参考#成绩修改api.md文件,根据接口文档内容。封装成绩相关的文件,用于封装每个接口的请求方法,包括请求参数、请求方法、请求路径等。
+参考/src/service/api/auth.ts文件,封装一个src/service/api/score.ts文件及其相关的类型定义文件,用于封装成绩相关的接口请求方法,包括请求参数、请求方法、请求路径等。利用好pinia插件。
+之后在业务代码中调用成绩相关的接口请求方法,如获取当前用户的当前分数、修改当前用户的当前分数等。
\ No newline at end of file