Merge branch 'refs/heads/develop'
This commit is contained in:
@@ -7,8 +7,9 @@
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import { HttpRequestClient } from '@/utils/request';
|
||||
import { HttpRequestClient, originalAxios } from '@/utils/request';
|
||||
import type { ApiDataResponse, BasicResponse } from '@/types';
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import type { RuleConfig, RuleConfigPageableResponse, RuleConfigRequest, RuleDictItem, RuleFourBlocksPayload, RuleGraphPayload, RuleParamMeta } from './types';
|
||||
|
||||
const req = HttpRequestClient.create<BasicResponse>({
|
||||
@@ -50,3 +51,24 @@ export const findRuleConfigGraph = (query: Partial<RuleConfigRequest> = {}): Pro
|
||||
export const findRuleFourBlocksGraph = (): Promise<ApiDataResponse<RuleFourBlocksPayload>> => {
|
||||
return req.get('/system/rule/config/graph/four-blocks');
|
||||
};
|
||||
|
||||
export const exportRuleConfig = (query: Partial<RuleConfigRequest> = {}): Promise<AxiosResponse<Blob>> => {
|
||||
return originalAxios.post('/api/system/rule/config/export', query, {
|
||||
responseType: 'blob',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8',
|
||||
'Accept': 'application/octet-stream',
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const importRuleConfig = (file: File, updateSupport: boolean = true): Promise<BasicResponse> => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('updateSupport', String(updateSupport));
|
||||
return originalAxios.post('/api/system/rule/config/importData', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
}).then((response) => response.data as BasicResponse);
|
||||
};
|
||||
|
||||
@@ -6,10 +6,31 @@
|
||||
<span class="icon"></span>
|
||||
<span class="text">规则聚合测试</span>
|
||||
</a-flex>
|
||||
<a-button class="ks-sidebar-add" size="small" @click="handleCreate">
|
||||
<PlusOutlined />
|
||||
新增
|
||||
</a-button>
|
||||
<a-space class="ks-sidebar-actions">
|
||||
<a-button class="ks-sidebar-add" size="small" @click="handleCreate">
|
||||
<PlusOutlined />
|
||||
新增
|
||||
</a-button>
|
||||
<a-tooltip title="导入 Excel">
|
||||
<a-button class="rule-config-sidebar-action" size="small" :loading="importLoading" @click="handleImportTrigger">
|
||||
<UploadOutlined />
|
||||
导入
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip title="导出 Excel">
|
||||
<a-button class="rule-config-sidebar-action" size="small" :loading="exportLoading" @click="handleExport">
|
||||
<DownloadOutlined />
|
||||
导出
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
</a-space>
|
||||
<input
|
||||
ref="importInputRef"
|
||||
type="file"
|
||||
accept=".xls,.xlsx"
|
||||
style="display: none;"
|
||||
@change="handleImportChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<a-tree
|
||||
@@ -72,7 +93,15 @@
|
||||
<div
|
||||
class="rule-config-right-panel"
|
||||
:class="{ 'rule-config-right-panel--collapsed': !rightPanelExpanded }"
|
||||
:style="rightPanelExpanded ? { flexBasis: `${rightPanelWidth}px`, width: `${rightPanelWidth}px` } : undefined"
|
||||
>
|
||||
<button
|
||||
v-if="rightPanelExpanded"
|
||||
type="button"
|
||||
class="rule-config-right-panel-edge"
|
||||
title="左右拖动调整参数配置区域宽度"
|
||||
@mousedown="onRightPanelResizeMouseDown"
|
||||
/>
|
||||
<div class="rule-config-right-panel__inner">
|
||||
<a-form
|
||||
ref="formRef"
|
||||
@@ -182,10 +211,10 @@
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onMounted, ref } from 'vue';
|
||||
import { type FormInstance, message } from 'ant-design-vue';
|
||||
import { LeftOutlined, MinusCircleOutlined, PlusCircleOutlined, PlusOutlined, RightOutlined } from '@ant-design/icons-vue';
|
||||
import { DownloadOutlined, LeftOutlined, MinusCircleOutlined, PlusCircleOutlined, PlusOutlined, RightOutlined, UploadOutlined } from '@ant-design/icons-vue';
|
||||
import Layout from '../layout.vue';
|
||||
import RuleKnowledgeGraph from './RuleKnowledgeGraph.vue';
|
||||
import { createRuleConfig, deleteRuleConfig, findRuleConfigByCode, findRuleConfigByQuery, findRuleParamMeta, updateRuleConfig } from './api';
|
||||
import { createRuleConfig, deleteRuleConfig, exportRuleConfig, findRuleConfigByCode, findRuleConfigByQuery, findRuleParamMeta, importRuleConfig, updateRuleConfig } from './api';
|
||||
import type { RuleConfig, RuleConfigParam, RuleConfigRequest, RuleParamMeta } from './types';
|
||||
|
||||
const query = ref<RuleConfigRequest>({
|
||||
@@ -225,6 +254,9 @@ const datasource = ref<RuleConfig[]>([]);
|
||||
const datasourceTotal = ref<number>(0);
|
||||
const selectedRuleConfig = ref<RuleConfig>(JSON.parse(JSON.stringify(defaultRuleConfig)));
|
||||
const formRef = ref<FormInstance | null>(null);
|
||||
const importInputRef = ref<HTMLInputElement | null>(null);
|
||||
const importLoading = ref(false);
|
||||
const exportLoading = ref(false);
|
||||
const treeData = ref<any[]>([]);
|
||||
const selectedTreeKeys = ref<string[]>([]);
|
||||
const expandedTreeKeys = ref<string[]>([]);
|
||||
@@ -250,14 +282,24 @@ const rightPanelExpanded = ref(true);
|
||||
const GRAPH_PANE_STORAGE_KEY = 'rule-config-graph-pane-percent';
|
||||
const GRAPH_PANE_MIN = 18;
|
||||
const GRAPH_PANE_MAX = 70;
|
||||
const RIGHT_PANEL_WIDTH_STORAGE_KEY = 'rule-config-right-panel-width';
|
||||
const RIGHT_PANEL_MIN = 360;
|
||||
const RIGHT_PANEL_MAX = 960;
|
||||
const graphPanePercent = ref(32);
|
||||
const graphPanePercentBeforeFourBlocks = ref<number | null>(null);
|
||||
const splitRootRef = ref<HTMLElement | null>(null);
|
||||
const graphRevision = ref(0);
|
||||
const rightPanelWidth = ref(480);
|
||||
|
||||
const clampGraphPercent = (n: number) =>
|
||||
Math.min(GRAPH_PANE_MAX, Math.max(GRAPH_PANE_MIN, Math.round(n)));
|
||||
|
||||
const clampRightPanelWidth = (n: number) => {
|
||||
const rootWidth = splitRootRef.value?.getBoundingClientRect().width ?? window.innerWidth;
|
||||
const dynamicMax = Math.min(RIGHT_PANEL_MAX, Math.max(420, Math.floor(rootWidth * 0.72)));
|
||||
return Math.min(dynamicMax, Math.max(RIGHT_PANEL_MIN, Math.round(n)));
|
||||
};
|
||||
|
||||
const onRuleGraphDensityChange = (mode: 'overview' | 'full' | 'four-blocks') => {
|
||||
if (mode === 'four-blocks') {
|
||||
if (graphPanePercentBeforeFourBlocks.value === null) {
|
||||
@@ -295,6 +337,28 @@ const onGraphSplitMouseDown = (e: MouseEvent) => {
|
||||
window.addEventListener('mouseup', onUp);
|
||||
};
|
||||
|
||||
const onRightPanelResizeMouseDown = (e: MouseEvent) => {
|
||||
e.preventDefault();
|
||||
const root = splitRootRef.value;
|
||||
if (!root) return;
|
||||
const rect = root.getBoundingClientRect();
|
||||
const onMove = (ev: MouseEvent) => {
|
||||
const width = rect.right - ev.clientX;
|
||||
rightPanelWidth.value = clampRightPanelWidth(width);
|
||||
};
|
||||
const onUp = () => {
|
||||
window.removeEventListener('mousemove', onMove);
|
||||
window.removeEventListener('mouseup', onUp);
|
||||
document.body.style.removeProperty('cursor');
|
||||
document.body.style.removeProperty('user-select');
|
||||
sessionStorage.setItem(RIGHT_PANEL_WIDTH_STORAGE_KEY, String(rightPanelWidth.value));
|
||||
};
|
||||
document.body.style.cursor = 'col-resize';
|
||||
document.body.style.userSelect = 'none';
|
||||
window.addEventListener('mousemove', onMove);
|
||||
window.addEventListener('mouseup', onUp);
|
||||
};
|
||||
|
||||
const kindOptions = [
|
||||
{ code: 'select', name: '选择' },
|
||||
{ code: 'assign', name: '分配' },
|
||||
@@ -581,6 +645,79 @@ const handleMinusParam = (index: number) => {
|
||||
selectedRuleConfig.value.params = params;
|
||||
};
|
||||
|
||||
|
||||
const extractFilename = (contentDisposition?: string) => {
|
||||
if (!contentDisposition) {
|
||||
return 'rule-config.xlsx';
|
||||
}
|
||||
const match = /filename\*=UTF-8''([^;]+)|filename="?([^";]+)"?/i.exec(contentDisposition);
|
||||
const raw = match?.[1] ?? match?.[2] ?? 'rule-config.xlsx';
|
||||
try {
|
||||
return decodeURIComponent(raw.replace(/\+/g, '%20'));
|
||||
} catch {
|
||||
return raw;
|
||||
}
|
||||
};
|
||||
|
||||
const downloadBlob = (blob: Blob, filename: string) => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = url;
|
||||
anchor.download = filename;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const handleExport = async () => {
|
||||
exportLoading.value = true;
|
||||
try {
|
||||
const response = await exportRuleConfig(query.value as Partial<RuleConfigRequest>);
|
||||
const filename = extractFilename(response.headers['content-disposition']);
|
||||
downloadBlob(response.data, filename);
|
||||
message.success('导出成功');
|
||||
} catch (err: any) {
|
||||
message.error(err?.message ?? '导出失败');
|
||||
} finally {
|
||||
exportLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleImportTrigger = () => {
|
||||
if (importInputRef.value) {
|
||||
importInputRef.value.value = '';
|
||||
importInputRef.value.click();
|
||||
}
|
||||
};
|
||||
|
||||
const handleImportChange = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement | null;
|
||||
const file = input?.files?.[0];
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
if (!/\.(xls|xlsx)$/i.test(file.name)) {
|
||||
message.error('请选择 Excel 文件');
|
||||
if (input) {
|
||||
input.value = '';
|
||||
}
|
||||
return;
|
||||
}
|
||||
importLoading.value = true;
|
||||
try {
|
||||
const response = await importRuleConfig(file, true);
|
||||
await load();
|
||||
message.success(response.msg ?? '导入成功');
|
||||
} catch (err: any) {
|
||||
message.error(err?.message ?? '导入失败');
|
||||
} finally {
|
||||
importLoading.value = false;
|
||||
if (input) {
|
||||
input.value = '';
|
||||
}
|
||||
}
|
||||
};
|
||||
onMounted(() => {
|
||||
const raw = sessionStorage.getItem(GRAPH_PANE_STORAGE_KEY);
|
||||
if (raw) {
|
||||
@@ -589,6 +726,13 @@ onMounted(() => {
|
||||
graphPanePercent.value = clampGraphPercent(v);
|
||||
}
|
||||
}
|
||||
const rightPanelRaw = sessionStorage.getItem(RIGHT_PANEL_WIDTH_STORAGE_KEY);
|
||||
if (rightPanelRaw) {
|
||||
const width = Number(rightPanelRaw);
|
||||
if (!Number.isNaN(width)) {
|
||||
rightPanelWidth.value = clampRightPanelWidth(width);
|
||||
}
|
||||
}
|
||||
loadParamMeta().then(() => load());
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user