合并代码

This commit is contained in:
筱野
2025-09-28 23:00:57 +08:00
23 changed files with 1901 additions and 422 deletions

View File

@@ -40,6 +40,17 @@ interface UserDetailData {
};
}
export interface PickerOption {
text: string | number;
value: string | number;
children?: PickerOption[];
}
export interface Profession {
name: string;
children: Profession[] | [];
}
// 用户详细信息接口(从 loginService 移过来)
export interface UserInfoType {
id: number
@@ -119,6 +130,21 @@ interface BackendGameData {
}[];
}
const formatOptions = (data: Profession[]): PickerOption[] => {
return data.map((item: Profession) => {
const { name: text, children } = item;
const itm: PickerOption = {
text,
value: text,
children: children ? formatOptions(children) : []
}
if (!itm.children!.length) {
delete itm.children
}
return itm
})
}
// 用户服务类
export class UserService {
// 数据转换函数将后端数据转换为ListContainer期望的格式
@@ -206,7 +232,7 @@ export class UserService {
date_str = `明天(${weekday})`;
} else if (start_date.getTime() === day_after_tomorrow.getTime()) {
date_str = `后天(${weekday})`;
} else if(this.is_date_in_this_week(start_time)) {
} else if (this.is_date_in_this_week(start_time)) {
date_str = weekday;
} else {
date_str = `${start_time.getFullYear()}-${(start_time.getMonth() + 1).toString().padStart(2, '0')}-${start_time.getDate().toString().padStart(2, '0')}(${weekday})`;
@@ -238,7 +264,7 @@ export class UserService {
if (response.code === 0) {
const userData = response.data;
return {
id: userData.id || '',
id: userData.id || '',
nickname: userData.nickname || '',
avatar: userData.avatar_url || '',
join_date: userData.subscribe_time ? `${new Date(userData.subscribe_time).getFullYear()}${new Date(userData.subscribe_time).getMonth() + 1}月加入` : '',
@@ -492,6 +518,39 @@ export class UserService {
return '';
}
}
// 获取职业树
static async getProfessions(): Promise<[] | PickerOption[]> {
try {
const response = await httpService.post<any>(API_CONFIG.PROFESSIONS);
const { code, data, message } = response;
if (code === 0) {
return formatOptions(data || []);
} else {
throw new Error(message || '获取职业树失败');
}
} catch (error) {
console.error('获取职业树失败:', error);
return [];
}
}
// 获取城市树
static async getCities(): Promise<[] | PickerOption[]> {
try {
const response = await httpService.post<any>(API_CONFIG.CITIS);
const { code, data, message } = response;
if (code === 0) {
return formatOptions(data || []);
} else {
throw new Error(message || '获取城市树失败');
}
} catch (error) {
console.error('获取职业树失败:', error);
return [];
}
}
}
// 从 loginService 移过来的用户相关方法