Browse Source

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

microrain 5 months ago
parent
commit
f57717839b
2 changed files with 22 additions and 13 deletions
  1. 19 12
      src/views/apihub/component/edit.vue
  2. 3 1
      src/views/apihub/component/view.vue

+ 19 - 12
src/views/apihub/component/edit.vue

@@ -56,7 +56,7 @@
             <el-form-item label="API路径" prop="path">
               <div class="path-input-container">
                 <div class="path-prefix2">
-                  {{ originUrl }}
+                  {{ originUrl }}/apihub/
                 </div>
                 <el-input v-model="formData.path" placeholder="请输入API路径" class="path-input" />
               </div>
@@ -159,8 +159,8 @@
               </el-radio-group>
             </el-form-item>
             <el-form-item label="SQL内容" prop="sqlContent" class="sql-content-item">
-              <SqlEditor 
-                v-model="formData.sqlContent" 
+              <SqlEditor
+                v-model="formData.sqlContent"
                 :height="300"
                 @update:modelValue="onSqlContentChange"
               />
@@ -623,43 +623,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) {
+
+      // 处理 private 字段的数据类型,确保是数字类型
+      if (rowData.private !== undefined) {
+        // 如果是字符串,转换为数字
+        if (typeof rowData.private === 'string') {
+          rowData.private = parseInt(rowData.private, 10) || 0;
+          console.log('将 private 从字符串转换为数字:', rowData.private);
+        }
+      } else {
+        // 如果没有 private,设置默认值
         rowData.private = 0;
         console.log('设置默认 private:', rowData.private);
       }
 
       Object.assign(formData, rowData);
-      
+
       // 打印最终表单数据,查看是否正确设置了这三个字段
       console.log('最终表单数据:', {
         contentType: formData.contentType,

+ 3 - 1
src/views/apihub/component/view.vue

@@ -2,7 +2,7 @@
   <el-dialog class="api-view" v-model="showDialog" title="API详情" width="800px" :close-on-click-modal="false" :close-on-press-escape="false">
     <el-descriptions :column="2" border>
       <el-descriptions-item label="API名称" :span="2">{{ apiData.name }}</el-descriptions-item>
-      <el-descriptions-item label="API路径" :span="2">{{ apiData.path }}</el-descriptions-item>
+      <el-descriptions-item label="API路径" :span="2">{{ originUrl }}/apihub/{{ apiData.path }}</el-descriptions-item>
       <el-descriptions-item label="请求方法">
         <el-tag :type="getMethodTagType(apiData.method)" size="small">{{ apiData.method }}</el-tag>
       </el-descriptions-item>
@@ -60,6 +60,7 @@
 
 <script lang="ts" setup>
 import { ref, reactive } from "vue";
+import getOrigin from "/@/utils/origin";
 
 const emit = defineEmits(["test"]);
 const showDialog = ref(false);
@@ -81,6 +82,7 @@ const apiData = reactive({
   createdAt: "",
   updatedAt: "",
 });
+const originUrl: string = getOrigin("");
 
 // 根据请求方法返回不同的标签类型
 const getMethodTagType = (method: string) => {