Browse Source

feat(front): 个人中心-练习汇总

Go 5 years ago
parent
commit
f9aee4aaca

+ 1 - 1
front/project/www/local.json

@@ -8,7 +8,7 @@
     ],
     "proxy": [
       {
-        "target": "http://qianxing.nuliji.com",
+        "target": "http://127.0.0.1:8888",
         "from": "/api",
         "to": "/api"
       }

+ 6 - 0
front/project/www/routes/my/main/index.less

@@ -56,9 +56,15 @@
         cursor: pointer;
         float: right;
         position: relative;
+        z-index: 1000;
+        background-color: #fff;
 
         .cal {
           position: absolute;
+          right: 0;
+          width: 300px;
+          background: #fff;
+          z-index: 1001;
         }
       }
     }

+ 73 - 21
front/project/www/routes/my/main/page.js

@@ -1,18 +1,18 @@
 import React, { Component } from 'react';
 import { Link } from 'react-router-dom';
 import './index.less';
-import { Tooltip, Icon } from 'antd';
+import { Tooltip, Icon, Calendar } from 'antd';
 import Page from '@src/containers/Page';
 import Assets from '@src/components/Assets';
 import { formatPercent, formatDate, formatSeconds } from '@src/services/Tools';
 import { asyncSMessage } from '@src/services/AsyncTools';
+import moment from 'moment';
 import UserLayout from '../../../layouts/User';
 import Tabs from '../../../components/Tabs';
 import Button from '../../../components/Button';
 import { Icon as GIcon } from '../../../components/Icon';
 import UserTable from '../../../components/UserTable';
 import Examination from '../../../components/Examination';
-import Tabs from '../../../components/Tabs';
 import menu from '../index';
 import { BindPhone, BindEmail, EditInfo, RealAuth, EditAvatar, InviteModal } from '../../../components/OtherModal';
 import VipRenew from '../../../components/VipRenew';
