Compare commits

...

4 Commits

Author SHA1 Message Date
Tim
5814fb673a feat: add join button for single polls 2025-09-01 01:06:51 +08:00
Tim
4ee4266e3d Merge pull request #804 from nagisa77/codex/fix-jpasystemexception-for-pollpost
Fix poll multiple property null handling
2025-08-31 14:22:59 +08:00
Tim
6a27fbe1d7 Fix null multiple field for poll posts 2025-08-31 14:22:44 +08:00
Tim
38ff04c358 Merge pull request #803 from nagisa77/codex/add-baseswitch-component-to-voting-post
feat(poll): use BaseSwitch for multiple selection
2025-08-31 14:13:32 +08:00
3 changed files with 35 additions and 6 deletions

View File

@@ -111,7 +111,7 @@ public class PostMapper {
.collect(Collectors.groupingBy(PollVote::getOptionIndex,
Collectors.mapping(v -> userMapper.toAuthorDto(v.getUser()), Collectors.toList())));
p.setOptionParticipants(optionParticipants);
p.setMultiple(pp.isMultiple());
p.setMultiple(Boolean.TRUE.equals(pp.getMultiple()));
dto.setPoll(p);
}
}

View File

@@ -33,7 +33,7 @@ public class PollPost extends Post {
private Set<User> participants = new HashSet<>();
@Column
private boolean multiple = false;
private Boolean multiple = false;
@Column
private LocalDateTime endTime;

View File

@@ -59,11 +59,26 @@
v-for="(opt, idx) in poll.options"
:key="idx"
class="poll-option"
@click="voteOption(idx)"
@click="selectOption(idx)"
>
<input type="radio" :checked="false" name="poll-option" class="poll-option-input" />
<input
type="radio"
:checked="selectedOption === idx"
name="poll-option"
class="poll-option-input"
/>
<span class="poll-option-text">{{ opt }}</span>
</div>
<div class="single-selection-container">
<div class="single-selection-title">
<i class="fas fa-info-circle info-icon"></i>
该投票为单选
</div>
<div class="join-poll-button" @click="submitSinglePoll">
<i class="fas fa-plus"></i> 加入投票
</div>
</div>
</template>
</div>
</div>
@@ -198,6 +213,18 @@ const voteOption = async (idx) => {
}
}
const selectedOption = ref(null)
const selectOption = (idx) => {
selectedOption.value = idx
}
const submitSinglePoll = async () => {
if (selectedOption.value === null) {
toast.error('请选择一个选项')
return
}
await voteOption(selectedOption.value)
}
const selectedOptions = ref([])
const toggleOption = (idx) => {
const i = selectedOptions.value.indexOf(idx)
@@ -368,14 +395,16 @@ const submitMultiPoll = async () => {
color: var(--text-color);
}
.multi-selection-container {
.multi-selection-container,
.single-selection-container {
padding: 20px 15px 20px 5px;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.multi-selection-title {
.multi-selection-title,
.single-selection-title {
font-size: 13px;
color: var(--text-color);
}