mirror of
				https://github.com/whyour/qinglong.git
				synced 2025-11-01 01:16:07 +08:00 
			
		
		
		
	定时任务增加置顶功能
This commit is contained in:
		
							parent
							
								
									b6a78550d6
								
							
						
					
					
						commit
						aa1fe98188
					
				|  | @ -191,6 +191,42 @@ export default (app: Router) => { | ||||||
|     }, |     }, | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|  |   route.put( | ||||||
|  |     '/crons/pin', | ||||||
|  |     celebrate({ | ||||||
|  |       body: Joi.array().items(Joi.string().required()), | ||||||
|  |     }), | ||||||
|  |     async (req: Request, res: Response, next: NextFunction) => { | ||||||
|  |       const logger: Logger = Container.get('logger'); | ||||||
|  |       try { | ||||||
|  |         const cronService = Container.get(CronService); | ||||||
|  |         const data = await cronService.pin(req.body); | ||||||
|  |         return res.send({ code: 200, data }); | ||||||
|  |       } catch (e) { | ||||||
|  |         logger.error('🔥 error: %o', e); | ||||||
|  |         return next(e); | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  |   route.put( | ||||||
|  |     '/crons/unpin', | ||||||
|  |     celebrate({ | ||||||
|  |       body: Joi.array().items(Joi.string().required()), | ||||||
|  |     }), | ||||||
|  |     async (req: Request, res: Response, next: NextFunction) => { | ||||||
|  |       const logger: Logger = Container.get('logger'); | ||||||
|  |       try { | ||||||
|  |         const cronService = Container.get(CronService); | ||||||
|  |         const data = await cronService.unPin(req.body); | ||||||
|  |         return res.send({ code: 200, data }); | ||||||
|  |       } catch (e) { | ||||||
|  |         logger.error('🔥 error: %o', e); | ||||||
|  |         return next(e); | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|   route.get( |   route.get( | ||||||
|     '/crons/import', |     '/crons/import', | ||||||
|     async (req: Request, res: Response, next: NextFunction) => { |     async (req: Request, res: Response, next: NextFunction) => { | ||||||
|  |  | ||||||
|  | @ -115,6 +115,32 @@ export default class CronService { | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   public async pin(ids: string[]) { | ||||||
|  |     return new Promise((resolve: any) => { | ||||||
|  |       this.cronDb.update( | ||||||
|  |         { _id: { $in: ids } }, | ||||||
|  |         { $set: { isPinned: 1 } }, | ||||||
|  |         { multi: true }, | ||||||
|  |         async (err) => { | ||||||
|  |           resolve(); | ||||||
|  |         }, | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   public async unPin(ids: string[]) { | ||||||
|  |     return new Promise((resolve: any) => { | ||||||
|  |       this.cronDb.update( | ||||||
|  |         { _id: { $in: ids } }, | ||||||
|  |         { $set: { isPinned: 0 } }, | ||||||
|  |         { multi: true }, | ||||||
|  |         async (err) => { | ||||||
|  |           resolve(); | ||||||
|  |         }, | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   public async crontabs(searchText?: string): Promise<Crontab[]> { |   public async crontabs(searchText?: string): Promise<Crontab[]> { | ||||||
|     let query = {}; |     let query = {}; | ||||||
|     if (searchText) { |     if (searchText) { | ||||||
|  |  | ||||||
|  | @ -25,6 +25,7 @@ import { | ||||||
|   DeleteOutlined, |   DeleteOutlined, | ||||||
|   PauseCircleOutlined, |   PauseCircleOutlined, | ||||||
|   FieldTimeOutlined, |   FieldTimeOutlined, | ||||||
|  |   PushpinOutlined, | ||||||
| } from '@ant-design/icons'; | } from '@ant-design/icons'; | ||||||
| import config from '@/utils/config'; | import config from '@/utils/config'; | ||||||
| import { PageContainer } from '@ant-design/pro-layout'; | import { PageContainer } from '@ant-design/pro-layout'; | ||||||
|  | @ -49,6 +50,8 @@ enum OperationName { | ||||||
|   '禁用', |   '禁用', | ||||||
|   '运行', |   '运行', | ||||||
|   '停止', |   '停止', | ||||||
|  |   '置顶', | ||||||
|  |   '取消置顶', | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| enum OperationPath { | enum OperationPath { | ||||||
|  | @ -56,6 +59,8 @@ enum OperationPath { | ||||||
|   'disable', |   'disable', | ||||||
|   'run', |   'run', | ||||||
|   'stop', |   'stop', | ||||||
|  |   'pin', | ||||||
|  |   'unpin', | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const Crontab = ({ headerStyle, isPhone }: any) => { | const Crontab = ({ headerStyle, isPhone }: any) => { | ||||||
|  | @ -66,7 +71,16 @@ const Crontab = ({ headerStyle, isPhone }: any) => { | ||||||
|       key: 'name', |       key: 'name', | ||||||
|       align: 'center' as const, |       align: 'center' as const, | ||||||
|       render: (text: string, record: any) => ( |       render: (text: string, record: any) => ( | ||||||
|         <span>{record.name || record._id}</span> |         <span> | ||||||
|  |           {record.name || record._id}{' '} | ||||||
|  |           {record.isPinned ? ( | ||||||
|  |             <span> | ||||||
|  |               <PushpinOutlined /> | ||||||
|  |             </span> | ||||||
|  |           ) : ( | ||||||
|  |             '' | ||||||
|  |           )} | ||||||
|  |         </span> | ||||||
|       ), |       ), | ||||||
|       sorter: { |       sorter: { | ||||||
|         compare: (a: any, b: any) => a.name.localeCompare(b.name), |         compare: (a: any, b: any) => a.name.localeCompare(b.name), | ||||||
|  | @ -237,7 +251,12 @@ const Crontab = ({ headerStyle, isPhone }: any) => { | ||||||
|           data.data.sort((a: any, b: any) => { |           data.data.sort((a: any, b: any) => { | ||||||
|             const sortA = a.isDisabled ? 4 : a.status; |             const sortA = a.isDisabled ? 4 : a.status; | ||||||
|             const sortB = b.isDisabled ? 4 : b.status; |             const sortB = b.isDisabled ? 4 : b.status; | ||||||
|  |             a.isPinned = a.isPinned ? a.isPinned : 0; | ||||||
|  |             b.isPinned = b.isPinned ? b.isPinned : 0; | ||||||
|  |             if (a.isPinned === b.isPinned) { | ||||||
|               return CrontabSort[sortA] - CrontabSort[sortB]; |               return CrontabSort[sortA] - CrontabSort[sortB]; | ||||||
|  |             } | ||||||
|  |             return b.isPinned - a.isPinned; | ||||||
|           }), |           }), | ||||||
|         ); |         ); | ||||||
|         setCurrentPage(1); |         setCurrentPage(1); | ||||||
|  | @ -403,6 +422,50 @@ const Crontab = ({ headerStyle, isPhone }: any) => { | ||||||
|     }); |     }); | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  |   const pinOrunPinCron = (record: any, index: number) => { | ||||||
|  |     Modal.confirm({ | ||||||
|  |       title: `确认${record.isPinned === 1 ? '取消置顶' : '置顶'}`, | ||||||
|  |       content: ( | ||||||
|  |         <> | ||||||
|  |           确认{record.isPinned === 1 ? '取消置顶' : '置顶'} | ||||||
|  |           定时任务{' '} | ||||||
|  |           <Text style={{ wordBreak: 'break-all' }} type="warning"> | ||||||
|  |             {record.name} | ||||||
|  |           </Text>{' '} | ||||||
|  |           吗 | ||||||
|  |         </> | ||||||
|  |       ), | ||||||
|  |       onOk() { | ||||||
|  |         request | ||||||
|  |           .put( | ||||||
|  |             `${config.apiPrefix}crons/${ | ||||||
|  |               record.isPinned === 1 ? 'unpin' : 'pin' | ||||||
|  |             }`,
 | ||||||
|  |             { | ||||||
|  |               data: [record._id], | ||||||
|  |             }, | ||||||
|  |           ) | ||||||
|  |           .then((data: any) => { | ||||||
|  |             if (data.code === 200) { | ||||||
|  |               const newStatus = record.isPinned === 1 ? 0 : 1; | ||||||
|  |               const result = [...value]; | ||||||
|  |               const i = result.findIndex((x) => x._id === record._id); | ||||||
|  |               result.splice(i, 1, { | ||||||
|  |                 ...record, | ||||||
|  |                 isPinned: newStatus, | ||||||
|  |               }); | ||||||
|  |               setValue(result); | ||||||
|  |             } else { | ||||||
|  |               message.error(data); | ||||||
|  |             } | ||||||
|  |           }); | ||||||
|  |       }, | ||||||
|  |       onCancel() { | ||||||
|  |         console.log('Cancel'); | ||||||
|  |       }, | ||||||
|  |     }); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|   const MoreBtn: React.FC<{ |   const MoreBtn: React.FC<{ | ||||||
|     record: any; |     record: any; | ||||||
|     index: number; |     index: number; | ||||||
|  | @ -432,6 +495,14 @@ const Crontab = ({ headerStyle, isPhone }: any) => { | ||||||
|               删除 |               删除 | ||||||
|             </Menu.Item> |             </Menu.Item> | ||||||
|           )} |           )} | ||||||
|  |           <Menu.Item | ||||||
|  |             key="pinOrunPin" | ||||||
|  |             icon={ | ||||||
|  |               record.isPinned === 1 ? <StopOutlined /> : <PushpinOutlined /> | ||||||
|  |             } | ||||||
|  |           > | ||||||
|  |             {record.isPinned === 1 ? '取消置顶' : '置顶'} | ||||||
|  |           </Menu.Item> | ||||||
|         </Menu> |         </Menu> | ||||||
|       } |       } | ||||||
|     > |     > | ||||||
|  | @ -452,6 +523,9 @@ const Crontab = ({ headerStyle, isPhone }: any) => { | ||||||
|       case 'delete': |       case 'delete': | ||||||
|         delCron(record, index); |         delCron(record, index); | ||||||
|         break; |         break; | ||||||
|  |       case 'pinOrunPin': | ||||||
|  |         pinOrunPinCron(record, index); | ||||||
|  |         break; | ||||||
|       default: |       default: | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|  | @ -626,6 +700,20 @@ const Crontab = ({ headerStyle, isPhone }: any) => { | ||||||
|           <Button type="primary" onClick={() => operateCrons(3)}> |           <Button type="primary" onClick={() => operateCrons(3)}> | ||||||
|             批量停止 |             批量停止 | ||||||
|           </Button> |           </Button> | ||||||
|  |           <Button | ||||||
|  |             type="primary" | ||||||
|  |             onClick={() => operateCrons(4)} | ||||||
|  |             style={{ marginLeft: 8, marginRight: 8 }} | ||||||
|  |           > | ||||||
|  |             批量置顶 | ||||||
|  |           </Button> | ||||||
|  |           <Button | ||||||
|  |             type="primary" | ||||||
|  |             onClick={() => operateCrons(5)} | ||||||
|  |             style={{ marginLeft: 8, marginRight: 8 }} | ||||||
|  |           > | ||||||
|  |             批量取消置顶 | ||||||
|  |           </Button> | ||||||
|           <span style={{ marginLeft: 8 }}> |           <span style={{ marginLeft: 8 }}> | ||||||
|             已选择 |             已选择 | ||||||
|             <a>{selectedRowIds?.length}</a>项 |             <a>{selectedRowIds?.length}</a>项 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 hanhh
						hanhh