| | |
| | | } from '@element-plus/icons-vue' |
| | | import pointsApi from '@/api/pointsApi' |
| | | import type { PointsStats, PointsFlow, PointsQueryParams } from '@/types/points' |
| | | import { useUserInfo } from '@/stores/modules/userInfo' |
| | | import { queryUserDetail } from '@/api/userInfo' |
| | | |
| | | // 获取用户信息 store |
| | | const userStore = useUserInfo() |
| | | |
| | | // 积分统计 |
| | | const stats = ref<PointsStats>({ |
| | |
| | | |
| | | // 查询参数 |
| | | const queryParams = reactive<PointsQueryParams>({ |
| | | userId: '1', |
| | | userId: '', |
| | | dataCategory: '', |
| | | dataType: '', |
| | | pageNum: 1, |
| | |
| | | // 获取积分统计 |
| | | const getPointsStats = async () => { |
| | | try { |
| | | const userId = 1; |
| | | const userId = userStore.getUserId || userStore.getUserInfo?.userId |
| | | if (!userId) { |
| | | console.error('无法获取用户ID') |
| | | return |
| | | } |
| | | // 更新查询参数中的 userId |
| | | queryParams.userId = userId.toString() |
| | | const res = await pointsApi.getPersonalPointsStats(userId) |
| | | if (res.code === 200 && res.data) { |
| | | stats.value = res.data |
| | |
| | | // 获取积分流水 |
| | | const getPointsFlow = async () => { |
| | | try { |
| | | const userId = userStore.getUserId || userStore.getUserInfo?.userId |
| | | if (!userId) { |
| | | console.error('无法获取用户ID') |
| | | return |
| | | } |
| | | // 更新查询参数中的 userId |
| | | queryParams.userId = userId.toString() |
| | | const res = await pointsApi.getPersonalPointsFlow(queryParams) |
| | | if (res.code === 200) { |
| | | flowList.value = res.data.list || [] |
| | |
| | | ElMessage.info('关闭全部功能') |
| | | } |
| | | |
| | | onMounted(() => { |
| | | onMounted(async () => { |
| | | // 页面挂载时,检查 userStore 是否已有用户信息 |
| | | let userId = userStore.getUserId || userStore.getUserInfo?.userId |
| | | if (!userId) { |
| | | try { |
| | | const res: any = await queryUserDetail() |
| | | if (res?.code === 200 && res.data) { |
| | | userStore.updateUserDetail(res.data) |
| | | userId = res.data.userId || res.data.id |
| | | } else { |
| | | ElMessage.error(res?.msg || '无法获取用户信息,请先登录') |
| | | return |
| | | } |
| | | } catch (e) { |
| | | console.error('获取用户详情失败:', e) |
| | | ElMessage.error('获取用户信息失败,请稍后重试') |
| | | return |
| | | } |
| | | } |
| | | |
| | | getPointsStats() |
| | | getPointsFlow() |
| | | getCategoryList() |