173 lines
4.0 KiB
JavaScript
173 lines
4.0 KiB
JavaScript
Page({
|
|
data: {
|
|
// 梦境内容
|
|
title: '',
|
|
scene: '',
|
|
characters: '',
|
|
plot: '',
|
|
details: '',
|
|
|
|
// 标签数据
|
|
dreamTags: [
|
|
'飞行', '追逐', '考试', '重逢', '坠落',
|
|
'迷路', '被追逐', '飞翔', '裸奔', '牙齿脱落',
|
|
'死亡', '结婚', '学校', '怪物', '亲人',
|
|
'朋友', '陌生人', '水', '火', '天空',
|
|
'未来', '过去', '重复的梦', '清明梦', '噩梦'
|
|
],
|
|
selectedTags: [],
|
|
|
|
// 情绪数据
|
|
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' }
|
|
],
|
|
selectedEmotion: ''
|
|
},
|
|
|
|
// 标题输入
|
|
onTitleChange(e) {
|
|
this.setData({
|
|
title: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 场景输入
|
|
onSceneChange(e) {
|
|
this.setData({
|
|
scene: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 人物输入
|
|
onCharactersChange(e) {
|
|
this.setData({
|
|
characters: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 情节输入
|
|
onPlotChange(e) {
|
|
this.setData({
|
|
plot: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 细节输入
|
|
onDetailsChange(e) {
|
|
this.setData({
|
|
details: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 切换标签选择状态
|
|
toggleTag(e) {
|
|
const tag = e.currentTarget.dataset.tag;
|
|
const { selectedTags } = this.data;
|
|
|
|
let newSelectedTags;
|
|
if (selectedTags.includes(tag)) {
|
|
// 移除标签
|
|
newSelectedTags = selectedTags.filter(t => t !== tag);
|
|
} else {
|
|
// 添加标签
|
|
newSelectedTags = [...selectedTags, tag];
|
|
}
|
|
|
|
this.setData({
|
|
selectedTags: newSelectedTags
|
|
});
|
|
},
|
|
|
|
// 选择情绪
|
|
selectEmotion(e) {
|
|
const emotion = e.currentTarget.dataset.emotion;
|
|
this.setData({
|
|
selectedEmotion: emotion
|
|
});
|
|
},
|
|
|
|
// 保存梦境记录
|
|
saveDreamRecord() {
|
|
// 简单验证
|
|
if (!this.data.title && !this.data.scene && !this.data.plot) {
|
|
wx.showToast({
|
|
title: '请至少填写一些内容',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
return;
|
|
}
|
|
|
|
// 创建记录对象
|
|
const dreamRecord = {
|
|
id: Date.now().toString(), // 使用时间戳作为唯一ID
|
|
title: this.data.title || '无标题梦境',
|
|
scene: this.data.scene,
|
|
characters: this.data.characters,
|
|
plot: this.data.plot,
|
|
details: this.data.details,
|
|
tags: this.data.selectedTags,
|
|
emotion: this.data.selectedEmotion,
|
|
date: new Date().toLocaleDateString(),
|
|
timestamp: Date.now()
|
|
};
|
|
|
|
// 从本地存储获取已有记录
|
|
wx.getStorage({
|
|
key: 'dreamRecords',
|
|
success: (res) => {
|
|
const records = res.data || [];
|
|
records.unshift(dreamRecord); // 添加到数组开头
|
|
|
|
// 保存回本地存储
|
|
wx.setStorage({
|
|
key: 'dreamRecords',
|
|
data: records,
|
|
success: () => {
|
|
wx.showToast({
|
|
title: '记录保存成功',
|
|
icon: 'success',
|
|
duration: 2000
|
|
});
|
|
|
|
// 返回首页
|
|
setTimeout(() => {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
});
|
|
}, 1500);
|
|
}
|
|
});
|
|
},
|
|
fail: () => {
|
|
// 如果没有已有记录,创建新数组
|
|
wx.setStorage({
|
|
key: 'dreamRecords',
|
|
data: [dreamRecord],
|
|
success: () => {
|
|
wx.showToast({
|
|
title: '记录保存成功',
|
|
icon: 'success',
|
|
duration: 2000
|
|
});
|
|
|
|
// 返回首页
|
|
setTimeout(() => {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
});
|
|
}, 1500);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|