完善新建订阅页面

This commit is contained in:
whyour 2022-05-14 19:21:24 +08:00
parent 419c5a7c5b
commit 5a21247cbb
7 changed files with 110 additions and 38 deletions

View File

@ -9,6 +9,7 @@ export default defineConfig({
type: 'none', type: 'none',
}, },
fastRefresh: {}, fastRefresh: {},
mfsu: {},
esbuild: {}, esbuild: {},
webpack5: {}, webpack5: {},
dynamicImport: { dynamicImport: {

View File

@ -80,6 +80,6 @@ export const SubscriptionModel = sequelize.define<SubscriptionInstance>(
isDisabled: DataTypes.NUMBER, isDisabled: DataTypes.NUMBER,
log_path: DataTypes.STRING, log_path: DataTypes.STRING,
schedule_type: DataTypes.STRING, schedule_type: DataTypes.STRING,
alias: DataTypes.STRING, alias: { type: DataTypes.STRING, unique: 'alias' },
}, },
); );

View File

@ -11,6 +11,7 @@
.ant-modal-body { .ant-modal-body {
max-height: calc(85vh - 110px); max-height: calc(85vh - 110px);
max-height: calc(85vh - var(--vh-offset, 110px));
overflow-y: auto; overflow-y: auto;
} }

View File

