|
|
@@ -1,6 +1,6 @@
|
|
|
import axios from 'axios';
|
|
|
|
|
|
-const API_BASE_URL = 'http://your-device-api-url.com'; // 替换为实际的设备 API URL
|
|
|
+const API_BASE_URL = 'http://localhost:3000/api'; // 修改为实际的 API URL
|
|
|
|
|
|
const instance = axios.create({
|
|
|
baseURL: API_BASE_URL,
|
|
|
@@ -11,22 +11,75 @@ const instance = axios.create({
|
|
|
});
|
|
|
|
|
|
export const deviceApi = {
|
|
|
- // ... 保留其他方法 ...
|
|
|
+ getPersonList: async () => {
|
|
|
+ try {
|
|
|
+ const response = await instance.get('/persons');
|
|
|
+ return response.data;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取会友列表失败', error);
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ createPerson: async (personData) => {
|
|
|
+ try {
|
|
|
+ const response = await instance.post('/persons', personData);
|
|
|
+ return response.data;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('创建会友失败', error);
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updatePerson: async (personId, personData) => {
|
|
|
+ try {
|
|
|
+ const response = await instance.put(`/persons/${personId}`, personData);
|
|
|
+ return response.data;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('更新会友失败', error);
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ deletePerson: async (personId) => {
|
|
|
+ try {
|
|
|
+ const response = await instance.delete(`/persons/${personId}`);
|
|
|
+ return response.data;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('删除会友失败', error);
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- // 下发人员信息到设备
|
|
|
downloadPersonToDevice: async (personId) => {
|
|
|
try {
|
|
|
const response = await instance.post('/person/issue', { personId });
|
|
|
- if (response.data.code === 0) {
|
|
|
- return response.data.data;
|
|
|
- } else {
|
|
|
- throw new Error(response.data.msg || '下发人员信息失败');
|
|
|
- }
|
|
|
+ return response.data;
|
|
|
} catch (error) {
|
|
|
console.error('下发人员信息失败', error);
|
|
|
throw error;
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // ... 保留其他方法 ...
|
|
|
+ getDeviceInfo: async () => {
|
|
|
+ try {
|
|
|
+ const response = await instance.get('/device/info');
|
|
|
+ return response.data;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取设备信息失败', error);
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getAttendanceRecords: async (startDate, endDate) => {
|
|
|
+ try {
|
|
|
+ const response = await instance.get('/attendance', {
|
|
|
+ params: { startDate, endDate }
|
|
|
+ });
|
|
|
+ return response.data;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取考勤记录失败', error);
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ },
|
|
|
};
|