All checks were successful
Build and Deploy Front / deploy (push) Successful in 5m47s
优化运单详情抽屉操作栏与申报表编辑观感,限制我的订单入库后不可编辑;完善接口参数全量替换/脏检查与全局 Message;修复价格表批量填价选中被清与弹窗被遮挡。 Co-authored-by: Cursor <cursoragent@cursor.com>
6363 lines
206 KiB
Vue
6363 lines
206 KiB
Vue
<script lang="ts" setup>
|
||
import { ref, reactive, watch, nextTick, onMounted, onUnmounted, computed } from 'vue';
|
||
import { IconDragArrow, IconPlus, IconDelete, IconCopy, IconSettings, IconImport, IconEraser } from '@arco-design/web-vue/es/icon';
|
||
import FormPro from '@/components/FormPro/index.vue';
|
||
import TablePro from '@/components/TablePro/index.vue';
|
||
import CodeMirror from '@/components/CodeMirror/index.vue';
|
||
import ReturnConfig from '@/views/api/downstreamInterface/comps/ReturnConfig.vue';
|
||
import {
|
||
getFixedParameterGetFixedParameterList,
|
||
postFixedParameterMaintainParameter,
|
||
} from '@/api/ParameterServices/fixedParameter';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { Message } from '@arco-design/web-vue';
|
||
import { random, cloneDeep } from 'lodash';
|
||
import Sortable from 'sortablejs';
|
||
import { validRulesEdit } from '@/views/api/upstreamInterface/config';
|
||
import { getDictionaryGetList } from '@/api/ApplicationServices/dictionary';
|
||
import { postParameterParse, postParameterValidateParameter } from '@/api/ParameterServices/parameter';
|
||
import { $baseMessage, $baseConfirm } from '@/utils';
|
||
import JSON5 from 'json5';
|
||
import SelectPro from '@/components/SelectPro/index.vue';
|
||
import { getMethodText } from '@/views/api/upstreamInterface/utils';
|
||
import {
|
||
buildCurlInterfaceFillPayload,
|
||
buildSmartFillResult,
|
||
} from '@/utils/curlToInterfaceFill';
|
||
import { useTabRowCounts } from '@/utils/useTabRowCounts';
|
||
import { FormKvPlaceholderOptions, ParameterType, FieldPosition } from '@/constants/itfxEnums';
|
||
import {
|
||
flattenTreeTableRows,
|
||
getTreeTableFlatRows,
|
||
isFormUrlEncodedContentType,
|
||
isJsonOrXmlContentType,
|
||
isMappingBodyContentType,
|
||
isNoneContentType,
|
||
normalizeContentType,
|
||
buildOriginalParamIdsFromHydrated,
|
||
createEmptyOriginalParamIds,
|
||
validateTreeParameterPaths,
|
||
type InterfaceDetailSnapshot,
|
||
type OriginalParamIdSets,
|
||
} from '@/utils/interfaceParameterModel';
|
||
import {
|
||
applyJsonCommentsToExistingRows,
|
||
buildCommentedJsonFromKvRows,
|
||
buildCommentedJsonFromParameterFlatList,
|
||
defaultResolveParameterType,
|
||
extractCommentsFromJson,
|
||
flatParameterListToTableRows,
|
||
hoistRedundantSyntheticArrayWrapper,
|
||
parseJsonTextToParameterFlatList,
|
||
pickBestJsonBodyText,
|
||
restoreSyntheticArrayWrapper,
|
||
sortFlatParameterListParentFirst,
|
||
} from '@/utils/jsonParameterTree';
|
||
|
||
const { t } = useI18n();
|
||
|
||
defineOptions({
|
||
name: 'InterfaceDetail',
|
||
});
|
||
|
||
const props = defineProps({
|
||
// 基本参数数据(对象形式,用于只读显示)
|
||
basicParams: {
|
||
type: Object,
|
||
default: () => ({}),
|
||
},
|
||
// 基本参数表单配置(用于编辑模式)
|
||
basicFormItems: {
|
||
type: Array,
|
||
default: () => [],
|
||
},
|
||
// 基本参数表单数据(用于编辑模式)
|
||
basicFormData: {
|
||
type: Object,
|
||
default: () => ({}),
|
||
},
|
||
// 基本参数表单验证规则
|
||
basicFormRules: {
|
||
type: Object,
|
||
default: () => ({}),
|
||
},
|
||
// 是否使用表单编辑模式(true=表单编辑,false=只读显示)
|
||
useFormEdit: {
|
||
type: Boolean,
|
||
default: false,
|
||
},
|
||
// Query 数据
|
||
queryParams: {
|
||
type: Array,
|
||
default: () => [],
|
||
},
|
||
// Request 数据
|
||
requestParams: {
|
||
type: Array,
|
||
default: () => [],
|
||
},
|
||
// Response 数据
|
||
responseParams: {
|
||
type: Array,
|
||
default: () => [],
|
||
},
|
||
// 接口ID(用于返回配置)
|
||
interfaceId: {
|
||
type: [Number, String],
|
||
default: null,
|
||
},
|
||
serviceProviderId: {
|
||
type: [Number, String],
|
||
default: null,
|
||
},
|
||
/** upstream=仅入参树;downstream=Query/Header/Body/Mapping Body */
|
||
parameterMode: {
|
||
type: String as () => 'upstream' | 'downstream',
|
||
default: 'downstream',
|
||
},
|
||
headerParams: {
|
||
type: Array,
|
||
default: () => [],
|
||
},
|
||
bodyFormParams: {
|
||
type: Array,
|
||
default: () => [],
|
||
},
|
||
mappingBodyParams: {
|
||
type: Array,
|
||
default: () => [],
|
||
},
|
||
// 是否显示 Query 容器
|
||
showQuery: {
|
||
type: Boolean,
|
||
default: true,
|
||
},
|
||
// 是否显示返回配置 tab
|
||
showReturnConfig: {
|
||
type: Boolean,
|
||
default: true,
|
||
},
|
||
// 是否在请求/响应容器上方显示请求类型、返回类型单选
|
||
showContentTypeSelectors: {
|
||
type: Boolean,
|
||
default: false,
|
||
},
|
||
});
|
||
|
||
const emit = defineEmits(['add-query', 'add-request', 'add-response', 'parse-request', 'parse-response', 'update:basicFormData', 'return-config-saved']);
|
||
|
||
const refBasicForm = ref();
|
||
const queryTableRef = ref();
|
||
const headerTableRef = ref();
|
||
const bodyFormTableRef = ref();
|
||
const mappingBodyTableRef = ref();
|
||
const queryFixedTableRef = ref();
|
||
const requestTableRef = ref();
|
||
const responseTableRef = ref();
|
||
const returnConfigRef = ref();
|
||
let requestSortable: any = null;
|
||
let mappingBodySortable: any = null;
|
||
|
||
/** Body / Mapping Body 参数树共用列(排序、参数名、必填、类型、描述、操作) */
|
||
const bodyParamTreeColumns = [
|
||
{
|
||
field: 'asdsad',
|
||
title: '排序',
|
||
className: 'sort',
|
||
width: 50,
|
||
slots: { default: 'asdsad' },
|
||
sortable: true,
|
||
},
|
||
{
|
||
field: 'name',
|
||
title: '参数名',
|
||
editRender: { name: '$input', props: { placeholder: '请输入参数名' } },
|
||
slots: { default: 'name', edit: 'name_edit' },
|
||
treeNode: true,
|
||
},
|
||
{
|
||
field: 'isRequired',
|
||
title: '必填',
|
||
width: 56,
|
||
align: 'center',
|
||
slots: { default: 'isRequired' },
|
||
},
|
||
{
|
||
field: 'type',
|
||
title: '参数类型',
|
||
width: 85,
|
||
editRender: {},
|
||
slots: { default: 'type', edit: 'type_edit' },
|
||
},
|
||
{
|
||
field: 'description',
|
||
title: '参数描述',
|
||
editRender: { name: '$input', props: { placeholder: '描述或示例值说明' } },
|
||
slots: { default: 'description', edit: 'description_edit' },
|
||
},
|
||
{
|
||
field: 'action',
|
||
title: '操作',
|
||
fixed: 'right',
|
||
align: 'center',
|
||
width: 140,
|
||
slots: { default: 'action' },
|
||
},
|
||
];
|
||
let responseSortable: any = null;
|
||
|
||
/** 加载接口时快照的参数 id,保存时用于区分新增(1) / 修改(3) */
|
||
const originalParamIds = ref<OriginalParamIdSets>(createEmptyOriginalParamIds());
|
||
|
||
function captureOriginalParamIds(source?: {
|
||
queryParams?: any[];
|
||
headerParams?: any[];
|
||
bodyFormParams?: any[];
|
||
requestParams?: any[];
|
||
mappingBodyParams?: any[];
|
||
responseParams?: any[];
|
||
}) {
|
||
originalParamIds.value = source
|
||
? buildOriginalParamIdsFromHydrated(source)
|
||
: createEmptyOriginalParamIds();
|
||
// 等表格/公共参数/表单回填落稳后再采基线,避免「刚打开就提示未保存」
|
||
void settleDirtyBaseline();
|
||
}
|
||
|
||
watch(
|
||
() => props.interfaceId,
|
||
(id) => {
|
||
if (!id) captureOriginalParamIds();
|
||
},
|
||
);
|
||
|
||
/** 跨重挂载记住每个接口上次打开的 Request / Response Tab */
|
||
const DETAIL_TAB_MEMORY = (globalThis as any).__omsInterfaceDetailTabMemory
|
||
|| ((globalThis as any).__omsInterfaceDetailTabMemory = new Map<string, { requestTab: string; responseTab: string }>());
|
||
|
||
// Request tab 切换
|
||
const requestTab = ref<'query' | 'header' | 'fixed' | 'body' | 'mappingBody' | 'demo'>('body');
|
||
// Response tab 在下方已有,先占位后与记忆联动
|
||
const responseTab = ref<'body' | 'demo' | 'returnConfig'>('body');
|
||
|
||
const PANEL_LAYOUT_KEY = 'oms-interface-detail-panel-layout';
|
||
const panelLayout = ref<'horizontal' | 'vertical'>(
|
||
typeof localStorage !== 'undefined' && localStorage.getItem(PANEL_LAYOUT_KEY) === 'horizontal'
|
||
? 'horizontal'
|
||
: 'vertical',
|
||
);
|
||
function setPanelLayout(layout: 'horizontal' | 'vertical') {
|
||
panelLayout.value = layout;
|
||
try {
|
||
localStorage.setItem(PANEL_LAYOUT_KEY, layout);
|
||
} catch {
|
||
/* ignore quota */
|
||
}
|
||
}
|
||
function onPanelLayoutSwitch(checked: string | number | boolean) {
|
||
setPanelLayout(checked ? 'vertical' : 'horizontal');
|
||
}
|
||
const bodyTreeExpanded = ref(true);
|
||
const mappingBodyTreeExpanded = ref(true);
|
||
const responseTreeExpanded = ref(true);
|
||
|
||
function memoryKey(id: unknown) {
|
||
return id == null || id === '' ? '' : String(id);
|
||
}
|
||
|
||
function saveTabMemory(id: unknown) {
|
||
const key = memoryKey(id);
|
||
if (!key) return;
|
||
DETAIL_TAB_MEMORY.set(key, {
|
||
requestTab: requestTab.value,
|
||
responseTab: responseTab.value,
|
||
});
|
||
}
|
||
|
||
function restoreTabMemory(id: unknown) {
|
||
const key = memoryKey(id);
|
||
if (!key) return;
|
||
const saved = DETAIL_TAB_MEMORY.get(key);
|
||
if (!saved) return;
|
||
const req = saved.requestTab as typeof requestTab.value;
|
||
const res = saved.responseTab as typeof responseTab.value;
|
||
if (req) requestTab.value = req;
|
||
if (res) responseTab.value = res;
|
||
}
|
||
|
||
const formDirtyBaseline = ref('');
|
||
const exampleDirtyBaseline = ref({ request: '', response: '' });
|
||
/** 参数表内容快照:比 VXE recordset / sticky manualDirty 更抗误报 */
|
||
const tablesDirtyBaseline = ref('');
|
||
const manualDirty = ref(false);
|
||
const isDirty = ref(false);
|
||
/** 接口明细加载/回填中:不算未保存,避免误报 */
|
||
const detailHydrating = ref(false);
|
||
let baselineSettleSeq = 0;
|
||
const dirtyBaselineReady = ref(false);
|
||
|
||
function pickFormDirtySnapshot() {
|
||
const d: any = props.basicFormData || {};
|
||
// 字典/SelectPro 常把 number 回写成 string,快照统一成字符串避免误报脏
|
||
const norm = (v: unknown) => (v == null || v === '' ? '' : String(v));
|
||
return JSON.stringify({
|
||
name: norm(d.name),
|
||
abbreviation: norm(d.abbreviation),
|
||
code: norm(d.code),
|
||
description: norm(d.description),
|
||
category: norm(d.category),
|
||
requestMethod: norm(d.requestMethod),
|
||
requestAddress: norm(d.requestAddress),
|
||
requestProtocol: norm(d.requestProtocol),
|
||
contentType: norm(d.contentType),
|
||
responseContentType: norm(d.responseContentType),
|
||
mappedParamType: norm(d.mappedParamType),
|
||
qps: norm(d.qps),
|
||
isBatch: !!d.isBatch,
|
||
});
|
||
}
|
||
|
||
function stabilizeDirtyRows(rows: any[]): any[] {
|
||
return flattenTreeTableRows(Array.isArray(rows) ? rows : [])
|
||
.filter((r) => r && !r.__isBodyRoot && r.id !== '__oms_body_root__')
|
||
.map((r) => ({
|
||
id: r.id ?? r.Id ?? null,
|
||
pId: r.pId ?? r.PId ?? 0,
|
||
name: String(r.name ?? r.Name ?? ''),
|
||
type: r.type ?? r.Type ?? null,
|
||
isRequired: !!(r.isRequired ?? r.IsRequired),
|
||
description: String(r.description ?? r.Description ?? ''),
|
||
cnName: String(r.cnName ?? r.CnName ?? ''),
|
||
alias: String(r.alias ?? r.Alias ?? ''),
|
||
value: String(r.value ?? r.Value ?? ''),
|
||
}))
|
||
.sort((a, b) => String(a.id).localeCompare(String(b.id), 'en'));
|
||
}
|
||
|
||
function pickTablesDirtySnapshot() {
|
||
try {
|
||
const mappingFromGrid =
|
||
mappingBodyTableRef.value?.getTableData?.()?.fullData
|
||
|| mappingBodyTableRef.value?.xGrid?.getTableData?.()?.fullData;
|
||
const responseFromGrid =
|
||
responseTableRef.value?.getTableData?.()?.fullData
|
||
|| responseTableRef.value?.xGrid?.getTableData?.()?.fullData;
|
||
return JSON.stringify({
|
||
query: stabilizeDirtyRows(
|
||
stripCommonRows(
|
||
queryTableRef.value?.getTableData?.()?.fullData
|
||
|| queryTableRef.value?.xGrid?.getTableData?.()?.fullData
|
||
|| queryTableProps.data
|
||
|| [],
|
||
),
|
||
),
|
||
header: stabilizeDirtyRows(
|
||
stripCommonRows(
|
||
headerTableRef.value?.getTableData?.()?.fullData
|
||
|| headerTableRef.value?.xGrid?.getTableData?.()?.fullData
|
||
|| headerTableProps.data
|
||
|| [],
|
||
),
|
||
),
|
||
bodyForm: stabilizeDirtyRows(
|
||
stripCommonRows(
|
||
bodyFormTableRef.value?.getTableData?.()?.fullData
|
||
|| bodyFormTableRef.value?.xGrid?.getTableData?.()?.fullData
|
||
|| bodyFormTableProps.data
|
||
|| [],
|
||
),
|
||
),
|
||
request: stabilizeDirtyRows(getRequestBodyFlatParams()),
|
||
mappingBody: stabilizeDirtyRows(
|
||
getTreeTableFlatRows(mappingFromGrid, mappingBodyTableProps.data),
|
||
),
|
||
response: stabilizeDirtyRows(
|
||
getTreeTableFlatRows(responseFromGrid, responseTableProps.data),
|
||
),
|
||
});
|
||
} catch {
|
||
return '';
|
||
}
|
||
}
|
||
|
||
function actionRowsDirty(getAction?: () => any) {
|
||
const a = getAction?.() || {};
|
||
return (
|
||
(a.insertRecords?.length || 0)
|
||
+ (a.removeRecords?.length || 0)
|
||
+ (a.updateRecords?.length || 0)
|
||
) > 0;
|
||
}
|
||
|
||
function hasUnsavedChanges() {
|
||
// 加载未完成时不提示「有未保存更改」
|
||
if (detailHydrating.value || !dirtyBaselineReady.value) return false;
|
||
if (fixedParamsHasChanges.value) return true;
|
||
if (returnConfigHasChanges.value) return true;
|
||
if (formDirtyBaseline.value && pickFormDirtySnapshot() !== formDirtyBaseline.value) return true;
|
||
if ((requestExample.value || '') !== (exampleDirtyBaseline.value.request || '')) return true;
|
||
if ((responseExample.value || '') !== (exampleDirtyBaseline.value.response || '')) return true;
|
||
// 以参数表内容快照为准(切 tab / SelectPro 回填导致的假 VXE insert、sticky markDirty 不再误报)
|
||
if (tablesDirtyBaseline.value) {
|
||
const currentTables = pickTablesDirtySnapshot();
|
||
if (currentTables && currentTables !== tablesDirtyBaseline.value) return true;
|
||
} else if (
|
||
// 基线尚未采到表快照时,回退 VXE recordset
|
||
actionRowsDirty(() => filterCommonFromActionRows(queryTableRef.value?.getActionRows?.()))
|
||
|| actionRowsDirty(() => filterCommonFromActionRows(headerTableRef.value?.getActionRows?.()))
|
||
|| actionRowsDirty(() => filterCommonFromActionRows(bodyFormTableRef.value?.getActionRows?.()))
|
||
|| actionRowsDirty(() =>
|
||
stripBodyRootFromActionRows(requestTableRef.value?.getActionRows?.() || {}),
|
||
)
|
||
|| actionRowsDirty(() => mappingBodyTableRef.value?.getActionRows?.())
|
||
|| actionRowsDirty(() => responseTableRef.value?.getActionRows?.())
|
||
) {
|
||
return true;
|
||
}
|
||
// sticky manualDirty:仅在内容快照不可用时作补充;有快照且内容一致则清掉误标
|
||
if (manualDirty.value) {
|
||
if (tablesDirtyBaseline.value) {
|
||
manualDirty.value = false;
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
function refreshDirtyState() {
|
||
isDirty.value = hasUnsavedChanges();
|
||
}
|
||
|
||
function markDirty() {
|
||
if (detailHydrating.value) return;
|
||
manualDirty.value = true;
|
||
// 立刻按内容快照重算,避免「点一下必填又点回去」仍显示未保存
|
||
refreshDirtyState();
|
||
}
|
||
|
||
function captureDirtyBaseline() {
|
||
manualDirty.value = false;
|
||
formDirtyBaseline.value = pickFormDirtySnapshot();
|
||
exampleDirtyBaseline.value = {
|
||
request: requestExample.value || '',
|
||
response: responseExample.value || '',
|
||
};
|
||
tablesDirtyBaseline.value = pickTablesDirtySnapshot();
|
||
isDirty.value = false;
|
||
dirtyBaselineReady.value = true;
|
||
}
|
||
|
||
/** 用当前 props.data 再 reload 一次,清掉 VXE keep-source 在回填过程中留下的假 insert/update */
|
||
function reseatParamTables() {
|
||
const reload = (refLike: { value?: { reloadData?: (rows: any[]) => void } }, rows: any[]) => {
|
||
if (!refLike?.value?.reloadData) return;
|
||
refLike.value.reloadData(Array.isArray(rows) ? [...rows] : []);
|
||
};
|
||
reload(queryTableRef, queryTableProps.data);
|
||
reload(headerTableRef, headerTableProps.data);
|
||
reload(bodyFormTableRef, bodyFormTableProps.data);
|
||
reload(mappingBodyTableRef, mappingBodyTableProps.data);
|
||
reload(requestTableRef, requestTableProps.data);
|
||
reload(responseTableRef, responseTableProps.data);
|
||
}
|
||
|
||
/**
|
||
* 等待公共参数合并、表格挂载、FormPro/SelectPro 回填后再采脏检查基线。
|
||
* 解决:选中接口后立刻切 API 调试误报「有未保存的更改」。
|
||
*/
|
||
async function settleDirtyBaseline() {
|
||
const seq = ++baselineSettleSeq;
|
||
detailHydrating.value = true;
|
||
dirtyBaselineReady.value = false;
|
||
manualDirty.value = false;
|
||
isDirty.value = false;
|
||
|
||
await nextTick();
|
||
await nextTick();
|
||
if (seq !== baselineSettleSeq) return;
|
||
|
||
// 等服务商公共参数拉取并合并进 Query/Header/Body
|
||
const waitStart = Date.now();
|
||
while (inheritedCommonParamsLoading.value && Date.now() - waitStart < 4000) {
|
||
await new Promise((r) => setTimeout(r, 40));
|
||
if (seq !== baselineSettleSeq) return;
|
||
}
|
||
|
||
await nextTick();
|
||
reseatParamTables();
|
||
await nextTick();
|
||
if (seq !== baselineSettleSeq) return;
|
||
|
||
captureDirtyBaseline();
|
||
detailHydrating.value = false;
|
||
|
||
// SelectPro/字典异步回写可能再改一帧表单值,二次采基线(仅无手动编辑时)
|
||
await new Promise((r) => setTimeout(r, 120));
|
||
if (seq !== baselineSettleSeq || manualDirty.value) return;
|
||
reseatParamTables();
|
||
await nextTick();
|
||
if (seq !== baselineSettleSeq || manualDirty.value) return;
|
||
captureDirtyBaseline();
|
||
}
|
||
|
||
/** 浏览器关闭/刷新:有未保存更改时提示 */
|
||
function onWindowBeforeUnload(e: BeforeUnloadEvent) {
|
||
if (!hasUnsavedChanges()) return;
|
||
e.preventDefault();
|
||
e.returnValue = '';
|
||
}
|
||
|
||
/**
|
||
* 统一离开确认(切接口 / 切调试 Tab / 父级调用)。
|
||
* resolve true = 可离开(丢弃更改),false = 留下继续编辑。
|
||
*/
|
||
async function confirmLeaveUnsaved(options?: { content?: string }): Promise<boolean> {
|
||
// 仍在回填:用户不可能已编辑,直接放行
|
||
if (detailHydrating.value || !dirtyBaselineReady.value) return true;
|
||
refreshDirtyState();
|
||
if (!hasUnsavedChanges()) return true;
|
||
return new Promise((resolve) => {
|
||
$baseConfirm({
|
||
title: '提示',
|
||
content:
|
||
options?.content
|
||
|| '当前接口明细有未保存的更改,离开后将丢失。保存成功后如需生效还需发布。是否继续离开?',
|
||
okText: '继续离开',
|
||
cancelText: '继续编辑',
|
||
onOk: () => resolve(true),
|
||
onCancel: () => resolve(false),
|
||
});
|
||
});
|
||
}
|
||
|
||
/** 子 Tab(固定配置 / 返回配置)离开:保存并离开 / 继续编辑(不丢弃) */
|
||
async function confirmSaveBeforeLeaveTab(options: {
|
||
content: string;
|
||
save: () => Promise<void>;
|
||
}): Promise<boolean> {
|
||
return new Promise((resolve) => {
|
||
$baseConfirm({
|
||
title: '提示',
|
||
content: options.content,
|
||
okText: '保存并离开',
|
||
cancelText: '继续编辑',
|
||
onOk: async () => {
|
||
try {
|
||
await options.save();
|
||
resolve(true);
|
||
} catch {
|
||
resolve(false);
|
||
}
|
||
},
|
||
onCancel: () => resolve(false),
|
||
});
|
||
});
|
||
}
|
||
|
||
const PARAM_TYPE_LOCKED_TIP = '存在子节点时不可修改类型,请先删除子节点';
|
||
function paramTypeLockedTitle(row: any) {
|
||
return row?.children?.length ? PARAM_TYPE_LOCKED_TIP : undefined;
|
||
}
|
||
|
||
function formatCaughtError(error: unknown, fallback: string) {
|
||
const e = error as any;
|
||
const msg =
|
||
e?.response?.data?.error?.message
|
||
|| e?.response?.data?.message
|
||
|| e?.response?.data?.msg
|
||
|| e?.message
|
||
|| e?.msg;
|
||
if (typeof msg === 'string' && msg.trim() && msg !== 'Error') {
|
||
const text = msg.trim();
|
||
return text.length > 220 ? `${text.slice(0, 220)}…` : text;
|
||
}
|
||
return fallback;
|
||
}
|
||
|
||
function getTableFullData(tableRef: any, fallback?: any[]) {
|
||
return (
|
||
tableRef?.value?.getTableData?.()?.fullData
|
||
|| tableRef?.value?.xGrid?.getTableData?.()?.fullData
|
||
|| fallback
|
||
|| []
|
||
);
|
||
}
|
||
|
||
function validateKvParamRows(rows: any[], label: string): string | null {
|
||
const seen = new Set<string>();
|
||
for (const row of rows || []) {
|
||
if (isCommonParamRow(row)) continue;
|
||
const name = String(row?.name ?? '').trim();
|
||
if (!name) return `${label} 存在未填写参数名的行,请补全或删除空行`;
|
||
const key = name.toLowerCase();
|
||
if (seen.has(key)) return `${label} 参数名重复:「${name}」`;
|
||
seen.add(key);
|
||
}
|
||
return null;
|
||
}
|
||
|
||
function validateTypedTreeRows(rows: any[], label: string): string | null {
|
||
for (const row of rows || []) {
|
||
const name = String(row?.name ?? '').trim();
|
||
if (!name) return `${label} 存在未填写参数名的行,请补全或删除空行`;
|
||
if (row?.type == null || row?.type === '') {
|
||
return `${label} 参数「${name}」未选择类型`;
|
||
}
|
||
}
|
||
return validateTreeParameterPaths(rows || []);
|
||
}
|
||
|
||
/** 保存前轻量校验:重名 / 空名 / 无类型 / 根节点 */
|
||
function validateDetailParamsBeforeSave(): string | null {
|
||
const queryErr = validateKvParamRows(
|
||
getTableFullData(queryTableRef, queryTableProps.data),
|
||
'Query',
|
||
);
|
||
if (queryErr) return queryErr;
|
||
|
||
if (showHeaderTab.value) {
|
||
const headerErr = validateKvParamRows(
|
||
getTableFullData(headerTableRef, headerTableProps.data),
|
||
'Header',
|
||
);
|
||
if (headerErr) return headerErr;
|
||
}
|
||
|
||
if (isBodyKvMode.value) {
|
||
const bodyKvErr = validateKvParamRows(
|
||
getTableFullData(bodyFormTableRef, bodyFormTableProps.data),
|
||
'Body',
|
||
);
|
||
if (bodyKvErr) return bodyKvErr;
|
||
} else if (!isNoneBodyContentType.value) {
|
||
if (showRootMappedParamType.value) {
|
||
const mpt = props.basicFormData?.mappedParamType;
|
||
if (mpt == null || mpt === '') {
|
||
return '请选择 Body 根节点类型(对象 / 数组)';
|
||
}
|
||
const mptNum = Number(mpt);
|
||
if (mptNum !== ParameterType.Object && mptNum !== ParameterType.Array) {
|
||
return 'Body 根节点类型仅支持对象或数组';
|
||
}
|
||
}
|
||
const bodyErr = validateTypedTreeRows(getRequestBodyFlatParams(), 'Body');
|
||
if (bodyErr) return bodyErr;
|
||
}
|
||
|
||
if (showMappingBodyTab.value) {
|
||
const mappingRows = getTreeTableFlatRows(
|
||
getTableFullData(mappingBodyTableRef, mappingBodyTableProps.data),
|
||
mappingBodyTableProps.data,
|
||
);
|
||
const mappingErr = validateTypedTreeRows(mappingRows, 'Mapping Body');
|
||
if (mappingErr) return mappingErr;
|
||
}
|
||
|
||
const responseRows = getTreeTableFlatRows(
|
||
getTableFullData(responseTableRef, responseTableProps.data),
|
||
responseTableProps.data,
|
||
);
|
||
const responseErr = validateTypedTreeRows(responseRows, 'Response');
|
||
if (responseErr) return responseErr;
|
||
|
||
return null;
|
||
}
|
||
|
||
function setBodyTreeExpandAll(expanded: string | number | boolean) {
|
||
const next = !!expanded;
|
||
const grid = requestTableRef.value?.xGrid;
|
||
grid?.setAllTreeExpand?.(next);
|
||
if (!next) grid?.clearTreeExpand?.();
|
||
bodyTreeExpanded.value = next;
|
||
}
|
||
|
||
function setMappingBodyTreeExpandAll(expanded: string | number | boolean) {
|
||
const next = !!expanded;
|
||
const grid = mappingBodyTableRef.value?.xGrid;
|
||
grid?.setAllTreeExpand?.(next);
|
||
if (!next) grid?.clearTreeExpand?.();
|
||
mappingBodyTreeExpanded.value = next;
|
||
}
|
||
|
||
function setResponseTreeExpandAll(expanded: string | number | boolean) {
|
||
const next = !!expanded;
|
||
const grid = responseTableRef.value?.xGrid;
|
||
grid?.setAllTreeExpand?.(next);
|
||
if (!next) grid?.clearTreeExpand?.();
|
||
responseTreeExpanded.value = next;
|
||
}
|
||
|
||
/** 设置面板:一次展开 / 折叠 Request Body、Mapping Body、Response 参数树 */
|
||
function setAllDetailTreesExpand(expanded: string | number | boolean) {
|
||
const next = !!expanded;
|
||
setBodyTreeExpandAll(next);
|
||
setMappingBodyTreeExpandAll(next);
|
||
setResponseTreeExpandAll(next);
|
||
}
|
||
|
||
const allDetailTreesExpanded = computed(
|
||
() => bodyTreeExpanded.value && mappingBodyTreeExpanded.value && responseTreeExpanded.value,
|
||
);
|
||
|
||
const detailSettingsVisible = ref(false);
|
||
|
||
watch(
|
||
() => props.interfaceId,
|
||
(id, oldId) => {
|
||
if (oldId) saveTabMemory(oldId);
|
||
if (id) {
|
||
// 切换接口:进入回填态,避免沿用上一接口的脏标记
|
||
detailHydrating.value = true;
|
||
dirtyBaselineReady.value = false;
|
||
manualDirty.value = false;
|
||
isDirty.value = false;
|
||
nextTick(() => {
|
||
restoreTabMemory(id);
|
||
});
|
||
} else {
|
||
detailHydrating.value = false;
|
||
dirtyBaselineReady.value = false;
|
||
manualDirty.value = false;
|
||
isDirty.value = false;
|
||
}
|
||
},
|
||
);
|
||
|
||
watch(
|
||
() => props.basicFormData,
|
||
() => refreshDirtyState(),
|
||
{ deep: true },
|
||
);
|
||
|
||
onUnmounted(() => {
|
||
saveTabMemory(props.interfaceId);
|
||
});
|
||
|
||
const isDownstreamMode = computed(() => props.parameterMode === 'downstream');
|
||
const showFixedConfigTab = computed(
|
||
() => props.showQuery && !isDownstreamMode.value,
|
||
);
|
||
const showHeaderTab = computed(() => isDownstreamMode.value && props.showQuery);
|
||
|
||
/** 下游:服务商公共参数按位置回落到 Query/Header/Body(只读置灰) */
|
||
const inheritedCommonParams = ref<any[]>([]);
|
||
const inheritedCommonParamsLoading = ref(false);
|
||
|
||
function normalizePositionList(row: any): number[] {
|
||
const list = row?.fieldPositionList;
|
||
if (Array.isArray(list) && list.length) {
|
||
return list.map((x: any) => Number(x)).filter((n: number) => Number.isFinite(n));
|
||
}
|
||
const fp = row?.fieldPositions;
|
||
if (typeof fp === 'string' && fp.trim()) {
|
||
return fp
|
||
.split(',')
|
||
.map((x) => Number(x.trim()))
|
||
.filter((n) => Number.isFinite(n));
|
||
}
|
||
if (Array.isArray(fp)) {
|
||
return fp.map((x: any) => Number(x)).filter((n: number) => Number.isFinite(n));
|
||
}
|
||
return [];
|
||
}
|
||
|
||
function commonParamsForPosition(position: number) {
|
||
return inheritedCommonParams.value.filter((row) =>
|
||
normalizePositionList(row).includes(position),
|
||
);
|
||
}
|
||
|
||
const inheritedQueryParams = computed(() =>
|
||
isDownstreamMode.value ? commonParamsForPosition(FieldPosition.Query) : [],
|
||
);
|
||
const inheritedHeaderParams = computed(() =>
|
||
isDownstreamMode.value ? commonParamsForPosition(FieldPosition.Header) : [],
|
||
);
|
||
const inheritedBodyParams = computed(() =>
|
||
isDownstreamMode.value ? commonParamsForPosition(FieldPosition.Body) : [],
|
||
);
|
||
|
||
function isCommonParamRow(row: any) {
|
||
return !!row?.__fromCommonParams;
|
||
}
|
||
|
||
function stripCommonRows<T extends Record<string, any>>(rows: T[] | undefined | null): T[] {
|
||
return (Array.isArray(rows) ? rows : []).filter((r) => !isCommonParamRow(r));
|
||
}
|
||
|
||
function filterCommonFromActionRows(actions: any) {
|
||
const filterRows = (arr: any[]) =>
|
||
(Array.isArray(arr) ? arr : []).filter((r) => !isCommonParamRow(r));
|
||
return {
|
||
insertRecords: filterRows(actions?.insertRecords),
|
||
removeRecords: filterRows(actions?.removeRecords),
|
||
updateRecords: filterRows(actions?.updateRecords),
|
||
};
|
||
}
|
||
|
||
function toCommonKvRows(list: any[]) {
|
||
return (list || []).map((row, idx) => ({
|
||
__fromCommonParams: true,
|
||
disableEdit: true,
|
||
id: `common-kv-${row.id ?? idx}`,
|
||
name: row.fieldName || '',
|
||
value: row.fieldValue || '',
|
||
description: row.description || '公共参数',
|
||
__commonParamId: row.id,
|
||
}));
|
||
}
|
||
|
||
function mergeCommonKvRows(ownRows: any[] | undefined, commonList: any[]) {
|
||
return [...toCommonKvRows(commonList), ...stripCommonRows(ownRows)];
|
||
}
|
||
|
||
async function applyKvTableWithCommon(
|
||
tableProps: { data: any[] },
|
||
tableRef: { value?: { reloadData?: (rows: any[]) => any } },
|
||
ownRows: any[] | undefined,
|
||
commonList: any[],
|
||
) {
|
||
const next = mergeCommonKvRows(ownRows, commonList);
|
||
tableProps.data = next;
|
||
await nextTick();
|
||
tableRef.value?.reloadData?.(next);
|
||
}
|
||
|
||
async function remergeInheritedCommonIntoKvTables() {
|
||
if (!isDownstreamMode.value) return;
|
||
await applyKvTableWithCommon(
|
||
queryTableProps,
|
||
queryTableRef,
|
||
stripCommonRows(queryTableProps.data),
|
||
inheritedQueryParams.value,
|
||
);
|
||
if (showHeaderTab.value) {
|
||
await applyKvTableWithCommon(
|
||
headerTableProps,
|
||
headerTableRef,
|
||
stripCommonRows(headerTableProps.data),
|
||
inheritedHeaderParams.value,
|
||
);
|
||
}
|
||
await applyKvTableWithCommon(
|
||
bodyFormTableProps,
|
||
bodyFormTableRef,
|
||
stripCommonRows(bodyFormTableProps.data),
|
||
inheritedBodyParams.value,
|
||
);
|
||
refreshTabCounts();
|
||
}
|
||
|
||
async function refreshInheritedCommonParams() {
|
||
const spId = Number(props.serviceProviderId);
|
||
if (!isDownstreamMode.value || !Number.isFinite(spId) || spId <= 0) {
|
||
inheritedCommonParams.value = [];
|
||
await remergeInheritedCommonIntoKvTables();
|
||
return;
|
||
}
|
||
inheritedCommonParamsLoading.value = true;
|
||
try {
|
||
const res: any = await getFixedParameterGetFixedParameterList({
|
||
serviceProviderId: spId,
|
||
});
|
||
const data = res?.data || res || [];
|
||
inheritedCommonParams.value = Array.isArray(data) ? data : [];
|
||
} catch {
|
||
inheritedCommonParams.value = [];
|
||
} finally {
|
||
inheritedCommonParamsLoading.value = false;
|
||
}
|
||
await remergeInheritedCommonIntoKvTables();
|
||
}
|
||
|
||
const isNoneBodyContentType = computed(
|
||
() => isDownstreamMode.value && isNoneContentType(props.basicFormData?.contentType),
|
||
);
|
||
const showMappingBodyTab = computed(
|
||
() => isDownstreamMode.value && isMappingBodyContentType(props.basicFormData?.contentType),
|
||
);
|
||
const isBodyKvMode = computed(
|
||
() => isDownstreamMode.value && isFormUrlEncodedContentType(props.basicFormData?.contentType),
|
||
);
|
||
/**
|
||
* Body 树虚拟根节点(Apifox 样式,导出剥离):
|
||
* - FormUrlEncoded / None 不显示
|
||
* - 有 ContentType 选择器时仅 Json/Xml
|
||
* - 上游无选择器时 Body 树始终显示
|
||
*/
|
||
const showRootMappedParamType = computed(() => {
|
||
if (isBodyKvMode.value || isNoneBodyContentType.value) return false;
|
||
if (props.showContentTypeSelectors || isDownstreamMode.value) {
|
||
return isJsonOrXmlContentType(props.basicFormData?.contentType);
|
||
}
|
||
return true;
|
||
});
|
||
/** 虚拟根节点 id(字符串,避免 vxe 对负数 id 处理异常) */
|
||
const BODY_ROOT_VIRTUAL_ID = '__oms_body_root__';
|
||
function isBodyRootRow(row: any) {
|
||
return !!row && (row.__isBodyRoot === true || row.id === BODY_ROOT_VIRTUAL_ID);
|
||
}
|
||
function isTopLevelBodyPid(pid: any) {
|
||
return (
|
||
pid == null ||
|
||
pid === '' ||
|
||
pid === 0 ||
|
||
pid === '0' ||
|
||
pid === BODY_ROOT_VIRTUAL_ID
|
||
);
|
||
}
|
||
/** 展示时提升掉的合成 array 包装,导出时还原 */
|
||
const hoistedBodyArrayWrapper = ref<any | null>(null);
|
||
function stripBodyRootFromFlat(rows: any[]): any[] {
|
||
const flat = flattenTreeTableRows(Array.isArray(rows) ? rows : []);
|
||
return flat
|
||
.filter((r) => !isBodyRootRow(r))
|
||
.map((r) => (r.pId === BODY_ROOT_VIRTUAL_ID ? { ...r, pId: 0 } : { ...r }));
|
||
}
|
||
function exportRequestBodyFlatParams(rows: any[]): any[] {
|
||
const stripped = stripBodyRootFromFlat(rows);
|
||
if (Number(props.basicFormData?.mappedParamType) !== ParameterType.Array) {
|
||
return stripped;
|
||
}
|
||
return restoreSyntheticArrayWrapper(
|
||
stripped,
|
||
hoistedBodyArrayWrapper.value,
|
||
isTopLevelBodyPid,
|
||
);
|
||
}
|
||
function remapHoistedArrayActionRow(row: any) {
|
||
if (!row || isBodyRootRow(row) || row.pId !== BODY_ROOT_VIRTUAL_ID) return row;
|
||
const wrapper = hoistedBodyArrayWrapper.value;
|
||
if (wrapper && Number(props.basicFormData?.mappedParamType) === ParameterType.Array) {
|
||
return { ...row, pId: wrapper.id };
|
||
}
|
||
return { ...row, pId: 0 };
|
||
}
|
||
function ensureBodyRootInRows(rows: any[], options?: { hoistSyntheticArray?: boolean }): any[] {
|
||
const cleaned = stripBodyRootFromFlat(rows);
|
||
if (!showRootMappedParamType.value) {
|
||
hoistedBodyArrayWrapper.value = null;
|
||
return cleaned;
|
||
}
|
||
const rootType =
|
||
props.basicFormData?.mappedParamType != null && props.basicFormData?.mappedParamType !== ''
|
||
? props.basicFormData.mappedParamType
|
||
: ParameterType.Object;
|
||
const hoisted = hoistRedundantSyntheticArrayWrapper(cleaned, {
|
||
enabled:
|
||
Number(rootType) === ParameterType.Array && options?.hoistSyntheticArray !== false,
|
||
arrayType: ParameterType.Array,
|
||
isTopLevelPid: isTopLevelBodyPid,
|
||
});
|
||
hoistedBodyArrayWrapper.value = hoisted.hoistedWrapper;
|
||
const root = {
|
||
id: BODY_ROOT_VIRTUAL_ID,
|
||
pId: null,
|
||
name: '根节点',
|
||
type: rootType,
|
||
description: '',
|
||
isRequired: false,
|
||
__isBodyRoot: true,
|
||
};
|
||
return [
|
||
root,
|
||
...hoisted.rows.map((r) =>
|
||
isTopLevelBodyPid(r.pId) ? { ...r, pId: BODY_ROOT_VIRTUAL_ID } : { ...r },
|
||
),
|
||
];
|
||
}
|
||
function applyRequestBodyTableData(rows: any[]) {
|
||
const next = ensureBodyRootInRows(rows);
|
||
requestTableProps.data = next as any[];
|
||
nextTick(() => {
|
||
requestTableRef.value?.reloadData?.(next);
|
||
const xGrid = requestTableRef.value?.xGrid;
|
||
if (showRootMappedParamType.value && xGrid?.setAllTreeExpand) {
|
||
xGrid.setAllTreeExpand(true);
|
||
}
|
||
});
|
||
}
|
||
function getRequestBodyFlatParams() {
|
||
const fromGrid =
|
||
requestTableRef.value?.getTableData?.()?.fullData ||
|
||
requestTableRef.value?.xGrid?.getTableData()?.fullData;
|
||
return exportRequestBodyFlatParams(getTreeTableFlatRows(fromGrid, requestTableProps.data));
|
||
}
|
||
function stripBodyRootFromActionRows(actions: any) {
|
||
const filterRows = (arr: any[]) =>
|
||
(Array.isArray(arr) ? arr.filter((r) => !isBodyRootRow(r)).map(remapHoistedArrayActionRow) : []);
|
||
return {
|
||
insertRecords: filterRows(actions?.insertRecords),
|
||
removeRecords: filterRows(actions?.removeRecords),
|
||
updateRecords: filterRows(actions?.updateRecords),
|
||
};
|
||
}
|
||
const kvPlaceholderOptions = computed(() => FormKvPlaceholderOptions);
|
||
const requestExample = ref<string>(''); // Demo内容
|
||
const requestExampleEditorRef = ref<any>(); // Demo编辑器引用
|
||
|
||
// 检查是否有Response参数
|
||
const hasResponseParams = computed(() => {
|
||
return props.responseParams && props.responseParams.length > 0;
|
||
});
|
||
const responseExample = ref<string>(''); // Demo内容
|
||
const responseExampleEditorRef = ref<any>(); // Demo编辑器引用
|
||
|
||
function relayoutExampleEditors() {
|
||
nextTick(() => {
|
||
requestExampleEditorRef.value?.getEditor?.()?.requestMeasure?.();
|
||
responseExampleEditorRef.value?.getEditor?.()?.requestMeasure?.();
|
||
});
|
||
}
|
||
|
||
watch(panelLayout, () => relayoutExampleEditors());
|
||
watch(requestTab, (tab) => {
|
||
if (tab === 'demo') relayoutExampleEditors();
|
||
});
|
||
watch(responseTab, (tab) => {
|
||
if (tab === 'demo') relayoutExampleEditors();
|
||
});
|
||
|
||
watch([requestExample, responseExample], () => refreshDirtyState());
|
||
|
||
// 解析弹窗相关状态
|
||
const drawerVisible = ref<boolean>(false); // Request 参数解析弹窗
|
||
const drawerVisible1 = ref<boolean>(false); // Response 参数解析弹窗
|
||
|
||
// 返回配置相关状态
|
||
const returnConfigHasChanges = ref<boolean>(false); // 返回配置是否有未保存的更改
|
||
const analysisLoading = ref<boolean>(false); // 解析loading
|
||
const importLoading = ref<boolean>(false); // 导入loading
|
||
const tabs = ref<'Json' | 'Xml'>('Json'); // Request 解析标签页
|
||
const tabs1 = ref<'Json' | 'Xml'>('Json'); // Response 解析标签页
|
||
const textareaJson = ref<string>(''); // Request Json文本域
|
||
const textareaXml = ref<string>(''); // Request Xml文本域
|
||
const textareaJson1 = ref<string>(''); // Response Json文本域
|
||
const textareaXml1 = ref<string>(''); // Response Xml文本域
|
||
const jsonEditorRef = ref<any>(); // Request Json编辑器引用
|
||
const xmlEditorRef = ref<any>(); // Request Xml编辑器引用
|
||
const jsonEditorRef1 = ref<any>(); // Response Json编辑器引用
|
||
const xmlEditorRef1 = ref<any>(); // Response Xml编辑器引用
|
||
const dataList = ref<any[] | undefined>(); // Request 解析后的数据列表
|
||
const dataList1 = ref<any[] | undefined>(); // Response 解析后的数据列表
|
||
|
||
const analysisBusy = computed(() => analysisLoading.value || importLoading.value);
|
||
const requestImportContent = computed(
|
||
() => String(tabs.value === 'Json' ? textareaJson.value : textareaXml.value || '').trim(),
|
||
);
|
||
const responseImportContent = computed(
|
||
() => String(tabs1.value === 'Json' ? textareaJson1.value : textareaXml1.value || '').trim(),
|
||
);
|
||
|
||
// 请求类型、返回类型、根节点选项(用于单选/下拉)
|
||
const contentTypeOptions = ref<any[]>([]);
|
||
const responseContentTypeOptions = ref<any[]>([]);
|
||
const mappedParamTypeOptions = ref<any[]>([]);
|
||
const requestMethodOptions = ref<any[]>([]);
|
||
|
||
// 只读模式下显示的请求方式文本
|
||
const displayRequestMethod = computed(() => {
|
||
const method = (props.basicParams as any)?.requestMethod;
|
||
return method !== undefined && method !== null ? getMethodText(method) : '';
|
||
});
|
||
|
||
// 过滤后的基本表单配置(排除 requestMethod、requestAddress 由上方 header 渲染;排除 contentType、responseContentType、mappedParamType,当 showContentTypeSelectors 时由上方栏渲染)
|
||
const filteredBasicFormItems = computed(() => {
|
||
return (props.basicFormItems || []).filter(
|
||
(item: any) =>
|
||
item?.field !== 'requestMethod' &&
|
||
item?.field !== 'requestAddress' &&
|
||
(item?.field !== 'contentType' || !props.showContentTypeSelectors) &&
|
||
(item?.field !== 'responseContentType' || !props.showContentTypeSelectors) &&
|
||
(item?.field !== 'mappedParamType' || !props.showContentTypeSelectors)
|
||
);
|
||
});
|
||
|
||
// 基本参数表单项(强制 span=4,使每行放 6 个输入框)
|
||
const basicFormItemsForLayout = computed(() => {
|
||
return filteredBasicFormItems.value.map((item: any) => ({
|
||
...item,
|
||
span: 4,
|
||
}));
|
||
});
|
||
|
||
// 只读模式下基本参数显示(排除 requestMethod、requestAddress,由上方 header 渲染)
|
||
const basicParamsForDisplay = computed(() => {
|
||
const params = props.basicParams || {};
|
||
const { requestMethod, requestAddress, ...rest } = params as Record<string, any>;
|
||
return rest;
|
||
});
|
||
|
||
// 加载请求方式选项(用于 header 中的请求方式下拉)
|
||
async function loadRequestMethodOptions() {
|
||
try {
|
||
const res = await getDictionaryGetList({ type: 'RequestMethod' });
|
||
requestMethodOptions.value = Array.isArray(res) ? res : ((res as any)?.data || []);
|
||
} catch (e) {
|
||
console.error('加载请求方式选项失败:', e);
|
||
}
|
||
}
|
||
|
||
// 加载请求类型、返回类型、根节点选项
|
||
async function loadContentTypeOptions() {
|
||
if (!props.showContentTypeSelectors) return;
|
||
try {
|
||
const [ctRes, rctRes, mptRes] = await Promise.all([
|
||
getDictionaryGetList({ type: 'ContentType' }),
|
||
getDictionaryGetList({ type: 'ResponseContentType' }),
|
||
getDictionaryGetList({ type: 'ParameterType' }),
|
||
]);
|
||
const normalizeDictKey = (list: any[]) =>
|
||
(list || []).map((item) => {
|
||
const keyNum = Number(item?.key);
|
||
return {
|
||
...item,
|
||
key: Number.isNaN(keyNum) ? item?.key : keyNum,
|
||
};
|
||
});
|
||
const ctList = Array.isArray(ctRes) ? ctRes : ((ctRes as any)?.data || []);
|
||
contentTypeOptions.value = normalizeDictKey(ctList);
|
||
responseContentTypeOptions.value = Array.isArray(rctRes) ? rctRes : ((rctRes as any)?.data || []);
|
||
mappedParamTypeOptions.value = Array.isArray(mptRes) ? mptRes : ((mptRes as any)?.data || []);
|
||
} catch (e) {
|
||
console.error('加载请求/返回类型选项失败:', e);
|
||
}
|
||
}
|
||
|
||
function updateContentType(value: any) {
|
||
const contentType = normalizeContentType(value);
|
||
emit('update:basicFormData', { ...props.basicFormData, contentType });
|
||
}
|
||
|
||
function updateResponseContentType(value: any) {
|
||
emit('update:basicFormData', { ...props.basicFormData, responseContentType: value });
|
||
}
|
||
|
||
function updateMappedParamType(value: any) {
|
||
emit('update:basicFormData', { ...props.basicFormData, mappedParamType: value });
|
||
}
|
||
|
||
// 参数类型文字色(按语义分类)
|
||
const PARAMETER_TYPE_TEXT_COLORS = {
|
||
number: '#1677ff',
|
||
string: '#8c8c8c',
|
||
boolean: '#00b42a',
|
||
array: '#fa8c16',
|
||
object: '#9254de',
|
||
null: '#8c8c8c',
|
||
date: '#08979c',
|
||
other: '#f5222d',
|
||
} as const;
|
||
type ParameterTypeTextKind = keyof typeof PARAMETER_TYPE_TEXT_COLORS;
|
||
|
||
function resolveParameterTypeTextKind(typeKey?: any, label?: any): ParameterTypeTextKind {
|
||
const keyNum = Number(typeKey);
|
||
if (keyNum === ParameterType.String) return 'string';
|
||
if (keyNum === ParameterType.Float || keyNum === ParameterType.Integer) return 'number';
|
||
if (keyNum === ParameterType.Boolean) return 'boolean';
|
||
if (keyNum === ParameterType.Array) return 'array';
|
||
if (keyNum === ParameterType.Object) return 'object';
|
||
if (keyNum === ParameterType.DateTime || keyNum === ParameterType.DateTimeOffset) return 'date';
|
||
|
||
const text = String(label ?? '').toLowerCase();
|
||
if (!text) return 'other';
|
||
if (/(null|undefined|空值)/.test(text)) return 'null';
|
||
if (/(array|数组|列表|list)/.test(text)) return 'array';
|
||
if (/(object|对象|结构体|struct)/.test(text)) return 'object';
|
||
if (/(bool|布尔)/.test(text)) return 'boolean';
|
||
if (/(datetime|date|time|日期|时间)/.test(text)) return 'date';
|
||
if (/(int|float|double|number|数字|整数|小数)/.test(text)) return 'number';
|
||
if (/(string|str|字符串)/.test(text)) return 'string';
|
||
return 'other';
|
||
}
|
||
|
||
function getTypeTextStyleByKind(kind: ParameterTypeTextKind) {
|
||
const style: { color: string; fontWeight?: 600 } = {
|
||
color: PARAMETER_TYPE_TEXT_COLORS[kind],
|
||
};
|
||
if (kind === 'array' || kind === 'object') {
|
||
style.fontWeight = 600;
|
||
}
|
||
return style;
|
||
}
|
||
|
||
function getTypeTextStyleByIndex(_index: number, option?: any) {
|
||
const kind = resolveParameterTypeTextKind(option?.key, option?.value ?? option?.label);
|
||
return getTypeTextStyleByKind(kind);
|
||
}
|
||
|
||
function getParameterTypeTextStyle(typeKey: any) {
|
||
const item = ParameterTypeList.value.find((x: any) => x.key === typeKey);
|
||
const kind = resolveParameterTypeTextKind(typeKey, item?.value ?? item?.label);
|
||
return getTypeTextStyleByKind(kind);
|
||
}
|
||
|
||
// 根节点仅允许对象 / 数组
|
||
const rootMappedParamTypeOptions = computed(() =>
|
||
(mappedParamTypeOptions.value || []).filter((opt: any) => {
|
||
const kind = resolveParameterTypeTextKind(opt?.key, opt?.value ?? opt?.label);
|
||
return kind === 'object' || kind === 'array';
|
||
}),
|
||
);
|
||
|
||
// 根节点选中项(彩色文字)
|
||
const selectedMappedParamOption = computed(() => {
|
||
const key = props.basicFormData?.mappedParamType;
|
||
if (key === undefined || key === null) return null;
|
||
const opt =
|
||
rootMappedParamTypeOptions.value.find((item: any) => item.key === key) ||
|
||
mappedParamTypeOptions.value.find((item: any) => item.key === key);
|
||
if (!opt) return null;
|
||
return { label: opt.value, ...getTypeTextStyleByIndex(0, opt) };
|
||
});
|
||
|
||
const mappedParamTypePopoverVisible = ref(false);
|
||
function pickMappedParamType(typeKey: any) {
|
||
const opt = rootMappedParamTypeOptions.value.find((item: any) => item.key === typeKey);
|
||
if (!opt) return;
|
||
updateMappedParamType(typeKey);
|
||
const data = requestTableProps.data || [];
|
||
const root = data.find((r: any) => isBodyRootRow(r));
|
||
if (root) root.type = typeKey;
|
||
mappedParamTypePopoverVisible.value = false;
|
||
}
|
||
|
||
const paramTypePopoverRowId = ref<string | number | null>(null);
|
||
function onParamTypePopoverVisibleChange(row: any, visible: boolean) {
|
||
if (row?.children?.length) return;
|
||
if (visible) {
|
||
paramTypePopoverRowId.value = row.id;
|
||
return;
|
||
}
|
||
if (paramTypePopoverRowId.value === row.id) {
|
||
paramTypePopoverRowId.value = null;
|
||
}
|
||
}
|
||
function pickParameterType(row: any, typeKey: any) {
|
||
if (!row || row.children?.length) return;
|
||
row.type = typeKey;
|
||
paramTypePopoverRowId.value = null;
|
||
markDirty();
|
||
}
|
||
|
||
// Query 表格配置(使用下游接口的配置方式)
|
||
const queryTableProps = reactive<any>({
|
||
columns: [
|
||
{
|
||
field: 'name',
|
||
title: '参数名',
|
||
editRender: { name: '$input', props: { placeholder: '请输入参数名' } },
|
||
slots: { default: 'name', edit: 'name_edit' },
|
||
},
|
||
{
|
||
field: 'value',
|
||
title: '参数值',
|
||
editRender: { name: '$input', props: { placeholder: '请输入参数值' } },
|
||
slots: { default: 'value', edit: 'value_edit' },
|
||
},
|
||
{
|
||
field: 'description',
|
||
title: '参数描述',
|
||
editRender: { name: '$input', props: { placeholder: '请输入描述' } },
|
||
slots: { default: 'description', edit: 'description_edit' },
|
||
},
|
||
{
|
||
field: 'action',
|
||
title: '操作',
|
||
fixed: 'right',
|
||
align: 'center',
|
||
width: 100,
|
||
slots: { default: 'action' },
|
||
},
|
||
],
|
||
isCellSort: false,
|
||
showToolbar: false,
|
||
isColumnsDrag: false,
|
||
showPager: false,
|
||
tableConfig: {
|
||
editConfig: {
|
||
trigger: 'click',
|
||
mode: 'row',
|
||
showStatus: true,
|
||
autoClear: false,
|
||
beforeEditMethod: ({ row }: { row: any }) => !isCommonParamRow(row),
|
||
},
|
||
rowClassName: ({ row }: { row: any }) => (isCommonParamRow(row) ? 'row-common-param' : ''),
|
||
},
|
||
showIndex: false,
|
||
data: [] as any[],
|
||
minHeight: 150,
|
||
keepSource: true,
|
||
size: 'small',
|
||
useForm: false,
|
||
autoHeight: false,
|
||
height: '100%',
|
||
editRules: validRulesEdit.value,
|
||
toolbarConfig: {
|
||
setting: false
|
||
},
|
||
});
|
||
|
||
const headerTableProps = reactive<any>({
|
||
...queryTableProps,
|
||
data: [] as any[],
|
||
});
|
||
const bodyFormTableProps = reactive<any>({
|
||
...queryTableProps,
|
||
data: [] as any[],
|
||
});
|
||
|
||
watch(
|
||
() => [props.serviceProviderId, props.parameterMode] as const,
|
||
() => {
|
||
refreshInheritedCommonParams();
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
// Query 固定配置表格(不传 height,随内容自然增高,与 Query 列表的固定高度区分)
|
||
const queryFixedTableProps = computed(() => ({
|
||
columns: [
|
||
{
|
||
field: 'fieldName',
|
||
title: '参数名',
|
||
editRender: { name: '$input', props: { placeholder: '请输入参数名' } },
|
||
slots: { default: 'fieldName', edit: 'fieldName_edit' },
|
||
},
|
||
{
|
||
field: 'fieldValue',
|
||
title: '参数值',
|
||
editRender: { name: '$input', props: { placeholder: '请输入参数值' } },
|
||
slots: { default: 'fieldValue', edit: 'fieldValue_edit' },
|
||
},
|
||
{
|
||
field: 'fieldPositions',
|
||
title: '位置',
|
||
editRender: {},
|
||
slots: { default: 'fieldPositions', edit: 'fieldPositions_edit' },
|
||
},
|
||
{
|
||
field: 'action',
|
||
title: '操作',
|
||
width: 100,
|
||
align: 'center',
|
||
fixed: 'right',
|
||
slots: { default: 'action' },
|
||
},
|
||
],
|
||
showPager: false,
|
||
showToolbar: false,
|
||
keepSource: true,
|
||
tableConfig: {
|
||
// 不传 height,vxe-table 的 height:'auto' 是铺满父容器,会固定高度;不传则随内容增高
|
||
data: fixedParams.value,
|
||
editConfig: {
|
||
trigger: 'click',
|
||
mode: 'row',
|
||
showStatus: true,
|
||
autoClear: false,
|
||
},
|
||
},
|
||
showIndex: false,
|
||
useForm: false,
|
||
size: 'small',
|
||
autoHeight: false,
|
||
editRules: {},
|
||
}));
|
||
|
||
// 与 Body 树分列配置副本,避免共用 columns 被 vxe 改写宽度后,切 Tab 时出现「先缩后撑」
|
||
const mappingBodyTableProps = reactive<any>({
|
||
columns: cloneDeep(bodyParamTreeColumns),
|
||
isCellSort: false,
|
||
showToolbar: false,
|
||
isColumnsDrag: false,
|
||
showPager: false,
|
||
data: [] as any[],
|
||
minHeight: 150,
|
||
keepSource: true,
|
||
size: 'small',
|
||
useForm: false,
|
||
autoHeight: false,
|
||
height: '100%',
|
||
editRules: validRulesEdit.value,
|
||
toolbarConfig: {
|
||
setting: false,
|
||
},
|
||
tableConfig: {
|
||
editConfig: {
|
||
trigger: 'click',
|
||
mode: 'row',
|
||
showStatus: false,
|
||
autoClear: false,
|
||
},
|
||
},
|
||
});
|
||
|
||
const requestTableProps = reactive<any>({
|
||
columns: cloneDeep(bodyParamTreeColumns),
|
||
isCellSort: false,
|
||
showToolbar: false,
|
||
isColumnsDrag: false,
|
||
showPager: false,
|
||
tableConfig: {
|
||
editConfig: {
|
||
trigger: 'click',
|
||
mode: 'row',
|
||
showStatus: false,
|
||
autoClear: false,
|
||
},
|
||
},
|
||
showIndex: false,
|
||
data: [] as any[],
|
||
minHeight: 150,
|
||
keepSource: true,
|
||
size: 'small',
|
||
useForm: false,
|
||
autoHeight: false,
|
||
height: '100%',
|
||
editRules: validRulesEdit.value,
|
||
toolbarConfig: {
|
||
setting: false
|
||
},
|
||
});
|
||
|
||
// Response Parameters 表格配置(使用下游接口的配置方式)
|
||
const responseTableProps = reactive<any>({
|
||
columns: [
|
||
{
|
||
field: 'asdsad',
|
||
title: '排序',
|
||
className: 'sort',
|
||
width: 50,
|
||
slots: {
|
||
default: 'asdsad',
|
||
},
|
||
sortable: true,
|
||
},
|
||
{
|
||
field: 'name',
|
||
title: '参数名',
|
||
editRender: { name: '$input', props: { placeholder: '请输入参数名' } },
|
||
slots: { default: 'name', edit: 'name_edit' },
|
||
treeNode: true,
|
||
},
|
||
{
|
||
field: 'isRequired',
|
||
title: '必填',
|
||
width: 56,
|
||
align: 'center',
|
||
slots: { default: 'isRequired' },
|
||
},
|
||
{
|
||
field: 'type',
|
||
title: '参数类型',
|
||
width: 85,
|
||
editRender: {},
|
||
slots: { default: 'type', edit: 'type_edit' },
|
||
},
|
||
{
|
||
field: 'description',
|
||
title: '参数描述',
|
||
editRender: { name: '$input', props: { placeholder: '描述或示例值说明' } },
|
||
slots: { default: 'description', edit: 'description_edit' },
|
||
},
|
||
{
|
||
field: 'action',
|
||
title: '操作',
|
||
fixed: 'right',
|
||
align: 'center',
|
||
width: 128,
|
||
slots: { default: 'action' },
|
||
},
|
||
],
|
||
isCellSort: false,
|
||
showToolbar: false,
|
||
isColumnsDrag: false,
|
||
showPager: false,
|
||
tableConfig: {
|
||
editConfig: {
|
||
trigger: 'click',
|
||
mode: 'row',
|
||
showStatus: false,
|
||
autoClear: false,
|
||
},
|
||
},
|
||
showIndex: false,
|
||
data: [] as any[],
|
||
minHeight: 150,
|
||
keepSource: true,
|
||
size: 'small',
|
||
useForm: false,
|
||
autoHeight: false,
|
||
height: '100%',
|
||
editRules: validRulesEdit.value,
|
||
toolbarConfig: {
|
||
setting: false
|
||
},
|
||
});
|
||
|
||
const { refresh: refreshTabCounts, countFromTable, revision: tabCountRevision } = useTabRowCounts();
|
||
|
||
const queryTabCount = computed(() =>
|
||
countFromTable(queryTableRef, () => queryTableProps.data),
|
||
);
|
||
const headerTabCount = computed(() =>
|
||
countFromTable(headerTableRef, () => headerTableProps.data),
|
||
);
|
||
const bodyFormTabCount = computed(() =>
|
||
countFromTable(bodyFormTableRef, () => bodyFormTableProps.data),
|
||
);
|
||
const requestBodyTabCount = computed(() => {
|
||
if (isNoneBodyContentType.value) return 0;
|
||
if (isBodyKvMode.value) {
|
||
return countFromTable(bodyFormTableRef, () => bodyFormTableProps.data);
|
||
}
|
||
void tabCountRevision.value;
|
||
return getRequestBodyFlatParams().length;
|
||
});
|
||
/** Body 树仅有虚拟根 / 无真实字段时展示空态指引 */
|
||
const isBodyTreeEmpty = computed(() => {
|
||
void tabCountRevision.value;
|
||
return getRequestBodyFlatParams().length === 0;
|
||
});
|
||
const isBodyKvEmpty = computed(
|
||
() => countFromTable(bodyFormTableRef, () => bodyFormTableProps.data) === 0,
|
||
);
|
||
const isMappingBodyEmpty = computed(
|
||
() => countFromTable(mappingBodyTableRef, () => mappingBodyTableProps.data) === 0,
|
||
);
|
||
const mappingBodyTabCount = computed(() =>
|
||
countFromTable(mappingBodyTableRef, () => mappingBodyTableProps.data),
|
||
);
|
||
const fixedConfigTabCount = computed(() =>
|
||
countFromTable(queryFixedTableRef, () => fixedParams.value),
|
||
);
|
||
const responseBodyTabCount = computed(() =>
|
||
countFromTable(responseTableRef, () => responseTableProps.data),
|
||
);
|
||
|
||
const requestTabItems = computed(() => {
|
||
const items: Array<{ key: string; label: string }> = [];
|
||
if (props.showQuery) {
|
||
items.push({ key: 'query', label: `Query (${queryTabCount.value})` });
|
||
}
|
||
if (showHeaderTab.value) {
|
||
items.push({ key: 'header', label: `Header (${headerTabCount.value})` });
|
||
}
|
||
items.push({
|
||
key: 'body',
|
||
label: isNoneBodyContentType.value
|
||
? 'Body (none)'
|
||
: `Body (${requestBodyTabCount.value})`,
|
||
});
|
||
if (showMappingBodyTab.value) {
|
||
items.push({
|
||
key: 'mappingBody',
|
||
label: `Mapping Body (${mappingBodyTabCount.value})`,
|
||
});
|
||
}
|
||
items.push({ key: 'demo', label: 'cURL' });
|
||
if (showFixedConfigTab.value) {
|
||
items.push({
|
||
key: 'fixed',
|
||
label: `固定配置 (${fixedConfigTabCount.value})`,
|
||
});
|
||
}
|
||
return items;
|
||
});
|
||
|
||
const responseTabItems = computed(() => {
|
||
const items: Array<{ key: string; label: string; disabled?: boolean }> = [
|
||
{ key: 'body', label: `Response (${responseBodyTabCount.value})` },
|
||
];
|
||
if (props.showReturnConfig) {
|
||
items.push({
|
||
key: 'returnConfig',
|
||
label: '返回配置',
|
||
disabled: !hasResponseParams.value,
|
||
});
|
||
}
|
||
items.push({ key: 'demo', label: '示例' });
|
||
return items;
|
||
});
|
||
|
||
const requestContentTypeItems = computed(() =>
|
||
(contentTypeOptions.value || []).map((opt: any) => ({
|
||
key: String(opt.key),
|
||
label: String(opt.value ?? opt.key),
|
||
})),
|
||
);
|
||
|
||
const responseContentTypeItems = computed(() =>
|
||
(responseContentTypeOptions.value || []).map((opt: any) => ({
|
||
key: String(opt.key),
|
||
label: String(opt.value ?? opt.key),
|
||
})),
|
||
);
|
||
|
||
const analysisTypeItems = [
|
||
{ key: 'Json', label: 'JSON' },
|
||
{ key: 'Xml', label: 'XML' },
|
||
];
|
||
|
||
const currentRequestTabClearLabel = computed(() => {
|
||
if (requestTab.value === 'query') return 'Query 参数';
|
||
if (requestTab.value === 'header') return 'Header 参数';
|
||
if (requestTab.value === 'fixed') return '固定配置';
|
||
if (requestTab.value === 'body') return 'Body 参数';
|
||
if (requestTab.value === 'mappingBody') return 'Mapping Body 参数';
|
||
if (requestTab.value === 'demo') return 'cURL 内容';
|
||
return '当前 Tab';
|
||
});
|
||
|
||
const showRequestTabClearAction = computed(() => {
|
||
if (requestTab.value === 'body' && isNoneBodyContentType.value) return false;
|
||
return ['query', 'header', 'fixed', 'body', 'mappingBody', 'demo'].includes(requestTab.value);
|
||
});
|
||
|
||
/** Body 参数树(非 KV)把「清空」放在根节点操作列,不再占顶栏 */
|
||
const isBodyTreeClearInRoot = computed(
|
||
() =>
|
||
requestTab.value === 'body'
|
||
&& !isNoneBodyContentType.value
|
||
&& !isBodyKvMode.value,
|
||
);
|
||
|
||
const canClearCurrentRequestTab = computed(() => {
|
||
if (!showRequestTabClearAction.value) return false;
|
||
if (requestTab.value === 'query') {
|
||
return stripCommonRows(getTableFullData(queryTableRef, queryTableProps.data)).length > 0;
|
||
}
|
||
if (requestTab.value === 'header') {
|
||
return stripCommonRows(getTableFullData(headerTableRef, headerTableProps.data)).length > 0;
|
||
}
|
||
if (requestTab.value === 'fixed') return fixedConfigTabCount.value > 0;
|
||
if (requestTab.value === 'body') {
|
||
if (isBodyKvMode.value) {
|
||
return stripCommonRows(getTableFullData(bodyFormTableRef, bodyFormTableProps.data)).length > 0;
|
||
}
|
||
return !isBodyTreeEmpty.value;
|
||
}
|
||
if (requestTab.value === 'mappingBody') return !isMappingBodyEmpty.value;
|
||
if (requestTab.value === 'demo') return !!(requestExample.value || '').trim();
|
||
return false;
|
||
});
|
||
|
||
// 监听 queryParams prop 变化,同步到表格数据(并合并公共参数)
|
||
watch(
|
||
() => props.queryParams,
|
||
async (newVal: any) => {
|
||
if (!newVal || !Array.isArray(newVal)) return;
|
||
const own = stripCommonRows(newVal);
|
||
const currentOwn = stripCommonRows(queryTableProps.data || []);
|
||
if (
|
||
currentOwn.length !== own.length
|
||
|| JSON.stringify(currentOwn) !== JSON.stringify(own)
|
||
) {
|
||
await applyKvTableWithCommon(
|
||
queryTableProps,
|
||
queryTableRef,
|
||
own,
|
||
inheritedQueryParams.value,
|
||
);
|
||
}
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
function syncKvTableProps(
|
||
propList: any[] | undefined,
|
||
tableProps: { data: any[] },
|
||
tableRef: typeof queryTableRef,
|
||
commonList: any[],
|
||
) {
|
||
if (!propList || !Array.isArray(propList)) return;
|
||
const own = stripCommonRows(propList);
|
||
const currentOwn = stripCommonRows(tableProps.data || []);
|
||
if (
|
||
currentOwn.length !== own.length
|
||
|| JSON.stringify(currentOwn) !== JSON.stringify(own)
|
||
) {
|
||
applyKvTableWithCommon(tableProps, tableRef, own, commonList);
|
||
}
|
||
}
|
||
|
||
watch(
|
||
() => props.headerParams,
|
||
(newVal) =>
|
||
syncKvTableProps(
|
||
newVal as any[],
|
||
headerTableProps,
|
||
headerTableRef,
|
||
inheritedHeaderParams.value,
|
||
),
|
||
{ immediate: true },
|
||
);
|
||
watch(
|
||
() => props.bodyFormParams,
|
||
(newVal) =>
|
||
syncKvTableProps(
|
||
newVal as any[],
|
||
bodyFormTableProps,
|
||
bodyFormTableRef,
|
||
inheritedBodyParams.value,
|
||
),
|
||
{ immediate: true },
|
||
);
|
||
watch(
|
||
() => props.mappingBodyParams,
|
||
(newVal: any) => {
|
||
if (!Array.isArray(newVal)) return;
|
||
const currentData = mappingBodyTableProps.data || [];
|
||
const incomingFlat = flattenTreeTableRows(newVal);
|
||
const currentFlat = flattenTreeTableRows(currentData);
|
||
if (incomingFlat.length === 0 && currentFlat.length > 0) return;
|
||
if (incomingFlat.length < currentFlat.length && currentFlat.length > 0) return;
|
||
const rows = incomingFlat.length ? incomingFlat : newVal;
|
||
if (
|
||
currentFlat.length !== rows.length
|
||
|| JSON.stringify(currentFlat) !== JSON.stringify(rows)
|
||
) {
|
||
mappingBodyTableProps.data = [...rows] as any[];
|
||
mappingBodyTableRef.value?.reloadData?.([...rows]);
|
||
}
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
watch(showMappingBodyTab, (visible) => {
|
||
if (!visible && requestTab.value === 'mappingBody') {
|
||
requestTab.value = 'body';
|
||
}
|
||
});
|
||
|
||
// Json Body 树 → 切 FormUrlEncoded / None 时迁入 Mapping Body
|
||
watch(
|
||
() => normalizeContentType(props.basicFormData?.contentType),
|
||
async (ct, prev) => {
|
||
if (!isDownstreamMode.value) return;
|
||
const toMapping = isMappingBodyContentType(ct) && !isMappingBodyContentType(prev);
|
||
if (!toMapping) return;
|
||
const requestFlat = getRequestBodyFlatParams();
|
||
const mappingFlat = flattenTreeTableRows(mappingBodyTableProps.data || []);
|
||
if (requestFlat.length > 0 && mappingFlat.length < requestFlat.length) {
|
||
await loadFlatListIntoTreeTable(requestFlat, mappingBodyTableProps, mappingBodyTableRef);
|
||
applyRequestBodyTableData([]);
|
||
refreshTabCounts();
|
||
}
|
||
},
|
||
);
|
||
|
||
watch(isBodyKvMode, (kv) => {
|
||
if (kv && requestTab.value === 'body' && !isBodyKvMode.value) return;
|
||
});
|
||
|
||
// 检查固定配置是否有未保存的更改
|
||
function checkFixedConfigChanges() {
|
||
// 固定配置直接使用状态变量,不需要通过ref组件检查
|
||
return fixedParamsHasChanges.value;
|
||
}
|
||
|
||
// 监听 Request tab 切换:固定配置未保存时先确认
|
||
watch(requestTab, async (newTab, oldTab) => {
|
||
if (oldTab === 'fixed' && newTab !== 'fixed') {
|
||
if (checkFixedConfigChanges()) {
|
||
const canLeave = await confirmSaveBeforeLeaveTab({
|
||
content: '固定配置有未保存的更改,是否保存后再离开?',
|
||
save: async () => {
|
||
await saveFixedParams();
|
||
},
|
||
});
|
||
if (!canLeave) {
|
||
requestTab.value = oldTab;
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 如果切换到固定配置tab,加载数据
|
||
if (newTab === 'fixed') {
|
||
// 避免重复加载(会覆盖表格里的当前输入)
|
||
const interfaceId = Number(props.interfaceId);
|
||
const serviceProviderId = Number(props.serviceProviderId);
|
||
const nextKey = `${interfaceId || 0}-${serviceProviderId}`;
|
||
if (fixedParamsLoadedKey.value !== nextKey) {
|
||
await loadFixedParams();
|
||
}
|
||
}
|
||
});
|
||
|
||
// 当 showQuery 为 false 时,若当前在 query/header/fixed tab,切回 body
|
||
watch(() => props.showQuery, (val) => {
|
||
if (
|
||
!val
|
||
&& ['query', 'header', 'fixed'].includes(requestTab.value)
|
||
) {
|
||
requestTab.value = 'body';
|
||
}
|
||
});
|
||
|
||
// 监听 requestParams prop 变化,同步到表格数据
|
||
watch(
|
||
() => props.requestParams,
|
||
(newVal: any) => {
|
||
if (!Array.isArray(newVal)) return;
|
||
const incomingFlat = stripBodyRootFromFlat(newVal);
|
||
const currentFlat = getRequestBodyFlatParams();
|
||
// 父组件误 sync 仅根节点或 [] 时,不覆盖已写入的完整 Body 树
|
||
if (incomingFlat.length === 0 && currentFlat.length > 0) return;
|
||
if (incomingFlat.length < currentFlat.length && currentFlat.length > 0) return;
|
||
const rows = incomingFlat;
|
||
const currentHasRoot = (requestTableProps.data || []).some((r: any) => isBodyRootRow(r));
|
||
const needRoot = showRootMappedParamType.value;
|
||
if (
|
||
currentFlat.length !== rows.length ||
|
||
JSON.stringify(currentFlat) !== JSON.stringify(rows) ||
|
||
needRoot !== currentHasRoot
|
||
) {
|
||
applyRequestBodyTableData(rows);
|
||
}
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
// Json/Xml 切换 / 根类型变更:挂上、拆掉或提升虚拟根下的合成 array
|
||
watch(
|
||
[showRootMappedParamType, () => props.basicFormData?.mappedParamType],
|
||
() => {
|
||
applyRequestBodyTableData(getRequestBodyFlatParams());
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
// 监听 responseParams prop 变化,同步到表格数据
|
||
watch(
|
||
() => props.responseParams,
|
||
(newVal: any) => {
|
||
if (newVal && Array.isArray(newVal)) {
|
||
// 只在数据真正变化时才更新,避免循环
|
||
const currentData = responseTableProps.data || [];
|
||
if (currentData.length !== newVal.length || JSON.stringify(currentData) !== JSON.stringify(newVal)) {
|
||
responseTableProps.data = [...newVal] as any[];
|
||
if (responseTableRef.value) {
|
||
responseTableRef.value.reloadData([...newVal]);
|
||
}
|
||
}
|
||
}
|
||
},
|
||
{ immediate: true }
|
||
);
|
||
|
||
// 检查返回配置是否有未保存的更改
|
||
function checkReturnConfigChanges() {
|
||
if (returnConfigRef.value?.hasUnsavedChanges) {
|
||
returnConfigHasChanges.value = returnConfigRef.value.hasUnsavedChanges();
|
||
} else {
|
||
returnConfigHasChanges.value = false;
|
||
}
|
||
}
|
||
|
||
|
||
// 保存返回配置;emitSaved 用于按钮保存后引导发布(切 tab 自动保存不引导)
|
||
async function saveReturnConfig(options?: { emitSaved?: boolean }) {
|
||
if (returnConfigRef.value?.save) {
|
||
try {
|
||
const ok = await returnConfigRef.value.save({
|
||
skipSuccessToast: !!options?.emitSaved,
|
||
});
|
||
if (ok === false) return false;
|
||
returnConfigHasChanges.value = false;
|
||
if (options?.emitSaved) {
|
||
emit('return-config-saved');
|
||
}
|
||
return true;
|
||
} catch (error) {
|
||
// ReturnConfig 内部吞掉错误时可能无提示;仅兜底
|
||
$baseMessage('保存失败', 'error');
|
||
return false;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 新增返回配置项
|
||
async function addReturnConfigItem() {
|
||
// 确保切换到了返回配置tab(避免 ref 还没挂载)
|
||
if (responseTab.value !== 'returnConfig') {
|
||
responseTab.value = 'returnConfig';
|
||
await nextTick();
|
||
}
|
||
await nextTick();
|
||
if (returnConfigRef.value?.addItem) {
|
||
await returnConfigRef.value.addItem();
|
||
// 新增后视为有更改
|
||
returnConfigHasChanges.value = true;
|
||
}
|
||
}
|
||
|
||
// 监听 Response tab 切换:返回配置未保存时先确认
|
||
watch(responseTab, async (newTab, oldTab) => {
|
||
if (oldTab === 'returnConfig' && newTab !== 'returnConfig') {
|
||
checkReturnConfigChanges();
|
||
if (returnConfigHasChanges.value) {
|
||
const canLeave = await confirmSaveBeforeLeaveTab({
|
||
content: '返回配置有未保存的更改,是否保存后再离开?',
|
||
save: async () => {
|
||
await saveReturnConfig();
|
||
},
|
||
});
|
||
if (!canLeave) {
|
||
responseTab.value = oldTab;
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 如果切换到返回配置tab,确保组件已初始化
|
||
if (newTab === 'returnConfig' && props.interfaceId) {
|
||
// 避免每次切 tab 都 init 覆盖当前未保存编辑
|
||
const currentKey = String(props.interfaceId);
|
||
if ((returnConfigRef.value as any)?._loadedKey === currentKey) return;
|
||
|
||
nextTick(() => {
|
||
if (returnConfigRef.value?.init) {
|
||
returnConfigRef.value.init(props.interfaceId);
|
||
// 记录加载过的 key(挂在组件实例上,避免额外改返回配置组件)
|
||
(returnConfigRef.value as any)._loadedKey = currentKey;
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
// 监听 showReturnConfig 变化,如果隐藏返回配置且当前选中它,则切换到 body
|
||
watch(
|
||
() => props.showReturnConfig,
|
||
(newVal) => {
|
||
if (!newVal && responseTab.value === 'returnConfig') {
|
||
responseTab.value = 'body';
|
||
}
|
||
},
|
||
{ immediate: true }
|
||
);
|
||
|
||
// 参数类型列表
|
||
const ParameterTypeList = ref<any[]>([]);
|
||
|
||
// 参数占位符列表
|
||
const parameterPlaceholderList = ref<any[]>([]);
|
||
const parameterPlaceholderLoading = ref<boolean>(false);
|
||
|
||
// 固定配置-参数值:下拉选项(与 Query tab 一致,支持选择或自定义输入)
|
||
const fixedFieldValueOptions = computed(() =>
|
||
(parameterPlaceholderList.value || []).map((item: any) => ({
|
||
value: String(item.value ?? item.key ?? ''),
|
||
label: String(item.value ?? item.key ?? ''),
|
||
}))
|
||
);
|
||
|
||
// 固定参数(Query-固定配置)
|
||
const fixedParams = ref<any[]>([]);
|
||
const fixedParamsLoading = ref(false);
|
||
const fixedParamsHasChanges = ref(false);
|
||
// 用于避免切换 tab 时重复从后端加载,清空用户当前输入
|
||
const fixedParamsLoadedKey = ref<string>('');
|
||
|
||
watch([fixedParamsHasChanges, returnConfigHasChanges], () => refreshDirtyState());
|
||
|
||
// 加载参数类型列表
|
||
async function loadParameterTypeList() {
|
||
try {
|
||
const response: any = await getDictionaryGetList({
|
||
type: 'ParameterType',
|
||
});
|
||
ParameterTypeList.value = response?.data || response || [];
|
||
} catch (error) {
|
||
console.error('加载参数类型列表失败:', error);
|
||
}
|
||
}
|
||
|
||
// 加载参数占位符列表
|
||
async function loadParameterPlaceholderList() {
|
||
try {
|
||
parameterPlaceholderLoading.value = true;
|
||
const response: any = await getDictionaryGetList({
|
||
type: 'ParameterPlaceholder',
|
||
});
|
||
parameterPlaceholderList.value = response?.data || response || [];
|
||
} catch (error) {
|
||
console.error('加载参数占位符列表失败:', error);
|
||
parameterPlaceholderList.value = [];
|
||
} finally {
|
||
parameterPlaceholderLoading.value = false;
|
||
}
|
||
}
|
||
|
||
// 位置字典(用于固定配置-位置列展示)
|
||
const fieldPositionDict = ref<{ key: number | string; value: string }[]>([]);
|
||
async function loadFieldPositionDict() {
|
||
try {
|
||
const res: any = await getDictionaryGetList({ type: 'FieldPosition' });
|
||
fieldPositionDict.value = res?.data || res || [];
|
||
} catch {
|
||
fieldPositionDict.value = [];
|
||
}
|
||
}
|
||
function formatFieldPositionsDisplay(row: any): string {
|
||
const list = row?.fieldPositionList;
|
||
if (list && Array.isArray(list) && list.length > 0) {
|
||
const labels = list.map((k: number | string) => {
|
||
const item = fieldPositionDict.value.find((d) => String(d.key) === String(k));
|
||
return item?.value ?? k;
|
||
});
|
||
return labels.filter(Boolean).join(',') || '-';
|
||
}
|
||
const fp = row?.fieldPositions;
|
||
if (Array.isArray(fp) && fp.length > 0) {
|
||
return fp.map((k: number | string) => {
|
||
const item = fieldPositionDict.value.find((d) => String(d.key) === String(k));
|
||
return item?.value ?? k;
|
||
}).filter(Boolean).join(',') || '-';
|
||
}
|
||
return typeof fp === 'string' ? fp : '-';
|
||
}
|
||
|
||
// 初始化时加载参数类型列表和参数占位符列表
|
||
loadParameterTypeList();
|
||
loadParameterPlaceholderList();
|
||
loadFieldPositionDict();
|
||
|
||
// 固定配置:加载
|
||
async function loadFixedParams() {
|
||
const interfaceId = Number(props.interfaceId);
|
||
const serviceProviderId = Number(props.serviceProviderId);
|
||
if (!Number.isFinite(serviceProviderId) || serviceProviderId <= 0) return;
|
||
try {
|
||
fixedParamsLoading.value = true;
|
||
const params: any = { serviceProviderId };
|
||
// 只有编辑模式才传递interfaceId,新增模式下不传
|
||
if (Number.isFinite(interfaceId) && interfaceId > 0) {
|
||
params.interfaceId = interfaceId;
|
||
}
|
||
const res = await getFixedParameterGetFixedParameterList(params);
|
||
const data = (res as any)?.data || res || [];
|
||
fixedParams.value = Array.isArray(data) ? data : [];
|
||
await nextTick();
|
||
queryFixedTableRef.value?.reloadData?.(fixedParams.value);
|
||
fixedParamsHasChanges.value = false;
|
||
fixedParamsLoadedKey.value = `${interfaceId || 0}-${serviceProviderId}`;
|
||
} finally {
|
||
fixedParamsLoading.value = false;
|
||
}
|
||
}
|
||
|
||
// 固定配置:新增
|
||
async function addFixedParam() {
|
||
if (requestTab.value !== 'fixed') {
|
||
requestTab.value = 'fixed';
|
||
await nextTick();
|
||
}
|
||
const record = {
|
||
fieldName: '',
|
||
fieldValue: '',
|
||
fieldPositions: '',
|
||
fieldPositionList: [],
|
||
};
|
||
const { row } = await queryFixedTableRef.value!.addRow(record);
|
||
await queryFixedTableRef.value?.editRowEvent(row);
|
||
fixedParamsHasChanges.value = true;
|
||
refreshTabCounts();
|
||
}
|
||
|
||
// 固定配置:删除
|
||
async function deleteFixedParam(row: any) {
|
||
await queryFixedTableRef.value?.removeRow(row);
|
||
fixedParamsHasChanges.value = true;
|
||
refreshTabCounts();
|
||
}
|
||
|
||
// 固定配置:保存
|
||
async function saveFixedParams() {
|
||
const interfaceId = Number(props.interfaceId);
|
||
const serviceProviderId = Number(props.serviceProviderId);
|
||
// 只有编辑模式才需要接口ID,新增模式下接口还没创建,可以先保存固定参数
|
||
if (!Number.isFinite(serviceProviderId) || serviceProviderId <= 0) {
|
||
return $baseMessage('缺少服务商ID,无法保存', 'error');
|
||
}
|
||
const actionRows = queryFixedTableRef.value?.getActionRows?.();
|
||
if (!actionRows) return;
|
||
const insert = (actionRows.insertRecords || []).map((i: any) => ({
|
||
...i,
|
||
options: 1,
|
||
id: undefined,
|
||
}));
|
||
const remove = (actionRows.removeRecords || []).map((i: any) => ({
|
||
...i,
|
||
options: 2,
|
||
}));
|
||
const update = (actionRows.updateRecords || []).map((i: any) => ({
|
||
...i,
|
||
options: 3,
|
||
}));
|
||
const items = [...insert, ...remove, ...update];
|
||
if (items.length === 0) {
|
||
return $baseMessage('暂无变更需要保存', 'warning');
|
||
}
|
||
try {
|
||
await postFixedParameterMaintainParameter({
|
||
serviceProviderId,
|
||
interfaceId: Number.isFinite(interfaceId) && interfaceId > 0 ? interfaceId : undefined,
|
||
items,
|
||
});
|
||
fixedParamsHasChanges.value = false;
|
||
$baseMessage('保存成功,如需生效请去发布', 'success');
|
||
await loadFixedParams();
|
||
} catch {
|
||
$baseMessage('保存失败', 'error');
|
||
}
|
||
}
|
||
|
||
// 获取参数类型名称
|
||
function getParameterTypeName(type: any) {
|
||
const paramType = ParameterTypeList.value.find(item => item.key === type);
|
||
return paramType ? paramType.value : type;
|
||
}
|
||
|
||
// 判断行是否处于编辑状态(Query / Header / Body KV)
|
||
function isTableRowEditing(row: any, tableRef: { value?: { isEditByRow?: (r: any) => boolean } }): boolean {
|
||
if (!row || !tableRef.value) return false;
|
||
try {
|
||
return !!tableRef.value.isEditByRow?.(row);
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function isQueryRowEditing(row: any): boolean {
|
||
return isTableRowEditing(row, queryTableRef);
|
||
}
|
||
|
||
function isHeaderRowEditing(row: any): boolean {
|
||
return isTableRowEditing(row, headerTableRef);
|
||
}
|
||
|
||
function isBodyFormRowEditing(row: any): boolean {
|
||
return isTableRowEditing(row, bodyFormTableRef);
|
||
}
|
||
|
||
async function removeTableRows(tableRef: { value?: { removeRow?: (row: any) => any; xGrid?: any } }, rows: any[]) {
|
||
if (!rows.length) return;
|
||
const grid = tableRef.value?.xGrid;
|
||
if (grid?.remove) {
|
||
await grid.remove(rows);
|
||
return;
|
||
}
|
||
for (const row of rows) {
|
||
await tableRef.value?.removeRow?.(row);
|
||
}
|
||
}
|
||
|
||
function collectRemovableTableRows(
|
||
tableRef: any,
|
||
keepRow?: (row: any) => boolean,
|
||
) {
|
||
const roots = [...(getTableFullData(tableRef) || [])].filter((r) => !isCommonParamRow(r));
|
||
if (!keepRow) return roots;
|
||
const toRemove: any[] = [];
|
||
roots.forEach((row) => {
|
||
if (keepRow(row)) {
|
||
if (Array.isArray(row?.children) && row.children.length) {
|
||
toRemove.push(...row.children.filter((c: any) => !isCommonParamRow(c)));
|
||
}
|
||
return;
|
||
}
|
||
toRemove.push(row);
|
||
});
|
||
return toRemove;
|
||
}
|
||
|
||
async function clearCurrentRequestTab() {
|
||
const tab = requestTab.value;
|
||
if (tab === 'query') {
|
||
await removeTableRows(queryTableRef, collectRemovableTableRows(queryTableRef));
|
||
await applyKvTableWithCommon(
|
||
queryTableProps,
|
||
queryTableRef,
|
||
[],
|
||
inheritedQueryParams.value,
|
||
);
|
||
} else if (tab === 'header') {
|
||
await removeTableRows(headerTableRef, collectRemovableTableRows(headerTableRef));
|
||
await applyKvTableWithCommon(
|
||
headerTableProps,
|
||
headerTableRef,
|
||
[],
|
||
inheritedHeaderParams.value,
|
||
);
|
||
} else if (tab === 'fixed') {
|
||
await removeTableRows(queryFixedTableRef, collectRemovableTableRows(queryFixedTableRef));
|
||
fixedParams.value = [];
|
||
fixedParamsHasChanges.value = true;
|
||
} else if (tab === 'body' && isBodyKvMode.value) {
|
||
await removeTableRows(bodyFormTableRef, collectRemovableTableRows(bodyFormTableRef));
|
||
await applyKvTableWithCommon(
|
||
bodyFormTableProps,
|
||
bodyFormTableRef,
|
||
[],
|
||
inheritedBodyParams.value,
|
||
);
|
||
} else if (tab === 'body' && !isNoneBodyContentType.value) {
|
||
if (hoistedBodyArrayWrapper.value) {
|
||
const persisted = getRequestBodyFlatParams();
|
||
hoistedBodyArrayWrapper.value = null;
|
||
const rows = ensureBodyRootInRows(persisted, { hoistSyntheticArray: false });
|
||
requestTableProps.data = rows;
|
||
await nextTick();
|
||
await requestTableRef.value?.reloadData?.(rows);
|
||
await nextTick();
|
||
}
|
||
await removeTableRows(
|
||
requestTableRef,
|
||
collectRemovableTableRows(requestTableRef, isBodyRootRow),
|
||
);
|
||
hoistedBodyArrayWrapper.value = null;
|
||
const remaining = getTableFullData(requestTableRef, []);
|
||
requestTableProps.data = remaining.length ? remaining : ensureBodyRootInRows([]);
|
||
} else if (tab === 'mappingBody') {
|
||
await removeTableRows(mappingBodyTableRef, collectRemovableTableRows(mappingBodyTableRef));
|
||
mappingBodyTableProps.data = [];
|
||
} else if (tab === 'demo') {
|
||
requestExample.value = '';
|
||
}
|
||
markDirty();
|
||
refreshTabCounts();
|
||
}
|
||
|
||
function confirmClearCurrentRequestTab() {
|
||
if (!canClearCurrentRequestTab.value) {
|
||
$baseMessage('当前 Tab 没有可清空的内容', 'warning');
|
||
return;
|
||
}
|
||
const label = currentRequestTabClearLabel.value;
|
||
const content =
|
||
requestTab.value === 'fixed'
|
||
? `确定清空当前「${label}」?清空后需点击「保存固定配置」才会同步到服务端。`
|
||
: requestTab.value === 'demo'
|
||
? '确定清空当前 cURL 内容?'
|
||
: `确定清空当前「${label}」?此操作仅影响编辑区,保存接口后才会同步到服务端。`;
|
||
$baseConfirm({
|
||
title: '清空确认',
|
||
content,
|
||
okText: '清空',
|
||
cancelText: '取消',
|
||
onOk: () => clearCurrentRequestTab(),
|
||
});
|
||
}
|
||
|
||
// 新增 Query 参数
|
||
async function addNewQueryParam() {
|
||
markDirty();
|
||
try {
|
||
const record = {
|
||
// 新增参数 id 从 1 开始伪造,用于表达层级关系
|
||
id: random(1, 2099999999),
|
||
name: '',
|
||
value: '',
|
||
description: '',
|
||
};
|
||
|
||
await nextTick();
|
||
const { row: newRow } = await queryTableRef.value!.addRow(record);
|
||
await nextTick();
|
||
await queryTableRef.value?.editRowEvent(newRow);
|
||
refreshTabCounts();
|
||
} catch (error) {
|
||
console.error('添加Query参数失败:', error);
|
||
}
|
||
}
|
||
|
||
// 删除 Query 参数行
|
||
async function deleteQueryRow(row: any) {
|
||
if (isCommonParamRow(row)) return;
|
||
markDirty();
|
||
await queryTableRef.value?.removeRow(row);
|
||
refreshTabCounts();
|
||
}
|
||
|
||
async function addNewHeaderParam() {
|
||
markDirty();
|
||
const record = { id: random(1, 2099999999), name: '', value: '', description: '' };
|
||
const { row: newRow } = await headerTableRef.value!.addRow(record);
|
||
await headerTableRef.value?.editRowEvent(newRow);
|
||
refreshTabCounts();
|
||
}
|
||
|
||
async function deleteHeaderRow(row: any) {
|
||
if (isCommonParamRow(row)) return;
|
||
markDirty();
|
||
await headerTableRef.value?.removeRow(row);
|
||
refreshTabCounts();
|
||
}
|
||
|
||
async function addNewBodyFormParam() {
|
||
markDirty();
|
||
const record = { id: random(1, 2099999999), name: '', value: '', description: '' };
|
||
const { row: newRow } = await bodyFormTableRef.value!.addRow(record);
|
||
await bodyFormTableRef.value?.editRowEvent(newRow);
|
||
refreshTabCounts();
|
||
}
|
||
|
||
async function deleteBodyFormRow(row: any) {
|
||
if (isCommonParamRow(row)) return;
|
||
markDirty();
|
||
await bodyFormTableRef.value?.removeRow(row);
|
||
refreshTabCounts();
|
||
}
|
||
|
||
async function addNewMappingBodyParam() {
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: 0,
|
||
name: '',
|
||
alias: '',
|
||
cnName: '',
|
||
type: 1,
|
||
isRequired: false,
|
||
description: '',
|
||
};
|
||
const { row: newRow } = await mappingBodyTableRef.value!.addRow(record);
|
||
await mappingBodyTableRef.value?.editRowEvent(newRow);
|
||
refreshTabCounts();
|
||
}
|
||
|
||
// 判断行是否处于编辑状态(Request Parameters)
|
||
function isRequestRowEditing(row: any): boolean {
|
||
if (!row || !requestTableRef.value) return false;
|
||
try {
|
||
return requestTableRef.value.isEditByRow(row);
|
||
} catch (error) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function activeBodyTreeTableRef() {
|
||
return requestTab.value === 'mappingBody' ? mappingBodyTableRef : requestTableRef;
|
||
}
|
||
|
||
// 新增 Body / Mapping Body 参数树根节点
|
||
async function addNewRequestParam() {
|
||
markDirty();
|
||
try {
|
||
const underVirtualRoot =
|
||
requestTab.value !== 'mappingBody' && showRootMappedParamType.value;
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: underVirtualRoot ? BODY_ROOT_VIRTUAL_ID : 0,
|
||
name: '',
|
||
type: 1,
|
||
description: '',
|
||
isRequired: false,
|
||
};
|
||
|
||
const tableRef = activeBodyTreeTableRef();
|
||
await nextTick();
|
||
const { row: newRow } = await tableRef.value!.addRow(record);
|
||
await nextTick();
|
||
if (underVirtualRoot) {
|
||
const root = (requestTableProps.data || []).find((r: any) => isBodyRootRow(r));
|
||
if (root) await tableRef.value?.setTreeExpand?.(root, true);
|
||
}
|
||
await tableRef.value?.editRowEvent(newRow);
|
||
refreshTabCounts();
|
||
} catch (error) {
|
||
console.error('添加参数失败:', error);
|
||
}
|
||
}
|
||
|
||
// 添加子级行(Request 参数)
|
||
async function addRequestRow(currRow: any) {
|
||
markDirty();
|
||
const activeRef = requestTab.value === 'mappingBody' ? mappingBodyTableRef : requestTableRef;
|
||
const underVirtualRoot =
|
||
requestTab.value !== 'mappingBody' && showRootMappedParamType.value;
|
||
// 虚拟根 / 空名:添加顶级(挂到虚拟根下)
|
||
if (isBodyRootRow(currRow) || !currRow.name) {
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: underVirtualRoot || isBodyRootRow(currRow) ? BODY_ROOT_VIRTUAL_ID : 0,
|
||
type: 1,
|
||
name: '',
|
||
description: '',
|
||
isRequired: false,
|
||
};
|
||
|
||
try {
|
||
if (isBodyRootRow(currRow)) {
|
||
await activeRef.value?.addRowsAt(record, -1);
|
||
await activeRef.value?.setTreeExpand(currRow, true);
|
||
} else {
|
||
const result = await activeRef.value?.addRow(record);
|
||
if (result && result.row) {
|
||
await nextTick();
|
||
await activeRef.value?.editRowEvent(result.row);
|
||
}
|
||
}
|
||
refreshTabCounts();
|
||
} catch (error) {
|
||
console.error('添加Request参数失败:', error);
|
||
}
|
||
return undefined;
|
||
}
|
||
|
||
// 如果当前行有内容,则添加子级行
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: currRow.id,
|
||
type: 1,
|
||
name: '',
|
||
description: '',
|
||
isRequired: false,
|
||
};
|
||
|
||
if (currRow.type === 8 || currRow.type === 9 || currRow.type === 11) {
|
||
console.error('该类型不允许添加子级');
|
||
return undefined;
|
||
}
|
||
|
||
await activeRef.value?.addRowsAt(record, -1);
|
||
await activeRef.value?.setTreeExpand(currRow, true);
|
||
refreshTabCounts();
|
||
return undefined;
|
||
}
|
||
|
||
// 删除 Request 参数行
|
||
async function deleteRequestRow(row: any) {
|
||
if (isBodyRootRow(row)) return;
|
||
markDirty();
|
||
const isMapping = requestTab.value === 'mappingBody';
|
||
const ref = isMapping ? mappingBodyTableRef : requestTableRef;
|
||
await ref.value?.removeRow(row);
|
||
const fromGrid =
|
||
ref.value?.getTableData?.()?.fullData
|
||
|| ref.value?.xGrid?.getTableData?.()?.fullData
|
||
|| [];
|
||
if (isMapping) {
|
||
mappingBodyTableProps.data = Array.isArray(fromGrid) ? [...fromGrid] : [];
|
||
} else {
|
||
const next = Array.isArray(fromGrid) ? [...fromGrid] : [];
|
||
requestTableProps.data = next.length ? next : ensureBodyRootInRows([]);
|
||
}
|
||
refreshTabCounts();
|
||
}
|
||
|
||
/** 复制 Body / Mapping Body 同行(不含子节点) */
|
||
async function copyBodyTreeRow(row: any) {
|
||
if (!row || isBodyRootRow(row)) return;
|
||
markDirty();
|
||
const activeRef = requestTab.value === 'mappingBody' ? mappingBodyTableRef : requestTableRef;
|
||
const baseName = String(row.name || '').trim();
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: row.pId ?? 0,
|
||
name: baseName ? `${baseName}_copy` : '',
|
||
type: row.type ?? 1,
|
||
description: row.description || '',
|
||
isRequired: !!row.isRequired,
|
||
};
|
||
try {
|
||
await activeRef.value?.addRowsAt(record, -1);
|
||
refreshTabCounts();
|
||
} catch (error) {
|
||
console.error('复制参数失败:', error);
|
||
$baseMessage('复制失败', 'error');
|
||
}
|
||
}
|
||
|
||
/** 复制 Response 同行(不含子节点) */
|
||
async function copyResponseRow(row: any) {
|
||
if (!row) return;
|
||
markDirty();
|
||
const baseName = String(row.name || '').trim();
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: row.pId ?? 0,
|
||
name: baseName ? `${baseName}_copy` : '',
|
||
type: row.type ?? 1,
|
||
description: row.description || '',
|
||
isRequired: !!row.isRequired,
|
||
};
|
||
try {
|
||
await responseTableRef.value?.addRowsAt(record, -1);
|
||
refreshTabCounts();
|
||
} catch (error) {
|
||
console.error('复制响应参数失败:', error);
|
||
$baseMessage('复制失败', 'error');
|
||
}
|
||
}
|
||
|
||
function isMappingBodyRowEditing(row: any): boolean {
|
||
if (!row || !mappingBodyTableRef.value) return false;
|
||
try {
|
||
return mappingBodyTableRef.value.isEditByRow(row);
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
async function addMappingBodyRow(currRow?: any) {
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: currRow?.id ?? 0,
|
||
type: 1,
|
||
name: '',
|
||
description: '',
|
||
isRequired: false,
|
||
};
|
||
if (!currRow?.name) {
|
||
const { row: newRow } = await mappingBodyTableRef.value!.addRow(record);
|
||
await mappingBodyTableRef.value?.editRowEvent(newRow);
|
||
} else {
|
||
await mappingBodyTableRef.value?.addRowsAt(record, -1);
|
||
await mappingBodyTableRef.value?.setTreeExpand(currRow, true);
|
||
}
|
||
refreshTabCounts();
|
||
}
|
||
|
||
// 判断行是否处于编辑状态(Response Parameters)
|
||
function isResponseRowEditing(row: any): boolean {
|
||
if (!row || !responseTableRef.value) return false;
|
||
try {
|
||
return responseTableRef.value.isEditByRow(row);
|
||
} catch (error) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// 新增 Response 参数
|
||
async function addNewResponseParam() {
|
||
markDirty();
|
||
try {
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: 0,
|
||
name: '',
|
||
type: 1,
|
||
description: '',
|
||
isRequired: false,
|
||
};
|
||
|
||
await nextTick();
|
||
const { row: newRow } = await responseTableRef.value!.addRow(record);
|
||
await nextTick();
|
||
await responseTableRef.value?.editRowEvent(newRow);
|
||
refreshTabCounts();
|
||
} catch (error) {
|
||
console.error('添加Response参数失败:', error);
|
||
}
|
||
}
|
||
|
||
// 添加子级行(Response 参数)
|
||
async function addResponseRow(currRow: any) {
|
||
markDirty();
|
||
// 如果当前行没有内容,则添加一个顶级行
|
||
if (!currRow.name) {
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: 0,
|
||
type: 1,
|
||
name: '',
|
||
description: '',
|
||
isRequired: false,
|
||
};
|
||
|
||
try {
|
||
const result = await responseTableRef.value?.addRow(record);
|
||
if (result && result.row) {
|
||
await nextTick();
|
||
await responseTableRef.value?.editRowEvent(result.row);
|
||
}
|
||
refreshTabCounts();
|
||
} catch (error) {
|
||
console.error('添加Response参数失败:', error);
|
||
}
|
||
return undefined;
|
||
}
|
||
|
||
// 如果当前行有内容,则添加子级行
|
||
const record = {
|
||
id: random(1, 2099999999),
|
||
pId: currRow.id,
|
||
type: 1,
|
||
name: '',
|
||
description: '',
|
||
isRequired: false,
|
||
};
|
||
|
||
if (currRow.type === 8 || currRow.type === 9 || currRow.type === 11) {
|
||
console.error('该类型不允许添加子级');
|
||
return undefined;
|
||
}
|
||
|
||
// 添加子级行
|
||
await responseTableRef.value?.addRowsAt(record, -1);
|
||
await responseTableRef.value?.setTreeExpand(currRow, true);
|
||
refreshTabCounts();
|
||
return undefined;
|
||
}
|
||
|
||
// 删除 Response 参数行
|
||
async function deleteResponseRow(row: any) {
|
||
markDirty();
|
||
await responseTableRef.value?.removeRow(row);
|
||
// 与表格同步,避免 props 残留旧树被校验/保存误读
|
||
const fromGrid =
|
||
responseTableRef.value?.getTableData?.()?.fullData
|
||
|| responseTableRef.value?.xGrid?.getTableData?.()?.fullData
|
||
|| [];
|
||
responseTableProps.data = Array.isArray(fromGrid) ? [...fromGrid] : [];
|
||
refreshTabCounts();
|
||
}
|
||
|
||
function createBodyTreeSortable(tableRef: { value?: any }, onCreate: (s: any) => void, onDestroy: () => void) {
|
||
if (!tableRef.value) return;
|
||
|
||
const $grid = tableRef.value;
|
||
const tableEl = $grid.$el || $grid.xGrid?.$el;
|
||
if (!tableEl) return;
|
||
|
||
const tbody = tableEl.querySelector('.vxe-table--body-wrapper tbody');
|
||
if (!tbody) return;
|
||
|
||
onDestroy();
|
||
|
||
onCreate(
|
||
Sortable.create(tbody, {
|
||
handle: '.sort',
|
||
animation: 150,
|
||
onEnd: async (evt: any) => {
|
||
const { oldIndex, newIndex } = evt;
|
||
if (oldIndex === newIndex) return;
|
||
|
||
const tableData =
|
||
tableRef.value?.getTableData?.()?.fullData
|
||
|| tableRef.value?.xGrid?.getTableData()?.fullData
|
||
|| [];
|
||
|
||
if (tableData?.length > 0) {
|
||
const movedRow = tableData[oldIndex];
|
||
tableData.splice(oldIndex, 1);
|
||
tableData.splice(newIndex, 0, movedRow);
|
||
tableData.forEach((row: any, index: number) => {
|
||
row.sort = index + 1;
|
||
});
|
||
await nextTick();
|
||
tableRef.value?.reloadData(tableData);
|
||
}
|
||
},
|
||
}),
|
||
);
|
||
}
|
||
|
||
function initRequestRowSortable() {
|
||
createBodyTreeSortable(
|
||
requestTableRef,
|
||
(s) => { requestSortable = s; },
|
||
() => {
|
||
if (requestSortable) {
|
||
requestSortable.destroy();
|
||
requestSortable = null;
|
||
}
|
||
},
|
||
);
|
||
}
|
||
|
||
function initMappingBodyRowSortable() {
|
||
createBodyTreeSortable(
|
||
mappingBodyTableRef,
|
||
(s) => { mappingBodySortable = s; },
|
||
() => {
|
||
if (mappingBodySortable) {
|
||
mappingBodySortable.destroy();
|
||
mappingBodySortable = null;
|
||
}
|
||
},
|
||
);
|
||
}
|
||
|
||
watch(
|
||
() => requestTableRef.value,
|
||
() => {
|
||
if (requestTableRef.value) {
|
||
nextTick(() => {
|
||
setTimeout(() => initRequestRowSortable(), 500);
|
||
});
|
||
}
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
watch(
|
||
() => mappingBodyTableRef.value,
|
||
() => {
|
||
if (mappingBodyTableRef.value) {
|
||
nextTick(() => {
|
||
setTimeout(() => initMappingBodyRowSortable(), 500);
|
||
});
|
||
}
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
/** v-show 隐藏时表格高度为 0,显示后需重算列宽/高度,避免缩放撑开动画感 */
|
||
function syncVisibleRequestTableLayout() {
|
||
nextTick(() => {
|
||
requestAnimationFrame(() => {
|
||
let tableRef: any = null;
|
||
if (requestTab.value === 'mappingBody') tableRef = mappingBodyTableRef.value;
|
||
else if (requestTab.value === 'query') tableRef = queryTableRef.value;
|
||
else if (requestTab.value === 'header') tableRef = headerTableRef.value;
|
||
else if (requestTab.value === 'fixed') tableRef = queryFixedTableRef.value;
|
||
else if (requestTab.value === 'body') {
|
||
if (isNoneBodyContentType.value) tableRef = null;
|
||
else if (isBodyKvMode.value) tableRef = bodyFormTableRef.value;
|
||
else tableRef = requestTableRef.value;
|
||
}
|
||
const grid = tableRef?.xGrid;
|
||
grid?.recalculate?.(true);
|
||
grid?.refreshColumn?.();
|
||
});
|
||
});
|
||
}
|
||
|
||
watch(requestTab, (tab) => {
|
||
syncVisibleRequestTableLayout();
|
||
if (tab === 'mappingBody') {
|
||
nextTick(() => {
|
||
setTimeout(() => initMappingBodyRowSortable(), 300);
|
||
});
|
||
}
|
||
});
|
||
|
||
// 处理 inParams 数据的专用函数
|
||
function processInParamsData(inParams: any): string {
|
||
if (!inParams) return '';
|
||
|
||
// 如果是对象,直接格式化
|
||
if (typeof inParams === 'object') {
|
||
return JSON.stringify(inParams, null, 2);
|
||
}
|
||
|
||
// 如果不是字符串,返回原值
|
||
if (typeof inParams !== 'string') {
|
||
return String(inParams);
|
||
}
|
||
|
||
const trimmed = inParams.trim();
|
||
// 非 JSON 内容(如 cURL、XML 等)直接返回,不尝试解析
|
||
if (!trimmed.startsWith('{') && !trimmed.startsWith('[')) {
|
||
return inParams;
|
||
}
|
||
|
||
try {
|
||
// 步骤1: 处理转义字符 - 将字面量的转义序列转换为实际字符
|
||
let processed = inParams;
|
||
|
||
// 按顺序处理转义字符(重要:顺序不能错)
|
||
processed = processed.replace(/\\r\\n/g, '\n'); // Windows 换行符转义 -> 实际换行
|
||
processed = processed.replace(/\\n/g, '\n'); // Unix 换行符转义 -> 实际换行
|
||
processed = processed.replace(/\\r/g, '\r'); // 回车符转义 -> 实际回车
|
||
processed = processed.replace(/\\t/g, '\t'); // 制表符转义 -> 实际制表符
|
||
processed = processed.replace(/\\\\/g, '\\'); // 反斜杠转义 -> 实际反斜杠
|
||
processed = processed.replace(/\\"/g, '"'); // 双引号转义 -> 实际双引号
|
||
|
||
// 步骤2: 校验 JSON5 可解析(支持 // 和 /* */ 注释)
|
||
JSON5.parse(processed);
|
||
|
||
// 步骤3: 直接返回处理后的字符串,保留注释和原始格式
|
||
return processed;
|
||
|
||
} catch (error) {
|
||
console.error('processInParamsData 处理失败:', error);
|
||
// 如果处理失败,返回原始数据
|
||
return inParams;
|
||
}
|
||
}
|
||
|
||
// 监听 basicParams 中与 Demo 相关的字段,避免对整个对象做深度 watch 导致性能问题
|
||
watch(
|
||
() => ({
|
||
inParams: (props.basicParams as any)?.inParams,
|
||
requestExample: (props.basicParams as any)?.requestExample,
|
||
demoData: (props.basicParams as any)?.demoData,
|
||
inParameterData: (props.basicParams as any)?.inParameterData,
|
||
}),
|
||
(val) => {
|
||
const inParams =
|
||
val.inParams ||
|
||
val.requestExample ||
|
||
val.demoData ||
|
||
val.inParameterData;
|
||
|
||
if (!inParams) {
|
||
return;
|
||
}
|
||
|
||
const processedData = processInParamsData(inParams);
|
||
requestExample.value = processedData;
|
||
},
|
||
{
|
||
immediate: true,
|
||
deep: false,
|
||
}
|
||
);
|
||
|
||
onMounted(() => {
|
||
window.addEventListener('beforeunload', onWindowBeforeUnload);
|
||
if (requestTableRef.value) {
|
||
setTimeout(() => {
|
||
initRequestRowSortable();
|
||
}, 500);
|
||
}
|
||
if (props.showContentTypeSelectors) {
|
||
loadContentTypeOptions();
|
||
}
|
||
loadRequestMethodOptions();
|
||
});
|
||
|
||
onUnmounted(() => {
|
||
window.removeEventListener('beforeunload', onWindowBeforeUnload);
|
||
if (mappingBodySortable) {
|
||
mappingBodySortable.destroy();
|
||
mappingBodySortable = null;
|
||
}
|
||
if (requestSortable) {
|
||
requestSortable.destroy();
|
||
requestSortable = null;
|
||
}
|
||
if (responseSortable) {
|
||
responseSortable.destroy();
|
||
responseSortable = null;
|
||
}
|
||
});
|
||
|
||
// 打开 Request 参数解析弹窗
|
||
function drawerClick() {
|
||
tabs.value = 'Json';
|
||
drawerVisible.value = true;
|
||
}
|
||
|
||
// 打开 Response 参数解析弹窗
|
||
function drawerClick1() {
|
||
tabs1.value = 'Json';
|
||
drawerVisible1.value = true;
|
||
}
|
||
|
||
function clearRequestImportEditors() {
|
||
textareaJson.value = '';
|
||
textareaXml.value = '';
|
||
dataList.value = undefined;
|
||
}
|
||
|
||
function clearResponseImportEditors() {
|
||
textareaJson1.value = '';
|
||
textareaXml1.value = '';
|
||
dataList1.value = undefined;
|
||
}
|
||
|
||
async function writeTextToClipboard(content: string) {
|
||
try {
|
||
await navigator.clipboard.writeText(content);
|
||
Message.success('已复制到剪贴板');
|
||
return true;
|
||
} catch {
|
||
const textArea = document.createElement('textarea');
|
||
textArea.value = content;
|
||
textArea.style.position = 'fixed';
|
||
textArea.style.left = '-999999px';
|
||
document.body.appendChild(textArea);
|
||
textArea.select();
|
||
try {
|
||
document.execCommand('copy');
|
||
Message.success('已复制到剪贴板');
|
||
return true;
|
||
} catch {
|
||
Message.error('复制失败');
|
||
return false;
|
||
} finally {
|
||
document.body.removeChild(textArea);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 复制 cURL tab 输入框内容到剪贴板
|
||
async function copyRequestExampleContent() {
|
||
const content = requestExample.value || '';
|
||
if (!content.trim()) {
|
||
Message.warning('暂无内容可复制');
|
||
return;
|
||
}
|
||
await writeTextToClipboard(content);
|
||
}
|
||
|
||
/** 复制当前 Body / Mapping Body 参数为带 // 描述的格式化 JSON */
|
||
async function copyBodyParamsAsCommentedJson() {
|
||
let content = '';
|
||
if (requestTab.value === 'mappingBody') {
|
||
const fromGrid =
|
||
mappingBodyTableRef.value?.getTableData?.()?.fullData
|
||
|| mappingBodyTableRef.value?.xGrid?.getTableData()?.fullData;
|
||
const rows = getTreeTableFlatRows(fromGrid, mappingBodyTableProps.data);
|
||
content = buildCommentedJsonFromParameterFlatList(rows);
|
||
} else if (isNoneBodyContentType.value) {
|
||
Message.warning('当前请求类型为 none,无 Body 参数可复制');
|
||
return;
|
||
} else if (isBodyKvMode.value) {
|
||
const rows = getTableFullData(bodyFormTableRef, bodyFormTableProps.data);
|
||
content = buildCommentedJsonFromKvRows(rows);
|
||
} else {
|
||
const rows = getRequestBodyFlatParams();
|
||
content = buildCommentedJsonFromParameterFlatList(rows, {
|
||
isRootRow: isBodyRootRow,
|
||
});
|
||
}
|
||
|
||
const compact = content.replace(/\s+/g, '');
|
||
if (!compact || compact === '{}' || compact === '[]') {
|
||
Message.warning('暂无参数可复制');
|
||
return;
|
||
}
|
||
await writeTextToClipboard(content);
|
||
}
|
||
|
||
/** 复制当前 Response Body 参数列表为带 // 描述的格式化 JSON */
|
||
async function copyResponseParamsAsCommentedJson() {
|
||
const fromGrid =
|
||
responseTableRef.value?.getTableData?.()?.fullData
|
||
|| responseTableRef.value?.xGrid?.getTableData()?.fullData;
|
||
const rows = getTreeTableFlatRows(fromGrid, responseTableProps.data);
|
||
const content = buildCommentedJsonFromParameterFlatList(rows);
|
||
const compact = content.replace(/\s+/g, '');
|
||
if (!compact || compact === '{}' || compact === '[]') {
|
||
Message.warning('暂无参数可复制');
|
||
return;
|
||
}
|
||
await writeTextToClipboard(content);
|
||
}
|
||
|
||
// 取消 Request 参数解析
|
||
function cancelClick() {
|
||
if (analysisBusy.value) return;
|
||
drawerVisible.value = false;
|
||
clearRequestImportEditors();
|
||
}
|
||
|
||
// 取消 Response 参数解析
|
||
function cancelClick1() {
|
||
if (analysisBusy.value) return;
|
||
drawerVisible1.value = false;
|
||
clearResponseImportEditors();
|
||
}
|
||
|
||
// 解析 Request 参数
|
||
async function JsonXmlClick() {
|
||
if (!textareaJson.value && !textareaXml.value) {
|
||
$baseMessage('请先输入Json或Xml内容', 'warning');
|
||
return;
|
||
}
|
||
|
||
analysisLoading.value = true;
|
||
try {
|
||
const content = tabs.value === 'Json' ? textareaJson.value : textareaXml.value;
|
||
const resp = await postParameterParse({
|
||
parameterParseType: tabs.value === 'Json' ? 1 : 2,
|
||
parameterContent: content,
|
||
});
|
||
const data = (resp as any)?.data || resp;
|
||
dataList.value = data;
|
||
$baseMessage('解析成功', 'success');
|
||
} catch (error) {
|
||
$baseMessage(formatCaughtError(error, '解析失败,请检查报文格式'), 'error');
|
||
} finally {
|
||
analysisLoading.value = false;
|
||
}
|
||
}
|
||
|
||
// 根据 JSON 值类型从 ParameterTypeList 中查找对应的 type key(与字典 value/key 匹配)
|
||
function resolveParameterType(jsonType: 'string' | 'number' | 'boolean' | 'object' | 'array'): number {
|
||
const list = ParameterTypeList.value || [];
|
||
const matchPatterns: Record<string, string[]> = {
|
||
string: ['string', '字符串', 'str'],
|
||
number: ['number', '数字', 'integer', '整数', 'int'],
|
||
boolean: ['boolean', '布尔'],
|
||
object: ['object', '对象'],
|
||
array: ['array', '数组'],
|
||
};
|
||
const patterns = matchPatterns[jsonType] || ['string'];
|
||
const found = list.find((item: any) => {
|
||
const val = String(item?.value ?? item?.label ?? '').toLowerCase();
|
||
const keyStr = String(item?.key ?? '').toLowerCase();
|
||
return patterns.some((p) => val.includes(p) || val === p || keyStr.includes(p) || keyStr === p);
|
||
});
|
||
if (found != null) return Number(found.key);
|
||
return defaultResolveParameterType(jsonType);
|
||
}
|
||
|
||
// 前端解析 JSON 结构并填充到 Body / Mapping Body 树(extInfo 等不展开内嵌 JSON)
|
||
async function handleFrontendParseRequest() {
|
||
if (!textareaJson.value?.trim()) {
|
||
$baseMessage('请先输入 Json 内容', 'warning');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const rawJson = textareaJson.value;
|
||
const flatList = parseJsonTextToParameterFlatList(rawJson, {
|
||
resolveParameterType: (kind) => resolveParameterType(kind),
|
||
idFactory: () => random(1, 2099999999),
|
||
rawJsonForComments: rawJson,
|
||
});
|
||
|
||
if (flatList.length === 0) {
|
||
$baseMessage('解析结果为空', 'warning');
|
||
return;
|
||
}
|
||
|
||
const target = resolveBodyTreeImportTarget();
|
||
const tableProps = target === 'mappingBody' ? mappingBodyTableProps : requestTableProps;
|
||
const tableRef = target === 'mappingBody' ? mappingBodyTableRef : requestTableRef;
|
||
await loadFlatListIntoTreeTable(flatList, tableProps, tableRef);
|
||
refreshTabCounts();
|
||
|
||
$baseMessage('前端解析成功', 'success');
|
||
drawerVisible.value = false;
|
||
clearRequestImportEditors();
|
||
} catch (error) {
|
||
$baseMessage(formatCaughtError(error, 'JSON 解析失败,请检查格式(括号/逗号/注释)'), 'error');
|
||
}
|
||
}
|
||
|
||
/** 仅导入 // 注释到已有字段 description,不新增参数 */
|
||
async function handleImportCommentsOnly() {
|
||
if (tabs.value !== 'Json') {
|
||
$baseMessage('仅导入注释仅支持 JSON', 'warning');
|
||
return;
|
||
}
|
||
if (!textareaJson.value?.trim()) {
|
||
$baseMessage('请先输入 Json 内容', 'warning');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const rawJson = textareaJson.value;
|
||
const commentMap = extractCommentsFromJson(rawJson);
|
||
if (commentMap.size === 0) {
|
||
$baseMessage('未找到 // 注释', 'warning');
|
||
return;
|
||
}
|
||
|
||
const target = resolveBodyTreeImportTarget();
|
||
const tableProps = target === 'mappingBody' ? mappingBodyTableProps : requestTableProps;
|
||
const tableRef = target === 'mappingBody' ? mappingBodyTableRef : requestTableRef;
|
||
const rows = Array.isArray(tableProps.data) ? tableProps.data : [];
|
||
if (!rows.length || (target === 'request' && rows.every((r: any) => isBodyRootRow(r)))) {
|
||
$baseMessage('当前没有可匹配的参数字段', 'warning');
|
||
return;
|
||
}
|
||
|
||
const { matched, updated } = applyJsonCommentsToExistingRows(rows, rawJson, {
|
||
isRootRow: isBodyRootRow,
|
||
});
|
||
if (matched === 0) {
|
||
$baseMessage('没有匹配到已有字段,未做任何修改', 'warning');
|
||
return;
|
||
}
|
||
if (updated === 0) {
|
||
$baseMessage(`已匹配 ${matched} 个字段,描述无需更新`, 'info');
|
||
drawerVisible.value = false;
|
||
clearRequestImportEditors();
|
||
return;
|
||
}
|
||
|
||
await nextTick();
|
||
if (tableRef.value?.reloadData) {
|
||
await tableRef.value.reloadData(tableProps.data);
|
||
}
|
||
refreshTabCounts();
|
||
|
||
$baseMessage(`已为 ${updated} 个字段导入注释`, 'success');
|
||
drawerVisible.value = false;
|
||
clearRequestImportEditors();
|
||
} catch (error) {
|
||
$baseMessage(formatCaughtError(error, '导入注释失败,请检查 JSON 格式'), 'error');
|
||
}
|
||
}
|
||
|
||
// 一键导入 Request 参数(自动完成解析和导入)
|
||
async function handleOneClickImport() {
|
||
if (!textareaJson.value && !textareaXml.value) {
|
||
$baseMessage('请先输入Json或Xml内容', 'warning');
|
||
return;
|
||
}
|
||
|
||
analysisLoading.value = true;
|
||
try {
|
||
// 第一步:解析
|
||
const content = tabs.value === 'Json' ? textareaJson.value : textareaXml.value;
|
||
const resp = await postParameterParse({
|
||
parameterParseType: tabs.value === 'Json' ? 1 : 2,
|
||
parameterContent: content,
|
||
});
|
||
const data = (resp as any)?.data || resp;
|
||
dataList.value = data;
|
||
|
||
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||
$baseMessage('解析结果为空', 'warning');
|
||
return;
|
||
}
|
||
|
||
// 确保 dataList.value 有值
|
||
if (!dataList.value) {
|
||
$baseMessage('解析结果为空', 'warning');
|
||
return;
|
||
}
|
||
|
||
// 第二步:自动导入
|
||
analysisLoading.value = false;
|
||
importLoading.value = true;
|
||
|
||
const rc: any[] = cloneDeep(dataList.value);
|
||
const arr: any[] = rc.map((i) => {
|
||
return {
|
||
...i,
|
||
cnName: '',
|
||
description: '',
|
||
optionType: 1,
|
||
alias: i?.alias || i?.name,
|
||
sort: `${i}`,
|
||
};
|
||
});
|
||
|
||
await postParameterValidateParameter(arr);
|
||
|
||
const target = resolveBodyTreeImportTarget();
|
||
const tableProps = target === 'mappingBody' ? mappingBodyTableProps : requestTableProps;
|
||
const tableRef = target === 'mappingBody' ? mappingBodyTableRef : requestTableRef;
|
||
await loadFlatListIntoTreeTable(arr, tableProps, tableRef);
|
||
refreshTabCounts();
|
||
|
||
$baseMessage('导入成功', 'success');
|
||
drawerVisible.value = false;
|
||
clearRequestImportEditors();
|
||
} catch (error) {
|
||
$baseMessage(formatCaughtError(error, '导入失败,请检查报文格式或字段结构'), 'error');
|
||
} finally {
|
||
analysisLoading.value = false;
|
||
importLoading.value = false;
|
||
}
|
||
}
|
||
|
||
// 一键导入 Response 参数(自动完成解析和导入)
|
||
async function handleOneClickImportResponse() {
|
||
if (!textareaJson1.value && !textareaXml1.value) {
|
||
$baseMessage('请先输入Json或Xml内容', 'warning');
|
||
return;
|
||
}
|
||
|
||
analysisLoading.value = true;
|
||
try {
|
||
// 第一步:解析
|
||
const content = tabs1.value === 'Json' ? textareaJson1.value : textareaXml1.value;
|
||
const resp = await postParameterParse({
|
||
parameterParseType: tabs1.value === 'Json' ? 1 : 2,
|
||
parameterContent: content,
|
||
});
|
||
const data = (resp as any)?.data || resp;
|
||
dataList1.value = data;
|
||
|
||
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||
$baseMessage('解析结果为空', 'warning');
|
||
return;
|
||
}
|
||
|
||
// 确保 dataList1.value 有值
|
||
if (!dataList1.value) {
|
||
$baseMessage('解析结果为空', 'warning');
|
||
return;
|
||
}
|
||
|
||
// 第二步:自动导入
|
||
analysisLoading.value = false;
|
||
importLoading.value = true;
|
||
|
||
const rc: any[] = cloneDeep(dataList1.value);
|
||
const arr: any[] = rc.map((i) => {
|
||
return {
|
||
...i,
|
||
cnName: '',
|
||
description: '',
|
||
optionType: 1,
|
||
alias: i?.alias || i?.name,
|
||
sort: `${i}`,
|
||
};
|
||
});
|
||
|
||
await postParameterValidateParameter(arr);
|
||
|
||
await loadFlatListIntoTreeTable(arr, responseTableProps, responseTableRef);
|
||
refreshTabCounts();
|
||
|
||
$baseMessage('导入成功', 'success');
|
||
drawerVisible1.value = false;
|
||
clearResponseImportEditors();
|
||
} catch (error) {
|
||
$baseMessage(formatCaughtError(error, '导入失败,请检查报文格式或字段结构'), 'error');
|
||
} finally {
|
||
analysisLoading.value = false;
|
||
importLoading.value = false;
|
||
}
|
||
}
|
||
|
||
// 解析 Response 参数
|
||
async function JsonXmlClick1() {
|
||
if (!textareaJson1.value && !textareaXml1.value) {
|
||
$baseMessage('请先输入Json或Xml内容', 'warning');
|
||
return;
|
||
}
|
||
|
||
analysisLoading.value = true;
|
||
try {
|
||
const content = tabs1.value === 'Json' ? textareaJson1.value : textareaXml1.value;
|
||
const resp = await postParameterParse({
|
||
parameterParseType: tabs1.value === 'Json' ? 1 : 2,
|
||
parameterContent: content,
|
||
});
|
||
const data = (resp as any)?.data || resp;
|
||
dataList1.value = data;
|
||
$baseMessage('解析成功', 'success');
|
||
} catch (error) {
|
||
$baseMessage(formatCaughtError(error, '解析失败,请检查报文格式'), 'error');
|
||
} finally {
|
||
analysisLoading.value = false;
|
||
}
|
||
}
|
||
|
||
// 导入 Request 参数
|
||
async function importClick() {
|
||
if (!dataList.value) {
|
||
$baseMessage('请先解析参数', 'error');
|
||
return;
|
||
}
|
||
|
||
importLoading.value = true;
|
||
try {
|
||
const rc: any[] = cloneDeep(dataList.value);
|
||
const arr: any[] = rc.map((i) => {
|
||
return {
|
||
...i,
|
||
cnName: '',
|
||
description: '',
|
||
optionType: 1,
|
||
alias: i?.alias || i?.name,
|
||
sort: `${i}`,
|
||
};
|
||
});
|
||
|
||
await postParameterValidateParameter(arr);
|
||
$baseMessage('导入成功', 'success');
|
||
|
||
const target = requestTab.value === 'mappingBody' ? 'mappingBody' : resolveBodyTreeImportTarget();
|
||
const tableProps = target === 'mappingBody' ? mappingBodyTableProps : requestTableProps;
|
||
const tableRef = target === 'mappingBody' ? mappingBodyTableRef : requestTableRef;
|
||
const rows = (dataList.value || []).map((i: any) => ({
|
||
...i,
|
||
cnName: i.cnName ?? '',
|
||
optionType: 1,
|
||
alias: i?.alias || i?.name,
|
||
}));
|
||
await loadFlatListIntoTreeTable(rows, tableProps, tableRef);
|
||
refreshTabCounts();
|
||
|
||
drawerVisible.value = false;
|
||
clearRequestImportEditors();
|
||
} catch (error) {
|
||
$baseMessage(formatCaughtError(error, '导入失败,请检查报文格式或字段结构'), 'error');
|
||
} finally {
|
||
importLoading.value = false;
|
||
}
|
||
}
|
||
|
||
// 导入 Response 参数
|
||
async function importClick1() {
|
||
if (!dataList1.value) {
|
||
$baseMessage('请先解析参数', 'error');
|
||
return;
|
||
}
|
||
|
||
importLoading.value = true;
|
||
try {
|
||
const rc: any[] = cloneDeep(dataList1.value);
|
||
const arr: any[] = rc.map((i) => {
|
||
return {
|
||
...i,
|
||
cnName: '',
|
||
description: '',
|
||
optionType: 1,
|
||
alias: i?.alias || i?.name,
|
||
sort: `${i}`,
|
||
};
|
||
});
|
||
|
||
await postParameterValidateParameter(arr);
|
||
|
||
const rows = (dataList1.value || []).map((i: any) => ({
|
||
...i,
|
||
cnName: i.cnName ?? '',
|
||
optionType: 1,
|
||
alias: i?.alias || i?.name,
|
||
}));
|
||
await loadFlatListIntoTreeTable(rows, responseTableProps, responseTableRef);
|
||
refreshTabCounts();
|
||
$baseMessage('导入成功', 'success');
|
||
|
||
drawerVisible1.value = false;
|
||
clearResponseImportEditors();
|
||
} catch (error) {
|
||
$baseMessage(formatCaughtError(error, '导入失败,请检查报文格式或字段结构'), 'error');
|
||
} finally {
|
||
importLoading.value = false;
|
||
}
|
||
}
|
||
|
||
async function reloadKvTable(
|
||
tableProps: { data: any[] },
|
||
tableRef: { value?: { reloadData?: (rows: any[]) => void } },
|
||
rows: any[],
|
||
commonList: any[] = [],
|
||
) {
|
||
await applyKvTableWithCommon(tableProps, tableRef, rows, commonList);
|
||
}
|
||
|
||
async function loadFlatListIntoTreeTable(
|
||
flatList: any[],
|
||
tableProps: { data: any[] },
|
||
tableRef: { value?: { reloadData?: (rows: any[]) => void; xGrid?: any; addRowsAt?: (row: any, index: number) => any } },
|
||
) {
|
||
// 全量覆盖:必须 reloadData 整表替换;禁止 addRowsAt 追加(否则肉眼像全量、保存仍是增量)
|
||
let rows = flatParameterListToTableRows(sortFlatParameterListParentFirst(flatList));
|
||
if (tableProps === requestTableProps) {
|
||
rows = ensureBodyRootInRows(rows);
|
||
}
|
||
tableProps.data = rows;
|
||
await nextTick();
|
||
if (tableRef.value?.reloadData) {
|
||
await tableRef.value.reloadData(rows);
|
||
} else {
|
||
// 无 reloadData 时先清空再写入,避免残留旧行
|
||
tableProps.data = [];
|
||
await nextTick();
|
||
tableProps.data = rows;
|
||
}
|
||
await nextTick();
|
||
const xGrid = tableRef.value?.xGrid;
|
||
if (xGrid?.setAllTreeExpand) {
|
||
xGrid.setAllTreeExpand(true);
|
||
}
|
||
// reloadData 会清空 VXE recordset,必须手动标脏,否则保存按钮不出现
|
||
markDirty();
|
||
}
|
||
|
||
/** Json/Xml → Body 树;FormUrlEncoded / None → Mapping Body 树 */
|
||
function resolveBodyTreeImportTarget(): 'mappingBody' | 'request' {
|
||
if (isDownstreamMode.value && isMappingBodyContentType(props.basicFormData?.contentType)) {
|
||
return 'mappingBody';
|
||
}
|
||
return 'request';
|
||
}
|
||
|
||
async function importJsonToParameterTree(
|
||
jsonBodies: string[],
|
||
target?: 'mappingBody' | 'request',
|
||
): Promise<boolean> {
|
||
const resolvedTarget = target ?? resolveBodyTreeImportTarget();
|
||
const tableProps = resolvedTarget === 'mappingBody' ? mappingBodyTableProps : requestTableProps;
|
||
const tableRef = resolvedTarget === 'mappingBody' ? mappingBodyTableRef : requestTableRef;
|
||
const parseOpts = {
|
||
resolveParameterType: (kind: 'string' | 'number' | 'boolean' | 'object' | 'array') =>
|
||
resolveParameterType(kind),
|
||
idFactory: () => random(1, 2099999999),
|
||
};
|
||
|
||
const bestText = pickBestJsonBodyText(jsonBodies, [], {
|
||
...parseOpts,
|
||
rawJsonForComments: jsonBodies[0],
|
||
});
|
||
const orderedBodies = bestText
|
||
? [bestText, ...jsonBodies.filter((b) => b !== bestText)]
|
||
: jsonBodies;
|
||
|
||
let bestFlat: any[] = [];
|
||
for (const jsonText of orderedBodies) {
|
||
if (!jsonText?.trim()) continue;
|
||
try {
|
||
const flatList = parseJsonTextToParameterFlatList(jsonText, {
|
||
...parseOpts,
|
||
rawJsonForComments: jsonText,
|
||
});
|
||
if (flatList.length > bestFlat.length) {
|
||
bestFlat = flatList;
|
||
}
|
||
} catch {
|
||
/* try next candidate */
|
||
}
|
||
}
|
||
|
||
if (!bestFlat.length) return false;
|
||
await loadFlatListIntoTreeTable(bestFlat, tableProps, tableRef);
|
||
return true;
|
||
}
|
||
|
||
/** 从 cURL 智能填充(方案 B:Query / Header / Body KV / Mapping Body / Request Body) */
|
||
async function applyCurlSmartFill(rawCurl: string) {
|
||
const payload = buildCurlInterfaceFillPayload(rawCurl, () => random(1, 2099999999));
|
||
const contentType = normalizeContentType(payload.contentType);
|
||
const isForm = isFormUrlEncodedContentType(contentType);
|
||
const isNone = isNoneContentType(contentType);
|
||
|
||
const nextBasic = {
|
||
...(props.basicFormData as any),
|
||
...payload.basicForm,
|
||
contentType,
|
||
};
|
||
emit('update:basicFormData', nextBasic);
|
||
await nextTick();
|
||
refBasicForm.value?.setFormValue?.(nextBasic);
|
||
|
||
await reloadKvTable(
|
||
queryTableProps,
|
||
queryTableRef,
|
||
payload.queryParams,
|
||
inheritedQueryParams.value,
|
||
);
|
||
|
||
if (isDownstreamMode.value) {
|
||
await reloadKvTable(
|
||
headerTableProps,
|
||
headerTableRef,
|
||
payload.headerParams ?? [],
|
||
inheritedHeaderParams.value,
|
||
);
|
||
await reloadKvTable(
|
||
bodyFormTableProps,
|
||
bodyFormTableRef,
|
||
isForm ? payload.bodyFormParams : [],
|
||
inheritedBodyParams.value,
|
||
);
|
||
if (!isForm && !isNone) {
|
||
mappingBodyTableProps.data = [];
|
||
await nextTick();
|
||
mappingBodyTableRef.value?.reloadData?.([]);
|
||
}
|
||
} else {
|
||
fixedParams.value = payload.fixedParams;
|
||
// 有固定配置数据 ≠ 未保存更改;加载后应视为干净
|
||
fixedParamsHasChanges.value = false;
|
||
await nextTick();
|
||
queryFixedTableRef.value?.reloadData?.(payload.fixedParams);
|
||
}
|
||
|
||
requestExample.value = payload.requestExample;
|
||
|
||
let mappingBodyImported = false;
|
||
let requestBodyImported = false;
|
||
|
||
// 先切到 Body / Mapping Body,确保树表已挂载再写入
|
||
if (isDownstreamMode.value && isForm) {
|
||
requestTab.value = 'mappingBody';
|
||
} else if (isNone) {
|
||
requestTab.value = payload.queryParams.length > 0 ? 'query' : 'body';
|
||
} else {
|
||
requestTab.value = 'body';
|
||
}
|
||
await nextTick();
|
||
await nextTick();
|
||
|
||
if (isNone) {
|
||
requestTab.value = payload.queryParams.length > 0 ? 'query' : 'mappingBody';
|
||
applyRequestBodyTableData([]);
|
||
bodyFormTableProps.data = [];
|
||
await nextTick();
|
||
bodyFormTableRef.value?.reloadData?.([]);
|
||
if (payload.jsonBodies.length) {
|
||
mappingBodyImported = await importJsonToParameterTree(payload.jsonBodies, 'mappingBody');
|
||
if (mappingBodyImported) {
|
||
requestTab.value = 'mappingBody';
|
||
await nextTick();
|
||
setTimeout(() => initMappingBodyRowSortable(), 400);
|
||
}
|
||
} else {
|
||
mappingBodyTableProps.data = [];
|
||
await nextTick();
|
||
mappingBodyTableRef.value?.reloadData?.([]);
|
||
}
|
||
} else if (!payload.jsonBodies.length && payload.parsed.body?.trim()) {
|
||
const bodyText = payload.parsed.body.trim();
|
||
if (bodyText.startsWith('{') || bodyText.startsWith('[')) {
|
||
payload.jsonBodies.push(bodyText);
|
||
}
|
||
}
|
||
|
||
if (isNone) {
|
||
/* mappingBody 已在上方按需导入 */
|
||
} else if (isDownstreamMode.value && isForm) {
|
||
mappingBodyImported = await importJsonToParameterTree(payload.jsonBodies, 'mappingBody');
|
||
if (mappingBodyImported) {
|
||
await nextTick();
|
||
setTimeout(() => initMappingBodyRowSortable(), 400);
|
||
}
|
||
applyRequestBodyTableData([]);
|
||
} else {
|
||
requestBodyImported = await importJsonToParameterTree(payload.jsonBodies, 'request');
|
||
if (isDownstreamMode.value) {
|
||
bodyFormTableProps.data = [];
|
||
await nextTick();
|
||
bodyFormTableRef.value?.reloadData?.([]);
|
||
}
|
||
}
|
||
|
||
refreshTabCounts();
|
||
|
||
const result = buildSmartFillResult(payload, {
|
||
mappingBodyImported,
|
||
requestBodyImported,
|
||
});
|
||
if (!requestBodyImported && !mappingBodyImported) {
|
||
requestTab.value = result.suggestedRequestTab;
|
||
}
|
||
|
||
return {
|
||
...result,
|
||
requestParamsSnapshot: requestBodyImported ? getRequestBodyFlatParams() : [],
|
||
mappingBodyParamsSnapshot: mappingBodyImported
|
||
? getTreeTableFlatRows(
|
||
mappingBodyTableRef.value?.getTableData?.()?.fullData
|
||
|| mappingBodyTableRef.value?.xGrid?.getTableData()?.fullData,
|
||
mappingBodyTableProps.data,
|
||
)
|
||
: [],
|
||
};
|
||
}
|
||
|
||
// 暴露表单方法
|
||
defineExpose({
|
||
applyCurlSmartFill,
|
||
getBasicFormValues: () => {
|
||
const formValues = refBasicForm.value?.getValues() || {};
|
||
if (props.showContentTypeSelectors) {
|
||
return {
|
||
...formValues,
|
||
// Header 区域字段不在 FormPro 的表单项里(InterfaceDetail 内部会过滤 requestAddress/requestMethod)
|
||
// saveInterface() 需要这些字段参与校验,所以这里强制从 basicFormData 合并回去。
|
||
requestAddress: (props.basicFormData as any)?.requestAddress,
|
||
requestMethod: (props.basicFormData as any)?.requestMethod,
|
||
// requestProtocol 在 FormPro 中通常是可获取的;避免被 basicFormData 的 undefined 覆盖
|
||
requestProtocol:
|
||
(formValues as any)?.requestProtocol ?? (props.basicFormData as any)?.requestProtocol,
|
||
contentType: props.basicFormData?.contentType,
|
||
responseContentType: props.basicFormData?.responseContentType,
|
||
mappedParamType: props.basicFormData?.mappedParamType,
|
||
};
|
||
}
|
||
return formValues;
|
||
},
|
||
setBasicFormValues: (values: any) => refBasicForm.value?.setFormValue(values),
|
||
validateBasicForm: () => refBasicForm.value?.validate(),
|
||
getBasicFormErrors: () => refBasicForm.value?.getFieldsError?.(),
|
||
// 获取参数数据
|
||
getQueryParams: () => {
|
||
const data = queryTableRef.value?.getTableData?.()?.fullData || queryTableRef.value?.xGrid?.getTableData()?.fullData || [];
|
||
return data;
|
||
},
|
||
getRequestParams: () => getRequestBodyFlatParams(),
|
||
getResponseParams: () => {
|
||
const data = responseTableRef.value?.getTableData?.()?.fullData || responseTableRef.value?.xGrid?.getTableData()?.fullData || [];
|
||
return data;
|
||
},
|
||
// 获取表格变更记录(用于保存时区分新增、删除、更新)
|
||
getQueryActionRows: () => queryTableRef.value?.getActionRows?.() || { insertRecords: [], removeRecords: [], updateRecords: [] },
|
||
getHeaderParams: () =>
|
||
headerTableRef.value?.getTableData?.()?.fullData
|
||
|| headerTableRef.value?.xGrid?.getTableData()?.fullData
|
||
|| [],
|
||
getHeaderActionRows: () => headerTableRef.value?.getActionRows?.() || { insertRecords: [], removeRecords: [], updateRecords: [] },
|
||
getBodyFormParams: () =>
|
||
bodyFormTableRef.value?.getTableData?.()?.fullData
|
||
|| bodyFormTableRef.value?.xGrid?.getTableData()?.fullData
|
||
|| [],
|
||
getBodyFormActionRows: () => bodyFormTableRef.value?.getActionRows?.() || { insertRecords: [], removeRecords: [], updateRecords: [] },
|
||
getMappingBodyParams: () => {
|
||
const fromGrid =
|
||
mappingBodyTableRef.value?.getTableData?.()?.fullData
|
||
|| mappingBodyTableRef.value?.xGrid?.getTableData()?.fullData;
|
||
return getTreeTableFlatRows(fromGrid, mappingBodyTableProps.data);
|
||
},
|
||
getMappingBodyActionRows: () => mappingBodyTableRef.value?.getActionRows?.() || { insertRecords: [], removeRecords: [], updateRecords: [] },
|
||
getRequestActionRows: () =>
|
||
stripBodyRootFromActionRows(
|
||
requestTableRef.value?.getActionRows?.() || {
|
||
insertRecords: [],
|
||
removeRecords: [],
|
||
updateRecords: [],
|
||
},
|
||
),
|
||
getResponseActionRows: () => responseTableRef.value?.getActionRows?.() || { insertRecords: [], removeRecords: [], updateRecords: [] },
|
||
getQueryTableRef: () => queryTableRef.value,
|
||
getHeaderTableRef: () => headerTableRef.value,
|
||
getBodyFormTableRef: () => bodyFormTableRef.value,
|
||
getMappingBodyTableRef: () => mappingBodyTableRef.value,
|
||
getRequestTableRef: () => requestTableRef.value,
|
||
getResponseTableRef: () => responseTableRef.value,
|
||
getRequestExample: () => requestExample.value,
|
||
getResponseExample: () => responseExample.value,
|
||
hasUnsavedChanges,
|
||
confirmLeaveUnsaved,
|
||
validateDetailParamsBeforeSave,
|
||
captureDirtyBaseline,
|
||
markDirty,
|
||
refreshInheritedCommonParams,
|
||
isDirty: () => isDirty.value,
|
||
getSaveSnapshot: (): InterfaceDetailSnapshot => ({
|
||
queryParams: stripCommonRows(
|
||
queryTableRef.value?.getTableData?.()?.fullData
|
||
|| queryTableRef.value?.xGrid?.getTableData()?.fullData
|
||
|| queryTableProps.data
|
||
|| [],
|
||
),
|
||
headerParams: stripCommonRows(
|
||
headerTableRef.value?.getTableData?.()?.fullData
|
||
|| headerTableRef.value?.xGrid?.getTableData()?.fullData
|
||
|| headerTableProps.data
|
||
|| [],
|
||
),
|
||
bodyFormParams: stripCommonRows(
|
||
bodyFormTableRef.value?.getTableData?.()?.fullData
|
||
|| bodyFormTableRef.value?.xGrid?.getTableData()?.fullData
|
||
|| bodyFormTableProps.data
|
||
|| [],
|
||
),
|
||
requestParams: getRequestBodyFlatParams(),
|
||
mappingBodyParams: getTreeTableFlatRows(
|
||
mappingBodyTableRef.value?.getTableData?.()?.fullData
|
||
|| mappingBodyTableRef.value?.xGrid?.getTableData()?.fullData,
|
||
mappingBodyTableProps.data,
|
||
),
|
||
responseParams: responseTableRef.value?.getTableData?.()?.fullData
|
||
|| responseTableRef.value?.xGrid?.getTableData()?.fullData
|
||
|| responseTableProps.data
|
||
|| [],
|
||
queryActionRows: filterCommonFromActionRows(queryTableRef.value?.getActionRows?.()),
|
||
headerActionRows: filterCommonFromActionRows(headerTableRef.value?.getActionRows?.()),
|
||
bodyFormActionRows: filterCommonFromActionRows(bodyFormTableRef.value?.getActionRows?.()),
|
||
requestActionRows: stripBodyRootFromActionRows(
|
||
requestTableRef.value?.getActionRows?.() || {
|
||
insertRecords: [],
|
||
removeRecords: [],
|
||
updateRecords: [],
|
||
},
|
||
),
|
||
mappingBodyActionRows: mappingBodyTableRef.value?.getActionRows?.() || { insertRecords: [], removeRecords: [], updateRecords: [] },
|
||
responseActionRows: responseTableRef.value?.getActionRows?.() || { insertRecords: [], removeRecords: [], updateRecords: [] },
|
||
queryTableRef: queryTableRef.value,
|
||
headerTableRef: headerTableRef.value,
|
||
bodyFormTableRef: bodyFormTableRef.value,
|
||
requestTableRef: requestTableRef.value,
|
||
mappingBodyTableRef: mappingBodyTableRef.value,
|
||
responseTableRef: responseTableRef.value,
|
||
requestExample: requestExample.value,
|
||
originalParamIds: originalParamIds.value,
|
||
}),
|
||
captureOriginalParamIds,
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<div class="interface-detail">
|
||
<!-- 请求方式 + 请求地址(独立容器,参考 ApiTest api-test-header) -->
|
||
<div class="api-test-header">
|
||
<a-select
|
||
v-if="useFormEdit"
|
||
:model-value="basicFormData?.requestMethod"
|
||
:class="['method-select', `method-${(getMethodText(basicFormData?.requestMethod) || 'get').toLowerCase()}`]"
|
||
placeholder="请求方法"
|
||
:style="{ width: '120px' }"
|
||
allow-clear
|
||
@update:model-value="emit('update:basicFormData', { ...basicFormData, requestMethod: $event })"
|
||
>
|
||
<a-option
|
||
v-for="opt in requestMethodOptions"
|
||
:key="opt.key"
|
||
:value="opt.key"
|
||
:class="`method-${(opt.value || '').toLowerCase()}`"
|
||
>
|
||
{{ opt.value }}
|
||
</a-option>
|
||
</a-select>
|
||
<span v-else class="method-badge" :class="`method-${(displayRequestMethod || 'get').toLowerCase()}`">
|
||
{{ displayRequestMethod || '-' }}
|
||
</span>
|
||
<a-input
|
||
v-if="useFormEdit"
|
||
:model-value="basicFormData?.requestAddress"
|
||
placeholder="接口路径"
|
||
class="url-input"
|
||
@update:model-value="emit('update:basicFormData', { ...basicFormData, requestAddress: $event })"
|
||
/>
|
||
<span v-else class="url-text">{{ (basicParams as any)?.requestAddress || '-' }}</span>
|
||
<div v-if="isDirty || $slots.headerActions" class="header-actions">
|
||
<span
|
||
v-if="isDirty"
|
||
class="dirty-badge"
|
||
title="有未保存的更改;保存成功后如需生效请去发布"
|
||
>
|
||
<i class="dirty-dot" />
|
||
未保存
|
||
</span>
|
||
<slot name="headerActions" />
|
||
</div>
|
||
</div>
|
||
|
||
<div class="detail-grid" :class="`layout-${panelLayout}`">
|
||
<!-- 顶部:基本参数(一行) -->
|
||
<div class="detail-section section-basic section-basic-fullwidth">
|
||
<div class="section-content section-basic-content">
|
||
<!-- 表单编辑模式 -->
|
||
<FormPro
|
||
v-if="useFormEdit"
|
||
ref="refBasicForm"
|
||
:model-value="basicFormData"
|
||
@update:model-value="emit('update:basicFormData', $event)"
|
||
:button-config="{ showBtn: false }"
|
||
:default-span="8"
|
||
:row-gutter="12"
|
||
:form-layout="'vertical'"
|
||
:item-list="basicFormItemsForLayout"
|
||
:required-position="'none'"
|
||
:rules="basicFormRules"
|
||
:hide-colon="false"
|
||
size="mini"
|
||
class="basic-form-pro"
|
||
/>
|
||
<!-- 只读显示模式 -->
|
||
<div v-else class="basic-form">
|
||
<div class="form-item" v-for="(value, key) in basicParamsForDisplay" :key="key">
|
||
<div class="form-label">{{ key }}</div>
|
||
<div class="form-value">{{ value || '-' }}</div>
|
||
</div>
|
||
<div v-if="Object.keys(basicParamsForDisplay).length === 0" class="empty-placeholder">
|
||
<a-empty description="暂无基本信息" />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 左下:Request(含 Query、固定配置、Body、cURL) -->
|
||
<div class="detail-section section-request" :class="{ 'section-request-fixed-tab': requestTab === 'fixed' }">
|
||
<div class="section-header">
|
||
<SlidingTabs
|
||
v-model="requestTab"
|
||
class="request-header-tabs"
|
||
size="mini"
|
||
:items="requestTabItems"
|
||
aria-label="Request tabs"
|
||
/>
|
||
<div class="section-header-right">
|
||
<div class="section-actions">
|
||
<a-button
|
||
v-if="showRequestTabClearAction && !isBodyTreeClearInRoot"
|
||
size="small"
|
||
class="section-icon-btn"
|
||
:disabled="!canClearCurrentRequestTab"
|
||
title="清空当前 Tab 内容"
|
||
@click="confirmClearCurrentRequestTab"
|
||
>
|
||
<IconEraser />
|
||
</a-button>
|
||
<template v-if="requestTab === 'query'">
|
||
<a-button size="small" class="section-icon-btn" title="新增" @click="addNewQueryParam">
|
||
<IconPlus />
|
||
</a-button>
|
||
</template>
|
||
<template v-else-if="requestTab === 'header'">
|
||
<a-button size="small" class="section-icon-btn" title="新增" @click="addNewHeaderParam">
|
||
<IconPlus />
|
||
</a-button>
|
||
</template>
|
||
<template v-else-if="requestTab === 'fixed'">
|
||
<a-button size="small" class="section-icon-btn" title="新增" @click="addFixedParam">
|
||
<IconPlus />
|
||
</a-button>
|
||
<a-button size="small" @click="saveFixedParams">保存固定配置</a-button>
|
||
</template>
|
||
<template v-else-if="requestTab === 'body' && isBodyKvMode">
|
||
<a-button
|
||
size="small"
|
||
class="section-icon-btn"
|
||
title="复制参数为带 // 描述的 JSON"
|
||
@click="copyBodyParamsAsCommentedJson"
|
||
>
|
||
<IconCopy />
|
||
</a-button>
|
||
<a-button size="small" class="section-icon-btn" title="新增" @click="addNewBodyFormParam">
|
||
<IconPlus />
|
||
</a-button>
|
||
</template>
|
||
<template v-else-if="requestTab === 'body' && !isNoneBodyContentType">
|
||
<a-button
|
||
size="small"
|
||
class="section-icon-btn"
|
||
title="复制参数为带 // 描述的 JSON"
|
||
@click="copyBodyParamsAsCommentedJson"
|
||
>
|
||
<IconCopy />
|
||
</a-button>
|
||
<a-button size="small" class="section-icon-btn" title="新增" @click="addNewRequestParam">
|
||
<IconPlus />
|
||
</a-button>
|
||
<a-button size="small" class="section-icon-btn" title="导入" @click="drawerClick">
|
||
<IconImport />
|
||
</a-button>
|
||
</template>
|
||
<template v-else-if="requestTab === 'mappingBody'">
|
||
<a-button
|
||
size="small"
|
||
class="section-icon-btn"
|
||
title="复制参数为带 // 描述的 JSON"
|
||
@click="copyBodyParamsAsCommentedJson"
|
||
>
|
||
<IconCopy />
|
||
</a-button>
|
||
<a-button size="small" class="section-icon-btn" title="新增" @click="addNewRequestParam">
|
||
<IconPlus />
|
||
</a-button>
|
||
<a-button size="small" class="section-icon-btn" title="导入" @click="drawerClick">
|
||
<IconImport />
|
||
</a-button>
|
||
</template>
|
||
<template v-else-if="requestTab === 'demo'">
|
||
<a-button
|
||
size="small"
|
||
class="section-icon-btn"
|
||
title="复制"
|
||
@click="copyRequestExampleContent"
|
||
>
|
||
<IconCopy />
|
||
</a-button>
|
||
</template>
|
||
<a-popover
|
||
v-model:popup-visible="detailSettingsVisible"
|
||
trigger="click"
|
||
position="br"
|
||
content-class="detail-settings-popover"
|
||
>
|
||
<a-button
|
||
size="small"
|
||
class="detail-settings-btn"
|
||
title="布局与节点展开设置"
|
||
>
|
||
<IconSettings />
|
||
</a-button>
|
||
<template #content>
|
||
<div class="detail-settings-panel">
|
||
<div class="detail-settings-row">
|
||
<span class="detail-settings-label">请求 / 响应布局</span>
|
||
<a-switch
|
||
class="layout-switch"
|
||
:model-value="panelLayout === 'vertical'"
|
||
checked-text="上下"
|
||
unchecked-text="左右"
|
||
title="切换请求 / 响应布局"
|
||
@change="onPanelLayoutSwitch"
|
||
/>
|
||
</div>
|
||
<div class="detail-settings-row">
|
||
<span class="detail-settings-label">参数树节点</span>
|
||
<a-switch
|
||
class="tree-expand-switch"
|
||
:model-value="allDetailTreesExpanded"
|
||
checked-text="展开"
|
||
unchecked-text="折叠"
|
||
title="展开 / 折叠全部参数树节点(含 Response)"
|
||
@change="setAllDetailTreesExpand"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content" :class="{ 'section-content-fixed-tab': requestTab === 'fixed' }">
|
||
<div
|
||
v-if="showContentTypeSelectors && requestTab === 'body'"
|
||
class="content-type-bar"
|
||
>
|
||
<SlidingTabs
|
||
size="mini"
|
||
class="content-type-tabs"
|
||
:model-value="String(basicFormData?.contentType ?? '')"
|
||
:items="requestContentTypeItems"
|
||
aria-label="Request content type"
|
||
@change="updateContentType"
|
||
/>
|
||
</div>
|
||
<!-- Query tab 内容 -->
|
||
<div v-show="requestTab === 'query'" class="query-tab-pane">
|
||
<div class="table-content">
|
||
<TablePro
|
||
ref="queryTableRef"
|
||
v-bind="queryTableProps"
|
||
:row-config="{ isHover: true }"
|
||
:mouse-config="{
|
||
area: false,
|
||
}"
|
||
class="query-params-table"
|
||
>
|
||
<template #name="{ row }">
|
||
<template v-if="isQueryRowEditing(row)">
|
||
<a-input
|
||
v-model="row.name"
|
||
allow-clear
|
||
placeholder="请输入参数名"
|
||
/>
|
||
</template>
|
||
<span v-else class="kv-name-cell">
|
||
{{ row.name || '-' }}
|
||
<span v-if="isCommonParamRow(row)" class="common-param-tag">公共</span>
|
||
</span>
|
||
</template>
|
||
|
||
<template #name_edit="{ row }">
|
||
<a-input
|
||
v-model="row.name"
|
||
allow-clear
|
||
placeholder="请输入参数名"
|
||
/>
|
||
</template>
|
||
|
||
<template #value="{ row }">
|
||
<template v-if="isQueryRowEditing(row)">
|
||
<a-select
|
||
v-model="row.value"
|
||
placeholder="请选择参数值"
|
||
allow-clear
|
||
:loading="parameterPlaceholderLoading"
|
||
>
|
||
<a-option
|
||
v-for="option in parameterPlaceholderList"
|
||
:key="option.key"
|
||
:value="option.value"
|
||
>
|
||
{{ option.value }}
|
||
</a-option>
|
||
</a-select>
|
||
</template>
|
||
<span v-else>{{ row.value || '-' }}</span>
|
||
</template>
|
||
|
||
<template #value_edit="{ row }">
|
||
<a-select
|
||
v-model="row.value"
|
||
placeholder="请选择参数值"
|
||
allow-clear
|
||
:loading="parameterPlaceholderLoading"
|
||
>
|
||
<a-option
|
||
v-for="option in parameterPlaceholderList"
|
||
:key="option.key"
|
||
:value="option.value"
|
||
>
|
||
{{ option.value }}
|
||
</a-option>
|
||
</a-select>
|
||
</template>
|
||
|
||
<template #description="{ row }">
|
||
<template v-if="isQueryRowEditing(row)">
|
||
<a-input
|
||
v-model="row.description"
|
||
allow-clear
|
||
placeholder="请输入描述"
|
||
/>
|
||
</template>
|
||
<span v-else>{{ row.description || '-' }}</span>
|
||
</template>
|
||
|
||
<template #description_edit="{ row }">
|
||
<a-input
|
||
v-model="row.description"
|
||
allow-clear
|
||
placeholder="请输入描述"
|
||
/>
|
||
</template>
|
||
|
||
<template #action="{ row }">
|
||
<a-space v-if="!isCommonParamRow(row)">
|
||
<a-popconfirm content="确定删除该参数?" @ok="deleteQueryRow(row)">
|
||
<a-button type="text" class="row-action-btn">
|
||
<IconDelete />
|
||
</a-button>
|
||
</a-popconfirm>
|
||
</a-space>
|
||
<span v-else class="common-param-action">—</span>
|
||
</template>
|
||
</TablePro>
|
||
</div>
|
||
<div class="query-usage-tip">
|
||
<div class="query-usage-tip-title">Query 用法说明</div>
|
||
<ul class="query-usage-tip-list">
|
||
<li><strong>含义</strong>:配置真实 HTTP 请求 URL 上 <code>?key=value</code> 查询参数(保存为 <code>queryFormParameterList</code>,<code>fieldPosition=Query</code>)。Json / FormUrlEncoded 等类型均可使用。</li>
|
||
<li><strong>参数名</strong>:与服务商文档、curl、Mapping Body / Body 参数树、前置脚本写入字段名保持一致(如 <code>_aop_signature</code>、<code>notifyBizEventDTO</code>)。</li>
|
||
<li><strong>参数值</strong>:使用<strong>占位符</strong>或留空,不要填写 curl 中的真实签名/业务样例;转发前由 Like API 替换。</li>
|
||
<li><code>$FromMappingBody</code>(FormUrlEncoded):Query 上承载业务 JSON 的字段(如 <code>*DTO</code>)填此占位符,映射结果来自 <strong>Mapping Body</strong> 参数树;POST 参数仅在 URL、无 Body 时,DTO 应配置在 Query 而非 Body 表单。</li>
|
||
<li><code>$FromAccount</code>:按参数名从<strong>服务商账户</strong>取值;<code>$TimeStamp</code> / <code>$DateTime</code>:时间;<code>$Token</code>:令牌;<code>$Url</code>:当前请求地址。</li>
|
||
<li><strong>留空</strong>:签名类参数(如 <code>sign</code>、<code>_aop_signature</code>)由<strong>前置脚本</strong>写入。</li>
|
||
<li><strong>参数描述</strong>:可记录备注或 curl 片段,便于对照映射,不参与转发。</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 固定配置 tab 内容 -->
|
||
<div v-show="requestTab === 'fixed'" class="table-content query-fixed-content">
|
||
<a-spin :loading="fixedParamsLoading" class="query-fixed-spin">
|
||
<TablePro
|
||
ref="queryFixedTableRef"
|
||
v-bind="queryFixedTableProps"
|
||
class="query-fixed-params-table"
|
||
keep-source
|
||
>
|
||
<template #fieldName="{ row }">
|
||
<span>{{ row.fieldName || '-' }}</span>
|
||
</template>
|
||
<template #fieldName_edit="{ row }">
|
||
<a-input v-model="row.fieldName" placeholder="请输入参数名" />
|
||
</template>
|
||
|
||
<template #fieldValue="{ row }">
|
||
<span>{{ row.fieldValue || '-' }}</span>
|
||
</template>
|
||
<template #fieldValue_edit="{ row }">
|
||
<a-auto-complete
|
||
v-model="row.fieldValue"
|
||
:data="fixedFieldValueOptions"
|
||
placeholder="请选择或输入参数值"
|
||
allow-clear
|
||
:filter-option="
|
||
(inputValue, option) =>
|
||
!inputValue || String(option.value || '').toLowerCase().includes(String(inputValue).toLowerCase())
|
||
"
|
||
@select="(val) => (row.fieldValue = val)"
|
||
@change="(val) => (row.fieldValue = val)"
|
||
/>
|
||
</template>
|
||
|
||
<template #fieldPositions="{ row }">
|
||
<span>{{ formatFieldPositionsDisplay(row) }}</span>
|
||
</template>
|
||
<template #fieldPositions_edit="{ row }">
|
||
<SelectPro
|
||
v-model="row.fieldPositionList"
|
||
:api="getDictionaryGetList"
|
||
:extra="{ type: 'FieldPosition' }"
|
||
:is-page="false"
|
||
:immediate="true"
|
||
:label-keys="['value']"
|
||
:multiple="true"
|
||
id-key="key"
|
||
placeholder="请选择位置"
|
||
@select-change="(v) => (row.fieldPositions = v)"
|
||
/>
|
||
</template>
|
||
|
||
<template #action="{ row }">
|
||
<a-space>
|
||
<a-popconfirm content="确定删除该参数?" @ok="deleteFixedParam(row)">
|
||
<a-button type="text" class="row-action-btn">
|
||
<IconDelete />
|
||
</a-button>
|
||
</a-popconfirm>
|
||
</a-space>
|
||
</template>
|
||
</TablePro>
|
||
</a-spin>
|
||
</div>
|
||
|
||
<!-- Header tab -->
|
||
<div v-show="requestTab === 'header'" class="query-tab-pane">
|
||
<div class="table-content">
|
||
<TablePro
|
||
ref="headerTableRef"
|
||
v-bind="headerTableProps"
|
||
:row-config="{ isHover: true }"
|
||
class="query-params-table"
|
||
>
|
||
<template #name="{ row }">
|
||
<a-input v-if="isHeaderRowEditing(row)" v-model="row.name" allow-clear placeholder="请输入参数名" />
|
||
<span v-else class="kv-name-cell">
|
||
{{ row.name || '-' }}
|
||
<span v-if="isCommonParamRow(row)" class="common-param-tag">公共</span>
|
||
</span>
|
||
</template>
|
||
<template #name_edit="{ row }">
|
||
<a-input v-model="row.name" allow-clear placeholder="请输入参数名" />
|
||
</template>
|
||
<template #value="{ row }">
|
||
<a-auto-complete
|
||
v-if="isHeaderRowEditing(row)"
|
||
v-model="row.value"
|
||
:data="kvPlaceholderOptions"
|
||
allow-clear
|
||
placeholder="请选择或输入占位符"
|
||
/>
|
||
<span v-else>{{ row.value || '-' }}</span>
|
||
</template>
|
||
<template #value_edit="{ row }">
|
||
<a-auto-complete
|
||
v-model="row.value"
|
||
:data="kvPlaceholderOptions"
|
||
allow-clear
|
||
placeholder="请选择或输入占位符"
|
||
/>
|
||
</template>
|
||
<template #description="{ row }">
|
||
<a-input v-if="isHeaderRowEditing(row)" v-model="row.description" allow-clear placeholder="请输入描述" />
|
||
<span v-else>{{ row.description || '-' }}</span>
|
||
</template>
|
||
<template #description_edit="{ row }">
|
||
<a-input v-model="row.description" allow-clear placeholder="请输入描述" />
|
||
</template>
|
||
<template #action="{ row }">
|
||
<a-popconfirm
|
||
v-if="!isCommonParamRow(row)"
|
||
content="确定删除该参数?"
|
||
@ok="deleteHeaderRow(row)"
|
||
>
|
||
<a-button type="text" class="row-action-btn">
|
||
<IconDelete />
|
||
</a-button>
|
||
</a-popconfirm>
|
||
<span v-else class="common-param-action">—</span>
|
||
</template>
|
||
</TablePro>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Body:none 无请求体 -->
|
||
<div v-show="requestTab === 'body' && isNoneBodyContentType" class="body-none-pane">
|
||
<div class="body-none-tip">当前请求类型为 none,无 HTTP Body;请在 Query / Header / Mapping Body 中配置参数。</div>
|
||
</div>
|
||
|
||
<!-- Body KV(FormUrlEncoded) -->
|
||
<div v-show="requestTab === 'body' && isBodyKvMode" class="table-content body-kv-pane">
|
||
<TablePro
|
||
ref="bodyFormTableRef"
|
||
v-bind="bodyFormTableProps"
|
||
:row-config="{ isHover: true }"
|
||
class="query-params-table"
|
||
>
|
||
<template #name="{ row }">
|
||
<a-input v-if="isBodyFormRowEditing(row)" v-model="row.name" allow-clear placeholder="参数名" />
|
||
<span v-else class="kv-name-cell">
|
||
{{ row.name || '-' }}
|
||
<span v-if="isCommonParamRow(row)" class="common-param-tag">公共</span>
|
||
</span>
|
||
</template>
|
||
<template #name_edit="{ row }">
|
||
<a-input v-model="row.name" allow-clear placeholder="参数名" />
|
||
</template>
|
||
<template #value="{ row }">
|
||
<a-auto-complete
|
||
v-if="isBodyFormRowEditing(row)"
|
||
v-model="row.value"
|
||
:data="kvPlaceholderOptions"
|
||
allow-clear
|
||
placeholder="占位符,如 $FromMappingBody"
|
||
/>
|
||
<span v-else>{{ row.value || '-' }}</span>
|
||
</template>
|
||
<template #value_edit="{ row }">
|
||
<a-auto-complete
|
||
v-model="row.value"
|
||
:data="kvPlaceholderOptions"
|
||
allow-clear
|
||
placeholder="占位符,如 $FromMappingBody"
|
||
/>
|
||
</template>
|
||
<template #description="{ row }">
|
||
<a-input v-if="isBodyFormRowEditing(row)" v-model="row.description" allow-clear />
|
||
<span v-else>{{ row.description || '-' }}</span>
|
||
</template>
|
||
<template #description_edit="{ row }">
|
||
<a-input v-model="row.description" allow-clear />
|
||
</template>
|
||
<template #action="{ row }">
|
||
<a-popconfirm
|
||
v-if="!isCommonParamRow(row)"
|
||
content="确定删除该参数?"
|
||
@ok="deleteBodyFormRow(row)"
|
||
>
|
||
<a-button type="text" class="row-action-btn">
|
||
<IconDelete />
|
||
</a-button>
|
||
</a-popconfirm>
|
||
<span v-else class="common-param-action">—</span>
|
||
</template>
|
||
</TablePro>
|
||
</div>
|
||
|
||
<!-- Body 参数树(Json/Xml 或上游);Json/Xml 下游含 Apifox 式虚拟根节点 -->
|
||
<div v-show="requestTab === 'body' && !isBodyKvMode && !isNoneBodyContentType" class="table-content">
|
||
<TablePro
|
||
ref="requestTableRef"
|
||
v-bind="requestTableProps"
|
||
:tree-config="{
|
||
transform: true,
|
||
rowField: 'id',
|
||
parentField: 'pId',
|
||
lazy: false,
|
||
showIcon: true,
|
||
expandAll: true,
|
||
}"
|
||
:row-config="{ isHover: true }"
|
||
:mouse-config="{
|
||
area: false,
|
||
}"
|
||
:row-class-name="({ row }) => (isBodyRootRow(row) ? 'body-root-tree-row' : '')"
|
||
class="request-params-table"
|
||
>
|
||
<template #asdsad="{ row }">
|
||
<div v-if="!isBodyRootRow(row)" class="flex justify-center items-center">
|
||
<IconDragArrow class="drag-handle-icon" />
|
||
</div>
|
||
</template>
|
||
|
||
<template #name="{ row }">
|
||
<span v-if="isBodyRootRow(row)" class="body-root-name">根节点</span>
|
||
<template v-else-if="isRequestRowEditing(row)">
|
||
<a-input
|
||
v-model="row.name"
|
||
allow-clear
|
||
placeholder="请输入参数名"
|
||
/>
|
||
</template>
|
||
<span v-else class="param-name-text" :class="{ required: row.isRequired }">
|
||
<span v-if="row.isRequired" class="required-star">*</span>{{ row.name || '-' }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #name_edit="{ row }">
|
||
<span v-if="isBodyRootRow(row)" class="body-root-name">根节点</span>
|
||
<a-input
|
||
v-else
|
||
v-model="row.name"
|
||
allow-clear
|
||
placeholder="请输入参数名"
|
||
/>
|
||
</template>
|
||
|
||
<template #type="{ row }">
|
||
<a-popover
|
||
v-if="isBodyRootRow(row)"
|
||
v-model:popup-visible="mappedParamTypePopoverVisible"
|
||
trigger="click"
|
||
position="bl"
|
||
content-class="param-type-popover"
|
||
>
|
||
<span
|
||
class="param-type-text"
|
||
:class="{ placeholder: !selectedMappedParamOption }"
|
||
:style="selectedMappedParamOption
|
||
? { color: selectedMappedParamOption.color, fontWeight: selectedMappedParamOption.fontWeight }
|
||
: undefined"
|
||
>
|
||
{{ selectedMappedParamOption?.label || '请选择' }}
|
||
</span>
|
||
<template #content>
|
||
<div class="param-type-picker">
|
||
<div
|
||
v-for="(opt, optIdx) in rootMappedParamTypeOptions"
|
||
:key="opt.key"
|
||
class="param-type-picker-item"
|
||
:class="{ active: basicFormData?.mappedParamType === opt.key }"
|
||
@click="pickMappedParamType(opt.key)"
|
||
>
|
||
<span :style="getTypeTextStyleByIndex(optIdx, opt)">{{ opt.value }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
<a-popover
|
||
v-else
|
||
:popup-visible="paramTypePopoverRowId === row.id"
|
||
trigger="click"
|
||
position="bl"
|
||
content-class="param-type-popover"
|
||
:disabled="!!row.children?.length"
|
||
@popup-visible-change="(v) => onParamTypePopoverVisibleChange(row, v)"
|
||
>
|
||
<span
|
||
class="param-type-text"
|
||
:class="{
|
||
disabled: !!row.children?.length,
|
||
placeholder: row.type == null,
|
||
}"
|
||
:title="paramTypeLockedTitle(row)"
|
||
:style="row.type != null ? getParameterTypeTextStyle(row.type) : undefined"
|
||
>
|
||
{{ row.type != null ? getParameterTypeName(row.type) || '-' : '请选择类型' }}
|
||
</span>
|
||
<template #content>
|
||
<div class="param-type-picker">
|
||
<div
|
||
v-for="(option, optIdx) in ParameterTypeList"
|
||
:key="option.key"
|
||
class="param-type-picker-item"
|
||
:class="{ active: row.type === option.key }"
|
||
@click="pickParameterType(row, option.key)"
|
||
>
|
||
<span :style="getTypeTextStyleByIndex(optIdx, option)">{{ option.value }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
</template>
|
||
|
||
<template #type_edit="{ row }">
|
||
<a-popover
|
||
v-if="isBodyRootRow(row)"
|
||
v-model:popup-visible="mappedParamTypePopoverVisible"
|
||
trigger="click"
|
||
position="bl"
|
||
content-class="param-type-popover"
|
||
>
|
||
<span
|
||
class="param-type-text"
|
||
:class="{ placeholder: !selectedMappedParamOption }"
|
||
:style="selectedMappedParamOption
|
||
? { color: selectedMappedParamOption.color, fontWeight: selectedMappedParamOption.fontWeight }
|
||
: undefined"
|
||
>
|
||
{{ selectedMappedParamOption?.label || '请选择' }}
|
||
</span>
|
||
<template #content>
|
||
<div class="param-type-picker">
|
||
<div
|
||
v-for="(opt, optIdx) in rootMappedParamTypeOptions"
|
||
:key="opt.key"
|
||
class="param-type-picker-item"
|
||
:class="{ active: basicFormData?.mappedParamType === opt.key }"
|
||
@click="pickMappedParamType(opt.key)"
|
||
>
|
||
<span :style="getTypeTextStyleByIndex(optIdx, opt)">{{ opt.value }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
<a-popover
|
||
v-else
|
||
:popup-visible="paramTypePopoverRowId === row.id"
|
||
trigger="click"
|
||
position="bl"
|
||
content-class="param-type-popover"
|
||
:disabled="!!row.children?.length"
|
||
@popup-visible-change="(v) => onParamTypePopoverVisibleChange(row, v)"
|
||
>
|
||
<span
|
||
class="param-type-text"
|
||
:class="{
|
||
disabled: !!row.children?.length,
|
||
placeholder: row.type == null,
|
||
}"
|
||
:title="paramTypeLockedTitle(row)"
|
||
:style="row.type != null ? getParameterTypeTextStyle(row.type) : undefined"
|
||
>
|
||
{{ row.type != null ? getParameterTypeName(row.type) || '-' : '请选择类型' }}
|
||
</span>
|
||
<template #content>
|
||
<div class="param-type-picker">
|
||
<div
|
||
v-for="(option, optIdx) in ParameterTypeList"
|
||
:key="option.key"
|
||
class="param-type-picker-item"
|
||
:class="{ active: row.type === option.key }"
|
||
@click="pickParameterType(row, option.key)"
|
||
>
|
||
<span :style="getTypeTextStyleByIndex(optIdx, option)">{{ option.value }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
</template>
|
||
|
||
<template #description="{ row }">
|
||
<span v-if="isBodyRootRow(row)" class="body-root-desc">报文最外层结构</span>
|
||
<template v-else-if="isRequestRowEditing(row)">
|
||
<a-input
|
||
v-model="row.description"
|
||
allow-clear
|
||
placeholder="描述或示例值说明"
|
||
/>
|
||
</template>
|
||
<span v-else>{{ row.description || '-' }}</span>
|
||
</template>
|
||
|
||
<template #description_edit="{ row }">
|
||
<span v-if="isBodyRootRow(row)" class="body-root-desc">报文最外层结构</span>
|
||
<a-input
|
||
v-else
|
||
v-model="row.description"
|
||
allow-clear
|
||
placeholder="描述或示例值说明"
|
||
/>
|
||
</template>
|
||
|
||
<template #isRequired="{ row }">
|
||
<a-checkbox
|
||
v-if="!isBodyRootRow(row)"
|
||
v-model="row.isRequired"
|
||
class="required-checkbox"
|
||
:class="{ 'is-on': row.isRequired }"
|
||
@change="markDirty"
|
||
/>
|
||
</template>
|
||
|
||
<template #action="{ row }">
|
||
<a-space :size="2">
|
||
<a-button
|
||
v-if="isBodyRootRow(row)"
|
||
type="text"
|
||
size="mini"
|
||
class="row-action-btn row-clear-btn"
|
||
title="清空当前 Tab 内容"
|
||
:disabled="!canClearCurrentRequestTab"
|
||
@click="confirmClearCurrentRequestTab"
|
||
>
|
||
<IconEraser />
|
||
</a-button>
|
||
<a-button type="text" size="mini" class="row-action-btn" title="新增子节点" @click="addRequestRow(row)">
|
||
<IconPlus />
|
||
</a-button>
|
||
<a-button
|
||
v-if="!isBodyRootRow(row)"
|
||
type="text"
|
||
size="mini"
|
||
class="row-action-btn"
|
||
title="复制行"
|
||
@click="copyBodyTreeRow(row)"
|
||
>
|
||
<IconCopy />
|
||
</a-button>
|
||
<a-popconfirm
|
||
v-if="!isBodyRootRow(row)"
|
||
content="确定删除该参数?"
|
||
@ok="deleteRequestRow(row)"
|
||
>
|
||
<a-button type="text" size="mini" class="row-action-btn" title="删除">
|
||
<IconDelete />
|
||
</a-button>
|
||
</a-popconfirm>
|
||
</a-space>
|
||
</template>
|
||
</TablePro>
|
||
</div>
|
||
|
||
<!-- Mapping Body 参数树(FormUrlEncoded,列与 Body 参数树一致) -->
|
||
<div v-show="requestTab === 'mappingBody'" class="table-content">
|
||
<TablePro
|
||
ref="mappingBodyTableRef"
|
||
v-bind="mappingBodyTableProps"
|
||
:tree-config="{
|
||
transform: true,
|
||
rowField: 'id',
|
||
parentField: 'pId',
|
||
lazy: false,
|
||
showIcon: true,
|
||
}"
|
||
:row-config="{ isHover: true }"
|
||
:mouse-config="{ area: false }"
|
||
class="request-params-table"
|
||
>
|
||
<template #asdsad="{ row }">
|
||
<div class="flex justify-center items-center">
|
||
<IconDragArrow class="drag-handle-icon" />
|
||
</div>
|
||
</template>
|
||
|
||
<template #name="{ row }">
|
||
<template v-if="isMappingBodyRowEditing(row)">
|
||
<a-input v-model="row.name" allow-clear placeholder="请输入参数名" />
|
||
</template>
|
||
<span v-else class="param-name-text" :class="{ required: row.isRequired }">
|
||
<span v-if="row.isRequired" class="required-star">*</span>{{ row.name || '-' }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #name_edit="{ row }">
|
||
<a-input v-model="row.name" allow-clear placeholder="请输入参数名" />
|
||
</template>
|
||
|
||
<template #type="{ row }">
|
||
<a-popover
|
||
:popup-visible="paramTypePopoverRowId === row.id"
|
||
trigger="click"
|
||
position="bl"
|
||
content-class="param-type-popover"
|
||
:disabled="!!row.children?.length"
|
||
@popup-visible-change="(v) => onParamTypePopoverVisibleChange(row, v)"
|
||
>
|
||
<span
|
||
class="param-type-text"
|
||
:class="{
|
||
disabled: !!row.children?.length,
|
||
placeholder: row.type == null,
|
||
}"
|
||
:title="paramTypeLockedTitle(row)"
|
||
:style="row.type != null ? getParameterTypeTextStyle(row.type) : undefined"
|
||
>
|
||
{{ row.type != null ? getParameterTypeName(row.type) || '-' : '请选择类型' }}
|
||
</span>
|
||
<template #content>
|
||
<div class="param-type-picker">
|
||
<div
|
||
v-for="(option, optIdx) in ParameterTypeList"
|
||
:key="option.key"
|
||
class="param-type-picker-item"
|
||
:class="{ active: row.type === option.key }"
|
||
@click="pickParameterType(row, option.key)"
|
||
>
|
||
<span :style="getTypeTextStyleByIndex(optIdx, option)">{{ option.value }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
</template>
|
||
|
||
<template #type_edit="{ row }">
|
||
<a-popover
|
||
:popup-visible="paramTypePopoverRowId === row.id"
|
||
trigger="click"
|
||
position="bl"
|
||
content-class="param-type-popover"
|
||
:disabled="!!row.children?.length"
|
||
@popup-visible-change="(v) => onParamTypePopoverVisibleChange(row, v)"
|
||
>
|
||
<span
|
||
class="param-type-text"
|
||
:class="{
|
||
disabled: !!row.children?.length,
|
||
placeholder: row.type == null,
|
||
}"
|
||
:title="paramTypeLockedTitle(row)"
|
||
:style="row.type != null ? getParameterTypeTextStyle(row.type) : undefined"
|
||
>
|
||
{{ row.type != null ? getParameterTypeName(row.type) || '-' : '请选择类型' }}
|
||
</span>
|
||
<template #content>
|
||
<div class="param-type-picker">
|
||
<div
|
||
v-for="(option, optIdx) in ParameterTypeList"
|
||
:key="option.key"
|
||
class="param-type-picker-item"
|
||
:class="{ active: row.type === option.key }"
|
||
@click="pickParameterType(row, option.key)"
|
||
>
|
||
<span :style="getTypeTextStyleByIndex(optIdx, option)">{{ option.value }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
</template>
|
||
|
||
|
||
<template #description="{ row }">
|
||
<template v-if="isMappingBodyRowEditing(row)">
|
||
<a-input v-model="row.description" allow-clear placeholder="描述或示例值说明" />
|
||
</template>
|
||
<span v-else>{{ row.description || '-' }}</span>
|
||
</template>
|
||
|
||
<template #description_edit="{ row }">
|
||
<a-input v-model="row.description" allow-clear placeholder="描述或示例值说明" />
|
||
</template>
|
||
|
||
<template #isRequired="{ row }">
|
||
<a-checkbox
|
||
v-model="row.isRequired"
|
||
class="required-checkbox"
|
||
:class="{ 'is-on': row.isRequired }"
|
||
@change="markDirty"
|
||
/>
|
||
</template>
|
||
|
||
<template #action="{ row }">
|
||
<a-space :size="2">
|
||
<a-button type="text" size="mini" class="row-action-btn" title="新增子节点" @click="addRequestRow(row)">
|
||
<IconPlus />
|
||
</a-button>
|
||
<a-button type="text" size="mini" class="row-action-btn" title="复制行" @click="copyBodyTreeRow(row)">
|
||
<IconCopy />
|
||
</a-button>
|
||
<a-popconfirm content="确定删除该参数?" @ok="deleteRequestRow(row)">
|
||
<a-button type="text" size="mini" class="row-action-btn" title="删除">
|
||
<IconDelete />
|
||
</a-button>
|
||
</a-popconfirm>
|
||
</a-space>
|
||
</template>
|
||
</TablePro>
|
||
<p class="mapping-body-tip">Mapping Body 为 <code>notifyBizEventDTO</code> 等业务 JSON 映射体;Query/Body 字段可用 <code>$FromMappingBody</code> 引用。</p>
|
||
</div>
|
||
|
||
<!-- Demo tab 内容 -->
|
||
<div v-if="requestTab === 'demo'" class="request-example-content">
|
||
<div class="request-example-container">
|
||
<CodeMirror
|
||
ref="requestExampleEditorRef"
|
||
v-model="requestExample"
|
||
language="json"
|
||
theme="vs"
|
||
:options="{
|
||
automaticLayout: true,
|
||
fontSize: 14,
|
||
minimap: { enabled: false },
|
||
scrollBeyondLastLine: false,
|
||
wordWrap: 'on',
|
||
}"
|
||
height="100%"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 右下:Response -->
|
||
<div class="detail-section section-response">
|
||
<div class="section-header">
|
||
<SlidingTabs
|
||
v-model="responseTab"
|
||
class="response-header-tabs"
|
||
size="mini"
|
||
:items="responseTabItems"
|
||
aria-label="Response tabs"
|
||
/>
|
||
<div class="section-header-right">
|
||
<div class="section-actions">
|
||
<template v-if="responseTab === 'body'">
|
||
<a-button size="small" class="section-icon-btn" title="新增" @click="addNewResponseParam">
|
||
<IconPlus />
|
||
</a-button>
|
||
<a-button size="small" class="section-icon-btn" title="导入" @click="drawerClick1">
|
||
<IconImport />
|
||
</a-button>
|
||
</template>
|
||
<template v-if="responseTab === 'returnConfig'">
|
||
<a-button size="small" class="section-icon-btn" title="新增" @click="addReturnConfigItem">
|
||
<IconPlus />
|
||
</a-button>
|
||
<a-button size="small" @click="saveReturnConfig({ emitSaved: true })">保存返回配置</a-button>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<div
|
||
v-if="showContentTypeSelectors && responseTab === 'body'"
|
||
class="content-type-bar"
|
||
>
|
||
<SlidingTabs
|
||
size="mini"
|
||
class="content-type-tabs"
|
||
:model-value="String(basicFormData?.responseContentType ?? '')"
|
||
:items="responseContentTypeItems"
|
||
aria-label="Response content type"
|
||
@change="updateResponseContentType"
|
||
/>
|
||
<a-button
|
||
size="mini"
|
||
class="content-type-copy-btn section-icon-btn"
|
||
title="复制当前参数为带描述的 JSON"
|
||
@click="copyResponseParamsAsCommentedJson"
|
||
>
|
||
<IconCopy />
|
||
</a-button>
|
||
</div>
|
||
<!-- Response body tab 内容 -->
|
||
<div v-show="responseTab === 'body'" class="table-content">
|
||
<TablePro
|
||
ref="responseTableRef"
|
||
v-bind="responseTableProps"
|
||
:tree-config="{
|
||
transform: true,
|
||
rowField: 'id',
|
||
parentField: 'pId',
|
||
lazy: false,
|
||
showIcon: true,
|
||
}"
|
||
:row-config="{ isHover: true }"
|
||
:mouse-config="{
|
||
area: false,
|
||
}"
|
||
class="response-params-table"
|
||
>
|
||
<template #asdsad="{ row }">
|
||
<div class="flex justify-center items-center">
|
||
<IconDragArrow class="drag-handle-icon" />
|
||
</div>
|
||
</template>
|
||
|
||
<template #name="{ row }">
|
||
<template v-if="isResponseRowEditing(row)">
|
||
<a-input
|
||
v-model="row.name"
|
||
allow-clear
|
||
placeholder="请输入参数名"
|
||
/>
|
||
</template>
|
||
<span v-else class="param-name-text" :class="{ required: row.isRequired }">
|
||
<span v-if="row.isRequired" class="required-star">*</span>{{ row.name || '-' }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #name_edit="{ row }">
|
||
<a-input
|
||
v-model="row.name"
|
||
allow-clear
|
||
placeholder="请输入参数名"
|
||
/>
|
||
</template>
|
||
|
||
<template #type="{ row }">
|
||
<a-popover
|
||
:popup-visible="paramTypePopoverRowId === row.id"
|
||
trigger="click"
|
||
position="bl"
|
||
content-class="param-type-popover"
|
||
:disabled="!!row.children?.length"
|
||
@popup-visible-change="(v) => onParamTypePopoverVisibleChange(row, v)"
|
||
>
|
||
<span
|
||
class="param-type-text"
|
||
:class="{
|
||
disabled: !!row.children?.length,
|
||
placeholder: row.type == null,
|
||
}"
|
||
:title="paramTypeLockedTitle(row)"
|
||
:style="row.type != null ? getParameterTypeTextStyle(row.type) : undefined"
|
||
>
|
||
{{ row.type != null ? getParameterTypeName(row.type) || '-' : '请选择类型' }}
|
||
</span>
|
||
<template #content>
|
||
<div class="param-type-picker">
|
||
<div
|
||
v-for="(option, optIdx) in ParameterTypeList"
|
||
:key="option.key"
|
||
class="param-type-picker-item"
|
||
:class="{ active: row.type === option.key }"
|
||
@click="pickParameterType(row, option.key)"
|
||
>
|
||
<span :style="getTypeTextStyleByIndex(optIdx, option)">{{ option.value }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
</template>
|
||
|
||
<template #type_edit="{ row }">
|
||
<a-popover
|
||
:popup-visible="paramTypePopoverRowId === row.id"
|
||
trigger="click"
|
||
position="bl"
|
||
content-class="param-type-popover"
|
||
:disabled="!!row.children?.length"
|
||
@popup-visible-change="(v) => onParamTypePopoverVisibleChange(row, v)"
|
||
>
|
||
<span
|
||
class="param-type-text"
|
||
:class="{
|
||
disabled: !!row.children?.length,
|
||
placeholder: row.type == null,
|
||
}"
|
||
:title="paramTypeLockedTitle(row)"
|
||
:style="row.type != null ? getParameterTypeTextStyle(row.type) : undefined"
|
||
>
|
||
{{ row.type != null ? getParameterTypeName(row.type) || '-' : '请选择类型' }}
|
||
</span>
|
||
<template #content>
|
||
<div class="param-type-picker">
|
||
<div
|
||
v-for="(option, optIdx) in ParameterTypeList"
|
||
:key="option.key"
|
||
class="param-type-picker-item"
|
||
:class="{ active: row.type === option.key }"
|
||
@click="pickParameterType(row, option.key)"
|
||
>
|
||
<span :style="getTypeTextStyleByIndex(optIdx, option)">{{ option.value }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-popover>
|
||
</template>
|
||
|
||
|
||
<template #description="{ row }">
|
||
<template v-if="isResponseRowEditing(row)">
|
||
<a-input
|
||
v-model="row.description"
|
||
allow-clear
|
||
placeholder="描述或示例值说明"
|
||
/>
|
||
</template>
|
||
<span v-else>{{ row.description || '-' }}</span>
|
||
</template>
|
||
|
||
<template #description_edit="{ row }">
|
||
<a-input
|
||
v-model="row.description"
|
||
allow-clear
|
||
placeholder="描述或示例值说明"
|
||
/>
|
||
</template>
|
||
|
||
<template #isRequired="{ row }">
|
||
<a-checkbox
|
||
v-model="row.isRequired"
|
||
class="required-checkbox"
|
||
:class="{ 'is-on': row.isRequired }"
|
||
@change="markDirty"
|
||
/>
|
||
</template>
|
||
|
||
<template #action="{ row }">
|
||
<a-space :size="2">
|
||
<a-button type="text" size="mini" class="row-action-btn" title="新增子节点" @click="addResponseRow(row)">
|
||
<IconPlus />
|
||
</a-button>
|
||
<a-button type="text" size="mini" class="row-action-btn" title="复制行" @click="copyResponseRow(row)">
|
||
<IconCopy />
|
||
</a-button>
|
||
<a-popconfirm content="确定删除该参数?" @ok="deleteResponseRow(row)">
|
||
<a-button type="text" size="mini" class="row-action-btn" title="删除">
|
||
<IconDelete />
|
||
</a-button>
|
||
</a-popconfirm>
|
||
</a-space>
|
||
</template>
|
||
</TablePro>
|
||
</div>
|
||
|
||
<!-- Response 返回配置 tab 内容 -->
|
||
<div v-show="responseTab === 'returnConfig'" class="response-return-config-content">
|
||
<ReturnConfig
|
||
ref="returnConfigRef"
|
||
:interface-id="props.interfaceId"
|
||
/>
|
||
</div>
|
||
|
||
<!-- Response Demo tab 内容 -->
|
||
<div v-if="responseTab === 'demo'" class="response-example-content">
|
||
<div class="response-example-container">
|
||
<CodeMirror
|
||
ref="responseExampleEditorRef"
|
||
v-model="responseExample"
|
||
language="json"
|
||
theme="vs"
|
||
:options="{
|
||
automaticLayout: true,
|
||
fontSize: 14,
|
||
minimap: { enabled: false },
|
||
scrollBeyondLastLine: false,
|
||
wordWrap: 'on',
|
||
}"
|
||
height="100%"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Request 参数导入弹窗 -->
|
||
<a-modal
|
||
v-model:visible="drawerVisible"
|
||
:width="800"
|
||
title="导入请求参数"
|
||
:footer="false"
|
||
unmount-on-close
|
||
:mask-closable="!analysisBusy"
|
||
:esc-to-close="!analysisBusy"
|
||
class="analysis-modal"
|
||
@cancel="cancelClick"
|
||
>
|
||
<div class="analysis-content">
|
||
<div class="analysis-tip">
|
||
粘贴 JSON 或 XML 内容后<strong>全量替换</strong>当前参数树(先清空再导入,保存时会删除库中旧节点)。JSON 可用「前端解析」(支持 <code>//</code> 备注写入描述)、「仅导入注释」(只更新已有字段描述,不新增/不删树),或使用「解析并导入」走后端解析。
|
||
</div>
|
||
<div class="analysis-tabs">
|
||
<SlidingTabs v-model="tabs" size="mini" :items="analysisTypeItems" aria-label="Import format" />
|
||
<div v-show="tabs === 'Json'" class="editor-container">
|
||
<CodeMirror
|
||
ref="jsonEditorRef"
|
||
v-model="textareaJson"
|
||
language="json"
|
||
theme="vs"
|
||
:options="{
|
||
automaticLayout: true,
|
||
fontSize: 14,
|
||
minimap: { enabled: false },
|
||
scrollBeyondLastLine: false,
|
||
wordWrap: 'on',
|
||
}"
|
||
:height="400"
|
||
/>
|
||
</div>
|
||
<div v-show="tabs === 'Xml'" class="editor-container">
|
||
<CodeMirror
|
||
ref="xmlEditorRef"
|
||
v-model="textareaXml"
|
||
language="xml"
|
||
theme="vs"
|
||
:options="{
|
||
automaticLayout: true,
|
||
fontSize: 14,
|
||
minimap: { enabled: false },
|
||
scrollBeyondLastLine: false,
|
||
wordWrap: 'on',
|
||
}"
|
||
:height="400"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="analysis-footer">
|
||
<a-button
|
||
size="small"
|
||
:disabled="!requestImportContent || analysisBusy"
|
||
@click="clearRequestImportEditors"
|
||
>
|
||
清空
|
||
</a-button>
|
||
<div class="analysis-footer-actions">
|
||
<a-button :disabled="analysisBusy" @click="cancelClick">取消</a-button>
|
||
<a-button
|
||
v-if="tabs === 'Json'"
|
||
type="outline"
|
||
class="btn-app-outline"
|
||
:disabled="!textareaJson?.trim() || analysisBusy"
|
||
@click="handleImportCommentsOnly"
|
||
>
|
||
仅导入注释
|
||
</a-button>
|
||
<a-button
|
||
v-if="tabs === 'Json'"
|
||
type="outline"
|
||
class="btn-app-outline"
|
||
:disabled="!textareaJson?.trim() || analysisBusy"
|
||
@click="handleFrontendParseRequest"
|
||
>
|
||
前端解析
|
||
</a-button>
|
||
<a-button
|
||
type="primary"
|
||
:loading="analysisBusy"
|
||
:disabled="!requestImportContent"
|
||
@click="handleOneClickImport"
|
||
>
|
||
解析并导入
|
||
</a-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</a-modal>
|
||
|
||
<!-- Response 参数导入弹窗 -->
|
||
<a-modal
|
||
v-model:visible="drawerVisible1"
|
||
:width="800"
|
||
title="导入响应参数"
|
||
:footer="false"
|
||
unmount-on-close
|
||
:mask-closable="!analysisBusy"
|
||
:esc-to-close="!analysisBusy"
|
||
class="analysis-modal"
|
||
@cancel="cancelClick1"
|
||
>
|
||
<div class="analysis-content">
|
||
<div class="analysis-tip">
|
||
粘贴 JSON 或 XML 响应示例,点击「解析并导入」将<strong>全量替换</strong>当前响应参数树(先清空再导入)。
|
||
</div>
|
||
<div class="analysis-tabs">
|
||
<SlidingTabs v-model="tabs1" size="mini" :items="analysisTypeItems" aria-label="Import format" />
|
||
<div v-show="tabs1 === 'Json'" class="editor-container">
|
||
<CodeMirror
|
||
ref="jsonEditorRef1"
|
||
v-model="textareaJson1"
|
||
language="json"
|
||
theme="vs"
|
||
:options="{
|
||
automaticLayout: true,
|
||
fontSize: 14,
|
||
minimap: { enabled: false },
|
||
scrollBeyondLastLine: false,
|
||
wordWrap: 'on',
|
||
}"
|
||
:height="400"
|
||
/>
|
||
</div>
|
||
<div v-show="tabs1 === 'Xml'" class="editor-container">
|
||
<CodeMirror
|
||
ref="xmlEditorRef1"
|
||
v-model="textareaXml1"
|
||
language="xml"
|
||
theme="vs"
|
||
:options="{
|
||
automaticLayout: true,
|
||
fontSize: 14,
|
||
minimap: { enabled: false },
|
||
scrollBeyondLastLine: false,
|
||
wordWrap: 'on',
|
||
}"
|
||
:height="400"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="analysis-footer">
|
||
<a-button
|
||
size="small"
|
||
:disabled="!responseImportContent || analysisBusy"
|
||
@click="clearResponseImportEditors"
|
||
>
|
||
清空
|
||
</a-button>
|
||
<div class="analysis-footer-actions">
|
||
<a-button :disabled="analysisBusy" @click="cancelClick1">取消</a-button>
|
||
<a-button
|
||
type="primary"
|
||
:loading="analysisBusy"
|
||
:disabled="!responseImportContent"
|
||
@click="handleOneClickImportResponse"
|
||
>
|
||
解析并导入
|
||
</a-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</a-modal>
|
||
|
||
</div>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
.interface-detail {
|
||
width: 100%;
|
||
height: 100%;
|
||
padding: 12px;
|
||
background: var(--app-card-bg);
|
||
box-sizing: border-box;
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
// Input/Select focus:只描外层,避免内层再画一圈导致左右双线
|
||
:deep(.arco-input-wrapper.arco-input-focus),
|
||
:deep(.arco-input-wrapper:focus-within),
|
||
:deep(.arco-select-view-focus) {
|
||
border-color: var(--app-primary-color) !important;
|
||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--app-primary-color) 14%, transparent) !important;
|
||
}
|
||
|
||
:deep(.arco-input-wrapper .arco-input),
|
||
:deep(.arco-input-wrapper .arco-input:focus) {
|
||
border: none !important;
|
||
box-shadow: none !important;
|
||
outline: none !important;
|
||
}
|
||
}
|
||
|
||
.kv-name-cell {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
max-width: 100%;
|
||
}
|
||
|
||
.common-param-tag {
|
||
flex-shrink: 0;
|
||
padding: 0 5px;
|
||
height: 18px;
|
||
line-height: 18px;
|
||
border-radius: 3px;
|
||
font-size: 11px;
|
||
color: var(--color-text-3);
|
||
background: var(--color-fill-2);
|
||
border: 1px solid var(--color-border-2);
|
||
}
|
||
|
||
.common-param-action {
|
||
color: var(--color-text-4);
|
||
font-size: 12px;
|
||
}
|
||
|
||
:deep(.row-common-param) {
|
||
color: var(--color-text-3) !important;
|
||
background: var(--color-fill-1) !important;
|
||
|
||
td {
|
||
color: var(--color-text-3) !important;
|
||
background: var(--color-fill-1) !important;
|
||
}
|
||
}
|
||
|
||
.body-kv-pane {
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
}
|
||
|
||
// 请求方式 + 请求地址 - 符合设计规范
|
||
.api-test-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
margin-bottom: 12px;
|
||
padding: 10px 16px;
|
||
background: var(--app-card-bg);
|
||
border-radius: 4px;
|
||
flex-shrink: 0;
|
||
box-sizing: border-box;
|
||
min-height: 52px;
|
||
position: relative;
|
||
overflow: hidden;
|
||
border: 1px solid color-mix(in srgb, var(--color-border-2) 40%, transparent);
|
||
|
||
:deep(.arco-btn) {
|
||
height: 32px;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
:deep(.arco-input-wrapper),
|
||
:deep(.arco-select-view-single) {
|
||
height: 32px;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
:deep(.arco-input) {
|
||
height: 30px;
|
||
line-height: 30px;
|
||
}
|
||
|
||
:deep(.arco-select-view-value),
|
||
:deep(.arco-select-view-input) {
|
||
line-height: 30px;
|
||
}
|
||
|
||
.method-select,
|
||
.method-badge {
|
||
font-weight: 600;
|
||
letter-spacing: 0.02em;
|
||
flex-shrink: 0;
|
||
}
|
||
.method-badge {
|
||
min-width: 72px;
|
||
height: 32px;
|
||
line-height: 30px;
|
||
padding: 0 14px;
|
||
font-size: 13px;
|
||
border-radius: 4px;
|
||
background: var(--color-fill-2);
|
||
border: 1px solid var(--color-border-2);
|
||
box-sizing: border-box;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
.method-get { color: #059669 !important; }
|
||
.method-post { color: #d97706 !important; }
|
||
.method-delete { color: #dc2626 !important; }
|
||
.method-put, .method-patch, .method-head, .method-options { color: #64748b !important; }
|
||
|
||
.url-input {
|
||
flex: 1;
|
||
min-width: 0;
|
||
height: 32px;
|
||
margin-left: 0;
|
||
margin-right: 0;
|
||
}
|
||
.url-text {
|
||
flex: 1;
|
||
min-width: 0;
|
||
height: 32px;
|
||
margin-left: 0;
|
||
padding: 0 14px;
|
||
background: var(--color-fill-1);
|
||
border-radius: 4px;
|
||
font-size: 13px;
|
||
color: var(--color-text-2);
|
||
font-family: ui-monospace, monospace;
|
||
box-sizing: border-box;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.header-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--app-button-gap, 8px);
|
||
margin-left: auto;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.dirty-badge {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
height: 24px;
|
||
padding: 0 8px;
|
||
border-radius: 4px;
|
||
font-size: 12px;
|
||
line-height: 1;
|
||
color: #b45309;
|
||
background: color-mix(in srgb, #f59e0b 14%, var(--app-card-bg));
|
||
border: 1px solid color-mix(in srgb, #f59e0b 35%, transparent);
|
||
flex-shrink: 0;
|
||
user-select: none;
|
||
}
|
||
|
||
.dirty-dot {
|
||
width: 6px;
|
||
height: 6px;
|
||
border-radius: 50%;
|
||
background: #f59e0b;
|
||
flex-shrink: 0;
|
||
}
|
||
}
|
||
|
||
.detail-grid {
|
||
display: grid;
|
||
gap: 12px;
|
||
flex: 1;
|
||
min-height: 0;
|
||
|
||
&.layout-horizontal {
|
||
grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
|
||
grid-template-rows: auto 1fr;
|
||
}
|
||
|
||
&.layout-vertical {
|
||
grid-template-columns: minmax(0, 1fr);
|
||
/* minmax(0, fr):允许面板被压缩,编辑器在内部滚动,避免撑破后被 overflow:hidden 裁切 */
|
||
grid-template-rows: auto minmax(0, 1.2fr) minmax(0, 1fr);
|
||
overflow: hidden;
|
||
}
|
||
}
|
||
|
||
.section-header-right {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
flex-shrink: 0;
|
||
margin-left: auto;
|
||
}
|
||
|
||
.header-switches {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
gap: 10px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.detail-settings-btn {
|
||
padding: 0 8px !important;
|
||
color: var(--color-text-2);
|
||
|
||
:deep(.arco-icon) {
|
||
font-size: 16px;
|
||
}
|
||
}
|
||
|
||
.section-icon-btn {
|
||
padding: 0 8px !important;
|
||
min-width: 32px;
|
||
|
||
:deep(.arco-icon) {
|
||
font-size: 16px;
|
||
}
|
||
}
|
||
|
||
.layout-switch,
|
||
.tree-expand-switch {
|
||
flex-shrink: 0;
|
||
min-width: 58px !important;
|
||
width: auto;
|
||
height: 28px !important;
|
||
line-height: 28px !important;
|
||
border-radius: 14px !important;
|
||
padding: 0;
|
||
background-color: var(--color-fill-3) !important;
|
||
|
||
&:hover {
|
||
background-color: var(--color-fill-4) !important;
|
||
}
|
||
|
||
:deep(.arco-switch-handle) {
|
||
top: 4px;
|
||
left: 4px;
|
||
width: 20px;
|
||
height: 20px;
|
||
background-color: #fff;
|
||
}
|
||
|
||
:deep(.arco-switch-text-holder) {
|
||
margin: 0 10px 0 30px;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
}
|
||
|
||
:deep(.arco-switch-text) {
|
||
left: 30px;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
color: var(--color-text-2) !important;
|
||
}
|
||
|
||
:deep(&.arco-switch-checked) {
|
||
background-color: var(--color-fill-3) !important;
|
||
}
|
||
|
||
:deep(&.arco-switch-checked .arco-switch-handle) {
|
||
left: calc(100% - 24px);
|
||
}
|
||
|
||
:deep(&.arco-switch-checked .arco-switch-text-holder) {
|
||
margin: 0 30px 0 10px;
|
||
}
|
||
|
||
:deep(&.arco-switch-checked .arco-switch-text) {
|
||
left: 10px;
|
||
color: var(--color-text-2) !important;
|
||
}
|
||
}
|
||
|
||
.drag-handle-icon {
|
||
font-size: 14px;
|
||
color: var(--color-text-4);
|
||
cursor: move;
|
||
opacity: 0.55;
|
||
transition: color 0.15s ease, opacity 0.15s ease;
|
||
|
||
&:hover {
|
||
color: var(--color-text-3);
|
||
opacity: 0.85;
|
||
}
|
||
}
|
||
|
||
.param-name-text {
|
||
&.required {
|
||
font-weight: 500;
|
||
}
|
||
}
|
||
|
||
.required-star {
|
||
color: #f53f3f;
|
||
margin-right: 2px;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.required-checkbox {
|
||
:deep(.arco-checkbox-icon) {
|
||
border-radius: 3px;
|
||
}
|
||
|
||
&.is-on {
|
||
:deep(.arco-checkbox-icon) {
|
||
background-color: var(--app-primary-color) !important;
|
||
border-color: var(--app-primary-color) !important;
|
||
}
|
||
}
|
||
}
|
||
|
||
.section-basic-fullwidth {
|
||
grid-column: 1 / -1;
|
||
background: var(--app-card-bg);
|
||
border-radius: 8px;
|
||
border: 1px solid color-mix(in srgb, var(--color-border-2) 40%, transparent);
|
||
height: auto;
|
||
min-height: 0;
|
||
}
|
||
|
||
.detail-section {
|
||
display: flex;
|
||
flex-direction: column;
|
||
background-color: var(--app-card-bg);
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
min-height: 0;
|
||
border: 1px solid color-mix(in srgb, var(--color-border-2) 40%, transparent);
|
||
}
|
||
|
||
.content-type-bar {
|
||
position: relative;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--app-button-gap, 8px);
|
||
padding: 0 var(--vxe-table-cell-padding-left, 10px) 10px;
|
||
min-height: 28px;
|
||
box-sizing: border-box;
|
||
background: transparent;
|
||
flex-shrink: 0;
|
||
border: none;
|
||
|
||
.content-type-tabs {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.content-type-copy-btn {
|
||
margin-left: auto;
|
||
flex-shrink: 0;
|
||
width: 24px;
|
||
height: 24px;
|
||
padding: 0;
|
||
border-radius: 4px;
|
||
}
|
||
}
|
||
|
||
/* Apifox 式虚拟根节点(仅 Json/Xml 展示,导出剥离) */
|
||
.request-params-table {
|
||
:deep(.body-root-tree-row) {
|
||
background: color-mix(in srgb, var(--app-primary-color) 7%, var(--app-card-bg));
|
||
box-shadow: inset 3px 0 0 var(--app-primary-color);
|
||
}
|
||
|
||
:deep(.body-root-tree-row:hover) {
|
||
background: color-mix(in srgb, var(--app-primary-color) 12%, var(--app-card-bg));
|
||
}
|
||
}
|
||
|
||
.body-root-name {
|
||
display: inline-block;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
color: var(--app-primary-color);
|
||
line-height: 22px;
|
||
}
|
||
|
||
.body-root-desc {
|
||
font-size: 12px;
|
||
color: var(--color-text-3);
|
||
}
|
||
|
||
// 请求方式下拉样式(参考 API 调试页)
|
||
.basic-form-pro {
|
||
:deep(.method-select) {
|
||
.arco-select-view,
|
||
.arco-select-view-single,
|
||
.arco-select-view-value {
|
||
font-weight: 600;
|
||
}
|
||
&.method-get .arco-select-view,
|
||
&.method-get .arco-select-view-single .arco-select-view-value {
|
||
color: #10b981 !important;
|
||
}
|
||
&.method-post .arco-select-view,
|
||
&.method-post .arco-select-view-single .arco-select-view-value {
|
||
color: #f59e0b !important;
|
||
}
|
||
&.method-delete .arco-select-view,
|
||
&.method-delete .arco-select-view-single .arco-select-view-value {
|
||
color: #ef4444 !important;
|
||
}
|
||
&.method-put .arco-select-view,
|
||
&.method-patch .arco-select-view,
|
||
&.method-head .arco-select-view,
|
||
&.method-options .arco-select-view,
|
||
&.method-put .arco-select-view-single .arco-select-view-value,
|
||
&.method-patch .arco-select-view-single .arco-select-view-value,
|
||
&.method-head .arco-select-view-single .arco-select-view-value,
|
||
&.method-options .arco-select-view-single .arco-select-view-value {
|
||
color: #6b7280 !important;
|
||
}
|
||
}
|
||
}
|
||
|
||
.section-header {
|
||
position: relative;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 8px 14px;
|
||
background: var(--app-card-bg);
|
||
border-bottom: 1px solid color-mix(in srgb, var(--color-border-2) 35%, transparent);
|
||
flex-shrink: 0;
|
||
min-height: 40px;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.section-title {
|
||
font-weight: 600;
|
||
font-size: 14px;
|
||
color: var(--color-text-1);
|
||
line-height: 24px;
|
||
letter-spacing: 0.01em;
|
||
}
|
||
|
||
.section-tabs {
|
||
display: flex;
|
||
gap: 8px;
|
||
}
|
||
|
||
.section-actions {
|
||
display: flex;
|
||
gap: var(--app-button-gap, 8px);
|
||
align-items: center;
|
||
min-height: 24px; // 确保空actions区域也有高度,与按钮高度一致
|
||
}
|
||
|
||
.section-content {
|
||
padding: 12px;
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
|
||
&.section-basic-content {
|
||
overflow-y: auto;
|
||
padding: 6px 12px;
|
||
color: var(--color-text-3);
|
||
|
||
:deep(.arco-form-item-label),
|
||
:deep(.arco-input),
|
||
:deep(.arco-input-tag-input),
|
||
:deep(.arco-select-view-value),
|
||
:deep(.arco-textarea),
|
||
:deep(.arco-input-number-input) {
|
||
color: var(--color-text-3) !important;
|
||
font-weight: 400 !important;
|
||
}
|
||
|
||
:deep(.arco-input::placeholder),
|
||
:deep(.arco-textarea::placeholder) {
|
||
color: var(--color-text-4) !important;
|
||
}
|
||
|
||
:deep(.arco-form-item) {
|
||
margin-bottom: 4px !important;
|
||
}
|
||
|
||
:deep(.arco-form-item-label-col) {
|
||
margin-bottom: 2px !important;
|
||
}
|
||
|
||
:deep(.arco-form-item-label) {
|
||
margin-bottom: 2px !important;
|
||
font-size: 12px !important;
|
||
line-height: 1.3 !important;
|
||
}
|
||
|
||
:deep(.arco-input-wrapper),
|
||
:deep(.arco-select-view-single),
|
||
:deep(.arco-input-number),
|
||
:deep(.arco-textarea-wrapper) {
|
||
min-height: 24px;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 基本参数样式
|
||
.basic-form {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 14px;
|
||
}
|
||
|
||
.form-item {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.form-label {
|
||
min-width: 90px;
|
||
font-size: 13px;
|
||
font-weight: 400;
|
||
color: var(--color-text-3);
|
||
}
|
||
|
||
.form-value {
|
||
flex: 1;
|
||
padding: 8px 14px;
|
||
background-color: var(--color-fill-1);
|
||
border-radius: 8px;
|
||
font-size: 13px;
|
||
color: var(--color-text-3);
|
||
min-height: 36px;
|
||
display: flex;
|
||
align-items: center;
|
||
border: 1px solid var(--color-border-2);
|
||
}
|
||
|
||
// 表格样式
|
||
.table-content {
|
||
margin-top: 14px;
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: auto;
|
||
}
|
||
|
||
.query-params-table {
|
||
height: 100%;
|
||
min-height: 0;
|
||
|
||
:deep(.vxe-table) {
|
||
height: 100%;
|
||
}
|
||
|
||
:deep(.vxe-table--body-wrapper) {
|
||
max-height: 100%;
|
||
overflow-y: auto;
|
||
}
|
||
}
|
||
|
||
/* 固定配置 tab 时:section-request 允许内容溢出,section-content 不限制高度,列表自然展开 */
|
||
.section-request.section-request-fixed-tab {
|
||
overflow: visible;
|
||
}
|
||
|
||
.section-content.section-content-fixed-tab {
|
||
overflow: visible;
|
||
min-height: auto;
|
||
flex: none;
|
||
}
|
||
|
||
/* 固定配置:无滚动面板,列表自然展开 */
|
||
.query-fixed-content.table-content {
|
||
overflow: visible;
|
||
flex: none;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.query-fixed-spin {
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.query-fixed-spin :deep(.arco-spin) {
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.query-fixed-spin :deep(.arco-spin-children) {
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.query-fixed-params-table {
|
||
:deep(.vxe-table) {
|
||
height: auto !important;
|
||
}
|
||
|
||
:deep(.vxe-table--body-wrapper) {
|
||
overflow: visible !important;
|
||
}
|
||
|
||
/* 防止弹窗内行被压缩挤在一起 */
|
||
:deep(.vxe-body--row) {
|
||
min-height: 36px;
|
||
}
|
||
|
||
:deep(.vxe-body--row > td) {
|
||
padding: 8px 12px;
|
||
}
|
||
}
|
||
|
||
.request-params-table {
|
||
height: 100%;
|
||
min-height: 0;
|
||
|
||
:deep(.vxe-table) {
|
||
height: 100%;
|
||
}
|
||
|
||
:deep(.vxe-table--body-wrapper) {
|
||
max-height: 100%;
|
||
overflow-y: auto;
|
||
}
|
||
}
|
||
|
||
.response-params-table {
|
||
height: 100%;
|
||
min-height: 0;
|
||
|
||
:deep(.vxe-table) {
|
||
height: 100%;
|
||
}
|
||
|
||
:deep(.vxe-table--body-wrapper) {
|
||
max-height: 100%;
|
||
overflow-y: auto;
|
||
}
|
||
}
|
||
|
||
.params-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
font-size: 13px;
|
||
|
||
thead {
|
||
background-color: var(--color-fill-1);
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 10;
|
||
}
|
||
|
||
th {
|
||
padding: 10px 12px;
|
||
text-align: left;
|
||
font-weight: 600;
|
||
color: var(--color-text-1);
|
||
white-space: nowrap;
|
||
background-color: var(--color-fill-1);
|
||
}
|
||
|
||
td {
|
||
padding: 10px 12px;
|
||
color: var(--color-text-2);
|
||
word-break: break-word;
|
||
}
|
||
|
||
.empty-cell {
|
||
text-align: center;
|
||
color: var(--color-text-3);
|
||
padding: 40px 0;
|
||
}
|
||
}
|
||
|
||
.empty-placeholder {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 14px;
|
||
opacity: 0.7;
|
||
}
|
||
|
||
// FormPro样式优化
|
||
.basic-form-pro {
|
||
:deep(.arco-form-item) {
|
||
margin-bottom: 4px;
|
||
margin-right: 0 !important;
|
||
}
|
||
|
||
:deep(.arco-form-inline) {
|
||
column-gap: 12px;
|
||
row-gap: 4px;
|
||
}
|
||
|
||
:deep(.arco-form-item-label-col) {
|
||
display: block !important;
|
||
width: 100% !important;
|
||
margin-bottom: 2px !important;
|
||
|
||
.arco-form-item-label-required,
|
||
.arco-form-item-label-asterisk,
|
||
.arco-form-item-label-required-symbol {
|
||
display: none !important;
|
||
}
|
||
.arco-form-item-label {
|
||
padding-left: 0 !important;
|
||
display: block !important;
|
||
margin-bottom: 2px !important;
|
||
font-weight: 400 !important;
|
||
color: var(--color-text-3) !important;
|
||
font-size: 12px !important;
|
||
line-height: 1.3 !important;
|
||
}
|
||
}
|
||
|
||
// 确保 vertical 布局下 label 显示
|
||
:deep(.arco-form-layout-vertical) {
|
||
.arco-form-item-label-col {
|
||
display: block !important;
|
||
width: 100% !important;
|
||
margin-bottom: 2px !important;
|
||
}
|
||
.arco-form-item-label {
|
||
display: block !important;
|
||
margin-bottom: 2px !important;
|
||
font-weight: 400 !important;
|
||
color: var(--color-text-3) !important;
|
||
font-size: 12px !important;
|
||
line-height: 1.3 !important;
|
||
}
|
||
}
|
||
|
||
// 通用样式,确保所有布局下 label 都显示
|
||
:deep(.arco-form-item) {
|
||
.arco-form-item-label-col {
|
||
display: block !important;
|
||
}
|
||
.arco-form-item-label {
|
||
display: block !important;
|
||
}
|
||
}
|
||
}
|
||
|
||
.request-header-tabs,
|
||
.response-header-tabs {
|
||
flex: 0 1 auto;
|
||
width: fit-content;
|
||
max-width: 100%;
|
||
}
|
||
|
||
.request-example-content {
|
||
display: flex;
|
||
flex-direction: column;
|
||
flex: 1;
|
||
height: 100%;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.request-example-container {
|
||
flex: 1;
|
||
min-height: 0;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
border: 1px solid var(--color-border-2);
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
:deep(.codemirror-container) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
height: 100%;
|
||
}
|
||
}
|
||
|
||
.response-example-content {
|
||
display: flex;
|
||
flex-direction: column;
|
||
flex: 1;
|
||
height: 100%;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.response-example-container {
|
||
flex: 1;
|
||
min-height: 0;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
border: 1px solid var(--color-border-2);
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
:deep(.codemirror-container) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
height: 100%;
|
||
}
|
||
}
|
||
|
||
.response-return-config-content {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
margin-top: 12px;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
:deep(.return-config-tab-content) {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
|
||
.table-container {
|
||
flex: 1;
|
||
min-height: 0;
|
||
}
|
||
}
|
||
|
||
.analysis-modal {
|
||
:deep(.arco-modal-body) {
|
||
padding: 16px;
|
||
}
|
||
|
||
.analysis-content {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12px;
|
||
}
|
||
|
||
.analysis-tip {
|
||
margin: 0;
|
||
padding: 10px 12px;
|
||
font-size: 12px;
|
||
line-height: 1.6;
|
||
color: var(--color-text-2);
|
||
background: var(--color-fill-1);
|
||
border: 1px solid var(--color-border-2);
|
||
border-radius: 4px;
|
||
|
||
code {
|
||
padding: 0 4px;
|
||
font-size: 11px;
|
||
border-radius: 2px;
|
||
background: var(--color-fill-2);
|
||
color: var(--app-primary-color);
|
||
}
|
||
}
|
||
|
||
.analysis-tabs {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12px;
|
||
}
|
||
|
||
.editor-container {
|
||
height: 400px;
|
||
border-radius: 4px;
|
||
overflow: hidden;
|
||
margin-top: 0;
|
||
border: 1px solid var(--color-border-2);
|
||
}
|
||
|
||
.analysis-footer {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
margin-top: 4px;
|
||
padding-top: 12px;
|
||
border-top: 1px solid var(--color-border-2);
|
||
}
|
||
|
||
.analysis-footer-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--app-button-gap, 8px);
|
||
margin-left: auto;
|
||
}
|
||
|
||
:deep(.arco-btn) {
|
||
height: 32px;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
:deep(.arco-btn-size-small) {
|
||
height: 28px;
|
||
}
|
||
|
||
:deep(.arco-btn-primary) {
|
||
background-color: var(--app-primary-color);
|
||
border-color: var(--app-primary-color);
|
||
}
|
||
|
||
:deep(.arco-btn-outline) {
|
||
color: var(--app-primary-color);
|
||
border-color: var(--app-primary-color);
|
||
|
||
&:hover {
|
||
color: var(--app-primary-color);
|
||
border-color: var(--app-primary-color);
|
||
background-color: color-mix(in srgb, var(--app-primary-color) 8%, transparent);
|
||
}
|
||
}
|
||
}
|
||
|
||
.query-tab-pane {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
min-height: 0;
|
||
}
|
||
|
||
.mapping-body-tip {
|
||
flex-shrink: 0;
|
||
margin: 0 0 12px;
|
||
padding: 10px 14px;
|
||
font-size: 12px;
|
||
line-height: 1.6;
|
||
color: var(--color-text-2);
|
||
border-radius: 4px;
|
||
background: var(--color-fill-1);
|
||
border: 1px solid var(--color-border-2);
|
||
|
||
code {
|
||
padding: 0 4px;
|
||
font-size: 11px;
|
||
border-radius: 2px;
|
||
background: var(--color-fill-2);
|
||
color: var(--app-primary-color, rgb(var(--primary-6)));
|
||
}
|
||
}
|
||
|
||
.query-usage-tip {
|
||
flex-shrink: 0;
|
||
margin-top: 12px;
|
||
padding: 12px 14px;
|
||
border-radius: 4px;
|
||
background: var(--color-fill-1);
|
||
border: 1px solid var(--color-border-2);
|
||
}
|
||
|
||
.query-usage-tip-title {
|
||
margin-bottom: 8px;
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
color: var(--color-text-1);
|
||
}
|
||
|
||
.query-usage-tip-list {
|
||
margin: 0;
|
||
padding-left: 18px;
|
||
font-size: 12px;
|
||
line-height: 1.75;
|
||
color: var(--color-text-2);
|
||
|
||
li + li {
|
||
margin-top: 4px;
|
||
}
|
||
|
||
code {
|
||
padding: 0 4px;
|
||
font-size: 11px;
|
||
border-radius: 2px;
|
||
background: var(--color-fill-2);
|
||
color: var(--app-primary-color, rgb(var(--primary-6)));
|
||
}
|
||
}
|
||
|
||
.body-none-pane {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
min-height: 120px;
|
||
}
|
||
|
||
.body-none-tip {
|
||
font-size: 13px;
|
||
color: var(--color-text-3);
|
||
}
|
||
|
||
.params-empty-tip {
|
||
margin: 0 0 8px;
|
||
padding: 8px 12px;
|
||
font-size: 12px;
|
||
line-height: 1.5;
|
||
color: var(--color-text-3);
|
||
background: var(--color-fill-1);
|
||
border: 1px dashed var(--color-border-2);
|
||
border-radius: 4px;
|
||
}
|
||
|
||
// 列表:表头白底 + 边框弱化(仅本页)
|
||
:deep(.vxe-table) {
|
||
--vxe-table-border-color: color-mix(in srgb, var(--color-border-2) 42%, transparent);
|
||
border-color: color-mix(in srgb, var(--color-border-2) 42%, transparent) !important;
|
||
}
|
||
|
||
:deep(.vxe-table--header-wrapper),
|
||
:deep(.vxe-table--header),
|
||
:deep(.vxe-header--row),
|
||
:deep(.vxe-header--column) {
|
||
background-color: var(--app-card-bg) !important;
|
||
}
|
||
|
||
:deep(.vxe-header--column),
|
||
:deep(.vxe-body--column),
|
||
:deep(.vxe-table--border-line) {
|
||
border-color: color-mix(in srgb, var(--color-border-2) 42%, transparent) !important;
|
||
}
|
||
|
||
:deep(.vxe-table--header-border-line) {
|
||
border-color: color-mix(in srgb, var(--color-border-2) 42%, transparent) !important;
|
||
}
|
||
|
||
// 隐藏vxe-table的编辑和必填图标
|
||
:deep(.vxe-cell--required-icon),
|
||
:deep(.vxe-cell--edit-icon),
|
||
:deep(.vxe-icon-edit) {
|
||
display: none !important;
|
||
}
|
||
|
||
// 隐藏vxe-table的排序符号
|
||
:deep(.vxe-cell--sort),
|
||
:deep(.vxe-cell--sort-vertical-layout) {
|
||
display: none !important;
|
||
}
|
||
|
||
// 表头字段名居中显示
|
||
:deep(.vxe-header--column .vxe-cell) {
|
||
text-align: center !important;
|
||
justify-content: center !important;
|
||
}
|
||
|
||
:deep(.row-action-btn) {
|
||
color: var(--color-text-3) !important;
|
||
width: 24px !important;
|
||
height: 24px !important;
|
||
min-width: 24px !important;
|
||
padding: 0 !important;
|
||
line-height: 24px !important;
|
||
|
||
:deep(.arco-icon),
|
||
.arco-icon {
|
||
font-size: 14px;
|
||
}
|
||
|
||
&:hover,
|
||
&:focus {
|
||
color: var(--color-text-1) !important;
|
||
background-color: var(--color-fill-2) !important;
|
||
}
|
||
}
|
||
|
||
/* 操作列:避免按钮偏大撑出单元格滚动条(右下角黑点) */
|
||
:deep(.vxe-body--column.col--last .vxe-cell),
|
||
:deep(.vxe-header--column.col--last .vxe-cell) {
|
||
overflow: hidden !important;
|
||
scrollbar-width: none;
|
||
}
|
||
|
||
:deep(.vxe-body--column.col--last .vxe-cell::-webkit-scrollbar),
|
||
:deep(.vxe-header--column.col--last .vxe-cell::-webkit-scrollbar) {
|
||
width: 0 !important;
|
||
height: 0 !important;
|
||
display: none !important;
|
||
}
|
||
|
||
:deep(.vxe-body--column.col--dirty:before) {
|
||
display: none !important;
|
||
}
|
||
|
||
:deep(.row-clear-btn) {
|
||
padding: 0 4px !important;
|
||
color: var(--color-text-3) !important;
|
||
|
||
&:hover:not(:disabled),
|
||
&:focus:not(:disabled) {
|
||
color: #cf1322 !important;
|
||
background-color: color-mix(in srgb, #cf1322 8%, transparent) !important;
|
||
}
|
||
|
||
&:disabled {
|
||
color: var(--color-text-4) !important;
|
||
}
|
||
}
|
||
|
||
.btn-app-outline {
|
||
color: var(--app-primary-color) !important;
|
||
border-color: var(--app-primary-color) !important;
|
||
background-color: transparent !important;
|
||
|
||
&:hover,
|
||
&:focus {
|
||
color: var(--app-primary-color) !important;
|
||
border-color: var(--app-primary-color) !important;
|
||
background-color: color-mix(in srgb, var(--app-primary-color) 8%, transparent) !important;
|
||
}
|
||
|
||
&:disabled,
|
||
&[disabled] {
|
||
color: var(--color-text-4) !important;
|
||
border-color: var(--color-border-2) !important;
|
||
background-color: transparent !important;
|
||
}
|
||
}
|
||
|
||
</style>
|
||
|
||
<style lang="less">
|
||
/* 导入弹窗挂到 body,需非 scoped 才能覆盖按钮主色 */
|
||
.analysis-modal {
|
||
.arco-btn-primary {
|
||
background-color: var(--app-primary-color);
|
||
border-color: var(--app-primary-color);
|
||
|
||
&:hover,
|
||
&:focus {
|
||
background-color: var(--app-primary-color);
|
||
border-color: var(--app-primary-color);
|
||
opacity: 0.9;
|
||
}
|
||
}
|
||
|
||
.arco-btn-outline,
|
||
.btn-app-outline {
|
||
color: var(--app-primary-color) !important;
|
||
border-color: var(--app-primary-color) !important;
|
||
|
||
&:hover,
|
||
&:focus {
|
||
color: var(--app-primary-color) !important;
|
||
border-color: var(--app-primary-color) !important;
|
||
background-color: color-mix(in srgb, var(--app-primary-color) 8%, transparent) !important;
|
||
}
|
||
}
|
||
|
||
.arco-tabs-tab-active {
|
||
color: var(--app-primary-color);
|
||
}
|
||
|
||
.arco-tabs-nav-ink {
|
||
background-color: var(--app-primary-color);
|
||
}
|
||
}
|
||
</style>
|
||
|
||
<style lang="less" scoped>
|
||
.param-type-text {
|
||
display: inline-block;
|
||
min-width: 48px;
|
||
font-size: 13px;
|
||
line-height: 22px;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
|
||
&:hover:not(.disabled) {
|
||
text-decoration: underline;
|
||
text-underline-offset: 2px;
|
||
}
|
||
|
||
&.placeholder {
|
||
color: var(--color-text-3);
|
||
}
|
||
|
||
&.disabled {
|
||
cursor: not-allowed;
|
||
opacity: 0.55;
|
||
text-decoration: none;
|
||
}
|
||
}
|
||
</style>
|
||
|
||
<style lang="less">
|
||
/* popover 内容挂到 body,需非 scoped */
|
||
.param-type-popover {
|
||
padding: 6px !important;
|
||
|
||
.param-type-picker {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 2px;
|
||
min-width: 120px;
|
||
max-height: 280px;
|
||
overflow: auto;
|
||
}
|
||
|
||
.param-type-picker-item {
|
||
padding: 6px 10px;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
transition: background 0.15s;
|
||
font-size: 13px;
|
||
line-height: 20px;
|
||
white-space: nowrap;
|
||
|
||
&:hover,
|
||
&.active {
|
||
background: var(--color-fill-2);
|
||
}
|
||
|
||
&.active {
|
||
background: color-mix(in srgb, var(--app-primary-color) 8%, transparent);
|
||
}
|
||
}
|
||
}
|
||
|
||
.detail-settings-popover {
|
||
padding: 10px 12px !important;
|
||
|
||
.detail-settings-panel {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12px;
|
||
min-width: 220px;
|
||
}
|
||
|
||
.detail-settings-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 16px;
|
||
}
|
||
|
||
.detail-settings-label {
|
||
font-size: 13px;
|
||
color: var(--color-text-2);
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.layout-switch,
|
||
.tree-expand-switch {
|
||
flex-shrink: 0;
|
||
min-width: 58px !important;
|
||
width: auto;
|
||
height: 28px !important;
|
||
line-height: 28px !important;
|
||
border-radius: 14px !important;
|
||
padding: 0;
|
||
background-color: var(--color-fill-3) !important;
|
||
|
||
&:hover {
|
||
background-color: var(--color-fill-4) !important;
|
||
}
|
||
|
||
.arco-switch-handle {
|
||
top: 4px;
|
||
left: 4px;
|
||
width: 20px;
|
||
height: 20px;
|
||
background-color: #fff;
|
||
}
|
||
|
||
.arco-switch-text-holder {
|
||
margin: 0 10px 0 30px;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
}
|
||
|
||
.arco-switch-text {
|
||
left: 30px;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
color: var(--color-text-2) !important;
|
||
}
|
||
|
||
&.arco-switch-checked {
|
||
background-color: var(--color-fill-3) !important;
|
||
}
|
||
|
||
&.arco-switch-checked .arco-switch-handle {
|
||
left: calc(100% - 24px);
|
||
}
|
||
|
||
&.arco-switch-checked .arco-switch-text-holder {
|
||
margin: 0 30px 0 10px;
|
||
}
|
||
|
||
&.arco-switch-checked .arco-switch-text {
|
||
left: 10px;
|
||
color: var(--color-text-2) !important;
|
||
}
|
||
}
|
||
}
|
||
</style>
|