@ -41,6 +41,12 @@ const tabList = [
tab: '脚本', tab: '脚本',
}, },
]; ];
const LangMap: any = {
'.py': 'python',
'.js': 'javascript',
'.sh': 'shell',
'.ts': 'typescript',
};
interface LogItem { interface LogItem {
directory: string; directory: string;
@ -87,9 +93,9 @@ const CronDetailModal = ({
)} )}
/> />
), ),
script: ( script: scriptInfo.filename && (
<Editor <Editor
language="shell" language={LangMap[scriptInfo.filename.slice(-3)] || ''}
theme={theme} theme={theme}
value={value} value={value}
options={{ options={{

View File

@ -123,8 +123,6 @@ const CronLogModal = ({
centered centered
className="log-modal" className="log-modal"
bodyStyle={{ bodyStyle={{
overflowY: 'auto',
maxHeight: 'calc(80vh - var(--vh-offset, 0px))',
minHeight: '300px', minHeight: '300px',
}} }}
forceRender forceRender

View File

@ -6,6 +6,9 @@ import cron_parser from 'cron-parser';
import EditableTagGroup from '@/components/tag'; import EditableTagGroup from '@/components/tag';
const { Option } = Select; const { Option } = Select;
const repoUrlRegx = /[^\/\:]+\/[^\/]+(?=\.git)/;
const fileUrlRegx = /[^\/\:]+\/[^\/]+$/;
const SubscriptionModal = ({ const SubscriptionModal = ({
subscription, subscription,
handleCancel, handleCancel,
@ -51,6 +54,12 @@ const SubscriptionModal = ({
const typeChange = (e) => { const typeChange = (e) => {
setType(e.target.value); 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) => { const scheduleTypeChange = (e) => {
@ -62,6 +71,32 @@ const SubscriptionModal = ({
setPullType(e.target.value); 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 = ({ const IntervalSelect = ({
value, value,
onChange, onChange,
@ -109,6 +144,7 @@ const SubscriptionModal = ({
</Input.Group> </Input.Group>
); );
}; };
const PullOptions = ({ const PullOptions = ({
value, value,
onChange, onChange,
@ -141,6 +177,9 @@ const SubscriptionModal = ({
useEffect(() => { useEffect(() => {
form.resetFields(); form.resetFields();
setType('public-repo');
setScheduleType('crontab');
setPullType('ssh-key');
}, [subscription, visible]); }, [subscription, visible]);
return ( return (
@ -171,13 +210,70 @@ const SubscriptionModal = ({
<Form.Item name="name" label="别名"> <Form.Item name="name" label="别名">
<Input placeholder="请输入订阅别名" /> <Input placeholder="请输入订阅别名" />
</Form.Item> </Form.Item>
<Form.Item name="url" label="链接" rules={[{ required: true }]}> <Form.Item
<Input placeholder="请输入订阅链接" /> name="type"
label="类型"
rules={[{ required: true }]}
initialValue={'public-repo'}
>
<Radio.Group onChange={typeChange}>
<Radio value="public-repo"></Radio>
<Radio value="private-repo"></Radio>
<Radio value="file"></Radio>
</Radio.Group>
</Form.Item> </Form.Item>
<Form.Item
name="url"
label="链接"
rules={[
{ required: true },
{ pattern: type === 'file' ? fileUrlRegx : repoUrlRegx },
]}
>
<Input
placeholder="请输入订阅链接"
onPaste={onUrlChange}
onChange={onUrlChange}
/>
</Form.Item>
{type !== 'file' && (
<Form.Item name="branch" label="分支">
<Input
placeholder="请输入分支"
onPaste={onBranchChange}
onChange={onBranchChange}
/>
</Form.Item>
)}
<Form.Item
name="alias"
label="唯一值"
rules={[{ required: true, message: '' }]}
tooltip="唯一值用于日志目录和私钥别名"
>
<Input placeholder="自动生成" disabled />
</Form.Item>
{type === 'private-repo' && (
<>
<Form.Item
name="pull_type"
label="拉取方式"
initialValue={'ssh-key'}
rules={[{ required: true }]}
>
<Radio.Group onChange={pullTypeChange}>
<Radio value="ssh-key"></Radio>
<Radio value="user-pwd">/Token</Radio>
</Radio.Group>
</Form.Item>
<PullOptions type={pullType} />
</>
)}
<Form.Item <Form.Item
name="schedule_type" name="schedule_type"
label="定时类型" label="定时类型"
initialValue={'crontab'} initialValue={'crontab'}
rules={[{ required: true }]}
> >
<Radio.Group onChange={scheduleTypeChange}> <Radio.Group onChange={scheduleTypeChange}>
<Radio value="crontab">crontab</Radio> <Radio value="crontab">crontab</Radio>
@ -210,13 +306,6 @@ const SubscriptionModal = ({
<Input placeholder="秒(可选) 分 时 天 月 周" /> <Input placeholder="秒(可选) 分 时 天 月 周" />
)} )}
</Form.Item> </Form.Item>
<Form.Item name="type" label="类型" initialValue={'public-repo'}>
<Radio.Group onChange={typeChange}>
<Radio value="public-repo"></Radio>
<Radio value="private-repo"></Radio>
<Radio value="file"></Radio>
</Radio.Group>
</Form.Item>
{type !== 'file' && ( {type !== 'file' && (
<> <>
<Form.Item <Form.Item
@ -255,29 +344,6 @@ const SubscriptionModal = ({
placeholder="请输入脚本依赖文件关键词,多个关键词竖线分割" placeholder="请输入脚本依赖文件关键词,多个关键词竖线分割"
/> />
</Form.Item> </Form.Item>
{type === 'private-repo' && (
<>
<Form.Item
name="pull_type"
label="拉取方式"
initialValue={'ssh-key'}
>
<Radio.Group onChange={pullTypeChange}>
<Radio value="ssh-key"></Radio>
<Radio value="user-pwd">/Token</Radio>
</Radio.Group>
</Form.Item>
<PullOptions type={pullType} />
</>
)}
<Form.Item
name="alias"
label="唯一值"
rules={[{ required: true }]}
tooltip="唯一值用于日志目录和私钥别名"
>
<Input placeholder="自动生成" disabled />
</Form.Item>
</> </>
)} )}
</Form> </Form>

View File

@ -13,7 +13,7 @@
"@/*": ["src/*"], "@/*": ["src/*"],
"@@/*": ["src/.umi/*"] "@@/*": ["src/.umi/*"]
}, },
"lib": ["dom", "es2017", "esnext.asynciterable"], "lib": ["dom", "es2021", "esnext.asynciterable"],
"typeRoots": [ "typeRoots": [
"./node_modules/@types", "./node_modules/@types",
"./back/types", "./back/types",