|
@@ -23,8 +23,7 @@
|
|
placeholder="搜索分组"
|
|
placeholder="搜索分组"
|
|
clearable
|
|
clearable
|
|
prefix-icon="ele-Search"
|
|
prefix-icon="ele-Search"
|
|
- @input="filterGroups"
|
|
|
|
- />
|
|
|
|
|
|
+ @input="filterGroups" />
|
|
</div>
|
|
</div>
|
|
<div class="group-tree-container">
|
|
<div class="group-tree-container">
|
|
<el-tree
|
|
<el-tree
|
|
@@ -35,14 +34,13 @@
|
|
highlight-current
|
|
highlight-current
|
|
:expand-on-click-node="true"
|
|
:expand-on-click-node="true"
|
|
default-expand-all
|
|
default-expand-all
|
|
- @node-click="handleGroupClick"
|
|
|
|
- >
|
|
|
|
|
|
+ @node-click="handleGroupClick">
|
|
<template #default="{ node, data }">
|
|
<template #default="{ node, data }">
|
|
<div class="custom-tree-node">
|
|
<div class="custom-tree-node">
|
|
<span>{{ node.label }}</span>
|
|
<span>{{ node.label }}</span>
|
|
<span class="api-count" v-if="data.ApiCount">{{ data.ApiCount }}</span>
|
|
<span class="api-count" v-if="data.ApiCount">{{ data.ApiCount }}</span>
|
|
<div class="node-actions">
|
|
<div class="node-actions">
|
|
- <el-dropdown @command="(command) => handleGroupCommand(command, data)" trigger="click">
|
|
|
|
|
|
+ <el-dropdown @command="(command: string) => handleGroupCommand(command, data)" trigger="click">
|
|
<el-icon><ele-More /></el-icon>
|
|
<el-icon><ele-More /></el-icon>
|
|
<template #dropdown>
|
|
<template #dropdown>
|
|
<el-dropdown-menu>
|
|
<el-dropdown-menu>
|
|
@@ -72,107 +70,105 @@
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<el-form :model="params" inline ref="queryRef">
|
|
<el-form :model="params" inline ref="queryRef">
|
|
- <el-form-item label="API名称" prop="keyWord">
|
|
|
|
- <el-input v-model="params.keyWord" placeholder="请输入API名称" clearable style="width: 180px" @keyup.enter.native="getList(1)" />
|
|
|
|
- </el-form-item>
|
|
|
|
- <el-form-item label="数据源" prop="dataSourceId">
|
|
|
|
- <el-select v-model="params.dataSourceId" placeholder="请选择数据源" clearable style="width: 180px">
|
|
|
|
- <el-option v-for="item in dataSources" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
|
- </el-select>
|
|
|
|
- </el-form-item>
|
|
|
|
- <el-form-item label="状态" prop="status">
|
|
|
|
- <el-select v-model="params.status" placeholder="请选择状态" clearable style="width: 120px">
|
|
|
|
- <el-option label="全部" value="" />
|
|
|
|
- <el-option label="草稿" value="Draft" />
|
|
|
|
- <el-option label="已发布" value="Published" />
|
|
|
|
- <el-option label="已废弃" value="Deprecated" />
|
|
|
|
- </el-select>
|
|
|
|
- </el-form-item>
|
|
|
|
- <el-form-item label="日期范围" prop="dateRange">
|
|
|
|
- <el-date-picker
|
|
|
|
- v-model="params.dateRange"
|
|
|
|
- type="daterange"
|
|
|
|
- range-separator="至"
|
|
|
|
- start-placeholder="开始日期"
|
|
|
|
- end-placeholder="结束日期"
|
|
|
|
- value-format="YYYY-MM-DD"
|
|
|
|
- style="width: 240px"
|
|
|
|
- />
|
|
|
|
- </el-form-item>
|
|
|
|
- <el-form-item>
|
|
|
|
- <el-button type="primary" class="ml10" @click="getList(1)">
|
|
|
|
- <el-icon>
|
|
|
|
- <ele-Search />
|
|
|
|
- </el-icon>
|
|
|
|
- 查询
|
|
|
|
- </el-button>
|
|
|
|
- <el-button @click="resetQuery()">
|
|
|
|
- <el-icon>
|
|
|
|
- <ele-Refresh />
|
|
|
|
- </el-icon>
|
|
|
|
- 重置
|
|
|
|
- </el-button>
|
|
|
|
- <el-button type="primary" @click="addOrEdit()" v-auth="'add'">
|
|
|
|
- <el-icon>
|
|
|
|
- <ele-FolderAdd />
|
|
|
|
- </el-icon>
|
|
|
|
- 新增API
|
|
|
|
- </el-button>
|
|
|
|
- </el-form-item>
|
|
|
|
- </el-form>
|
|
|
|
- <el-table :data="tableData" style="width: 100%" v-loading="loading" row-key="id">
|
|
|
|
- <el-table-column type="selection" width="55" align="center" />
|
|
|
|
- <el-table-column prop="id" label="ID" width="80" align="center" />
|
|
|
|
- <el-table-column prop="name" label="API名称" min-width="120" show-overflow-tooltip></el-table-column>
|
|
|
|
- <el-table-column prop="path" label="API路径" min-width="150" show-overflow-tooltip></el-table-column>
|
|
|
|
- <el-table-column prop="method" label="请求方法" width="100" align="center">
|
|
|
|
- <template #default="scope">
|
|
|
|
- <el-tag
|
|
|
|
- :type="getMethodTagType(scope.row.method)"
|
|
|
|
- size="small"
|
|
|
|
- >
|
|
|
|
- {{ scope.row.method }}
|
|
|
|
- </el-tag>
|
|
|
|
- </template>
|
|
|
|
- </el-table-column>
|
|
|
|
- <el-table-column prop="dataSourceName" label="数据源" width="120" show-overflow-tooltip></el-table-column>
|
|
|
|
- <el-table-column prop="sqlType" label="SQL类型" width="100" align="center">
|
|
|
|
- <template #default="scope">
|
|
|
|
- <el-tag size="small" type="info" v-if="scope.row.sqlType === 'query'">查询</el-tag>
|
|
|
|
- <el-tag size="small" type="warning" v-else-if="scope.row.sqlType === 'procedure'">存储过程</el-tag>
|
|
|
|
- <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="status" label="状态" width="100" align="center">
|
|
|
|
- <template #default="scope">
|
|
|
|
- <el-tag size="small" v-if="scope.row.status === 'Draft'">草稿</el-tag>
|
|
|
|
- <el-tag size="small" type="success" v-else-if="scope.row.status === 'Published'">已发布</el-tag>
|
|
|
|
- <el-tag size="small" type="info" v-else-if="scope.row.status === 'Deprecated'">已废弃</el-tag>
|
|
|
|
- <span v-else>{{ scope.row.status }}</span>
|
|
|
|
- </template>
|
|
|
|
- </el-table-column>
|
|
|
|
- <el-table-column prop="createdAt" label="创建时间" width="160" align="center"></el-table-column>
|
|
|
|
- <el-table-column label="操作" width="220" align="center">
|
|
|
|
- <template #default="scope">
|
|
|
|
- <el-button size="small" text type="primary" @click="viewDetail(scope.row)" v-auth="'view'">查看</el-button>
|
|
|
|
- <el-button size="small" text type="warning" @click="addOrEdit(scope.row)" v-auth="'edit'">编辑</el-button>
|
|
|
|
- <el-button size="small" text type="success" @click="testApi(scope.row)" v-auth="'test'">测试</el-button>
|
|
|
|
- <el-dropdown @command="(command) => handleCommand(command, scope.row)">
|
|
|
|
- <el-button size="small" text type="primary">
|
|
|
|
- 更多<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
|
|
|
|
|
+ <el-form-item label="API名称" prop="keyWord">
|
|
|
|
+ <el-input v-model="params.keyWord" placeholder="请输入API名称" clearable style="width: 180px" @keyup.enter.native="getList(1)" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="数据源" prop="dataSourceId">
|
|
|
|
+ <el-select v-model="params.dataSourceId" placeholder="请选择数据源" clearable style="width: 180px">
|
|
|
|
+ <el-option v-for="item in dataSources" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
|
+ </el-select>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="状态" prop="status">
|
|
|
|
+ <el-select v-model="params.status" placeholder="请选择状态" clearable style="width: 120px">
|
|
|
|
+ <el-option label="全部" value="" />
|
|
|
|
+ <el-option label="草稿" value="Draft" />
|
|
|
|
+ <el-option label="已发布" value="Published" />
|
|
|
|
+ <el-option label="已废弃" value="Deprecated" />
|
|
|
|
+ </el-select>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="日期范围" prop="dateRange">
|
|
|
|
+ <el-date-picker
|
|
|
|
+ v-model="params.dateRange"
|
|
|
|
+ type="daterange"
|
|
|
|
+ range-separator="至"
|
|
|
|
+ start-placeholder="开始日期"
|
|
|
|
+ end-placeholder="结束日期"
|
|
|
|
+ value-format="YYYY-MM-DD"
|
|
|
|
+ style="width: 240px" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item>
|
|
|
|
+ <el-button type="primary" class="ml10" @click="getList(1)">
|
|
|
|
+ <el-icon>
|
|
|
|
+ <ele-Search />
|
|
|
|
+ </el-icon>
|
|
|
|
+ 查询
|
|
|
|
+ </el-button>
|
|
|
|
+ <el-button @click="resetQuery()">
|
|
|
|
+ <el-icon>
|
|
|
|
+ <ele-Refresh />
|
|
|
|
+ </el-icon>
|
|
|
|
+ 重置
|
|
|
|
+ </el-button>
|
|
|
|
+ <el-button type="primary" @click="addOrEdit()" v-auth="'add'">
|
|
|
|
+ <el-icon>
|
|
|
|
+ <ele-FolderAdd />
|
|
|
|
+ </el-icon>
|
|
|
|
+ 新增API
|
|
</el-button>
|
|
</el-button>
|
|
- <template #dropdown>
|
|
|
|
- <el-dropdown-menu>
|
|
|
|
- <el-dropdown-item command="publish" v-if="scope.row.status === 'Draft'" v-auth="'publish'">发布</el-dropdown-item>
|
|
|
|
- <el-dropdown-item command="deprecate" v-if="scope.row.status === 'Published'" v-auth="'deprecate'">废弃</el-dropdown-item>
|
|
|
|
- <el-dropdown-item command="delete" v-auth="'delete'">删除</el-dropdown-item>
|
|
|
|
- </el-dropdown-menu>
|
|
|
|
|
|
+ </el-form-item>
|
|
|
|
+ </el-form>
|
|
|
|
+ <el-table :data="tableData" style="width: 100%" v-loading="loading" row-key="id">
|
|
|
|
+ <el-table-column type="selection" width="55" align="center" />
|
|
|
|
+ <el-table-column prop="id" label="ID" width="80" align="center" />
|
|
|
|
+ <el-table-column prop="name" label="API名称" min-width="120" show-overflow-tooltip></el-table-column>
|
|
|
|
+ <el-table-column prop="path" label="API路径" min-width="150" show-overflow-tooltip></el-table-column>
|
|
|
|
+ <el-table-column prop="method" label="请求方法" width="100" align="center">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ <el-tag
|
|
|
|
+ :type="getMethodTagType(scope.row.method)"
|
|
|
|
+ size="small">
|
|
|
|
+ {{ scope.row.method }}
|
|
|
|
+ </el-tag>
|
|
</template>
|
|
</template>
|
|
- </el-dropdown>
|
|
|
|
- </template>
|
|
|
|
- </el-table-column>
|
|
|
|
- </el-table>
|
|
|
|
|
|
+ </el-table-column>
|
|
|
|
+ <el-table-column prop="dataSourceName" label="数据源" width="120" show-overflow-tooltip></el-table-column>
|
|
|
|
+ <el-table-column prop="sqlType" label="SQL类型" width="100" align="center">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ <el-tag size="small" type="info" v-if="scope.row.sqlType === 'query'">查询</el-tag>
|
|
|
|
+ <el-tag size="small" type="warning" v-else-if="scope.row.sqlType === 'procedure'">存储过程</el-tag>
|
|
|
|
+ <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="status" label="状态" width="100" align="center">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ <el-tag size="small" v-if="scope.row.status === 'Draft'">草稿</el-tag>
|
|
|
|
+ <el-tag size="small" type="success" v-else-if="scope.row.status === 'Published'">已发布</el-tag>
|
|
|
|
+ <el-tag size="small" type="info" v-else-if="scope.row.status === 'Deprecated'">已废弃</el-tag>
|
|
|
|
+ <span v-else>{{ scope.row.status }}</span>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
|
|
+ <el-table-column prop="createdAt" label="创建时间" width="160" align="center"></el-table-column>
|
|
|
|
+ <el-table-column label="操作" width="220" align="center">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ <el-button size="small" text type="primary" @click="viewDetail(scope.row)" v-auth="'view'">查看</el-button>
|
|
|
|
+ <el-button size="small" text type="warning" @click="addOrEdit(scope.row)" v-auth="'edit'">编辑</el-button>
|
|
|
|
+ <el-button size="small" text type="success" @click="testApi(scope.row)" v-auth="'test'">测试</el-button>
|
|
|
|
+ <el-dropdown @command="(command: string) => handleCommand(command, scope.row)">
|
|
|
|
+ <el-button size="small" text type="primary">
|
|
|
|
+ 更多<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
|
|
|
+ </el-button>
|
|
|
|
+ <template #dropdown>
|
|
|
|
+ <el-dropdown-menu>
|
|
|
|
+ <el-dropdown-item command="publish" v-if="scope.row.status === 'Draft'" v-auth="'publish'">发布</el-dropdown-item>
|
|
|
|
+ <el-dropdown-item command="deprecate" v-if="scope.row.status === 'Published'" v-auth="'deprecate'">废弃</el-dropdown-item>
|
|
|
|
+ <el-dropdown-item command="delete" v-auth="'delete'">删除</el-dropdown-item>
|
|
|
|
+ </el-dropdown-menu>
|
|
|
|
+ </template>
|
|
|
|
+ </el-dropdown>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
|
|
+ </el-table>
|
|
<pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
|
|
<pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
|
|
</el-card>
|
|
</el-card>
|
|
</div>
|
|
</div>
|
|
@@ -195,7 +191,7 @@ import GroupForm from './component/group.vue'
|
|
import { useSearch } from '/@/hooks/useCommon'
|
|
import { useSearch } from '/@/hooks/useCommon'
|
|
import { ElMessageBox, ElMessage } from 'element-plus'
|
|
import { ElMessageBox, ElMessage } from 'element-plus'
|
|
import { ArrowDown } from '@element-plus/icons-vue'
|
|
import { ArrowDown } from '@element-plus/icons-vue'
|
|
-import request from '/@/utils/request'
|
|
|
|
|
|
+import api from '/@/api/modules/apiHub'
|
|
|
|
|
|
// 定义API接口类型
|
|
// 定义API接口类型
|
|
interface ApiDefinition {
|
|
interface ApiDefinition {
|
|
@@ -227,101 +223,65 @@ const groupTreeRef = ref()
|
|
|
|
|
|
// 分组相关状态
|
|
// 分组相关状态
|
|
const groupSearchKey = ref('')
|
|
const groupSearchKey = ref('')
|
|
-const groupTreeData = ref([])
|
|
|
|
-const currentGroup = reactive({
|
|
|
|
|
|
+const groupTreeData = ref<any[]>([])
|
|
|
|
+const currentGroup = reactive<any>({
|
|
Id: undefined,
|
|
Id: undefined,
|
|
GroupKey: '',
|
|
GroupKey: '',
|
|
Name: '',
|
|
Name: '',
|
|
ParentId: 0,
|
|
ParentId: 0,
|
|
Description: ''
|
|
Description: ''
|
|
})
|
|
})
|
|
-const originalGroupTree = ref([])
|
|
|
|
|
|
+const originalGroupTree = ref<any[]>([])
|
|
|
|
|
|
// 数据源列表
|
|
// 数据源列表
|
|
-const dataSources = ref([])
|
|
|
|
-
|
|
|
|
-// API列表请求函数
|
|
|
|
-const apiRequest = (params: any) => {
|
|
|
|
- // 这里使用request函数发起请求
|
|
|
|
- // 实际使用时替换为真实API路径
|
|
|
|
- return request({
|
|
|
|
- url: '/api/list',
|
|
|
|
- method: 'get',
|
|
|
|
- params
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 获取分组树形结构
|
|
|
|
-const getGroupTree = () => {
|
|
|
|
- return request({
|
|
|
|
- url: '/api_group/tree',
|
|
|
|
- method: 'get'
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 删除分组
|
|
|
|
-const deleteGroup = (ids: number[]) => {
|
|
|
|
- return request({
|
|
|
|
- url: '/api_group/delete',
|
|
|
|
- method: 'post',
|
|
|
|
- data: { ids }
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
|
|
+const dataSources = ref<any[]>([])
|
|
|
|
|
|
// 使用通用搜索钩子
|
|
// 使用通用搜索钩子
|
|
-const { params, tableData, getList, loading } = useSearch<ApiDefinition[]>(
|
|
|
|
- apiRequest,
|
|
|
|
- 'data',
|
|
|
|
- {
|
|
|
|
- keyWord: '',
|
|
|
|
- dataSourceId: '',
|
|
|
|
- status: '',
|
|
|
|
- dateRange: [],
|
|
|
|
- orderBy: '',
|
|
|
|
- pageNum: 1,
|
|
|
|
- pageSize: 10
|
|
|
|
- }
|
|
|
|
-)
|
|
|
|
|
|
+const { params, tableData, getList, loading } = useSearch<ApiDefinition[]>(api.list, 'Data', {
|
|
|
|
+ keyWord: '',
|
|
|
|
+ dataSourceId: '',
|
|
|
|
+ status: '',
|
|
|
|
+ dateRange: [],
|
|
|
|
+ orderBy: '',
|
|
|
|
+ pageNum: 1,
|
|
|
|
+ pageSize: 10
|
|
|
|
+})
|
|
|
|
|
|
// 加载数据源列表
|
|
// 加载数据源列表
|
|
const loadDataSources = () => {
|
|
const loadDataSources = () => {
|
|
- // 实际使用时替换为真实API调用
|
|
|
|
- // 模拟数据
|
|
|
|
- dataSources.value = [
|
|
|
|
- { id: 1, name: '主数据库' },
|
|
|
|
- { id: 2, name: '业务数据库' },
|
|
|
|
- { id: 3, name: '日志数据库' }
|
|
|
|
- ]
|
|
|
|
|
|
+ api.dataSource.list().then((res: any) => {
|
|
|
|
+ dataSources.value = res.list
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
// 页面加载时获取列表数据
|
|
// 页面加载时获取列表数据
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
// 获取API列表
|
|
// 获取API列表
|
|
getList(1)
|
|
getList(1)
|
|
-
|
|
|
|
|
|
+
|
|
// 加载数据源列表
|
|
// 加载数据源列表
|
|
loadDataSources()
|
|
loadDataSources()
|
|
-
|
|
|
|
|
|
+
|
|
// 加载分组树
|
|
// 加载分组树
|
|
refreshGroups()
|
|
refreshGroups()
|
|
})
|
|
})
|
|
|
|
|
|
// 将扁平数组转换为树形结构
|
|
// 将扁平数组转换为树形结构
|
|
-const convertToTree = (flatData) => {
|
|
|
|
|
|
+const convertToTree = (flatData: any[]) => {
|
|
// 创建一个映射表,用于快速查找节点
|
|
// 创建一个映射表,用于快速查找节点
|
|
- const map = {}
|
|
|
|
- const result = []
|
|
|
|
-
|
|
|
|
|
|
+ const map: any = {}
|
|
|
|
+ const result: any[] = []
|
|
|
|
+
|
|
// 首先创建所有节点的映射
|
|
// 首先创建所有节点的映射
|
|
flatData.forEach(item => {
|
|
flatData.forEach(item => {
|
|
// 确保每个节点都有Children属性
|
|
// 确保每个节点都有Children属性
|
|
map[item.Id] = { ...item, Children: [] }
|
|
map[item.Id] = { ...item, Children: [] }
|
|
})
|
|
})
|
|
-
|
|
|
|
|
|
+
|
|
// 然后建立父子关系
|
|
// 然后建立父子关系
|
|
flatData.forEach(item => {
|
|
flatData.forEach(item => {
|
|
const node = map[item.Id]
|
|
const node = map[item.Id]
|
|
-
|
|
|
|
|
|
+
|
|
if (item.ParentId === 0 || !map[item.ParentId]) {
|
|
if (item.ParentId === 0 || !map[item.ParentId]) {
|
|
// 如果ParentId为0或者父节点不存在,则为顶级节点
|
|
// 如果ParentId为0或者父节点不存在,则为顶级节点
|
|
result.push(node)
|
|
result.push(node)
|
|
@@ -330,19 +290,19 @@ const convertToTree = (flatData) => {
|
|
map[item.ParentId].Children.push(node)
|
|
map[item.ParentId].Children.push(node)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
-
|
|
|
|
|
|
+
|
|
// 清理空的Children数组
|
|
// 清理空的Children数组
|
|
flatData.forEach(item => {
|
|
flatData.forEach(item => {
|
|
if (map[item.Id].Children.length === 0) {
|
|
if (map[item.Id].Children.length === 0) {
|
|
map[item.Id].Children = null
|
|
map[item.Id].Children = null
|
|
}
|
|
}
|
|
})
|
|
})
|
|
-
|
|
|
|
|
|
+
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
// 检查数据是否已经是树形结构
|
|
// 检查数据是否已经是树形结构
|
|
-const isTreeStructure = (data) => {
|
|
|
|
|
|
+const isTreeStructure = (data: any[]) => {
|
|
// 检查数据中是否有包含非空的Children字段的项
|
|
// 检查数据中是否有包含非空的Children字段的项
|
|
return data.some(item => item.Children && Array.isArray(item.Children) && item.Children.length > 0)
|
|
return data.some(item => item.Children && Array.isArray(item.Children) && item.Children.length > 0)
|
|
}
|
|
}
|
|
@@ -351,60 +311,29 @@ const isTreeStructure = (data) => {
|
|
const refreshGroups = async () => {
|
|
const refreshGroups = async () => {
|
|
try {
|
|
try {
|
|
// 调用API获取分组树
|
|
// 调用API获取分组树
|
|
- const res = await getGroupTree()
|
|
|
|
- console.log('获取到的API分组数据:', res)
|
|
|
|
|
|
+ const res: any = await api.group.tree()
|
|
|
|
|
|
// 使用API返回的数据
|
|
// 使用API返回的数据
|
|
- if (res.data && res.data.list) {
|
|
|
|
|
|
+ if (res?.list) {
|
|
// 获取原始数据
|
|
// 获取原始数据
|
|
- const apiData = res.data.list || []
|
|
|
|
- console.log('原始数据:', apiData)
|
|
|
|
-
|
|
|
|
|
|
+ const apiData = res.list || []
|
|
|
|
+
|
|
// 检查数据是否已经是树形结构
|
|
// 检查数据是否已经是树形结构
|
|
const hasTreeStructure = isTreeStructure(apiData)
|
|
const hasTreeStructure = isTreeStructure(apiData)
|
|
- console.log('是否已经是树形结构:', hasTreeStructure)
|
|
|
|
-
|
|
|
|
- let treeData
|
|
|
|
|
|
+
|
|
|
|
+ let treeData: any[]
|
|
if (hasTreeStructure) {
|
|
if (hasTreeStructure) {
|
|
// 如果已经是树形结构,直接使用
|
|
// 如果已经是树形结构,直接使用
|
|
treeData = apiData
|
|
treeData = apiData
|
|
- console.log('使用原始树形结构')
|
|
|
|
} else {
|
|
} else {
|
|
// 如果是扁平结构,通过ParentId构建树形结构
|
|
// 如果是扁平结构,通过ParentId构建树形结构
|
|
treeData = convertToTree(apiData)
|
|
treeData = convertToTree(apiData)
|
|
- console.log('通过ParentId构建的树形结构:', treeData)
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 手动设置测试数据,确认组件是否正常工作
|
|
|
|
- const testData = [
|
|
|
|
- {
|
|
|
|
- "Id": 10,
|
|
|
|
- "GroupKey": "group_1746503398664_968",
|
|
|
|
- "Name": "巡检管理",
|
|
|
|
- "ParentId": 0,
|
|
|
|
- "Sort": 0,
|
|
|
|
- "Description": "",
|
|
|
|
- "Children": [
|
|
|
|
- {
|
|
|
|
- "Id": 11,
|
|
|
|
- "GroupKey": "group_1746515959076_509",
|
|
|
|
- "Name": "能耗分析",
|
|
|
|
- "ParentId": 10,
|
|
|
|
- "Sort": 0,
|
|
|
|
- "Description": "",
|
|
|
|
- "Children": null,
|
|
|
|
- "ApiCount": 0
|
|
|
|
- }
|
|
|
|
- ],
|
|
|
|
- "ApiCount": 0
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
- console.log('测试数据:', testData)
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// 设置到组件中
|
|
// 设置到组件中
|
|
- groupTreeData.value = testData
|
|
|
|
- originalGroupTree.value = JSON.parse(JSON.stringify(testData))
|
|
|
|
- console.log('设置后的分组数据:', groupTreeData.value)
|
|
|
|
|
|
+ groupTreeData.value = treeData
|
|
|
|
+ originalGroupTree.value = JSON.parse(JSON.stringify(treeData))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -425,7 +354,7 @@ const filterGroups = () => {
|
|
}
|
|
}
|
|
|
|
|
|
// 递归搜索函数
|
|
// 递归搜索函数
|
|
- const searchTree = (nodes) => {
|
|
|
|
|
|
+ const searchTree = (nodes: any[]) => {
|
|
return nodes.filter(node => {
|
|
return nodes.filter(node => {
|
|
// 当前节点名称匹配
|
|
// 当前节点名称匹配
|
|
const matchesName = node.Name.toLowerCase().includes(groupSearchKey.value.toLowerCase())
|
|
const matchesName = node.Name.toLowerCase().includes(groupSearchKey.value.toLowerCase())
|
|
@@ -445,7 +374,8 @@ const filterGroups = () => {
|
|
}
|
|
}
|
|
|
|
|
|
// 点击分组节点
|
|
// 点击分组节点
|
|
-const handleGroupClick = (data) => {
|
|
|
|
|
|
+const handleGroupClick = (data: any) => {
|
|
|
|
+ console.log(data)
|
|
// 设置当前选中分组
|
|
// 设置当前选中分组
|
|
Object.assign(currentGroup, data)
|
|
Object.assign(currentGroup, data)
|
|
|
|
|
|
@@ -462,7 +392,7 @@ const addGroup = () => {
|
|
}
|
|
}
|
|
|
|
|
|
// 处理分组操作
|
|
// 处理分组操作
|
|
-const handleGroupCommand = (command, data) => {
|
|
|
|
|
|
+const handleGroupCommand = (command: string, data: any) => {
|
|
switch (command) {
|
|
switch (command) {
|
|
case 'edit':
|
|
case 'edit':
|
|
groupFormRef.value.open(data)
|
|
groupFormRef.value.open(data)
|
|
@@ -477,7 +407,7 @@ const handleGroupCommand = (command, data) => {
|
|
}
|
|
}
|
|
|
|
|
|
// 删除分组确认
|
|
// 删除分组确认
|
|
-const deleteGroupConfirm = (data) => {
|
|
|
|
|
|
+const deleteGroupConfirm = (data: any) => {
|
|
ElMessageBox.confirm(`确定要删除分组「${data.Name}」吗?如果包含子分组或API,将一并删除。`, '警告', {
|
|
ElMessageBox.confirm(`确定要删除分组「${data.Name}」吗?如果包含子分组或API,将一并删除。`, '警告', {
|
|
confirmButtonText: '确定',
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
cancelButtonText: '取消',
|
|
@@ -485,7 +415,7 @@ const deleteGroupConfirm = (data) => {
|
|
}).then(async () => {
|
|
}).then(async () => {
|
|
try {
|
|
try {
|
|
// 实际使用时调用API
|
|
// 实际使用时调用API
|
|
- await deleteGroup([data.Id])
|
|
|
|
|
|
+ await api.group.delete([data.Id])
|
|
ElMessage.success('删除成功')
|
|
ElMessage.success('删除成功')
|
|
|
|
|
|
// 如果当前选中的是要删除的分组,则清空当前分组
|
|
// 如果当前选中的是要删除的分组,则清空当前分组
|
|
@@ -506,7 +436,7 @@ const deleteGroupConfirm = (data) => {
|
|
} catch (error) {
|
|
} catch (error) {
|
|
ElMessage.error('删除失败')
|
|
ElMessage.error('删除失败')
|
|
}
|
|
}
|
|
- }).catch(() => {})
|
|
|
|
|
|
+ }).catch(() => { })
|
|
}
|
|
}
|
|
|
|
|
|
// 根据请求方法返回不同的标签类型
|
|
// 根据请求方法返回不同的标签类型
|
|
@@ -539,7 +469,7 @@ const addOrEdit = (row?: ApiDefinition) => {
|
|
editFormRef.value.open(row)
|
|
editFormRef.value.open(row)
|
|
} else {
|
|
} else {
|
|
// 新增API,如果有选中分组,则传递分组标识
|
|
// 新增API,如果有选中分组,则传递分组标识
|
|
- editFormRef.value.open(null, currentGroup.groupKey)
|
|
|
|
|
|
+ editFormRef.value.open(null, currentGroup.GroupKey)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -575,11 +505,10 @@ const publishApi = (row: ApiDefinition) => {
|
|
cancelButtonText: '取消',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
type: 'warning'
|
|
}).then(async () => {
|
|
}).then(async () => {
|
|
- // 实际使用时替换为真实API调用
|
|
|
|
- // await api.apihub.publish({ id: row.id })
|
|
|
|
|
|
+ await api.publish(row.id!)
|
|
ElMessage.success('发布成功')
|
|
ElMessage.success('发布成功')
|
|
getList()
|
|
getList()
|
|
- }).catch(() => {})
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
// 废弃API
|
|
// 废弃API
|
|
@@ -589,11 +518,10 @@ const deprecateApi = (row: ApiDefinition) => {
|
|
cancelButtonText: '取消',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
type: 'warning'
|
|
}).then(async () => {
|
|
}).then(async () => {
|
|
- // 实际使用时替换为真实API调用
|
|
|
|
- // await api.apihub.deprecate({ id: row.id })
|
|
|
|
|
|
+ await api.deprecate(row.id!)
|
|
ElMessage.success('废弃成功')
|
|
ElMessage.success('废弃成功')
|
|
getList()
|
|
getList()
|
|
- }).catch(() => {})
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
// 删除API
|
|
// 删除API
|
|
@@ -603,11 +531,10 @@ const deleteApi = (row: ApiDefinition) => {
|
|
cancelButtonText: '取消',
|
|
cancelButtonText: '取消',
|
|
type: 'error'
|
|
type: 'error'
|
|
}).then(async () => {
|
|
}).then(async () => {
|
|
- // 实际使用时替换为真实API调用
|
|
|
|
- // await api.apihub.delete({ ids: [row.id] })
|
|
|
|
|
|
+ await api.delete([row.id!])
|
|
ElMessage.success('删除成功')
|
|
ElMessage.success('删除成功')
|
|
getList()
|
|
getList()
|
|
- }).catch(() => {})
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|
|
@@ -656,8 +583,10 @@ const deleteApi = (row: ApiDefinition) => {
|
|
.group-tree-container {
|
|
.group-tree-container {
|
|
overflow-y: auto;
|
|
overflow-y: auto;
|
|
flex: 1;
|
|
flex: 1;
|
|
- min-height: 200px; /* 确保容器有最小高度 */
|
|
|
|
- border: 1px solid #ebeef5; /* 添加边框以便于调试 */
|
|
|
|
|
|
+ min-height: 200px;
|
|
|
|
+ /* 确保容器有最小高度 */
|
|
|
|
+ border: 1px solid #ebeef5;
|
|
|
|
+ /* 添加边框以便于调试 */
|
|
padding: 10px;
|
|
padding: 10px;
|
|
}
|
|
}
|
|
|
|
|