mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-07 10:37:33 +08:00
feat: 添加分类提案功能,包括提案表单和相关后端逻辑
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
</div>
|
||||
<LotteryForm v-if="postType === 'LOTTERY'" :data="lottery" />
|
||||
<PollForm v-if="postType === 'POLL'" :data="poll" />
|
||||
<ProposalForm v-if="postType === 'PROPOSAL'" :data="proposal" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -50,6 +51,7 @@ import PostTypeSelect from '~/components/PostTypeSelect.vue'
|
||||
import TagSelect from '~/components/TagSelect.vue'
|
||||
import LotteryForm from '~/components/LotteryForm.vue'
|
||||
import PollForm from '~/components/PollForm.vue'
|
||||
import ProposalForm from '~/components/ProposalForm.vue'
|
||||
import { toast } from '~/main'
|
||||
import { authState, getToken } from '~/utils/auth'
|
||||
const config = useRuntimeConfig()
|
||||
@@ -76,6 +78,15 @@ const poll = reactive({
|
||||
endTime: null,
|
||||
multiple: false,
|
||||
})
|
||||
const proposal = reactive({
|
||||
proposedName: '',
|
||||
proposedSlug: '',
|
||||
proposalDescription: '',
|
||||
approveThreshold: 60,
|
||||
quorum: 10,
|
||||
endTime: null,
|
||||
options: ['同意', '反对'],
|
||||
})
|
||||
const startTime = ref(null)
|
||||
const isWaitingPosting = ref(false)
|
||||
const isAiLoading = ref(false)
|
||||
@@ -123,6 +134,13 @@ const clearPost = async () => {
|
||||
poll.options = ['', '']
|
||||
poll.endTime = null
|
||||
poll.multiple = false
|
||||
proposal.proposedName = ''
|
||||
proposal.proposedSlug = ''
|
||||
proposal.proposalDescription = ''
|
||||
proposal.approveThreshold = 60
|
||||
proposal.quorum = 10
|
||||
proposal.endTime = null
|
||||
proposal.options = ['同意', '反对']
|
||||
|
||||
// 删除草稿
|
||||
const token = getToken()
|
||||
@@ -283,6 +301,32 @@ const submitPost = async () => {
|
||||
return
|
||||
}
|
||||
}
|
||||
if (postType.value === 'PROPOSAL') {
|
||||
if (!proposal.proposedName.trim()) {
|
||||
toast.error('请填写拟议分类名称')
|
||||
return
|
||||
}
|
||||
if (!proposal.proposedSlug.trim()) {
|
||||
toast.error('请填写拟议分类 Slug')
|
||||
return
|
||||
}
|
||||
if (proposal.approveThreshold < 0 || proposal.approveThreshold > 100) {
|
||||
toast.error('通过阈值需在0到100之间')
|
||||
return
|
||||
}
|
||||
if (proposal.quorum < 0) {
|
||||
toast.error('最小参与数需大于或等于0')
|
||||
return
|
||||
}
|
||||
if (proposal.options.length < 2 || proposal.options.some((o) => !o.trim())) {
|
||||
toast.error('请填写至少两个投票选项')
|
||||
return
|
||||
}
|
||||
if (!proposal.endTime) {
|
||||
toast.error('请选择投票结束时间')
|
||||
return
|
||||
}
|
||||
}
|
||||
try {
|
||||
const token = getToken()
|
||||
await ensureTags(token)
|
||||
@@ -321,6 +365,18 @@ const submitPost = async () => {
|
||||
prizeDescription: postType.value === 'LOTTERY' ? lottery.prizeDescription : undefined,
|
||||
options: postType.value === 'POLL' ? poll.options : undefined,
|
||||
multiple: postType.value === 'POLL' ? poll.multiple : undefined,
|
||||
proposedName: postType.value === 'PROPOSAL' ? proposal.proposedName : undefined,
|
||||
proposedSlug: postType.value === 'PROPOSAL' ? proposal.proposedSlug : undefined,
|
||||
proposalDescription:
|
||||
postType.value === 'PROPOSAL' ? proposal.proposalDescription : undefined,
|
||||
approveThreshold: postType.value === 'PROPOSAL' ? proposal.approveThreshold : undefined,
|
||||
quorum: postType.value === 'PROPOSAL' ? proposal.quorum : undefined,
|
||||
options:
|
||||
postType.value === 'POLL'
|
||||
? poll.options
|
||||
: postType.value === 'PROPOSAL'
|
||||
? proposal.options
|
||||
: undefined,
|
||||
startTime:
|
||||
postType.value === 'LOTTERY' ? new Date(startTime.value).toISOString() : undefined,
|
||||
pointCost: postType.value === 'LOTTERY' ? lottery.pointCost : undefined,
|
||||
@@ -330,7 +386,11 @@ const submitPost = async () => {
|
||||
? new Date(new Date(lottery.endTime).getTime() + 8.02 * 60 * 60 * 1000).toISOString()
|
||||
: postType.value === 'POLL'
|
||||
? new Date(new Date(poll.endTime).getTime() + 8.02 * 60 * 60 * 1000).toISOString()
|
||||
: undefined,
|
||||
: postType.value === 'PROPOSAL'
|
||||
? new Date(
|
||||
new Date(proposal.endTime).getTime() + 8.02 * 60 * 60 * 1000,
|
||||
).toISOString()
|
||||
: undefined,
|
||||
}),
|
||||
})
|
||||
const data = await res.json()
|
||||
|
||||
Reference in New Issue
Block a user