520 lines
24 KiB
Vue
520 lines
24 KiB
Vue
<template>
|
|
<div class="cid-apis-container">
|
|
<el-card shadow="hover">
|
|
<template #header>
|
|
<span style="font-weight: 600">平台管理</span>
|
|
</template>
|
|
<el-form ref="pqf" :model="pq" :inline="true" label-width="68px" class="mb15">
|
|
<el-form-item label="关键字" prop="keyword">
|
|
<el-input v-model="pq.keyword" placeholder="请输入平台名称/编码" clearable style="width: 240px" @keyup.enter.native="searchPlatform" />
|
|
</el-form-item>
|
|
<el-form-item label="状态" prop="status">
|
|
<el-select v-model="pq.status" placeholder="平台状态" clearable style="width: 160px">
|
|
<el-option label="启用" value="ACTIVE" />
|
|
<el-option label="禁用" value="INACTIVE" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" @click="searchPlatform"><el-icon><ele-Search /></el-icon>查询</el-button>
|
|
<el-button @click="resetPlatformQuery"><el-icon><ele-Refresh /></el-icon>重置</el-button>
|
|
<el-button type="success" @click="openPlatform()"><el-icon><ele-FolderAdd /></el-icon>新增平台</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
<el-table :data="platformRows" row-key="id" v-loading="platformLoading">
|
|
<el-table-column type="index" label="序号" width="60" />
|
|
<el-table-column prop="platformCode" label="平台编码" min-width="140" show-overflow-tooltip />
|
|
<el-table-column prop="platformName" label="平台名称" min-width="160" show-overflow-tooltip />
|
|
<el-table-column prop="apiBaseUrl" label="API地址" min-width="220" show-overflow-tooltip />
|
|
<el-table-column prop="authType" label="认证" width="100" align="center" />
|
|
<el-table-column prop="status" label="状态" width="90" align="center">
|
|
<template #default="s">
|
|
<el-tag size="small" :type="s.row.status === 'ACTIVE' ? 'success' : 'danger'">{{ s.row.status === 'ACTIVE' ? '启用' : '禁用' }}</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="rateLimitPerMinute" label="限流/分钟" width="110" align="center" />
|
|
<el-table-column prop="requestTimeoutMs" label="超时(ms)" width="110" align="center" />
|
|
<el-table-column label="创建时间" width="170">
|
|
<template #default="s">{{ ft(s.row.createdAt) }}</template>
|
|
</el-table-column>
|
|
<el-table-column label="操作" width="240" fixed="right">
|
|
<template #default="s">
|
|
<el-button size="small" text type="primary" @click="manageApis(s.row)">接口管理</el-button>
|
|
<el-button size="small" text type="primary" @click="openPlatform(s.row)">修改</el-button>
|
|
<el-button size="small" text type="danger" @click="delPlatform(s.row)">删除</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
<pagination :total="platformTotal" v-model:page="pq.pageNum" v-model:limit="pq.pageSize" @pagination="getPlatforms" />
|
|
</el-card>
|
|
<el-dialog v-model="apiListDialog.visible" :title="apiListDialog.title" width="1100px" :close-on-click-modal="false" destroy-on-close @closed="handleApiListClose"
|
|
><el-form ref="aqf" :model="aq" :inline="true" label-width="68px" class="mb15"
|
|
><el-form-item label="关键字" prop="keyword"
|
|
><el-input v-model="aq.keyword" placeholder="请输入接口名称/编码" clearable style="width: 220px" @keyup.enter.native="searchApi" /></el-form-item
|
|
><el-form-item label="状态" prop="status"
|
|
><el-select v-model="aq.status" placeholder="状态" clearable style="width: 130px"
|
|
><el-option label="启用" value="active" /><el-option label="禁用" value="inactive" /></el-select></el-form-item
|
|
><el-form-item label="方法" prop="method"
|
|
><el-select v-model="aq.method" placeholder="请求方式" clearable style="width: 130px"
|
|
><el-option v-for="m in methods" :key="m" :label="m" :value="m" /></el-select></el-form-item
|
|
><el-form-item
|
|
><el-button type="primary" @click="searchApi"><el-icon><ele-Search /></el-icon>查询</el-button
|
|
><el-button @click="resetApiQuery"><el-icon><ele-Refresh /></el-icon>重置</el-button
|
|
><el-button type="success" @click="openApiForCurrentPlatform()"><el-icon><ele-FolderAdd /></el-icon>新增接口</el-button></el-form-item></el-form
|
|
><el-table :data="apiRows" v-loading="apiLoading" max-height="420"
|
|
><el-table-column type="index" label="序号" width="60" /><el-table-column prop="code" label="接口编码" min-width="140" show-overflow-tooltip
|
|
/><el-table-column prop="name" label="接口名称" min-width="150" show-overflow-tooltip /><el-table-column prop="url" label="URL" min-width="220"
|
|
show-overflow-tooltip /><el-table-column prop="method" label="请求方式" width="100" align="center"
|
|
><template #default="s"
|
|
><el-tag size="small" :type="s.row.method === 'GET' ? 'success' : 'primary'">{{ s.row.method }}</el-tag></template></el-table-column
|
|
><el-table-column prop="status" label="状态" width="90" align="center"
|
|
><template #default="s"
|
|
><el-tag size="small" :type="ns(s.row.status) === 'active' ? 'success' : 'danger'">{{ ns(s.row.status) === 'active' ? '启用' : '禁用' }}</el-tag></template></el-table-column
|
|
><el-table-column prop="platformName" label="所属平台" min-width="140" show-overflow-tooltip /><el-table-column label="创建时间" width="170"
|
|
><template #default="s">{{ ft(s.row.createdAt) }}</template></el-table-column
|
|
><el-table-column label="操作" width="160" fixed="right"
|
|
><template #default="s"
|
|
><el-button size="small" text type="primary" @click="openApi(String(s.row.id))">修改</el-button
|
|
><el-button size="small" text type="danger" @click="delApi(s.row)">删除</el-button></template></el-table-column></el-table
|
|
><template #footer
|
|
><div style="display: flex; justify-content: space-between; align-items: center; width: 100%;"
|
|
><pagination :total="apiTotal" v-model:page="aq.pageNum" v-model:limit="aq.pageSize" @pagination="getApis" />
|
|
<el-button type="primary" @click="apiListDialog.visible = false">关闭</el-button></div></template
|
|
></el-dialog>
|
|
<el-dialog v-model="platformDialog.visible" :title="platformDialog.title" width="720px" :close-on-click-modal="false" destroy-on-close
|
|
><el-form ref="platformFormRef" :model="platformForm" :rules="platformRules" label-width="120px" v-loading="platformDialog.loading"
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="平台编码" prop="platformCode"><el-input v-model="platformForm.platformCode" /></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="平台名称" prop="platformName"><el-input v-model="platformForm.platformName" /></el-form-item></el-col></el-row
|
|
><el-form-item label="平台描述"><el-input v-model="platformForm.description" type="textarea" :rows="3" /></el-form-item
|
|
><el-form-item label="API地址"><el-input v-model="platformForm.apiBaseUrl" /></el-form-item
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="认证类型" prop="authType"
|
|
><el-select v-model="platformForm.authType" style="width: 100%"
|
|
><el-option label="Token" value="TOKEN" /><el-option label="API Key" value="API_KEY" /><el-option
|
|
label="OAuth2"
|
|
value="OAUTH2" /><el-option label="Basic" value="BASIC" /></el-select></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="状态" prop="status"
|
|
><el-select v-model="platformForm.status" style="width: 100%"
|
|
><el-option label="启用" value="ACTIVE" /><el-option label="停用" value="INACTIVE" /></el-select></el-form-item></el-col></el-row
|
|
><el-form-item label="Token/密钥"><el-input v-model="platformForm.token" show-password /></el-form-item
|
|
><el-form-item label="API Key"><el-input v-model="platformForm.apiKey" show-password /></el-form-item
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="Client ID"><el-input v-model="platformForm.clientId" /></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="Client Secret"><el-input v-model="platformForm.clientSecret" show-password /></el-form-item></el-col></el-row
|
|
><el-form-item label="认证配置 JSON" prop="authConfigText"
|
|
><el-input v-model="platformForm.authConfigText" type="textarea" :rows="6" /></el-form-item
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="限流/分钟"
|
|
><el-input-number v-model="platformForm.rateLimitPerMinute" :min="0" style="width: 100%" /></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="限流/小时"
|
|
><el-input-number v-model="platformForm.rateLimitPerHour" :min="0" style="width: 100%" /></el-form-item></el-col></el-row
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="并发限制"
|
|
><el-input-number v-model="platformForm.concurrencyLimit" :min="0" style="width: 100%" /></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="超时(ms)"
|
|
><el-input-number v-model="platformForm.requestTimeoutMs" :min="0" style="width: 100%" /></el-form-item></el-col></el-row
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="最大重试"><el-input-number v-model="platformForm.maxRetries" :min="0" style="width: 100%" /></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="重试延迟(ms)"
|
|
><el-input-number v-model="platformForm.retryDelayMs" :min="0" style="width: 100%" /></el-form-item></el-col></el-row></el-form
|
|
><template #footer
|
|
><el-button @click="platformDialog.visible = false">取消</el-button
|
|
><el-button type="primary" :loading="platformDialog.saving" @click="savePlatform">确定</el-button></template
|
|
></el-dialog
|
|
><el-dialog v-model="apiDialog.visible" :title="apiDialog.title" width="780px" :close-on-click-modal="false" destroy-on-close
|
|
><el-form ref="apiFormRef" :model="apiForm" :rules="apiRules" label-width="110px" v-loading="apiDialog.loading"
|
|
><el-form-item label="所属平台" prop="platformId"
|
|
><el-select v-model="apiForm.platformId" style="width: 100%" filterable
|
|
><el-option v-for="i in platforms" :key="i.id" :label="i.platformName" :value="String(i.id)" /></el-select></el-form-item
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="接口编码" prop="code"><el-input v-model="apiForm.code" /></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="接口名称" prop="name"><el-input v-model="apiForm.name" /></el-form-item></el-col></el-row
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="URL" prop="url"><el-input v-model="apiForm.url" /></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="请求方式" prop="method"
|
|
><el-select v-model="apiForm.method" style="width: 100%"
|
|
><el-option v-for="m in methods" :key="m" :label="m" :value="m" /></el-select></el-form-item></el-col></el-row
|
|
><el-row :gutter="16"
|
|
><el-col :span="12"
|
|
><el-form-item label="状态" prop="status"
|
|
><el-select v-model="apiForm.status" style="width: 100%"
|
|
><el-option label="启用" value="active" /><el-option label="禁用" value="inactive" /></el-select></el-form-item></el-col
|
|
><el-col :span="12"
|
|
><el-form-item label="认证类型"
|
|
><el-select v-model="apiForm.authType" style="width: 100%" clearable
|
|
><el-option label="Token" value="TOKEN" /><el-option label="API Key" value="API_KEY" /><el-option
|
|
label="OAuth2"
|
|
value="OAUTH2" /><el-option label="APP_SIGNATURE" value="APP_SIGNATURE" /></el-select></el-form-item></el-col></el-row
|
|
><el-form-item label="请求配置 JSON" prop="requestConfigText"
|
|
><el-input v-model="apiForm.requestConfigText" type="textarea" :rows="6" /></el-form-item
|
|
><el-form-item label="响应配置 JSON" prop="responseConfigText"
|
|
><el-input v-model="apiForm.responseConfigText" type="textarea" :rows="5" /></el-form-item
|
|
><el-form-item label="限流配置 JSON" prop="limitConfigText"
|
|
><el-input v-model="apiForm.limitConfigText" type="textarea" :rows="4" /></el-form-item
|
|
><el-form-item label="表结构定义 JSON" prop="tableDefinitionText"
|
|
><el-input v-model="apiForm.tableDefinitionText" type="textarea" :rows="6" /></el-form-item></el-form
|
|
><template #footer
|
|
><el-button @click="apiDialog.visible = false">取消</el-button
|
|
><el-button type="primary" :loading="apiDialog.saving" @click="saveApi">确定</el-button></template
|
|
></el-dialog
|
|
>
|
|
</div>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { onMounted, reactive, ref } from 'vue';
|
|
import type { FormInstance, FormRules } from 'element-plus';
|
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
import { getApiErrorMessage } from '/@/utils/request';
|
|
import {
|
|
createDatasourcePlatform,
|
|
deleteDatasourcePlatform,
|
|
getDatasourcePlatform,
|
|
listDatasourcePlatforms,
|
|
updateDatasourcePlatform,
|
|
} from '/@/api/cid/datasource';
|
|
import {
|
|
createApiInterface,
|
|
deleteApiInterface,
|
|
getApiInterface,
|
|
listApiInterfaces,
|
|
updateApiInterface,
|
|
type ApiInterfaceInfo,
|
|
} from '/@/api/cid/apis';
|
|
defineOptions({ name: 'cidApis' });
|
|
const currentPlatform = ref<any>(null),
|
|
methods = ['GET', 'POST', 'PUT', 'DELETE'],
|
|
platforms = ref<any[]>([]),
|
|
platformRows = ref<any[]>([]),
|
|
apiRows = ref<ApiInterfaceInfo[]>([]),
|
|
platformTotal = ref(0),
|
|
apiTotal = ref(0),
|
|
platformLoading = ref(false),
|
|
apiLoading = ref(false);
|
|
const pqf = ref<FormInstance>(),
|
|
aqf = ref<FormInstance>(),
|
|
platformFormRef = ref<FormInstance>(),
|
|
apiFormRef = ref<FormInstance>();
|
|
const pq = reactive({ pageNum: 1, pageSize: 10, keyword: '', status: '' }),
|
|
aq = reactive({ pageNum: 1, pageSize: 10, keyword: '', platformId: '', status: '', method: '' });
|
|
const platformDialog = reactive({ visible: false, title: '', loading: false, saving: false }),
|
|
apiDialog = reactive({ visible: false, title: '', loading: false, saving: false }),
|
|
apiListDialog = reactive({ visible: false, title: '' });
|
|
const dpf = () => ({
|
|
id: '',
|
|
platformCode: '',
|
|
platformName: '',
|
|
description: '',
|
|
apiBaseUrl: '',
|
|
authType: 'TOKEN',
|
|
status: 'ACTIVE',
|
|
token: '',
|
|
apiKey: '',
|
|
clientId: '',
|
|
clientSecret: '',
|
|
authConfigText: '{}',
|
|
rateLimitPerMinute: 60,
|
|
rateLimitPerHour: 1000,
|
|
concurrencyLimit: 10,
|
|
requestTimeoutMs: 30000,
|
|
maxRetries: 3,
|
|
retryDelayMs: 1000,
|
|
});
|
|
const daf = () => ({
|
|
id: '',
|
|
platformId: '',
|
|
code: '',
|
|
name: '',
|
|
url: '',
|
|
method: 'GET',
|
|
status: 'active',
|
|
authType: '',
|
|
requestConfigText: '{}',
|
|
responseConfigText: '{}',
|
|
limitConfigText: '{}',
|
|
tableDefinitionText: '{}',
|
|
});
|
|
const platformForm = reactive(dpf()),
|
|
apiForm = reactive(daf());
|
|
const jv = (v: string, cb: (e?: Error) => void, l: string) => {
|
|
if (!v) return cb();
|
|
try {
|
|
JSON.parse(v);
|
|
cb();
|
|
} catch {
|
|
cb(new Error(`${l} 格式错误`));
|
|
}
|
|
};
|
|
const platformRules: FormRules = {
|
|
platformCode: [{ required: true, message: '请输入平台编码', trigger: 'blur' }],
|
|
platformName: [{ required: true, message: '请输入平台名称', trigger: 'blur' }],
|
|
authType: [{ required: true, message: '请选择认证类型', trigger: 'change' }],
|
|
authConfigText: [{ validator: (_r, v, cb) => jv(v, cb, '认证配置 JSON'), trigger: 'blur' }],
|
|
};
|
|
const apiRules: FormRules = {
|
|
platformId: [{ required: true, message: '请选择所属平台', trigger: 'change' }],
|
|
code: [{ required: true, message: '请输入接口编码', trigger: 'blur' }],
|
|
name: [{ required: true, message: '请输入接口名称', trigger: 'blur' }],
|
|
url: [{ required: true, message: '请输入接口 URL', trigger: 'blur' }],
|
|
method: [{ required: true, message: '请选择请求方式', trigger: 'change' }],
|
|
requestConfigText: [{ validator: (_r, v, cb) => jv(v, cb, '请求配置 JSON'), trigger: 'blur' }],
|
|
responseConfigText: [{ validator: (_r, v, cb) => jv(v, cb, '响应配置 JSON'), trigger: 'blur' }],
|
|
limitConfigText: [{ validator: (_r, v, cb) => jv(v, cb, '接口独立限流配置 JSON'), trigger: 'blur' }],
|
|
tableDefinitionText: [{ validator: (_r, v, cb) => jv(v, cb, '表结构定义 JSON'), trigger: 'blur' }],
|
|
};
|
|
const ft = (t?: number) => (!t ? '' : new Date(String(t).length === 10 ? t * 1000 : t).toLocaleString('zh-CN', { hour12: false })),
|
|
ns = (s?: string) => (String(s || '').toLowerCase() === 'active' ? 'active' : 'inactive');
|
|
const loadPlatforms = async () => {
|
|
const r = await listDatasourcePlatforms({ pageNum: 1, pageSize: 100 });
|
|
platforms.value = r.data?.list || [];
|
|
};
|
|
const getPlatforms = async () => {
|
|
platformLoading.value = true;
|
|
try {
|
|
const r = await listDatasourcePlatforms({
|
|
pageNum: pq.pageNum,
|
|
pageSize: pq.pageSize,
|
|
...(pq.keyword ? { keyword: pq.keyword } : {}),
|
|
...(pq.status ? { status: pq.status } : {}),
|
|
});
|
|
platformRows.value = r.data?.list || [];
|
|
platformTotal.value = r.data?.total || 0;
|
|
} catch (e) {
|
|
ElMessage.error(getApiErrorMessage(e) || '获取平台列表失败');
|
|
} finally {
|
|
platformLoading.value = false;
|
|
}
|
|
};
|
|
const getApis = async () => {
|
|
apiLoading.value = true;
|
|
try {
|
|
const r = await listApiInterfaces({
|
|
pageNum: aq.pageNum,
|
|
pageSize: aq.pageSize,
|
|
...(aq.keyword ? { keyword: aq.keyword } : {}),
|
|
...(aq.platformId ? { platformId: aq.platformId } : {}),
|
|
...(aq.status ? { status: aq.status } : {}),
|
|
...(aq.method ? { method: aq.method } : {}),
|
|
});
|
|
apiRows.value = r.data?.list || [];
|
|
apiTotal.value = r.data?.total || 0;
|
|
} catch (e) {
|
|
ElMessage.error(getApiErrorMessage(e) || '获取接口列表失败');
|
|
} finally {
|
|
apiLoading.value = false;
|
|
}
|
|
};
|
|
const searchPlatform = () => {
|
|
pq.pageNum = 1;
|
|
getPlatforms();
|
|
};
|
|
const searchApi = () => {
|
|
aq.pageNum = 1;
|
|
getApis();
|
|
};
|
|
const resetPlatformQuery = () => {
|
|
pqf.value?.resetFields();
|
|
searchPlatform();
|
|
};
|
|
const resetApiQuery: any = () => {
|
|
aqf.value?.resetFields();
|
|
searchApi();
|
|
};
|
|
const manageApis = (row: any) => {
|
|
currentPlatform.value = row;
|
|
aq.platformId = String(row.id);
|
|
aq.pageNum = 1;
|
|
aq.keyword = '';
|
|
aq.status = '';
|
|
aq.method = '';
|
|
apiListDialog.title = `${row.platformName} - 接口管理`;
|
|
apiListDialog.visible = true;
|
|
getApis();
|
|
};
|
|
const handleApiListClose = () => {
|
|
currentPlatform.value = null;
|
|
};
|
|
const openApiForCurrentPlatform = () => {
|
|
openApi('', currentPlatform.value?.id || '');
|
|
};
|
|
const openPlatform = async (row?: any) => {
|
|
Object.assign(platformForm, dpf());
|
|
platformFormRef.value?.clearValidate();
|
|
platformDialog.title = row ? '编辑平台' : '新建平台';
|
|
platformDialog.visible = true;
|
|
if (!row) return;
|
|
platformDialog.loading = true;
|
|
try {
|
|
const r = await getDatasourcePlatform(row.id);
|
|
const d = r.data || {};
|
|
Object.assign(platformForm, {
|
|
id: String(d.id || row.id),
|
|
platformCode: d.platformCode || '',
|
|
platformName: d.platformName || '',
|
|
description: d.description || '',
|
|
apiBaseUrl: d.apiBaseUrl || '',
|
|
authType: d.authType || 'TOKEN',
|
|
status: d.status || 'ACTIVE',
|
|
token: d.token || '',
|
|
apiKey: d.apiKey || '',
|
|
clientId: d.clientId || '',
|
|
clientSecret: d.clientSecret || '',
|
|
authConfigText: JSON.stringify(d.authConfig ?? {}, null, 2),
|
|
rateLimitPerMinute: d.rateLimitPerMinute ?? 60,
|
|
rateLimitPerHour: d.rateLimitPerHour ?? 1000,
|
|
concurrencyLimit: d.concurrencyLimit ?? 10,
|
|
requestTimeoutMs: d.requestTimeoutMs ?? 30000,
|
|
maxRetries: d.maxRetries ?? 3,
|
|
retryDelayMs: d.retryDelayMs ?? 1000,
|
|
});
|
|
} catch (e) {
|
|
platformDialog.visible = false;
|
|
ElMessage.error(getApiErrorMessage(e) || '获取平台详情失败');
|
|
} finally {
|
|
platformDialog.loading = false;
|
|
}
|
|
};
|
|
const savePlatform = async () => {
|
|
if (!platformFormRef.value) return;
|
|
const ok = await platformFormRef.value.validate().catch(() => false);
|
|
if (!ok) return;
|
|
platformDialog.saving = true;
|
|
try {
|
|
const p = {
|
|
platformCode: platformForm.platformCode,
|
|
platformName: platformForm.platformName,
|
|
description: platformForm.description,
|
|
apiBaseUrl: platformForm.apiBaseUrl,
|
|
authType: platformForm.authType,
|
|
status: platformForm.status,
|
|
token: platformForm.token,
|
|
apiKey: platformForm.apiKey,
|
|
clientId: platformForm.clientId,
|
|
clientSecret: platformForm.clientSecret,
|
|
authConfig: JSON.parse(platformForm.authConfigText || '{}'),
|
|
rateLimitPerMinute: platformForm.rateLimitPerMinute || 60,
|
|
rateLimitPerHour: platformForm.rateLimitPerHour || 1000,
|
|
concurrencyLimit: platformForm.concurrencyLimit || 10,
|
|
requestTimeoutMs: platformForm.requestTimeoutMs || 30000,
|
|
maxRetries: platformForm.maxRetries || 3,
|
|
retryDelayMs: platformForm.retryDelayMs || 1000,
|
|
};
|
|
platformForm.id ? await updateDatasourcePlatform({ id: platformForm.id, ...p }) : await createDatasourcePlatform(p);
|
|
ElMessage.success(platformForm.id ? '更新成功' : '创建成功');
|
|
platformDialog.visible = false;
|
|
await Promise.all([getPlatforms(), loadPlatforms()]);
|
|
} catch (e) {
|
|
ElMessage.error(getApiErrorMessage(e) || (platformForm.id ? '更新失败' : '创建失败'));
|
|
} finally {
|
|
platformDialog.saving = false;
|
|
}
|
|
};
|
|
const delPlatform = (row: any) => {
|
|
const ids = [row.id];
|
|
ElMessageBox.confirm(`确定删除平台「${row.platformName}」吗?`, '提示', { type: 'warning' })
|
|
.then(async () => {
|
|
try {
|
|
for (const id of ids) await deleteDatasourcePlatform(id);
|
|
ElMessage.success('删除成功');
|
|
await Promise.all([getPlatforms(), loadPlatforms()]);
|
|
} catch (e) {
|
|
ElMessage.error(getApiErrorMessage(e) || '删除失败');
|
|
}
|
|
})
|
|
.catch(() => undefined);
|
|
};
|
|
const openApi = async (id = '', platformId = '') => {
|
|
Object.assign(apiForm, daf(), platformId ? { platformId } : {});
|
|
apiFormRef.value?.clearValidate();
|
|
if (!platforms.value.length) await loadPlatforms();
|
|
apiDialog.title = id ? '编辑接口' : '新建接口';
|
|
apiDialog.visible = true;
|
|
if (!id) return;
|
|
apiDialog.loading = true;
|
|
try {
|
|
const r = await getApiInterface(id);
|
|
const d = r.data || {};
|
|
Object.assign(apiForm, {
|
|
id: String(d.id || id),
|
|
platformId: String(d.platformId || platformId || ''),
|
|
code: d.code || '',
|
|
name: d.name || '',
|
|
url: d.url || '',
|
|
method: d.method || 'GET',
|
|
status: ns(d.status),
|
|
authType: d.authType || '',
|
|
requestConfigText: JSON.stringify(d.requestConfig ?? {}, null, 2),
|
|
responseConfigText: JSON.stringify(d.responseConfig ?? {}, null, 2),
|
|
limitConfigText: JSON.stringify(d.limitConfig ?? {}, null, 2),
|
|
tableDefinitionText: JSON.stringify(d.tableDefinition ?? {}, null, 2),
|
|
});
|
|
} catch (e) {
|
|
apiDialog.visible = false;
|
|
ElMessage.error(getApiErrorMessage(e) || '获取接口详情失败');
|
|
} finally {
|
|
apiDialog.loading = false;
|
|
}
|
|
};
|
|
const saveApi = async () => {
|
|
if (!apiFormRef.value) return;
|
|
const ok = await apiFormRef.value.validate().catch(() => false);
|
|
if (!ok) return;
|
|
apiDialog.saving = true;
|
|
try {
|
|
const p = {
|
|
platformId: Number(apiForm.platformId),
|
|
code: apiForm.code,
|
|
name: apiForm.name,
|
|
url: apiForm.url,
|
|
method: apiForm.method,
|
|
status: apiForm.status,
|
|
authType: apiForm.authType || undefined,
|
|
requestConfig: JSON.parse(apiForm.requestConfigText || '{}'),
|
|
responseConfig: JSON.parse(apiForm.responseConfigText || '{}'),
|
|
limitConfig: JSON.parse(apiForm.limitConfigText || '{}'),
|
|
tableDefinition: JSON.parse(apiForm.tableDefinitionText || '{}'),
|
|
};
|
|
apiForm.id ? await updateApiInterface({ id: apiForm.id, ...p }) : await createApiInterface(p);
|
|
ElMessage.success(apiForm.id ? '更新成功' : '创建成功');
|
|
apiDialog.visible = false;
|
|
await getApis();
|
|
} catch (e) {
|
|
ElMessage.error(getApiErrorMessage(e) || (apiForm.id ? '更新失败' : '创建失败'));
|
|
} finally {
|
|
apiDialog.saving = false;
|
|
}
|
|
};
|
|
const delApi = (row: any) => {
|
|
ElMessageBox.confirm(`确定删除接口「${row.name}」吗?`, '提示', { type: 'warning' })
|
|
.then(async () => {
|
|
try {
|
|
await deleteApiInterface(String(row.id));
|
|
ElMessage.success('删除成功');
|
|
await getApis();
|
|
} catch (e) {
|
|
ElMessage.error(getApiErrorMessage(e) || '删除失败');
|
|
}
|
|
})
|
|
.catch(() => undefined);
|
|
};
|
|
onMounted(async () => {
|
|
await loadPlatforms();
|
|
await getPlatforms();
|
|
});
|
|
</script>
|