@@ -11,15 +11,16 @@ import { DropArea } from "@/components/drop"
1111import { Table } from "@/components/table"
1212import { Button } from "@/components/button"
1313import { FileVideoIcon , FileTextIcon , FileArchiveIcon } from "@phosphor-icons/react"
14+ import { useSubtitleStore } from "@/store/subtitle"
1415
1516const colKeys = [ "video" , "sc" , "tc" ]
1617
1718export function SubtitleRename ( ) {
1819 const [ cell , setCell ] = useState ( null )
19- const [ fileList , setFileList ] = useState ( { } ) // 拖入时生成,便于排序,右键菜单也会操作此对象
2020 const [ fileData , setFileData ] = useState ( [ ] ) // 展平为带路径的数组,用于重命名
2121 const [ tableData , setTableData ] = useState ( [ ] ) // 上面数组的基础上移除了路径,只保留文件名
22- const [ archiveList , setArchiveList ] = useState ( [ ] ) // 拖入的压缩包路径
22+
23+ const { fileList, archiveList, setFileList, setArchiveList, clearAll } = useSubtitleStore ( )
2324
2425 const tableColumns = [
2526 { key : "video" , title : "视频文件" } ,
@@ -66,8 +67,8 @@ export function SubtitleRename() {
6667 if ( addedCount === 0 ) {
6768 throw new Error ( `${ filterText } ,耗时 ${ elapsedTime ( startTime ) } ` )
6869 } else {
69- setFileList ( files )
70- setArchiveList ( archives )
70+ setFileList ( ( ) => files )
71+ setArchiveList ( ( ) => archives )
7172 return { message : `添加了 ${ addedCount } 个文件${ filterText && `,${ filterText } ` } ,耗时 ${ elapsedTime ( startTime ) } ` }
7273 }
7374 } ) ( )
@@ -77,7 +78,7 @@ export function SubtitleRename() {
7778 success : { title : ( data ) => data . message } ,
7879 error : { type : "warning" , title : ( err ) => err . message }
7980 } )
80- } , [ fileList , archiveList ] )
81+ } , [ fileList , archiveList , setFileList , setArchiveList ] )
8182
8283 // 更改字幕类型
8384 const handleChangeType = useCallback ( ( ) => {
@@ -89,7 +90,7 @@ export function SubtitleRename() {
8990 [ sourceKey ] : ( prev [ sourceKey ] || [ ] ) . filter ( ( _ , i ) => i !== cell . row ) ,
9091 [ targetKey ] : [ ...( prev [ targetKey ] || [ ] ) , value ] . sort ( sortFiles )
9192 } ) )
92- } , [ cell , fileList ] )
93+ } , [ cell , fileList , setFileList ] )
9394
9495 // 内容移动
9596 const handleMove = useCallback ( ( offset ) => {
@@ -100,7 +101,7 @@ export function SubtitleRename() {
100101 [ key ] : prev [ key ] . map ( ( v , i ) => i === cell . row ? prev [ key ] [ targetRow ] : i === targetRow ? prev [ key ] [ cell . row ] : v
101102 )
102103 } ) )
103- } , [ cell ] )
104+ } , [ cell , setFileList ] )
104105
105106 // 删除单个内容
106107 const handleDeleteItem = useCallback ( ( ) => {
@@ -109,7 +110,7 @@ export function SubtitleRename() {
109110 ...prev ,
110111 [ key ] : prev [ key ] . filter ( ( _ , i ) => i !== cell . row )
111112 } ) )
112- } , [ cell ] )
113+ } , [ cell , setFileList ] )
113114
114115 // 删除整行
115116 const handleDeleteRow = useCallback ( ( ) => {
@@ -118,18 +119,12 @@ export function SubtitleRename() {
118119 Object . entries ( prev ) . map ( ( [ key , arr ] ) => [ key , arr . filter ( ( _ , i ) => i !== cell . row ) ] )
119120 )
120121 )
121- } , [ cell ] )
122-
123- // 清空列表
124- const handleClearList = ( ) => {
125- setFileList ( { } )
126- setArchiveList ( [ ] )
127- }
122+ } , [ cell , setFileList ] )
128123
129124 // 重命名字幕
130125 const handleRename = async ( ) => {
131126 const success = await renameSubtitles ( fileData , archiveList )
132- if ( success ) handleClearList ( )
127+ if ( success ) clearAll ( )
133128 }
134129
135130 return (
@@ -175,7 +170,7 @@ export function SubtitleRename() {
175170 </ PageBlock >
176171
177172 < PageBlock className = "items-center justify-end gap-3 p-4" last >
178- < Button className = "w-26" onClick = { ( ) => handleClearList ( ) } > 清空列表</ Button >
173+ < Button className = "w-26" onClick = { ( ) => clearAll ( ) } > 清空列表</ Button >
179174 < Button variant = "primary" className = "w-26" onClick = { handleRename } > 重命名</ Button >
180175 </ PageBlock >
181176 </ Page >
0 commit comments