@@ -33,7 +33,7 @@ class LogItem extends Component {
 
   render() {
     const { data = {} } = this.props;
-    const { total = [], detail = [] } = data;
+    const { total = [], type } = data;
     const { open } = this.state;
     return (
       <div className="log-item">
@@ -47,20 +47,38 @@ class LogItem extends Component {
         <div className="open">
           <GIcon name={open ? 'small-up' : 'small-down'} onClick={() => this.setState({ open: !open })} />
         </div>
-        <div hidden={!open} className="table">
-          <UserTable size="small" columns={this.columns} data={detail} />
-          <div className="t-r">
-            <Link to="">继续练习></Link>
-          </div>
-        </div>
+        {type === 'exercise' && this.renderExercise()}
+        {type === 'examination' && this.renderExamination()}
+        {type === 'course' && this.renderCourse()}
       </div>
     );
   }
+
+  renderExercise() {
+    const { data = {} } = this.props;
+    const { detail = [] } = data;
+    const { open } = this.state;
+    return <div hidden={!open} className="table">
+      <UserTable size="small" columns={this.columns} data={detail} />
+      <div className="t-r">
+        <Link to="/exercise">继续练习></Link>
+      </div>
+    </div>;
+  }
+
+  renderExamination() {
+
+  }
+
+  renderCourse() {
+
+  }
 }
 
 export default class extends Page {
   initState() {
     return {
+      day: 'today',
       showExamination: false,
       timeList: [
         { title: '长难句', time: '3h60min', ratio: 10, color: '#3C39CC' },
@@ -142,6 +160,7 @@ export default class extends Page {
       .then(result => {
         this.setState({ messages: result.list });
       });
+    this.refreshDay(this.state.day);
   }
 
   readAllMessage() {
@@ -152,7 +171,44 @@ export default class extends Page {
   }
 
   refreshDay(value) {
-    console.log(value);
+    let time = '';
+    switch (value) {
+      case 'today':
+        time = moment().format('YYYY-MM-DD');
+        break;
+      case 'yesterday':
+        time = moment().add(-1, 'days').format('YYYY-MM-DD');
+        break;
+      case 'before':
+        time = moment().add(-2, 'days').format('YYYY-MM-DD');
+        break;
+      default:
+        time = value.format('YYYY-MM-DD');
+        value = 'other';
+    }
+    My.getStudy(time).then(result => {
+      const study = [];
+      const exerciseMap = {};
+      result.exerciseList.forEach(row => {
+        exerciseMap[row.title] = row;
+      });
+      study.push({
+        type: 'exercise',
+        total: [
+          { title: '<span>练习和订正</span>', width: 130 },
+          { title: result.exerciseTime ? formatSeconds(result.exerciseTime).replace(/([0-9]+)(m|min|h|hour|s)/g, '<b>$1</b>$2') : '<b>-</b>', width: 90 },
+          { title: `<b>${result.exerciseQuestion || '-'}</b>题`, width: 80 },
+          { title: `超过了<b>${result.exerciseExceed ? formatPercent(result.exerciseExceed.rank, result.exerciseExceed.total) : '-%'}</b>的用户` },
+        ],
+        detail: [
+          { title: '做题数', sc: exerciseMap.sc ? exerciseMap.sc.number : '-', cr: exerciseMap.cr ? exerciseMap.cr.number : '-', rc: exerciseMap.rc ? exerciseMap.rc.number : '-' },
+          { title: '平均正确率', sc: exerciseMap.sc ? formatPercent(exerciseMap.sc.correct, exerciseMap.sc.number) : '-%', cr: exerciseMap.cr ? formatPercent(exerciseMap.cr.correct, exerciseMap.cr.number) : '-%', rc: exerciseMap.rc ? formatPercent(exerciseMap.rc.correct, exerciseMap.rc.number) : '-%' },
+          { title: '平均用时', sc: exerciseMap.sc ? exerciseMap.sc.time / exerciseMap.sc.number : '-', cr: exerciseMap.cr ? exerciseMap.cr.time / exerciseMap.cr.number : '-', rc: exerciseMap.rc ? exerciseMap.rc.time / exerciseMap.rc.number : '-' },
+        ],
+      });
+      this.setState({ study });
+    });
+    this.setState({ day: value, time, showCal: false });
   }
 
   renderView() {
@@ -175,8 +231,8 @@ export default class extends Page {
   }
 
   renderLog() {
-    const { logList = [] } = this.state;
-    const { latest = {}, diff = 0, diffPercent = 0, diffLast = 0, diffLastPercent = 0, day, time } = this.state;
+    const { study = [] } = this.state;
+    const { latest = {}, diff = 0, diffPercent = 0, diffLast = 0, diffLastPercent = 0, day, time, showCal } = this.state;
     return (
       <div className="log-layout">
         <div className="header">
@@ -197,8 +253,7 @@ export default class extends Page {
             type="tag"
             width={54}
             space={5}
-<<<<<<< HEAD
-            value={day}
+            active={day}
             tabs={[{ title: '今天', key: 'today' }, { title: '昨天', key: 'yesterday' }, { title: '前天', key: 'before' }]}
             onChange={(value) => {
               this.refreshDay(value);
@@ -209,15 +264,12 @@ export default class extends Page {
             <Assets className="right" name="calendar" onClick={() => {
               this.setState({ showCal: true });
             }} />
+            {showCal && <Calendar className="cal" fullscreen={false} disabledDate={date => date.unix() <= moment.unix()} onSelect={(date) => {
+              this.refreshDay(date);
+            }} />}
           </div>
-=======
-            value={'1'}
-            tabs={[{ title: '123', key: '1' }, { title: '123', key: '1' }, { title: '123', key: '1' }]}
-          />
-          <Assets className="right" name="calendar" />
->>>>>>> 56361e65e19d9288d1bd8eda36fef496dccddbcc
         </div>
-        {logList.map((log, index) => {
+        {study.map((log, index) => {
           return <LogItem key={index} data={log} />;
         })}
       </div>

+ 1 - 1
server/data/src/main/java/com/qxgmat/data/relation/mapping/UserCourseRecordRelationMapper.xml

@@ -120,7 +120,7 @@
           and ucr.`create_time` &gt; #{startTime,jdbcType=VARCHAR}
         </if>
         <if test="endTime != null">
-          and ur.`create_time` &lt; #{endTime,jdbcType=VARCHAR}
+          and ucr.`create_time` &lt; #{endTime,jdbcType=VARCHAR}
         </if>
         group by ucr.`user_id`
       ) as aaa, (select @rank:=0) as bbb  order by `user_time` desc

+ 8 - 6
server/gateway-api/src/main/java/com/qxgmat/controller/api/MyController.java

@@ -472,7 +472,8 @@ public class MyController {
         }
         // todo 练习统计排行
         UserRankStatRelation exerciseRank = userReportService.rankExerciseByTime(user.getId(), startTime, endTime);
-        exerciseRank.setTotal(total);
+        if (exerciseRank != null)
+            exerciseRank.setTotal(total);
 
         dto.setExerciseTime(exerciseTime);
         dto.setExerciseQuestion(exerciseQuestion);
@@ -496,7 +497,8 @@ public class MyController {
         }
         // todo 模考统计排行
         UserRankStatRelation examinationRank = userReportService.rankExaminationByTime(user.getId(), startTime, endTime);
-        examinationRank.setTotal(total);
+        if (examinationRank != null)
+            examinationRank.setTotal(total);
 
         dto.setExaminationTime(examinationTime);
         dto.setExaminationPaper(examinationPaper);
@@ -523,14 +525,14 @@ public class MyController {
             courseResultList.add(d);
         }
         // todo 听课统计排行
-        UserRankStatRelation classRank = userCourseRecordService.rankByTime(user.getId(), startTime, endTime);
-        classRank.setTotal(total);
+        UserRankStatRelation courseRank = userCourseRecordService.rankByTime(user.getId(), startTime, endTime);
+        if (courseRank != null)
+            courseRank.setTotal(total);
 
         dto.setCourseTime(courseTime);
         dto.setCourseNumber(courseNumber);
         dto.setCourseList(courseResultList);
-        dto.setCourseExceed(classRank);
-
+        dto.setCourseExceed(courseRank);
 
         return ResponseHelp.success(dto);
     }