fix:用户管理用户信息界面
This commit is contained in:
@@ -9,57 +9,52 @@ import { doGetUserList } from '@/service/api/user';
|
||||
import type { UserInfo, SearchModel } from '@/views/user-center/user/type';
|
||||
|
||||
// 修改API函数实现
|
||||
const doGetUserInfo: AntDesign.TableApiFn<UserInfo, SearchModel> = async (params: SearchModel) => {
|
||||
const doGetUserInfo = async (params: SearchModel) => {
|
||||
try {
|
||||
console.log('Search params received in API function:', params);
|
||||
console.log('API function received params:', params);
|
||||
|
||||
// 构造API请求参数
|
||||
const apiParams = {
|
||||
const apiParams: Api.SystemManage.UserSearchParams = {
|
||||
userName: params.username,
|
||||
email: params.email,
|
||||
pageNum: params.pageNum,
|
||||
pageSize: params.pageSize
|
||||
};
|
||||
|
||||
console.log('Sending to API:', apiParams);
|
||||
console.log('Sending API request with params:', apiParams);
|
||||
|
||||
const { data, error } = await doGetUserList(apiParams);
|
||||
console.log('Response:', data, error);
|
||||
const response = await doGetUserList(apiParams);
|
||||
|
||||
if (error) {
|
||||
if (!response.data) {
|
||||
return {
|
||||
data: {
|
||||
rows: [],
|
||||
total: 0
|
||||
},
|
||||
error: null
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
rows: data.rows.map(user => ({
|
||||
rows: response.data.rows.map(user => ({
|
||||
userId: user.userId,
|
||||
username: user.userName,
|
||||
fullname: user.nickName,
|
||||
sex: user.sex === '1' ? 'M' : 'F',
|
||||
birthdate: user.createTime?.split(' ')[0] || '-',
|
||||
age: 0, // 如果后端没有提供年龄字段,可以设为0或者根据生日计算
|
||||
age: calculateAge(user.createTime),
|
||||
email: user.email,
|
||||
phonenumber: user.phonenumber,
|
||||
isKYC: user.status === '0' // 假设status为'0'表示已验证
|
||||
isKYC: user.status === '0'
|
||||
})),
|
||||
total: data.total
|
||||
},
|
||||
error: null
|
||||
total: response.data.total
|
||||
}
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
data: {
|
||||
rows: [],
|
||||
total: 0
|
||||
},
|
||||
error: null
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -83,7 +78,7 @@ const {
|
||||
mobilePagination,
|
||||
searchParams,
|
||||
updateSearchParams,
|
||||
resetSearchParams
|
||||
|
||||
} = useTable({
|
||||
apiFn: doGetUserInfo,
|
||||
immediate: true,
|
||||
@@ -166,26 +161,53 @@ const {
|
||||
]
|
||||
});
|
||||
|
||||
const handUpdateModel = (item: SearchModel) => {
|
||||
console.log('Received updated model:', item);
|
||||
// 更新搜索参数
|
||||
updateSearchParams({
|
||||
...item,
|
||||
pageNum: 1 // 每次搜索条件改变时重置页码
|
||||
});
|
||||
};
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = () => {
|
||||
// 使用 updateSearchParams 更新搜索参数
|
||||
updateSearchParams({
|
||||
...searchParams,
|
||||
pageNum: 1 // 搜索时重置页码
|
||||
});
|
||||
// 直接使用已更新的搜索参数
|
||||
console.log('Executing search with params:', searchParams.value);
|
||||
getData();
|
||||
};
|
||||
|
||||
// 处理重置
|
||||
const handleReset = () => {
|
||||
const defaultParams = {
|
||||
// 定义默认参数
|
||||
const defaultParams: SearchModel = {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
username: undefined,
|
||||
email: undefined
|
||||
};
|
||||
|
||||
console.log('Resetting search params to:', defaultParams);
|
||||
|
||||
// 更新搜索参数到默认值
|
||||
updateSearchParams(defaultParams);
|
||||
resetSearchParams();
|
||||
|
||||
// 重新获取数据
|
||||
getData();
|
||||
};
|
||||
|
||||
const calculateAge = (birthDate: string): number => {
|
||||
if (!birthDate) return 0;
|
||||
const birth = new Date(birthDate);
|
||||
const today = new Date();
|
||||
let age = today.getFullYear() - birth.getFullYear();
|
||||
const monthDiff = today.getMonth() - birth.getMonth();
|
||||
|
||||
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
|
||||
age--;
|
||||
}
|
||||
|
||||
return age;
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -194,6 +216,7 @@ const handleReset = () => {
|
||||
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
||||
<UserSearch
|
||||
v-model:model="searchParams"
|
||||
@updateModel="handUpdateModel"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user