mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-17 17:54:32 +08:00
初始化api
This commit is contained in:
@@ -14,9 +14,12 @@ const Crontab = () => {
|
||||
|
||||
const getConfig = () => {
|
||||
setLoading(true);
|
||||
request.get(`${config.apiPrefix}config/shareCode`).then((data) => {
|
||||
setValue(data);
|
||||
}).finally(() => setLoading(false));
|
||||
request
|
||||
.get(`${config.apiPrefix}config/shareCode`)
|
||||
.then((data) => {
|
||||
setValue(data.content);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
|
||||
const updateConfig = () => {
|
||||
|
||||
@@ -15,9 +15,12 @@ const Config = () => {
|
||||
|
||||
const getConfig = () => {
|
||||
setLoading(true);
|
||||
request.get(`${config.apiPrefix}config/config`).then((data) => {
|
||||
setValue(data);
|
||||
}).finally(() => setLoading(false));
|
||||
request
|
||||
.get(`${config.apiPrefix}config/config`)
|
||||
.then((data) => {
|
||||
setValue(data.content);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
|
||||
const updateConfig = () => {
|
||||
|
||||
@@ -25,9 +25,7 @@ const columns = [
|
||||
title: '状态',
|
||||
key: 'status',
|
||||
dataIndex: 'status',
|
||||
render: (text: string, record: any) => (
|
||||
<Tag color="success">success</Tag>
|
||||
),
|
||||
render: (text: string, record: any) => <Tag color="success">success</Tag>,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
@@ -74,9 +72,12 @@ const Config = () => {
|
||||
|
||||
const getConfig = () => {
|
||||
setLoading(true);
|
||||
request.get(`${config.apiPrefix}config/config`).then((data) => {
|
||||
setValue(data);
|
||||
}).finally(() => setLoading(false));
|
||||
request
|
||||
.get(`${config.apiPrefix}config/config`)
|
||||
.then((data) => {
|
||||
setValue(data.content);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
|
||||
const updateConfig = () => {
|
||||
@@ -182,7 +183,11 @@ const Config = () => {
|
||||
height: '100vh',
|
||||
}}
|
||||
>
|
||||
<Table columns={columns} pagination={{hideOnSinglePage: true}} dataSource={data} />
|
||||
<Table
|
||||
columns={columns}
|
||||
pagination={{ hideOnSinglePage: true }}
|
||||
dataSource={data}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -14,9 +14,12 @@ const Crontab = () => {
|
||||
|
||||
const getConfig = () => {
|
||||
setLoading(true);
|
||||
request.get(`${config.apiPrefix}config/crontab`).then((data) => {
|
||||
setValue(data);
|
||||
}).finally(() => setLoading(false));
|
||||
request
|
||||
.get(`${config.apiPrefix}config/crontab`)
|
||||
.then((data) => {
|
||||
setValue(data.content);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
|
||||
const updateConfig = () => {
|
||||
|
||||
+20
-14
@@ -16,15 +16,18 @@ const Crontab = () => {
|
||||
|
||||
const getConfig = () => {
|
||||
request.get(`${config.apiPrefix}config/config`).then((data) => {
|
||||
setValue(data);
|
||||
setValue(data.content);
|
||||
});
|
||||
};
|
||||
|
||||
const getSample = () => {
|
||||
setLoading(true);
|
||||
request.get(`${config.apiPrefix}config/sample`).then((data) => {
|
||||
setSample(data);
|
||||
}).finally(() => setLoading(false));
|
||||
request
|
||||
.get(`${config.apiPrefix}config/sample`)
|
||||
.then((data) => {
|
||||
setSample(data.content);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -63,16 +66,19 @@ const Crontab = () => {
|
||||
}}
|
||||
>
|
||||
<ReactDiffViewer
|
||||
styles={{ diffRemoved: {
|
||||
overflowX: 'auto',
|
||||
maxWidth: 300,
|
||||
},
|
||||
diffAdded: {
|
||||
overflowX: 'auto',
|
||||
maxWidth: 300,
|
||||
},line: {
|
||||
wordBreak: 'break-word',
|
||||
}, }}
|
||||
styles={{
|
||||
diffRemoved: {
|
||||
overflowX: 'auto',
|
||||
maxWidth: 300,
|
||||
},
|
||||
diffAdded: {
|
||||
overflowX: 'auto',
|
||||
maxWidth: 300,
|
||||
},
|
||||
line: {
|
||||
wordBreak: 'break-word',
|
||||
},
|
||||
}}
|
||||
oldValue={value}
|
||||
newValue={sample}
|
||||
splitView={true}
|
||||
|
||||
@@ -14,9 +14,12 @@ const Crontab = () => {
|
||||
|
||||
const getConfig = () => {
|
||||
setLoading(true);
|
||||
request.get(`${config.apiPrefix}config/diy`).then((data) => {
|
||||
setValue(data);
|
||||
}).finally(() => setLoading(false));
|
||||
request
|
||||
.get(`${config.apiPrefix}config/diy`)
|
||||
.then((data) => {
|
||||
setValue(data.content);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
|
||||
const updateConfig = () => {
|
||||
|
||||
@@ -18,7 +18,7 @@ const Login = () => {
|
||||
})
|
||||
.then((data) => {
|
||||
if (data.err == 0) {
|
||||
localStorage.setItem(config.authKey, 'true');
|
||||
localStorage.setItem(config.authKey, data.token);
|
||||
history.push('/cookie');
|
||||
} else {
|
||||
notification.open({
|
||||
@@ -36,7 +36,7 @@ const Login = () => {
|
||||
if (isAuth) {
|
||||
history.push('/cookie');
|
||||
}
|
||||
}, [])
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
@@ -50,7 +50,7 @@ const Login = () => {
|
||||
rules={[{ required: true, message: '请输入用户名' }]}
|
||||
hasFeedback
|
||||
>
|
||||
<Input placeholder="用户名" autoFocus/>
|
||||
<Input placeholder="用户名" autoFocus />
|
||||
</FormItem>
|
||||
<FormItem
|
||||
name="password"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
export default {
|
||||
siteName: '京东羊毛脚本控制面板',
|
||||
apiPrefix: '/api/',
|
||||
authKey: 'whyour',
|
||||
authKey: 'token',
|
||||
|
||||
/* Layout configuration, specify which layout to use for route. */
|
||||
layouts: [
|
||||
|
||||
+17
-7
@@ -1,29 +1,39 @@
|
||||
import { extend } from 'umi-request';
|
||||
import { history } from 'umi';
|
||||
import config from './config';
|
||||
|
||||
const time = Date.now();
|
||||
const errorHandler = function (error: any) {
|
||||
if (error.response) {
|
||||
console.log(error.response)
|
||||
console.log(error.response);
|
||||
} else {
|
||||
console.log(error.message);
|
||||
}
|
||||
|
||||
throw error; // 如果throw. 错误将继续抛出.
|
||||
// return {some: 'data'};
|
||||
};
|
||||
|
||||
const _request = extend({ timeout: 5000, params: { t: time }, errorHandler });
|
||||
|
||||
_request.interceptors.response.use(async response => {
|
||||
const res = await response.clone().text()
|
||||
if (res === '请先登录!') {
|
||||
_request.interceptors.request.use((url, options) => {
|
||||
const token = localStorage.getItem(config.authKey);
|
||||
if (token) {
|
||||
const headers = {
|
||||
Authorization: `Bearer ${token}`,
|
||||
};
|
||||
return { url, options: { ...options, headers } };
|
||||
}
|
||||
return { url, options };
|
||||
});
|
||||
|
||||
_request.interceptors.response.use(async (response) => {
|
||||
const res = await response.clone();
|
||||
if (res.status === 401) {
|
||||
setTimeout(() => {
|
||||
localStorage.removeItem('whyour');
|
||||
history.push('/login');
|
||||
});
|
||||
}
|
||||
return response;
|
||||
})
|
||||
});
|
||||
|
||||
export const request = _request;
|
||||
|
||||
Reference in New Issue
Block a user