130 lines
2.5 KiB
JavaScript
130 lines
2.5 KiB
JavaScript
Page({
|
|
data: {
|
|
records: [],
|
|
filteredRecords: [],
|
|
allTags: [],
|
|
selectedFilterTag: '',
|
|
searchKeyword: ''
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadDreamRecords();
|
|
},
|
|
|
|
onShow() {
|
|
// 每次页面显示时重新加载数据
|
|
this.loadDreamRecords();
|
|
},
|
|
|
|
// 加载梦境记录
|
|
loadDreamRecords() {
|
|
wx.getStorage({
|
|
key: 'dreamRecords',
|
|
success: (res) => {
|
|
const records = res.data || [];
|
|
const allTags = this.extractAllTags(records);
|
|
|
|
this.setData({
|
|
records,
|
|
filteredRecords: records,
|
|
allTags
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
// 提取所有标签
|
|
extractAllTags(records) {
|
|
const tagSet = new Set();
|
|
|
|
records.forEach(record => {
|
|
record.tags.forEach(tag => {
|
|
tagSet.add(tag);
|
|
});
|
|
});
|
|
|
|
return Array.from(tagSet);
|
|
},
|
|
|
|
// 搜索功能
|
|
onSearchChange(e) {
|
|
const keyword = e.detail.value.trim().toLowerCase();
|
|
this.setData({
|
|
searchKeyword: keyword
|
|
});
|
|
this.filterRecords(keyword, this.data.selectedFilterTag);
|
|
},
|
|
|
|
// 选择筛选标签
|
|
selectFilterTag(e) {
|
|
const tag = e.currentTarget.dataset.tag;
|
|
this.setData({
|
|
selectedFilterTag: tag
|
|
});
|
|
this.filterRecords(this.data.searchKeyword, tag);
|
|
},
|
|
|
|
// 筛选记录
|
|
filterRecords(keyword, tag) {
|
|
let filtered = [...this.data.records];
|
|
|
|
// 按标签筛选
|
|
if (tag) {
|
|
filtered = filtered.filter(record =>
|
|
record.tags.includes(tag)
|
|
);
|
|
}
|
|
|
|
// 按关键词搜索
|
|
if (keyword) {
|
|
filtered = filtered.filter(record => {
|
|
const textToSearch = [
|
|
record.title,
|
|
record.scene,
|
|
record.characters,
|
|
record.plot,
|
|
record.details,
|
|
...record.tags
|
|
].join(' ').toLowerCase();
|
|
|
|
return textToSearch.includes(keyword);
|
|
});
|
|
}
|
|
|
|
this.setData({
|
|
filteredRecords: filtered
|
|
});
|
|
},
|
|
|
|
// 获取情绪对应的图标
|
|
getEmotionIcon(emotion) {
|
|
const emotionMap = {
|
|
'happy': 'smile',
|
|
'scared': 'warn',
|
|
'healing': 'like',
|
|
'strange': 'question',
|
|
'sad': 'cry',
|
|
'angry': 'no',
|
|
'nervous': 'waiting',
|
|
'calm': 'sleep'
|
|
};
|
|
|
|
return emotionMap[emotion] || 'info';
|
|
},
|
|
|
|
// 跳转到记录页面
|
|
navigateToRecord() {
|
|
wx.navigateTo({
|
|
url: '/pages/record/record'
|
|
});
|
|
},
|
|
|
|
// 跳转到详情页面
|
|
navigateToDetail(e) {
|
|
const id = e.currentTarget.dataset.id;
|
|
wx.navigateTo({
|
|
url: `/pages/detail/detail?id=${id}`
|
|
});
|
|
}
|
|
});
|