File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' ]
Original file line number Diff line number Diff line change 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 />
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 />
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments