|
@@ -61,21 +61,37 @@ const iconItemStyle = computed((): ParameterCSSProperties => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
function setVal() {
|
|
function setVal() {
|
|
|
- currentActiveType.value = inputValue.value.substring(
|
|
|
|
|
- 0,
|
|
|
|
|
- inputValue.value.indexOf(":") + 1
|
|
|
|
|
- );
|
|
|
|
|
- icon.value = inputValue.value.substring(inputValue.value.indexOf(":") + 1);
|
|
|
|
|
|
|
+ const v = inputValue.value as unknown as string;
|
|
|
|
|
+ if (!v || typeof v !== "string") {
|
|
|
|
|
+ icon.value = "";
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const sepIndex = v.indexOf(":");
|
|
|
|
|
+ if (sepIndex < 0) {
|
|
|
|
|
+ icon.value = "";
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ currentActiveType.value = v.substring(0, sepIndex + 1);
|
|
|
|
|
+ icon.value = v.substring(sepIndex + 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function onBeforeEnter() {
|
|
function onBeforeEnter() {
|
|
|
- if (isAllEmpty(icon.value)) return;
|
|
|
|
|
|
|
+ const v = inputValue.value as unknown as string;
|
|
|
|
|
+ if (!v || typeof v !== "string" || v.indexOf(":") < 0) {
|
|
|
|
|
+ // 空值或不符合在线格式时,显示默认搜索图标,并重置分页/选项卡
|
|
|
|
|
+ icon.value = "";
|
|
|
|
|
+ currentActiveType.value = tabsList[0].name; // 默认 Element Plus 图标集
|
|
|
|
|
+ currentPage.value = 1;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
setVal();
|
|
setVal();
|
|
|
// 寻找当前图标在第几页
|
|
// 寻找当前图标在第几页
|
|
|
- const curIconIndex = copyIconList[currentActiveType.value].findIndex(
|
|
|
|
|
- i => i === icon.value
|
|
|
|
|
|
|
+ const list = copyIconList[currentActiveType.value] || [];
|
|
|
|
|
+ const curIconIndex = list.findIndex(i => i === icon.value);
|
|
|
|
|
+ currentPage.value = Math.max(
|
|
|
|
|
+ 1,
|
|
|
|
|
+ Math.ceil((curIconIndex + 1) / pageSize.value)
|
|
|
);
|
|
);
|
|
|
- currentPage.value = Math.ceil((curIconIndex + 1) / pageSize.value);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function onAfterLeave() {
|
|
function onAfterLeave() {
|
|
@@ -111,7 +127,13 @@ watch(
|
|
|
);
|
|
);
|
|
|
watch(
|
|
watch(
|
|
|
() => inputValue.value,
|
|
() => inputValue.value,
|
|
|
- val => val && setVal(),
|
|
|
|
|
|
|
+ val => {
|
|
|
|
|
+ if (val && typeof val === "string") return setVal();
|
|
|
|
|
+ // 当输入值为空时,清空内部状态以确保显示默认图标
|
|
|
|
|
+ icon.value = "";
|
|
|
|
|
+ currentActiveType.value = tabsList[0].name;
|
|
|
|
|
+ currentPage.value = 1;
|
|
|
|
|
+ },
|
|
|
{ immediate: true }
|
|
{ immediate: true }
|
|
|
);
|
|
);
|
|
|
watch(
|
|
watch(
|