提交 9f85ffd2 authored 作者: kxjia's avatar kxjia

修改 验证组件样式

上级 9ee7229c
<template>
<div class="bank-report-table" style="height: 80vh">
<div class="bank-report-table" style="height: 80vh" @click="closeAllTooltips">
<!-- 加载遮罩层 -->
<div v-if="loading" class="loading-overlay">
<div class="loading-spinner">
......@@ -9,54 +9,47 @@
</div>
<vxe-toolbar>
<template #button>
<div style="margin: 10px">
<span style="font-weight: bold"> 填报任务:{{ queryParam?.taskName }} </span>
<span style="font-weight: bold; margin-left: 20px"> 表格:{{ queryParam?.tplCode }} {{ queryParam?.tplName }}</span>
<template #buttons>
<div style="margin:10px">
<span class="table-info-text">填报任务:{{ queryParam.taskName }}</span>
<span class="table-info-text" style="margin-left:20px">
表格:{{ queryParam.tplCode }} {{ queryParam.tplName }}
</span>
</div>
</template>
<template #tools>
<vxe-button status="primary" icon="vxe-icon-edit" @click="handleOpenHistoryDrawer()" :disabled="loading">近5年数据填报</vxe-button>
<vxe-button status="primary" icon="vxe-icon-save" @click="checkData()">校验</vxe-button>
<vxe-button status="primary" icon="vxe-icon-save" @click="saveBatch()">保存</vxe-button>
<vxe-button
status="primary"
icon="vxe-icon-edit"
@click="handleOpenHistoryDrawer"
:disabled="loading"
>
近5年数据填报
</vxe-button>
<vxe-button
status="primary"
icon="vxe-icon-save"
@click="validateData"
>
校验
</vxe-button>
<vxe-button
status="primary"
icon="vxe-icon-save"
@click="saveBatch"
>
保存
</vxe-button>
</template>
</vxe-toolbar>
<!-- 校验结果抽屉 -->
<vxe-drawer v-model="drawerVisible" placement="right" @show="handleValidationDrawerShow" title="校验结果" width="40%" :footer="{ show: true }">
<template #default>
<div class="validation-results">
<div class="result-summary">
<div class="summary-item">
<span class="summary-label">校验字段数:</span>
<span class="summary-value">{{ validationResultsList.length }}</span>
</div>
<div class="summary-item">
<span class="summary-label">通过:</span>
<span class="summary-value success">{{ validationResultsList.filter((item) => item.isValid).length }}</span>
</div>
<div class="summary-item">
<span class="summary-label">失败:</span>
<span class="summary-value error">{{ validationResultsList.filter((item) => !item.isValid).length }}</span>
</div>
</div>
<div class="results-list">
<div
v-for="(result, index) in validationResultsList"
:key="index"
class="result-item"
:class="{ success: result.isValid, error: !result.isValid }"
@click="handleValidationResultClick(result)"
>
<div class="result-field">{{ result.field }}</div>
<div class="result-desc">{{ result.description }}</div>
<div class="result-value">值:{{ result.fieldValue || '空' }}</div>
<div v-if="!result.isValid" class="result-error">失败原因:{{ result.description }}</div>
</div>
</div>
</div>
</template>
</vxe-drawer>
<!-- 校验抽屉 -->
<ValidationDrawer
ref="validationDrawerRef"
v-model="drawerVisible"
:tableFormData="tableFormData"
@validationResultClick="handleValidationResultClick"
/>
<vxe-table
border
......@@ -68,13 +61,15 @@
:row-config="{ resizable: true }"
class="custom-table"
>
<vxe-column field="serialNumber" title="序号" width="80"></vxe-column>
<vxe-column field="project" title="项目" width="200">
<vxe-column field="serialNumber" title="序号" width="50"></vxe-column>
<vxe-column field="project" title="项目" width="100">
<template #default="{ row }">
<span style="font-weight: bold; size: 20px">{{ row.project }}</span>
<span class="project-name">{{ row.project }}</span>
</template>
</vxe-column>
<vxe-column field="content" title="内容" row-resize>
<vxe-column field="content" title="内容">
<template #default="{ row }">
<div class="content-cell">
<template v-if="row.type === 'MultiColumnTable'">
......@@ -95,9 +90,12 @@
:calcSum="row.calcSum"
:showFooter="row.showFooter"
:ref="(el) => setAttachTableRef(el, row.code)"
style="margin: 0px; padding: 0px"
:disabled="!row.hasRight"
style="margin:0px;padding:0px"
/>
</template>
<!-- Vxe表格 -->
<template v-else-if="row.type === 'VxeTable'">
<MyVxeTable1
:title="row.project"
......@@ -107,7 +105,8 @@
:footerData="row.footerData"
:showFooter="row.showFooter"
:ref="(el) => setMyVxeTableRef(el, row.code)"
style="margin: 0px; padding: 0px"
:disabled="!row.hasRight"
style="margin:0px;padding:0px"
/>
</template>
<template v-else>
......@@ -266,9 +265,63 @@
</div>
</div>
<template v-else>
<vxe-input :type="item.type" v-model="formData[row.code + '_' + item.field]" size="mini" class="table-input" :style="item.style">
</vxe-input>
<div class="input-wrapper">
<vxe-input
:type="item.type"
v-model="formData[getFieldKey(row.code, item.field)]"
size="mini"
class="table-input"
:style="item.style"
@blur="handleInputBlur(row.code, item.field, item.matchedFormula?.formula)"
/>
<span class="unit"> {{ item.unit }}</span>
<!-- 帮助图标 -->
<span
v-if="item.hasValidFormula"
class="help-icon"
@click.stop="toggleTooltip(row.code, item.field)"
>
?
</span>
<!-- 错误图标 -->
<span
v-if="inputErrors[getFieldKey(row.code, item.field)]"
class="error-icon"
@click.stop="toggleErrorTooltip(row.code, item.field)"
>
<i class="vxe-icon-error"></i>
</span>
<!-- 错误提示 -->
<div
v-if="showErrorTooltip && hoveredErrorKey === getFieldKey(row.code, item.field)"
class="error-tooltip"
@click.stop
>
{{ inputErrors[getFieldKey(row.code, item.field)].message }}
<br>
<span style="color: #ffcccc;">
公式: {{ inputErrors[getFieldKey(row.code, item.field)].formula }}
</span>
<template v-if="inputErrors[getFieldKey(row.code, item.field)].error">
<br>
<span style="color: #ff9999; font-size: 11px;">
错误: {{ inputErrors[getFieldKey(row.code, item.field)].error }}
</span>
</template>
</div>
<!-- 校验规则提示 -->
<div
v-if="showTooltip && hoveredKey === getFieldKey(row.code, item.field)"
class="tooltip"
@click.stop
>
{{ item.matchedFormula?.des || '暂无校验规则' }}
</div>
</div>
</template>
</template>
</template>
......@@ -279,15 +332,6 @@
<!-- 历史填报检查组件 -->
<HistoryFillCheck ref="historyFillCheckRef" v-model="historyDrawerVisible" @close-drawer="closeHistoryDrawer" />
<!-- 验证公式帮助提示 -->
<div
v-if="validationTooltipVisible"
class="validation-tooltip"
:style="{ left: validationTooltipPosition.left + 'px', top: validationTooltipPosition.top + 'px' }"
>
<pre class="tooltip-content">{{ validationTooltipContent }}</pre>
</div>
<!-- 原有检查组件 -->
<CheckTbData ref="refCheckTbData"></CheckTbData>
</div>
......@@ -299,8 +343,9 @@
import MyVxeTable1 from '../tableComponents/MyVxeTable.vue';
import CheckTbData from './CheckTbData.vue';
import HistoryFillCheck from './check/historyFillCheck.vue';
import ValidationDrawer from './check/ValidationDrawer.vue';
import { tableFormData } from '../../data/tb6.data';
import { ref, reactive, nextTick, onMounted, toRaw } from 'vue';
import { ref, reactive, nextTick, onMounted, toRaw, computed } from 'vue';
import { VxeUI, VxeToolbarInstance, VxeToolbarPropTypes } from 'vxe-table';
import { batchSaveOrUpdate, queryRecord, batchSaveOrUpdateBeforeDelete } from '../../record/BaosongTaskRecord.api';
import { queryAllTplItemForUser, findUserRightForTplItem } from '../../alloc/BaosongTaskAlloc.api';
......@@ -310,6 +355,7 @@
const refCheckTbData = ref();
const historyFillCheckRef = ref<any>(null);
const validationDrawerRef = ref();
const route = useRoute();
const tableRef = ref();
......@@ -325,12 +371,12 @@
// 权限相关状态
const userAllocItems = ref<string[]>([]);
const validFormula = ref<any[]>([]);
const validationResultsList = ref<any[]>([]);
const drawerVisible = ref(false);
const historyDrawerVisible = ref(false);
const validationTooltipVisible = ref(false);
const validationTooltipPosition = ref({ left: 0, top: 0 });
const validationTooltipContent = ref('');
const showTooltip = ref(false);
const hoveredKey = ref('');
const showErrorTooltip = ref(false);
const hoveredErrorKey = ref('');
interface FormData {
id: number | null;
......@@ -343,6 +389,18 @@
rind: number;
}
interface FormulaItem {
formula: string;
des: string;
[key: string]: any;
}
interface InputError {
message: string;
formula: string;
error?: string;
}
onMounted(async () => {
if (route.query.taskId) {
queryParam.value.taskId = Number(route.query.taskId);
......@@ -375,13 +433,20 @@
}
await setTplItemMap();
await setFormItemRight();
await setData();
});
const loading = ref(false);
const formData = reactive({});
const formValues = ref<FormData[]>([]);
const inputErrors = ref<Record<string, InputError>>({});
const fieldKeys = computed(() => Object.keys(formData));
const getFieldKey = (rowCode: string, field: string): string => {
return `${rowCode}_${field}`;
};
const saveBatch = async () => {
try {
......@@ -512,121 +577,146 @@
};
// 校验数据
const checkData = () => {
const validateData = () => {
drawerVisible.value = true;
validationDrawerRef.value.setValidateData(validFormula.value,formData);
};
// 校验结果抽屉显示时触发
const handleValidationDrawerShow = () => {
performValidation();
};
const handleInputBlur = (rowCode: string, field: string, formula?: string) => {
if (!formula) return;
// 执行校验
const performValidation = () => {
validationResultsList.value = [];
const process: string[] = [];
process.push('开始校验');
process.push(`找到 ${validFormula.value.length} 个验证公式`);
const key = getFieldKey(rowCode, field);
const value = formData[key];
validFormula.value.forEach((formulaItem: any) => {
process.push(`开始校验公式: ${formulaItem.des}`);
const result = evaluateFormula(formulaItem.formula, formulaItem.des, process);
if (result) {
validationResultsList.value.push(result);
if (!value || value === '') {
delete inputErrors.value[key];
return;
}
});
process.push('校验完成');
validateFieldFormula(rowCode, field, formula);
};
// 解析和执行验证公式
const evaluateFormula = (formula: string, description: string, process: string[]): any => {
try {
const fieldMatch = formula.match(/\[(\w+)\]/);
if (!fieldMatch) {
process.push(`跳过: 无法解析公式字段 ${formula}`);
return null;
}
const validateFieldFormula = (rowCode: string, field: string, formula: string) => {
const key = getFieldKey(rowCode, field);
const fieldName = fieldMatch[1];
const row = tableFormData.find((r: any) => r.content?.some((c: any) => c.field === fieldName));
if (!row) {
process.push(`跳过: 未找到字段 ${fieldName}`);
return null;
try {
const expression = buildExpression(formula, rowCode);
const isValid = eval(expression);
if (!isValid) {
inputErrors.value[key] = {
message: "公式校验失败,请检查填写内容",
formula
};
} else {
delete inputErrors.value[key];
}
const fieldItem = row.content.find((c: any) => c.field === fieldName);
if (!fieldItem) {
process.push(`跳过: 未找到字段 ${fieldName}`);
return null;
} catch (error: any) {
inputErrors.value[key] = {
message: "公式校验失败,请检查填写内容",
formula,
error: error.message
};
}
};
const strKey = `${row.code}_${fieldName}`;
const fieldValue = formData[strKey];
const buildExpression = (formula: string, rowCode: string): string => {
const fieldNames = formula.match(/\b[A-Za-z][A-Za-z0-9_]*\b/g) || [];
const uniqueFields = [...new Set(fieldNames.filter(f =>
!['and', 'or', 'not', 'equal', 'less', 'greater', 'if', 'else', 'true', 'false']
.includes(f.toLowerCase())
))];
// 检查是否有空字段规则
const emptyFieldRule = validFormula.value.find((f: any) => f.formula.includes(fieldName) && f.des.includes('空字段'));
uniqueFields.sort((a, b) => b.length - a.length);
if (emptyFieldRule && (!fieldValue || fieldValue === '')) {
process.push(`跳过: 字段 ${fieldName} 为空,跳过空字段规则`);
return null;
let expression = formula;
for (const fieldName of uniqueFields) {
const key = getFieldKey(rowCode, fieldName);
const value = formData[key];
if (value !== undefined) {
expression = expression.replace(
new RegExp(`\\b${fieldName}\\b`, 'g'),
`Number(${value})`
);
}
}
const expression = formula.replace(/\[(\w+)\]/g, (_, field) => {
const value = formData[`${row.code}_${field}`];
return value !== undefined ? `Number(${value})` : '0';
});
process.push(`执行公式: ${expression}`);
const isValid = eval(expression);
return expression;
};
return {
field: fieldName,
description: description,
formula: formula,
isValid: isValid,
fieldValue: fieldValue,
rowCode: row.code,
const toggleTooltip = (rowCode: string, field: string) => {
const key = getFieldKey(rowCode, field);
if (hoveredKey.value === key) {
showTooltip.value = false;
hoveredKey.value = '';
} else {
showTooltip.value = true;
hoveredKey.value = key;
}
};
} catch (error) {
process.push(`公式执行错误: ${error instanceof Error ? error.message : String(error)}`);
return null;
const toggleErrorTooltip = (rowCode: string, field: string) => {
const key = getFieldKey(rowCode, field);
if (hoveredErrorKey.value === key) {
showErrorTooltip.value = false;
hoveredErrorKey.value = '';
} else {
showErrorTooltip.value = true;
hoveredErrorKey.value = key;
}
};
// 处理校验结果点击,定位到表格
const handleValidationResultClick = (result: any) => {
const row = tableFormData.find((r: any) => r.code === result.rowCode);
if (row) {
const fieldItem = row.content.find((c: any) => c.field === result.field);
if (fieldItem) {
const strKey = `${row.code}_${result.field}`;
const inputElement = document.querySelector(`[data-field="${strKey}"]`) as HTMLElement;
if (inputElement) {
inputElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
inputElement.focus();
inputElement.style.border = '2px solid #ff4d4f';
setTimeout(() => {
inputElement.style.border = '';
}, 2000);
const closeAllTooltips = () => {
showTooltip.value = false;
hoveredKey.value = '';
showErrorTooltip.value = false;
hoveredErrorKey.value = '';
};
const setFormItemRight = () => {
tableFormData.forEach((row: any) => {
if (row.content && Array.isArray(row.content)) {
row.content.forEach((item: any) => {
if (item.field) {
const key = getFieldKey(row.code, item.field);
item.hasRight = userAllocItems.value.includes(key);
if (item.hasRight) {
const { formula } = findEarliestFormulaForField(validFormula.value, item.field);
item.hasValidFormula = !!formula;
item.matchedFormula = formula;
}
}
});
}
});
};
// 显示验证公式帮助
const showValidationHelp = (formulaItem: any, event: MouseEvent) => {
const rect = (event.target as HTMLElement).getBoundingClientRect();
validationTooltipPosition.value = {
left: rect.left + rect.width / 2,
top: rect.top - 10,
};
validationTooltipContent.value = `验证公式: ${formulaItem.formula}\n说明: ${formulaItem.des}`;
validationTooltipVisible.value = true;
const findEarliestFormulaForField = (
formulas: FormulaItem[],
field: string
): { formula: FormulaItem | null, index: number } => {
let result = { formula: null, index: Infinity };
formulas?.forEach((f: FormulaItem) => {
const text = f.formula || '';
const escapedField = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp(`\\b${escapedField}\\b(?!\\w)`, 'g');
const match = regex.exec(text);
if (match && match.index < result.index) {
result = { formula: f, index: match.index };
}
});
return result;
};
// 关闭验证公式帮助
const closeTooltip = () => {
validationTooltipVisible.value = false;
// 处理校验结果点击
const handleValidationResultClick = (result: any) => {
const message = `字段 ${result.field} 的校验结果: ${result.isValid ? '通过' : '失败'}`;
const status = result.isValid ? 'success' : 'error';
VxeUI.modal.message({ content: message, status });
};
// 打开历史填报抽屉
......@@ -829,109 +919,8 @@
font-size: 14px;
}
/* 校验结果样式 */
.validation-results {
padding: 20px;
height: 600px;
overflow-y: auto;
}
.result-summary {
display: flex;
gap: 20px;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.summary-item {
display: flex;
flex-direction: column;
}
.summary-label {
font-size: 12px;
color: #666;
}
.summary-value {
font-size: 16px;
font-weight: bold;
color: #333;
}
.summary-value.success {
color: #52c41a;
}
.summary-value.error {
color: #ff4d4f;
}
.results-list {
margin-top: 10px;
}
.result-item {
padding: 10px;
margin-bottom: 8px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
.result-item:hover {
background-color: #f5f5f5;
}
.result-item.success {
background-color: #f6ffed;
border-left: 4px solid #52c41a;
}
.result-item.error {
background-color: #fff2f0;
border-left: 4px solid #ff4d4f;
}
.result-field {
font-weight: bold;
margin-bottom: 5px;
}
.result-desc {
font-size: 12px;
color: #666;
margin-bottom: 5px;
}
.result-value {
font-size: 12px;
color: #999;
}
.result-error {
font-size: 12px;
color: #ff4d4f;
margin-top: 5px;
}
/* 验证公式帮助提示样式 */
.validation-tooltip {
position: absolute;
background-color: #333;
color: #fff;
padding: 10px;
border-radius: 4px;
font-size: 12px;
z-index: 1000;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.tooltip-content {
margin: 0;
white-space: pre-wrap;
}
.custom-table {
width: 100%;
......@@ -1081,4 +1070,101 @@
color: black;
cursor: pointer;
}
// 输入框包装器
.input-wrapper {
position: relative;
display: inline-block;
}
// 单位文本
.unit {
margin-left: 5px;
font-size: 12px;
}
// 帮助图标
.help-icon {
margin-left: 5px;
cursor: pointer;
color: #1890ff;
font-weight: bold;
font-size: 14px;
display: inline-block;
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
background: #e6f7ff;
border-radius: 50%;
transition: all 0.3s;
&:hover {
background: #bae7ff;
}
}
// 错误图标
.error-icon {
margin-left: 5px;
cursor: pointer;
color: #ff4d4f;
font-size: 16px;
display: inline-block;
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
transition: all 0.3s;
&:hover {
transform: scale(1.1);
}
}
// 提示框
.tooltip, .error-tooltip {
position: absolute;
top: 100%;
left: 0;
margin-top: 5px;
padding: 10px;
font-size: 12px;
border-radius: 4px;
z-index: 1000;
white-space: pre-wrap;
max-width: 300px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.tooltip {
background: #333;
color: #fff;
&::before {
content: '';
position: absolute;
bottom: 100%;
left: 10px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #333 transparent;
}
}
.error-tooltip {
background: #8b0000;
color: #fff;
border: 1px solid #ff4d4f;
&::before {
content: '';
position: absolute;
bottom: 100%;
left: 5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #8b0000 transparent;
}
}
</style>
......@@ -7,6 +7,7 @@
title="校验结果"
width="55%"
:footer="{ show: true }"
height="100%"
>
<template #default>
<div class="validation-results">
......@@ -302,8 +303,10 @@ defineExpose({
<style lang="less" scoped>
.validation-results {
padding: 20px;
height: 600px;
height: calc(100vh-10px);
overflow-y: auto;
display: flex;
flex-direction: column;
}
.result-summary {
......@@ -371,6 +374,8 @@ defineExpose({
.results-list {
margin-top: 10px;
flex: 1;
overflow-y: auto;
}
.result-item {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论