feat: refresh
This commit is contained in:
@@ -6,6 +6,7 @@ import type {
|
||||
YesNo,
|
||||
} from "./types";
|
||||
import { api } from "./client";
|
||||
import { getApiErrorBody, getApiErrorStatus } from "@/utils/api-error";
|
||||
|
||||
/**
|
||||
* 課程建議的 5 支 API。
|
||||
@@ -41,8 +42,20 @@ function toCourseRow(raw: CourseListApiRow): CourseRow {
|
||||
}
|
||||
|
||||
/** 依登入 Cookie 取得目前使用者的體適能組別。 */
|
||||
export function fetchGroup(): Promise<FitnessGroup | ""> {
|
||||
return api.get("course/group").json<FitnessGroup | "">();
|
||||
export async function fetchGroup(): Promise<FitnessGroup | ""> {
|
||||
try {
|
||||
return await api.get("course/group").json<FitnessGroup | "">();
|
||||
} catch (error) {
|
||||
// 尚未完成分組時,後端以 404 與業務訊息回應,轉成 store 可處理的空組別。
|
||||
if (
|
||||
getApiErrorStatus(error) === 404 &&
|
||||
getApiErrorBody(error)?.message === "尚未建立體適能組別"
|
||||
) {
|
||||
return "";
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/** 取得是否納入早上時段 */
|
||||
|
||||
@@ -2,9 +2,21 @@
|
||||
<v-card class="rounded-xl elevation-2 mt-4" color="surface">
|
||||
<v-card-title class="d-flex align-center justify-space-between">
|
||||
<span>11 項體適能測驗</span>
|
||||
<v-chip color="primary" size="small" variant="tonal">
|
||||
{{ completedCount }}/{{ displayItems.length }} 項有資料
|
||||
</v-chip>
|
||||
<div class="d-flex align-center ga-2">
|
||||
<v-btn
|
||||
aria-label="重新取得體適能資料"
|
||||
color="primary"
|
||||
:disabled="loading"
|
||||
icon="mdi-refresh"
|
||||
:loading="loading"
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="$emit('refresh')"
|
||||
/>
|
||||
<v-chip color="primary" size="small" variant="tonal">
|
||||
{{ completedCount }}/{{ displayItems.length }} 項有資料
|
||||
</v-chip>
|
||||
</div>
|
||||
</v-card-title>
|
||||
|
||||
<v-card-subtitle> 顯示目前帳號各測驗項目的最新成績。 </v-card-subtitle>
|
||||
@@ -31,7 +43,7 @@
|
||||
color="error"
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="$emit('retry')"
|
||||
@click="$emit('refresh')"
|
||||
>
|
||||
重試
|
||||
</v-btn>
|
||||
@@ -52,7 +64,6 @@
|
||||
<div class="text-body-2 font-weight-bold">
|
||||
{{ item.fitnessName }}
|
||||
</div>
|
||||
<div class="text-caption text-grey">{{ item.fitnessCode }}</div>
|
||||
</div>
|
||||
<div
|
||||
class="text-body-1 font-weight-black text-no-wrap"
|
||||
@@ -78,7 +89,7 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
defineEmits<{
|
||||
retry: [];
|
||||
refresh: [];
|
||||
}>();
|
||||
|
||||
const FITNESS_TEST_DEFINITIONS = [
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
:error="physicalFitnessError"
|
||||
:items="physicalFitnessItems"
|
||||
:loading="physicalFitnessLoading"
|
||||
@retry="loadPhysicalFitness"
|
||||
@refresh="loadPhysicalFitness"
|
||||
/>
|
||||
|
||||
<ModuleRouterCard
|
||||
|
||||
Reference in New Issue
Block a user