@@ -6,7 +6,8 @@ import { selectGroup } from '@/pages/options/utils';
66import BoolRadioGroup from '@/share/components/bool-radio' ;
77import { TABLE_NAMES_ARR } from '@/share/core/constant' ;
88import { fromJson } from '@/share/core/rule-utils' ;
9- import type { BasicRule , ImportRule } from '@/share/core/types' ;
9+ import { getRuleUsedTasks } from '@/share/core/tasks' ;
10+ import type { BasicRule , ImportRule , Rule , Task } from '@/share/core/types' ;
1011import { t } from '@/share/core/utils' ;
1112import Api from '@/share/pages/api' ;
1213
@@ -26,6 +27,8 @@ export default class ImportDrawer extends React.Component<
2627 ImportDrawerProps ,
2728 ImportDrawerState
2829> {
30+ tasks ?: Record < string , Task > ;
31+
2932 constructor ( props : any ) {
3033 super ( props ) ;
3134
@@ -42,7 +45,7 @@ export default class ImportDrawer extends React.Component<
4245 } ;
4346 }
4447
45- show ( content : { [ key : string ] : BasicRule [ ] } ) {
48+ show ( content : any ) {
4649 this . setState ( {
4750 ...this . state ,
4851 list : [ ] ,
@@ -57,7 +60,7 @@ export default class ImportDrawer extends React.Component<
5760 if ( ! list [ tableName ] ) {
5861 return ;
5962 }
60- list [ tableName ] . forEach ( e => {
63+ list [ tableName ] . forEach ( ( e : Rule ) => {
6164 totalCount ++ ;
6265 Api . getRules ( tableName , { name : e . name } ) . then ( rule => {
6366 const it : ImportRule = {
@@ -79,15 +82,18 @@ export default class ImportDrawer extends React.Component<
7982 } ) ;
8083 } ) ;
8184 } ) ;
85+ if ( content . tasks ) {
86+ this . tasks = content . tasks ;
87+ }
8288 } catch ( e ) {
8389 console . error ( e ) ;
8490 }
8591 }
8692
8793 handleConfirm ( ) {
88- // TODO: 处理 task 导入
8994 // 确认导入
9095 const queue : any [ ] = [ ] ;
96+ const tasks = new Set < string > ( ) ;
9197 this . state . list . forEach ( ( e : any ) => {
9298 // 不导入
9399 if ( e . importAction === 3 ) {
@@ -106,8 +112,15 @@ export default class ImportDrawer extends React.Component<
106112 if ( typeof e . enable === 'undefined' ) {
107113 e . enable = true ;
108114 }
115+ getRuleUsedTasks ( e ) . forEach ( task => tasks . add ( task ) ) ;
109116 queue . push ( Api . saveRule ( e ) ) ;
110117 } ) ;
118+ // 处理 task 导入
119+ if ( tasks . size > 0 ) {
120+ Array . from ( tasks )
121+ . map ( x => this . tasks ?. [ x ] )
122+ . forEach ( t => queue . push ( t ? Api . saveTask ( t ) : Promise . resolve ( ) ) ) ;
123+ }
111124 Promise . all ( queue ) . then ( ( ) => {
112125 // this.imports.status = 0;
113126 Toast . success ( t ( 'import_success' ) ) ;
@@ -222,8 +235,8 @@ export default class ImportDrawer extends React.Component<
222235 render : ( _v : any , item : ImportRule ) => (
223236 < Select
224237 value = { item . importAction }
225- onChange = { ( value : string ) =>
226- this . handleActionChange ( item , value )
238+ onChange = { value =>
239+ this . handleActionChange ( item , value as string )
227240 }
228241 optionList = { [
229242 { label : t ( 'import_new' ) , value : 1 } ,
0 commit comments