mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-08 11:47:28 +08:00
Merge pull request #473 from nagisa77/f9h526-codex/add-post-creation-enhancements
feat: add lottery post fields
This commit is contained in:
27
frontend_nuxt/components/PostTypeSelect.vue
Normal file
27
frontend_nuxt/components/PostTypeSelect.vue
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<template>
|
||||||
|
<Dropdown v-model="selected" :fetch-options="fetchOptions" placeholder="帖子类型" :initial-options="options" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import Dropdown from '~/components/Dropdown.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'PostTypeSelect',
|
||||||
|
components: { Dropdown },
|
||||||
|
props: { modelValue: { type: String, default: 'NORMAL' } },
|
||||||
|
emits: ['update:modelValue'],
|
||||||
|
setup(props, { emit }) {
|
||||||
|
const options = [
|
||||||
|
{ id: 'NORMAL', name: '普通帖' },
|
||||||
|
{ id: 'LOTTERY', name: '抽奖贴' }
|
||||||
|
]
|
||||||
|
const fetchOptions = async () => options
|
||||||
|
const selected = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: v => emit('update:modelValue', v)
|
||||||
|
})
|
||||||
|
return { selected, fetchOptions, options }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="post-options">
|
<div class="post-options">
|
||||||
<div class="post-options-left">
|
<div class="post-options-left">
|
||||||
|
<PostTypeSelect v-model="postType" />
|
||||||
<CategorySelect v-model="selectedCategory" />
|
<CategorySelect v-model="selectedCategory" />
|
||||||
<TagSelect v-model="selectedTags" creatable />
|
<TagSelect v-model="selectedTags" creatable />
|
||||||
</div>
|
</div>
|
||||||
@@ -32,6 +33,25 @@
|
|||||||
<div v-else class="post-submit-loading"> <i class="fa-solid fa-spinner fa-spin"></i> 发布中...</div>
|
<div v-else class="post-submit-loading"> <i class="fa-solid fa-spinner fa-spin"></i> 发布中...</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="postType === 'LOTTERY'" class="lottery-options">
|
||||||
|
<div class="lottery-field">
|
||||||
|
<label>奖品图片</label>
|
||||||
|
<input type="file" accept="image/*" @change="uploadPrizeIcon" />
|
||||||
|
<img v-if="prizeIcon" :src="prizeIcon" class="prize-preview" />
|
||||||
|
</div>
|
||||||
|
<div class="lottery-field">
|
||||||
|
<label>奖品数量</label>
|
||||||
|
<div class="prize-count-input">
|
||||||
|
<button type="button" @click="decreasePrizeCount">-</button>
|
||||||
|
<input type="number" v-model.number="prizeCount" min="1" />
|
||||||
|
<button type="button" @click="increasePrizeCount">+</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="lottery-field">
|
||||||
|
<label>抽奖结束时间</label>
|
||||||
|
<input type="datetime-local" v-model="endTime" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -40,6 +60,7 @@
|
|||||||
import { ref, onMounted, computed } from 'vue'
|
import { ref, onMounted, computed } from 'vue'
|
||||||
import PostEditor from '../components/PostEditor.vue'
|
import PostEditor from '../components/PostEditor.vue'
|
||||||
import CategorySelect from '../components/CategorySelect.vue'
|
import CategorySelect from '../components/CategorySelect.vue'
|
||||||
|
import PostTypeSelect from '../components/PostTypeSelect.vue'
|
||||||
import TagSelect from '../components/TagSelect.vue'
|
import TagSelect from '../components/TagSelect.vue'
|
||||||
import { API_BASE_URL, toast } from '../main'
|
import { API_BASE_URL, toast } from '../main'
|
||||||
import { getToken, authState } from '../utils/auth'
|
import { getToken, authState } from '../utils/auth'
|
||||||
@@ -47,12 +68,16 @@ import LoginOverlay from '../components/LoginOverlay.vue'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'NewPostPageView',
|
name: 'NewPostPageView',
|
||||||
components: { PostEditor, CategorySelect, TagSelect, LoginOverlay },
|
components: { PostEditor, CategorySelect, PostTypeSelect, TagSelect, LoginOverlay },
|
||||||
setup() {
|
setup() {
|
||||||
const title = ref('')
|
const title = ref('')
|
||||||
const content = ref('')
|
const content = ref('')
|
||||||
const selectedCategory = ref('')
|
const selectedCategory = ref('')
|
||||||
const selectedTags = ref([])
|
const selectedTags = ref([])
|
||||||
|
const postType = ref('NORMAL')
|
||||||
|
const prizeIcon = ref('')
|
||||||
|
const prizeCount = ref(1)
|
||||||
|
const endTime = ref('')
|
||||||
const isWaitingPosting = ref(false)
|
const isWaitingPosting = ref(false)
|
||||||
const isAiLoading = ref(false)
|
const isAiLoading = ref(false)
|
||||||
const isLogin = computed(() => authState.loggedIn)
|
const isLogin = computed(() => authState.loggedIn)
|
||||||
@@ -85,6 +110,10 @@ export default {
|
|||||||
content.value = ''
|
content.value = ''
|
||||||
selectedCategory.value = ''
|
selectedCategory.value = ''
|
||||||
selectedTags.value = []
|
selectedTags.value = []
|
||||||
|
postType.value = 'NORMAL'
|
||||||
|
prizeIcon.value = ''
|
||||||
|
prizeCount.value = 1
|
||||||
|
endTime.value = ''
|
||||||
|
|
||||||
// 删除草稿
|
// 删除草稿
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
@@ -164,6 +193,39 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uploadPrizeIcon = async (e) => {
|
||||||
|
const file = e.target.files[0]
|
||||||
|
if (!file) return
|
||||||
|
try {
|
||||||
|
const token = getToken()
|
||||||
|
const res = await fetch(`${API_BASE_URL}/api/upload/presign?filename=${encodeURIComponent(file.name)}`, {
|
||||||
|
headers: { Authorization: `Bearer ${token}` }
|
||||||
|
})
|
||||||
|
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 (err) {
|
||||||
|
toast.error('上传失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const increasePrizeCount = () => {
|
||||||
|
prizeCount.value++
|
||||||
|
}
|
||||||
|
|
||||||
|
const decreasePrizeCount = () => {
|
||||||
|
if (prizeCount.value > 1) prizeCount.value--
|
||||||
|
}
|
||||||
|
|
||||||
const aiGenerate = async () => {
|
const aiGenerate = async () => {
|
||||||
if (!content.value.trim()) {
|
if (!content.value.trim()) {
|
||||||
toast.error('内容为空,无法优化')
|
toast.error('内容为空,无法优化')
|
||||||
@@ -213,6 +275,20 @@ export default {
|
|||||||
toast.error('请选择标签')
|
toast.error('请选择标签')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (postType.value === 'LOTTERY') {
|
||||||
|
if (!prizeIcon.value) {
|
||||||
|
toast.error('请上传奖品图片')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!prizeCount.value || prizeCount.value <= 0) {
|
||||||
|
toast.error('奖品数量必须大于0')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!endTime.value) {
|
||||||
|
toast.error('请选择抽奖结束时间')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
await ensureTags(token)
|
await ensureTags(token)
|
||||||
@@ -227,7 +303,13 @@ export default {
|
|||||||
title: title.value,
|
title: title.value,
|
||||||
content: content.value,
|
content: content.value,
|
||||||
categoryId: selectedCategory.value,
|
categoryId: selectedCategory.value,
|
||||||
tagIds: selectedTags.value
|
tagIds: selectedTags.value,
|
||||||
|
type: postType.value,
|
||||||
|
prizeIcon: postType.value === 'LOTTERY' ? prizeIcon.value : null,
|
||||||
|
prizeCount: postType.value === 'LOTTERY' ? prizeCount.value : null,
|
||||||
|
startTime: postType.value === 'LOTTERY' ? new Date().toISOString() : null,
|
||||||
|
endTime: postType.value === 'LOTTERY' ? new Date(endTime.value).toISOString() : null,
|
||||||
|
prizeDescription: postType.value === 'LOTTERY' ? '' : null
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
@@ -251,7 +333,26 @@ export default {
|
|||||||
isWaitingPosting.value = false
|
isWaitingPosting.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { title, content, selectedCategory, selectedTags, submitPost, saveDraft, clearPost, isWaitingPosting, aiGenerate, isAiLoading, isLogin }
|
return {
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
selectedCategory,
|
||||||
|
selectedTags,
|
||||||
|
postType,
|
||||||
|
prizeIcon,
|
||||||
|
prizeCount,
|
||||||
|
endTime,
|
||||||
|
submitPost,
|
||||||
|
saveDraft,
|
||||||
|
clearPost,
|
||||||
|
isWaitingPosting,
|
||||||
|
aiGenerate,
|
||||||
|
isAiLoading,
|
||||||
|
isLogin,
|
||||||
|
uploadPrizeIcon,
|
||||||
|
increasePrizeCount,
|
||||||
|
decreasePrizeCount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -366,6 +467,40 @@ export default {
|
|||||||
padding-bottom: 50px;
|
padding-bottom: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lottery-options {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lottery-field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.prize-preview {
|
||||||
|
max-width: 200px;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.prize-count-input {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.prize-count-input input {
|
||||||
|
width: 60px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.prize-count-input button {
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.new-post-page {
|
.new-post-page {
|
||||||
width: calc(100vw - 20px);
|
width: calc(100vw - 20px);
|
||||||
|
|||||||
Reference in New Issue
Block a user