parent
d6293e879d
commit
50d5c4080d
|
|
@ -4,12 +4,17 @@ import type {
|
||||||
DashboardConfigType,
|
DashboardConfigType,
|
||||||
} from "@/gql/graphql";
|
} from "@/gql/graphql";
|
||||||
import type { DashboardCourseConfigType } from "@/services/dashboard";
|
import type { DashboardCourseConfigType } from "@/services/dashboard";
|
||||||
import { fetchDashboardConfigv2, fetchStatisticData } from "@/services/dashboard";
|
import {
|
||||||
|
fetchDashboardConfig,
|
||||||
|
fetchDashboardConfigv2,
|
||||||
|
fetchStatisticData,
|
||||||
|
} from "@/services/dashboard";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import type { Ref } from "vue";
|
import type { Ref } from "vue";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
|
|
||||||
export const useDashboardStore = defineStore("dashboard", () => {
|
export const useDashboardStore = defineStore("dashboard", () => {
|
||||||
|
const dashboardConfigs: Ref<DashboardConfigType[]> = ref([]);
|
||||||
const dashboardConfigsv2: Ref<DashboardCourseConfigType[]> = ref([]);
|
const dashboardConfigsv2: Ref<DashboardCourseConfigType[]> = ref([]);
|
||||||
const currentDashboardConfig: Ref<DashboardConfigType | undefined> = ref();
|
const currentDashboardConfig: Ref<DashboardConfigType | undefined> = ref();
|
||||||
const dashBoardDataCache: Record<
|
const dashBoardDataCache: Record<
|
||||||
|
|
@ -25,6 +30,15 @@ export const useDashboardStore = defineStore("dashboard", () => {
|
||||||
await loadDashboardDetails();
|
await loadDashboardDetails();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadDashboardConfig = async () => {
|
||||||
|
if (dashboardConfigs.value.length > 0) return;
|
||||||
|
const configData = await fetchDashboardConfig();
|
||||||
|
if (configData && configData.length > 0) {
|
||||||
|
dashboardConfigs.value = configData;
|
||||||
|
await switchAndLoadDashboardConfig(configData[0]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const loadDashboardDetails = async () => {
|
const loadDashboardDetails = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
dashboardConfigsv2.value = await fetchDashboardConfigv2();
|
dashboardConfigsv2.value = await fetchDashboardConfigv2();
|
||||||
|
|
@ -45,9 +59,11 @@ export const useDashboardStore = defineStore("dashboard", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
dashboardConfigs,
|
||||||
dashboardConfigsv2,
|
dashboardConfigsv2,
|
||||||
currentDashboardConfig,
|
currentDashboardConfig,
|
||||||
switchAndLoadDashboardConfig,
|
switchAndLoadDashboardConfig,
|
||||||
|
loadDashboardConfig,
|
||||||
loadDashboardDetails,
|
loadDashboardDetails,
|
||||||
currentDashBoardData,
|
currentDashBoardData,
|
||||||
loading,
|
loading,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue