diff --git a/src/locales/langs/en-us.ts b/src/locales/langs/en-us.ts index f24f10f..6e5130a 100644 --- a/src/locales/langs/en-us.ts +++ b/src/locales/langs/en-us.ts @@ -562,6 +562,8 @@ const local: any = { uptime:"Up Time", lasttime:"Last seen Time", cdr:"CDR Records", + refresh:"Refresh", + mac:"MAC" }, records:{ clientID:"Client ID", @@ -572,6 +574,7 @@ const local: any = { endtime:"End Time", clienthistory:"Client history", refresh:"Refresh", + dataUsage:"Data Usage", }, access:{ devicename:"Device Name", diff --git a/src/locales/langs/zh-cn.ts b/src/locales/langs/zh-cn.ts index 67cf952..d49dd9d 100644 --- a/src/locales/langs/zh-cn.ts +++ b/src/locales/langs/zh-cn.ts @@ -562,6 +562,8 @@ const local:any = { uptime:"接入时间", lasttime:"断开时间", cdr:"CDR记录", + refresh:"刷新", + mac:"mac地址" }, records:{ clientID:"设备ID", @@ -572,6 +574,7 @@ const local:any = { endtime:"结束时间", clienthistory:"接入历史记录", refresh:"刷新", + dataUsage:"流量使用量", }, access:{ devicename:"设备名称", diff --git a/src/service/api/auth.ts b/src/service/api/auth.ts index 94e1bba..a074f1d 100644 --- a/src/service/api/auth.ts +++ b/src/service/api/auth.ts @@ -91,3 +91,34 @@ export function doGetCheckCode() { url: '/code' }); } +//首页仪表盘 +/** Get dashboard gauge data */ +export function fetchDashboardData() { + return request({ + url: '/u/cdr/getOne', + method: 'get' + }); +} +/** Get current connected devices */ +export function fetchCurrentDevices() { + return request({ + url: '/u/client/pageCurrentClient', + method: 'get' + }); +} +/** Get historical devices */ +export function fetchHistoricalDevices() { + return request({ + url: '/u/client/pageHistoryClient', + method: 'get' + }); +} +/** Get CDR history records */ +export function fetchCDRHistory(params: Api.CDR.CDRQueryParams) { + return request({ + url: '/u/cdr/pageHistory', + method: 'get', + params + }); +} + diff --git a/src/store/modules/auth/index.ts b/src/store/modules/auth/index.ts index c0aac7c..57554ba 100644 --- a/src/store/modules/auth/index.ts +++ b/src/store/modules/auth/index.ts @@ -7,7 +7,7 @@ import { localStg } from '@/utils/storage'; import { $t } from '@/locales'; import { useRouteStore } from '../route'; import { clearAuthStorage, emptyInfo, getToken } from './shared'; -import { doCheckUserRepeat, sendCaptcha } from '@/service/api/auth'; +import { doCheckUserRepeat, sendCaptcha, fetchDashboardData } from '@/service/api/auth'; export const useAuthStore = defineStore(SetupStoreId.Auth, () => { const routeStore = useRouteStore(); @@ -18,6 +18,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { const userInfo: Api.Auth.UserInfo = reactive(emptyInfo); const permissions = computed(() => userInfo.permissions); + /** Dashboard data */ + const dashboardData = ref(null); watch( () => token.value, @@ -159,6 +161,16 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { const { data, error } = await sendCaptcha({ email }); // 这里调用后端接口发送验证码 return { data, error }; } + /** Fetch dashboard data */ + async function getDashboardData() { + const { data, error } = await fetchDashboardData(); + if (!error) { + dashboardData.value = data; + return data; + } + return null; + } + return { token, @@ -172,6 +184,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { register, captcha, checkUserRepeat, - updateUserProfile + updateUserProfile, + dashboardData, + getDashboardData }; }); diff --git a/src/store/modules/route/index.ts b/src/store/modules/route/index.ts index ac2715c..3bcef99 100644 --- a/src/store/modules/route/index.ts +++ b/src/store/modules/route/index.ts @@ -162,6 +162,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { if (!error) { const {authRoutes: staticAuthRoutes} = createStaticRoutes(); const filteredAuthRoutes = filterAuthRoutesByRoles(staticAuthRoutes, authStore.userInfo.roles ?? []); + console.log (filteredAuthRoutes.concat(routes)) addAuthRoutes(filteredAuthRoutes.concat(routes)); handleAuthRoutes(); @@ -184,7 +185,6 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { const vueRoutes = getAuthVueRoutes(sortRoutes); resetVueRoutes(); - addRoutesToVueRouter(vueRoutes); getGlobalMenus(sortRoutes); diff --git a/src/typings/api.d.ts b/src/typings/api.d.ts index 507bbf0..7f44b20 100644 --- a/src/typings/api.d.ts +++ b/src/typings/api.d.ts @@ -435,4 +435,154 @@ declare namespace Api { type DictList = Common.PaginatingQueryRecord; } + /** + * Namespace Dashboard + * + * Backend api module: "dashboard" + */ + namespace Dashboard { + /** Dashboard gauge data */ + interface GaugeData { + /** Remaining credit amount */ + remainingCredit: number; + /** Used credit amount */ + usedCredit: number; + /** Remaining flow amount (MB) */ + remainingFlow: number; + /** Used flow amount (MB) */ + usedFlow: number; + /** Current traffic rate (MB/s) */ + trafficRate: number; + /** Peak traffic rate (MB/s) */ + peakTrafficRate: number; + } + } + + /** + * Namespace Device + * + * Backend api module: "device" + */ + namespace Device { + /** Device information */ + interface DeviceInfo { + /** Device unique key */ + key: string; + /** Device name */ + deviceName: string; + /** MAC address */ + macAddress: string; + /** Current speed */ + speed: string; + } + + /** Device list response */ + interface DeviceListResponse { + /** List of devices */ + rows: DeviceInfo[]; + /** Total count */ + total: number; + } + + /** Historical device information */ + interface HistoricalDeviceInfo { + /** Device unique key */ + key: string; + /** Device name */ + deviceName: string; + /** MAC address */ + macAddress: string; + /** Connection time */ + connectionTime: string; + /** Disconnection time */ + disconnectionTime: string; + /** Data usage */ + dataUsage: string; + } + + /** Historical device list response */ + interface HistoricalDeviceListResponse { + /** List of historical devices */ + rows: HistoricalDeviceInfo[]; + /** Total count */ + total: number; + } + + interface DeviceInfo { + id: number; + clientName: string; + clientMac: string; + clientDeviceType: string; + activity: number; + } + + interface DeviceResponse { + total: number; + rows: DeviceInfo[]; + } + interface HistoricalDeviceInfo { + id: number; + clientName: string; + clientMac: string; + startTime: number; // 时间戳 + endTime: number; // 时间戳 + duration: number; // 流量使用量(bytes) + } + + interface HistoricalDeviceResponse { + total: number; + rows: HistoricalDeviceInfo[]; + } + } + + + namespace CDR { + /** CDR record information */ + interface CDRRecord { + /** Record ID */ + id: number; + /** AP name */ + ap_name: string; + /** Upload traffic */ + traffic_up: number; + /** Download traffic */ + traffic_down: number; + /** Up time */ + up_time: string; + /** Last seen time */ + last_seen_time: string; + } + interface CDRRecord { + /** Record ID */ + id: number; + /** Client name */ + clientName: string; + /** Client MAC address */ + clientMac: string; + /** Upload traffic in bytes */ + trafficUp: number; + /** Download traffic in bytes */ + trafficDown: number; + /** Start time timestamp */ + startTime: number; + /** End time timestamp */ + endTime: number; + } + + /** CDR record list response */ + interface CDRListResponse { + /** List of CDR records */ + rows: CDRRecord[]; + /** Total count */ + total: number; + } + + /** CDR query params */ + interface CDRQueryParams { + /** Page number */ + pageNum: number; + /** Page size */ + pageSize: number; + } + } } diff --git a/src/typings/auto-imports.d.ts b/src/typings/auto-imports.d.ts index f7cbfd4..9c126be 100644 --- a/src/typings/auto-imports.d.ts +++ b/src/typings/auto-imports.d.ts @@ -92,10 +92,14 @@ declare global { const expect: typeof import('vitest')['expect'] const extendRef: typeof import('@vueuse/core')['extendRef'] const extractTabsByAllRoutes: typeof import('../store/modules/tab/shared')['extractTabsByAllRoutes'] + const fetchCDRHistory: typeof import('../service/api/auth')['fetchCDRHistory'] + const fetchCurrentDevices: typeof import('../service/api/auth')['fetchCurrentDevices'] const fetchCustomBackendError: typeof import('../service/api/auth')['fetchCustomBackendError'] + const fetchDashboardData: typeof import('../service/api/auth')['fetchDashboardData'] const fetchGetAllPages: typeof import('../service/api/menu')['fetchGetAllPages'] const fetchGetConstantRoutes: typeof import('../service/api/route')['fetchGetConstantRoutes'] const fetchGetMenuTree: typeof import('../service/api/menu')['fetchGetMenuTree'] + const fetchHistoricalDevices: typeof import('../service/api/auth')['fetchHistoricalDevices'] const fetchIsRouteExist: typeof import('../service/api/route')['fetchIsRouteExist'] const fetchLogin: typeof import('../service/api/auth')['fetchLogin'] const fetchRefreshToken: typeof import('../service/api/auth')['fetchRefreshToken'] diff --git a/src/views/endpoint/records/index.vue b/src/views/endpoint/records/index.vue index 32d8fbc..f761c1f 100644 --- a/src/views/endpoint/records/index.vue +++ b/src/views/endpoint/records/index.vue @@ -1,133 +1,122 @@