umi-request 替换为 axios

This commit is contained in:
whyour
2023-07-17 23:13:06 +08:00
parent bd166ee794
commit efd4f1d5ab
32 changed files with 215 additions and 214 deletions
+1 -3
View File
@@ -51,9 +51,7 @@ const Config = () => {
: value;
request
.post(`${config.apiPrefix}configs/save`, {
data: { content, name: select },
})
.post(`${config.apiPrefix}configs/save`, { content, name: select })
.then(({ code, data }) => {
if (code === 200) {
message.success('保存成功');
+7 -13
View File
@@ -184,11 +184,9 @@ const CronDetailModal = ({
return new Promise((resolve, reject) => {
request
.put(`${config.apiPrefix}scripts`, {
data: {
filename: scriptInfo.filename,
path: scriptInfo.parent || '',
content,
},
filename: scriptInfo.filename,
path: scriptInfo.parent || '',
content,
})
.then(({ code, data }) => {
if (code === 200) {
@@ -220,7 +218,7 @@ const CronDetailModal = ({
),
onOk() {
request
.put(`${config.apiPrefix}crons/run`, { data: [currentCron.id] })
.put(`${config.apiPrefix}crons/run`, [currentCron.id])
.then(({ code, data }) => {
if (code === 200) {
setCurrentCron({ ...currentCron, status: CrontabStatus.running });
@@ -250,7 +248,7 @@ const CronDetailModal = ({
),
onOk() {
request
.put(`${config.apiPrefix}crons/stop`, { data: [currentCron.id] })
.put(`${config.apiPrefix}crons/stop`, [currentCron.id] )
.then(({ code, data }) => {
if (code === 200) {
setCurrentCron({ ...currentCron, status: CrontabStatus.idle });
@@ -282,9 +280,7 @@ const CronDetailModal = ({
`${config.apiPrefix}crons/${
currentCron.isDisabled === 1 ? 'enable' : 'disable'
}`,
{
data: [currentCron.id],
},
[currentCron.id],
)
.then(({ code, data }) => {
if (code === 200) {
@@ -320,9 +316,7 @@ const CronDetailModal = ({
`${config.apiPrefix}crons/${
currentCron.isPinned === 1 ? 'unpin' : 'pin'
}`,
{
data: [currentCron.id],
},
[currentCron.id],
)
.then(({ code, data }) => {
if (code === 200) {
+8 -11
View File
@@ -457,7 +457,7 @@ const Crontab = () => {
),
onOk() {
request
.put(`${config.apiPrefix}crons/run`, { data: [record.id] })
.put(`${config.apiPrefix}crons/run`, [record.id])
.then(({ code, data }) => {
if (code === 200) {
const result = [...value];
@@ -492,7 +492,7 @@ const Crontab = () => {
),
onOk() {
request
.put(`${config.apiPrefix}crons/stop`, { data: [record.id] })
.put(`${config.apiPrefix}crons/stop`, [record.id])
.then(({ code, data }) => {
if (code === 200) {
const result = [...value];
@@ -533,9 +533,7 @@ const Crontab = () => {
`${config.apiPrefix}crons/${
record.isDisabled === 1 ? 'enable' : 'disable'
}`,
{
data: [record.id],
},
[record.id],
)
.then(({ code, data }) => {
if (code === 200) {
@@ -577,9 +575,7 @@ const Crontab = () => {
`${config.apiPrefix}crons/${
record.isPinned === 1 ? 'unpin' : 'pin'
}`,
{
data: [record.id],
},
[record.id],
)
.then(({ code, data }) => {
if (code === 200) {
@@ -725,9 +721,10 @@ const Crontab = () => {
content: <>{OperationName[operationStatus]}</>,
onOk() {
request
.put(`${config.apiPrefix}crons/${OperationPath[operationStatus]}`, {
data: selectedRowIds,
})
.put(
`${config.apiPrefix}crons/${OperationPath[operationStatus]}`,
selectedRowIds,
)
.then(({ code, data }) => {
if (code === 200) {
getCrons();
+5 -6
View File
@@ -25,9 +25,10 @@ const CronModal = ({
payload.id = cron.id;
}
try {
const { code, data } = await request[method](`${config.apiPrefix}crons`, {
data: payload,
});
const { code, data } = await request[method](
`${config.apiPrefix}crons`,
payload,
);
if (code === 200) {
message.success(cron ? '更新Cron成功' : '新建Cron成功');
@@ -130,9 +131,7 @@ const CronLabelModal = ({
try {
const { code, data } = await request[action](
`${config.apiPrefix}crons/labels`,
{
data: payload,
},
payload,
);
if (code === 200) {
+1 -3
View File
@@ -80,9 +80,7 @@ const ViewCreateModal = ({
try {
const { code, data } = await request[method](
`${config.apiPrefix}crons/views`,
{
data: view ? { ...values, id: view.id } : values,
},
view ? { ...values, id: view.id } : values,
);
if (code === 200) {
+6 -4
View File
@@ -168,9 +168,9 @@ const ViewManageModal = ({
const onShowChange = (checked: boolean, record: any, index: number) => {
request
.put(`${config.apiPrefix}crons/views/${checked ? 'enable' : 'disable'}`, {
data: [record.id],
})
.put(`${config.apiPrefix}crons/views/${checked ? 'enable' : 'disable'}`, [
record.id,
])
.then(({ code, data }) => {
if (code === 200) {
const _list = [...list];
@@ -195,7 +195,9 @@ const ViewManageModal = ({
const dragRow = list[dragIndex];
request
.put(`${config.apiPrefix}crons/views/move`, {
data: { fromIndex: dragIndex, toIndex: hoverIndex, id: dragRow.id },
fromIndex: dragIndex,
toIndex: hoverIndex,
id: dragRow.id,
})
.then(({ code, data }) => {
if (code === 200) {
+2 -6
View File
@@ -269,9 +269,7 @@ const Dependence = () => {
),
onOk() {
request
.put(`${config.apiPrefix}dependencies/reinstall`, {
data: [record.id],
})
.put(`${config.apiPrefix}dependencies/reinstall`, [record.id])
.then(({ code, data }) => {
if (code === 200) {
handleDependence(data[0]);
@@ -342,9 +340,7 @@ const Dependence = () => {
content: <></>,
onOk() {
request
.put(`${config.apiPrefix}dependencies/reinstall`, {
data: selectedRowIds,
})
.put(`${config.apiPrefix}dependencies/reinstall`, selectedRowIds)
.then(({ code, data }) => {
if (code === 200) {
setSelectedRowIds([]);
+6 -4
View File
@@ -48,9 +48,7 @@ const DependenceModal = ({
try {
const { code, data } = await request[method](
`${config.apiPrefix}dependencies`,
{
data: payload,
},
payload,
);
if (code === 200) {
@@ -122,7 +120,11 @@ const DependenceModal = ({
name="name"
label="名称"
rules={[
{ required: true, message: '请输入依赖名称,支持指定版本', whitespace: true },
{
required: true,
message: '请输入依赖名称,支持指定版本',
whitespace: true,
},
]}
>
<Input.TextArea
+2 -1
View File
@@ -48,7 +48,8 @@ const Diff = () => {
request
.post(`${config.apiPrefix}configs/save`, {
data: { content, name: current },
content,
name: current,
})
.then(({ code, data }) => {
if (code === 200) {
+2 -4
View File
@@ -19,10 +19,8 @@ const EditNameModal = ({
setLoading(true);
try {
const { code, data } = await request.put(`${config.apiPrefix}envs/name`, {
data: {
ids,
name: values.name,
},
ids,
name: values.name,
});
if (code === 200) {
+8 -10
View File
@@ -248,9 +248,7 @@ const Env = () => {
`${config.apiPrefix}envs/${
record.status === Status. ? 'enable' : 'disable'
}`,
{
data: [record.id],
},
[record.id],
)
.then(({ code, data }) => {
if (code === 200) {
@@ -388,7 +386,8 @@ const Env = () => {
const dragRow = value[dragIndex];
request
.put(`${config.apiPrefix}envs/${dragRow.id}/move`, {
data: { fromIndex: dragIndex, toIndex: hoverIndex },
fromIndex: dragIndex,
toIndex: hoverIndex,
})
.then(({ code, data }) => {
if (code === 200) {
@@ -438,9 +437,10 @@ const Env = () => {
content: <>{OperationName[operationStatus]}</>,
onOk() {
request
.put(`${config.apiPrefix}envs/${OperationPath[operationStatus]}`, {
data: selectedRowIds,
})
.put(
`${config.apiPrefix}envs/${OperationPath[operationStatus]}`,
selectedRowIds,
)
.then(({ code, data }) => {
if (code === 200) {
getEnvs();
@@ -477,9 +477,7 @@ const Env = () => {
try {
const { code, data } = await request.post(
`${config.apiPrefix}envs/upload`,
{
data: formData,
},
formData,
);
if (code === 200) {
+4 -3
View File
@@ -37,9 +37,10 @@ const EnvModal = ({
payload = { ...values, id: env.id };
}
try {
const { code, data } = await request[method](`${config.apiPrefix}envs`, {
data: payload,
});
const { code, data } = await request[method](
`${config.apiPrefix}envs`,
payload,
);
if (code === 200) {
message.success(env ? '更新变量成功' : '新建变量成功');
+3 -7
View File
@@ -36,10 +36,8 @@ const Initialization = () => {
setLoading(true);
request
.put(`${config.apiPrefix}user/init`, {
data: {
username: values.username,
password: values.password,
},
username: values.username,
password: values.password,
})
.then(({ code, data }) => {
if (code === 200) {
@@ -53,9 +51,7 @@ const Initialization = () => {
setLoading(true);
request
.put(`${config.apiPrefix}user/notification/init`, {
data: {
...values,
},
values,
})
.then(({ code, data }) => {
if (code === 200) {
+4 -5
View File
@@ -35,10 +35,8 @@ const Login = () => {
setWaitTime(null);
request
.post(`${config.apiPrefix}user/login`, {
data: {
username: values.username,
password: values.password,
},
username: values.username,
password: values.password,
})
.then((data) => {
checkResponse(data, values);
@@ -54,7 +52,8 @@ const Login = () => {
setVerifying(true);
request
.put(`${config.apiPrefix}user/two-factor/login`, {
data: { ...loginInfo, code: values.code },
...loginInfo,
code: values.code,
})
.then((data: any) => {
checkResponse(data);
+6 -10
View File
@@ -86,11 +86,9 @@ const EditModal = ({
const content = editorRef.current.getValue().replace(/\r\n/g, '\n');
request
.put(`${config.apiPrefix}scripts/run`, {
data: {
filename: cNode.title,
path: cNode.parent || '',
content,
},
filename: cNode.title,
path: cNode.parent || '',
content,
})
.then(({ code, data }) => {
if (code === 200) {
@@ -106,11 +104,9 @@ const EditModal = ({
}
request
.put(`${config.apiPrefix}scripts/stop`, {
data: {
filename: cNode.title,
path: cNode.parent || '',
pid: currentPid,
},
filename: cNode.title,
path: cNode.parent || '',
pid: currentPid,
})
.then(({ code, data }) => {
if (code === 200) {
+1 -3
View File
@@ -44,9 +44,7 @@ const EditScriptNameModal = ({
formData.append('content', '');
formData.append('directory', directory);
request
.post(`${config.apiPrefix}scripts`, {
data: formData,
})
.post(`${config.apiPrefix}scripts`, formData)
.then(({ code, data }) => {
if (code === 200) {
message.success(directory ? '新建文件夹成功' : '新建文件成功');
+4 -8
View File
@@ -223,11 +223,9 @@ const Script = () => {
return new Promise((resolve, reject) => {
request
.put(`${config.apiPrefix}scripts`, {
data: {
filename: currentNode.title,
path: currentNode.parent || '',
content,
},
filename: currentNode.title,
path: currentNode.parent || '',
content,
})
.then(({ code, data }) => {
if (code === 200) {
@@ -341,9 +339,7 @@ const Script = () => {
const downloadFile = () => {
request
.post(`${config.apiPrefix}scripts/download`, {
data: {
filename: currentNode.title,
},
filename: currentNode.title,
})
.then(({ code, data }) => {
if (code === 200) {
+3 -5
View File
@@ -21,11 +21,9 @@ const RenameModal = ({
const { code, data } = await request.put(
`${config.apiPrefix}scripts/rename`,
{
data: {
filename: currentNode.title,
path: currentNode.parent || '',
newFilename: values.name,
},
filename: currentNode.title,
path: currentNode.parent || '',
newFilename: values.name,
},
);
+1 -3
View File
@@ -19,9 +19,7 @@ const SaveModal = ({
setLoading(true);
const payload = { ...file, ...values, originFilename: file.title };
request
.post(`${config.apiPrefix}scripts`, {
data: payload,
})
.post(`${config.apiPrefix}scripts`, payload)
.then(({ code, data }) => {
if (code === 200) {
message.success('保存文件成功');
+1 -3
View File
@@ -19,9 +19,7 @@ const SettingModal = ({
setLoading(true);
const payload = { ...file, ...values };
request
.post(`${config.apiPrefix}scripts`, {
data: payload,
})
.post(`${config.apiPrefix}scripts`, payload)
.then(({ code, data }) => {
if (code === 200) {
message.success('保存文件成功');
+4 -3
View File
@@ -23,9 +23,10 @@ const AppModal = ({
payload.id = app.id;
}
try {
const { code, data } = await request[method](`${config.apiPrefix}apps`, {
data: payload,
});
const { code, data } = await request[method](
`${config.apiPrefix}apps`,
payload,
);
if (code === 200) {
message.success(app ? '更新应用成功' : '新建应用成功');
+1 -1
View File
@@ -129,7 +129,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
okText: '重启',
onOk() {
request
.put(`${config.apiPrefix}system/reload`, { data: { type: 'system' } })
.put(`${config.apiPrefix}system/reload`, { type: 'system' })
.then((_data: any) => {
message.success({
content: (
+1 -3
View File
@@ -20,9 +20,7 @@ const NotificationSetting = ({ data }: any) => {
request
.put(`${config.apiPrefix}user/notification`, {
data: {
...values,
},
values,
})
.then(({ code, data }) => {
if (code === 200) {
+19 -36
View File
@@ -19,6 +19,7 @@ import { saveAs } from 'file-saver';
import './index.less';
import { UploadOutlined } from '@ant-design/icons';
import Countdown from 'antd/lib/statistic/Countdown';
import useProgress from './progress';
const optionsWithDisabled = [
{ label: '亮色', value: 'light' },
@@ -39,6 +40,8 @@ const Other = ({
const [form] = Form.useForm();
const modalRef = useRef<any>();
const [exportLoading, setExportLoading] = useState(false);
const showUploadProgress = useProgress('上传');
const showDownloadProgress = useProgress('下载');
const {
enable: enableDarkMode,
@@ -78,9 +81,7 @@ const Other = ({
const updateSystemConfig = () => {
request
.put(`${config.apiPrefix}system/config`, {
data: { ...systemConfig },
})
.put(`${config.apiPrefix}system/config`, systemConfig)
.then(({ code, data }) => {
if (code === 200) {
message.success('更新成功');
@@ -94,7 +95,18 @@ const Other = ({
const exportData = () => {
setExportLoading(true);
request
.put(`${config.apiPrefix}system/data/export`, { responseType: 'blob' })
.put<Blob>(
`${config.apiPrefix}system/data/export`,
{},
{
responseType: 'blob',
onDownloadProgress: (e) => {
if (e.progress) {
showDownloadProgress(parseFloat((e.progress * 100).toFixed(1)));
}
},
},
)
.then((res) => {
saveAs(res, 'data.tgz');
})
@@ -104,34 +116,6 @@ const Other = ({
.finally(() => setExportLoading(false));
};
const showUploadModal = (progress: number) => {
if (modalRef.current) {
modalRef.current.update({
content: (
<Progress
style={{ display: 'flex', justifyContent: 'center' }}
type="circle"
percent={progress}
/>
),
});
} else {
modalRef.current = Modal.info({
width: 600,
maskClosable: false,
title: '上传中...',
centered: true,
content: (
<Progress
style={{ display: 'flex', justifyContent: 'center' }}
type="circle"
percent={progress}
/>
),
});
}
};
const showReloadModal = () => {
Modal.confirm({
width: 600,
@@ -142,8 +126,8 @@ const Other = ({
okText: '重启',
onOk() {
request
.put(`${config.apiPrefix}system/reload`, { data: { type: 'data' } })
.then((_data: any) => {
.put(`${config.apiPrefix}system/reload`, { type: 'data' })
.then(() => {
message.success({
content: (
<span>
@@ -231,8 +215,7 @@ const Other = ({
action="/api/system/data/import"
onChange={(e) => {
if (e.event?.percent) {
const percent = parseFloat(e.event?.percent.toFixed(1));
showUploadModal(percent);
showUploadProgress(parseFloat(e.event?.percent.toFixed(1)));
if (e.event?.percent === 100) {
showReloadModal();
}
+33
View File
@@ -0,0 +1,33 @@
import { Modal, Progress } from 'antd';
import { useRef } from 'react';
export default function useProgress(title: string) {
const modalRef = useRef<ReturnType<typeof Modal.info>>();
const ProgressElement = ({ percent }: { percent: number }) => (
<Progress
style={{ display: 'flex', justifyContent: 'center' }}
type="circle"
percent={percent}
/>
);
const showProgress = (percent: number) => {
if (modalRef.current) {
modalRef.current.update({
title: `${title}${percent >= 100 ? '成功' : '中...'}`,
content: <ProgressElement percent={percent} />,
});
} else {
modalRef.current = Modal.info({
width: 600,
maskClosable: false,
title: `${title}${percent >= 100 ? '成功' : '中...'}`,
centered: true,
content: <ProgressElement percent={percent} />,
});
}
};
return showProgress;
}
+3 -5
View File
@@ -22,10 +22,8 @@ const SecuritySettings = ({ user, userChange }: any) => {
const handleOk = (values: any) => {
request
.put(`${config.apiPrefix}user`, {
data: {
username: values.username,
password: values.password,
},
username: values.username,
password: values.password,
})
.then(({ code, data }) => {
if (code === 200) {
@@ -64,7 +62,7 @@ const SecuritySettings = ({ user, userChange }: any) => {
const completeTowFactor = () => {
setLoading(true);
request
.put(`${config.apiPrefix}user/two-factor/active`, { data: { code } })
.put(`${config.apiPrefix}user/two-factor/active`, { code })
.then(({ code, data }) => {
if (code === 200) {
if (data) {
+3 -5
View File
@@ -254,7 +254,7 @@ const Subscription = () => {
),
onOk() {
request
.put(`${config.apiPrefix}subscriptions/run`, { data: [record.id] })
.put(`${config.apiPrefix}subscriptions/run`, [record.id])
.then(({ code, data }) => {
if (code === 200) {
const result = [...value];
@@ -289,7 +289,7 @@ const Subscription = () => {
),
onOk() {
request
.put(`${config.apiPrefix}subscriptions/stop`, { data: [record.id] })
.put(`${config.apiPrefix}subscriptions/stop`, [record.id])
.then(({ code, data }) => {
if (code === 200) {
const result = [...value];
@@ -386,9 +386,7 @@ const Subscription = () => {
`${config.apiPrefix}subscriptions/${
record.is_disabled === 1 ? 'enable' : 'disable'
}`,
{
data: [record.id],
},
[record.id],
)
.then(({ code, data }) => {
if (code === 200) {
+1 -3
View File
@@ -47,9 +47,7 @@ const SubscriptionModal = ({
try {
const { code, data } = await request[method](
`${config.apiPrefix}subscriptions`,
{
data: payload,
},
payload,
);
if (code === 200) {
message.success(subscription ? '更新订阅成功' : '新建订阅成功');