feat(core): sgw-device-ui

This commit is contained in:
Tran Anh Tuan
2025-09-26 18:22:04 +07:00
parent 466e931537
commit 2707b92f7e
88 changed files with 19104 additions and 0 deletions

25
src/models/getAlarm.ts Normal file
View File

@@ -0,0 +1,25 @@
import { queryAlarms } from '@/services/controller/DeviceController';
import { useCallback, useState } from 'react';
export default function useAlarmModel() {
const [alarmData, setAlarmData] = useState<API.AlarmResponse | null>(null);
const [loading, setLoading] = useState(false);
const getAlarmData = useCallback(async () => {
setLoading(true);
try {
const res = await queryAlarms(); // đổi URL cho phù hợp
console.log('Alarm Data fetched:', res);
setAlarmData(res || []);
} catch (err) {
console.error('Fetch alarm data failed', err);
} finally {
setLoading(false);
}
}, []);
return {
alarmData,
loading,
getAlarmData,
};
}

25
src/models/getSos.ts Normal file
View File

@@ -0,0 +1,25 @@
import { getGPS } from '@/services/controller/DeviceController';
import { useCallback, useState } from 'react';
export default function useGetGpsModel() {
const [gpsData, setGpsData] = useState<API.GPSResonse | null>(null);
const [loading, setLoading] = useState(false);
const getGPSData = useCallback(async () => {
setLoading(true);
try {
const res = await getGPS(); // đổi URL cho phù hợp
console.log('GPS Data fetched:', res);
setGpsData(res || []);
} catch (err) {
console.error('Fetch gps data failed', err);
} finally {
setLoading(false);
}
}, []);
return {
gpsData,
loading,
getGPSData,
};
}

23
src/models/getTrip.ts Normal file
View File

@@ -0,0 +1,23 @@
import { getTrip } from '@/services/controller/TripController';
import { useCallback, useState } from 'react';
export default function useGetTripModel() {
const [data, setData] = useState<API.Trip | null>(null);
const [loading, setLoading] = useState(false);
const getApi = useCallback(async () => {
setLoading(true);
try {
const res = await getTrip(); // đổi URL cho phù hợp
setData(res || []);
} catch (err) {
console.error('Fetch data failed', err);
} finally {
setLoading(false);
}
}, []);
return {
data,
loading,
getApi,
};
}

13
src/models/global.ts Normal file
View File

@@ -0,0 +1,13 @@
// 全局共享数据示例
import { DEFAULT_NAME } from '@/constants';
import { useState } from 'react';
const useUser = () => {
const [name, setName] = useState<string>(DEFAULT_NAME);
return {
name,
setName,
};
};
export default useUser;