Browse Source

feat:优化API定义的编辑页面

microrain 5 months ago
parent
commit
e29ebb9ba2
2 changed files with 48 additions and 4 deletions
  1. 3 1
      src/views/apihub/apilist.vue
  2. 45 3
      src/views/apihub/component/edit.vue

+ 3 - 1
src/views/apihub/apilist.vue

@@ -115,7 +115,7 @@
 <!--              <span v-else>{{ scope.row.sqlType }}</span>-->
 <!--            </template>-->
 <!--          </el-table-column>-->
-          <el-table-column prop="version" label="版本" width="80" align="center"></el-table-column>
+<!--          <el-table-column prop="version" label="版本" width="80" align="center"></el-table-column>-->
           <el-table-column prop="description" label="描述" width="140" />
 
           <el-table-column prop="status" label="状态" width="100" align="center">
@@ -186,6 +186,7 @@ interface ApiDefinition {
   returnFormat: string;
   version: string;
   status: string;
+  private: string;
   plugins?: any[];
   description?: string;
   createdAt?: string;
@@ -220,6 +221,7 @@ const { params, tableData, getList, loading } = useSearch<ApiDefinition[]>(api.l
   keyWord: "",
   dataSourceKey: "",
   status: "",
+  private: "-1",
   dateRange: [],
   orderBy: "",
 });

+ 45 - 3
src/views/apihub/component/edit.vue

@@ -64,9 +64,9 @@
             <el-form-item label="所属分组" prop="groupKey">
               <el-cascader v-model="formData.groupKey" :options="groupOptions" :props="{ checkStrictly: true, emitPath: false, value: 'GroupKey', label: 'Name', children: 'Children' }" placeholder="请选择所属分组" clearable style="width: 100%" />
             </el-form-item>
-            <el-form-item label="版本" prop="version">
+            <!-- <el-form-item label="版本" prop="version">
               <el-input v-model="formData.version" placeholder="请输入版本号,如1.0" />
-            </el-form-item>
+            </el-form-item> -->
             <!-- <el-form-item label="状态" prop="status">
               <el-select v-model="formData.status" placeholder="请选择状态">
                 <el-option label="草稿" value="Draft"></el-option>
@@ -622,8 +622,50 @@ const open = async (row?: any, defaultGroupKey?: string) => {
       // 如果是编辑模式,需要先获取详情
       // 实际使用时,可能需要先调用API获取完整数据
       // 这里模拟直接使用传入的行数据
+      const rowData = JSON.parse(JSON.stringify(row));
+      
+      // 打印原始数据,查看后端返回的字段结构
+      console.log('编辑模式下原始数据:', rowData);
+      
+      // 处理字段名称的映射,确保前端和后端字段名称一致
+      // 处理 ContentType 字段(可能后端是 ContentType,前端是 contentType)
+      if (rowData.ContentType !== undefined && rowData.contentType === undefined) {
+        rowData.contentType = rowData.ContentType;
+        console.log('映射 ContentType -> contentType:', rowData.contentType);
+      }
+      
+      // 处理 Example 字段(可能后端是 Example,前端是 example)
+      if (rowData.Example !== undefined && rowData.example === undefined) {
+        rowData.example = rowData.Example;
+        console.log('映射 Example -> example:', rowData.example);
+      }
+      
+      // 处理 Private 字段(可能后端是 Private,前端是 private)
+      if (rowData.Private !== undefined && rowData.private === undefined) {
+        rowData.private = rowData.Private;
+        console.log('映射 Private -> private:', rowData.private);
+      }
+      
+      // 如果没有 contentType,设置默认值
+      if (rowData.contentType === undefined || rowData.contentType === null || rowData.contentType === '') {
+        rowData.contentType = 'application/x-www-form-urlencoded';
+        console.log('设置默认 contentType:', rowData.contentType);
+      }
+      
+      // 如果没有 private,设置默认值
+      if (rowData.private === undefined || rowData.private === null) {
+        rowData.private = 0;
+        console.log('设置默认 private:', rowData.private);
+      }
 
-      Object.assign(formData, JSON.parse(JSON.stringify(row)));
+      Object.assign(formData, rowData);
+      
+      // 打印最终表单数据,查看是否正确设置了这三个字段
+      console.log('最终表单数据:', {
+        contentType: formData.contentType,
+        example: formData.example,
+        private: formData.private
+      });
 
       // 确保参数数组存在
       if (!formData.parameters) {