first
This commit is contained in:
129
pages/history/history.js
Normal file
129
pages/history/history.js
Normal file
@@ -0,0 +1,129 @@
|
||||
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}`
|
||||
});
|
||||
}
|
||||
});
|
||||
3
pages/history/history.json
Normal file
3
pages/history/history.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
90
pages/history/history.wxml
Normal file
90
pages/history/history.wxml
Normal file
@@ -0,0 +1,90 @@
|
||||
<view class="container">
|
||||
<view class="header">
|
||||
<text class="title">我的梦境记录</text>
|
||||
<text class="count">{{records.length}} 条记录</text>
|
||||
</view>
|
||||
|
||||
<!-- 搜索框 -->
|
||||
<view class="search-box">
|
||||
<icon type="search" size="16" color="#999" class="search-icon" />
|
||||
<input
|
||||
class="search-input"
|
||||
placeholder="搜索标签或内容..."
|
||||
bindinput="onSearchChange"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 标签筛选 -->
|
||||
<view class="filter-tags" wx:if="{{allTags.length > 0}}">
|
||||
<scroll-view scroll-x="true" class="tags-scroll">
|
||||
<view
|
||||
class="filter-tag {{selectedFilterTag === '' ? 'active' : ''}}"
|
||||
bindtap="selectFilterTag"
|
||||
data-tag=""
|
||||
>
|
||||
全部
|
||||
</view>
|
||||
<view
|
||||
wx:for="{{allTags}}"
|
||||
wx:key="index"
|
||||
class="filter-tag {{selectedFilterTag === item ? 'active' : ''}}"
|
||||
bindtap="selectFilterTag"
|
||||
data-tag="{{item}}"
|
||||
>
|
||||
{{item}}
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 记录列表 -->
|
||||
<view class="records-list">
|
||||
<view wx:if="{{filteredRecords.length === 0}}" class="empty-state">
|
||||
<icon type="sleep" size="60" color="#ccc" />
|
||||
<text class="empty-text">还没有记录呢</text>
|
||||
<text class="empty-desc">快去记录你的第一个梦境吧</text>
|
||||
<button
|
||||
class="add-btn"
|
||||
bindtap="navigateToRecord"
|
||||
>
|
||||
+ 记录新梦境
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<view
|
||||
wx:for="{{filteredRecords}}"
|
||||
wx:key="id"
|
||||
class="record-item"
|
||||
bindtap="navigateToDetail"
|
||||
data-id="{{item.id}}"
|
||||
>
|
||||
<view class="record-header">
|
||||
<text class="record-title">{{item.title}}</text>
|
||||
<text class="record-date">{{item.date}}</text>
|
||||
</view>
|
||||
|
||||
<view class="record-preview">
|
||||
<text class="preview-text">
|
||||
{{item.plot.length > 50 ? item.plot.substring(0, 50) + '...' : item.plot || '点击查看详情'}}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<view class="record-tags">
|
||||
<view
|
||||
wx:for="{{item.tags}}"
|
||||
wx:key="index"
|
||||
class="record-tag"
|
||||
>
|
||||
{{item}}
|
||||
</view>
|
||||
|
||||
<view class="emotion-indicator" wx:if="{{item.emotion}}">
|
||||
<icon
|
||||
type="{{getEmotionIcon(item.emotion)}}"
|
||||
size="16"
|
||||
color="#4a6fa5"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
1
pages/history/history.wxss
Normal file
1
pages/history/history.wxss
Normal file
@@ -0,0 +1 @@
|
||||
/* pages/history/history.wxss */
|
||||
Reference in New Issue
Block a user