code Copy code
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮,点击只翻转,不传数据 -->
<el-button
type="danger"
v-if="!isFlipped"
@click="flipCard"
>忘记</el-button>
<el-button
type="success"
v-if="!isFlipped"
@click="flipCard"
>认识</el-button>
<!-- 背面按钮,点击提交复习结果 -->
<el-button
type="danger"
v-if="isFlipped"
@click="submitReviewResult(false)"
>忘记</el-button>
<el-button
type="success"
v-if="isFlipped"
@click="submitReviewResult(true)"
>认识</el-button>
</div>
</div>
</div>
<!-- 当没有复习单词时显示提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 弹窗:选择待学习单词 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">
确认选择({{ selectedToAdd.length }})
</el-button>
</span>
</template>
</el-dialog>
卡片左上角记录对应单词score
Show full message · 420 lines Assistant2025-06-08 07:47 UTC Copy response
要在卡片左上角显示当前单词的 score,可以按下面步骤修改你已有的代码:
1. 模板中卡片左上角新增显示 score
找到 .card 区块内,给 .card-front 和 .card-back 都添加一个左上角的分数字段,比如放一个小的 div,放在两面都显示。
vue Copy code
<div class="card" :class="{ flipped: isFlipped }">
<!-- 左上角 score -->
<div class="score-badge">
Score: {{ currentWord.score ?? 0 }}
</div>
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>🔊 发音</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>🔊 发音</el-button>
</div>
</div>
2. 增加 CSS 样式,让分数固定在卡片左上角
你 style scoped 里,添加如下样式:
css Copy code
.score-badge {
position: absolute;
top: 15px;
left: 15px;
background-color: #409EFF; /* element-plus 主色,也可以改 */
color: white;
font-weight: bold;
padding: 6px 12px;
border-radius: 12px;
font-size: 14px;
pointer-events: none; /* 避免盖住按钮等交互 */
user-select: none;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
z-index: 10;
}
这会让 score 显示在卡片左上角,样式美观。
3. 注意:
currentWord.score 取分数字段时用 ?? 0 以防没有值时显示0。
你的后端接口数据结构中需要包含 score,如果没有,需要在接口返回的单词数据里加入该字段。
如果你的分数字段名不是 score,请根据实际字段名替换。
总结
只要在卡片容器内放一个定位元素显示分数,再增加相应样式即可展示左上角分数。
如需我帮你做完整修改后的代码,告诉我!
Assistant2025-06-08 07:49 UTC Copy response
以下是你完整代码的修改版本,已在卡片左上角添加了 score 显示:
Show full message · 456 lines Show full message · 446 lines Assistant2025-06-08 08:09 UTC Copy response
你想在页面中实时显示当前待复习单词的数量 ,与展示“通过次数”的 score-badge 类似。可以在左侧“短期记忆区域”里的适当位置新增一个显示单词数量的元素。
假设你想把它放在“短期记忆区域”标题行右侧按钮组的左边,和“查看已选单词”、“选择单词”按钮并列。示例如下:
vue Copy code
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div style="display: flex; align-items: center;">
<!-- 实时显示当前复习单词数量 -->
<div style="margin-right: 20px; font-weight: bold; font-size: 16px; color: #409EFF;">
待复习单词数量: {{ reviewList.length }}
</div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
详细说明
reviewList 是一个数组,存的是当前复习列表,你用 reviewList.length 就是当前待复习的单词数量。
这里加了个新的 div,显示成“待复习单词数量: XX”。
使用内联样式让它和按钮保持在一排,并且字体加粗、颜色用主色(#409EFF)醒目一点。
你也可以用更适合你的样式,或者换成 el-tag、el-badge 等组件来显示数字。
完整修改示例(仅展示标题区域部分)
vue Copy code
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div style="display: flex; align-items: center;">
<div style="margin-right: 20px; font-weight: bold; font-size: 16px; color: #409EFF;">
待复习单词数量: {{ reviewList.length }}
</div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
这样用户就可以随时看到当前待复习的单词数量了。如果你想放在其他位置,也可以告诉我,我帮你调整!
Show full message · 448 lines Assistant2025-06-08 08:15 UTC Copy response
你说“待复习单词数量一直显示3”,很可能是下面两个原因之一:
1. 后端接口返回的数据固定,或 reviewList 数组没动态更新
2. 页面没正确触发数据更新,或者复习过程未正确移除单词
你每做一次复习(点击“认识”或“忘记”),reviewIndex 加1,卡片更新,但 reviewList 数组并没有删减,只用索引控制当前显示的单词。
reviewList.length 还是接口拉取的全部复习单词数量,不随进度变化。
这就导致你的 reviewList.length 是固定的请求列表长度(3),而不是剩余待复习单词数量。
解决方案
方法1:显示剩余待复习单词数量变量
当前代码的 reviewList 是完整列表,reviewIndex 是当前卡片索引,剩余实质是:
js Copy code
const remainingCount = computed(() => {
return reviewList.value.length - reviewIndex.value
})
在模板中显示:
vue Copy code
<div>待复习单词数量: {{ remainingCount }}</div>
方法2:代码示例,补充 remainingCount 计算属性
在 <script setup> 部分添加:
js Copy code
import { computed } from 'vue'
// 剩余单词数量
const remainingCount = computed(() => {
return Math.max(reviewList.value.length - reviewIndex.value, 0)
})
模板中改成:
vue Copy code
<div>待复习单词数量: {{ remainingCount }}</div>
备注
这样 remainingCount 会随复习索引递增自动减少,显示“还剩多少未复习”更直观。
reviewList.length 是总列表,固定不变,reviewIndex 变化,你计算剩余数量更合理。
总结
你当前直接用 reviewList.length 做待复习数量,它是总单词数,不随复习进度减少。
改用剩余数量计算即可解决:
js Copy code
const remainingCount = computed(() => Math.max(reviewList.value.length - reviewIndex.value, 0))
再在模板用 {{ remainingCount }} 显示即可。
如果需要我帮你直接写完整对应的修改代码,也可以告诉我!
package com.example.springboot.controller;
import com.example.springboot.entity.Study;
import com.example.springboot.service.StudyService;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/study")
public class StudyController {
code Copy code
@Resource
private StudyService studyService;
// 用户选择单词
@PostMapping("/select-words")
public ResponseEntity<?> userSelectWords(@RequestBody Map<String, Object> payload) {
Integer userId = (Integer) payload.get("userId");
List<Integer> wordIds = (List<Integer>) payload.get("wordIds");
if (userId == null || wordIds == null || wordIds.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("参数错误");
}
int insertedCount = studyService.insertUserSelectedWords(userId, wordIds);
if (insertedCount == 0) {
return ResponseEntity.status(HttpStatus.CONFLICT).body("所有单词已存在,无需再添加");
}
return ResponseEntity.ok("成功添加 " + insertedCount + " 个新单词");
}
// 获取已经选择的单词列表
@GetMapping("/select-words")
public ResponseEntity<?> getSelectedWords(@RequestParam(value = "userId", required = false) String userIdStr) {
if (userIdStr == null || !userIdStr.matches("\d+")) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("缺少或非法的 userId");
}
Show full message · 855 lines Assistant2025-06-08 08:18 UTC Copy response
根据你的需求,这里帮你修改 StudyService 里的相关逻辑:
用户选择单词加入 user_word_memory 时,同时删除 user_word_plan 里对应单词(避免重复待选)。
达到通过标准,单词从 user_word_memory 迁移到 long_term_memory 后,删除 user_word_memory 记录。
具体修改步骤
1. 新增删除 user_word_plan 逻辑
需要在 StudyMapper 或新建 UserWordPlanMapper 提供删除接口,这里为了方便,先在 StudyMapper 加方法:
StudyMapper.java
java Copy code
// 删除user_word_plan中对应记录
int deletePlanWord(@Param("userId") Integer userId, @Param("wordId") Integer wordId);
StudyMapper.xml
xml Copy code
<!-- 删除user_word_plan中对应记录 -->
<delete id="deletePlanWord" parameterType="map">
DELETE FROM user_word_plan WHERE user_id = #{userId} AND word_id = #{wordId}
</delete>
2. 修改 StudyService.insertUserSelectedWords 方法
新增调用删除 user_word_plan 逻辑:
java Copy code
public int insertUserSelectedWords(Integer userId, List<Integer> wordIds) {
int count = 0;
for (Integer wordId : wordIds) {
// 先判断 user_word_memory是否存在
Study exist = studyMapper.selectStudyByUserIdAndWordId(userId, wordId);
if (exist == null) {
Study study = new Study();
study.setUserId(userId);
study.setWordId(wordId);
study.setScore(0);
study.setLastSeen(-1);
studyMapper.insertStudy(study);
count++;
// 删除 user_word_plan 中对应记录
studyMapper.deletePlanWord(userId, wordId);
}
}
return count;
}
3. 迁移单词到长期记忆后,删除 user_word_memory 记录(你已有这步)
你已有:
java Copy code
studyMapper.deleteStudyByUserIdAndWordId(userId, wordId);
这部分保持不变即可!
你的 StudyMapper 接口示例
java Copy code
@Mapper
public interface StudyMapper {
// ...
int deletePlanWord(@Param("userId") Integer userId, @Param("wordId") Integer wordId);
}
你的 StudyMapper.xml示例
xml Copy code
<delete id="deletePlanWord" parameterType="map">
DELETE FROM user_word_plan WHERE user_id = #{userId} AND word_id = #{wordId}
</delete>
总结
在选单词接口插入 user_word_memory 后,删除 user_word_plan 对应单词(避免重复选择)。
在复习达到通过标准后,迁移单词到长期记忆表,删除 user_word_memory 单词(你已有)。
以上保证了数据的一致性和状态正确更新。
如果你需要我帮你写完整的修改后的 StudyService 或 Controller 具体代码,也可以告诉我。
Assistant2025-06-08 08:30 UTC Copy response
你说“释义显示数字”,这通常是前端渲染时取错了字段,导致把数字(比如单词ID)显示成释义了。
结合你后端以及前端代码,原因大概率是:
分析原因
后端接口 /study/review-list 返回的单词列表其实是 Study 实体
java Copy code
public List<Study> getReviewList(Integer userId, int round) {
return studyMapper.getReviewList(userId, round);
}
你这个接口直接返回 Study 实体列表,没有联表查询出对应的单词释义(definition)字段。
前端reviewList 是显示卡片单词释义,模版用 currentWord.definition
vue Copy code
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
但是从后端接口返回的 Study 对象,没有definition字段,导致 Vue 取不到对应释义,取到的是默认字段值,或者错用了别的字段(如id等数字),最终显示数字。
解决方案
你需要改造后端接口 /study/review-list,让返回的结果不仅包含 Study 表中的字段,还包含单词的详细信息,比如 word 和 definition。
方案一:SQL 联表查询,把单词表 words 中数据关联进来
修改 StudyMapper 的selectReviewCandidates,把单词信息一起查询:
xml Copy code
<select id="selectReviewCandidates" resultType="com.example.springboot.entity.Study" parameterType="map">
SELECT
um.id,
um.user_id AS userId,
um.word_id AS wordId,
um.score,
um.last_seen AS lastSeen,
w.word,
w.definition
FROM user_word_memory um
JOIN words w ON um.word_id = w.id
WHERE um.user_id = #{userId} AND #{round} - um.last_seen >= #{cooldown}
ORDER BY um.score ASC, um.last_seen ASC
LIMIT #{limit}
</select>
说明:
这里加了 w.word, w.definition 字段,关联查询单词内容。
Study 实体需要有对应的 word 和 definition 字段(或者你建一个新的 DTO 类)。
方案二:新增专门的 DTO 类(推荐)
定义一个包含 Study 和 Word 相关字段的综合类(或者 Map),供接口返回:
java Copy code
public class StudyWordDTO {
private Integer id;
private Integer userId;
private Integer wordId;
private Integer score;
private Integer lastSeen;
private String word;
private String definition;
// 省略getter/setter
}
然后 Mapper 中声明:
xml Copy code
<select id="selectReviewCandidates" resultType="com.example.springboot.dto.StudyWordDTO" parameterType="map">
<!-- SQL 同上 -->
</select>
方案三:前端额外请求单词释义
不推荐,效率低且复杂。
你需要修改实体类 Study
确保 Study 实体里有字段:
java Copy code
private String word;
private String definition;
// 以及getter/setter
否则 MyBatis 没法自动映射出来。
总结
后端接口返回的数据结构不完整,是造成“释义显示数字”的关键原因。
你需要在数据库查询中联表查询 words 表,获取单词及释义,并映射到返回实体。
改完后,前端的 currentWord.definition 就会是正确的释义文本,不会显示数字。
如果需要,我可以帮你写修改后的完整 Mapper XML 和实体代码示例。
Show full message · 448 lines Assistant2025-06-08 08:36 UTC Copy response
你现在复习单词数量没有实时更新,原因应该是:
原因分析
你目前显示复习单词数量的地方,本质上用的是 reviewList.length 或类似数据,它是在调用 fetchReviewList() 时异步加载的。
但是,你在复习过程中,只是更新了 reviewIndex(当前复习单词索引) ,reviewList 数组本身没有改变(数组元素不变,只有索引在走)。
因此 reviewList.length 是从接口得到的「当前批次复习列表的总数」,不会随复习进度自动减少,数量显示没变是正常的。
解决方案
1. 显示「剩余待复习单词数」而非列表总数
你定义一个计算属性 remainingCount,表示剩余尚未复习的单词数:
js Copy code
const remainingCount = computed(() => {
return Math.max(reviewList.value.length - reviewIndex.value, 0)
})
2. 在模板中显示这个剩余数
找你待显示单词数量的 <div>,写:
vue Copy code
<div>待复习单词数量: {{ remainingCount }}</div>
代码示例
<script setup>
js Copy code
import { computed } from 'vue'
// ...
const remainingCount = computed(() => {
return Math.max(reviewList.value.length - reviewIndex.value, 0)
})
<template>
vue Copy code
<div class="score-badge">
<div>待复习单词数量: {{ remainingCount }}</div>
</div>
3. 备注
你的复习流程是:后端返回一个批次单词列表 reviewList,前端通过 reviewIndex 控制当前复习进度。
这种设计下,数组长度不变,复习进行时索引递增,因此这样计算剩余数更准确。
如果想要实时从数据库拿最新数量,应该调用查询接口刷新列表,这样开销较大且意义不大。
总结:
不要直接显示 reviewList.length, 因为它是当前批次总单词数。
定义一个计算属性,用 reviewList.length - reviewIndex 得到剩余数。
在模板用该计算属性展示即可。
如果需要,我可以帮你调整带这部分的完整代码。
Assistant2025-06-08 08:37 UTC Copy response
以下是你的 Vue 组件完整代码示例,已集成:
实时显示 剩余待复习单词数量 (使用计算属性 remainingCount)
其他功能保持不变
Show full message · 430 lines Show full message · 448 lines Assistant2025-06-08 08:41 UTC Copy response
你要实时显示 user_word_memory 表中的待复习单词数量 ,而不是仅靠前端当前批次数据剩余数量。
这里给你一个方案:
实现思路
后端提供一个接口,返回当前用户 user_word_memory 表中待复习单词总数。
前端调用该接口,获取最新待复习数量,通过一个状态变量保存并展示。
你可以在:
页面初次加载时
每次提交复习结果后(复习单词完成,数量可能减少)
选择更多单词添加后(数量增加)
调用此接口刷新待复习数量。
具体步骤
1. 后端API示例
Controller新增接口
java Copy code
// 获取用户待复习单词数量
@GetMapping("/pending-count")
public ResponseEntity<?> getPendingCount(@RequestParam Integer userId) {
int count = studyService.getPendingCount(userId);
return ResponseEntity.ok(count);
}
Service新增方法
java Copy code
public int getPendingCount(Integer userId) {
return studyMapper.countPendingWords(userId);
}
Mapper新增方法
java Copy code
int countPendingWords(@Param("userId") Integer userId);
Mapper.xml新增SQL
xml Copy code
<select id="countPendingWords" resultType="int" parameterType="int">
SELECT COUNT(*) FROM user_word_memory WHERE user_id = #{userId}
</select>
2. 前端实现
新增状态变量
js Copy code
const pendingCount = ref(0)
新增获取数量方法
js Copy code
const fetchPendingCount = async () => {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning("请先登录或设置 userId")
try {
const res = await axios.get('/study/pending-count', { params: { userId: Number(userId) }})
pendingCount.value = res.data
} catch {
ElMessage.error("获取待复习单词数量失败")
}
}
Show full message · 448 lines Assistant2025-06-08 08:44 UTC Copy response
根据你后端已经新增了获取user_word_memory待复习单词数的接口,我帮你修改了前端代码,添加了一个状态pendingCount,在需要刷新数量的地方调用接口,并在卡片左上角显示该数量。
这是修改后的完整 Vue 代码:
Show full message · 446 lines Show full message · 426 lines Assistant2025-06-08 08:51 UTC Copy response
你当前“通过次数”显示在卡片背面,而且用了 .score-badge 这个样式类,而“待复习单词数量”也是用同样的类,导致两者样式看起来类似。
你希望:
通过次数 放在卡片左上角 ,样式像悬浮小标签。
待复习单词数量 样式不同(比如放在页面其他位置,或者样式更简洁,或者放在卡片容器内但不一样的样式)。
方案示范
1. 新增两个样式类
.score-badge 保留给“通过次数”用,样式悬浮卡片左上角。
.pending-count 新增给“待复习单词数量”,样式简洁放上方或者适合的位置。
2. 代码示例
vue Copy code
<div class="card-container" v-if="reviewList.length">
<!-- 待复习单词数量,样式新加 -->
<div class="pending-count">
待复习单词数量: {{ pendingCount }}
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<!-- 通过次数,卡片左上角 -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<!-- 按钮 -->
<div class="btn-group">
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
Assistant2025-06-08 08:53 UTC Copy response
好的,以下是根据你的需求 修改后的完整代码:
通过次数 独立使用 .score-badge 类,固定卡片左上角悬浮显示。
待复习单词数量 用 .pending-count 类,放在卡片容器顶部,样式简洁清晰,不同于通过次数。
Show full message · 448 lines Assistant2025-06-08 08:58 UTC Copy response
明白了,你希望**“通过次数”只在卡片正面左上角显示,不再出现在卡片背面**。我帮你去了卡片背面通过次数的内容,保留了卡片正面左上角悬浮显示的“通过次数”,样式和位置如下。
这是调整后的完整关键部分代码:
vue Copy code
<template>
<!-- 省略其他部分保持不变 -->
<div class="card-container" v-if="reviewList.length">
<!-- 待复习单词数量(卡片容器顶部) -->
<div class="pending-count">
待复习单词数量: {{ pendingCount }}
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<!-- 正面左上角显示通过次数 -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<!-- 去掉了卡片背面的通过次数显示 -->
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<!-- 按钮组保持不变 -->
<div class="btn-group">
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 省略其他部分保持不变 -->
</template>
样式部分保持不变,只要保证 .score-badge 样式是悬浮定位在卡片左上角即可。
如果你需要,我可以帮你发完整的改完的文件(包含 <script setup> 和 <style> 部分),或者你把上面修改点替换到你已有代码里就行了。
Show full message · 437 lines Assistant2025-06-08 09:03 UTC Copy response
你模板里的背面部分没有去掉“通过次数”相关代码,导致背面依然显示。
仔细看下你发的代码,背面部分还有:
vue Copy code
<div class="score-badge" style="position: static; margin-bottom: 12px;">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
</div>
这段是在卡片背面的 <div class="card-face card-back"> 中,所以背面会显示通过次数。
解决办法
要去掉背面这段 代码,只在正面悬浮显示即可。
你需要把卡片背面代码改成如下,只保留释义和发音按钮:
vue Copy code
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
你的完整卡片部分调整示例:
vue Copy code
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<!-- 通过次数(卡片正面左上角悬浮显示) -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<!-- 这里没有通过次数 -->
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
</div>
总结
正面(card-front)左上角用 .score-badge 显示“通过次数”,悬浮显示。
背面(card-back)不要显示“通过次数”。
确认模板中卡片背面部分代码已去除通过次数相关内容。
如果你按照上述方法编辑了但仍显示,请确认:
你的浏览器无缓存(尝试硬刷新、清缓存)
编辑的文件被正确保存并重新编译
同一个组件文件没有重复写显示“通过次数”的代码
需要我帮你写完整删去背面通过次数的完整代码段也可以,告诉我!
Show full message · 436 lines Assistant2025-06-08 09:05 UTC Copy response
你说你想要的是正面不显示通过次数,背面显示通过次数 ,下面是基于你现有代码调整后的完整代码,重点说明:
卡片正面不显示“通过次数”
卡片背面左上角显示“通过次数”
对应调整了模板和样式,保证背面“通过次数”是定位且样式合适
修改重点
模板:
正面card-front 不带 通过次数标签
背面card-back 加一个通过次数的 <div class="score-badge-back">...</div>
样式:
新增 .score-badge-back,定位于卡片背面左上角,样式类似 .score-badge,可适度调整
完整示例代码:
Show full message · 467 lines Show full message · 437 lines Assistant2025-06-08 09:07 UTC Copy response
你说“通过次数”没有出现在卡片的左上角,通常是因为样式 .score-badge 被遮挡或没有生效导致的。下面帮你排查和调整,让“通过次数”正确显示在卡片正面和背面的 左上角 。
1. 确认 .score-badge 位置和父容器 position
.score-badge 需要 position: absolute,且它的最近的定位父元素需要 position: relative,否则绝对定位无效,位置会错乱。
修改 .card 添加 position: relative; (你代码已有),确认:
css Copy code
.card {
position: relative;
...
}
确认 .score-badge 样式(你的代码要和下面类似):
css Copy code
.score-badge {
position: absolute;
top: 15px;
left: 15px;
background-color: #409EFF;
color: white;
font-weight: bold;
padding: 6px 12px;
border-radius: 12px;
font-size: 14px;
pointer-events: none;
user-select: none;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
z-index: 10;
}
2. 确保 .score-badge 在 .card 内,并且在对应的卡片面(front 或 back)的直接子元素 才更合适
你可以试试修改模板,把 .score-badge 放到卡片某一面的第一层子元素,这样避免重叠或被 card-face 覆盖。
例如,如果放在背面左上角:
vue Copy code
<div class="card-face card-back">
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<!-- 下面是内容 -->
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
...
</div>
3. 有时 backface-visibility 或 overflow 会影响布局显示,可尝试调试以下:
把 .score-badge 放到 .card-face 内,且确保 .card-face 没有限制 overflow 或添加合适。
4. 推荐的完整示范卡片结构(尤其是背面)
Show full message · 428 lines Assistant2025-06-08 09:18 UTC Copy response
你遇到的问题:前端成功添加单词后,卡片区域(复习列表)没有立即更新显示,必须刷新页面才能看到新的复习单词 。这是因为:
点击“确认选择”后,虽然你调用了 fetchSelectedWords 和 fetchPendingCount,但是没有立即调用刷新复习列表的接口 fetchReviewList,所以 reviewList 并没有最新数据。
导致卡片区域数据没更新。
解决方案
在submitSelectedWords成功添加单词后,增加调用 fetchReviewList() 刷新复习列表 。
修改后的关键代码片段
前端submitSelectedWords函数,可以加上 await fetchReviewList():
js Copy code
async function submitSelectedWords() {
const userId = localStorage.getItem('userId')
const wordIds = selectedToAdd.value.map(item => item.wordId || item.id)
if (wordIds.length < 10) {
ElMessage.warning('请至少选择10个单词')
return
}
try {
await axios.post('/study/select-words', { userId: Number(userId), wordIds })
dialogVisible.value = false
await fetchSelectedWords()
await fetchPendingCount()
await fetchReviewList() // *** 加入这里,刷新复习列表 ***
ElMessage.success('添加成功')
} catch {
ElMessage.error('添加单词失败')
}
}
其他操作类似的建议
你也可以在添加单词完成、删除单词完成后,根据需要调用 fetchReviewList() 保持界面数据同步。
为什么要调用 fetchReviewList() ?
选择待学习单词,就相当于往 user_word_memory 加单词。
复习单词列表 reviewList 是从后端接口 /study/review-list 获取符合冷却和优先级的短期记忆词汇列表。
添加后要刷新复习列表,前端才能获取最新复习单词并渲染出来。
总结
添加单词接口调用成功后同时调用 fetchReviewList()。
这样卡片组件数据更新,页面能立即显示新添加的复习单词。
核心是刷新数据源 reviewList,否则视图没变化。
如果你需要,我可以帮你做完整含改动的示例代码。需要告诉我!
package com.example.springboot.controller;
import com.example.springboot.dto.AddWordsRequest;
import com.example.springboot.entity.TodayPlan;
import com.example.springboot.service.TodayPlanService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/today-plan")
public class TodayPlanController {
code Copy code
@Resource
private TodayPlanService todayPlanService;
@PostMapping("/add")
public void addWordsToPlan(@RequestBody AddWordsRequest request) {
todayPlanService.addWordsToPlan(request.getUserId(), request.getWordIds());
}
@GetMapping("/todaylist")
public List<TodayPlan> getTodayPlan(@RequestParam Integer userId) {
return todayPlanService.getTodayPlan(userId);
}
@PostMapping("/delete")
public void deleteWordsFromPlan(@RequestBody AddWordsRequest request) {
todayPlanService.deletePlansByIds(request.getUserId(), request.getWordIds());
}
}
package com.example.springboot.service;
import com.example.springboot.entity.TodayPlan;
import com.example.springboot.mapper.TodayPlanMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class TodayPlanService {
code Copy code
@Resource
private TodayPlanMapper todayPlanMapper;
public void addWordsToPlan(Integer userId, List<Integer> wordIds) {
todayPlanMapper.batchInsertPlans(userId, wordIds);
}
public List<TodayPlan> getTodayPlan(Integer userId) {
return todayPlanMapper.getTodayPlans(userId);
}
public List<TodayPlan> exportPlanByIds(Integer userId, List<Integer> ids) {
return todayPlanMapper.selectPlansByIds(userId, ids);
}
public void deletePlansByIds(Integer userId, List<Integer> ids) {
todayPlanMapper.deletePlansByIds(userId, ids);
}
Show full message · 491 lines Assistant2025-06-08 09:40 UTC Copy response
你目前逻辑设计是:
long_term_memory 表表示用户的长期记忆单词
user_word_plan 是用户的“待学习”或“待背诵”单词计划表
现在你想:
取消长期记忆表的存在 ,即不再用 long_term_memory 表管理单词
允许用户从长期记忆单词中也能选单词放入待背诵计划 (user_word_plan)
解决方案思路
后端的数据结构调整:
可以考虑直接取消对 long_term_memory 表的操作,或者忽略该表不做复用。
单词选择范围扩大:
前端选择范围 pendingWords 或待选单词列表,需要包含以前属于long_term_memory的单词。
移除依赖长时记忆表的逻辑:
如 processReviewResult 中的搬迁操作不再执行 long_term_memory,而是直接从 user_word_memory 里维护单词状态。
确保 user_word_plan 中单词来源覆盖 :
user_word_plan 也要能包含“之前属于长时记忆”或“所有单词”的统一展示,方便用户选择。
具体如何做?
1. 后端:
修改复习相关逻辑,取消搬迁 long_term_memory ,复习状态都放或维护在 user_word_memory。
user_word_plan 获取单词列表的时候,接口需调整为包含所有单词,不区分是否属于长期记忆。
你可以改 pending-words 接口,让它返回 所有未加入计划的单词 ,不再排除长期记忆单词。
2. 前端修改:
3. 示意示例:
后端示例
假设你原来排除了 long_term_memory 的单词,改为:
sql Copy code
-- 获取所有但未在计划中的单词,包括长时记忆
SELECT * FROM words w
WHERE w.id NOT IN (
SELECT word_id FROM user_word_plan WHERE user_id = #{userId}
)
这样用户可以把任何单词加入计划。
前端示例
你的单词选择代码无需变更,只要后端接口 pending-words 返回的数据包含所有可选单词即可。
重点总结
取消长期记忆表的迁移逻辑 ,让所有单词状态集中维护(简化逻辑同时避免单词“被挤出”长期记忆这类状态切换);
确保待选单词范围完整 ,包含原长期记忆单词,方便用户随时选取;
后端复习接口 /study/review-list 直接读 user_word_memory 状态即可 。
如果你需要,我可以帮你给出去掉长期记忆表迁移的后端代码修改示例 ,以及前端对接完整示例 ,告诉我!
我表达错了,单词已经存在long_term_memory,用户不应该能选取存在long_term_memory的单词放入user_word_plan里面,这样会有冲突
Assistant2025-06-08 09:41 UTC Copy response
明白了,你的需求是:
单词如果已经存在 long_term_memory 表,说明用户已经进入长期记忆阶段,不应再在“今日计划”或者 user_word_plan 中再次出现,避免状态冲突。
用户在“待学习单词”选择时,不应该能选择那些已存在于 long_term_memory 表的单词。
解决方案综述
1. 后端控制:待学习单词列表接口要排除已经存在于 long_term_memory 的单词
在你的 /study/pending-words 或 /today-plan 获取可选单词的接口中,SQL 查询需要排除在 long_term_memory 表中同时属于该用户的单词。
2. 具体做法
假设有以下三张表:
words (单词基本信息)
user_word_plan(今日计划/待学习单词)
long_term_memory(长期记忆单词)
你需要保证:
sql Copy code
SELECT w.*
FROM words w
LEFT JOIN user_word_plan p ON p.word_id = w.id AND p.user_id = #{userId}
LEFT JOIN long_term_memory ltm ON ltm.word_id = w.id AND ltm.user_id = #{userId}
WHERE p.word_id IS NULL -- 未加入计划
AND ltm.word_id IS NULL -- 不在长期记忆中
或者你目前已有获取待选单词的逻辑,给它加入排除条件:
sql Copy code
AND w.id NOT IN (
SELECT word_id FROM long_term_memory WHERE user_id = #{userId}
)
3. 示例:修改 MyBatis Mapper XML 里 selectPendingWordsFromPlan 的 SQL:
xml Copy code
<select id="selectPendingWordsFromPlan" parameterType="map" resultType="com.example.springboot.entity.Study">
SELECT
NULL AS id,
up.user_id AS userId,
up.word_id AS wordId,
w.word AS word,
w.definition AS definition,
0 AS score,
-1 AS lastSeen
FROM user_word_plan up
JOIN words w ON up.word_id = w.id
WHERE up.user_id = #{userId}
AND up.status = 'pending'
AND up.word_id NOT IN (
SELECT word_id FROM long_term_memory WHERE user_id = #{userId}
)
ORDER BY up.added_at ASC
LIMIT #{limit}
</select>
或者你查询可选单词列表的接口也可以类似:
sql Copy code
SELECT w.*
FROM words w
WHERE w.id NOT IN (
SELECT word_id FROM user_word_plan WHERE user_id = #{userId}
UNION
SELECT word_id FROM long_term_memory WHERE user_id = #{userId}
)
LIMIT #{limit}
4. 前端
5. 复习列表接口可同理排除已进入长期记忆的单词,避免重复出现。
总结
方案点 说明 【待选单词接口】 查询的时候加条件排除 long_term_memory 中的该用户单词 【今日计划接口】 保证不会包含长期记忆单词 【复习接口】 同理避免加载长期记忆单词(如从 user_word_memory 里筛选满足条件) 【前端选择逻辑】 无需额外限制,后端接口已过滤
如果你需要,我可以帮你准备具体的 Mapper XML 修改文件、后台服务更新代码示例,或者协助前端确认接口调用完整。告诉我!
Copy first response
Not yet included in a published release.
<template>
<el-row style="height: 100vh; padding: 20px;" :gutter="20">
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<!-- 左上角 score -->
<div class="score-badge">
Score: {{ currentWord.score ?? 0 }}
</div>
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮,点击只翻转,不传数据 -->
<el-button
type="danger"
v-if="!isFlipped"
@click="flipCard"
>忘记</el-button>
<el-button
type="success"
v-if="!isFlipped"
@click="flipCard"
>认识</el-button>
<!-- 背面按钮,点击提交复习结果 -->
<el-button
type="danger"
v-if="isFlipped"
@click="submitReviewResult(false)"
>忘记</el-button>
<el-button
type="success"
v-if="isFlipped"
@click="submitReviewResult(true)"
>认识</el-button>
</div>
</div>
</div>
<!-- 当没有复习单词时显示提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 弹窗:选择待学习单词 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">
确认选择({{ selectedToAdd.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-row>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
axios.defaults.baseURL = 'http://localhost:8080'
// 状态
const selectedWords = ref([])
const pendingWords = ref([])
const selectedToAdd = ref([])
const selectedToDelete = ref([])
const dialogVisible = ref(false)
const selectedDialogVisible = ref(false)
// 当前复习轮次
const round = ref(1)
// 复习单词列表(短期记忆复习单词,每轮调用接口获取)
const reviewList = ref([])
// 当前复习索引
const reviewIndex = ref(0)
// 卡片是否翻转状态
const isFlipped = ref(false)
// 当前复习单词
const currentWord = computed(() => {
return reviewList.value[reviewIndex.value] || {}
})
// 语音合成器缓存
const utterance = new SpeechSynthesisUtterance()
utterance.lang = 'en-US'
// 页面加载时预热语音合成器,减少首次朗读延迟
onMounted(() => {
speechSynthesis.speak(new SpeechSynthesisUtterance(' '))
fetchReviewList()
})
// 获取已选单词(用于已选单词弹窗)
const fetchSelectedWords = async () => {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning("请先登录或设置 userId")
try {
const res = await axios.get('/study/select-words', { params: { userId } })
selectedWords.value = res.data
} catch {
ElMessage.error("获取已选单词失败")
}
}
// 获取当前轮复习列表(短期记忆,符合冷却原则+优先级)
const fetchReviewList = async () => {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning("请先登录或设置 userId")
try {
const res = await axios.get('/study/review-list', {
params: { userId: Number(userId), round: round.value }
})
reviewList.value = res.data
reviewIndex.value = 0
isFlipped.value = false
if (reviewList.value.length === 0) {
ElMessage.success(`第${round.value}轮复习结束,无更多单词`)
return
}
speakWord(currentWord.value.word)
} catch (e) {
ElMessage.error("加载复习单词失败")
console.error(e)
}
}
// 翻转卡片(正面点击“忘记”或“认识”调用)
const flipCard = () => {
if (!currentWord.value.word) return
speakWord(currentWord.value.word)
isFlipped.value = true
}
// 提交复习结果(背面点击“忘记”或“认识”调用)
const submitReviewResult = async (remembered) => {
const userId = localStorage.getItem('userId')
if (!userId) {
ElMessage.warning("请先登录或设置 userId")
return
}
try {
await axios.post('/study/review-result', {
userId: Number(userId),
wordId: currentWord.value.wordId || currentWord.value.id,
round: round.value,
remembered: remembered
})
reviewIndex.value++
isFlipped.value = false
if (reviewIndex.value >= reviewList.value.length) {
round.value++
await fetchReviewList()
}
if (reviewIndex.value < reviewList.value.length) {
speakWord(currentWord.value.word)
}
} catch (e) {
ElMessage.error("提交复习结果失败")
console.error(e)
}
}
// 语音朗读函数
const speakWord = (text) => {
if (!text) return
if (speechSynthesis.speaking) {
speechSynthesis.cancel()
}
utterance.text = text
speechSynthesis.speak(utterance)
}
// 查看已选单词弹窗
const openSelectedDialog = async () => {
await fetchSelectedWords()
selectedToDelete.value = []
selectedDialogVisible.value = true
}
// 打开选择单词弹窗
const openDialog = async () => {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning("请先登录或设置 userId")
try {
const res = await axios.get('/study/pending-words', {
params: { userId, limit: 100 }
})
pendingWords.value = res.data
dialogVisible.value = true
} catch {
ElMessage.error("获取待学习单词失败")
}
}
// 选择表格单词
const handleSelectionChange = (val) => {
selectedToAdd.value = val
}
const handleSelectedChange = (val) => {
selectedToDelete.value = val
}
// 确认添加单词
const submitSelectedWords = async () => {
const userId = localStorage.getItem('userId')
const wordIds = selectedToAdd.value.map(item => item.wordId || item.id)
if (wordIds.length < 10) return ElMessage.warning("请至少选择10个单词")
try {
await axios.post('/study/select-words', { userId: Number(userId), wordIds })
dialogVisible.value = false
await fetchSelectedWords()
ElMessage.success("添加成功")
} catch {
ElMessage.error("添加单词失败")
}
}
// 单个删除
const removeWord = async (row) => {
const userId = localStorage.getItem('userId')
try {
await axios.post('/study/remove-word', {
userId: Number(userId),
wordId: row.wordId || row.id
})
await fetchSelectedWords()
ElMessage.success("删除成功")
} catch {
ElMessage.error("删除失败")
}
}
// 批量删除
const batchRemoveWords = async () => {
const userId = localStorage.getItem('userId')
const wordIds = selectedToDelete.value.map(item => item.wordId || item.id)
if (!wordIds.length) return ElMessage.warning("请选择要删除的单词")
try {
await axios.post('/study/remove-words', { userId: Number(userId), wordIds })
await fetchSelectedWords()
selectedToDelete.value = []
ElMessage.success("批量删除成功")
} catch {
ElMessage.error("批量删除失败")
}
}
</script>
<style scoped>
.left-panel {
display: flex;
flex-direction: column;
border: 1px solid #eee;
height: 100%;
}
.card-container {
flex-grow: 1;
margin-top: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
perspective: 1000px;
width: 100%;
}
/* 卡片尺寸你可以自己调整 */
.card {
width: 100%;
max-width: 550px;
height: 500px; /* ← 你可以根据需要自行改这个高度 */
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
border-radius: 16px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
background-color: #fff;
}
/* 新增:左上角score样式 */
.score-badge {
position: absolute;
top: 15px;
left: 15px;
background-color: #409EFF;
color: white;
font-weight: bold;
padding: 6px 12px;
border-radius: 12px;
font-size: 14px;
pointer-events: none;
user-select: none;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
z-index: 10;
}
.card.flipped {
transform: rotateY(180deg);
}
.card-face {
position: absolute;
width: 100%;
height: 100%;
padding: 20px;
box-sizing: border-box;
backface-visibility: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.card-front {
font-size: 1em;
font-weight: bold;
}
.card-back {
transform: rotateY(180deg);
font-size: 1.2em;
text-align: center;
line-height: 1.6;
}
.card-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
.btn-group {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 30px;
margin-top: 30px;
}
/* 按钮样式更大更显眼 */
.btn-group .el-button {
padding: 18px 40px;
font-size: 18px;
border-radius: 10px;
font-weight: bold;
min-width: 140px;
transition: all 0.2s ease-in-out;
}
.btn-group .el-button:hover {
transform: scale(1.05);
}
</style>
说明:
新增了 .score-badge div,展示当前单词 score,默认显示0防止异常。
.score-badge 绝对定位在卡片左上角,样式和 Element Plus 主题色匹配,美观且不干扰卡片其他元素。
你后端的接口返回的每个单词对象需包含 score 字段(或改成你实际字段名)。
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮,点击只翻转,不传数据 -->
<el-button
type="danger"
v-if="!isFlipped"
@click="flipCard"
>忘记</el-button>
<el-button
type="success"
v-if="!isFlipped"
@click="flipCard"
>认识</el-button>
<!-- 背面按钮,点击提交复习结果 -->
<el-button
type="danger"
v-if="isFlipped"
@click="submitReviewResult(false)"
>忘记</el-button>
<el-button
type="success"
v-if="isFlipped"
@click="submitReviewResult(true)"
>认识</el-button>
</div>
</div>
</div>
<!-- 当没有复习单词时显示提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 弹窗:选择待学习单词 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">
确认选择({{ selectedToAdd.length }})
</el-button>
</span>
</template>
</el-dialog>
在这里加一个实时显示单词数量
通过次数: {{ currentWord.score ?? 0 }}/3
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score -->
<div class="score-badge">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
<!-- 实时显示当前复习单词数量 -->
<div>待复习单词数量: {{ reviewList.length }}</div>
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮,点击只翻转,不传数据 -->
<el-button
type="danger"
v-if="!isFlipped"
@click="flipCard"
>忘记</el-button>
<el-button
type="success"
v-if="!isFlipped"
@click="flipCard"
>认识</el-button>
<!-- 背面按钮,点击提交复习结果 -->
<el-button
type="danger"
v-if="isFlipped"
@click="submitReviewResult(false)"
>忘记</el-button>
<el-button
type="success"
v-if="isFlipped"
@click="submitReviewResult(true)"
>认识</el-button>
</div>
</div>
</div>
<!-- 当没有复习单词时显示提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 弹窗:选择待学习单词 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">
确认选择({{ selectedToAdd.length }})
</el-button>
</span>
</template>
</el-dialog>
Integer userId = Integer.valueOf(userIdStr);
return ResponseEntity.ok(studyService.getSelectedWordsByUserId(userId));
}
// 获取用户可选的未学习单词(用于前端弹窗选择)
@GetMapping("/pending-words")
public ResponseEntity<?> getPendingWords(
@RequestParam("userId") Integer userId,
@RequestParam(value = "limit", defaultValue = "100") Integer limit) {
return ResponseEntity.ok(studyService.getPendingWords(userId, limit));
}
// 删除用户选择的单词
@PostMapping("/remove-word")
public ResponseEntity<?> removeWord(@RequestBody Map<String, Object> payload) {
Integer userId = (Integer) payload.get("userId");
Integer wordId = (Integer) payload.get("wordId");
if (userId == null || wordId == null) {
return ResponseEntity.badRequest().body("参数错误");
}
int rows = studyService.deleteWord(userId, wordId);
if (rows > 0) {
return ResponseEntity.ok("删除成功");
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("未找到单词");
}
}
// 批量删除用户选择的单词
@PostMapping("/remove-words")
public ResponseEntity<?> removeWords(@RequestBody Map<String, Object> payload) {
Integer userId = (Integer) payload.get("userId");
List<Integer> wordIds = (List<Integer>) payload.get("wordIds");
if (userId == null || wordIds == null || wordIds.isEmpty()) {
return ResponseEntity.badRequest().body("参数错误");
}
int rows = studyService.deleteWords(userId, wordIds);
if (rows > 0) {
return ResponseEntity.ok("批量删除成功");
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("未找到单词");
}
}
// 获取当前轮复习列表
@GetMapping("/review-list")
public ResponseEntity<?> getReviewList(@RequestParam Integer userId, @RequestParam Integer round) {
List<Study> reviewList = studyService.getReviewList(userId, round);
return ResponseEntity.ok(reviewList);
}
// 处理复习结果
@PostMapping("/review-result")
public ResponseEntity<?> postReviewResult(@RequestBody Map<String, Object> payload) {
Integer userId = (Integer) payload.get("userId");
Integer wordId = (Integer) payload.get("wordId");
Integer round = (Integer) payload.get("round");
Boolean remembered = (Boolean) payload.get("remembered");
if (userId == null || wordId == null || round == null || remembered == null) {
return ResponseEntity.badRequest().body("参数错误");
}
studyService.processReviewResult(userId, wordId, round, remembered);
return ResponseEntity.ok("复习结果处理成功");
}
}
package com.example.springboot.service;
import com.example.springboot.entity.LongTermMemory;
import com.example.springboot.entity.Study;
import com.example.springboot.entity.Word;
import com.example.springboot.mapper.LongTermMemoryMapper;
import com.example.springboot.mapper.StudyMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class StudyService {
code Copy code
@Resource
private StudyMapper studyMapper;
@Resource
private LongTermMemoryMapper longTermMemoryMapper;
private static final int COOLDOWN = 2;
private static final int PASS_SCORE = 3;
private static final int N = 3;
/**
* 获取当前轮次可复习单词列表(冷却结束且优先级最高的N个)
* @param userId 用户ID
* @param round 当前轮次
* @return 待复习单词列表
*/
public List<Study> getReviewList(Integer userId, int round) {
// 筛选 user_word_memory表中满足冷却条件的单词并排序,取前N个
return studyMapper.selectReviewCandidates(userId, round, COOLDOWN, N);
}
/**
* 处理用户对单词的复习反馈
* @param userId 用户ID
* @param wordId 单词ID
* @param currentRound 当前轮次
* @param remembered 是否记住(true表示认识,false表示忘记)
*/
public void processReviewResult(Integer userId, Integer wordId, int currentRound, boolean remembered) {
Study study = studyMapper.selectStudyByUserIdAndWordId(userId, wordId);
if (study == null) return;
int newScore = study.getScore();
if (remembered) {
newScore += 1;
} else {
newScore = Math.max(newScore - 1, 0);
}
if (newScore >= PASS_SCORE) {
// 达标,迁移到 long_term_memory
moveToLongTermMemory(study, currentRound, newScore);
studyMapper.deleteStudyByUserIdAndWordId(userId, wordId);
} else {
// 未达标,更新score及last_seen,留在 user_word_memory
study.setScore(newScore);
study.setLastSeen(currentRound);
studyMapper.updateStudy(study);
}
}
/**
* 新单词迁移到长期记忆表,初始各字段赋值
*/
private void moveToLongTermMemory(Study study, int currentRound, int score) {
// 创建 long_term_memory 实例(假设有相应实体类LongTermMemory)
LongTermMemory ltm = new LongTermMemory();
ltm.setUserId(study.getUserId());
ltm.setWordId(study.getWordId());
ltm.setReviewCount(1);
ltm.setEaseFactor(2.5f);
ltm.setIntervalDays(0);
ltm.setLastReviewDate(java.sql.Date.valueOf(java.time.LocalDate.now())); // 设置为当天
ltm.setNextReviewDate(java.sql.Date.valueOf(java.time.LocalDate.now().plusDays(1))); // 初始下一天复习
ltm.setLastScore(score);
longTermMemoryMapper.insertLongTermMemory(ltm);
}
// 用户手动选择单词加入记忆
public int insertUserSelectedWords(Integer userId, List<Integer> wordIds) {
int count = 0;
for (Integer wordId : wordIds) {
Study exist = studyMapper.selectStudyByUserIdAndWordId(userId, wordId);
if (exist == null) {
Study study = new Study();
study.setUserId(userId);
study.setWordId(wordId);
study.setScore(0);
study.setLastSeen(-1);
studyMapper.insertStudy(study);
count++;
}
}
return count;
}
// 获取用户选择的单词
public List<Word> getSelectedWordsByUserId(Integer userId) {
return studyMapper.selectSelectedWordsByUserId(userId);
}
// 获取待背单词
public List<Study> getPendingWords(Integer userId, int limit) {
return studyMapper.selectPendingWordsFromPlan(userId, limit);
}
// 删除单词
public int deleteWord(Integer userId, Integer wordId) {
return studyMapper.deleteStudyByUserIdAndWordId(userId, wordId);
}
// 批量删除
public int deleteWords(Integer userId, List<Integer> wordIds) {
return studyMapper.deleteStudiesByUserIdAndWordIds(userId, wordIds);
}
}
package com.example.springboot.mapper;
import com.example.springboot.entity.Study;
import com.example.springboot.entity.Word;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface StudyMapper {
code Copy code
// 从user_word_plan抽取指定数量且user_word_memory中不存在的单词
List<Study> selectPendingWordsFromPlan(@Param("userId") Integer userId, @Param("limit") int limit);
// 查询 user_word_memory 中对应记录
Study selectStudyByUserIdAndWordId(@Param("userId") Integer userId, @Param("wordId") Integer wordId);
// 插入 user_word_memory
int insertStudy(Study study);
// 更新 user_word_memory
int updateStudy(Study study);
// 查询单词详情
Word selectWordById(@Param("id") Integer id);
// 查询某个用户的所有已选单词详细信息
List<Word> selectSelectedWordsByUserId(@Param("userId") Integer userId);
// 单个删除
int deleteStudyByUserIdAndWordId(@Param("userId") Integer userId, @Param("wordId") Integer wordId);
// 批量删除
int deleteStudiesByUserIdAndWordIds(@Param("userId") Integer userId, @Param("wordIds") List<Integer> wordIds);
// 根据冷却轮数筛选出符合条件的单词,排序返回前N个
List<Study> selectReviewCandidates(@Param("userId") Integer userId,
@Param("round") int round,
@Param("cooldown") int cooldown,
@Param("limit") int limit);
code Copy code
<!-- 从 user_word_plan 中抽取待学习且 user_word_memory 中不存在的单词 -->
<select id="selectPendingWordsFromPlan" parameterType="map" resultType="com.example.springboot.entity.Study">
SELECT
NULL AS id,
up.user_id AS userId,
up.word_id AS wordId,
w.word AS word,
w.definition AS definition,
0 AS score,
-1 AS lastSeen
FROM user_word_plan up
JOIN words w ON up.word_id = w.id
LEFT JOIN user_word_memory um ON up.user_id = um.user_id AND up.word_id = um.word_id
WHERE up.user_id = #{userId} AND up.status = 'pending' AND um.id IS NULL
ORDER BY up.added_at ASC
LIMIT #{limit}
</select>
<!-- 查询 user_word_memory -->
<select id="selectStudyByUserIdAndWordId" parameterType="map" resultType="com.example.springboot.entity.Study">
SELECT id, user_id AS userId, word_id AS wordId, score, last_seen AS lastSeen
FROM user_word_memory
WHERE user_id = #{userId} AND word_id = #{wordId}
</select>
<!-- 插入 user_word_memory -->
<insert id="insertStudy" parameterType="com.example.springboot.entity.Study" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user_word_memory(user_id, word_id, score, last_seen)
VALUES(#{userId}, #{wordId}, #{score}, #{lastSeen})
</insert>
<!-- 更新 user_word_memory -->
<update id="updateStudy" parameterType="com.example.springboot.entity.Study">
UPDATE user_word_memory
SET score = #{score},
last_seen = #{lastSeen}
WHERE id = #{id}
</update>
<!-- 查询单词详情 -->
<select id="selectWordById" parameterType="int" resultType="com.example.springboot.entity.Word">
SELECT id, word, definition, pronunciation, custom_content AS customContent, created_at AS createdAt
FROM words
WHERE id = #{id}
</select>
<!-- 查询用户已选择的单词 -->
<select id="selectSelectedWordsByUserId" parameterType="int" resultType="com.example.springboot.entity.Word">
SELECT
w.id,
w.word,
w.definition,
w.pronunciation,
w.custom_content AS customContent,
w.created_at AS createdAt
FROM user_word_memory uwm
JOIN words w ON uwm.word_id = w.id
WHERE uwm.user_id = #{userId}
</select>
<!-- 删除单个单词 -->
<delete id="deleteStudyByUserIdAndWordId" parameterType="map">
DELETE FROM user_word_memory WHERE user_id = #{userId} AND word_id = #{wordId}
</delete>
<!-- 批量删除单词 -->
<delete id="deleteStudiesByUserIdAndWordIds" parameterType="map">
DELETE FROM user_word_memory WHERE user_id = #{userId} AND word_id IN
<foreach item="wordId" collection="wordIds" open="(" separator="," close=")">
#{wordId}
</foreach>
</delete>
<select id="selectReviewCandidates" resultType="com.example.springboot.entity.Study" parameterType="map">
SELECT id, user_id AS userId, word_id AS wordId, score, last_seen AS lastSeen
FROM user_word_memory
WHERE user_id = #{userId} AND #{round} - last_seen >= #{cooldown}
ORDER BY score ASC, last_seen ASC
LIMIT #{limit}
</select>
import com.example.springboot.entity.LongTermMemory;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface LongTermMemoryMapper {
int insertLongTermMemory(LongTermMemory ltm);
}
code Copy code
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score -->
<div class="score-badge">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
<!-- 实时显示当前复习单词数量 -->
<div>待复习单词数量: {{ }}</div>
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮,点击只翻转,不传数据 -->
<el-button
type="danger"
v-if="!isFlipped"
@click="flipCard"
>忘记</el-button>
<el-button
type="success"
v-if="!isFlipped"
@click="flipCard"
>认识</el-button>
<!-- 背面按钮,点击提交复习结果 -->
<el-button
type="danger"
v-if="isFlipped"
@click="submitReviewResult(false)"
>忘记</el-button>
<el-button
type="success"
v-if="isFlipped"
@click="submitReviewResult(true)"
>认识</el-button>
</div>
</div>
</div>
<!-- 当没有复习单词时显示提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 弹窗:选择待学习单词 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">
确认选择({{ selectedToAdd.length }})
</el-button>
</span>
</template>
</el-dialog>
帮忙修改一下:加入到user_word_memory表的单词,要删除对应user_word_plan表里的单词,加入到long_term_memory的单词,要删除对应user_word_memory里的单词
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score -->
<div class="score-badge">
<div>待复习单词数量: {{ }}</div>
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<div class="score-badge">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
</div>
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮,点击只翻转,不传数据 -->
<el-button
type="danger"
v-if="!isFlipped"
@click="flipCard"
>忘记</el-button>
<el-button
type="success"
v-if="!isFlipped"
@click="flipCard"
>认识</el-button>
<!-- 背面按钮,点击提交复习结果 -->
<el-button
type="danger"
v-if="isFlipped"
@click="submitReviewResult(false)"
>忘记</el-button>
<el-button
type="success"
v-if="isFlipped"
@click="submitReviewResult(true)"
>认识</el-button>
</div>
</div>
</div>
<!-- 当没有复习单词时显示提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 弹窗:选择待学习单词 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">
确认选择({{ selectedToAdd.length }})
</el-button>
</span>
</template>
</el-dialog>
为什么待单词复习数量,没有实时更新获取user_word_memory的单词数量
<template>
<el-row style="height: 100vh; padding: 20px;" :gutter="20">
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score 和剩余数量 -->
<div class="score-badge">
<div>待复习单词数量: {{ remainingCount }}</div>
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<div class="score-badge" style="position: static; margin-bottom: 12px;">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
</div>
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮 -->
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<!-- 背面按钮 -->
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
</el-row>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
axios.defaults.baseURL = 'http://localhost:8080'
const selectedWords = ref([])
const pendingWords = ref([])
const selectedToAdd = ref([])
const selectedToDelete = ref([])
const dialogVisible = ref(false)
const selectedDialogVisible = ref(false)
const round = ref(1)
const reviewList = ref([])
const reviewIndex = ref(0)
const isFlipped = ref(false)
const currentWord = computed(() => reviewList.value[reviewIndex.value] || {})
const remainingCount = computed(() => Math.max(reviewList.value.length - reviewIndex.value, 0))
const utterance = new SpeechSynthesisUtterance()
utterance.lang = 'en-US'
onMounted(() => {
speechSynthesis.speak(new SpeechSynthesisUtterance(' '))
fetchReviewList()
})
const fetchSelectedWords = async () => {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/select-words', { params: { userId } })
selectedWords.value = res.data
} catch {
ElMessage.error('获取已选单词失败')
}
}
const fetchReviewList = async () => {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/review-list', {
params: { userId: Number(userId), round: round.value }
})
reviewList.value = res.data
reviewIndex.value = 0
isFlipped.value = false
if (reviewList.value.length === 0) {
ElMessage.success(`第${round.value}轮复习结束,无更多单词`)
return
}
speakWord(currentWord.value.word)
} catch (e) {
ElMessage.error('加载复习单词失败')
console.error(e)
}
}
const flipCard = () => {
if (!currentWord.value.word) return
speakWord(currentWord.value.word)
isFlipped.value = true
}
const submitReviewResult = async (remembered) => {
const userId = localStorage.getItem('userId')
if (!userId) {
ElMessage.warning('请先登录或设置 userId')
return
}
try {
await axios.post('/study/review-result', {
userId: Number(userId),
wordId: currentWord.value.wordId || currentWord.value.id,
round: round.value,
remembered: remembered
})
reviewIndex.value++
isFlipped.value = false
if (reviewIndex.value >= reviewList.value.length) {
round.value++
await fetchReviewList()
} else {
speakWord(currentWord.value.word)
}
} catch (e) {
ElMessage.error('提交复习结果失败')
console.error(e)
}
}
const speakWord = (text) => {
if (!text) return
if (speechSynthesis.speaking) speechSynthesis.cancel()
utterance.text = text
speechSynthesis.speak(utterance)
}
const openSelectedDialog = async () => {
await fetchSelectedWords()
selectedToDelete.value = []
selectedDialogVisible.value = true
}
const openDialog = async () => {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/pending-words', {
params: { userId, limit: 100 }
})
pendingWords.value = res.data
dialogVisible.value = true
} catch {
ElMessage.error('获取待学习单词失败')
}
}
const handleSelectionChange = (val) => {
selectedToAdd.value = val
}
const handleSelectedChange = (val) => {
selectedToDelete.value = val
}
const submitSelectedWords = async () => {
const userId = localStorage.getItem('userId')
const wordIds = selectedToAdd.value.map(item => item.wordId || item.id)
if (wordIds.length < 10) {
ElMessage.warning('请至少选择10个单词')
return
}
try {
await axios.post('/study/select-words', { userId: Number(userId), wordIds })
dialogVisible.value = false
await fetchSelectedWords()
ElMessage.success('添加成功')
} catch {
ElMessage.error('添加单词失败')
}
}
const removeWord = async (row) => {
const userId = localStorage.getItem('userId')
try {
await axios.post('/study/remove-word', {
userId: Number(userId),
wordId: row.wordId || row.id
})
await fetchSelectedWords()
ElMessage.success('删除成功')
} catch {
ElMessage.error('删除失败')
}
}
const batchRemoveWords = async () => {
const userId = localStorage.getItem('userId')
const wordIds = selectedToDelete.value.map(item => item.wordId || item.id)
if (wordIds.length === 0) {
ElMessage.warning('请选择要删除的单词')
return
}
try {
await axios.post('/study/remove-words', { userId: Number(userId), wordIds })
await fetchSelectedWords()
selectedToDelete.value = []
ElMessage.success('批量删除成功')
} catch {
ElMessage.error('批量删除失败')
}
}
</script>
<style scoped>
.left-panel {
display: flex;
flex-direction: column;
border: 1px solid #eee;
height: 100%;
}
.card-container {
flex-grow: 1;
margin-top: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
perspective: 1000px;
width: 100%;
}
.card {
width: 100%;
max-width: 550px;
height: 500px;
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
border-radius: 16px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
background-color: #fff;
}
.score-badge {
position: absolute;
top: 15px;
left: 15px;
background-color: #409EFF;
color: white;
font-weight: bold;
padding: 6px 12px;
border-radius: 12px;
font-size: 14px;
pointer-events: none;
user-select: none;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
z-index: 10;
}
.card.flipped {
transform: rotateY(180deg);
}
.card-face {
position: absolute;
width: 100%;
height: 100%;
padding: 20px;
box-sizing: border-box;
backface-visibility: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.card-front {
font-size: 1em;
font-weight: bold;
}
.card-back {
transform: rotateY(180deg);
font-size: 1.2em;
text-align: center;
line-height: 1.6;
}
.card-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
.btn-group {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 30px;
margin-top: 30px;
}
.btn-group .el-button {
padding: 18px 40px;
font-size: 18px;
border-radius: 10px;
font-weight: bold;
min-width: 140px;
transition: all 0.2s ease-in-out;
}
.btn-group .el-button:hover {
transform: scale(1.05);
}
</style>
主要改动
新增计算属性 remainingCount,计算剩余待复习单词数量,
模板中用 {{ remainingCount }} 显示剩余数量,
复习过程更新 reviewIndex,实时反应剩余数量,
如果你需要后端代码示例或者其他辅助,也可以告诉我。
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score -->
<div class="score-badge">
<div>待复习单词数量: {{ }}</div>
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<div class="score-badge">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
</div>
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮,点击只翻转,不传数据 -->
<el-button
type="danger"
v-if="!isFlipped"
@click="flipCard"
>忘记</el-button>
<el-button
type="success"
v-if="!isFlipped"
@click="flipCard"
>认识</el-button>
<!-- 背面按钮,点击提交复习结果 -->
<el-button
type="danger"
v-if="isFlipped"
@click="submitReviewResult(false)"
>忘记</el-button>
<el-button
type="success"
v-if="isFlipped"
@click="submitReviewResult(true)"
>认识</el-button>
</div>
</div>
</div>
<!-- 当没有复习单词时显示提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 弹窗:选择待学习单词 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">
确认选择({{ selectedToAdd.length }})
</el-button>
</span>
</template>
</el-dialog>
待复习单词的数量,我要获取的是user_word_memory的列表数,实时更新
修改 onMounted 调用 js Copy code
onMounted(async () => {
speechSynthesis.speak(new SpeechSynthesisUtterance(' '))
await fetchPendingCount() // 新增刷新数量
await fetchReviewList()
})
提交复习结果后刷新数量 js Copy code
const submitReviewResult = async (remembered) => {
const userId = localStorage.getItem('userId')
if (!userId) {
ElMessage.warning("请先登录或设置 userId")
return
}
try {
await axios.post('/study/review-result', {
userId: Number(userId),
wordId: currentWord.value.wordId || currentWord.value.id,
round: round.value,
remembered: remembered
})
reviewIndex.value++
isFlipped.value = false
await fetchPendingCount() // 新增:复习结果后刷新待复习数量
if (reviewIndex.value >= reviewList.value.length) {
round.value++
await fetchReviewList()
} else {
speakWord(currentWord.value.word)
}
} catch (e) {
ElMessage.error("提交复习结果失败")
console.error(e)
}
}
添加单词后刷新数量(示例) js Copy code
const submitSelectedWords = async () => {
const userId = localStorage.getItem('userId')
const wordIds = selectedToAdd.value.map(item => item.wordId || item.id)
if (wordIds.length < 10) return ElMessage.warning("请至少选择10个单词")
try {
await axios.post('/study/select-words', { userId: Number(userId), wordIds })
dialogVisible.value = false
await fetchSelectedWords()
await fetchPendingCount() // 新增刷新数量
ElMessage.success("添加成功")
} catch {
ElMessage.error("添加单词失败")
}
}
模板中显示 vue Copy code
<div class="score-badge">
<div>待复习单词数量: {{ pendingCount }}</div>
</div>
总结 关键点 说明 后端接口 新增 /study/pending-count 返回数量 前端状态 新增 pendingCount 数据获取 页面加载、复习结果提交、添加单词后刷新 显示位置 绑定模板 {{ pendingCount }}
这样就保证实时从数据库拿最新的待复习单词数量 ,准确无误。
如果你需要,我可以帮你写完整的后端 Controller + Service + Mapper代码示例,或者帮你整合以上前端代码。需要告诉我!
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score -->
<div class="score-badge">
<div>待复习单词数量: {{ }}</div>
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<div class="score-badge">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
</div>
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮,点击只翻转,不传数据 -->
<el-button
type="danger"
v-if="!isFlipped"
@click="flipCard"
>忘记</el-button>
<el-button
type="success"
v-if="!isFlipped"
@click="flipCard"
>认识</el-button>
<!-- 背面按钮,点击提交复习结果 -->
<el-button
type="danger"
v-if="isFlipped"
@click="submitReviewResult(false)"
>忘记</el-button>
<el-button
type="success"
v-if="isFlipped"
@click="submitReviewResult(true)"
>认识</el-button>
</div>
</div>
</div>
<!-- 当没有复习单词时显示提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 弹窗:选择待学习单词 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">
确认选择({{ selectedToAdd.length }})
</el-button>
</span>
</template>
</el-dialog>
<template>
<el-row style="height: 100vh; padding: 20px;" :gutter="20">
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score -->
<div class="score-badge">
<div>待复习单词数量: {{ pendingCount }}</div>
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<div class="score-badge" style="position: static; margin-bottom: 12px;">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
</div>
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮 -->
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<!-- 背面按钮 -->
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
</el-row>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
axios.defaults.baseURL = 'http://localhost:8080'
const selectedWords = ref([])
const pendingWords = ref([])
const selectedToAdd = ref([])
const selectedToDelete = ref([])
const dialogVisible = ref(false)
const selectedDialogVisible = ref(false)
const round = ref(1)
const reviewList = ref([])
const reviewIndex = ref(0)
const pendingCount = ref(0)
const isFlipped = ref(false)
const currentWord = computed(() => reviewList.value[reviewIndex.value] || {})
const utterance = new SpeechSynthesisUtterance()
utterance.lang = 'en-US'
async function fetchPendingCount() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/pending-count', { params: { userId: Number(userId) } })
pendingCount.value = res.data
} catch {
ElMessage.error('获取待复习单词数量失败')
}
}
async function fetchSelectedWords() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/select-words', { params: { userId } })
selectedWords.value = res.data
} catch {
ElMessage.error('获取已选单词失败')
}
}
async function fetchReviewList() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/review-list', {
params: { userId: Number(userId), round: round.value }
})
reviewList.value = res.data
reviewIndex.value = 0
isFlipped.value = false
if (reviewList.value.length === 0) {
ElMessage.success(`第${round.value}轮复习结束,无更多单词`)
return
}
speakWord(currentWord.value.word)
} catch (e) {
ElMessage.error('加载复习单词失败')
console.error(e)
}
}
function flipCard() {
if (!currentWord.value.word) return
speakWord(currentWord.value.word)
isFlipped.value = true
}
async function submitReviewResult(remembered) {
const userId = localStorage.getItem('userId')
if (!userId) {
ElMessage.warning('请先登录或设置 userId')
return
}
try {
await axios.post('/study/review-result', {
userId: Number(userId),
wordId: currentWord.value.wordId || currentWord.value.id,
round: round.value,
remembered: remembered
})
reviewIndex.value++
isFlipped.value = false
await fetchPendingCount() // 刷新待复习数量
if (reviewIndex.value >= reviewList.value.length) {
round.value++
await fetchReviewList()
} else {
speakWord(currentWord.value.word)
}
} catch (e) {
ElMessage.error('提交复习结果失败')
console.error(e)
}
}
function speakWord(text) {
if (!text) return
if (speechSynthesis.speaking) speechSynthesis.cancel()
utterance.text = text
speechSynthesis.speak(utterance)
}
async function openSelectedDialog() {
await fetchSelectedWords()
selectedToDelete.value = []
selectedDialogVisible.value = true
}
async function openDialog() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/pending-words', {
params: { userId, limit: 100 }
})
pendingWords.value = res.data
dialogVisible.value = true
} catch {
ElMessage.error('获取待学习单词失败')
}
}
function handleSelectionChange(val) {
selectedToAdd.value = val
}
function handleSelectedChange(val) {
selectedToDelete.value = val
}
async function submitSelectedWords() {
const userId = localStorage.getItem('userId')
const wordIds = selectedToAdd.value.map(item => item.wordId || item.id)
if (wordIds.length < 10) {
ElMessage.warning('请至少选择10个单词')
return
}
try {
await axios.post('/study/select-words', { userId: Number(userId), wordIds })
dialogVisible.value = false
await fetchSelectedWords()
await fetchPendingCount() // 选择后刷新数量
ElMessage.success('添加成功')
} catch {
ElMessage.error('添加单词失败')
}
}
async function removeWord(row) {
const userId = localStorage.getItem('userId')
try {
await axios.post('/study/remove-word', {
userId: Number(userId),
wordId: row.wordId || row.id
})
await fetchSelectedWords()
await fetchPendingCount() // 删除后刷新数量
ElMessage.success('删除成功')
} catch {
ElMessage.error('删除失败')
}
}
async function batchRemoveWords() {
const userId = localStorage.getItem('userId')
const wordIds = selectedToDelete.value.map(item => item.wordId || item.id)
if (!wordIds.length) {
ElMessage.warning('请选择要删除的单词')
return
}
try {
await axios.post('/study/remove-words', { userId: Number(userId), wordIds })
await fetchSelectedWords()
selectedToDelete.value = []
await fetchPendingCount() // 批量删除后刷新数量
ElMessage.success('批量删除成功')
} catch {
ElMessage.error('批量删除失败')
}
}
// 页面加载时同时刷新待复习数量和复习列表
onMounted(async () => {
speechSynthesis.speak(new SpeechSynthesisUtterance(' '))
await fetchPendingCount()
await fetchReviewList()
})
</script>
<style scoped>
.left-panel {
display: flex;
flex-direction: column;
border: 1px solid #eee;
height: 100%;
}
.card-container {
flex-grow: 1;
margin-top: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
perspective: 1000px;
width: 100%;
}
.card {
width: 100%;
max-width: 550px;
height: 500px;
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
border-radius: 16px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
background-color: #fff;
}
.score-badge {
position: absolute;
top: 15px;
left: 15px;
background-color: #409EFF;
color: white;
font-weight: bold;
padding: 6px 12px;
border-radius: 12px;
font-size: 14px;
pointer-events: none;
user-select: none;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
z-index: 10;
}
.card.flipped {
transform: rotateY(180deg);
}
.card-face {
position: absolute;
width: 100%;
height: 100%;
padding: 20px;
box-sizing: border-box;
backface-visibility: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.card-front {
font-size: 1em;
font-weight: bold;
}
.card-back {
transform: rotateY(180deg);
font-size: 1.2em;
text-align: center;
line-height: 1.6;
}
.card-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
.btn-group {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 30px;
margin-top: 30px;
}
.btn-group .el-button {
padding: 18px 40px;
font-size: 18px;
border-radius: 10px;
font-weight: bold;
min-width: 140px;
transition: all 0.2s ease-in-out;
}
.btn-group .el-button:hover {
transform: scale(1.05);
}
</style>
说明
新增 pendingCount 并调用 /study/pending-count 接口获取最新单词数。
在 submitReviewResult、添加单词、删除单词等操作后,都调用了 fetchPendingCount 刷新数量。
页面加载时 onMounted 会获取 pendingCount 和复习列表。
在卡片左上角用 {{ pendingCount }} 显示。
这样,待复习单词数量从数据库实时获取,数据和界面同步且实时更新 。
有任何问题或者需要进一步帮助,欢迎继续提问!
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<!-- 左上角 score -->
<div class="score-badge">
<div>待复习单词数量: {{ pendingCount }}</div>
</div>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<div class="score-badge" style="position: static; margin-bottom: 12px;">
<div>通过次数: {{ currentWord.score ?? 0 }}/3</div>
</div>
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<!-- 正面按钮 -->
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<!-- 背面按钮 -->
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧:区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
3. 样式 css Copy code
/* 通过次数 — 卡片左上角悬浮标签 */
.score-badge {
position: absolute;
top: 15px;
left: 15px;
background-color: #409EFF;
color: white;
font-weight: bold;
padding: 6px 12px;
border-radius: 12px;
font-size: 14px;
pointer-events: none;
user-select: none;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
z-index: 10;
}
/* 待复习单词数量,页面顶部或卡片容器顶部显示 */
.pending-count {
font-size: 18px;
font-weight: bold;
color: #409EFF;
padding: 10px 0 0 0;
margin-bottom: 10px;
user-select: none;
}
4. 说明
.score-badge 绝对定位卡片左上角,悬浮显示“通过次数”。
.pending-count 是普通块级元素,不遮挡卡片,颜色和字号清晰,但无阴影和圆角效果。
两者的样式分开,样式不冲突,看起来更合理。
5. 贴合你代码的整体位置 你可把 .pending-count 放在 .card-container 内,卡片正上方 ,不覆盖卡片内容:
vue Copy code
<div class="card-container" v-if="reviewList.length">
<div class="pending-count">
待复习单词数量: {{ pendingCount }}
</div>
<div class="card-wrapper">
...
<div class="score-badge">通过次数: {{ currentWord.score ?? 0 }}/3</div>
...
</div>
</div>
总结
把“通过次数”用 .score-badge 类,定位放卡片左上角。
把“待复习单词数量”用 .pending-count 类,放卡片容器顶部,样式简洁明显。
这样视觉上区分清晰,不混淆。
如果需要,我可帮你把这部分完整代码(含样式)打包发给你。需要告诉我!
<template>
<el-row style="height: 100vh; padding: 20px;" :gutter="20">
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 待复习单词数量 -->
<div class="pending-count" v-if="reviewList.length">
待复习单词数量: {{ pendingCount }}
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<!-- 通过次数(卡片左上角悬浮显示) -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
</el-row>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
axios.defaults.baseURL = 'http://localhost:8080'
const selectedWords = ref([])
const pendingWords = ref([])
const selectedToAdd = ref([])
const selectedToDelete = ref([])
const dialogVisible = ref(false)
const selectedDialogVisible = ref(false)
const round = ref(1)
const reviewList = ref([])
const reviewIndex = ref(0)
const pendingCount = ref(0)
const isFlipped = ref(false)
const currentWord = computed(() => reviewList.value[reviewIndex.value] || {})
const utterance = new SpeechSynthesisUtterance()
utterance.lang = 'en-US'
async function fetchPendingCount() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/pending-count', { params: { userId: Number(userId) } })
pendingCount.value = res.data
} catch {
ElMessage.error('获取待复习单词数量失败')
}
}
async function fetchSelectedWords() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/select-words', { params: { userId } })
selectedWords.value = res.data
} catch {
ElMessage.error('获取已选单词失败')
}
}
async function fetchReviewList() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/review-list', {
params: { userId: Number(userId), round: round.value }
})
reviewList.value = res.data
reviewIndex.value = 0
isFlipped.value = false
if (reviewList.value.length === 0) {
ElMessage.success(`第${round.value}轮复习结束,无更多单词`)
return
}
speakWord(currentWord.value.word)
} catch (e) {
ElMessage.error('加载复习单词失败')
console.error(e)
}
}
function flipCard() {
if (!currentWord.value.word) return
speakWord(currentWord.value.word)
isFlipped.value = true
}
async function submitReviewResult(remembered) {
const userId = localStorage.getItem('userId')
if (!userId) {
ElMessage.warning('请先登录或设置 userId')
return
}
try {
await axios.post('/study/review-result', {
userId: Number(userId),
wordId: currentWord.value.wordId || currentWord.value.id,
round: round.value,
remembered: remembered
})
reviewIndex.value++
isFlipped.value = false
await fetchPendingCount() // 刷新待复习数量
if (reviewIndex.value >= reviewList.value.length) {
round.value++
await fetchReviewList()
} else {
speakWord(currentWord.value.word)
}
} catch (e) {
ElMessage.error('提交复习结果失败')
console.error(e)
}
}
function speakWord(text) {
if (!text) return
if (speechSynthesis.speaking) speechSynthesis.cancel()
utterance.text = text
speechSynthesis.speak(utterance)
}
async function openSelectedDialog() {
await fetchSelectedWords()
selectedToDelete.value = []
selectedDialogVisible.value = true
}
async function openDialog() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/pending-words', {
params: { userId, limit: 100 }
})
pendingWords.value = res.data
dialogVisible.value = true
} catch {
ElMessage.error('获取待学习单词失败')
}
}
function handleSelectionChange(val) {
selectedToAdd.value = val
}
function handleSelectedChange(val) {
selectedToDelete.value = val
}
async function submitSelectedWords() {
const userId = localStorage.getItem('userId')
const wordIds = selectedToAdd.value.map(item => item.wordId || item.id)
if (wordIds.length < 10) {
ElMessage.warning('请至少选择10个单词')
return
}
try {
await axios.post('/study/select-words', { userId: Number(userId), wordIds })
dialogVisible.value = false
await fetchSelectedWords()
await fetchPendingCount() // 选择后刷新数量
ElMessage.success('添加成功')
} catch {
ElMessage.error('添加单词失败')
}
}
async function removeWord(row) {
const userId = localStorage.getItem('userId')
try {
await axios.post('/study/remove-word', {
userId: Number(userId),
wordId: row.wordId || row.id
})
await fetchSelectedWords()
await fetchPendingCount() // 删除后刷新数量
ElMessage.success('删除成功')
} catch {
ElMessage.error('删除失败')
}
}
async function batchRemoveWords() {
const userId = localStorage.getItem('userId')
const wordIds = selectedToDelete.value.map(item => item.wordId || item.id)
if (!wordIds.length) {
ElMessage.warning('请选择要删除的单词')
return
}
try {
await axios.post('/study/remove-words', { userId: Number(userId), wordIds })
await fetchSelectedWords()
selectedToDelete.value = []
await fetchPendingCount() // 批量删除后刷新数量
ElMessage.success('批量删除成功')
} catch {
ElMessage.error('批量删除失败')
}
}
// 页面加载时同时刷新待复习数量和复习列表
onMounted(async () => {
speechSynthesis.speak(new SpeechSynthesisUtterance(' '))
await fetchPendingCount()
await fetchReviewList()
})
</script>
<style scoped>
.left-panel {
display: flex;
flex-direction: column;
border: 1px solid #eee;
height: 100%;
}
.pending-count {
font-size: 18px;
font-weight: bold;
color: #409EFF;
padding: 10px 0 0 0;
margin-bottom: 10px;
user-select: none;
}
.card-container {
flex-grow: 1;
margin-top: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
perspective: 1000px;
width: 100%;
}
.card {
width: 100%;
max-width: 550px;
height: 500px;
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
border-radius: 16px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
background-color: #fff;
}
.score-badge {
position: absolute;
top: 15px;
left: 15px;
background-color: #409EFF;
color: white;
font-weight: bold;
padding: 6px 12px;
border-radius: 12px;
font-size: 14px;
pointer-events: none;
user-select: none;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
z-index: 10;
}
.card.flipped {
transform: rotateY(180deg);
}
.card-face {
position: absolute;
width: 100%;
height: 100%;
padding: 20px;
box-sizing: border-box;
backface-visibility: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.card-front {
font-size: 1em;
font-weight: bold;
}
.card-back {
transform: rotateY(180deg);
font-size: 1.2em;
text-align: center;
line-height: 1.6;
}
.card-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
.btn-group {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 30px;
margin-top: 30px;
}
.btn-group .el-button {
padding: 18px 40px;
font-size: 18px;
border-radius: 10px;
font-weight: bold;
min-width: 140px;
transition: all 0.2s ease-in-out;
}
.btn-group .el-button:hover {
transform: scale(1.05);
}
</style>
如果你需要“通过次数”显示在卡片背面的左上角,也可以告诉我,我可以帮你调整。现在代码中“通过次数”是悬浮在卡片正面的左上角。
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 待复习单词数量 -->
<div class="pending-count" v-if="reviewList.length">
待复习单词数量: {{ pendingCount }}
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<!-- 通过次数(卡片左上角悬浮显示) -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 待复习单词数量 -->
<div class="pending-count" v-if="reviewList.length">
待复习单词数量: {{ pendingCount }}
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<!-- 通过次数(卡片左上角悬浮显示) -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
<template>
<el-row style="height: 100vh; padding: 20px;" :gutter="20">
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 待复习单词数量 -->
<div class="pending-count" v-if="reviewList.length">
待复习单词数量: {{ pendingCount }}
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<!-- 通过次数:放在背面左上角 -->
<div class="score-badge-back">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
</el-row>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
axios.defaults.baseURL = 'http://localhost:8080'
const selectedWords = ref([])
const pendingWords = ref([])
const selectedToAdd = ref([])
const selectedToDelete = ref([])
const dialogVisible = ref(false)
const selectedDialogVisible = ref(false)
const round = ref(1)
const reviewList = ref([])
const reviewIndex = ref(0)
const pendingCount = ref(0)
const isFlipped = ref(false)
const currentWord = computed(() => reviewList.value[reviewIndex.value] || {})
const utterance = new SpeechSynthesisUtterance()
utterance.lang = 'en-US'
async function fetchPendingCount() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/pending-count', { params: { userId: Number(userId) } })
pendingCount.value = res.data
} catch {
ElMessage.error('获取待复习单词数量失败')
}
}
async function fetchSelectedWords() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/select-words', { params: { userId } })
selectedWords.value = res.data
} catch {
ElMessage.error('获取已选单词失败')
}
}
async function fetchReviewList() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/review-list', {
params: { userId: Number(userId), round: round.value }
})
reviewList.value = res.data
reviewIndex.value = 0
isFlipped.value = false
if (reviewList.value.length === 0) {
ElMessage.success(`第${round.value}轮复习结束,无更多单词`)
return
}
speakWord(currentWord.value.word)
} catch (e) {
ElMessage.error('加载复习单词失败')
console.error(e)
}
}
function flipCard() {
if (!currentWord.value.word) return
speakWord(currentWord.value.word)
isFlipped.value = true
}
async function submitReviewResult(remembered) {
const userId = localStorage.getItem('userId')
if (!userId) {
ElMessage.warning('请先登录或设置 userId')
return
}
try {
await axios.post('/study/review-result', {
userId: Number(userId),
wordId: currentWord.value.wordId || currentWord.value.id,
round: round.value,
remembered: remembered
})
reviewIndex.value++
isFlipped.value = false
await fetchPendingCount() // 刷新待复习数量
if (reviewIndex.value >= reviewList.value.length) {
round.value++
await fetchReviewList()
} else {
speakWord(currentWord.value.word)
}
} catch (e) {
ElMessage.error('提交复习结果失败')
console.error(e)
}
}
function speakWord(text) {
if (!text) return
if (speechSynthesis.speaking) speechSynthesis.cancel()
utterance.text = text
speechSynthesis.speak(utterance)
}
async function openSelectedDialog() {
await fetchSelectedWords()
selectedToDelete.value = []
selectedDialogVisible.value = true
}
async function openDialog() {
const userId = localStorage.getItem('userId')
if (!userId) return ElMessage.warning('请先登录或设置 userId')
try {
const res = await axios.get('/study/pending-words', {
params: { userId, limit: 100 }
})
pendingWords.value = res.data
dialogVisible.value = true
} catch {
ElMessage.error('获取待学习单词失败')
}
}
function handleSelectionChange(val) {
selectedToAdd.value = val
}
function handleSelectedChange(val) {
selectedToDelete.value = val
}
async function submitSelectedWords() {
const userId = localStorage.getItem('userId')
const wordIds = selectedToAdd.value.map(item => item.wordId || item.id)
if (wordIds.length < 10) {
ElMessage.warning('请至少选择10个单词')
return
}
try {
await axios.post('/study/select-words', { userId: Number(userId), wordIds })
dialogVisible.value = false
await fetchSelectedWords()
await fetchPendingCount() // 选择后刷新数量
ElMessage.success('添加成功')
} catch {
ElMessage.error('添加单词失败')
}
}
async function removeWord(row) {
const userId = localStorage.getItem('userId')
try {
await axios.post('/study/remove-word', {
userId: Number(userId),
wordId: row.wordId || row.id
})
await fetchSelectedWords()
await fetchPendingCount() // 删除后刷新数量
ElMessage.success('删除成功')
} catch {
ElMessage.error('删除失败')
}
}
async function batchRemoveWords() {
const userId = localStorage.getItem('userId')
const wordIds = selectedToDelete.value.map(item => item.wordId || item.id)
if (!wordIds.length) {
ElMessage.warning('请选择要删除的单词')
return
}
try {
await axios.post('/study/remove-words', { userId: Number(userId), wordIds })
await fetchSelectedWords()
selectedToDelete.value = []
await fetchPendingCount() // 批量删除后刷新数量
ElMessage.success('批量删除成功')
} catch {
ElMessage.error('批量删除失败')
}
}
// 页面加载时同时刷新待复习数量和复习列表
onMounted(async () => {
speechSynthesis.speak(new SpeechSynthesisUtterance(' '))
await fetchPendingCount()
await fetchReviewList()
})
</script>
<style scoped>
.left-panel {
display: flex;
flex-direction: column;
border: 1px solid #eee;
height: 100%;
}
.pending-count {
font-size: 18px;
font-weight: bold;
color: #409EFF;
padding: 10px 0 0 0;
margin-bottom: 10px;
user-select: none;
}
.card-container {
flex-grow: 1;
margin-top: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
perspective: 1000px;
width: 100%;
}
.card {
width: 100%;
max-width: 550px;
height: 500px;
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
border-radius: 16px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
background-color: #fff;
}
.score-badge {
position: absolute;
top: 15px;
left: 15px;
background-color: #409EFF;
color: white;
font-weight: bold;
padding: 6px 12px;
border-radius: 12px;
font-size: 14px;
pointer-events: none;
user-select: none;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
z-index: 10;
}
.card.flipped {
transform: rotateY(180deg);
}
.card-face {
position: absolute;
width: 100%;
height: 100%;
padding: 20px;
box-sizing: border-box;
backface-visibility: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.card-front {
font-size: 1em;
font-weight: bold;
}
.card-back {
transform: rotateY(180deg);
font-size: 1.2em;
text-align: center;
line-height: 1.6;
}
.card-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
.btn-group {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 30px;
margin-top: 30px;
}
.btn-group .el-button {
padding: 18px 40px;
font-size: 18px;
border-radius: 10px;
font-weight: bold;
min-width: 140px;
transition: all 0.2s ease-in-out;
}
.btn-group .el-button:hover {
transform: scale(1.05);
}
</style>
这样,“通过次数”只会显示在卡片背面左上角 。 正面没有此显示。
如果想要“通过次数”背面标签样式更为明显,可以告诉我,我可以帮你细化样式。
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 待复习单词数量 -->
<div class="pending-count" v-if="reviewList.length">
待复习单词数量: {{ pendingCount }}
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<h1>{{ currentWord.word }}</h1>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
<div class="card-face card-back">
<!-- 通过次数:放在背面左上角 -->
<div class="score-badge-back">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<h1>{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button
@click.stop="speakWord(currentWord.word)"
style="background-color: #ffffff; border-color: #ffffff; color: #000000; margin-top: 20px;"
>
🔊 发音
</el-button>
</div>
</div>
<div class="btn-group">
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<!-- 正面不显示通过次数,如果需要,类似写这里 -->
<h1>{{ currentWord.word }}</h1>
<el-button @click.stop="speakWord(currentWord.word)" style="...">🔊 发音</el-button>
</div>
<div class="card-face card-back" style="position: relative;">
<!-- 通过次数左上角绝对定位 -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<h1 style="margin-top: 40px;">{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button @click.stop="speakWord(currentWord.word)" style="...">🔊 发音</el-button>
</div>
</div>
</div>
给 .card-face.card-back 加了 position: relative;,为 .score-badge 绝对定位提供参考体系。
给正文内容留出顶部空间 margin-top: 40px,避免和通过次数覆盖。
5. 如果你想“通过次数”显示在卡片正面左上角 vue Copy code
<div class="card-face card-front" style="position: relative;">
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<h1>{{ currentWord.word }}</h1>
<el-button ...>🔊 发音</el-button>
</div>
6. 确保 CSS 样式生效 如果你的样式有 scoped,且使用了选择器类似 .score-badge,请确保样式能正确作用,或者调整选择器加上对应父元素写法,比如:
css Copy code
.card-face .score-badge {
position: absolute;
top: 15px;
left: 15px;
/* 其他样式 */
}
7. 完整简化的背面 with 通过次数示例: vue Copy code
<div class="card-face card-back" style="position: relative;">
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}/3
</div>
<h1 style="margin-top: 40px;">{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button @click.stop="speakWord(currentWord.word)" style="background-color: #fff; border-color:#fff; color:#000000; margin-top: 20px;">
🔊 发音
</el-button>
</div>
总结
给显示“通过次数”的卡片面容器(正面或背面)加 position: relative
将 .score-badge 放入卡片面内部,并设置 position: absolute; top/left
给正文内容留足顶部空间防止遮挡
确认 CSS 被正确加载、无缓存
如果需要,我可以帮你整理全套修改好的代码示例,或者你可以告诉我想把“通过次数”放在哪个面,我帮你写精准方案!
<!-- 左侧:学习单词区域 -->
<el-col :span="12" class="left-panel" style="height: 100%;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>短期记忆区域</h2>
<div>
<el-button type="primary" @click="openSelectedDialog">查看已选单词</el-button>
<el-button type="success" @click="openDialog" style="margin-left: 10px;">选择单词</el-button>
</div>
</div>
<!-- 待复习单词数量 -->
<div class="pending-count" v-if="reviewList.length">
待复习单词数量: {{ pendingCount }}
</div>
<!-- 单词卡片 -->
<div class="card-container" v-if="reviewList.length">
<div class="card-wrapper">
<div class="card" :class="{ flipped: isFlipped }">
<div class="card-face card-front">
<!-- 正面不显示通过次数,如果需要,类似写这里 -->
<h1>{{ currentWord.word }}</h1>
<el-button @click.stop="speakWord(currentWord.word)" style="...">🔊 发音</el-button>
</div>
<div class="card-face card-back" style="position: relative;">
<!-- 通过次数左上角绝对定位 -->
<div class="score-badge">
通过次数: {{ currentWord.score ?? 0 }}
</div>
<h1 style="margin-top: 40px;">{{ currentWord.word }}</h1>
<p><strong>释义:</strong>{{ currentWord.definition }}</p>
<el-button @click.stop="speakWord(currentWord.word)" style="...">🔊 发音</el-button>
</div>
</div>
<div class="btn-group">
<el-button type="danger" v-if="!isFlipped" @click="flipCard">忘记</el-button>
<el-button type="success" v-if="!isFlipped" @click="flipCard">认识</el-button>
<el-button type="danger" v-if="isFlipped" @click="submitReviewResult(false)">忘记</el-button>
<el-button type="success" v-if="isFlipped" @click="submitReviewResult(true)">认识</el-button>
</div>
</div>
</div>
<!-- 无可复习单词提示 -->
<div v-else style="text-align:center; margin-top: 50px; font-size: 20px; color: #999;">
无可复习单词,复习完成!
</div>
<!-- 已选单词弹窗 -->
<el-dialog v-model="selectedDialogVisible" title="已选单词列表" width="800px">
<el-table
:data="selectedWords"
style="width: 100%;"
border
@selection-change="handleSelectedChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
<el-table-column label="操作" width="100">
<template #default="scope">
<el-button type="danger" size="small" @click="removeWord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="selectedDialogVisible = false">关闭</el-button>
<el-button type="danger" :disabled="!selectedToDelete.length" @click="batchRemoveWords">
批量删除({{ selectedToDelete.length }})
</el-button>
</span>
</template>
</el-dialog>
</el-col>
<!-- 右侧区域 -->
<el-col :span="12" class="right-panel" style="border: 1px solid #eee; padding: 20px;">
<h2>暂未开发</h2>
<p>暂未开发</p>
</el-col>
<!-- 选择待学习单词弹窗 -->
<el-dialog v-model="dialogVisible" title="选择待学习单词" width="600px">
<el-table :data="pendingWords" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="word" label="单词" />
<el-table-column prop="definition" label="释义" />
</el-table>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitSelectedWords">确认选择({{ selectedToAdd.length }})</el-button>
</span>
</template>
</el-dialog>
为什么每次点击选择待学习单词后,单词卡片还没有出来,点击选择待学习单词里的确认选择,单词卡片还是没有出来,非得点击一次网页刷新才出来
}
package com.example.springboot.mapper;
import com.example.springboot.entity.TodayPlan;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface TodayPlanMapper {
void batchInsertPlans(@Param("userId") Integer userId, @Param("wordIds") List wordIds);
List getTodayPlans(@Param("userId") Integer userId);
List exportPlans(@Param("userId") Integer userId);
code Copy code
List<TodayPlan> selectPlansByIds(@Param("userId") Integer userId, @Param("ids") List<Integer> ids);
void deletePlansByIds(@Param("userId") Integer userId, @Param("ids") List<Integer> ids);
code Copy code
<insert id="batchInsertPlans">
INSERT IGNORE INTO user_word_plan (user_id, word_id)
VALUES
<foreach collection="wordIds" item="wordId" separator=",">
(#{userId}, #{wordId})
</foreach>
</insert>
<select id="getTodayPlans" resultType="com.example.springboot.entity.TodayPlan">
SELECT uwp.*,
w.word AS wordText,
w.definition AS meaning
FROM user_word_plan uwp
JOIN words w ON uwp.word_id = w.id
WHERE uwp.user_id = #{userId}
AND DATE(uwp.added_at) = CURDATE()
ORDER BY uwp.added_at DESC
</select>
<select id="exportPlans" resultType="com.example.springboot.entity.TodayPlan">
SELECT uwp.*,
w.word AS wordText,
w.definition AS meaning
FROM user_word_plan uwp
JOIN words w ON uwp.word_id = w.id
WHERE uwp.user_id = #{userId}
ORDER BY uwp.added_at DESC
</select>
<select id="selectPlansByIds" resultType="com.example.springboot.entity.TodayPlan">
SELECT uwp.*,
w.word AS wordText,
w.definition AS meaning
FROM user_word_plan uwp
JOIN words w ON uwp.word_id = w.id
WHERE uwp.user_id = #{userId}
AND uwp.id IN
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<delete id="deletePlansByIds">
DELETE FROM user_word_plan
WHERE user_id = #{userId}
AND id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
code Copy code
<!-- 操作按钮区域 -->
<div class="card" style="margin-bottom: 10px">
<el-button
type="primary"
:disabled="!selectedIds.size"
@click="addSelectedWordsToPlan"
style="margin-right: 10px"
>
加入背诵计划
</el-button>
</div>
<!-- 表格区域 -->
<div class="card">
<el-table
ref="tableRef"
:data="tableData"
:row-key="row => row.id"
stripe
border
style="width: 100%"
@selection-change="handleSelectionChange"
:row-class-name="getRowClassName"
>
<el-table-column type="selection" width="55" :selectable="isSelectable" />
// 单词列
<el-table-column prop="word" label="单词">
<template #default="{ row }">
<el-tooltip v-if="todayPlanWordIds.has(row.id)" content="已在今日计划中" placement="top">
<span>{{ row.word }}</span>
</el-tooltip>
<span v-else>{{ row.word }}</span>
</template>
</el-table-column>
<el-table-column prop="definition" label="词义" />
<el-table-column prop="customContent" label="例句" />
<el-table-column label="操作" width="100">
<template #default="{ row }">
<el-button size="small" @click="playWord(row.word)">🔊 发音</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<el-pagination
layout="total, sizes, prev, pager, next, jumper"
:total="total"
:page-size="pageSize"
:page-sizes="[10, 20, 30, 50]"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
style="margin-top: 15px; text-align: right"
/>
</div>
<!-- 今日背诵计划弹窗 -->
<el-dialog title="📘 今日背诵计划" v-model="todayPlanDialogVisible" width="60%">
<div style="margin-bottom: 10px; display: flex; justify-content: space-between;">
<div>共 {{ todayPlanTotal }} 个单词</div>
</div>
<el-table
:data="todayPlanWords"
@selection-change="handleTodaySelectionChange"
stripe
border
style="width: 100%"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="wordText" label="单词" />
<el-table-column prop="meaning" label="词义" />
</el-table>
<template #footer>
<el-button @click="todayPlanDialogVisible = false">关闭</el-button>
<el-button
type="success"
:disabled="!selectedTodayWords.length"
@click="exportSelectedTodayWords"
>
导出选中单词
</el-button>
<el-button
type="danger"
:disabled="!selectedTodayWords.length"
@click="deleteSelectedTodayWords"
>
删除选中单词
</el-button>
</template>
</el-dialog>
我不想单词存在long_term_memory了,用户还能选取存在long_term_memory的单词放入user_word_plan里面