Skip to content

Commit 3d5acbb

Browse files
committed
perf(UI): 修复「自定义 CSS 字体」开启时修改「全局字体」卡顿
换成了自定义的 `s-input.vue` 组件,提供了 `update-value-on-input` 既然该都改了,那就两个都一起改掉了
1 parent a88af61 commit 3d5acbb

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ declare module 'vue' {
151151
SidebarHideManager: typeof import('./src/components/Modal/Setting/SidebarHideManager.vue')['default']
152152
Sider: typeof import('./src/components/Layout/Sider.vue')['default']
153153
SImage: typeof import('./src/components/UI/s-image.vue')['default']
154+
SInput: typeof import('./src/components/UI/s-input.vue')['default']
154155
SongCard: typeof import('./src/components/Card/SongCard.vue')['default']
155156
SongDataCard: typeof import('./src/components/Card/SongDataCard.vue')['default']
156157
SongInfoEditor: typeof import('./src/components/Modal/SongInfoEditor.vue')['default']

src/components/Modal/Setting/FontManager.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
恢复默认
2727
</n-button>
2828
</Transition>
29-
<n-input
29+
<s-input
3030
v-if="settingStore.useCustomFont"
3131
v-model:value="settingStore.globalFont"
32+
:update-value-on-input="false"
3233
placeholder="输入字体名称,例如: 'Microsoft YaHei'"
3334
class="set"
3435
/>
@@ -62,9 +63,10 @@
6263
恢复默认
6364
</n-button>
6465
</Transition>
65-
<n-input
66+
<s-input
6667
v-if="settingStore.useCustomFont"
6768
v-model:value="settingStore[font.key]"
69+
:update-value-on-input="false"
6870
placeholder="输入字体名称"
6971
class="set"
7072
/>

src/components/UI/s-input.vue

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<template>
2+
<n-input
3+
:value="input"
4+
@input="handleInput"
5+
@blur="handleConfirm"
6+
@keyup.enter="handleConfirm"
7+
v-bind="$attrs"
8+
/>
9+
</template>
10+
11+
<script setup lang="ts">
12+
const props = withDefaults(
13+
defineProps<{
14+
value?: string;
15+
updateValueOnInput?: boolean;
16+
}>(),
17+
{
18+
value: "",
19+
updateValueOnInput: false,
20+
},
21+
);
22+
23+
const emit = defineEmits<{
24+
(e: "update:value", value: string): void;
25+
}>();
26+
27+
const input = ref(props.value); // 内部值
28+
const value = ref(props.value); // 外部值
29+
30+
// 监听父组件 value 变化,同步到内部值
31+
watch(
32+
() => props.value,
33+
(newValue) => {
34+
value.value = newValue;
35+
input.value = newValue;
36+
},
37+
{ immediate: true },
38+
);
39+
40+
const handleInput = (newValue: string) => {
41+
if (props.updateValueOnInput) {
42+
value.value = newValue;
43+
emit("update:value", newValue);
44+
} else {
45+
input.value = newValue;
46+
}
47+
};
48+
49+
const handleConfirm = () => {
50+
if (!props.updateValueOnInput && input.value !== value.value) {
51+
value.value = input.value;
52+
emit("update:value", value.value);
53+
}
54+
}
55+
</script>

0 commit comments

Comments
 (0)