fix: 自評API

This commit is contained in:
skytek_xinliang
2026-09-21 16:29:37 +08:00
parent b8997975a5
commit fdc93142d9
2 changed files with 48 additions and 5 deletions
@@ -491,7 +491,7 @@
variant="flat" variant="flat"
@click="handleAppointment" @click="handleAppointment"
> >
{{ APPOINTMENT_ENABLED ? "立即預約" : "預約功能尚未開放" }} {{ APPOINTMENT_ENABLED ? "立即預約" : "註冊會員" }}
</v-btn> </v-btn>
</div> </div>
</v-card-actions> </v-card-actions>
@@ -506,7 +506,7 @@
to="/" to="/"
variant="outlined" variant="outlined"
> >
回首頁健康儀表板 回首頁
</v-btn> </v-btn>
</template> </template>
</Layout> </Layout>
+46 -3
View File
@@ -35,6 +35,7 @@ import {
saveGuestSelfAssessmentDraft, saveGuestSelfAssessmentDraft,
type GuestSelfAssessmentDraft, type GuestSelfAssessmentDraft,
} from "@/utils/guest-self-assessment"; } from "@/utils/guest-self-assessment";
import { getApiErrorMessage, getApiErrorStatus } from "@/utils/api-error";
import { calculateProvisionalRiskLevel } from "@/utils/self-assessment"; import { calculateProvisionalRiskLevel } from "@/utils/self-assessment";
/** 開發環境可用 VITE_USE_MOCK=true 模擬流程;正式串接時設為 false。 */ /** 開發環境可用 VITE_USE_MOCK=true 模擬流程;正式串接時設為 false。 */
@@ -313,6 +314,8 @@ export const useAppStore = defineStore("app", () => {
const userID = ref(""); const userID = ref("");
const userProfile = ref<UserProfile>(createEmptyUserProfile()); const userProfile = ref<UserProfile>(createEmptyUserProfile());
const selfAssessment = ref<SelfAssessment>(createEmptySelfAssessment()); const selfAssessment = ref<SelfAssessment>(createEmptySelfAssessment());
const selfAssessmentLoading = ref(false);
const selfAssessmentError = ref("");
const appointments = ref<Appointment[]>(createDefaultAppointments()); const appointments = ref<Appointment[]>(createDefaultAppointments());
const measurements = ref<Record<string, MeasurementStation>>( const measurements = ref<Record<string, MeasurementStation>>(
createDefaultMeasurements(), createDefaultMeasurements(),
@@ -373,6 +376,12 @@ export const useAppStore = defineStore("app", () => {
const profile = await apiGetProfile(); const profile = await apiGetProfile();
isLoggedIn.value = true; isLoggedIn.value = true;
userProfile.value = applyProfileToStore(profile); userProfile.value = applyProfileToStore(profile);
try {
await loadLatestSelfAssessment();
} catch {
// 最近自評載入失敗不應使已驗證的登入 Session 失效。
}
} }
return isLoggedIn.value; return isLoggedIn.value;
@@ -405,6 +414,13 @@ export const useAppStore = defineStore("app", () => {
: await apiLogin({ phone, password }); : await apiLogin({ phone, password });
setAuthenticated(response); setAuthenticated(response);
try {
await loadLatestSelfAssessment();
} catch {
// 最近自評載入失敗不應使已驗證的登入 Session 失效。
}
return response; return response;
} }
@@ -443,6 +459,8 @@ export const useAppStore = defineStore("app", () => {
userID.value = ""; userID.value = "";
userProfile.value = createEmptyUserProfile(); userProfile.value = createEmptyUserProfile();
selfAssessment.value = createEmptySelfAssessment(); selfAssessment.value = createEmptySelfAssessment();
selfAssessmentLoading.value = false;
selfAssessmentError.value = "";
} }
/** 呼叫後端登出,無論請求結果都清除前端登入狀態。 */ /** 呼叫後端登出,無論請求結果都清除前端登入狀態。 */
@@ -510,9 +528,32 @@ export const useAppStore = defineStore("app", () => {
return null; return null;
} }
const assessment = await apiGetLatestSelfAssessment(); selfAssessmentLoading.value = true;
setSelfAssessment(assessment); selfAssessmentError.value = "";
return assessment;
try {
const assessment = await apiGetLatestSelfAssessment();
setSelfAssessment(assessment);
return assessment;
} catch (error) {
const status = getApiErrorStatus(error);
if (status === 404) {
selfAssessment.value = createEmptySelfAssessment();
return null;
}
if (status !== 401) {
selfAssessmentError.value = getApiErrorMessage(
error,
"無法載入最近一次自評,請稍後再試。",
);
}
throw error;
} finally {
selfAssessmentLoading.value = false;
}
} }
/** /**
@@ -631,6 +672,8 @@ export const useAppStore = defineStore("app", () => {
userID, userID,
userProfile, userProfile,
selfAssessment, selfAssessment,
selfAssessmentLoading,
selfAssessmentError,
appointments, appointments,
measurements, measurements,
completedStationsCount, completedStationsCount,