mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-08-16 16:21:00 +00:00
feat: add paginated tag loading
This commit is contained in:
@@ -80,18 +80,15 @@ public class TagController {
|
|||||||
@ApiResponse(responseCode = "200", description = "List of tags",
|
@ApiResponse(responseCode = "200", description = "List of tags",
|
||||||
content = @Content(array = @ArraySchema(schema = @Schema(implementation = TagDto.class))))
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = TagDto.class))))
|
||||||
public List<TagDto> list(@RequestParam(value = "keyword", required = false) String keyword,
|
public List<TagDto> list(@RequestParam(value = "keyword", required = false) String keyword,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "page", required = false) Integer page,
|
||||||
List<Tag> tags = tagService.searchTags(keyword);
|
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||||
|
List<Tag> tags = tagService.searchTags(keyword, page, pageSize);
|
||||||
List<Long> tagIds = tags.stream().map(Tag::getId).toList();
|
List<Long> tagIds = tags.stream().map(Tag::getId).toList();
|
||||||
Map<Long, Long> postCntByTagIds = postService.countPostsByTagIds(tagIds);
|
Map<Long, Long> postCntByTagIds = postService.countPostsByTagIds(tagIds);
|
||||||
List<TagDto> dtos = tags.stream()
|
return tags.stream()
|
||||||
.map(t -> tagMapper.toDto(t, postCntByTagIds.getOrDefault(t.getId(), 0L)))
|
.map(t -> tagMapper.toDto(t, postCntByTagIds.getOrDefault(t.getId(), 0L)))
|
||||||
.sorted((a, b) -> Long.compare(b.getCount(), a.getCount()))
|
.sorted((a, b) -> Long.compare(b.getCount(), a.getCount()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (limit != null && limit > 0 && dtos.size() > limit) {
|
|
||||||
return dtos.subList(0, limit);
|
|
||||||
}
|
|
||||||
return dtos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.openisle.model.Tag;
|
|||||||
import com.openisle.model.User;
|
import com.openisle.model.User;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -13,6 +14,8 @@ public interface TagRepository extends JpaRepository<Tag, Long> {
|
|||||||
List<Tag> findByApproved(boolean approved);
|
List<Tag> findByApproved(boolean approved);
|
||||||
List<Tag> findByApprovedTrue();
|
List<Tag> findByApprovedTrue();
|
||||||
List<Tag> findByNameContainingIgnoreCaseAndApprovedTrue(String keyword);
|
List<Tag> findByNameContainingIgnoreCaseAndApprovedTrue(String keyword);
|
||||||
|
Page<Tag> findByApprovedTrue(Pageable pageable);
|
||||||
|
Page<Tag> findByNameContainingIgnoreCaseAndApprovedTrue(String keyword, Pageable pageable);
|
||||||
|
|
||||||
List<Tag> findByCreatorOrderByCreatedAtDesc(User creator, Pageable pageable);
|
List<Tag> findByCreatorOrderByCreatedAtDesc(User creator, Pageable pageable);
|
||||||
List<Tag> findByCreator(User creator);
|
List<Tag> findByCreator(User creator);
|
||||||
|
|||||||
@@ -108,6 +108,17 @@ public class TagService {
|
|||||||
return tagRepository.findByNameContainingIgnoreCaseAndApprovedTrue(keyword);
|
return tagRepository.findByNameContainingIgnoreCaseAndApprovedTrue(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tag> searchTags(String keyword, Integer page, Integer pageSize) {
|
||||||
|
if (page == null || pageSize == null) {
|
||||||
|
return searchTags(keyword);
|
||||||
|
}
|
||||||
|
Pageable pageable = PageRequest.of(page, pageSize);
|
||||||
|
if (keyword == null || keyword.isBlank()) {
|
||||||
|
return tagRepository.findByApprovedTrue(pageable).getContent();
|
||||||
|
}
|
||||||
|
return tagRepository.findByNameContainingIgnoreCaseAndApprovedTrue(keyword, pageable).getContent();
|
||||||
|
}
|
||||||
|
|
||||||
public List<Tag> getRecentTagsByUser(String username, int limit) {
|
public List<Tag> getRecentTagsByUser(String username, int limit) {
|
||||||
User user = userRepository.findByUsername(username)
|
User user = userRepository.findByUsername(username)
|
||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
|
|||||||
@@ -75,9 +75,9 @@ class TagControllerTest {
|
|||||||
t.setDescription("d2");
|
t.setDescription("d2");
|
||||||
t.setIcon("i2");
|
t.setIcon("i2");
|
||||||
t.setSmallIcon("s2");
|
t.setSmallIcon("s2");
|
||||||
Mockito.when(tagService.searchTags(null)).thenReturn(List.of(t));
|
Mockito.when(tagService.searchTags(null, 0, 10)).thenReturn(List.of(t));
|
||||||
|
|
||||||
mockMvc.perform(get("/api/tags"))
|
mockMvc.perform(get("/api/tags?page=0&pageSize=10"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$[0].name").value("spring"))
|
.andExpect(jsonPath("$[0].name").value("spring"))
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
v-if="open && !isMobile && (loading || filteredOptions.length > 0 || showSearch)"
|
v-if="open && !isMobile && (loading || filteredOptions.length > 0 || showSearch)"
|
||||||
:class="['dropdown-menu', menuClass]"
|
:class="['dropdown-menu', menuClass]"
|
||||||
v-click-outside="close"
|
v-click-outside="close"
|
||||||
|
ref="menuRef"
|
||||||
>
|
>
|
||||||
<div v-if="showSearch" class="dropdown-search">
|
<div v-if="showSearch" class="dropdown-search">
|
||||||
<search-icon class="search-icon" />
|
<search-icon class="search-icon" />
|
||||||
@@ -80,6 +81,13 @@
|
|||||||
<span>{{ o.name }}</span>
|
<span>{{ o.name }}</span>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
|
<InfiniteLoadMore
|
||||||
|
v-if="infinite && !done"
|
||||||
|
:on-load="fetchNextPage"
|
||||||
|
:pause="loading"
|
||||||
|
:root="menuRef"
|
||||||
|
root-margin="0px 0px"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
@@ -88,7 +96,7 @@
|
|||||||
<next class="back-icon" @click="close" />
|
<next class="back-icon" @click="close" />
|
||||||
<span class="mobile-title">{{ placeholder }}</span>
|
<span class="mobile-title">{{ placeholder }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-mobile-menu">
|
<div class="dropdown-mobile-menu" ref="mobileMenuRef">
|
||||||
<div v-if="showSearch" class="dropdown-search">
|
<div v-if="showSearch" class="dropdown-search">
|
||||||
<search-icon class="search-icon" />
|
<search-icon class="search-icon" />
|
||||||
<input type="text" v-model="search" placeholder="搜索" />
|
<input type="text" v-model="search" placeholder="搜索" />
|
||||||
@@ -116,6 +124,13 @@
|
|||||||
<span>{{ o.name }}</span>
|
<span>{{ o.name }}</span>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
|
<InfiniteLoadMore
|
||||||
|
v-if="infinite && !done"
|
||||||
|
:on-load="fetchNextPage"
|
||||||
|
:pause="loading"
|
||||||
|
:root="mobileMenuRef"
|
||||||
|
root-margin="0px 0px"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -126,6 +141,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { computed, onMounted, ref, watch } from 'vue'
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
import { useIsMobile } from '~/utils/screen'
|
import { useIsMobile } from '~/utils/screen'
|
||||||
|
import InfiniteLoadMore from '~/components/InfiniteLoadMore.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'BaseDropdown',
|
name: 'BaseDropdown',
|
||||||
@@ -139,6 +155,8 @@ export default {
|
|||||||
optionClass: { type: String, default: '' },
|
optionClass: { type: String, default: '' },
|
||||||
showSearch: { type: Boolean, default: true },
|
showSearch: { type: Boolean, default: true },
|
||||||
initialOptions: { type: Array, default: () => [] },
|
initialOptions: { type: Array, default: () => [] },
|
||||||
|
infinite: { type: Boolean, default: false },
|
||||||
|
pageSize: { type: Number, default: 20 },
|
||||||
},
|
},
|
||||||
emits: ['update:modelValue', 'update:search', 'close'],
|
emits: ['update:modelValue', 'update:search', 'close'],
|
||||||
setup(props, { emit, expose }) {
|
setup(props, { emit, expose }) {
|
||||||
@@ -152,6 +170,10 @@ export default {
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const wrapper = ref(null)
|
const wrapper = ref(null)
|
||||||
const isMobile = useIsMobile()
|
const isMobile = useIsMobile()
|
||||||
|
const menuRef = ref(null)
|
||||||
|
const mobileMenuRef = ref(null)
|
||||||
|
const page = ref(0)
|
||||||
|
const done = ref(false)
|
||||||
|
|
||||||
const toggle = () => {
|
const toggle = () => {
|
||||||
open.value = !open.value
|
open.value = !open.value
|
||||||
@@ -188,18 +210,36 @@ export default {
|
|||||||
|
|
||||||
const loadOptions = async (kw = '') => {
|
const loadOptions = async (kw = '') => {
|
||||||
if (!props.remote && loaded.value) return
|
if (!props.remote && loaded.value) return
|
||||||
|
if (done.value) return
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
const res = await props.fetchOptions(props.remote ? kw : undefined)
|
const res = await props.fetchOptions(props.remote ? kw : undefined, page.value)
|
||||||
options.value = Array.isArray(res) ? res : []
|
const arr = Array.isArray(res) ? res : []
|
||||||
|
arr.forEach((o) => {
|
||||||
|
if (!options.value.some((e) => e.id === o.id)) {
|
||||||
|
options.value.push(o)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (arr.length < props.pageSize) done.value = true
|
||||||
if (!props.remote) loaded.value = true
|
if (!props.remote) loaded.value = true
|
||||||
} catch {
|
page.value += 1
|
||||||
options.value = []
|
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resetAndLoad = async (kw = '') => {
|
||||||
|
options.value = Array.isArray(props.initialOptions) ? [...props.initialOptions] : []
|
||||||
|
page.value = 0
|
||||||
|
done.value = false
|
||||||
|
await loadOptions(kw)
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchNextPage = async () => {
|
||||||
|
await loadOptions(search.value)
|
||||||
|
return done.value
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.initialOptions,
|
() => props.initialOptions,
|
||||||
(val) => {
|
(val) => {
|
||||||
@@ -212,7 +252,7 @@ export default {
|
|||||||
watch(open, async (val) => {
|
watch(open, async (val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
if (props.remote) {
|
if (props.remote) {
|
||||||
await loadOptions(search.value)
|
await resetAndLoad(search.value)
|
||||||
} else if (!loaded.value) {
|
} else if (!loaded.value) {
|
||||||
await loadOptions()
|
await loadOptions()
|
||||||
}
|
}
|
||||||
@@ -222,13 +262,13 @@ export default {
|
|||||||
watch(search, async (val) => {
|
watch(search, async (val) => {
|
||||||
emit('update:search', val)
|
emit('update:search', val)
|
||||||
if (props.remote && open.value) {
|
if (props.remote && open.value) {
|
||||||
await loadOptions(val)
|
await resetAndLoad(val)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!props.remote) {
|
if (!props.remote) {
|
||||||
loadOptions()
|
resetAndLoad()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -259,14 +299,19 @@ export default {
|
|||||||
search,
|
search,
|
||||||
filteredOptions,
|
filteredOptions,
|
||||||
wrapper,
|
wrapper,
|
||||||
|
menuRef,
|
||||||
|
mobileMenuRef,
|
||||||
selectedLabels,
|
selectedLabels,
|
||||||
isSelected,
|
isSelected,
|
||||||
loading,
|
loading,
|
||||||
isImageIcon,
|
isImageIcon,
|
||||||
|
fetchNextPage,
|
||||||
|
done,
|
||||||
setSearch,
|
setSearch,
|
||||||
isMobile,
|
isMobile,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
components: { InfiniteLoadMore },
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ const props = defineProps({
|
|||||||
rootMargin: { type: String, default: '200px 0px' },
|
rootMargin: { type: String, default: '200px 0px' },
|
||||||
/** 触发阈值 */
|
/** 触发阈值 */
|
||||||
threshold: { type: Number, default: 0 },
|
threshold: { type: Number, default: 0 },
|
||||||
|
/** 自定义 IntersectionObserver 根元素(默认为视口) */
|
||||||
|
root: { type: Object, default: null },
|
||||||
})
|
})
|
||||||
|
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
@@ -58,7 +60,11 @@ const startObserver = () => {
|
|||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ root: null, rootMargin: props.rootMargin, threshold: props.threshold },
|
{
|
||||||
|
root: props.root || null,
|
||||||
|
rootMargin: props.rootMargin,
|
||||||
|
threshold: props.threshold,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if (sentinel.value) io.observe(sentinel.value)
|
if (sentinel.value) io.observe(sentinel.value)
|
||||||
}
|
}
|
||||||
@@ -76,6 +82,13 @@ watch(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.root,
|
||||||
|
() => {
|
||||||
|
nextTick(startObserver)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
/** 父组件可选择性调用,用于外部强制重置(一般直接用 :key 重建更简单) */
|
/** 父组件可选择性调用,用于外部强制重置(一般直接用 :key 重建更简单) */
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
done.value = false
|
done.value = false
|
||||||
|
|||||||
@@ -132,6 +132,11 @@
|
|||||||
>{{ t.name }} <span class="section-item-text-count">x {{ t.count }}</span></span
|
>{{ t.name }} <span class="section-item-text-count">x {{ t.count }}</span></span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<InfiniteLoadMore
|
||||||
|
v-if="tagData.length > 0 && !tagDone"
|
||||||
|
:on-load="loadMoreTags"
|
||||||
|
:pause="isLoadingTag"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -154,6 +159,7 @@ import { authState, fetchCurrentUser } from '~/utils/auth'
|
|||||||
import { fetchUnreadCount, notificationState } from '~/utils/notification'
|
import { fetchUnreadCount, notificationState } from '~/utils/notification'
|
||||||
import { useIsMobile } from '~/utils/screen'
|
import { useIsMobile } from '~/utils/screen'
|
||||||
import { cycleTheme, ThemeMode, themeState } from '~/utils/theme'
|
import { cycleTheme, ThemeMode, themeState } from '~/utils/theme'
|
||||||
|
import InfiniteLoadMore from '~/components/InfiniteLoadMore.vue'
|
||||||
|
|
||||||
const isMobile = useIsMobile()
|
const isMobile = useIsMobile()
|
||||||
|
|
||||||
@@ -186,15 +192,41 @@ const {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const TAG_PAGE_SIZE = 10
|
||||||
|
const tagPage = ref(1)
|
||||||
|
const tagDone = ref(false)
|
||||||
const {
|
const {
|
||||||
data: tagData,
|
data: tagData,
|
||||||
pending: isLoadingTag,
|
pending: isLoadingTag,
|
||||||
error: tagError,
|
error: tagError,
|
||||||
} = await useAsyncData('menu:tags', () => $fetch(`${API_BASE_URL}/api/tags?limit=10`), {
|
} = await useAsyncData(
|
||||||
server: true,
|
'menu:tags',
|
||||||
default: () => [],
|
async () => {
|
||||||
staleTime: 5 * 60 * 1000,
|
const res = await $fetch(`${API_BASE_URL}/api/tags?page=0&pageSize=${TAG_PAGE_SIZE}`)
|
||||||
})
|
if (res.length < TAG_PAGE_SIZE) tagDone.value = true
|
||||||
|
return res
|
||||||
|
},
|
||||||
|
{
|
||||||
|
server: true,
|
||||||
|
default: () => [],
|
||||||
|
staleTime: 5 * 60 * 1000,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const loadMoreTags = async () => {
|
||||||
|
if (tagDone.value) return true
|
||||||
|
const res = await $fetch(
|
||||||
|
`${API_BASE_URL}/api/tags?page=${tagPage.value}&pageSize=${TAG_PAGE_SIZE}`,
|
||||||
|
)
|
||||||
|
if (Array.isArray(res) && res.length > 0) {
|
||||||
|
tagData.value.push(...res)
|
||||||
|
if (res.length < TAG_PAGE_SIZE) tagDone.value = true
|
||||||
|
tagPage.value++
|
||||||
|
} else {
|
||||||
|
tagDone.value = true
|
||||||
|
}
|
||||||
|
return tagDone.value
|
||||||
|
}
|
||||||
|
|
||||||
/** 其余逻辑保持不变 */
|
/** 其余逻辑保持不变 */
|
||||||
const iconClass = computed(() => {
|
const iconClass = computed(() => {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
placeholder="选择标签"
|
placeholder="选择标签"
|
||||||
remote
|
remote
|
||||||
:initial-options="mergedOptions"
|
:initial-options="mergedOptions"
|
||||||
|
infinite
|
||||||
|
:page-size="10"
|
||||||
>
|
>
|
||||||
<template #option="{ option }">
|
<template #option="{ option }">
|
||||||
<div class="option-container">
|
<div class="option-container">
|
||||||
@@ -42,6 +44,7 @@ const props = defineProps({
|
|||||||
options: { type: Array, default: () => [] },
|
options: { type: Array, default: () => [] },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const defaultOption = { id: 0, name: '无标签' }
|
||||||
const localTags = ref([])
|
const localTags = ref([])
|
||||||
const providedTags = ref(Array.isArray(props.options) ? [...props.options] : [])
|
const providedTags = ref(Array.isArray(props.options) ? [...props.options] : [])
|
||||||
|
|
||||||
@@ -53,7 +56,7 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const mergedOptions = computed(() => {
|
const mergedOptions = computed(() => {
|
||||||
const arr = [...providedTags.value, ...localTags.value]
|
const arr = [defaultOption, ...providedTags.value, ...localTags.value]
|
||||||
return arr.filter((v, i, a) => a.findIndex((t) => t.id === v.id) === i)
|
return arr.filter((v, i, a) => a.findIndex((t) => t.id === v.id) === i)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -62,21 +65,20 @@ const isImageIcon = (icon) => {
|
|||||||
return /^https?:\/\//.test(icon) || icon.startsWith('/')
|
return /^https?:\/\//.test(icon) || icon.startsWith('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildTagsUrl = (kw = '') => {
|
const buildTagsUrl = (kw = '', page = 0) => {
|
||||||
const base = API_BASE_URL || (import.meta.client ? window.location.origin : '')
|
const base = API_BASE_URL || (import.meta.client ? window.location.origin : '')
|
||||||
const url = new URL('/api/tags', base)
|
const url = new URL('/api/tags', base)
|
||||||
|
|
||||||
if (kw) url.searchParams.set('keyword', kw)
|
if (kw) url.searchParams.set('keyword', kw)
|
||||||
url.searchParams.set('limit', '10')
|
url.searchParams.set('page', String(page))
|
||||||
|
url.searchParams.set('pageSize', '10')
|
||||||
|
|
||||||
return url.toString()
|
return url.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchTags = async (kw = '') => {
|
const fetchTags = async (kw = '', page = 0) => {
|
||||||
const defaultOption = { id: 0, name: '无标签' }
|
|
||||||
|
|
||||||
// 1) 先拼 URL(自动兜底到 window.location.origin)
|
// 1) 先拼 URL(自动兜底到 window.location.origin)
|
||||||
const url = buildTagsUrl(kw)
|
const url = buildTagsUrl(kw, page)
|
||||||
|
|
||||||
// 2) 拉数据
|
// 2) 拉数据
|
||||||
let data = []
|
let data = []
|
||||||
@@ -87,17 +89,18 @@ const fetchTags = async (kw = '') => {
|
|||||||
toast.error('获取标签失败')
|
toast.error('获取标签失败')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) 合并、去重、可创建
|
// 3) 可创建
|
||||||
let options = [...data, ...localTags.value]
|
if (
|
||||||
|
props.creatable &&
|
||||||
if (props.creatable && kw && !options.some((t) => t.name.toLowerCase() === kw.toLowerCase())) {
|
kw &&
|
||||||
options.push({ id: `__create__:${kw}`, name: `创建"${kw}"` })
|
![...data, ...localTags.value, ...providedTags.value].some(
|
||||||
|
(t) => t.name.toLowerCase() === kw.toLowerCase(),
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
data.push({ id: `__create__:${kw}`, name: `创建"${kw}"` })
|
||||||
}
|
}
|
||||||
|
|
||||||
options = Array.from(new Map(options.map((t) => [t.id, t])).values())
|
return data
|
||||||
|
|
||||||
// 4) 最终结果
|
|
||||||
return [defaultOption, ...options]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const selected = computed({
|
const selected = computed({
|
||||||
|
|||||||
Reference in New Issue
Block a user