@ -50,6 +50,77 @@
< / template >
< / template >
< / e l - i n p u t >
< / e l - i n p u t >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< el -form -item prop = "hasSpec" >
< el -checkbox v -model = " dialogData.rowData ! .hasSpec " :label ="$t('toolbox.clam.cron')" / >
< / e l - f o r m - i t e m >
< el -form -item v-if ="dialogData.rowData!.hasSpec && !isProductPro" >
< span > { { $t ( 'toolbox.clam.cronHelper' ) } } < / span >
< el -button link type = "primary" @click ="toUpload" >
{ { $t ( 'license.levelUpPro' ) } }
< / e l - b u t t o n >
< / e l - f o r m - i t e m >
< el -form -item prop = "spec" v-if ="dialogData.rowData!.hasSpec && isProductPro" >
< el -select
class = "specTypeClass"
v - model = "dialogData.rowData!.specObj.specType"
@ change = "changeSpecType()"
>
< el -option
v - for = "item in specOptions"
: key = "item.label"
: value = "item.value"
: label = "item.label"
/ >
< / e l - s e l e c t >
< el -select
v - if = "dialogData.rowData!.specObj.specType === 'perWeek'"
class = "specClass"
v - model = "dialogData.rowData!.specObj.week"
>
< el -option
v - for = "item in weekOptions"
: key = "item.label"
: value = "item.value"
: label = "item.label"
/ >
< / e l - s e l e c t >
< el -input
v - if = "hasDay(dialogData.rowData!.specObj)"
class = "specClass"
v - model . number = "dialogData.rowData!.specObj.day"
>
< template # append >
< div class = "append" > { { $t ( 'cronjob.day' ) } } < / div >
< / template >
< / e l - i n p u t >
< el -input
v - if = "hasHour(dialogData.rowData!.specObj)"
class = "specClass"
v - model . number = "dialogData.rowData!.specObj.hour"
>
< template # append >
< div class = "append" > { { $t ( 'commons.units.hour' ) } } < / div >
< / template >
< / e l - i n p u t >
< el -input
v - if = "dialogData.rowData!.specObj.specType !== 'perNSecond'"
class = "specClass"
v - model . number = "dialogData.rowData!.specObj.minute"
>
< template # append >
< div class = "append" > { { $t ( 'commons.units.minute' ) } } < / div >
< / template >
< / e l - i n p u t >
< el -input
v - if = "dialogData.rowData!.specObj.specType === 'perNSecond'"
class = "specClass"
v - model . number = "dialogData.rowData!.specObj.second"
>
< template # append >
< div class = "append" > { { $t ( 'commons.units.second' ) } } < / div >
< / template >
< / e l - i n p u t >
< / e l - f o r m - i t e m >
< el -form -item :label ="$t('commons.table.description')" prop = "description" >
< el -form -item :label ="$t('commons.table.description')" prop = "description" >
< el -input type = "textarea" :rows ="3" clearable v -model = " dialogData.rowData ! .description " / >
< el -input type = "textarea" :rows ="3" clearable v -model = " dialogData.rowData ! .description " / >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
@ -64,6 +135,7 @@
< / e l - b u t t o n >
< / e l - b u t t o n >
< / span >
< / span >
< / template >
< / template >
< LicenseImport ref = "licenseRef" / >
< / e l - d r a w e r >
< / e l - d r a w e r >
< / template >
< / template >
@ -73,11 +145,18 @@ import { Rules } from '@/global/form-rules';
import FileList from '@/components/file-list/index.vue' ;
import FileList from '@/components/file-list/index.vue' ;
import i18n from '@/lang' ;
import i18n from '@/lang' ;
import { ElForm } from 'element-plus' ;
import { ElForm } from 'element-plus' ;
import LicenseImport from '@/components/license-import/index.vue' ;
import DrawerHeader from '@/components/drawer-header/index.vue' ;
import DrawerHeader from '@/components/drawer-header/index.vue' ;
import { Msg Success } from '@/utils/message' ;
import { Msg Error, Msg Success } from '@/utils/message' ;
import { Toolbox } from '@/api/interface/toolbox' ;
import { Toolbox } from '@/api/interface/toolbox' ;
import { createClam , updateClam } from '@/api/modules/toolbox' ;
import { createClam , updateClam } from '@/api/modules/toolbox' ;
import { specOptions , transObjToSpec , transSpecToObj , weekOptions } from '../../../cronjob/helper' ;
import { storeToRefs } from 'pinia' ;
import { GlobalStore } from '@/store' ;
const globalStore = GlobalStore ( ) ;
const licenseRef = ref ( ) ;
const { isProductPro } = storeToRefs ( globalStore ) ;
interface DialogProps {
interface DialogProps {
title : string ;
title : string ;
rowData ? : Toolbox . ClamInfo ;
rowData ? : Toolbox . ClamInfo ;
@ -92,6 +171,19 @@ const dialogData = ref<DialogProps>({
const acceptParams = ( params : DialogProps ) : void => {
const acceptParams = ( params : DialogProps ) : void => {
dialogData . value = params ;
dialogData . value = params ;
if ( dialogData . value . rowData ? . spec ) {
dialogData . value . rowData . hasSpec = true ;
dialogData . value . rowData . specObj = transSpecToObj ( dialogData . value . rowData . spec ) ;
} else {
dialogData . value . rowData . specObj = {
specType : 'perDay' ,
week : 1 ,
day : 3 ,
hour : 1 ,
minute : 30 ,
second : 30 ,
} ;
}
title . value = i18n . global . t ( 'commons.button.' + dialogData . value . title ) ;
title . value = i18n . global . t ( 'commons.button.' + dialogData . value . title ) ;
drawerVisible . value = true ;
drawerVisible . value = true ;
} ;
} ;
@ -101,9 +193,97 @@ const handleClose = () => {
drawerVisible . value = false ;
drawerVisible . value = false ;
} ;
} ;
const verifySpec = ( rule : any , value : any , callback : any ) => {
let item = dialogData . value . rowData ! . specObj ;
if (
! Number . isInteger ( item . day ) ||
! Number . isInteger ( item . hour ) ||
! Number . isInteger ( item . minute ) ||
! Number . isInteger ( item . second ) ||
! Number . isInteger ( item . week )
) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
switch ( item . specType ) {
case 'perMonth' :
if (
item . day < 0 ||
item . day > 31 ||
item . hour < 0 ||
item . hour > 23 ||
item . minute < 0 ||
item . minute > 59
) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
break ;
case 'perNDay' :
if (
item . day < 0 ||
item . day > 366 ||
item . hour < 0 ||
item . hour > 23 ||
item . minute < 0 ||
item . minute > 59
) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
break ;
case 'perWeek' :
if (
item . week < 0 ||
item . week > 6 ||
item . hour < 0 ||
item . hour > 23 ||
item . minute < 0 ||
item . minute > 59
) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
break ;
case 'perDay' :
if ( item . hour < 0 || item . hour > 23 || item . minute < 0 || item . minute > 59 ) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
break ;
case 'perNHour' :
if ( item . hour < 0 || item . hour > 8784 || item . minute < 0 || item . minute > 59 ) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
break ;
case 'perHour' :
if ( item . minute < 0 || item . minute > 59 ) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
case 'perNMinute' :
if ( item . minute < 0 || item . minute > 527040 ) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
break ;
case 'perNSecond' :
if ( item . second < 0 || item . second > 31622400 ) {
callback ( new Error ( i18n . global . t ( 'cronjob.specErr' ) ) ) ;
return ;
}
break ;
}
callback ( ) ;
} ;
const rules = reactive ( {
const rules = reactive ( {
name : [ Rules . simpleName ] ,
name : [ Rules . simpleName ] ,
path : [ Rules . requiredInput , Rules . noSpace ] ,
path : [ Rules . requiredInput , Rules . noSpace ] ,
spec : [
{ validator : verifySpec , trigger : 'blur' , required : true } ,
{ validator : verifySpec , trigger : 'change' , required : true } ,
] ,
} ) ;
} ) ;
type FormInstance = InstanceType < typeof ElForm > ;
type FormInstance = InstanceType < typeof ElForm > ;
@ -120,12 +300,62 @@ const loadDir = async (path: string) => {
const loadInfectedDir = async ( path : string ) => {
const loadInfectedDir = async ( path : string ) => {
dialogData . value . rowData ! . infectedDir = path ;
dialogData . value . rowData ! . infectedDir = path ;
} ;
} ;
const hasDay = ( item : any ) => {
return item . specType === 'perMonth' || item . specType === 'perNDay' ;
} ;
const hasHour = ( item : any ) => {
return item . specType !== 'perHour' && item . specType !== 'perNMinute' && item . specType !== 'perNSecond' ;
} ;
const toUpload = ( ) => {
licenseRef . value . acceptParams ( ) ;
} ;
const changeSpecType = ( ) => {
let item = dialogData . value . rowData ! . specObj ;
switch ( item . specType ) {
case 'perMonth' :
case 'perNDay' :
item . day = 3 ;
item . hour = 1 ;
item . minute = 30 ;
break ;
case 'perWeek' :
item . week = 1 ;
item . hour = 1 ;
item . minute = 30 ;
break ;
case 'perDay' :
case 'perNHour' :
item . hour = 2 ;
item . minute = 30 ;
break ;
case 'perHour' :
case 'perNMinute' :
item . minute = 30 ;
break ;
case 'perNSecond' :
item . second = 30 ;
break ;
}
} ;
const onSubmit = async ( formEl : FormInstance | undefined ) => {
const onSubmit = async ( formEl : FormInstance | undefined ) => {
if ( ! formEl ) return ;
if ( ! formEl ) return ;
formEl . validate ( async ( valid ) => {
formEl . validate ( async ( valid ) => {
if ( ! valid ) return ;
if ( ! valid ) return ;
loading . value = true ;
loading . value = true ;
let spec = '' ;
let item = dialogData . value . rowData . specObj ;
if ( dialogData . value . rowData ! . hasSpec ) {
spec = transObjToSpec ( item . specType , item . week , item . day , item . hour , item . minute , item . second ) ;
if ( spec === '' ) {
MsgError ( i18n . global . t ( 'cronjob.cronSpecHelper' ) ) ;
return ;
}
}
dialogData . value . rowData . spec = spec ;
if ( dialogData . value . title === 'edit' ) {
if ( dialogData . value . title === 'edit' ) {
await updateClam ( dialogData . value . rowData )
await updateClam ( dialogData . value . rowData )
. then ( ( ) => {
. then ( ( ) => {
@ -158,3 +388,31 @@ defineExpose({
acceptParams ,
acceptParams ,
} ) ;
} ) ;
< / script >
< / script >
< style scoped lang = "scss" >
. specClass {
width : 20 % ! important ;
margin - left : 20 px ;
. append {
width : 20 px ;
}
}
@ media only screen and ( max - width : 1000 px ) {
. specClass {
width : 100 % ! important ;
margin - top : 20 px ;
margin - left : 0 ;
. append {
width : 43 px ;
}
}
}
. specTypeClass {
width : 22 % ! important ;
}
@ media only screen and ( max - width : 1000 px ) {
. specTypeClass {
width : 100 % ! important ;
}
}
< / style >