From 6f4e811b7dc83f696ff3410237aae3ea4730141a Mon Sep 17 00:00:00 2001 From: ssongliu Date: Tue, 20 Sep 2022 19:12:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=89=8D=E7=AB=AF=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/cronjob.go | 87 ++++ backend/app/api/v1/entry.go | 1 + backend/app/dto/cronjob.go | 61 +++ backend/app/model/cronjob.go | 25 ++ backend/app/repo/cronjob.go | 58 +++ backend/app/repo/entry.go | 1 + backend/app/service/cornjob.go | 87 ++++ backend/app/service/entry.go | 2 + backend/cron/{corn.go => cron.go} | 2 +- backend/global/global.go | 2 +- backend/init/migration/migrate.go | 1 + backend/init/migration/migrations/init.go | 8 + backend/init/router/router.go | 1 + backend/router/entry.go | 1 + backend/router/ro_cronjob.go | 22 + frontend/src/api/interface/cronjob.ts | 56 +++ frontend/src/api/modules/cronjob.ts | 19 + frontend/src/lang/modules/en.ts | 2 +- frontend/src/lang/modules/zh.ts | 44 +- frontend/src/routers/modules/cronjob.ts | 22 + frontend/src/routers/modules/plan.ts | 22 - frontend/src/views/cronjob/index.vue | 472 +++++++++++++++++++++ frontend/src/views/cronjob/options.ts | 38 ++ frontend/src/views/plan/index.vue | 7 - frontend/src/views/setting/tabs/backup.vue | 1 - 25 files changed, 1008 insertions(+), 34 deletions(-) create mode 100644 backend/app/api/v1/cronjob.go create mode 100644 backend/app/dto/cronjob.go create mode 100644 backend/app/model/cronjob.go create mode 100644 backend/app/repo/cronjob.go create mode 100644 backend/app/service/cornjob.go rename backend/cron/{corn.go => cron.go} (95%) create mode 100644 backend/router/ro_cronjob.go create mode 100644 frontend/src/api/interface/cronjob.ts create mode 100644 frontend/src/api/modules/cronjob.ts create mode 100644 frontend/src/routers/modules/cronjob.ts delete mode 100644 frontend/src/routers/modules/plan.ts create mode 100644 frontend/src/views/cronjob/index.vue create mode 100644 frontend/src/views/cronjob/options.ts delete mode 100644 frontend/src/views/plan/index.vue diff --git a/backend/app/api/v1/cronjob.go b/backend/app/api/v1/cronjob.go new file mode 100644 index 000000000..5275c1199 --- /dev/null +++ b/backend/app/api/v1/cronjob.go @@ -0,0 +1,87 @@ +package v1 + +import ( + "github.com/1Panel-dev/1Panel/app/api/v1/helper" + "github.com/1Panel-dev/1Panel/app/dto" + "github.com/1Panel-dev/1Panel/constant" + "github.com/1Panel-dev/1Panel/global" + "github.com/gin-gonic/gin" +) + +func (b *BaseApi) CreateCronjob(c *gin.Context) { + var req dto.CronjobCreate + if err := c.ShouldBindJSON(&req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + if err := global.VALID.Struct(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + if err := cronjobService.Create(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} + +func (b *BaseApi) SearchCronjob(c *gin.Context) { + var req dto.SearchWithPage + if err := c.ShouldBindJSON(&req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + + total, list, err := cronjobService.SearchWithPage(req) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + + helper.SuccessWithData(c, dto.PageResult{ + Items: list, + Total: total, + }) +} + +func (b *BaseApi) DeleteCronjob(c *gin.Context) { + var req dto.BatchDeleteReq + if err := c.ShouldBindJSON(&req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + if err := global.VALID.Struct(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + + if err := cronjobService.Delete(req.Ids); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} + +func (b *BaseApi) UpdateCronjob(c *gin.Context) { + var req dto.CronjobUpdate + if err := c.ShouldBindJSON(&req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + if err := global.VALID.Struct(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + id, err := helper.GetParamID(c) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + + upMap := make(map[string]interface{}) + if err := cronjobService.Update(id, upMap); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} diff --git a/backend/app/api/v1/entry.go b/backend/app/api/v1/entry.go index 62ece23e0..d8213cd42 100644 --- a/backend/app/api/v1/entry.go +++ b/backend/app/api/v1/entry.go @@ -16,5 +16,6 @@ var ( commandService = service.ServiceGroupApp.CommandService operationService = service.ServiceGroupApp.OperationService fileService = service.ServiceGroupApp.FileService + cronjobService = service.ServiceGroupApp.CronjobService settingService = service.ServiceGroupApp.SettingService ) diff --git a/backend/app/dto/cronjob.go b/backend/app/dto/cronjob.go new file mode 100644 index 000000000..f71d69b2f --- /dev/null +++ b/backend/app/dto/cronjob.go @@ -0,0 +1,61 @@ +package dto + +type CronjobCreate struct { + Name string `json:"name" validate:"required"` + Type string `json:"type" validate:"required"` + SpecType string `json:"specType" validate:"required"` + Week int `json:"week" validate:"number,max=7,min=1"` + Day int `json:"day" validate:"number,max=31,min=1"` + Hour int `json:"hour" validate:"number,max=23,min=0"` + Minute int `json:"minute" validate:"number,max=59,min=0"` + + Script string `json:"script"` + Website string `json:"website"` + ExclusionRules string `json:"exclusionRules"` + Database string `json:"database"` + URL string `json:"url"` + TargetDirID int `json:"targetDirID"` + RetainCopies int `json:"retainCopies" validate:"number,min=1"` +} + +type CronjobUpdate struct { + Name string `json:"name" validate:"required"` + Type string `json:"type" validate:"required"` + SpecType string `json:"specType" validate:"required"` + Week int `json:"week" validate:"number,max=7,min=1"` + Day int `json:"day" validate:"number,max=31,min=1"` + Hour int `json:"hour" validate:"number,max=23,min=0"` + Minute int `json:"minute" validate:"number,max=60,min=1"` + + Script string `json:"script"` + Website string `json:"website"` + ExclusionRules string `json:"exclusionRules"` + Database string `json:"database"` + URL string `json:"url"` + TargetDirID int `json:"targetDirID" validate:"number,min=1"` + RetainCopies int `json:"retainCopies" validate:"number,min=1"` + + Status string `json:"status"` +} + +type CronjobInfo struct { + ID uint `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + SpecType string `json:"specType"` + Week int `json:"week"` + Day int `json:"day"` + Hour int `json:"hour"` + Minute int `json:"minute"` + + Script string `json:"script"` + Website string `json:"website"` + ExclusionRules string `json:"exclusionRules"` + Database string `json:"database"` + URL string `json:"url"` + TargetDir string `json:"targetDir"` + TargetDirID int `json:"targetDirID"` + RetainCopies int `json:"retainCopies"` + + Status string `json:"status"` +} diff --git a/backend/app/model/cronjob.go b/backend/app/model/cronjob.go new file mode 100644 index 000000000..d235f5b86 --- /dev/null +++ b/backend/app/model/cronjob.go @@ -0,0 +1,25 @@ +package model + +type Cronjob struct { + BaseModel + + Name string `gorm:"type:varchar(64);not null" json:"name"` + Type string `gorm:"type:varchar(64);not null" json:"type"` + SpecType string `gorm:"type:varchar(64);not null" json:"specType"` + Spec string `gorm:"type:varchar(64);not null" json:"spec"` + Week uint64 `gorm:"type:decimal" json:"week"` + Day uint64 `gorm:"type:decimal" json:"day"` + Hour uint64 `gorm:"type:decimal" json:"hour"` + Minute uint64 `gorm:"type:decimal" json:"minute"` + + Script string `gorm:"longtext" json:"script"` + Website string `gorm:"type:varchar(64)" json:"website"` + Database string `gorm:"type:varchar(64)" json:"database"` + URL string `gorm:"type:varchar(256)" json:"url"` + SourceDir string `gorm:"type:varchar(256)" json:"sourceDir"` + TargetDirID uint64 `gorm:"type:decimal" json:"targetDirID"` + ExclusionRules string `gorm:"longtext" json:"exclusionRules"` + RetainCopies uint64 `gorm:"type:decimal" json:"retainCopies"` + + Status string `gorm:"type:varchar(64)" json:"status"` +} diff --git a/backend/app/repo/cronjob.go b/backend/app/repo/cronjob.go new file mode 100644 index 000000000..675b65d7e --- /dev/null +++ b/backend/app/repo/cronjob.go @@ -0,0 +1,58 @@ +package repo + +import ( + "github.com/1Panel-dev/1Panel/app/model" + "github.com/1Panel-dev/1Panel/global" +) + +type CronjobRepo struct{} + +type ICronjobRepo interface { + Get(opts ...DBOption) (model.Cronjob, error) + Page(limit, offset int, opts ...DBOption) (int64, []model.Cronjob, error) + Create(cronjob *model.Cronjob) error + Update(id uint, vars map[string]interface{}) error + Delete(opts ...DBOption) error +} + +func NewICronjobService() ICronjobRepo { + return &CronjobRepo{} +} + +func (u *CronjobRepo) Get(opts ...DBOption) (model.Cronjob, error) { + var cronjob model.Cronjob + db := global.DB + for _, opt := range opts { + db = opt(db) + } + err := db.First(&cronjob).Error + return cronjob, err +} + +func (u *CronjobRepo) Page(page, size int, opts ...DBOption) (int64, []model.Cronjob, error) { + var users []model.Cronjob + db := global.DB.Model(&model.Cronjob{}) + for _, opt := range opts { + db = opt(db) + } + count := int64(0) + db = db.Count(&count) + err := db.Limit(size).Offset(size * (page - 1)).Find(&users).Error + return count, users, err +} + +func (u *CronjobRepo) Create(cronjob *model.Cronjob) error { + return global.DB.Create(cronjob).Error +} + +func (u *CronjobRepo) Update(id uint, vars map[string]interface{}) error { + return global.DB.Model(&model.Cronjob{}).Where("id = ?", id).Updates(vars).Error +} + +func (u *CronjobRepo) Delete(opts ...DBOption) error { + db := global.DB + for _, opt := range opts { + db = opt(db) + } + return db.Delete(&model.Cronjob{}).Error +} diff --git a/backend/app/repo/entry.go b/backend/app/repo/entry.go index 0b662becc..4f380ccfe 100644 --- a/backend/app/repo/entry.go +++ b/backend/app/repo/entry.go @@ -7,6 +7,7 @@ type RepoGroup struct { CommandRepo OperationRepo CommonRepo + CronjobRepo SettingRepo } diff --git a/backend/app/service/cornjob.go b/backend/app/service/cornjob.go new file mode 100644 index 000000000..5d05e0ae9 --- /dev/null +++ b/backend/app/service/cornjob.go @@ -0,0 +1,87 @@ +package service + +import ( + "fmt" + + "github.com/1Panel-dev/1Panel/app/dto" + "github.com/1Panel-dev/1Panel/constant" + "github.com/jinzhu/copier" + "github.com/pkg/errors" +) + +type CronjobService struct{} + +type ICronjobService interface { + SearchWithPage(search dto.SearchWithPage) (int64, interface{}, error) + Create(cronjobDto dto.CronjobCreate) error + Update(id uint, upMap map[string]interface{}) error + Delete(ids []uint) error +} + +func NewICronjobService() ICronjobService { + return &CronjobService{} +} + +func (u *CronjobService) SearchWithPage(search dto.SearchWithPage) (int64, interface{}, error) { + total, cronjobs, err := cronjobRepo.Page(search.Page, search.PageSize, commonRepo.WithLikeName(search.Info)) + var dtoCronjobs []dto.CronjobInfo + for _, cronjob := range cronjobs { + var item dto.CronjobInfo + if err := copier.Copy(&item, &cronjob); err != nil { + return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) + } + if item.Type == "website" || item.Type == "database" || item.Type == "directory" { + backup, _ := backupRepo.Get(commonRepo.WithByID(uint(item.TargetDirID))) + if len(backup.Type) != 0 { + item.TargetDir = backup.Type + } + } else { + item.TargetDir = "-" + } + dtoCronjobs = append(dtoCronjobs, item) + } + return total, dtoCronjobs, err +} + +func (u *CronjobService) Create(cronjobDto dto.CronjobCreate) error { + cronjob, _ := cronjobRepo.Get(commonRepo.WithByName(cronjobDto.Name)) + if cronjob.ID != 0 { + return constant.ErrRecordExist + } + if err := copier.Copy(&cronjob, &cronjobDto); err != nil { + return errors.WithMessage(constant.ErrStructTransform, err.Error()) + } + switch cronjobDto.SpecType { + case "perMonth": + cronjob.Spec = fmt.Sprintf("%v %v %v * *", cronjobDto.Minute, cronjobDto.Hour, cronjobDto.Day) + case "perWeek": + cronjob.Spec = fmt.Sprintf("%v %v * * %v", cronjobDto.Minute, cronjobDto.Hour, cronjobDto.Week) + case "perNDay": + cronjob.Spec = fmt.Sprintf("%v %v */%v * *", cronjobDto.Minute, cronjobDto.Hour, cronjobDto.Day) + case "perNHour": + cronjob.Spec = fmt.Sprintf("%v */%v * * *", cronjobDto.Minute, cronjobDto.Hour) + case "perHour": + cronjob.Spec = fmt.Sprintf("%v * * * *", cronjobDto.Minute) + case "perNMinute": + cronjob.Spec = fmt.Sprintf("@every %vm", cronjobDto.Minute) + } + if err := cronjobRepo.Create(&cronjob); err != nil { + return err + } + return nil +} + +func (u *CronjobService) Delete(ids []uint) error { + if len(ids) == 1 { + cronjob, _ := cronjobRepo.Get(commonRepo.WithByID(ids[0])) + if cronjob.ID == 0 { + return constant.ErrRecordNotFound + } + return cronjobRepo.Delete(commonRepo.WithByID(ids[0])) + } + return cronjobRepo.Delete(commonRepo.WithIdsIn(ids)) +} + +func (u *CronjobService) Update(id uint, upMap map[string]interface{}) error { + return cronjobRepo.Update(id, upMap) +} diff --git a/backend/app/service/entry.go b/backend/app/service/entry.go index 09ff6626f..fa6d5e2e3 100644 --- a/backend/app/service/entry.go +++ b/backend/app/service/entry.go @@ -10,6 +10,7 @@ type ServiceGroup struct { CommandService OperationService FileService + CronjobService SettingService } @@ -22,5 +23,6 @@ var ( commandRepo = repo.RepoGroupApp.CommandRepo operationRepo = repo.RepoGroupApp.OperationRepo commonRepo = repo.RepoGroupApp.CommonRepo + cronjobRepo = repo.RepoGroupApp.CronjobRepo settingRepo = repo.RepoGroupApp.SettingRepo ) diff --git a/backend/cron/corn.go b/backend/cron/cron.go similarity index 95% rename from backend/cron/corn.go rename to backend/cron/cron.go index c75c5611b..a6384a35b 100644 --- a/backend/cron/corn.go +++ b/backend/cron/cron.go @@ -17,5 +17,5 @@ func Run() { } Cron.Start() - global.Corn = Cron + global.Cron = Cron } diff --git a/backend/global/global.go b/backend/global/global.go index 74f061a98..a10740fe9 100644 --- a/backend/global/global.go +++ b/backend/global/global.go @@ -18,5 +18,5 @@ var ( SESSION *psession.PSession CACHE *badger_db.Cache - Corn *cron.Cron + Cron *cron.Cron ) diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index 5915d9f0a..fd0b30e91 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -14,6 +14,7 @@ func Init() { migrations.AddTableMonitor, migrations.AddTableSetting, migrations.AddTableBackupAccount, + migrations.AddTableCronjob, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index e90983c6f..57f1ecc2d 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -136,3 +136,11 @@ var AddTableBackupAccount = &gormigrate.Migration{ return nil }, } + +var AddTableCronjob = &gormigrate.Migration{ + ID: "20200921-add-table-cronjob", + Migrate: func(tx *gorm.DB) error { + return tx.AutoMigrate(&model.Cronjob{}) + + }, +} diff --git a/backend/init/router/router.go b/backend/init/router/router.go index bfdec1ba0..8de87fb59 100644 --- a/backend/init/router/router.go +++ b/backend/init/router/router.go @@ -52,6 +52,7 @@ func Routers() *gin.Engine { systemRouter.InitMonitorRouter(PrivateGroup) systemRouter.InitOperationLogRouter(PrivateGroup) systemRouter.InitFileRouter(PrivateGroup) + systemRouter.InitCronjobRouter(PrivateGroup) systemRouter.InitSettingRouter(PrivateGroup) } diff --git a/backend/router/entry.go b/backend/router/entry.go index 5bde3c8ee..c1681c381 100644 --- a/backend/router/entry.go +++ b/backend/router/entry.go @@ -10,6 +10,7 @@ type RouterGroup struct { OperationLogRouter FileRouter TerminalRouter + CronjobRouter SettingRouter } diff --git a/backend/router/ro_cronjob.go b/backend/router/ro_cronjob.go new file mode 100644 index 000000000..f837586ae --- /dev/null +++ b/backend/router/ro_cronjob.go @@ -0,0 +1,22 @@ +package router + +import ( + v1 "github.com/1Panel-dev/1Panel/app/api/v1" + "github.com/1Panel-dev/1Panel/middleware" + + "github.com/gin-gonic/gin" +) + +type CronjobRouter struct{} + +func (s *CronjobRouter) InitCronjobRouter(Router *gin.RouterGroup) { + cmdRouter := Router.Group("cronjobs").Use(middleware.JwtAuth()).Use(middleware.SessionAuth()) + withRecordRouter := Router.Group("cronjobs").Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.OperationRecord()) + baseApi := v1.ApiGroupApp.BaseApi + { + withRecordRouter.POST("", baseApi.CreateCronjob) + withRecordRouter.POST("/del", baseApi.DeleteCronjob) + withRecordRouter.PUT(":id", baseApi.UpdateCronjob) + cmdRouter.POST("/search", baseApi.SearchCronjob) + } +} diff --git a/frontend/src/api/interface/cronjob.ts b/frontend/src/api/interface/cronjob.ts new file mode 100644 index 000000000..21090a503 --- /dev/null +++ b/frontend/src/api/interface/cronjob.ts @@ -0,0 +1,56 @@ +export namespace Cronjob { + export interface CronjobInfo { + id: number; + name: string; + type: string; + specType: string; + week: number; + day: number; + hour: number; + minute: number; + + script: string; + website: string; + exclusionRules: string; + database: string; + url: string; + targetDirID: number; + targetDir: string; + retainCopies: number; + status: string; + } + export interface CronjobCreate { + name: string; + type: string; + specType: string; + week: number; + day: number; + hour: number; + minute: number; + + script: string; + website: string; + exclusionRules: string; + database: string; + url: string; + targetDirID: number; + retainCopies: number; + } + export interface CronjobUpdate { + id: number; + specType: string; + week: number; + day: number; + hour: number; + minute: number; + + script: string; + website: string; + exclusionRules: string; + database: string; + url: string; + targetDirID: number; + retainCopies: number; + status: string; + } +} diff --git a/frontend/src/api/modules/cronjob.ts b/frontend/src/api/modules/cronjob.ts new file mode 100644 index 000000000..56ecdc8dd --- /dev/null +++ b/frontend/src/api/modules/cronjob.ts @@ -0,0 +1,19 @@ +import http from '@/api'; +import { ResPage, ReqPage } from '../interface'; +import { Cronjob } from '../interface/cronjob'; + +export const getCronjobPage = (params: ReqPage) => { + return http.post>(`/cronjobs/search`, params); +}; + +export const addCronjob = (params: Cronjob.CronjobCreate) => { + return http.post(`/cronjobs`, params); +}; + +export const editCronjob = (params: Cronjob.CronjobUpdate) => { + return http.put(`/cronjobs/${params.id}`, params); +}; + +export const deleteCronjob = (params: { ids: number[] }) => { + return http.post(`/cronjobs/del`, params); +}; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 4f2d241b5..d0b003031 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -114,7 +114,7 @@ export default { firewall: 'Firewall', database: 'Database', container: 'Container', - plan: 'Planned Task', + cronjob: 'Cronjob', host: 'Host', security: 'Security', files: 'File Management', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 364fa2867..b91e4a6d0 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -111,7 +111,7 @@ export default { firewall: '防火墙', database: '数据库', container: '容器', - plan: '计划任务', + cron: '计划任务', host: '主机', security: '安全', files: '文件管理', @@ -133,6 +133,48 @@ export default { header: { logout: '退出登录', }, + cronjob: { + createCronTask: '创建计划任务', + taskType: '任务类型', + shell: 'Shell 脚本', + website: '备份网站', + all: '所有', + database: '备份数据库', + missBackupAccount: '未能找到备份账号', + syncDate: '同步时间 ', + syncDateName: '定期同步服务器时间 ', + releaseMemory: '释放内存', + curl: '访问', + taskName: '任务名称', + cronSpec: '执行周期', + directory: '备份目录', + sourceDir: '备份目录', + exclusionRules: '排除规则', + url: 'URL 地址', + target: '备份到', + retainCopies: '保留份数', + cronSpecRule: '请输入正确的执行周期', + perMonth: '每月', + perWeek: '每周', + perHour: '每小时', + perNDay: '每隔 N 日', + perNHour: '每隔 N 时', + perNMinute: '每隔 N 分钟', + per: '每隔', + handle: '执行', + day: '日', + day1: '天', + hour: '小时', + minute: '分钟', + monday: '周一', + tuesday: '周二', + wednesday: '周三', + thursday: '周四', + friday: '周五', + saturday: '周六', + sunday: '周日', + shellContent: '脚本内容', + }, monitor: { avgLoad: '平均负载', loadDetail: '负载详情', diff --git a/frontend/src/routers/modules/cronjob.ts b/frontend/src/routers/modules/cronjob.ts new file mode 100644 index 000000000..6353e89c5 --- /dev/null +++ b/frontend/src/routers/modules/cronjob.ts @@ -0,0 +1,22 @@ +import { Layout } from '@/routers/constant'; + +const cronRouter = { + sort: 6, + path: '/cronjobs', + component: Layout, + redirect: '/cronjobs', + meta: { + icon: 'p-plan', + title: 'menu.cron', + }, + children: [ + { + path: '/cronjobs', + name: 'Cronjob', + component: () => import('@/views/cronjob/index.vue'), + meta: {}, + }, + ], +}; + +export default cronRouter; diff --git a/frontend/src/routers/modules/plan.ts b/frontend/src/routers/modules/plan.ts deleted file mode 100644 index 667f41941..000000000 --- a/frontend/src/routers/modules/plan.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Layout } from '@/routers/constant'; - -const planRouter = { - sort: 6, - path: '/plans', - component: Layout, - redirect: '/plans', - meta: { - icon: 'p-plan', - title: 'menu.plan', - }, - children: [ - { - path: '/plans', - name: 'Plan', - component: () => import('@/views/plan/index.vue'), - meta: {}, - }, - ], -}; - -export default planRouter; diff --git a/frontend/src/views/cronjob/index.vue b/frontend/src/views/cronjob/index.vue new file mode 100644 index 000000000..a44963d85 --- /dev/null +++ b/frontend/src/views/cronjob/index.vue @@ -0,0 +1,472 @@ + + + diff --git a/frontend/src/views/cronjob/options.ts b/frontend/src/views/cronjob/options.ts new file mode 100644 index 000000000..0f3f38c0a --- /dev/null +++ b/frontend/src/views/cronjob/options.ts @@ -0,0 +1,38 @@ +import i18n from '@/lang'; + +export const typeOptions = [ + { label: i18n.global.t('cronjob.shell'), value: 'shell' }, + { label: i18n.global.t('cronjob.website'), value: 'website' }, + { label: i18n.global.t('cronjob.database'), value: 'database' }, + { label: i18n.global.t('cronjob.directory'), value: 'directory' }, + { label: i18n.global.t('cronjob.syncDate'), value: 'sync' }, + { label: i18n.global.t('cronjob.releaseMemory'), value: 'release' }, + { label: i18n.global.t('cronjob.curl') + ' URL', value: 'curl' }, +]; + +export const specOptions = [ + { label: i18n.global.t('cronjob.perMonth'), value: 'perMonth' }, + { label: i18n.global.t('cronjob.perWeek'), value: 'perWeek' }, + { label: i18n.global.t('cronjob.perNDay'), value: 'perNDay' }, + { label: i18n.global.t('cronjob.perNHour'), value: 'perNHour' }, + { label: i18n.global.t('cronjob.perHour'), value: 'perHour' }, + { label: i18n.global.t('cronjob.perNMinute'), value: 'perNMinute' }, +]; + +export const weekOptions = [ + { label: i18n.global.t('cronjob.monday'), value: 1 }, + { label: i18n.global.t('cronjob.tuesday'), value: 2 }, + { label: i18n.global.t('cronjob.wednesday'), value: 3 }, + { label: i18n.global.t('cronjob.thursday'), value: 4 }, + { label: i18n.global.t('cronjob.friday'), value: 5 }, + { label: i18n.global.t('cronjob.saturday'), value: 6 }, + { label: i18n.global.t('cronjob.sunday'), value: 7 }, +]; +export const loadWeek = (i: number) => { + for (const week of weekOptions) { + if (week.value === i) { + return week.label; + } + } + return ''; +}; diff --git a/frontend/src/views/plan/index.vue b/frontend/src/views/plan/index.vue deleted file mode 100644 index cdfc73be6..000000000 --- a/frontend/src/views/plan/index.vue +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/frontend/src/views/setting/tabs/backup.vue b/frontend/src/views/setting/tabs/backup.vue index 83a2a1863..e014f58eb 100644 --- a/frontend/src/views/setting/tabs/backup.vue +++ b/frontend/src/views/setting/tabs/backup.vue @@ -277,7 +277,6 @@ const getBuckets = async () => { buckets.value = res.data; }; const loadDir = async (path: string) => { - console.log(path); form.varsJson['dir'] = path; }; const loadOption = () => {