|
|
@@ -27,6 +27,7 @@ export function ApiTester() {
|
|
|
const [apiKey, setApiKey] = useState('excel2json-api-key');
|
|
|
const [selectedTemplateId, setSelectedTemplateId] = useState<number | undefined>(undefined);
|
|
|
const [uploadedInput, setUploadedInput] = useState('');
|
|
|
+ const [fileUrl, setFileUrl] = useState('');
|
|
|
|
|
|
// 在组件挂载时获取当前网站的完整域名
|
|
|
useEffect(() => {
|
|
|
@@ -49,12 +50,18 @@ export function ApiTester() {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 处理文件上传并生成Base64
|
|
|
- const handleBase64Generated = (base64: string) => {
|
|
|
- setUploadedInput(base64);
|
|
|
+ // 处理文件上传或URL输入
|
|
|
+ const handleInputChange = (input: string, isUrl = false) => {
|
|
|
+ if (isUrl) {
|
|
|
+ setFileUrl(input);
|
|
|
+ setUploadedInput(input);
|
|
|
+ } else {
|
|
|
+ setUploadedInput(input);
|
|
|
+ setFileUrl('');
|
|
|
+ }
|
|
|
try {
|
|
|
const currentBody = JSON.parse(requestBody);
|
|
|
- currentBody.input = base64;
|
|
|
+ currentBody.input = input;
|
|
|
setRequestBody(JSON.stringify(currentBody, null, 2));
|
|
|
} catch (error) {
|
|
|
console.error('解析请求体失败', error);
|
|
|
@@ -109,8 +116,8 @@ export function ApiTester() {
|
|
|
type="info"
|
|
|
message="API调用必须同时提供模板ID和Excel文件数据"
|
|
|
description="请确保已选择模板并上传了Excel文件或提供了有效的Excel文件URL"
|
|
|
- showIcon
|
|
|
style={{ marginBottom: '16px' }}
|
|
|
+ showIcon
|
|
|
/>
|
|
|
|
|
|
<Form layout="vertical">
|
|
|
@@ -144,12 +151,21 @@ export function ApiTester() {
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
|
|
|
- <Form.Item
|
|
|
- label={<Text strong>上传Excel文件 (必填)</Text>}
|
|
|
+ <Form.Item
|
|
|
+ label={<Text strong>Excel文件 (必填)</Text>}
|
|
|
required
|
|
|
help="上传Excel文件或提供文件URL"
|
|
|
>
|
|
|
- <ApiTesterFileUpload onBase64Generated={handleBase64Generated} />
|
|
|
+ <div className="space-y-2">
|
|
|
+ <ApiTesterFileUpload onBase64Generated={(base64) => handleInputChange(base64)} />
|
|
|
+ <Divider plain>或</Divider>
|
|
|
+ <Input
|
|
|
+ placeholder="输入Excel文件URL"
|
|
|
+ value={fileUrl}
|
|
|
+ onChange={(e) => handleInputChange(e.target.value, true)}
|
|
|
+ prefix={<FileExcelOutlined />}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
</Form.Item>
|
|
|
</div>
|
|
|
|