2
0
Просмотр исходного кода

✨ feat(exam): 显示用户昵称代替用户ID

- 在考试管理和结果展示中,将userId替换为username显示
- 添加用户昵称渲染处理,未知用户显示"未知用户"
- 完善Answer和CumulativeResult类型定义,增加username字段
- 确保Redis存储时username字段正确处理
- 在提交答案时包含用户名信息
yourname 6 месяцев назад
Родитель
Сommit
0d0362a552

+ 6 - 4
src/client/mobile/components/Exam/ExamAdmin.tsx

@@ -180,8 +180,9 @@ export default function ExamAdmin() {
   const columns = [
   const columns = [
     {
     {
       title: '昵称',
       title: '昵称',
-      dataIndex: 'userId',
-      key: 'userId',
+      dataIndex: 'username',
+      key: 'username',
+      render: (text: string | undefined) => text || '未知用户',
     },
     },
     {
     {
       title: '日期',
       title: '日期',
@@ -222,8 +223,9 @@ export default function ExamAdmin() {
   const resultColumns: ColumnType[] = [
   const resultColumns: ColumnType[] = [
     {
     {
       title: '昵称',
       title: '昵称',
-      dataIndex: 'userId',
-      key: 'userId',
+      dataIndex: 'username',
+      key: 'username',
+      render: (text: string | undefined) => text || '未知用户',
     },
     },
     {
     {
       title: '累计盈亏(元)',
       title: '累计盈亏(元)',

+ 2 - 0
src/client/mobile/components/Exam/ExamCard.tsx

@@ -142,6 +142,7 @@ export default function ExamCard() {
         holdingStock: '1',
         holdingStock: '1',
         holdingCash: '0',
         holdingCash: '0',
         userId: user.id,
         userId: user.id,
+        username: user.username,
         price: currentPrice
         price: currentPrice
       };
       };
       
       
@@ -184,6 +185,7 @@ export default function ExamCard() {
         holdingStock: '0',
         holdingStock: '0',
         holdingCash: '1',
         holdingCash: '1',
         userId: user.id,
         userId: user.id,
+        username: user.username,
         price: currentPrice
         price: currentPrice
       };
       };
       
       

+ 3 - 1
src/client/mobile/components/Exam/types.ts

@@ -45,6 +45,7 @@ export interface Answer extends QuizContent {
   profitPercent?: number;
   profitPercent?: number;
   totalProfitAmount?: number;
   totalProfitAmount?: number;
   totalProfitPercent?: number;
   totalProfitPercent?: number;
+  username?: string;
 }
 }
 
 
 // 教室数据
 // 教室数据
@@ -58,6 +59,7 @@ export interface ClassroomData {
 // 累计结果
 // 累计结果
 export interface CumulativeResult {
 export interface CumulativeResult {
   userId: number;
   userId: number;
+  username?: string;
   totalProfitAmount: number;
   totalProfitAmount: number;
   totalProfitPercent: number;
   totalProfitPercent: number;
-} 
+}

+ 6 - 1
src/server/socket/services/redis.service.ts

@@ -86,7 +86,12 @@ export class RedisService {
     answer: Answer
     answer: Answer
   ) {
   ) {
     const key = `exam:${roomId}:answers:${userId}:${questionId}`;
     const key = `exam:${roomId}:answers:${userId}:${questionId}`;
-    await this.client.hset(key, 'data', JSON.stringify(answer));
+    // 确保username字段被正确存储
+    const answerWithUsername = {
+      ...answer,
+      username: answer.username || ''
+    };
+    await this.client.hset(key, 'data', JSON.stringify(answerWithUsername));
     // 设置过期时间,30天
     // 设置过期时间,30天
     await this.client.expire(key, 30 * 24 * 60 * 60);
     await this.client.expire(key, 30 * 24 * 60 * 60);
   }
   }

+ 1 - 0
src/share/utils/calculateCumulativeResults.ts

@@ -26,6 +26,7 @@ export function calculateCumulativeResults(answers: Answer[]): CumulativeResult[
       if (!userResults.has(userId)) {
       if (!userResults.has(userId)) {
         userResults.set(userId, {
         userResults.set(userId, {
           userId: parseInt(userId),
           userId: parseInt(userId),
+          username: answer.username,
           totalProfitAmount: 0,
           totalProfitAmount: 0,
           totalProfitPercent: 0
           totalProfitPercent: 0
         });
         });