2025-9-24-21:10

This commit is contained in:
JACKYMYPERSON
2025-09-24 21:10:29 +08:00
parent 19085f6875
commit 940fb884c6
5 changed files with 226 additions and 219 deletions

View File

@@ -1,8 +1,55 @@
Component({
data: {
},
methods: {
},
})
data: {
// 用对象存储多个卡片的选中状态键为卡片ID值为选中的选项ID
selectedOptions: {} as Record<string, string>
},
methods: {
/**
* 选择选项
* @param e 事件对象包含卡片ID和选项ID
*/
selectOption(e: WechatMiniprogram.TouchEvent) {
const { card, id } = e.currentTarget.dataset as { card: string; id: string };
// 更新选中状态(使用对象展开语法保持响应式)
this.setData({
selectedOptions: {
...this.data.selectedOptions,
[card]: id
}
});
},
/**
* 提交投票
* @param e 事件对象包含卡片ID
*/
submitVote(e: WechatMiniprogram.TouchEvent) {
const { card } = e.currentTarget.dataset as { card: string };
const selected = this.data.selectedOptions[card];
if (!selected) {
wx.showToast({
title: '请先选择一个选项',
icon: 'none',
duration: 2000
});
return;
}
// 可以通过triggerEvent向父组件传递投票结果
this.triggerEvent('voteSuccess', {
cardId: card,
selectedOption: selected,
timestamp: Date.now()
});
wx.showToast({
title: '投票成功',
icon: 'success',
duration: 2000
});
}
}
});