From 7616a2d0e0776a95c2049991e1866f332fea28e0 Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Mon, 11 Aug 2025 01:29:22 +0800 Subject: [PATCH] feat: add lottery post options --- frontend_nuxt/pages/new-post.vue | 136 ++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-) diff --git a/frontend_nuxt/pages/new-post.vue b/frontend_nuxt/pages/new-post.vue index 93f9b4211..ca79c55bf 100644 --- a/frontend_nuxt/pages/new-post.vue +++ b/frontend_nuxt/pages/new-post.vue @@ -10,6 +10,10 @@
+
@@ -32,6 +36,21 @@
发布中...
+ +
+
+ + +
+
+ + + +
+
+ +
+
@@ -56,6 +75,10 @@ export default { const isWaitingPosting = ref(false) const isAiLoading = ref(false) const isLogin = computed(() => authState.loggedIn) + const postType = ref('NORMAL') + const prizeIcon = ref('') + const prizeCount = ref(1) + const lotteryEndTime = ref('') const loadDraft = async () => { const token = getToken() @@ -85,6 +108,10 @@ export default { content.value = '' selectedCategory.value = '' selectedTags.value = [] + postType.value = 'NORMAL' + prizeIcon.value = '' + prizeCount.value = 1 + lotteryEndTime.value = '' // 删除草稿 const token = getToken() @@ -213,6 +240,20 @@ export default { toast.error('请选择标签') return } + if (postType.value === 'LOTTERY') { + if (!prizeIcon.value) { + toast.error('请上传奖品图片') + return + } + if (!prizeCount.value || prizeCount.value <= 0) { + toast.error('奖品数量必须大于0') + return + } + if (!lotteryEndTime.value) { + toast.error('请选择抽奖结束时间') + return + } + } try { const token = getToken() await ensureTags(token) @@ -227,7 +268,14 @@ export default { title: title.value, content: content.value, categoryId: selectedCategory.value, - tagIds: selectedTags.value + tagIds: selectedTags.value, + type: postType.value, + prizeIcon: postType.value === 'LOTTERY' ? prizeIcon.value : undefined, + prizeCount: postType.value === 'LOTTERY' ? prizeCount.value : undefined, + endTime: + postType.value === 'LOTTERY' && lotteryEndTime.value + ? new Date(lotteryEndTime.value).toISOString() + : undefined }) }) const data = await res.json() @@ -251,7 +299,55 @@ export default { isWaitingPosting.value = false } } - return { title, content, selectedCategory, selectedTags, submitPost, saveDraft, clearPost, isWaitingPosting, aiGenerate, isAiLoading, isLogin } + const incPrizeCount = () => { + prizeCount.value += 1 + } + const decPrizeCount = () => { + if (prizeCount.value > 1) prizeCount.value -= 1 + } + const handlePrizeImage = async (e) => { + const file = e.target.files[0] + if (!file) return + try { + const res = await fetch(`${API_BASE_URL}/api/upload/presign?filename=${encodeURIComponent(file.name)}`, { + headers: { Authorization: `Bearer ${getToken()}` } + }) + if (!res.ok) { + toast.error('获取上传地址失败') + return + } + const info = await res.json() + const put = await fetch(info.uploadUrl, { method: 'PUT', body: file }) + if (!put.ok) { + toast.error('上传失败') + return + } + prizeIcon.value = info.fileUrl + toast.success('上传成功') + } catch (e) { + toast.error('上传失败') + } + } + return { + title, + content, + selectedCategory, + selectedTags, + submitPost, + saveDraft, + clearPost, + isWaitingPosting, + aiGenerate, + isAiLoading, + isLogin, + postType, + prizeIcon, + prizeCount, + lotteryEndTime, + incPrizeCount, + decPrizeCount, + handlePrizeImage + } } } @@ -366,6 +462,42 @@ export default { padding-bottom: 50px; } +.post-type-select { + padding: 5px; + border-radius: 5px; +} + +.lottery-options { + margin-top: 20px; + display: flex; + flex-direction: column; + gap: 10px; +} + +.prize-image input { + display: block; +} + +.prize-preview { + margin-top: 10px; + max-width: 200px; +} + +.prize-count { + display: flex; + align-items: center; + gap: 5px; +} + +.prize-count button { + padding: 5px 10px; +} + +.lottery-end-time input { + padding: 5px; + border-radius: 5px; +} + @media (max-width: 768px) { .new-post-page { width: calc(100vw - 20px);