11import dayjs from 'dayjs' ;
2+ import { TABLE_NAMES , TABLE_NAMES_ARR } from '@/share/core/constant' ;
23import emitter from '@/share/core/emitter' ;
34import { convertToBasicRule } from '@/share/core/rule-utils' ;
45import { collectRulesUsedTasks } from '@/share/core/tasks' ;
@@ -10,35 +11,53 @@ export function getExportName(additional?: string) {
1011 return `HE_${ date } ${ additional ? '_' + additional : '' } .json` ;
1112}
1213
13- export async function createTaskExport ( task : Task ) {
14- if ( task . isFunction && task . code ) {
15- }
14+ export function createTaskExport ( x : Task ) {
15+ delete x . lastRun ;
16+ delete x . _func ;
17+ return x ;
1618}
1719
18- export async function createExport ( arr : {
19- [ key : string ] : Array < Rule | InitdRule > ;
20- } ) {
20+ export async function createExport (
21+ arr : Partial < {
22+ [ TABLE_NAMES . receiveHeader ] : Array < Rule | InitdRule > ;
23+ [ TABLE_NAMES . receiveBody ] : Array < Rule | InitdRule > ;
24+ [ TABLE_NAMES . request ] : Array < Rule | InitdRule > ;
25+ [ TABLE_NAMES . sendHeader ] : Array < Rule | InitdRule > ;
26+ tasks : Record < string , Task > ;
27+ } > ,
28+ ) {
2129 const result : any = { } ;
2230 const tasks = new Set < string > ( ) ;
23- Object . keys ( arr ) . forEach ( k => {
24- result [ k ] = arr [ k ] . map ( e => convertToBasicRule ( e ) ) ;
25- const t = collectRulesUsedTasks ( arr [ k ] ) ;
31+
32+ TABLE_NAMES_ARR . forEach ( tb => {
33+ if ( ! arr [ tb ] ) {
34+ return ;
35+ }
36+ result [ tb ] = arr [ tb ] . map ( e => convertToBasicRule ( e ) ) ;
37+ const t = collectRulesUsedTasks ( arr [ tb ] ) ;
2638 t . forEach ( e => tasks . add ( e ) ) ;
2739 } ) ;
40+
2841 // 一并导出任务
29- if ( tasks . size ) {
42+ if ( tasks . size || arr . tasks ) {
3043 const allTasks = await Api . getTasks ( ) ;
31- result . tasks = Object . fromEntries (
32- (
33- Array . from ( tasks )
34- . map ( x => allTasks . find ( y => y . key === x ) )
35- . filter ( Boolean ) as Task [ ]
36- ) . map ( x => {
37- delete x . lastRun ;
38- delete x . _func ;
39- return [ x . key , x ] ;
40- } ) ,
41- ) ;
44+ if ( ! result . tasks ) {
45+ result . tasks = { } ;
46+ }
47+ if ( arr . tasks ) {
48+ Object . keys ( arr . tasks ) . forEach ( x => {
49+ result . tasks [ x ] = createTaskExport ( arr . tasks ! [ x ] ) ;
50+ } ) ;
51+ }
52+ const tasksArr = Array . from ( tasks )
53+ . map ( x => allTasks . find ( y => y . key === x ) )
54+ . filter ( Boolean ) as Task [ ] ;
55+ tasksArr . forEach ( x => {
56+ if ( result . tasks [ x . key ] ) {
57+ return ;
58+ }
59+ result . tasks [ x . key ] = createTaskExport ( x ) ;
60+ } ) ;
4261 }
4362 return result ;
4463}
0 commit comments