mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-11 21:27:31 +08:00
Revert "feat: add lottery post fields"
This commit is contained in:
@@ -1,27 +0,0 @@
|
|||||||
<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,7 +8,6 @@
|
|||||||
</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>
|
||||||
@@ -33,25 +32,6 @@
|
|||||||
<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>
|
||||||
@@ -60,7 +40,6 @@
|
|||||||
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'
|
||||||
@@ -68,16 +47,12 @@ import LoginOverlay from '../components/LoginOverlay.vue'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'NewPostPageView',
|
name: 'NewPostPageView',
|
||||||
components: { PostEditor, CategorySelect, PostTypeSelect, TagSelect, LoginOverlay },
|
components: { PostEditor, CategorySelect, 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)
|
||||||
@@ -110,10 +85,6 @@ 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()
|
||||||
@@ -193,39 +164,6 @@ 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('内容为空,无法优化')
|
||||||
@@ -275,20 +213,6 @@ 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)
|
||||||
@@ -303,13 +227,7 @@ 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()
|
||||||
@@ -333,26 +251,7 @@ export default {
|
|||||||
isWaitingPosting.value = false
|
isWaitingPosting.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return { title, content, selectedCategory, selectedTags, submitPost, saveDraft, clearPost, isWaitingPosting, aiGenerate, isAiLoading, isLogin }
|
||||||
title,
|
|
||||||
content,
|
|
||||||
selectedCategory,
|
|
||||||
selectedTags,
|
|
||||||
postType,
|
|
||||||
prizeIcon,
|
|
||||||
prizeCount,
|
|
||||||
endTime,
|
|
||||||
submitPost,
|
|
||||||
saveDraft,
|
|
||||||
clearPost,
|
|
||||||
isWaitingPosting,
|
|
||||||
aiGenerate,
|
|
||||||
isAiLoading,
|
|
||||||
isLogin,
|
|
||||||
uploadPrizeIcon,
|
|
||||||
increasePrizeCount,
|
|
||||||
decreasePrizeCount
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -467,40 +366,6 @@ 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