seatonwan9
2025-08-28 bfbb1ea3c6bb2dd7db064fb189290a1bfcf6c9cd
src/views/pointsManage/personal/index.vue
@@ -157,6 +157,11 @@
} 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>({
@@ -168,7 +173,7 @@
// 查询参数
const queryParams = reactive<PointsQueryParams>({
  userId: '1',
  userId: '',
  dataCategory: '',
  dataType: '',
  pageNum: 1,
@@ -208,7 +213,13 @@
// 获取积分统计
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
@@ -233,6 +244,13 @@
// 获取积分流水
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 || []
@@ -300,7 +318,26 @@
  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()