From 5a21247cbbcdb3cb3f5b00359cf1b3e7a207f822 Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 14 May 2022 19:21:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=96=B0=E5=BB=BA=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .umirc.ts | 1 + back/data/subscription.ts | 2 +- src/layouts/index.less | 1 + src/pages/crontab/detail.tsx | 10 ++- src/pages/crontab/logModal.tsx | 2 - src/pages/subscription/modal.tsx | 130 +++++++++++++++++++++++-------- tsconfig.json | 2 +- 7 files changed, 110 insertions(+), 38 deletions(-) diff --git a/.umirc.ts b/.umirc.ts index e8c58209..f8853dff 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -9,6 +9,7 @@ export default defineConfig({ type: 'none', }, fastRefresh: {}, + mfsu: {}, esbuild: {}, webpack5: {}, dynamicImport: { diff --git a/back/data/subscription.ts b/back/data/subscription.ts index 77683fe5..230ece4f 100644 --- a/back/data/subscription.ts +++ b/back/data/subscription.ts @@ -80,6 +80,6 @@ export const SubscriptionModel = sequelize.define( isDisabled: DataTypes.NUMBER, log_path: DataTypes.STRING, schedule_type: DataTypes.STRING, - alias: DataTypes.STRING, + alias: { type: DataTypes.STRING, unique: 'alias' }, }, ); diff --git a/src/layouts/index.less b/src/layouts/index.less index 61c87b01..bc72d6ed 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -11,6 +11,7 @@ .ant-modal-body { max-height: calc(85vh - 110px); + max-height: calc(85vh - var(--vh-offset, 110px)); overflow-y: auto; } diff --git a/src/pages/crontab/detail.tsx b/src/pages/crontab/detail.tsx index 93d82060..d5c571c3 100644 --- a/src/pages/crontab/detail.tsx +++ b/src/pages/crontab/detail.tsx @@ -41,6 +41,12 @@ const tabList = [ tab: '脚本', }, ]; +const LangMap: any = { + '.py': 'python', + '.js': 'javascript', + '.sh': 'shell', + '.ts': 'typescript', +}; interface LogItem { directory: string; @@ -87,9 +93,9 @@ const CronDetailModal = ({ )} /> ), - script: ( + script: scriptInfo.filename && ( { setType(e.target.value); + const _url = form.getFieldValue('url'); + const _branch = form.getFieldValue('branch'); + form.setFieldsValue({ + alias: formatAlias(_url, _branch, e.target.value), + }); + form.validateFields(['url']); }; const scheduleTypeChange = (e) => { @@ -62,6 +71,32 @@ const SubscriptionModal = ({ setPullType(e.target.value); }; + const onUrlChange = (e) => { + const _branch = form.getFieldValue('branch'); + form.setFieldsValue({ + alias: formatAlias(e.target.value, _branch), + }); + }; + + const onBranchChange = (e) => { + const _url = form.getFieldValue('url'); + form.setFieldsValue({ + alias: formatAlias(_url, e.target.value), + }); + }; + + const formatAlias = (_url: string, _branch: string, _type = type) => { + let _alias = ''; + const _regx = _type === 'file' ? fileUrlRegx : repoUrlRegx; + if (_regx.test(_url)) { + _alias = _url.match(_regx)![0].replaceAll('/', '_').replaceAll('.', '_'); + } + if (_branch) { + _alias = _alias + '_' + _branch; + } + return _alias; + }; + const IntervalSelect = ({ value, onChange, @@ -109,6 +144,7 @@ const SubscriptionModal = ({ ); }; + const PullOptions = ({ value, onChange, @@ -141,6 +177,9 @@ const SubscriptionModal = ({ useEffect(() => { form.resetFields(); + setType('public-repo'); + setScheduleType('crontab'); + setPullType('ssh-key'); }, [subscription, visible]); return ( @@ -171,13 +210,70 @@ const SubscriptionModal = ({ - - + + + 公开仓库 + 私有仓库 + 单个文件 + + + + + {type !== 'file' && ( + + + + )} + + + + {type === 'private-repo' && ( + <> + + + 私钥 + 用户名密码/Token + + + + + )} crontab @@ -210,13 +306,6 @@ const SubscriptionModal = ({ )} - - - 公开仓库 - 私有仓库 - 单个文件 - - {type !== 'file' && ( <> - {type === 'private-repo' && ( - <> - - - 私钥 - 用户名密码/Token - - - - - )} - - - )} diff --git a/tsconfig.json b/tsconfig.json index 06ab0637..c3266d56 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ "@/*": ["src/*"], "@@/*": ["src/.umi/*"] }, - "lib": ["dom", "es2017", "esnext.asynciterable"], + "lib": ["dom", "es2021", "esnext.asynciterable"], "typeRoots": [ "./node_modules/@types", "./back/types",