Просмотр исходного кода

修改表格名称为空不能调用问题

zyf 1 месяц назад
Родитель
Сommit
3cfcba3294
2 измененных файлов с 34 добавлено и 7 удалено
  1. 27 7
      src/components/App.tsx
  2. 7 0
      src/components/style.css

+ 27 - 7
src/components/App.tsx

@@ -76,6 +76,7 @@ function App() {
   const [error, setError] = useState<string>('');
   const [error, setError] = useState<string>('');
   const [customTableId, setCustomTableId] = useState<string>('');
   const [customTableId, setCustomTableId] = useState<string>('');
   const [customTableName, setCustomTableName] = useState<string>('');
   const [customTableName, setCustomTableName] = useState<string>('');
+  const [docInfoLoaded, setDocInfoLoaded] = useState<boolean>(false);
 
 
   const loadApiList = useCallback(async () => {
   const loadApiList = useCallback(async () => {
     try {
     try {
@@ -144,8 +145,11 @@ function App() {
   const loadDocumentInfo = useCallback(async () => {
   const loadDocumentInfo = useCallback(async () => {
     try {
     try {
       const info = await Dingdocs.script.runWithTimeout('getDocumentInfo', 120000);
       const info = await Dingdocs.script.runWithTimeout('getDocumentInfo', 120000);
-      setCustomTableId(info?.uuid || '');
-      setCustomTableName(info?.currentSheet || '');
+      if (info?.uuid) {
+        setCustomTableId(info.uuid);
+        setCustomTableName(info.currentSheet || '');
+        setDocInfoLoaded(true);
+      }
     } catch (error: any) {
     } catch (error: any) {
       console.error('获取文档信息失败:', error);
       console.error('获取文档信息失败:', error);
     }
     }
@@ -178,6 +182,12 @@ function App() {
   const handleCallApi = async () => {
   const handleCallApi = async () => {
     if (!currentApi || callLoading) return;
     if (!currentApi || callLoading) return;
     
     
+    const tableName = customTableName || currentApi.aiTablename;
+    if (!tableName) {
+      setResult('调用失败: 表格名称不能为空,请先选择或输入表格名称');
+      return;
+    }
+    
     setCallLoading(true);
     setCallLoading(true);
     setResult('');
     setResult('');
     
     
@@ -187,7 +197,7 @@ function App() {
     const apiItem = {
     const apiItem = {
       ...currentApi,
       ...currentApi,
       aiTableId: customTableId || currentApi.aiTableId,
       aiTableId: customTableId || currentApi.aiTableId,
-      aiTablename: customTableName || currentApi.aiTablename,
+      aiTablename: tableName,
       apiParamAuth: currentApi.apiParamAuth.map(p => ({
       apiParamAuth: currentApi.apiParamAuth.map(p => ({
         paramName: p.paramName,
         paramName: p.paramName,
         value: apiParams[p.paramName] || p.value || ''
         value: apiParams[p.paramName] || p.value || ''
@@ -196,12 +206,16 @@ function App() {
     
     
     try {
     try {
       const response: ApiResponse = await Dingdocs.script.runWithTimeout('callApi', 120000, apiItem, token, userInfo?.userId);
       const response: ApiResponse = await Dingdocs.script.runWithTimeout('callApi', 120000, apiItem, token, userInfo?.userId);
-      setResult(JSON.stringify(response, null, 2));
+      if (response.code === 200 || response.code === 0) {
+        setResult(JSON.stringify(response, null, 2));
+      } else {
+        setResult(`调用失败: ${response.msg || '未知错误'}`);
+      }
     } catch (error: any) {
     } catch (error: any) {
-      setResult(`调用失败: ${error.message}`);
-    } finally {
-      setCallLoading(false);
+      console.error('调用API失败:', error);
+      setResult(`调用失败: ${error?.message || '网络请求超时,请检查网络连接'}`);
     }
     }
+    setCallLoading(false);
   };
   };
 
 
   useEffect(() => {
   useEffect(() => {
@@ -313,7 +327,13 @@ function App() {
                     placeholder="请输入文档 ID"
                     placeholder="请输入文档 ID"
                     value={customTableId || ''}
                     value={customTableId || ''}
                     onChange={(e) => setCustomTableId(e.target.value)}
                     onChange={(e) => setCustomTableId(e.target.value)}
+                    disabled={docInfoLoaded}
                   />
                   />
+                  {docInfoLoaded && (
+                    <Typography.Text type="secondary" className="param-tip">
+                      已自动获取,不可修改
+                    </Typography.Text>
+                  )}
                 </div>
                 </div>
                 <div className="param-item">
                 <div className="param-item">
                   <Typography.Text className="param-label">
                   <Typography.Text className="param-label">

+ 7 - 0
src/components/style.css

@@ -112,6 +112,13 @@
   width: 100%;
   width: 100%;
 }
 }
 
 
+.param-tip {
+  display: block;
+  margin-top: 4px;
+  font-size: 12px;
+  color: #faad14;
+}
+
 .action-bar {
 .action-bar {
   display: flex;
   display: flex;
   justify-content: flex-start;
   justify-content: flex-start;