Merge pull request #143 from nagisa77/i3fpxu-codex

Add none option for category and tag selectors
This commit is contained in:
Tim
2025-07-09 20:28:33 +08:00
committed by GitHub
2 changed files with 13 additions and 5 deletions

View File

@@ -18,7 +18,8 @@ export default {
const fetchCategories = async () => {
const res = await fetch(`${API_BASE_URL}/api/categories`)
if (!res.ok) return []
return await res.json()
const data = await res.json()
return [{ id: '', name: '无分类' }, ...data]
}
const selected = computed({

View File

@@ -18,15 +18,22 @@ export default {
const fetchTags = async () => {
const res = await fetch(`${API_BASE_URL}/api/tags`)
if (!res.ok) return []
return await res.json()
const data = await res.json()
return [{ id: 0, name: '无标签' }, ...data]
}
const selected = computed({
get: () => props.modelValue,
set: v => {
if (Array.isArray(v) && v.length > 2) {
toast.error('最多选择两个标签')
return
if (Array.isArray(v)) {
if (v.includes(0)) {
emit('update:modelValue', [])
return
}
if (v.length > 2) {
toast.error('最多选择两个标签')
return
}
}
emit('update:modelValue', v)
}