22 <div :class =" $vuetify.display.mobile ? '' : 'd-flex'" >
33 <v-tabs v-model =" tab" :direction =" $vuetify.display.mobile ? 'horizontal' : 'vertical'"
44 :align-tabs =" $vuetify.display.mobile ? 'left' : 'start'" color =" deep-purple-accent-4" class =" config-tabs" >
5- <v-tab v-for =" (val, key, index) in metadata " :key =" index " :value =" index "
5+ <v-tab v-for =" section in visibleSections " :key =" section.key " :value =" section.key "
66 style =" font-weight : 1000 ; font-size : 15px " >
7- {{ tm(metadata[key] ['name']) }}
7+ {{ tm(section.value ['name']) }}
88 </v-tab >
99 </v-tabs >
1010 <v-tabs-window v-model =" tab" class =" config-tabs-window" :style =" readonly ? 'pointer-events: none; opacity: 0.6;' : ''" >
11- <v-tabs-window-item v-for =" (val, key, index) in metadata " v-show = " index == tab " :key = " index " >
11+ <v-tabs-window-item v-for =" section in visibleSections " :key = " section.key " :value = " section.key " >
1212 <v-container fluid >
13- <div v-for =" (val2, key2, index2) in metadata[key] ['metadata']" :key =" key2" >
13+ <div v-for =" (val2, key2, index2) in section.value ['metadata']" :key =" key2" >
1414 <!-- Support both traditional and JSON selector metadata -->
15- <AstrBotConfigV4 :metadata =" { [key2]: metadata[key]['metadata'][key2] }" :iterable =" config_data"
16- :metadataKey =" key2" >
15+ <AstrBotConfigV4
16+ :metadata =" { [key2]: section.value['metadata'][key2] }"
17+ :iterable =" config_data"
18+ :metadataKey =" key2"
19+ :search-keyword =" searchKeyword"
20+ >
1721 </AstrBotConfigV4 >
1822 </div >
1923 </v-container >
3135
3236 </v-tabs-window >
3337 </div >
38+ <v-container v-if =" visibleSections.length === 0" fluid class =" px-0" >
39+ <v-alert type =" info" variant =" tonal" >
40+ {{ tm('search.noResult') }}
41+ </v-alert >
42+ </v-container >
3443</template >
3544
3645<script >
@@ -56,6 +65,10 @@ export default {
5665 readonly: {
5766 type: Boolean ,
5867 default: false
68+ },
69+ searchKeyword: {
70+ type: String ,
71+ default: ' '
5972 }
6073 },
6174 setup () {
@@ -76,11 +89,63 @@ export default {
7689 },
7790 data () {
7891 return {
79- tab: 0 , // 用于切换配置标签页
92+ tab: null , // 当前激活的配置标签页 key
93+ }
94+ },
95+ computed: {
96+ normalizedSearchKeyword () {
97+ return String (this .searchKeyword || ' ' ).trim ().toLowerCase ();
98+ },
99+ visibleSections () {
100+ if (! this .metadata || typeof this .metadata !== ' object' ) {
101+ return [];
102+ }
103+ const allSections = Object .entries (this .metadata ).map (([key , value ]) => ({ key, value }));
104+ if (! this .normalizedSearchKeyword ) {
105+ return allSections;
106+ }
107+ return allSections .filter ((section ) => this .sectionHasSearchMatch (section .value ));
80108 }
81109 },
110+ watch: {
111+ visibleSections (newSections ) {
112+ const sectionKeys = newSections .map ((section ) => section .key );
113+ if (! sectionKeys .includes (this .tab )) {
114+ this .tab = sectionKeys[0 ] ?? null ;
115+ }
116+ }
117+ },
118+ mounted () {
119+ const sectionKeys = this .visibleSections .map ((section ) => section .key );
120+ this .tab = sectionKeys[0 ] ?? null ;
121+ },
82122 methods: {
83- // 如果需要添加其他方法,可以在这里添加
123+ sectionHasSearchMatch (section ) {
124+ const keyword = this .normalizedSearchKeyword ;
125+ if (! keyword) {
126+ return true ;
127+ }
128+ const sectionMetadata = section? .metadata || {};
129+ return Object .values (sectionMetadata).some ((metaItem ) => this .metaObjectHasSearchMatch (metaItem, keyword));
130+ },
131+ metaObjectHasSearchMatch (metaObject , keyword ) {
132+ if (! metaObject || typeof metaObject !== ' object' ) {
133+ return false ;
134+ }
135+ const target = [
136+ this .tm (metaObject .description || ' ' ),
137+ this .tm (metaObject .hint || ' ' ),
138+ ... Object .entries (metaObject .items || {}).flatMap (([itemKey , itemMeta ]) => ([
139+ itemKey,
140+ this .tm (itemMeta? .description || ' ' ),
141+ this .tm (itemMeta? .hint || ' ' )
142+ ]))
143+ ]
144+ .join (' ' )
145+ .toLowerCase ();
146+
147+ return target .includes (keyword);
148+ }
84149 }
85150}
86151< / script>
@@ -112,4 +177,4 @@ export default {
112177 margin- top: 16px ;
113178 }
114179}
115- </style >
180+ < / style>
0 commit comments