|
@@ -2,6 +2,32 @@ import axios from 'axios';
|
|
|
|
|
|
|
|
const API_BASE_URL = 'http://your-device-api-url.com'; // 替换为实际的设备 API URL
|
|
const API_BASE_URL = 'http://your-device-api-url.com'; // 替换为实际的设备 API URL
|
|
|
|
|
|
|
|
|
|
+// 模拟数据存储
|
|
|
|
|
+let mockData = [
|
|
|
|
|
+ {
|
|
|
|
|
+ personId: '1',
|
|
|
|
|
+ name: '张三',
|
|
|
|
|
+ gender: '男',
|
|
|
|
|
+ age: 30,
|
|
|
|
|
+ birthDate: '1994-01-01',
|
|
|
|
|
+ maritalStatus: '已婚',
|
|
|
|
|
+ isBaptized: true,
|
|
|
|
|
+ baptismDate: '2010-05-15',
|
|
|
|
|
+ contact: '13800138000'
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ personId: '2',
|
|
|
|
|
+ name: '李四',
|
|
|
|
|
+ gender: '女',
|
|
|
|
|
+ age: 25,
|
|
|
|
|
+ birthDate: '1999-03-15',
|
|
|
|
|
+ maritalStatus: '未婚',
|
|
|
|
|
+ isBaptized: false,
|
|
|
|
|
+ baptismDate: null,
|
|
|
|
|
+ contact: '13900139000'
|
|
|
|
|
+ }
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
export const deviceApi = {
|
|
export const deviceApi = {
|
|
|
getAllPersons: async () => {
|
|
getAllPersons: async () => {
|
|
|
try {
|
|
try {
|
|
@@ -10,30 +36,7 @@ export const deviceApi = {
|
|
|
return new Promise((resolve) => {
|
|
return new Promise((resolve) => {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
console.log('模拟 API 返回数据');
|
|
console.log('模拟 API 返回数据');
|
|
|
- resolve([
|
|
|
|
|
- {
|
|
|
|
|
- personId: '1',
|
|
|
|
|
- name: '张三',
|
|
|
|
|
- gender: '男',
|
|
|
|
|
- age: 30,
|
|
|
|
|
- birthDate: '1994-01-01',
|
|
|
|
|
- maritalStatus: '已婚',
|
|
|
|
|
- isBaptized: true,
|
|
|
|
|
- baptismDate: '2010-05-15',
|
|
|
|
|
- contact: '13800138000'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- personId: '2',
|
|
|
|
|
- name: '李四',
|
|
|
|
|
- gender: '女',
|
|
|
|
|
- age: 25,
|
|
|
|
|
- birthDate: '1999-03-15',
|
|
|
|
|
- maritalStatus: '未婚',
|
|
|
|
|
- isBaptized: false,
|
|
|
|
|
- baptismDate: null,
|
|
|
|
|
- contact: '13900139000'
|
|
|
|
|
- }
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ resolve([...mockData]); // 返回模拟数据的深拷贝
|
|
|
}, 1000);
|
|
}, 1000);
|
|
|
});
|
|
});
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -48,10 +51,12 @@ export const deviceApi = {
|
|
|
// 模拟添加操作
|
|
// 模拟添加操作
|
|
|
return new Promise((resolve) => {
|
|
return new Promise((resolve) => {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
- resolve({
|
|
|
|
|
|
|
+ const newPerson = {
|
|
|
...personInfo,
|
|
...personInfo,
|
|
|
- personId: Date.now().toString(), // 模拟生成ID
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ personId: (mockData.length + 1).toString(),
|
|
|
|
|
+ };
|
|
|
|
|
+ mockData.push(newPerson);
|
|
|
|
|
+ resolve(newPerson);
|
|
|
}, 500);
|
|
}, 500);
|
|
|
});
|
|
});
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -66,10 +71,13 @@ export const deviceApi = {
|
|
|
// 模拟更新操作
|
|
// 模拟更新操作
|
|
|
return new Promise((resolve) => {
|
|
return new Promise((resolve) => {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
- resolve({
|
|
|
|
|
- ...personInfo,
|
|
|
|
|
- personId,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const index = mockData.findIndex(p => p.personId === personId);
|
|
|
|
|
+ if (index !== -1) {
|
|
|
|
|
+ mockData[index] = { ...personInfo, personId };
|
|
|
|
|
+ resolve(mockData[index]);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new Error('未找到指定会友');
|
|
|
|
|
+ }
|
|
|
}, 500);
|
|
}, 500);
|
|
|
});
|
|
});
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -84,6 +92,7 @@ export const deviceApi = {
|
|
|
// 模拟删除操作
|
|
// 模拟删除操作
|
|
|
return new Promise((resolve) => {
|
|
return new Promise((resolve) => {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
|
|
+ mockData = mockData.filter(p => p.personId !== personId);
|
|
|
resolve({ success: true });
|
|
resolve({ success: true });
|
|
|
}, 500);
|
|
}, 500);
|
|
|
});
|
|
});
|