2025-04-22 22:04:01 +08:00

112 lines
2.8 KiB
XML

<template>
<div class="wrapper">
<vw-list-des-radio-left
list-array="{{listArray}}"
onwidgetclick="handleWidgetClick"
title="错题本"
onback="handleBack"
onscrollbottom="handleBottom"
></vw-list-des-radio-left>
</div>
</template>
<script>
import router from '@blueos.app.appmanager.router'
import storage from '@blueos.storage.storage';
import prompt from '@blueos.window.prompt';
export default {
data: {
listArray: [] // 初始化为空数组
},
onInit() {
try {
// 同步获取存储数据
const storedData = storage.getSync({ key: 'noLearnList' });
if (typeof storedData!="string") return;
// 解析数据并转换格式
if (storedData) {
const noLearnList = JSON.parse(storedData);
// 过滤无效数据并转换格式
this.listArray = noLearnList
.map(item => ({
id: item.id,
title: item.word,
des: item.translation,
checked: false,
// 保留原始数据用于后续操作
originData: item
}));
}
} catch (e) {
console.error('数据加载失败:', e);
// 可以添加用户提示
prompt.showToast({ message: '加载错题本失败' });
}
},
handleBack() {
router.replace({
uri: 'pages/index'
});
},
handleWidgetClick(data) {
const index = data.index;
if (index >= 0 && index < this.listArray.length) {
const targetId = this.listArray[index].id;
//
const storedData = storage.getSync({ key: 'noLearnList' });
if (!storedData||typeof storedData!="string") return;
const noLearnList = JSON.parse(storedData);
const newList = noLearnList.filter(item => item.id !== targetId);
// 双重保障:更新存储和当前数据
storage.set({ key: 'noLearnList', value: JSON.stringify(newList) });
this.listArray = newList.map(item => ({
id: item.id,
title: item.word,
des: item.translation,
originData: item
}));
}
},
// 处理滚动到底部(示例)
handleBottom() {
// 可以添加加载更多逻辑
},
loadData() {
try {
const storedData = storage.getSync({ key: 'noLearnList' });
if (storedData && typeof storedData == "string") {
const noLearnList = JSON.parse(storedData);
this.listArray = noLearnList.map(item => ({
id: item.id,
title: item.word,
des: item.translation,
originData: item
}));
}
} catch (e) {
console.error('加载失败:', e);
}
},
}
</script>
<style lang="scss">
.wrapper {
background-color: #000000; /* 更友好的背景色 */
height: 100%;
/* 适配列表组件样式 */
vw-list-des-radio-left {
height: 100%;
}
}
</style>