diff --git a/src/components/IconSelect/index.vue b/src/components/IconSelect/index.vue index 1f8c57b4..ba8e787d 100644 --- a/src/components/IconSelect/index.vue +++ b/src/components/IconSelect/index.vue @@ -11,12 +11,13 @@ const inputValue = toRef(props, "modelValue"); const visible = ref(false); // 弹窗显示状态 -const iconNames: string[] = []; // 所有的图标名称集合 +const allIconNames: string[] = []; // 所有的图标名称集合 const filterValue = ref(""); // 筛选的值 const filterIconNames = ref([]); // 过滤后的图标名称集合 -const iconSelectorRef = ref(null); +const iconSelectorRef = ref(); +const iconSelectorDialogRef = ref(); /** * icon 加载 */ @@ -24,9 +25,9 @@ function loadIcons() { const icons = import.meta.glob("../../assets/icons/*.svg"); for (const icon in icons) { const iconName = icon.split("assets/icons/")[1].split(".svg")[0]; - iconNames.push(iconName); + allIconNames.push(iconName); } - filterIconNames.value = iconNames; + filterIconNames.value = allIconNames; } /** @@ -34,11 +35,11 @@ function loadIcons() { */ function handleFilter() { if (filterValue.value) { - filterIconNames.value = iconNames.filter((iconName) => + filterIconNames.value = allIconNames.filter((iconName) => iconName.includes(filterValue.value) ); } else { - filterIconNames.value = iconNames; + filterIconNames.value = allIconNames; } } @@ -53,7 +54,9 @@ function handleSelect(iconName: string) { /** * 点击容器外的区域关闭弹窗 VueUse onClickOutside */ -onClickOutside(iconSelectorRef, () => (visible.value = false)); +onClickOutside(iconSelectorRef, () => (visible.value = false), { + ignore: [iconSelectorDialogRef], +}); onMounted(() => { loadIcons(); @@ -91,32 +94,34 @@ onMounted(() => { - - +
+ + - -
    -
  • - - - -
  • -
-
+ +
    +
  • + + + +
  • +
+
+