feat: 後端API

This commit is contained in:
skytek_xinliang
2026-08-06 14:34:20 +08:00
parent db6fe95a11
commit 60c4a414a3
8 changed files with 230 additions and 74 deletions
+22 -2
View File
@@ -1,5 +1,9 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { login as apiLogin } from '@/api/auth'
/** 後端尚未完成前保持 true,改為 false 才會實際呼叫登入 API */
const USE_MOCK = import.meta.env.VITE_USE_MOCK !== 'false'
export interface UserProfile {
name: string
@@ -198,6 +202,8 @@ function createDefaultRadarData () {
export const useAppStore = defineStore('app', () => {
const isLoggedIn = ref(false)
/** 登入取得的使用者識別碼,課程建議等 API 需要此值查詢 */
const userID = ref('')
const userProfile = ref<UserProfile>(createDefaultUserProfile())
const selfAssessment = ref<SelfAssessment>(createDefaultSelfAssessment())
const appointments = ref<Appointment[]>(createDefaultAppointments())
@@ -224,13 +230,26 @@ export const useAppStore = defineStore('app', () => {
return Math.round((done / keys.length) * 100)
})
function login (phone: string) {
/** 手機門號登入;後端未完成時走模擬資料,完成後設 VITE_USE_MOCK=false 改打真實 API */
async function login (phone: string) {
if (USE_MOCK) {
isLoggedIn.value = true
userID.value = 'MOCK-USER'
userProfile.value.phone = phone
return
}
const response = await apiLogin(phone)
isLoggedIn.value = true
userProfile.value.phone = phone
userID.value = response.userID
userProfile.value.phone = response.phone
userProfile.value.name = response.userName
}
function logout () {
isLoggedIn.value = false
userID.value = ''
}
function updateProfile (profile: Partial<UserProfile>) {
@@ -374,6 +393,7 @@ export const useAppStore = defineStore('app', () => {
return {
isLoggedIn,
userID,
userProfile,
selfAssessment,
appointments,
+11 -5
View File
@@ -15,6 +15,7 @@ import {
fetchNight,
fetchNoon,
} from '@/api/course'
import { useAppStore } from '@/stores/app'
/** 後端尚未完成,預設走前端模擬資料;設定 VITE_USE_MOCK=false 即改打真實 API */
const USE_MOCK = import.meta.env.VITE_USE_MOCK !== 'false'
@@ -152,11 +153,16 @@ export const useCourseStore = defineStore('course', () => {
return
}
const [groupValue, morningValue, noonValue, nightValue] = await Promise.all([
fetchGroup(),
fetchMorning(),
fetchNoon(),
fetchNight(),
// 真實後端:course/group 需要 userIDcourse/morning、noon、night 需要 group
// 兩者有相依順序,因此無法四支平行呼叫(與 doc/課程建議API規格.md 的示意圖不同,
// 以 doc/課程建議_API_前端使用說明_20260806.md 的建議測試流程為準)
const { userID } = useAppStore()
const groupValue = await fetchGroup(userID)
const [morningValue, noonValue, nightValue] = await Promise.all([
fetchMorning(groupValue),
fetchNoon(groupValue),
fetchNight(groupValue),
])
group.value = groupValue