Merge branch 'hugo-shipping-notice' into dev
# Conflicts: # backend/app/api/__init__.py # backend/app/jobs/types.py # backend/app/models/__init__.py # backend/app/services/schedule/job_registry.py # docs/features/README.md # docs/funclist.md # docs/tec.md # frontend/src/locales/zh-CN/admin.json
This commit is contained in:
commit
dac31e48bd
691 files changed
+53341
-14863
No files matched your search
+275
@@ -0,0 +1,275 @@
|
||||
<!--
|
||||
features/admin/modules/integration-connector/IntegrationConnectorPage.vue
|
||||
用途:集成连接器管理页——四个配置实体(客户端实例/接口定义/绑定/凭据引用)tab 列表 +
|
||||
能力清单与手动调用测试;创建/编辑弹窗 + 连接测试。
|
||||
依赖:useIntegrationConnectorAdmin、两个弹窗组件、useI18n。
|
||||
逻辑:按 tab 展示列表与「新增」;配置「绑定」是让自动调拨跑起来的最小闭环核心。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Plus, Edit, Trash2, Plug, PlayCircle } from 'lucide-vue-next';
|
||||
import IntegrationConnectorFormModal from './components/IntegrationConnectorFormModal.vue';
|
||||
import IntegrationCapabilityCallModal from './components/IntegrationCapabilityCallModal.vue';
|
||||
import { useIntegrationConnectorAdmin } from './composables/useIntegrationConnectorAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
clients, interfaces, bindings, credentials, capabilities,
|
||||
isLoading, activeEntity, showFormModal, isSaving,
|
||||
clientForm, interfaceForm, bindingForm, credentialForm,
|
||||
showCallModal, callCapability, callParamsText, callContextText, callResult, callBusy,
|
||||
testResultText,
|
||||
loadAll, openCreateModal, openEditModal, closeFormModal, saveActive,
|
||||
testConnection, openCallModal, closeCallModal, runCall, deleteClient,
|
||||
} = useIntegrationConnectorAdmin();
|
||||
|
||||
onMounted(() => { void loadAll(); });
|
||||
|
||||
type TabKey = 'client' | 'interface' | 'binding' | 'credential' | 'capability';
|
||||
const tabs: Array<{ key: TabKey; labelKey: string }> = [
|
||||
{ key: 'client', labelKey: 'admin.integrationConnector.tabs.client' },
|
||||
{ key: 'interface', labelKey: 'admin.integrationConnector.tabs.interface' },
|
||||
{ key: 'binding', labelKey: 'admin.integrationConnector.tabs.binding' },
|
||||
{ key: 'credential', labelKey: 'admin.integrationConnector.tabs.credential' },
|
||||
{ key: 'capability', labelKey: 'admin.integrationConnector.tabs.capability' },
|
||||
];
|
||||
const activeTab = computed<TabKey>(() => (activeEntity.value === 'credential' ? 'credential' : activeEntity.value));
|
||||
|
||||
const clientOptions = computed(() => clients.value.map((c) => ({ code: c.code, name: c.name })));
|
||||
const interfaceOptions = computed(() => interfaces.value.map((i) => ({ code: i.code, name: i.name })));
|
||||
const capabilityOptions = computed(() => capabilities.value.map((c) => ({ name: c.name })));
|
||||
|
||||
function selectTab(key: TabKey) {
|
||||
// capability tab 只读展示,不进入表单实体;其余映射到可编辑实体。
|
||||
if (key === 'capability') return;
|
||||
activeEntity.value = key;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section animate-fade-in-up">
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.integrationConnector.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.integrationConnector.subtitle') }}</p>
|
||||
</div>
|
||||
<button
|
||||
v-if="activeTab !== 'capability'"
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-brand-600 text-white rounded-xl hover:bg-brand-700 transition-all shadow-lg shadow-brand-200 active:scale-95 text-sm font-medium"
|
||||
@click="openCreateModal(activeEntity)"
|
||||
>
|
||||
<Plus class="w-4 h-4" />
|
||||
<span>{{ t('admin.integrationConnector.add') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-1 border-b border-default" role="tablist">
|
||||
<button
|
||||
v-for="tab in tabs"
|
||||
:key="tab.key"
|
||||
type="button"
|
||||
role="tab"
|
||||
class="px-4 py-2.5 text-sm font-medium border-b-2 -mb-px transition-colors"
|
||||
:class="activeTab === tab.key ? 'border-brand-600 text-brand-600' : 'border-transparent text-muted hover:text-secondary'"
|
||||
:aria-selected="activeTab === tab.key"
|
||||
@click="selectTab(tab.key)"
|
||||
>
|
||||
{{ t(tab.labelKey) }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<!-- 客户端实例 -->
|
||||
<div v-if="activeTab === 'client'" class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.code') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.name') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.connectorType') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.environment') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs w-40">{{ t('admin.integrationConnector.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="clients.length === 0"><td colspan="5" class="px-6 admin-table-empty">{{ t('admin.integrationConnector.empty') }}</td></tr>
|
||||
<tr v-for="row in clients" :key="row.code">
|
||||
<td class="px-6 py-4 text-sm font-medium text-primary mono">{{ row.code }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.name }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.connector_type }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.environment }}</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<div class="inline-flex items-center gap-1">
|
||||
<button type="button" class="p-2 rounded-lg text-muted hover:bg-brand-50 hover:text-brand-600" :title="t('admin.integrationConnector.test')" @click="testConnection(row.code)">
|
||||
<Plug class="w-4 h-4" />
|
||||
</button>
|
||||
<button type="button" class="p-2 rounded-lg text-muted hover:bg-surface-soft hover:text-secondary" :title="t('admin.edit')" @click="openEditModal('client', row)">
|
||||
<Edit class="w-4 h-4" />
|
||||
</button>
|
||||
<button type="button" class="p-2 rounded-lg text-muted hover:bg-red-50 hover:text-red-600" :title="t('admin.delete')" @click="deleteClient(row.code)">
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-if="testResultText" class="mt-3 rounded-lg bg-surface-soft p-3 text-xs font-mono text-secondary whitespace-pre-wrap break-all">{{ testResultText }}</p>
|
||||
</div>
|
||||
|
||||
<!-- 接口定义 -->
|
||||
<div v-else-if="activeTab === 'interface'" class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.code') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.name') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.clientInstance') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.status') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs w-24">{{ t('admin.integrationConnector.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="interfaces.length === 0"><td colspan="5" class="px-6 admin-table-empty">{{ t('admin.integrationConnector.empty') }}</td></tr>
|
||||
<tr v-for="row in interfaces" :key="row.code">
|
||||
<td class="px-6 py-4 text-sm font-medium text-primary mono">{{ row.code }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.name }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.client_instance_code }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.status }}</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<div class="inline-flex items-center gap-1">
|
||||
<button type="button" class="p-2 rounded-lg text-muted hover:bg-surface-soft hover:text-secondary" :title="t('admin.edit')" @click="openEditModal('interface', row)">
|
||||
<Edit class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 绑定 -->
|
||||
<div v-else-if="activeTab === 'binding'" class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.capability') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.clientInstance') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.interfaceDef') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.status') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs w-24">{{ t('admin.integrationConnector.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="bindings.length === 0"><td colspan="5" class="px-6 admin-table-empty">{{ t('admin.integrationConnector.empty') }}</td></tr>
|
||||
<tr v-for="row in bindings" :key="row.id">
|
||||
<td class="px-6 py-4 text-sm font-medium text-primary">{{ row.capability }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.client_instance_code }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.interface_definition_code }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.status }}</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<div class="inline-flex items-center gap-1">
|
||||
<button type="button" class="p-2 rounded-lg text-muted hover:bg-surface-soft hover:text-secondary" :title="t('admin.edit')" @click="openEditModal('binding', row)">
|
||||
<Edit class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 凭据引用 -->
|
||||
<div v-else-if="activeTab === 'credential'" class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.code') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.secretRef') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.secretProvider') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.status') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs w-24">{{ t('admin.integrationConnector.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="credentials.length === 0"><td colspan="5" class="px-6 admin-table-empty">{{ t('admin.integrationConnector.empty') }}</td></tr>
|
||||
<tr v-for="row in credentials" :key="row.code">
|
||||
<td class="px-6 py-4 text-sm font-medium text-primary mono">{{ row.code }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary mono">{{ row.secret_ref }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.secret_provider }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.status }}</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<div class="inline-flex items-center gap-1">
|
||||
<button type="button" class="p-2 rounded-lg text-muted hover:bg-surface-soft hover:text-secondary" :title="t('admin.edit')" @click="openEditModal('credential', row)">
|
||||
<Edit class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 能力清单 -->
|
||||
<div v-else class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.name') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.write') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.integrationConnector.headers.idempotency') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs w-28">{{ t('admin.integrationConnector.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="capabilities.length === 0"><td colspan="4" class="px-6 admin-table-empty">{{ t('admin.integrationConnector.empty') }}</td></tr>
|
||||
<tr v-for="row in capabilities" :key="row.name">
|
||||
<td class="px-6 py-4 text-sm font-medium text-primary">{{ row.name }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.write ? 'yes' : 'no' }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.idempotency }}</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<button type="button" class="inline-flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium text-brand-600 hover:bg-brand-50" @click="openCallModal(row.name)">
|
||||
<PlayCircle class="w-4 h-4" />
|
||||
{{ t('admin.integrationConnector.call') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<IntegrationConnectorFormModal
|
||||
:visible="showFormModal"
|
||||
:active-entity="activeEntity"
|
||||
:client-form="clientForm"
|
||||
:interface-form="interfaceForm"
|
||||
:binding-form="bindingForm"
|
||||
:credential-form="credentialForm"
|
||||
:is-saving="isSaving"
|
||||
:client-options="clientOptions"
|
||||
:interface-options="interfaceOptions"
|
||||
:capability-options="capabilityOptions"
|
||||
@close="closeFormModal"
|
||||
@save="saveActive"
|
||||
/>
|
||||
|
||||
<IntegrationCapabilityCallModal
|
||||
:visible="showCallModal"
|
||||
:capability="callCapability"
|
||||
:params-text="callParamsText"
|
||||
:context-text="callContextText"
|
||||
:result="callResult"
|
||||
:busy="callBusy"
|
||||
@close="closeCallModal"
|
||||
@run="runCall"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* features/admin/modules/integration-connector/api/integration-connector.api.ts
|
||||
* 集成连接器管理 API 客户端:客户端实例/接口定义/绑定/凭据引用 CRUD + 能力清单 + 连接测试。
|
||||
* 依赖:@/shared/api/client(requestJson / BusinessError)、@/shared/utils/auth。
|
||||
* 逻辑:薄封装后端 /api/integration-connector/* 全部端点;JSON 写请求带 Content-Type。
|
||||
* 错误码(INTEGRATION.*)由 requestJson 解析到四语言文案。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type {
|
||||
IntegrationBindingRow,
|
||||
IntegrationCallResultRow,
|
||||
IntegrationCapabilityRow,
|
||||
IntegrationClientInstanceRow,
|
||||
IntegrationCredentialReferenceRow,
|
||||
IntegrationInterfaceDefinitionRow,
|
||||
} from '../types/integration-connector.types';
|
||||
|
||||
const BASE = '/api/integration-connector';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
||||
|
||||
// ---- 能力清单与调用 ----
|
||||
|
||||
/** 能力清单(写/幂等/入出参 Schema)。 */
|
||||
export const listIntegrationCapabilities = () =>
|
||||
requestJson<IntegrationCapabilityRow[]>(`${BASE}/capabilities`, auth());
|
||||
|
||||
/** 手动调用一个已注册能力(入参 + 路由上下文)。 */
|
||||
export const callIntegrationCapability = (capability: string, payload: { params?: Record<string, unknown>; context?: Record<string, unknown>; operation_id?: string; idempotency_key?: string }) =>
|
||||
requestJson<IntegrationCallResultRow>(`${BASE}/capabilities/${encodeURIComponent(capability)}`, {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
// ---- 客户端实例 ----
|
||||
|
||||
export const listIntegrationClientInstances = () =>
|
||||
requestJson<IntegrationClientInstanceRow[]>(`${BASE}/client-instances`, auth());
|
||||
|
||||
export const createIntegrationClientInstance = (payload: Record<string, unknown>) =>
|
||||
requestJson<IntegrationClientInstanceRow>(`${BASE}/client-instances`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const updateIntegrationClientInstance = (code: string, payload: Record<string, unknown>) =>
|
||||
requestJson<IntegrationClientInstanceRow>(`${BASE}/client-instances/${encodeURIComponent(code)}`, {
|
||||
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const deleteIntegrationClientInstance = (code: string) =>
|
||||
requestJson(`${BASE}/client-instances/${encodeURIComponent(code)}`, { method: 'DELETE', ...auth() });
|
||||
|
||||
/** 连接测试(返回底层传输 raw 结果)。 */
|
||||
export const testIntegrationClientConnection = (code: string) =>
|
||||
requestJson<Record<string, unknown>>(`${BASE}/client-instances/${encodeURIComponent(code)}/test`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify({}),
|
||||
});
|
||||
|
||||
// ---- 接口定义 ----
|
||||
|
||||
export const listIntegrationInterfaceDefinitions = () =>
|
||||
requestJson<IntegrationInterfaceDefinitionRow[]>(`${BASE}/interface-definitions`, auth());
|
||||
|
||||
export const createIntegrationInterfaceDefinition = (payload: Record<string, unknown>) =>
|
||||
requestJson<IntegrationInterfaceDefinitionRow>(`${BASE}/interface-definitions`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const updateIntegrationInterfaceDefinition = (code: string, payload: Record<string, unknown>) =>
|
||||
requestJson<IntegrationInterfaceDefinitionRow>(`${BASE}/interface-definitions/${encodeURIComponent(code)}`, {
|
||||
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
// ---- 绑定 ----
|
||||
|
||||
export const listIntegrationBindings = () =>
|
||||
requestJson<IntegrationBindingRow[]>(`${BASE}/bindings`, auth());
|
||||
|
||||
export const createIntegrationBinding = (payload: Record<string, unknown>) =>
|
||||
requestJson<IntegrationBindingRow>(`${BASE}/bindings`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const updateIntegrationBinding = (id: number, payload: Record<string, unknown>) =>
|
||||
requestJson<IntegrationBindingRow>(`${BASE}/bindings/${id}`, {
|
||||
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
// ---- 凭据引用 ----
|
||||
|
||||
export const listIntegrationCredentialReferences = () =>
|
||||
requestJson<IntegrationCredentialReferenceRow[]>(`${BASE}/credential-references`, auth());
|
||||
|
||||
export const createIntegrationCredentialReference = (payload: Record<string, unknown>) =>
|
||||
requestJson<IntegrationCredentialReferenceRow>(`${BASE}/credential-references`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const updateIntegrationCredentialReference = (code: string, payload: Record<string, unknown>) =>
|
||||
requestJson<IntegrationCredentialReferenceRow>(`${BASE}/credential-references/${encodeURIComponent(code)}`, {
|
||||
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<!--
|
||||
features/admin/modules/integration-connector/components/IntegrationCapabilityCallModal.vue
|
||||
用途:手动调用一个已注册能力(输入 params / context JSON),展示调用结果与 trace。
|
||||
依赖:showCallModal、callParamsText、callContextText、callResult、callBusy。
|
||||
逻辑:由 IntegrationConnectorPage 打开;emit close/run。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { IntegrationCallResultRow } from '../types/integration-connector.types';
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
capability: string;
|
||||
paramsText: string;
|
||||
contextText: string;
|
||||
result: IntegrationCallResultRow | null;
|
||||
busy: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
run: [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay animate-fade-in items-center">
|
||||
<div class="admin-modal-panel max-w-2xl max-h-[92vh] scale-100">
|
||||
<div class="px-5 sm:px-8 pt-5 sm:pt-7 pb-4 border-b border-subtle">
|
||||
<h3 class="section-title">{{ t('admin.integrationConnector.callModal.title', { capability }) }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('admin.integrationConnector.callModal.hint') }}</p>
|
||||
</div>
|
||||
<div class="px-5 sm:px-8 py-5 space-y-4 overflow-y-auto">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.callModal.params') }}</label>
|
||||
<textarea :value="props.paramsText" rows="6" class="input-field text-sm font-mono" spellcheck="false" readonly />
|
||||
<p class="text-xs text-muted">{{ t('admin.integrationConnector.callModal.paramsHint') }}</p>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.callModal.context') }}</label>
|
||||
<textarea :value="props.contextText" rows="4" class="input-field text-sm font-mono" spellcheck="false" readonly />
|
||||
<p class="text-xs text-muted">{{ t('admin.integrationConnector.callModal.contextHint') }}</p>
|
||||
</div>
|
||||
<div v-if="result" class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.callModal.result') }}</label>
|
||||
<pre class="rounded-lg bg-surface-soft p-3 text-xs font-mono text-secondary whitespace-pre-wrap break-all">{{ JSON.stringify(result, null, 2) }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.cancel') }}</button>
|
||||
<button type="button" class="btn-primary disabled:opacity-70" :disabled="busy" @click="emit('run')">
|
||||
{{ busy ? t('admin.integrationConnector.callModal.running') : t('admin.integrationConnector.callModal.run') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* features/admin/modules/integration-connector/components/IntegrationConnectorFormModal.spec.ts
|
||||
* 用途:锁定表单按连接器类型动态显示字段——REST 显示超时/HTTP方法/请求路径,
|
||||
* SOAP 显示 WSDL;关键字段从 JSON 拆出独立输入框,JSON 收进高级配置折叠。
|
||||
* 依赖:@vue/test-utils、i18n。
|
||||
* 逻辑:切换 connector_type 后断言对应字段的可见性;高级配置折叠默认收起。
|
||||
*/
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import i18n from '@/i18n';
|
||||
import IntegrationConnectorFormModal from './IntegrationConnectorFormModal.vue';
|
||||
import {
|
||||
createEmptyClientInstanceForm,
|
||||
createEmptyInterfaceDefinitionForm,
|
||||
createEmptyBindingForm,
|
||||
createEmptyCredentialReferenceForm,
|
||||
} from '../types/integration-connector.types';
|
||||
|
||||
function mountModal() {
|
||||
return mount(IntegrationConnectorFormModal, {
|
||||
props: {
|
||||
visible: true,
|
||||
activeEntity: 'client',
|
||||
clientForm: createEmptyClientInstanceForm(),
|
||||
interfaceForm: createEmptyInterfaceDefinitionForm(),
|
||||
bindingForm: createEmptyBindingForm(),
|
||||
credentialForm: createEmptyCredentialReferenceForm(),
|
||||
isSaving: false,
|
||||
clientOptions: [],
|
||||
interfaceOptions: [],
|
||||
capabilityOptions: [],
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
}
|
||||
|
||||
describe('IntegrationConnectorFormModal connector-type fields', () => {
|
||||
it('REST 默认显示接口地址与超时字段', () => {
|
||||
const wrapper = mountModal();
|
||||
expect(wrapper.find('[data-testid="client-endpoint"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="client-timeout"]').exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('切换到 SOAP 后连接地址 label 变为 WSDL,超时仍显示;同一 endpoint 字段', async () => {
|
||||
const wrapper = mountModal();
|
||||
await wrapper.find('[data-testid="client-connector-type"]').setValue('soap');
|
||||
await wrapper.vm.$nextTick();
|
||||
// 连接地址仍是同一 client-endpoint 字段,仅 label 变 WSDL
|
||||
expect(wrapper.find('[data-testid="client-endpoint"]').exists()).toBe(true);
|
||||
// 超时在 SOAP 下也显示
|
||||
expect(wrapper.find('[data-testid="client-timeout"]').exists()).toBe(true);
|
||||
const labels = wrapper.findAll('label').map((l) => l.text());
|
||||
expect(labels.some((t) => t.includes('WSDL'))).toBe(true);
|
||||
});
|
||||
|
||||
it('接口定义 REST 显示 HTTP 方法与请求路径', () => {
|
||||
const wrapper = mount(IntegrationConnectorFormModal, {
|
||||
props: {
|
||||
visible: true,
|
||||
activeEntity: 'interface',
|
||||
clientForm: createEmptyClientInstanceForm(),
|
||||
interfaceForm: createEmptyInterfaceDefinitionForm(),
|
||||
bindingForm: createEmptyBindingForm(),
|
||||
credentialForm: createEmptyCredentialReferenceForm(),
|
||||
isSaving: false,
|
||||
clientOptions: [],
|
||||
interfaceOptions: [],
|
||||
capabilityOptions: [],
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
const labels = wrapper.findAll('label').map((l) => l.text());
|
||||
expect(labels.some((t) => t.includes('HTTP 方法'))).toBe(true);
|
||||
expect(labels.some((t) => t.includes('请求路径'))).toBe(true);
|
||||
});
|
||||
|
||||
it('绑定显示来源实例编码独立字段', () => {
|
||||
const wrapper = mount(IntegrationConnectorFormModal, {
|
||||
props: {
|
||||
visible: true,
|
||||
activeEntity: 'binding',
|
||||
clientForm: createEmptyClientInstanceForm(),
|
||||
interfaceForm: createEmptyInterfaceDefinitionForm(),
|
||||
bindingForm: createEmptyBindingForm(),
|
||||
credentialForm: createEmptyCredentialReferenceForm(),
|
||||
isSaving: false,
|
||||
clientOptions: [],
|
||||
interfaceOptions: [],
|
||||
capabilityOptions: [],
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
const labels = wrapper.findAll('label').map((l) => l.text());
|
||||
expect(labels.some((t) => t.includes('来源实例编码'))).toBe(true);
|
||||
});
|
||||
});
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
<!--
|
||||
features/admin/modules/integration-connector/components/IntegrationConnectorFormModal.vue
|
||||
用途:集成连接器四实体(客户端实例/接口定义/绑定/凭据引用)创建与编辑弹窗。
|
||||
依赖:activeEntity 对应的表单 state、useI18n。
|
||||
逻辑:由 IntegrationConnectorPage 打开;按 activeEntity 渲染对应字段;提交 emit save。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type {
|
||||
BindingFormState,
|
||||
ClientInstanceFormState,
|
||||
CredentialReferenceFormState,
|
||||
InterfaceDefinitionFormState,
|
||||
} from '../types/integration-connector.types';
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
activeEntity: 'client' | 'interface' | 'binding' | 'credential';
|
||||
clientForm: ClientInstanceFormState;
|
||||
interfaceForm: InterfaceDefinitionFormState;
|
||||
bindingForm: BindingFormState;
|
||||
credentialForm: CredentialReferenceFormState;
|
||||
isSaving: boolean;
|
||||
clientOptions: Array<{ code: string; name: string }>;
|
||||
interfaceOptions: Array<{ code: string; name: string }>;
|
||||
capabilityOptions: Array<{ name: string }>;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
save: [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay animate-fade-in items-center">
|
||||
<div class="admin-modal-panel max-w-2xl max-h-[92vh] scale-100">
|
||||
<div class="px-5 sm:px-8 pt-5 sm:pt-7 pb-4 border-b border-subtle">
|
||||
<h3 class="section-title">{{ t(`admin.integrationConnector.tabs.${activeEntity}`) }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('admin.integrationConnector.formHint') }}</p>
|
||||
</div>
|
||||
<div class="px-5 sm:px-8 py-5 space-y-5 overflow-y-auto">
|
||||
<!-- 客户端实例 -->
|
||||
<template v-if="activeEntity === 'client'">
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.code') }}</label>
|
||||
<input v-model="clientForm.code" type="text" class="input-field text-sm" :disabled="Boolean(clientForm.id)" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.name') }}</label>
|
||||
<input v-model="clientForm.name" type="text" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.connectorType') }}</label>
|
||||
<select v-model="clientForm.connector_type" class="input-field text-sm" data-testid="client-connector-type">
|
||||
<option value="rest">rest</option>
|
||||
<option value="soap">soap</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.environment') }}</label>
|
||||
<input v-model="clientForm.environment" type="text" class="input-field text-sm" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- 连接地址:endpoint 合一字段;label 按连接器类型显示(REST=接口地址,SOAP=WSDL 地址) -->
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ clientForm.connector_type === 'soap' ? t('admin.integrationConnector.fields.wsdl') : t('admin.integrationConnector.fields.endpoint') }}</label>
|
||||
<input v-model="clientForm.endpoint" type="text" class="input-field text-sm" :placeholder="t(clientForm.connector_type === 'soap' ? 'admin.integrationConnector.placeholders.wsdl' : 'admin.integrationConnector.placeholders.endpoint')" data-testid="client-endpoint" />
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.timeout') }}</label>
|
||||
<input v-model="clientForm.timeout_seconds" type="number" class="input-field text-sm" min="0" data-testid="client-timeout" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.credentialRef') }}</label>
|
||||
<input v-model="clientForm.credential_ref_code" type="text" class="input-field text-sm" />
|
||||
</div>
|
||||
<details class="rounded-lg border border-slate-200 px-3 py-2">
|
||||
<summary class="cursor-pointer text-xs font-bold text-secondary">{{ t('admin.integrationConnector.advancedConfig') }}</summary>
|
||||
<div class="mt-2 space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.configJson') }}</label>
|
||||
<textarea v-model="clientForm.config_json" rows="6" class="input-field text-sm font-mono" spellcheck="false" />
|
||||
</div>
|
||||
</details>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary cursor-pointer">
|
||||
<input v-model="clientForm.enabled" type="checkbox" class="w-4 h-4 rounded text-brand-600 border-default" />
|
||||
{{ t('admin.integrationConnector.fields.enabled') }}
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<!-- 接口定义 -->
|
||||
<template v-else-if="activeEntity === 'interface'">
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.code') }}</label>
|
||||
<input v-model="interfaceForm.code" type="text" class="input-field text-sm" :disabled="Boolean(interfaceForm.id)" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.name') }}</label>
|
||||
<input v-model="interfaceForm.name" type="text" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.clientInstance') }}</label>
|
||||
<select v-model="interfaceForm.client_instance_code" class="input-field text-sm">
|
||||
<option v-for="opt in clientOptions" :key="opt.code" :value="opt.code">{{ opt.code }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.connectorType') }}</label>
|
||||
<select v-model="interfaceForm.connector_type" class="input-field text-sm">
|
||||
<option value="rest">rest</option>
|
||||
<option value="soap">soap</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="interfaceForm.connector_type === 'rest'" class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.httpMethod') }}</label>
|
||||
<select v-model="interfaceForm.http_method" class="input-field text-sm">
|
||||
<option value="">—</option>
|
||||
<option value="GET">GET</option>
|
||||
<option value="POST">POST</option>
|
||||
<option value="PUT">PUT</option>
|
||||
<option value="DELETE">DELETE</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.requestPath') }}</label>
|
||||
<input v-model="interfaceForm.request_path" type="text" class="input-field text-sm font-mono" :placeholder="t('admin.integrationConnector.placeholders.requestPath')" />
|
||||
</div>
|
||||
</div>
|
||||
<details class="rounded-lg border border-slate-200 px-3 py-2">
|
||||
<summary class="cursor-pointer text-xs font-bold text-secondary">{{ t('admin.integrationConnector.advancedConfig') }}</summary>
|
||||
<div class="mt-2 grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.requestSpec') }}</label>
|
||||
<textarea v-model="interfaceForm.request_spec_json" rows="5" class="input-field text-sm font-mono" spellcheck="false" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.inputSchema') }}</label>
|
||||
<textarea v-model="interfaceForm.input_schema_json" rows="5" class="input-field text-sm font-mono" spellcheck="false" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.responseMapping') }}</label>
|
||||
<textarea v-model="interfaceForm.response_mapping_json" rows="5" class="input-field text-sm font-mono" spellcheck="false" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.outputSchema') }}</label>
|
||||
<textarea v-model="interfaceForm.output_schema_json" rows="5" class="input-field text-sm font-mono" spellcheck="false" />
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.status') }}</label>
|
||||
<select v-model="interfaceForm.status" class="input-field text-sm">
|
||||
<option value="draft">draft</option>
|
||||
<option value="published">published</option>
|
||||
<option value="retired">retired</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex items-end pb-1">
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary cursor-pointer">
|
||||
<input v-model="interfaceForm.enabled" type="checkbox" class="w-4 h-4 rounded text-brand-600 border-default" />
|
||||
{{ t('admin.integrationConnector.fields.enabled') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 绑定 -->
|
||||
<template v-else-if="activeEntity === 'binding'">
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.capability') }}</label>
|
||||
<select v-model="bindingForm.capability" class="input-field text-sm">
|
||||
<option v-for="cap in capabilityOptions" :key="cap.name" :value="cap.name">{{ cap.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.environment') }}</label>
|
||||
<input v-model="bindingForm.environment" type="text" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.clientInstance') }}</label>
|
||||
<select v-model="bindingForm.client_instance_code" class="input-field text-sm">
|
||||
<option v-for="opt in clientOptions" :key="opt.code" :value="opt.code">{{ opt.code }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.interfaceDef') }}</label>
|
||||
<select v-model="bindingForm.interface_definition_code" class="input-field text-sm">
|
||||
<option v-for="opt in interfaceOptions" :key="opt.code" :value="opt.code">{{ opt.code }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.mappingVersion') }}</label>
|
||||
<input v-model.number="bindingForm.mapping_version" type="number" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.priority') }}</label>
|
||||
<input v-model.number="bindingForm.priority" type="number" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.effectiveFrom') }}</label>
|
||||
<input v-model="bindingForm.effective_from" type="datetime-local" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.effectiveTo') }}</label>
|
||||
<input v-model="bindingForm.effective_to" type="datetime-local" class="input-field text-sm" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.contextSourceCode') }}</label>
|
||||
<input v-model="bindingForm.context_source_code" type="text" class="input-field text-sm" :placeholder="t('admin.integrationConnector.placeholders.contextSourceCode')" />
|
||||
</div>
|
||||
<details class="rounded-lg border border-slate-200 px-3 py-2">
|
||||
<summary class="cursor-pointer text-xs font-bold text-secondary">{{ t('admin.integrationConnector.advancedConfig') }}</summary>
|
||||
<div class="mt-2 space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.contextSelector') }}</label>
|
||||
<textarea v-model="bindingForm.context_selector_json" rows="4" class="input-field text-sm font-mono" spellcheck="false" />
|
||||
</div>
|
||||
</details>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.status') }}</label>
|
||||
<select v-model="bindingForm.status" class="input-field text-sm">
|
||||
<option value="draft">draft</option>
|
||||
<option value="published">published</option>
|
||||
<option value="retired">retired</option>
|
||||
</select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 凭据引用 -->
|
||||
<template v-else>
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.code') }}</label>
|
||||
<input v-model="credentialForm.code" type="text" class="input-field text-sm" :disabled="Boolean(credentialForm.id)" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.secretRef') }}</label>
|
||||
<input v-model="credentialForm.secret_ref" type="text" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.secretProvider') }}</label>
|
||||
<input v-model="credentialForm.secret_provider" type="text" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.credentialType') }}</label>
|
||||
<input v-model="credentialForm.credential_type" type="text" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.integrationConnector.fields.status') }}</label>
|
||||
<select v-model="credentialForm.status" class="input-field text-sm">
|
||||
<option value="active">active</option>
|
||||
<option value="rotating">rotating</option>
|
||||
<option value="retired">retired</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.cancel') }}</button>
|
||||
<button type="button" class="btn-primary disabled:opacity-70" :disabled="isSaving" @click="emit('save')">
|
||||
{{ isSaving ? t('admin.save') + '...' : t('admin.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* features/admin/modules/integration-connector/composables/useIntegrationConnectorAdmin.spec.ts
|
||||
* 用途:锁定集成连接器管理编排——四实体保存(create/update 分支)、JSON 字段解析校验、
|
||||
* 必填校验拦截、能力调用与连接测试调用 API。
|
||||
* 依赖:vi.mock(integration-connector.api)、@vue/test-utils、i18n。
|
||||
* 逻辑:通过 setup 挂载 harness 组件访问 useIntegrationConnectorAdmin(useI18n 需在 setup 内);
|
||||
* Mock API 断言 payload 构造与调用;非法 JSON 触发拦截且不调 API。
|
||||
*/
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
import { defineComponent, h } from 'vue';
|
||||
import { mount } from '@vue/test-utils';
|
||||
import i18n from '@/i18n';
|
||||
import { useIntegrationConnectorAdmin } from './useIntegrationConnectorAdmin';
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
listIntegrationClientInstances: vi.fn(),
|
||||
createIntegrationClientInstance: vi.fn(),
|
||||
updateIntegrationClientInstance: vi.fn(),
|
||||
deleteIntegrationClientInstance: vi.fn(),
|
||||
testIntegrationClientConnection: vi.fn(),
|
||||
listIntegrationInterfaceDefinitions: vi.fn(),
|
||||
createIntegrationInterfaceDefinition: vi.fn(),
|
||||
updateIntegrationInterfaceDefinition: vi.fn(),
|
||||
listIntegrationBindings: vi.fn(),
|
||||
createIntegrationBinding: vi.fn(),
|
||||
updateIntegrationBinding: vi.fn(),
|
||||
listIntegrationCredentialReferences: vi.fn(),
|
||||
createIntegrationCredentialReference: vi.fn(),
|
||||
updateIntegrationCredentialReference: vi.fn(),
|
||||
listIntegrationCapabilities: vi.fn(),
|
||||
callIntegrationCapability: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/features/admin/modules/integration-connector/api/integration-connector.api', () => api);
|
||||
|
||||
function makeHarness() {
|
||||
let exposed: ReturnType<typeof useIntegrationConnectorAdmin> | null = null;
|
||||
const Harness = defineComponent({
|
||||
setup() {
|
||||
exposed = useIntegrationConnectorAdmin();
|
||||
return () => h('div');
|
||||
},
|
||||
});
|
||||
mount(Harness, { global: { plugins: [i18n] } });
|
||||
return exposed!;
|
||||
}
|
||||
|
||||
describe('useIntegrationConnectorAdmin', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('loadAll 拉取五个列表', async () => {
|
||||
api.listIntegrationClientInstances.mockResolvedValue([]);
|
||||
api.listIntegrationInterfaceDefinitions.mockResolvedValue([]);
|
||||
api.listIntegrationBindings.mockResolvedValue([]);
|
||||
api.listIntegrationCredentialReferences.mockResolvedValue([]);
|
||||
api.listIntegrationCapabilities.mockResolvedValue([]);
|
||||
const c = makeHarness();
|
||||
await c.loadAll();
|
||||
expect(api.listIntegrationClientInstances).toHaveBeenCalled();
|
||||
expect(api.listIntegrationCapabilities).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('新建客户端实例:关键字段独立列 + config_json 解析为对象并 POST', async () => {
|
||||
const c = makeHarness();
|
||||
c.openCreateModal('client');
|
||||
c.clientForm.value.code = 'ERP-X';
|
||||
c.clientForm.value.name = 'ERP X';
|
||||
c.clientForm.value.endpoint = 'https://x.invalid';
|
||||
c.clientForm.value.timeout_seconds = '90';
|
||||
c.clientForm.value.config_json = '{"headers":{"X-Tenant":"A"}}';
|
||||
await c.saveActive();
|
||||
expect(api.createIntegrationClientInstance).toHaveBeenCalledWith({
|
||||
code: 'ERP-X', name: 'ERP X', connector_type: 'rest', environment: 'prod',
|
||||
endpoint: 'https://x.invalid', timeout_seconds: 90,
|
||||
config_json: { headers: { 'X-Tenant': 'A' } }, credential_ref_code: null, enabled: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('编辑客户端实例:有 id 走 PUT', async () => {
|
||||
const c = makeHarness();
|
||||
c.openEditModal('client', {
|
||||
id: 1, code: 'ERP-X', name: 'old', connector_type: 'rest', environment: 'prod',
|
||||
config_json: {}, credential_ref_code: null, enabled: true,
|
||||
});
|
||||
c.clientForm.value.name = 'new';
|
||||
await c.saveActive();
|
||||
expect(api.updateIntegrationClientInstance).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('非法 JSON 字段触发拦截且不调 API', async () => {
|
||||
const c = makeHarness();
|
||||
c.openCreateModal('client');
|
||||
c.clientForm.value.code = 'ERP-X';
|
||||
c.clientForm.value.name = 'ERP X';
|
||||
c.clientForm.value.config_json = '{bad json';
|
||||
await c.saveActive();
|
||||
expect(api.createIntegrationClientInstance).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('客户端实例必填:缺 code 不调 API', async () => {
|
||||
const c = makeHarness();
|
||||
c.openCreateModal('client');
|
||||
c.clientForm.value.name = 'ERP X';
|
||||
await c.saveActive();
|
||||
expect(api.createIntegrationClientInstance).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('绑定:必填校验与 POST payload', async () => {
|
||||
const c = makeHarness();
|
||||
c.openCreateModal('binding');
|
||||
c.bindingForm.value.capability = 'in_transit_transfer.query_inventory';
|
||||
c.bindingForm.value.client_instance_code = 'CLI-A';
|
||||
c.bindingForm.value.interface_definition_code = 'IF-A';
|
||||
await c.saveActive();
|
||||
expect(api.createIntegrationBinding).toHaveBeenCalledWith({
|
||||
capability: 'in_transit_transfer.query_inventory', context_selector_json: {},
|
||||
context_source_code: null,
|
||||
client_instance_code: 'CLI-A', interface_definition_code: 'IF-A',
|
||||
mapping_version: 1, priority: 0, environment: 'prod',
|
||||
effective_from: null, effective_to: null, status: 'draft',
|
||||
});
|
||||
});
|
||||
|
||||
it('凭据引用:创建 payload 不含明文 secret', async () => {
|
||||
const c = makeHarness();
|
||||
c.openCreateModal('credential');
|
||||
c.credentialForm.value.code = 'CRED-A';
|
||||
c.credentialForm.value.secret_ref = 'IN_TRANSIT_ERP_PASSWORD';
|
||||
await c.saveActive();
|
||||
expect(api.createIntegrationCredentialReference).toHaveBeenCalledWith({
|
||||
code: 'CRED-A', secret_ref: 'IN_TRANSIT_ERP_PASSWORD', secret_provider: 'env',
|
||||
credential_type: 'password', status: 'active',
|
||||
});
|
||||
});
|
||||
|
||||
it('连接测试与能力调用走对应 API', async () => {
|
||||
const c = makeHarness();
|
||||
api.testIntegrationClientConnection.mockResolvedValue({ ok: true });
|
||||
api.callIntegrationCapability.mockResolvedValue({ status: 'success', data: { found: true }, error_code: null, error_message: null, document_no: null, trace_id: null });
|
||||
await c.testConnection('CLI-A');
|
||||
expect(api.testIntegrationClientConnection).toHaveBeenCalledWith('CLI-A');
|
||||
c.openCallModal('in_transit_transfer.query_inventory');
|
||||
await c.runCall();
|
||||
expect(api.callIntegrationCapability).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
/**
|
||||
* features/admin/modules/integration-connector/composables/useIntegrationConnectorAdmin.ts
|
||||
* 集成连接器管理编排:客户端实例/接口定义/绑定/凭据引用四实体列表与增改表单,
|
||||
* 以及能力清单与手动调用测试。
|
||||
* 依赖:integration-connector.api、types、useMessage、useI18n。
|
||||
* 逻辑:各列表独立 loadAll;新增/编辑共用表单弹窗态(form.id 区分);能力测试
|
||||
* 独立于配置表单(CapabilityCall 弹窗)。保存/删除后刷新对应列表。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
callIntegrationCapability,
|
||||
createIntegrationBinding,
|
||||
createIntegrationClientInstance,
|
||||
createIntegrationCredentialReference,
|
||||
createIntegrationInterfaceDefinition,
|
||||
deleteIntegrationClientInstance,
|
||||
listIntegrationBindings,
|
||||
listIntegrationCapabilities,
|
||||
listIntegrationClientInstances,
|
||||
listIntegrationCredentialReferences,
|
||||
listIntegrationInterfaceDefinitions,
|
||||
testIntegrationClientConnection,
|
||||
updateIntegrationBinding,
|
||||
updateIntegrationClientInstance,
|
||||
updateIntegrationCredentialReference,
|
||||
updateIntegrationInterfaceDefinition,
|
||||
} from '../api/integration-connector.api';
|
||||
import {
|
||||
bindingRowToForm,
|
||||
clientInstanceRowToForm,
|
||||
createEmptyBindingForm,
|
||||
createEmptyClientInstanceForm,
|
||||
createEmptyCredentialReferenceForm,
|
||||
createEmptyInterfaceDefinitionForm,
|
||||
credentialReferenceRowToForm,
|
||||
interfaceDefinitionRowToForm,
|
||||
type BindingFormState,
|
||||
type ClientInstanceFormState,
|
||||
type CredentialReferenceFormState,
|
||||
type IntegrationBindingRow,
|
||||
type IntegrationCallResultRow,
|
||||
type IntegrationCapabilityRow,
|
||||
type IntegrationClientInstanceRow,
|
||||
type IntegrationCredentialReferenceRow,
|
||||
type IntegrationInterfaceDefinitionRow,
|
||||
type InterfaceDefinitionFormState,
|
||||
} from '../types/integration-connector.types';
|
||||
|
||||
type EditableEntity = 'client' | 'interface' | 'binding' | 'credential';
|
||||
|
||||
export function useIntegrationConnectorAdmin() {
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
|
||||
// ---- 列表与加载态 ----
|
||||
const clients = ref<IntegrationClientInstanceRow[]>([]);
|
||||
const interfaces = ref<IntegrationInterfaceDefinitionRow[]>([]);
|
||||
const bindings = ref<IntegrationBindingRow[]>([]);
|
||||
const credentials = ref<IntegrationCredentialReferenceRow[]>([]);
|
||||
const capabilities = ref<IntegrationCapabilityRow[]>([]);
|
||||
const isLoading = ref(true);
|
||||
|
||||
// ---- 表单弹窗态 ----
|
||||
const activeEntity = ref<EditableEntity>('client');
|
||||
const showFormModal = ref(false);
|
||||
const isSaving = ref(false);
|
||||
const clientForm = ref<ClientInstanceFormState>(createEmptyClientInstanceForm());
|
||||
const interfaceForm = ref<InterfaceDefinitionFormState>(createEmptyInterfaceDefinitionForm());
|
||||
const bindingForm = ref<BindingFormState>(createEmptyBindingForm());
|
||||
const credentialForm = ref<CredentialReferenceFormState>(createEmptyCredentialReferenceForm());
|
||||
|
||||
// ---- 能力调用测试弹窗态 ----
|
||||
const showCallModal = ref(false);
|
||||
const callCapability = ref('');
|
||||
const callParamsText = ref('');
|
||||
const callContextText = ref('');
|
||||
const callResult = ref<IntegrationCallResultRow | null>(null);
|
||||
const callBusy = ref(false);
|
||||
|
||||
// ---- 连接测试 ----
|
||||
const testingClientCode = ref('');
|
||||
const testResultText = ref('');
|
||||
|
||||
const loadClients = async () => { clients.value = await listIntegrationClientInstances(); };
|
||||
const loadInterfaces = async () => { interfaces.value = await listIntegrationInterfaceDefinitions(); };
|
||||
const loadBindings = async () => { bindings.value = await listIntegrationBindings(); };
|
||||
const loadCredentials = async () => { credentials.value = await listIntegrationCredentialReferences(); };
|
||||
const loadCapabilities = async () => { capabilities.value = await listIntegrationCapabilities(); };
|
||||
|
||||
const loadAll = async () => {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
await Promise.all([loadClients(), loadInterfaces(), loadBindings(), loadCredentials(), loadCapabilities()]);
|
||||
} catch (e) {
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const reloadOne = async (entity: EditableEntity) => {
|
||||
if (entity === 'client') await loadClients();
|
||||
else if (entity === 'interface') await loadInterfaces();
|
||||
else if (entity === 'binding') await loadBindings();
|
||||
else await loadCredentials();
|
||||
};
|
||||
|
||||
// ---- 弹窗打开/关闭 ----
|
||||
const openCreateModal = (entity: EditableEntity) => {
|
||||
activeEntity.value = entity;
|
||||
if (entity === 'client') clientForm.value = createEmptyClientInstanceForm();
|
||||
else if (entity === 'interface') interfaceForm.value = createEmptyInterfaceDefinitionForm();
|
||||
else if (entity === 'binding') bindingForm.value = createEmptyBindingForm();
|
||||
else credentialForm.value = createEmptyCredentialReferenceForm();
|
||||
showFormModal.value = true;
|
||||
};
|
||||
|
||||
const openEditModal = (entity: EditableEntity, row: IntegrationClientInstanceRow | IntegrationInterfaceDefinitionRow | IntegrationBindingRow | IntegrationCredentialReferenceRow) => {
|
||||
activeEntity.value = entity;
|
||||
if (entity === 'client') clientForm.value = clientInstanceRowToForm(row as IntegrationClientInstanceRow);
|
||||
else if (entity === 'interface') interfaceForm.value = interfaceDefinitionRowToForm(row as IntegrationInterfaceDefinitionRow);
|
||||
else if (entity === 'binding') bindingForm.value = bindingRowToForm(row as IntegrationBindingRow);
|
||||
else credentialForm.value = credentialReferenceRowToForm(row as IntegrationCredentialReferenceRow);
|
||||
showFormModal.value = true;
|
||||
};
|
||||
|
||||
const closeFormModal = () => {
|
||||
showFormModal.value = false;
|
||||
clientForm.value = createEmptyClientInstanceForm();
|
||||
interfaceForm.value = createEmptyInterfaceDefinitionForm();
|
||||
bindingForm.value = createEmptyBindingForm();
|
||||
credentialForm.value = createEmptyCredentialReferenceForm();
|
||||
};
|
||||
|
||||
/** 解析 JSON 文本;空串返回 {},非法 JSON 抛错并提示。 */
|
||||
const parseJsonField = (text: string, fieldLabel: string): Record<string, unknown> => {
|
||||
const trimmed = String(text || '').trim();
|
||||
if (!trimmed) return {};
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed);
|
||||
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) return parsed;
|
||||
throw new Error('must be an object');
|
||||
} catch {
|
||||
msg.warning(t('admin.integrationConnector.msg.invalidJson', { field: fieldLabel }));
|
||||
throw new Error('invalid JSON');
|
||||
}
|
||||
};
|
||||
|
||||
// ---- 保存 ----
|
||||
const saveActive = async () => {
|
||||
isSaving.value = true;
|
||||
try {
|
||||
if (activeEntity.value === 'client') {
|
||||
const form = clientForm.value;
|
||||
if (!form.code.trim() || !form.name.trim()) {
|
||||
msg.warning(t('admin.integrationConnector.msg.fillClient'));
|
||||
return;
|
||||
}
|
||||
const configJson = parseJsonField(form.config_json, 'config_json');
|
||||
const payload = {
|
||||
code: form.code.trim(), name: form.name.trim(), connector_type: form.connector_type,
|
||||
environment: form.environment,
|
||||
endpoint: form.endpoint.trim() || null,
|
||||
timeout_seconds: form.timeout_seconds.trim() ? Number(form.timeout_seconds) : null,
|
||||
config_json: configJson,
|
||||
credential_ref_code: form.credential_ref_code.trim() || null, enabled: form.enabled,
|
||||
};
|
||||
if (form.id) await updateIntegrationClientInstance(form.code, payload);
|
||||
else await createIntegrationClientInstance(payload);
|
||||
} else if (activeEntity.value === 'interface') {
|
||||
const form = interfaceForm.value;
|
||||
if (!form.code.trim() || !form.client_instance_code.trim()) {
|
||||
msg.warning(t('admin.integrationConnector.msg.fillInterface'));
|
||||
return;
|
||||
}
|
||||
const payload = {
|
||||
code: form.code.trim(), name: form.name.trim() || form.code.trim(),
|
||||
client_instance_code: form.client_instance_code.trim(), connector_type: form.connector_type,
|
||||
http_method: form.http_method.trim() || null,
|
||||
request_path: form.request_path.trim() || null,
|
||||
request_spec_json: parseJsonField(form.request_spec_json, 'request_spec_json'),
|
||||
input_schema_json: parseJsonField(form.input_schema_json, 'input_schema_json'),
|
||||
response_mapping_json: parseJsonField(form.response_mapping_json, 'response_mapping_json'),
|
||||
output_schema_json: parseJsonField(form.output_schema_json, 'output_schema_json'),
|
||||
status: form.status, enabled: form.enabled,
|
||||
};
|
||||
if (form.id) await updateIntegrationInterfaceDefinition(form.code, payload);
|
||||
else await createIntegrationInterfaceDefinition(payload);
|
||||
} else if (activeEntity.value === 'binding') {
|
||||
const form = bindingForm.value;
|
||||
if (!form.capability.trim() || !form.client_instance_code.trim() || !form.interface_definition_code.trim()) {
|
||||
msg.warning(t('admin.integrationConnector.msg.fillBinding'));
|
||||
return;
|
||||
}
|
||||
const payload = {
|
||||
capability: form.capability.trim(), context_selector_json: parseJsonField(form.context_selector_json, 'context_selector_json'),
|
||||
context_source_code: form.context_source_code.trim() || null,
|
||||
client_instance_code: form.client_instance_code.trim(), interface_definition_code: form.interface_definition_code.trim(),
|
||||
mapping_version: Number(form.mapping_version || 1), priority: Number(form.priority || 0),
|
||||
environment: form.environment, effective_from: form.effective_from || null, effective_to: form.effective_to || null,
|
||||
status: form.status,
|
||||
};
|
||||
if (form.id) await updateIntegrationBinding(form.id, payload);
|
||||
else await createIntegrationBinding(payload);
|
||||
} else {
|
||||
const form = credentialForm.value;
|
||||
if (!form.code.trim() || !form.secret_ref.trim()) {
|
||||
msg.warning(t('admin.integrationConnector.msg.fillCredential'));
|
||||
return;
|
||||
}
|
||||
const payload = {
|
||||
code: form.code.trim(), secret_ref: form.secret_ref.trim(), secret_provider: form.secret_provider,
|
||||
credential_type: form.credential_type, status: form.status,
|
||||
};
|
||||
if (form.id) await updateIntegrationCredentialReference(form.code, payload);
|
||||
else await createIntegrationCredentialReference(payload);
|
||||
}
|
||||
closeFormModal();
|
||||
await reloadOne(activeEntity.value);
|
||||
msg.success(t('admin.integrationConnector.msg.saved'));
|
||||
} catch (e) {
|
||||
// parseJsonField 已在内部提示;这里兜底 API 错误。
|
||||
if (!(e instanceof Error && e.message === 'invalid JSON')) {
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// ---- 连接测试 ----
|
||||
const testConnection = async (code: string) => {
|
||||
testingClientCode.value = code;
|
||||
testResultText.value = '';
|
||||
try {
|
||||
const result = await testIntegrationClientConnection(code);
|
||||
testResultText.value = JSON.stringify(result, null, 2);
|
||||
msg.success(t('admin.integrationConnector.msg.testOk'));
|
||||
} catch (e) {
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
} finally {
|
||||
testingClientCode.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
// ---- 能力调用测试 ----
|
||||
const openCallModal = (capability: string) => {
|
||||
callCapability.value = capability;
|
||||
callParamsText.value = JSON.stringify({ invoice_no: '', from_warehouse: '', to_warehouse: '', quantity: 0 }, null, 2);
|
||||
callContextText.value = '{}';
|
||||
callResult.value = null;
|
||||
showCallModal.value = true;
|
||||
};
|
||||
|
||||
const closeCallModal = () => {
|
||||
showCallModal.value = false;
|
||||
callResult.value = null;
|
||||
};
|
||||
|
||||
const runCall = async () => {
|
||||
callBusy.value = true;
|
||||
try {
|
||||
const params = parseJsonField(callParamsText.value, 'params');
|
||||
const context = parseJsonField(callContextText.value, 'context');
|
||||
callResult.value = await callIntegrationCapability(callCapability.value, { params, context });
|
||||
} catch (e) {
|
||||
if (!(e instanceof Error && e.message === 'invalid JSON')) {
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
} finally {
|
||||
callBusy.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const deleteClient = async (code: string) => {
|
||||
try {
|
||||
await deleteIntegrationClientInstance(code);
|
||||
await loadClients();
|
||||
msg.success(t('admin.integrationConnector.msg.deleted'));
|
||||
} catch (e) {
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
clients, interfaces, bindings, credentials, capabilities,
|
||||
isLoading, activeEntity, showFormModal, isSaving,
|
||||
clientForm, interfaceForm, bindingForm, credentialForm,
|
||||
showCallModal, callCapability, callParamsText, callContextText, callResult, callBusy,
|
||||
testingClientCode, testResultText,
|
||||
loadAll, openCreateModal, openEditModal, closeFormModal, saveActive,
|
||||
testConnection, openCallModal, closeCallModal, runCall, deleteClient,
|
||||
};
|
||||
}
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
/**
|
||||
* features/admin/modules/integration-connector/types/integration-connector.types.ts
|
||||
* 集成连接器管理域类型:客户端实例、接口定义、绑定、凭据引用、能力清单、调用结果。
|
||||
* 依赖:无(纯类型与表单构建函数)。
|
||||
* 逻辑:与后端 /api/integration-connector/* 序列化契约对齐;JSON 配置字段以 Record 承载
|
||||
* 具体结构由表单/JSON 编辑器负责,前端不硬编码外部系统差异。
|
||||
*/
|
||||
|
||||
/** 连接器类型:与后端 CONNECTOR_TYPES 对齐。 */
|
||||
export type IntegrationConnectorType = 'rest' | 'soap';
|
||||
|
||||
/** 配置状态:draft 草稿 / published 已发布 / retired 已退役。 */
|
||||
export type IntegrationConfigStatus = 'draft' | 'published' | 'retired';
|
||||
|
||||
/** 凭据状态。 */
|
||||
export type IntegrationCredentialStatus = 'active' | 'rotating' | 'retired';
|
||||
|
||||
/** 能力清单项(后端 capability 注册表)。 */
|
||||
export interface IntegrationCapabilityRow {
|
||||
name: string;
|
||||
write: boolean;
|
||||
idempotency: string;
|
||||
input_schema: Record<string, unknown>;
|
||||
output_schema: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/** 能力调用结果(后端 IntegrationCallResult 序列化)。 */
|
||||
export interface IntegrationCallResultRow {
|
||||
status: string;
|
||||
data: Record<string, unknown> | null;
|
||||
error_code: string | null;
|
||||
error_message: string | null;
|
||||
document_no: string | null;
|
||||
trace_id: string | null;
|
||||
}
|
||||
|
||||
/** 客户端实例(接口地址/凭据引用/连接配置)。 */
|
||||
export interface IntegrationClientInstanceRow {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
connector_type: IntegrationConnectorType;
|
||||
environment: string;
|
||||
endpoint: string | null;
|
||||
timeout_seconds: number | null;
|
||||
config_json: Record<string, unknown>;
|
||||
credential_ref_code: string | null;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/** 接口定义(接口模板/入参字段/回传映射/出参 Schema)。 */
|
||||
export interface IntegrationInterfaceDefinitionRow {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
client_instance_code: string;
|
||||
connector_type: IntegrationConnectorType;
|
||||
http_method: string | null;
|
||||
request_path: string | null;
|
||||
request_spec_json: Record<string, unknown>;
|
||||
input_schema_json: Record<string, unknown>;
|
||||
response_mapping_json: Record<string, unknown>;
|
||||
output_schema_json: Record<string, unknown>;
|
||||
version: number;
|
||||
status: IntegrationConfigStatus;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/** 绑定(能力 → 客户端 + 接口 + 映射版本)。 */
|
||||
export interface IntegrationBindingRow {
|
||||
id: number;
|
||||
capability: string;
|
||||
context_selector_json: Record<string, unknown>;
|
||||
context_source_code: string | null;
|
||||
client_instance_code: string;
|
||||
interface_definition_code: string;
|
||||
mapping_version: number;
|
||||
priority: number;
|
||||
environment: string;
|
||||
effective_from: string | null;
|
||||
effective_to: string | null;
|
||||
status: IntegrationConfigStatus;
|
||||
}
|
||||
|
||||
/** 凭据引用(只存 secret_ref,不落明文)。 */
|
||||
export interface IntegrationCredentialReferenceRow {
|
||||
id: number;
|
||||
code: string;
|
||||
secret_ref: string;
|
||||
secret_provider: string;
|
||||
credential_type: string;
|
||||
version: number;
|
||||
status: IntegrationCredentialStatus;
|
||||
last_verified_at: string | null;
|
||||
}
|
||||
|
||||
/** 客户端实例表单。 */
|
||||
export interface ClientInstanceFormState {
|
||||
id: number | null;
|
||||
code: string;
|
||||
name: string;
|
||||
connector_type: IntegrationConnectorType;
|
||||
environment: string;
|
||||
endpoint: string;
|
||||
timeout_seconds: string;
|
||||
config_json: string;
|
||||
credential_ref_code: string;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/** 接口定义表单(JSON 字段以文本承载,提交时解析)。 */
|
||||
export interface InterfaceDefinitionFormState {
|
||||
id: number | null;
|
||||
code: string;
|
||||
name: string;
|
||||
client_instance_code: string;
|
||||
connector_type: IntegrationConnectorType;
|
||||
http_method: string;
|
||||
request_path: string;
|
||||
request_spec_json: string;
|
||||
input_schema_json: string;
|
||||
response_mapping_json: string;
|
||||
output_schema_json: string;
|
||||
status: IntegrationConfigStatus;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/** 绑定表单。 */
|
||||
export interface BindingFormState {
|
||||
id: number | null;
|
||||
capability: string;
|
||||
context_selector_json: string;
|
||||
context_source_code: string;
|
||||
client_instance_code: string;
|
||||
interface_definition_code: string;
|
||||
mapping_version: number;
|
||||
priority: number;
|
||||
environment: string;
|
||||
effective_from: string;
|
||||
effective_to: string;
|
||||
status: IntegrationConfigStatus;
|
||||
}
|
||||
|
||||
/** 凭据引用表单。 */
|
||||
export interface CredentialReferenceFormState {
|
||||
id: number | null;
|
||||
code: string;
|
||||
secret_ref: string;
|
||||
secret_provider: string;
|
||||
credential_type: string;
|
||||
status: IntegrationCredentialStatus;
|
||||
}
|
||||
|
||||
const toJsonText = (value: Record<string, unknown> | null | undefined): string => {
|
||||
if (!value || Object.keys(value).length === 0) return '';
|
||||
return JSON.stringify(value, null, 2);
|
||||
};
|
||||
|
||||
/** 创建空的客户端实例表单。 */
|
||||
export function createEmptyClientInstanceForm(): ClientInstanceFormState {
|
||||
return {
|
||||
id: null,
|
||||
code: '',
|
||||
name: '',
|
||||
connector_type: 'rest',
|
||||
environment: 'prod',
|
||||
endpoint: '',
|
||||
timeout_seconds: '60',
|
||||
config_json: '',
|
||||
credential_ref_code: '',
|
||||
enabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
/** 列表行回填为客户端实例编辑表单。 */
|
||||
export function clientInstanceRowToForm(row: IntegrationClientInstanceRow): ClientInstanceFormState {
|
||||
return {
|
||||
id: row.id,
|
||||
code: row.code,
|
||||
name: row.name,
|
||||
connector_type: row.connector_type,
|
||||
environment: row.environment,
|
||||
endpoint: row.endpoint ?? '',
|
||||
timeout_seconds: String(row.timeout_seconds ?? ''),
|
||||
config_json: toJsonText(row.config_json),
|
||||
credential_ref_code: row.credential_ref_code ?? '',
|
||||
enabled: Boolean(row.enabled),
|
||||
};
|
||||
}
|
||||
|
||||
/** 创建空的接口定义表单。 */
|
||||
export function createEmptyInterfaceDefinitionForm(): InterfaceDefinitionFormState {
|
||||
return {
|
||||
id: null,
|
||||
code: '',
|
||||
name: '',
|
||||
client_instance_code: '',
|
||||
connector_type: 'rest',
|
||||
http_method: '',
|
||||
request_path: '',
|
||||
request_spec_json: '',
|
||||
input_schema_json: '',
|
||||
response_mapping_json: '',
|
||||
output_schema_json: '',
|
||||
status: 'draft',
|
||||
enabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
/** 列表行回填为接口定义编辑表单。 */
|
||||
export function interfaceDefinitionRowToForm(row: IntegrationInterfaceDefinitionRow): InterfaceDefinitionFormState {
|
||||
return {
|
||||
id: row.id,
|
||||
code: row.code,
|
||||
name: row.name,
|
||||
client_instance_code: row.client_instance_code,
|
||||
connector_type: row.connector_type,
|
||||
http_method: row.http_method ?? '',
|
||||
request_path: row.request_path ?? '',
|
||||
request_spec_json: toJsonText(row.request_spec_json),
|
||||
input_schema_json: toJsonText(row.input_schema_json),
|
||||
response_mapping_json: toJsonText(row.response_mapping_json),
|
||||
output_schema_json: toJsonText(row.output_schema_json),
|
||||
status: row.status,
|
||||
enabled: Boolean(row.enabled),
|
||||
};
|
||||
}
|
||||
|
||||
/** 创建空的绑定表单。 */
|
||||
export function createEmptyBindingForm(): BindingFormState {
|
||||
return {
|
||||
id: null,
|
||||
capability: '',
|
||||
context_selector_json: '',
|
||||
context_source_code: '',
|
||||
client_instance_code: '',
|
||||
interface_definition_code: '',
|
||||
mapping_version: 1,
|
||||
priority: 0,
|
||||
environment: 'prod',
|
||||
effective_from: '',
|
||||
effective_to: '',
|
||||
status: 'draft',
|
||||
};
|
||||
}
|
||||
|
||||
/** 列表行回填为绑定编辑表单。 */
|
||||
export function bindingRowToForm(row: IntegrationBindingRow): BindingFormState {
|
||||
return {
|
||||
id: row.id,
|
||||
capability: row.capability,
|
||||
context_selector_json: toJsonText(row.context_selector_json),
|
||||
context_source_code: row.context_source_code ?? '',
|
||||
client_instance_code: row.client_instance_code,
|
||||
interface_definition_code: row.interface_definition_code,
|
||||
mapping_version: Number(row.mapping_version || 1),
|
||||
priority: Number(row.priority || 0),
|
||||
environment: row.environment,
|
||||
effective_from: row.effective_from ?? '',
|
||||
effective_to: row.effective_to ?? '',
|
||||
status: row.status,
|
||||
};
|
||||
}
|
||||
|
||||
/** 创建空的凭据引用表单。 */
|
||||
export function createEmptyCredentialReferenceForm(): CredentialReferenceFormState {
|
||||
return {
|
||||
id: null,
|
||||
code: '',
|
||||
secret_ref: '',
|
||||
secret_provider: 'env',
|
||||
credential_type: 'password',
|
||||
status: 'active',
|
||||
};
|
||||
}
|
||||
|
||||
/** 列表行回填为凭据引用编辑表单。 */
|
||||
export function credentialReferenceRowToForm(row: IntegrationCredentialReferenceRow): CredentialReferenceFormState {
|
||||
return {
|
||||
id: row.id,
|
||||
code: row.code,
|
||||
secret_ref: row.secret_ref,
|
||||
secret_provider: row.secret_provider,
|
||||
credential_type: row.credential_type,
|
||||
status: row.status,
|
||||
};
|
||||
}
|
||||
+6
-2
@@ -75,7 +75,8 @@ export function useOrderProfileValueAdapter(options: UseOrderProfileValueAdapter
|
||||
const profileId = computed(() => Number(toValue(options.profileId) || 0));
|
||||
const saveState = computed(() => toValue(options.saveState));
|
||||
const readonly = computed(() => saveState.value === 'readonly');
|
||||
const loading = ref(true);
|
||||
// 坐标模板不会启用该 adapter;初始状态必须是非加载,避免共享画布误显示 XFA loading。
|
||||
const loading = ref(false);
|
||||
const loadError = ref(false);
|
||||
const lockVersion = ref(0);
|
||||
const schemaFields = ref<ShippingOrderFieldConfig[]>([]);
|
||||
@@ -977,7 +978,10 @@ export function useOrderProfileValueAdapter(options: UseOrderProfileValueAdapter
|
||||
const enabled = computed(() => toValue(options.enabled) !== false);
|
||||
|
||||
watch(enabled, (isEnabled) => {
|
||||
if (isEnabled && profileId.value > 0) void load();
|
||||
if (isEnabled && profileId.value > 0) {
|
||||
loading.value = true;
|
||||
void load();
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
watch(diagnosticsOpen, async (open) => {
|
||||
|
||||
+2
-278
@@ -3,7 +3,7 @@
|
||||
用途:单一发货订单 Schema 的版本采用与版本级识别规则编辑;字段身份由全局字段资产库维护。
|
||||
依赖:shipping-order-schema.api、shipping-field-assets.api、FieldImpactDrawer、版本/审计抽屉组件、Vue I18n。
|
||||
逻辑:左侧勾选采用资产目录,右侧编辑已采用字段规则;草稿保存/发布与历史追溯由服务端冻结。无多族切换。
|
||||
「Schema 级策略」分组收纳自动建单总开关与字段派生规则;仅草稿可改,随保存/发布生效;支持样本模拟。
|
||||
「Schema 级策略」仅收纳自动建单总开关;订单项次由系统按单据内顺序生成。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
||||
@@ -26,8 +26,6 @@ import {
|
||||
listShippingOrderSchemaVersions,
|
||||
publishShippingOrderSchemaDraft,
|
||||
saveShippingOrderSchemaDraft,
|
||||
simulateShippingOrderSchemaDerivation,
|
||||
listShippingOrderSchemaDerivationSimulateSamples,
|
||||
} from '@/features/admin/api/shipping-order-schema.api';
|
||||
import FieldImpactDrawer from '@/features/admin/modules/shipping-field-assets/components/FieldImpactDrawer.vue';
|
||||
import SchemaExtractionAuditDrawer from '@/features/admin/modules/shipping-order-schema/components/SchemaExtractionAuditDrawer.vue';
|
||||
@@ -36,9 +34,6 @@ import SchemaVersionHistoryDrawer from '@/features/admin/modules/shipping-order-
|
||||
import SchemaVersionUsageDrawer from '@/features/admin/modules/shipping-order-schema/components/SchemaVersionUsageDrawer.vue';
|
||||
import type { ShippingFieldAsset, ShippingFieldAssetImpact } from '@/features/admin/types/shipping-field-assets.types';
|
||||
import type {
|
||||
ShippingOrderDerivationRule,
|
||||
ShippingOrderDerivationSimulateResult,
|
||||
ShippingOrderDerivationSimulateSampleItem,
|
||||
ShippingOrderField,
|
||||
ShippingOrderFieldConfig,
|
||||
ShippingOrderExtractionAudit,
|
||||
@@ -75,20 +70,6 @@ const autoCreationConfirmOpen = ref(false);
|
||||
const pendingAutoCreationEnabled = ref(false);
|
||||
const changeNote = ref('');
|
||||
const selectedDraftFieldId = ref<string | null>(null);
|
||||
const derivationRules = ref<ShippingOrderDerivationRule[]>([]);
|
||||
const derivationPanelOpen = ref(true);
|
||||
const simulateOpen = ref(false);
|
||||
const simulating = ref(false);
|
||||
const simulateMode = ref<'history' | 'inline'>('history');
|
||||
const simulateSamples = ref<ShippingOrderDerivationSimulateSampleItem[]>([]);
|
||||
const simulateSampleRef = ref('');
|
||||
const simulateSamplesLoading = ref(false);
|
||||
const simulateSampleJson = ref(`[
|
||||
{"customer_po_line_no": "00010", "line_no": null},
|
||||
{"customer_po_line_no": "00020", "line_no": "20"},
|
||||
{"customer_po_line_no": "ABC", "line_no": null}
|
||||
]`);
|
||||
const simulateResult = ref<ShippingOrderDerivationSimulateResult | null>(null);
|
||||
const fieldSearch = ref('');
|
||||
const expandedGroups = reactive<Record<AdoptionGroupKey, boolean>>({
|
||||
headerStandard: true,
|
||||
@@ -271,19 +252,6 @@ const syncDraftFields = (): void => {
|
||||
autoCreationEnabled.value = typeof draftPolicy === 'boolean'
|
||||
? draftPolicy
|
||||
: state.value?.schema?.auto_creation_policy?.enabled === true;
|
||||
const sourceRules = draft.value?.definition?.derivation_rules
|
||||
|| published.value?.definition?.derivation_rules
|
||||
|| [];
|
||||
derivationRules.value = sourceRules.length
|
||||
? sourceRules.map((rule) => ({ ...rule }))
|
||||
: [{
|
||||
rule_id: 'R-LINE-NO-FROM-CUSTOMER-PO',
|
||||
enabled: false,
|
||||
source_field_code: 'customer_po_line_no',
|
||||
target_field_code: 'line_no',
|
||||
strategy: 'copy_if_empty',
|
||||
scope: 'line',
|
||||
}];
|
||||
const existing = draft.value?.definition?.fields || published.value?.definition?.fields || [];
|
||||
const byId = new Map(existing.map((item) => [item.field_id, item]));
|
||||
draftFields.value = (state.value?.fields || [])
|
||||
@@ -441,7 +409,7 @@ const toggleAdoption = (field: ShippingOrderField, enabled: boolean): void => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存草稿的全部已采用字段规则、派生规则与自动建单策略;未采用字段不会进入发布契约。 */
|
||||
/** 保存草稿的全部已采用字段规则与自动建单策略;订单项次不属于可编辑 Schema 配置。 */
|
||||
const saveDraft = async (): Promise<void> => {
|
||||
if (!draft.value) return;
|
||||
saving.value = true;
|
||||
@@ -450,16 +418,12 @@ const saveDraft = async (): Promise<void> => {
|
||||
const saved = await saveShippingOrderSchemaDraft(draft.value.id, {
|
||||
fields,
|
||||
auto_creation_policy: { enabled: autoCreationEnabled.value },
|
||||
derivation_rules: derivationRules.value.map((item) => ({ ...item })),
|
||||
change_note: changeNote.value,
|
||||
expected_lock_version: draft.value.lock_version,
|
||||
});
|
||||
if (state.value) {
|
||||
state.value.versions = state.value.versions.map((item) => (item.id === saved.id ? saved : item));
|
||||
}
|
||||
if (saved.definition?.derivation_rules) {
|
||||
derivationRules.value = saved.definition.derivation_rules.map((item) => ({ ...item }));
|
||||
}
|
||||
message.success(t('admin.shippingOrderSchema.draftSaved'));
|
||||
} catch (error) {
|
||||
await handleWriteError(error);
|
||||
@@ -468,82 +432,6 @@ const saveDraft = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换派生规则启用状态(仅草稿可改)。
|
||||
* @param index - 规则下标
|
||||
* @param event - checkbox 事件
|
||||
*/
|
||||
const onDerivationEnabledChange = (index: number, event: Event): void => {
|
||||
if (!draft.value) return;
|
||||
const checked = (event.target as HTMLInputElement).checked;
|
||||
const current = derivationRules.value[index];
|
||||
if (!current) return;
|
||||
derivationRules.value[index] = { ...current, enabled: checked };
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开派生规则模拟弹窗并加载历史 Extraction 样本列表。
|
||||
*/
|
||||
const openDerivationSimulate = async (): Promise<void> => {
|
||||
simulateResult.value = null;
|
||||
simulateMode.value = 'history';
|
||||
simulateOpen.value = true;
|
||||
simulateSamplesLoading.value = true;
|
||||
try {
|
||||
const response = await listShippingOrderSchemaDerivationSimulateSamples(20);
|
||||
simulateSamples.value = response.items || [];
|
||||
simulateSampleRef.value = simulateSamples.value[0]?.sample_ref || '';
|
||||
if (!simulateSamples.value.length) {
|
||||
simulateMode.value = 'inline';
|
||||
}
|
||||
} catch (error) {
|
||||
await handleWriteError(error);
|
||||
simulateMode.value = 'inline';
|
||||
} finally {
|
||||
simulateSamplesLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 运行派生规则模拟:优先使用历史 Extraction 样本,亦可手工 JSON。
|
||||
*/
|
||||
const runDerivationSimulate = async (): Promise<void> => {
|
||||
if (!draft.value && !published.value) return;
|
||||
const versionId = draft.value?.id || published.value?.id;
|
||||
if (!versionId) return;
|
||||
simulating.value = true;
|
||||
try {
|
||||
if (simulateMode.value === 'history') {
|
||||
if (!simulateSampleRef.value) {
|
||||
message.error(t('admin.shippingOrderSchema.derivationSimulateSampleRequired'));
|
||||
return;
|
||||
}
|
||||
simulateResult.value = await simulateShippingOrderSchemaDerivation(versionId, {
|
||||
sample_ref: simulateSampleRef.value,
|
||||
derivation_rules: derivationRules.value,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const lines = JSON.parse(simulateSampleJson.value) as Array<Record<string, string | number | null>>;
|
||||
if (!Array.isArray(lines)) {
|
||||
throw new Error('invalid sample');
|
||||
}
|
||||
simulateResult.value = await simulateShippingOrderSchemaDerivation(versionId, {
|
||||
lines,
|
||||
derivation_rules: derivationRules.value,
|
||||
sample_ref: 'schema-admin-inline-sample',
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof SyntaxError || (error instanceof Error && error.message === 'invalid sample')) {
|
||||
message.error(t('admin.shippingOrderSchema.derivationSimulateSampleInvalid'));
|
||||
} else {
|
||||
await handleWriteError(error);
|
||||
}
|
||||
} finally {
|
||||
simulating.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 拦截自动建单开关变更:仅草稿可改,且须二次确认;确认后仅写入本地,随保存草稿/发布生效。
|
||||
* @param event - checkbox change 事件
|
||||
@@ -1049,48 +937,6 @@ onMounted(async () => {
|
||||
</label>
|
||||
<p class="schema-gate-note">{{ t('admin.shippingOrderSchema.effectiveReservationGate') }}</p>
|
||||
|
||||
<details class="derivation-panel" :open="derivationPanelOpen" @toggle="derivationPanelOpen = ($event.target as HTMLDetailsElement).open">
|
||||
<summary>
|
||||
<strong>{{ t('admin.shippingOrderSchema.derivationRulesTitle') }}</strong>
|
||||
<span>{{ t('admin.shippingOrderSchema.derivationRulesHint') }}</span>
|
||||
</summary>
|
||||
<div class="derivation-toolbar">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-secondary btn-sm"
|
||||
:disabled="simulating || (!draft && !published)"
|
||||
@click="openDerivationSimulate"
|
||||
>
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulate') }}
|
||||
</button>
|
||||
</div>
|
||||
<table class="derivation-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationEnabled') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationSource') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationTarget') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationStrategy') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(rule, index) in derivationRules" :key="rule.rule_id">
|
||||
<td>
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="rule.enabled"
|
||||
:disabled="!draft || saving"
|
||||
@change="onDerivationEnabledChange(index, $event)"
|
||||
>
|
||||
</td>
|
||||
<td><code>{{ rule.source_field_code }}</code></td>
|
||||
<td><code>{{ rule.target_field_code }}</code></td>
|
||||
<td>{{ t('admin.shippingOrderSchema.derivationStrategyCopyIfEmpty') }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="derivation-note">{{ t('admin.shippingOrderSchema.derivationRulesNote') }}</p>
|
||||
</details>
|
||||
</section>
|
||||
|
||||
<div class="schema-workbench">
|
||||
@@ -1508,96 +1354,6 @@ onMounted(async () => {
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div v-if="simulateOpen" class="impact-overlay" @click.self="simulateOpen = false">
|
||||
<section class="impact-dialog derivation-simulate-dialog">
|
||||
<header>
|
||||
<h2>{{ t('admin.shippingOrderSchema.derivationSimulateTitle') }}</h2>
|
||||
<button type="button" class="btn-ghost btn-sm" @click="simulateOpen = false">{{ t('common.close') }}</button>
|
||||
</header>
|
||||
<p class="simulate-hint">{{ t('admin.shippingOrderSchema.derivationSimulateNoMutate') }}</p>
|
||||
<div class="simulate-mode-row">
|
||||
<label>
|
||||
<input v-model="simulateMode" type="radio" value="history">
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateModeHistory') }}
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="simulateMode" type="radio" value="inline">
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateModeInline') }}
|
||||
</label>
|
||||
</div>
|
||||
<label v-if="simulateMode === 'history'" class="simulate-sample">
|
||||
<span>{{ t('admin.shippingOrderSchema.derivationSimulateHistorySample') }}</span>
|
||||
<select v-model="simulateSampleRef" :disabled="simulateSamplesLoading || !simulateSamples.length">
|
||||
<option disabled value="">
|
||||
{{ simulateSamplesLoading
|
||||
? t('admin.shippingOrderSchema.derivationSimulateSamplesLoading')
|
||||
: t('admin.shippingOrderSchema.derivationSimulateSamplesEmpty') }}
|
||||
</option>
|
||||
<option
|
||||
v-for="item in simulateSamples"
|
||||
:key="item.sample_ref"
|
||||
:value="item.sample_ref"
|
||||
>
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateSampleOption', {
|
||||
id: item.extraction_id,
|
||||
lines: item.line_count,
|
||||
status: item.status,
|
||||
}) }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label v-else class="simulate-sample">
|
||||
<span>{{ t('admin.shippingOrderSchema.derivationSimulateSample') }}</span>
|
||||
<textarea v-model="simulateSampleJson" rows="8" />
|
||||
</label>
|
||||
<footer>
|
||||
<button type="button" class="btn-secondary" @click="simulateOpen = false">{{ t('common.cancel') }}</button>
|
||||
<button type="button" class="btn-primary" :disabled="simulating" @click="runDerivationSimulate">
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateRun') }}
|
||||
</button>
|
||||
</footer>
|
||||
<div v-if="simulateResult" class="simulate-result">
|
||||
<p>
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateSummary', {
|
||||
version: simulateResult.schema_version,
|
||||
checksum: simulateResult.rules_checksum.slice(0, 12),
|
||||
derived: simulateResult.derived_count,
|
||||
skipped: simulateResult.skipped_count,
|
||||
}) }}
|
||||
</p>
|
||||
<div class="simulate-result-scroll" data-testid="derivation-simulate-result-scroll">
|
||||
<table class="derivation-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationSource') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationBefore') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationAfter') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationResult') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in simulateResult.results" :key="`${row.line_index}-${row.rule_id}`">
|
||||
<td>{{ row.line_index + 1 }}</td>
|
||||
<td>{{ row.before_source ?? '—' }}</td>
|
||||
<td>{{ row.before_target ?? '—' }}</td>
|
||||
<td>{{ row.after_target ?? '—' }}</td>
|
||||
<td>
|
||||
<template v-if="row.status === 'derived'">
|
||||
{{ t('admin.shippingOrderSchema.derivationStatusDerived') }}
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ t('admin.shippingOrderSchema.derivationStatusSkipped', { reason: row.skip_reason || '' }) }}
|
||||
</template>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="muted">{{ t('admin.shippingOrderSchema.derivationSimulateNoMutate') }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div v-if="profileImpactOpen && profileImpact" class="impact-overlay" @click.self="profileImpactOpen = false">
|
||||
<section class="impact-dialog">
|
||||
@@ -1725,38 +1481,6 @@ onMounted(async () => {
|
||||
.auto-creation-switch small { color: #64748b; font-size: 11px; }
|
||||
.auto-creation-effective { display: block; color: #0f766e; }
|
||||
.schema-gate-note { margin: 0 0 12px; color: #475569; font-size: 12px; line-height: 1.5; }
|
||||
.derivation-panel { margin: 0 0 8px; border: 1px solid #dbe6ef; border-radius: 8px; background: #fff; padding: 12px 14px; }
|
||||
.derivation-panel summary { cursor: pointer; display: grid; gap: 4px; color: #334155; }
|
||||
.derivation-panel summary span { color: #64748b; font-size: 12px; }
|
||||
.derivation-toolbar { display: flex; justify-content: flex-end; margin: 12px 0; }
|
||||
.derivation-table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||||
.derivation-table th, .derivation-table td { border-bottom: 1px solid #e2e8f0; padding: 8px 6px; text-align: left; vertical-align: middle; }
|
||||
.derivation-note { margin: 10px 0 0; color: #64748b; font-size: 12px; }
|
||||
.simulate-hint { margin: 0 0 10px; color: #64748b; font-size: 12px; }
|
||||
.simulate-mode-row { display: flex; gap: 16px; margin-bottom: 10px; font-size: 13px; color: #334155; }
|
||||
.simulate-mode-row label { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.derivation-simulate-dialog {
|
||||
max-width: 760px;
|
||||
width: min(760px, 92vw);
|
||||
overflow: auto;
|
||||
align-content: start;
|
||||
}
|
||||
.simulate-sample { display: grid; gap: 8px; margin: 12px 0; color: #475569; font-size: 13px; }
|
||||
.simulate-sample textarea,
|
||||
.simulate-sample select { width: 100%; font-size: 12px; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px; box-sizing: border-box; }
|
||||
.simulate-sample textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
||||
.simulate-result { margin-top: 14px; display: grid; gap: 10px; min-width: 0; }
|
||||
.simulate-result-scroll {
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.simulate-result-scroll .derivation-table {
|
||||
margin: 0;
|
||||
min-width: 520px;
|
||||
}
|
||||
.muted { margin: 0; color: #64748b; font-size: 12px; }
|
||||
.field-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; border-right: 1px solid #e5ebf1; background: #fbfcfe; }
|
||||
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 16px 10px; }
|
||||
|
||||
Reference in new issue
Block a user