@@ -57,10 +57,11 @@ import { i18nName } from "@App/locales/locales";
5757import { hashColor , ScriptIcons } from "../utils" ;
5858import type { ScriptLoading } from "@App/pages/store/features/script" ;
5959import { requestEnableScript , pinToTop , scriptClient , synchronizeClient } from "@App/pages/store/features/script" ;
60- import { type TFunction } from "i18next" ;
6160import { getCombinedMeta } from "@App/app/service/service_worker/utils" ;
6261import { parseTags } from "@App/app/repo/metadata" ;
63- import { EnableSwitch , HomeCell , MemoizedAvatar , SourceCell , UpdateTimeCell } from "./components" ;
62+ import { EnableSwitch , HomeCell , MemoizedAvatar , ScriptSearchField , SourceCell , UpdateTimeCell } from "./components" ;
63+ import type { SetSearchRequest } from "./hooks" ;
64+ import type { SearchType } from "@App/app/service/service_worker/types" ;
6465
6566type ListType = ScriptLoading ;
6667
@@ -115,47 +116,6 @@ const DraggableContainer = React.forwardRef<HTMLTableSectionElement, React.HTMLA
115116
116117DraggableContainer . displayName = "DraggableContainer" ;
117118
118- const FilterDropdown = React . memo (
119- ( {
120- filterKeys,
121- setFilterKeys,
122- confirm,
123- t,
124- inputRef,
125- } : {
126- filterKeys : string ;
127- setFilterKeys : ( filterKeys : string , callback ?: ( ...args : any [ ] ) => any ) => void ;
128- confirm : ( ...args : any [ ] ) => any ;
129- t : TFunction < "translation" , undefined > ;
130- inputRef : React . RefObject < RefInputType > ;
131- } ) => {
132- const { onSearchChange } = {
133- onSearchChange : ( value : string ) => {
134- setFilterKeys ( value ) ;
135- } ,
136- } ;
137- // onSearch 不能使用 useCallback / useMemo
138- const onSearch = ( ) => {
139- confirm ( filterKeys ) ;
140- } ;
141- return (
142- < div className = "arco-table-custom-filter flex flex-row gap-2" >
143- < Input . Search
144- ref = { inputRef }
145- size = "small"
146- searchButton
147- style = { { minWidth : 240 } }
148- placeholder = { t ( "enter_search_value" , { search : `${ t ( "name" ) } /${ t ( "script_code" ) } ` } ) }
149- defaultValue = { filterKeys || "" }
150- onChange = { onSearchChange }
151- onSearch = { onSearch }
152- />
153- </ div >
154- ) ;
155- }
156- ) ;
157- FilterDropdown . displayName = "FilterDropdown" ;
158-
159119function composeRefs < T > ( ...refs : React . Ref < T > [ ] ) : ( node : T | null ) => void {
160120 return ( node ) => {
161121 for ( const ref of refs ) {
@@ -460,7 +420,8 @@ interface ScriptTableProps {
460420 updateScripts : ( uuids : string [ ] , data : Partial < Script | ScriptLoading > ) => void ;
461421 setUserConfig : ( config : { script : Script ; userConfig : UserConfig ; values : { [ key : string ] : any } } ) => void ;
462422 setCloudScript : ( script : Script ) => void ;
463- setSearchKeyword : ( keyword : string ) => void ;
423+ searchRequest : { keyword : string ; type : SearchType } ;
424+ setSearchRequest : SetSearchRequest ;
464425 handleDelete : ( item : ScriptLoading ) => void ;
465426 handleConfig : (
466427 item : ScriptLoading ,
@@ -479,7 +440,8 @@ export const ScriptTable = ({
479440 updateScripts,
480441 setUserConfig,
481442 setCloudScript,
482- setSearchKeyword,
443+ searchRequest,
444+ setSearchRequest,
483445 handleDelete,
484446 handleConfig,
485447 handleRunStop,
@@ -532,18 +494,19 @@ export const ScriptTable = ({
532494 dataIndex : "name" ,
533495 sorter : ( a , b ) => a . name . localeCompare ( b . name ) ,
534496 filterIcon : < IconSearch /> ,
535- filterDropdown : ( { filterKeys , setFilterKeys , confirm } : any ) => {
497+ filterDropdown : ( { confirm } : any ) => {
536498 return (
537- < FilterDropdown
538- filterKeys = { filterKeys }
539- setFilterKeys = { setFilterKeys }
540- confirm = { ( value ) => {
541- setSearchKeyword ( value || "" ) ;
542- confirm ( ) ;
543- } }
544- t = { t }
545- inputRef = { inputRef }
546- />
499+ < div className = "arco-table-custom-filter flex flex-row gap-2" >
500+ < ScriptSearchField
501+ t = { t }
502+ defaultValue = { searchRequest }
503+ onSearch = { ( req ) => {
504+ setSearchRequest ( req ) ;
505+ confirm ( ) ;
506+ } }
507+ inputRef = { inputRef }
508+ />
509+ </ div >
547510 ) ;
548511 } ,
549512 onFilterDropdownVisibleChange : ( visible ) => {
@@ -657,7 +620,8 @@ export const ScriptTable = ({
657620 t ,
658621 sidebarOpen ,
659622 updateScripts ,
660- setSearchKeyword ,
623+ searchRequest ,
624+ setSearchRequest ,
661625 navigate ,
662626 setSidebarOpen ,
663627 setViewMode ,
@@ -679,30 +643,18 @@ export const ScriptTable = ({
679643 useEffect ( ( ) => {
680644 if ( savedWidths === null ) return ;
681645
682- setNewColumns ( ( nColumns ) => {
683- const widths = columns . map ( ( item ) => savedWidths [ item . key ! ] ?? item . width ) ;
684- const c = nColumns . length === widths . length ? nColumns : columns ;
685- return c . map ( ( item , i ) => {
686- const width = widths [ i ] ;
687- let dest ;
688- if ( i === 8 ) {
689- // 第8列特殊处理,因为可能涉及到操作图的显示
690- dest = item . render === columns [ i ] . render && item . title === columns [ i ] . title ? item : columns [ i ] ;
691- } else {
692- dest = item ;
646+ // 主要只需要处理列宽变化的情况
647+ setNewColumns (
648+ columns . map ( ( item , i ) => {
649+ if ( savedWidths [ item . key ! ] === undefined ) {
650+ return columns [ i ] ;
693651 }
694- let m =
695- width === dest . width
696- ? dest
697- : {
698- ...dest ,
699- width,
700- } ;
701- // 处理语言更新
702- if ( m . title !== columns [ i ] . title ) m = { ...m , title : columns [ i ] . title } ;
703- return m ;
704- } ) ;
705- } ) ;
652+ return {
653+ ...columns [ i ] ,
654+ width : savedWidths [ item . key ! ] ?? item . width ,
655+ } ;
656+ } )
657+ ) ;
706658 } , [ savedWidths , columns ] ) ;
707659
708660 useEffect ( ( ) => {
0 commit comments