@@ -22,6 +22,7 @@ import {
2222 useDebounceFn ,
2323 useInViewport ,
2424 useMemoizedFn ,
25+ useSelections ,
2526 useThrottleFn ,
2627 useUpdateEffect ,
2728 useVirtualList
@@ -37,7 +38,7 @@ import {YakitButton} from "@/components/yakitUI/YakitButton/YakitButton"
3738import { YakitRoute } from "@/enums/yakitRoute"
3839import { Form , Tooltip } from "antd"
3940import { yakitNotify } from "@/utils/notification"
40- import { AIForgeListDefaultPagination , ReActChatEventEnum } from "../defaultConstant"
41+ import { AIForgeListDefaultPagination , defaultExportAIForgeRequest , ReActChatEventEnum } from "../defaultConstant"
4142import { YakitPopconfirm } from "@/components/yakitUI/YakitPopconfirm/YakitPopconfirm"
4243import { AIForge , QueryAIForgeRequest , QueryAIForgeResponse } from "../type/forge"
4344import ImportExportModal , { ImportExportModalExtra } from "@/components/ImportExportModal/ImportExportModal"
@@ -51,14 +52,18 @@ import {LogListInfo} from "@/components/YakitUploadModal/YakitUploadModal"
5152
5253import classNames from "classnames"
5354import styles from "./ForgeName.module.scss"
55+ import { YakitProtoCheckbox } from "@/components/TableVirtualResize/YakitProtoCheckbox/YakitProtoCheckbox"
56+ import { YakitCheckbox } from "@/components/yakitUI/YakitCheckbox/YakitCheckbox"
57+ import { cloneDeep } from "lodash"
5458const { ipcRenderer} = window . require ( "electron" )
5559
5660export interface ForgeNameRef {
5761 openAdd : ( ) => void
5862 openImport : ( ) => void
63+ onBatchExport : ( ) => void
5964}
6065
61- const ForgeName = ( props , ref : Ref < ForgeNameRef > ) => {
66+ const ForwardForgeName = forwardRef ( ( props : ForgeNameProps , ref : Ref < ForgeNameRef > ) => {
6267 // const {} = props
6368
6469 // #region AIForge 模板增删改功能 使用功能
@@ -288,16 +293,15 @@ const ForgeName = (props, ref: Ref<ForgeNameRef>) => {
288293 apiKey : "ExportAIForge"
289294 } )
290295 const logListRef = useRef < LogListInfo [ ] > ( [ ] )
291- const forgeNamesRef = useRef < string [ ] > ( [ ] )
292- const toolNames = useRef < string [ ] > ( [ ] )
293- const outputNameRef = useRef < string > ( "" )
296+ const forgeExtraParams = useRef < ExportAIForgeRequest > ( cloneDeep ( defaultExportAIForgeRequest ) )
294297 const handleOpenImportExportHint = useMemoizedFn ( ( extra : Omit < ImportExportModalExtra , "hint" > ) => {
295298 if ( importExportExtra . hint ) return
296299 setImportExportExtra ( { ...extra , hint : true } )
297300 } )
298301
299302 const exportPath = useRef < string > ( "" )
300303 const handleFinishedImportExportHint = useMemoizedFn ( ( result : boolean ) => {
304+ onResetExportExtraParams ( )
301305 if ( result ) {
302306 const type = importExportExtra . type
303307 if ( type === "import" ) {
@@ -397,16 +401,56 @@ const ForgeName = (props, ref: Ref<ForgeNameRef>) => {
397401 }
398402 }
399403 // #endregion
404+ // #region AIForge 批量导出
405+ const { selected, allSelected, isSelected, toggle, toggleAll, partiallySelected} = useSelections ( data . Data )
406+ useEffect ( ( ) => {
407+ props . onSelectChange ( selected . length > 0 )
408+ } , [ selected . length ] )
409+ const onBatchExport = useMemoizedFn ( ( ) => {
410+ const query : ExportAIForgeRequest = {
411+ ForgeNames : [ ] ,
412+ OutputName : "" ,
413+ Filter : {
414+ Keyword : ""
415+ }
416+ }
417+ if ( allSelected ) {
418+ query . Filter = {
419+ Keyword : search
420+ }
421+ } else {
422+ query . ForgeNames = selected . map ( ( item ) => item . ForgeName ) as any
423+ }
424+ forgeExtraParams . current = {
425+ ...forgeExtraParams . current ,
426+ ...query
427+ }
428+ handleOpenImportExportHint ( {
429+ title : "导出技能" ,
430+ type : "export" ,
431+ apiKey : "ExportAIForge"
432+ } )
433+ } )
400434
401- useImperativeHandle ( ref , ( ) => ( {
402- openAdd : handleNewAIForge ,
403- openImport : ( ) =>
404- handleOpenImportExportHint ( {
405- title : "导入技能" ,
406- type : "import" ,
407- apiKey : "ImportAIForge"
408- } )
409- } ) )
435+ const onResetExportExtraParams = useMemoizedFn ( ( ) => {
436+ forgeExtraParams . current = cloneDeep ( defaultExportAIForgeRequest )
437+ } )
438+ //#endregion
439+
440+ useImperativeHandle (
441+ ref ,
442+ ( ) => ( {
443+ openAdd : handleNewAIForge ,
444+ openImport : ( ) =>
445+ handleOpenImportExportHint ( {
446+ title : "导入技能" ,
447+ type : "import" ,
448+ apiKey : "ImportAIForge"
449+ } ) ,
450+ onBatchExport : ( ) => onBatchExport ( )
451+ } ) ,
452+ [ ]
453+ )
410454
411455 return (
412456 < div ref = { wrapper } className = { styles [ "forge-name" ] } >
@@ -439,6 +483,14 @@ const ForgeName = (props, ref: Ref<ForgeNameRef>) => {
439483 value = { search }
440484 onChange = { ( e ) => setSearch ( e . target . value ) }
441485 />
486+ < div className = { styles [ "select-all" ] } >
487+ < YakitCheckbox
488+ checked = { allSelected }
489+ onChange = { ( ) => toggleAll ( ) }
490+ indeterminate = { partiallySelected }
491+ />
492+ < span > 全选</ span >
493+ </ div >
442494 </ div >
443495 </ div >
444496
@@ -500,13 +552,17 @@ const ForgeName = (props, ref: Ref<ForgeNameRef>) => {
500552 >
501553 < div className = { styles [ "forge-list-opt" ] } onClick = { ( ) => handleOnClick ( data ) } >
502554 < div
503- className = { classNames (
504- styles [ "opt-title" ] ,
505- "yakit-content-single-ellipsis"
506- ) }
555+ className = { classNames ( styles [ "opt-title" ] ) }
507556 title = { ForgeVerboseName || ForgeName }
508557 >
509- { ForgeVerboseName || ForgeName }
558+ < YakitProtoCheckbox
559+ checked = { isSelected ( data ) }
560+ onChange = { ( ) => toggle ( data ) }
561+ onClick = { ( e ) => e . stopPropagation ( ) }
562+ />
563+ < div className = 'yakit-content-single-ellipsis' >
564+ { ForgeVerboseName || ForgeName }
565+ </ div >
510566 </ div >
511567
512568 < div className = { styles [ "item-extra" ] } >
@@ -520,9 +576,12 @@ const ForgeName = (props, ref: Ref<ForgeNameRef>) => {
520576 icon = { < OutlineExportIcon /> }
521577 onClick = { ( e ) => {
522578 e . stopPropagation ( )
523- forgeNamesRef . current = [ ForgeName ]
524- toolNames . current = tools
525- outputNameRef . current = ForgeVerboseName || ForgeName || ""
579+ forgeExtraParams . current = {
580+ ...forgeExtraParams . current ,
581+ ForgeNames : [ ForgeName ] ,
582+ ToolNames : tools ,
583+ OutputName : ForgeVerboseName || ForgeName || ""
584+ }
526585 handleOpenImportExportHint ( {
527586 title : "导出技能" ,
528587 type : "export" ,
@@ -594,7 +653,10 @@ const ForgeName = (props, ref: Ref<ForgeNameRef>) => {
594653 < ImportExportModal < ExportAIForgeFormValues , ExportAIForgeRequest , ExportImportAIForgeProgress >
595654 { ...commonImportExportProps }
596655 formProps = { {
597- initialValues : { OutputName : outputNameRef . current || "" , ToolNames : toolNames . current }
656+ initialValues : {
657+ OutputName : forgeExtraParams . current ?. OutputName || "" ,
658+ ToolNames : forgeExtraParams . current ?. ToolNames || [ ]
659+ }
598660 } }
599661 renderForm = { ( ) => (
600662 < >
@@ -650,7 +712,7 @@ const ForgeName = (props, ref: Ref<ForgeNameRef>) => {
650712 } catch ( error ) { }
651713 } }
652714 onSubmitForm = { ( values ) => ( {
653- ForgeNames : forgeNamesRef . current ,
715+ ... forgeExtraParams . current ,
654716 ...values
655717 } ) }
656718 isProgressFinished = { ( p : ExportImportAIForgeProgress ) =>
@@ -687,8 +749,6 @@ const ForgeName = (props, ref: Ref<ForgeNameRef>) => {
687749 ) }
688750 </ div >
689751 )
690- }
691-
692- const ForwardForgeName = forwardRef < ForgeNameRef , { } > ( ForgeName )
752+ } )
693753
694754export default memo ( ForwardForgeName )
0 commit comments