This commit is contained in:
2025-09-24 22:32:15 +08:00
7 changed files with 66 additions and 254 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
});
}
}
});

View File

@@ -174,4 +174,4 @@
</view>
</view>
</scroll-view>
</view>
</view>