first
This commit is contained in:
107
pages/detail/detail.js
Normal file
107
pages/detail/detail.js
Normal file
@@ -0,0 +1,107 @@
|
||||
Page({
|
||||
data: {
|
||||
dream: {},
|
||||
dreamId: '',
|
||||
emotions: [
|
||||
{ name: '开心', value: 'happy', icon: 'smile' },
|
||||
{ name: '害怕', value: 'scared', icon: 'warn' },
|
||||
{ name: '治愈', value: 'healing', icon: 'like' },
|
||||
{ name: '怪异', value: 'strange', icon: 'question' },
|
||||
{ name: '悲伤', value: 'sad', icon: 'cry' },
|
||||
{ name: '愤怒', value: 'angry', icon: 'no' },
|
||||
{ name: '紧张', value: 'nervous', icon: 'waiting' },
|
||||
{ name: '平静', value: 'calm', icon: 'sleep' }
|
||||
]
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const id = options.id;
|
||||
this.setData({
|
||||
dreamId: id
|
||||
});
|
||||
this.loadDreamDetail(id);
|
||||
},
|
||||
|
||||
// 加载梦境详情
|
||||
loadDreamDetail(id) {
|
||||
wx.getStorage({
|
||||
key: 'dreamRecords',
|
||||
success: (res) => {
|
||||
const records = res.data || [];
|
||||
const dream = records.find(record => record.id === id);
|
||||
|
||||
if (dream) {
|
||||
this.setData({
|
||||
dream
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '未找到记录',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 获取情绪图标
|
||||
getEmotionIcon(emotion) {
|
||||
const emotionObj = this.data.emotions.find(item => item.value === emotion);
|
||||
return emotionObj ? emotionObj.icon : 'info';
|
||||
},
|
||||
|
||||
// 获取情绪名称
|
||||
getEmotionName(emotion) {
|
||||
const emotionObj = this.data.emotions.find(item => item.value === emotion);
|
||||
return emotionObj ? emotionObj.name : '';
|
||||
},
|
||||
|
||||
// 删除记录
|
||||
deleteRecord() {
|
||||
const that = this;
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除这条梦境记录吗?',
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
wx.getStorage({
|
||||
key: 'dreamRecords',
|
||||
success: (res) => {
|
||||
let records = res.data || [];
|
||||
records = records.filter(record => record.id !== that.data.dreamId);
|
||||
|
||||
wx.setStorage({
|
||||
key: 'dreamRecords',
|
||||
data: records,
|
||||
success: () => {
|
||||
wx.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1500);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 编辑记录
|
||||
editRecord() {
|
||||
// 在实际应用中,这里应该跳转到编辑页面
|
||||
// 并传递当前记录的数据
|
||||
wx.showToast({
|
||||
title: '编辑功能开发中',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user