提交 c9689b4d authored 作者: kxjia's avatar kxjia

Tb8.vue 校验

上级 ecf267ec
<template> <template>
<div class="bank-report-table" @click="closeTooltip"> <div class="bank-report-table" @click="closeAllTooltips">
<!-- 加载遮罩层 --> <!-- 加载遮罩层 -->
<div v-if="loading" class="loading-overlay"> <div v-if="loading" class="loading-overlay">
<div class="loading-spinner"> <div class="loading-spinner">
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
</template> </template>
<template #tools> <template #tools>
<vxe-button status="primary" icon="vxe-icon-edit" @click="handleOpenHistoryDrawer()" :disabled="loading">近5年数据填报</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="checkData()">校验</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-save" @click="saveBatch()">保存</vxe-button>
</template> </template>
</vxe-toolbar> </vxe-toolbar>
...@@ -78,175 +78,244 @@ ...@@ -78,175 +78,244 @@
<vxe-column field="serialNumber" title="序号" width="80"></vxe-column> <vxe-column field="serialNumber" title="序号" width="80"></vxe-column>
<vxe-column field="project" title="项目" width="200"> <vxe-column field="project" title="项目" width="200">
<template #default="{ row }"> <template #default="{ row }">
<span style="font-weight: bold;size:20px">{{ row.project }}</span> <span style="font-weight: bold; font-size: 14px">{{ row.project }}</span>
</template> </template>
</vxe-column> </vxe-column>
<vxe-column field="content" title="内容" row-resize> <vxe-column field="content" title="内容" row-resize>
<template #default="{ row }"> <template #default="{ row }">
<div class="content-cell"> <div class="content-cell">
<template v-for="(item, index) in row.content" :key="index"> <template v-for="(item, index) in row.content" :key="index">
<span v-if="item.type === 'text'" v-html="item.value" style="line-height: 35px;"></span> <span v-if="item.type === 'text'" v-html="item.value" style="line-height: 35px;"></span>
<span v-else-if="item.type === 'br'"><br></span> <span v-else-if="item.type === 'br'"><br></span>
<span v-else-if="item.type === 'brspace'"> <span v-else-if="item.type === 'brspace'">
<br> <br>
<template v-for="i in item.value||1" :key="i"> <template v-for="i in (item.value || 1)" :key="i">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</template> </template>
</span> </span>
<template v-else-if="item.type === 'yesno'"> <!-- 是/否单选组 -->
<!-- 是/否单选组 --> <template v-else-if="item.type === 'yesno'">
<vxe-radio-group v-model="formData[row.code +'_'+ item.field]"> <vxe-radio-group v-model="formData[getFieldKey(row.code, item.field)]">
<vxe-radio label="是" content="是"></vxe-radio> <vxe-radio label="是" content="是"></vxe-radio>
<vxe-radio label="否" content="否"></vxe-radio> <vxe-radio label="否" content="否"></vxe-radio>
</vxe-radio-group> </vxe-radio-group>
<!-- 额外字段区域 --> <!-- 额外字段区域 -->
<template v-if="item.extraField || item.extraFields"> <template v-if="item.extraField || item.extraFields">
<div v-if="formData[row.code +'_'+ item.field] === '是'" class="extra-fields-container"> <div v-if="formData[getFieldKey(row.code, item.field)] === '是'" class="extra-fields-container">
<!-- 单个额外字段的情况 -->
<template v-if="item.extraField">
<!-- 单个额外字段的情况 --> <span class="extra-fields-prompt">如是,</span>
<template v-if="item.extraField"> <span class="extra-label">{{ item.extraLabel }}</span>
<span class="extra-fields-prompt">如是,</span> <vxe-input
<span class="extra-label">{{ item.extraLabel }}</span> v-model="formData[getFieldKey(row.code, item.extraField)]"
<vxe-input style="width: 300px"
v-model="formData[row.code + '_'+ item.extraField]" ></vxe-input>
style="width: 300px" <span v-if="item.unit" class="unit">{{ item.unit }}</span>
></vxe-input>
<span v-if="item.unit" class="unit">{{ item.unit }}</span>
</template>
<!-- 多个额外字段的情况 -->
<template v-else-if="item.extraFields">
<span class="extra-fields-prompt">如是,</span>
<template v-for="(fieldOpt, index) in item.extraFields" :key="index">
<!-- 字段标签 -->
<span class="extra-field-item">
<span class="field-label">{{ fieldOpt.label }}: </span>
<template v-if="fieldOpt.formType === 'input'">
<vxe-input
v-model="formData[row.code + '_'+ fieldOpt.field]"
style="width: 250px"
></vxe-input>
</template>
<template v-else-if="fieldOpt.formType === 'number'">
<vxe-input
v-model="formData[row.code + '_'+ fieldOpt.field]"
type="number"
style="width: 250px"
></vxe-input>
<span v-if="fieldOpt.unit" class="unit">{{ fieldOpt.unit }}</span>
</template>
<template v-else-if="fieldOpt.formType === 'checkbox'">
<vxe-checkbox-group v-model="formData[row.code + '_'+ fieldOpt.field]">
<vxe-checkbox
v-for="(opt, optIndex) in fieldOpt.options"
:key="optIndex"
:label="opt"
:content="opt"
></vxe-checkbox>
</vxe-checkbox-group>
</template>
<template v-else-if="fieldOpt.formType === 'radio'">
<vxe-radio-group v-model="formData[row.code + '_'+ fieldOpt.field]">
<vxe-radio
v-for="(opt, optIndex) in fieldOpt.options"
:key="optIndex"
:label="opt"
:content="opt"
></vxe-radio>
</vxe-radio-group>
</template>
<template v-else>
<vxe-input
v-model="formData[row.code + '_'+ fieldOpt.field]"
:type="fieldOpt.formType"
style="width: 100px"
></vxe-input>
</template>
<!-- 其他选项 -->
<template v-if="fieldOpt.otherOption">
<div class="other-option">
其他:
<vxe-input
v-model="formData[row.code + '_'+ fieldOpt.otherField]"
style="width: 300px"
></vxe-input>
</div>
</template>
</span>
</template>
</template>
</div>
</template> </template>
</template>
<!-- 多个额外字段的情况 -->
<span v-else-if="item.type === 'radio-group'" class="radio-group"> <template v-else-if="item.extraFields">
<vxe-radio-group v-model="formData[row.code +'_'+ item.field]"> <span class="extra-fields-prompt">如是,</span>
<vxe-radio v-for="(opt, optIndex) in item.options" :key="optIndex" :label="opt">{{ opt }}</vxe-radio> <template v-for="(fieldOpt, index) in item.extraFields" :key="index">
</vxe-radio-group> <!-- 字段标签 -->
</span> <span class="extra-field-item">
<span v-else-if="item.type === 'radio-group-extraFields'" class="radio-group" style="width:100%"> <span class="field-label">{{ fieldOpt.label }}: </span>
<vxe-radio-group v-model="formData[row.code +'_'+ item.field]"> <template v-if="fieldOpt.formType === 'input'">
<vxe-radio v-for="(opt, optIndex) in item.options" :key="optIndex" :label="opt.label"> <vxe-input
{{ opt.label }} v-model="formData[getFieldKey(row.code, fieldOpt.field)]"
<template v-if="opt.extraField&&formData[row.code +'_'+ item.field]==opt.label"> style="width: 250px"
<span>{{ opt.extraField }}</span> ></vxe-input>
<vxe-input v-model="formData[row.code + '_'+ opt.otereField]" style="width: 200px;"></vxe-input> </template>
<template v-else-if="fieldOpt.formType === 'number'">
<vxe-input
v-model="formData[getFieldKey(row.code, fieldOpt.field)]"
type="number"
style="width: 250px"
></vxe-input>
<span v-if="fieldOpt.unit" class="unit">{{ fieldOpt.unit }}</span>
</template>
<template v-else-if="fieldOpt.formType === 'checkbox'">
<vxe-checkbox-group v-model="formData[getFieldKey(row.code, fieldOpt.field)]">
<vxe-checkbox
v-for="(opt, optIndex) in fieldOpt.options"
:key="optIndex"
:label="opt"
:content="opt"
></vxe-checkbox>
</vxe-checkbox-group>
</template>
<template v-else-if="fieldOpt.formType === 'radio'">
<vxe-radio-group v-model="formData[getFieldKey(row.code, fieldOpt.field)]">
<vxe-radio
v-for="(opt, optIndex) in fieldOpt.options"
:key="optIndex"
:label="opt"
:content="opt"
></vxe-radio>
</vxe-radio-group>
</template>
<template v-else>
<vxe-input
v-model="formData[getFieldKey(row.code, fieldOpt.field)]"
:type="fieldOpt.formType"
style="width: 100px"
></vxe-input>
</template>
<!-- 其他选项 -->
<template v-if="fieldOpt.otherOption">
<div class="other-option">
其他:
<vxe-input
v-model="formData[getFieldKey(row.code, fieldOpt.otherField)]"
style="width: 300px"
></vxe-input>
</div>
</template>
</span>
</template> </template>
<template v-if="opt.extraFields&&formData[row.code +'_'+ item.field]==opt.label"> </template>
<template v-for="(ccopt,ccind) in opt.extraFields" :key="ccind"> </div>
</template>
</template>
<!-- 普通单选组 -->
<span v-else-if="item.type === 'radio-group'" class="radio-group">
<vxe-radio-group v-model="formData[getFieldKey(row.code, item.field)]">
<vxe-radio v-for="(opt, optIndex) in item.options" :key="optIndex" :label="opt">{{ opt }}</vxe-radio>
</vxe-radio-group>
</span>
<!-- 带额外字段的单选组 -->
<span v-else-if="item.type === 'radio-group-extraFields'" class="radio-group" style="width:100%">
<vxe-radio-group v-model="formData[getFieldKey(row.code, item.field)]">
<vxe-radio v-for="(opt, optIndex) in item.options" :key="optIndex" :label="opt.label">
{{ opt.label }}
<template v-if="opt.extraField && formData[getFieldKey(row.code, item.field)] === opt.label">
<span>{{ opt.extraField }}</span>
<vxe-input v-model="formData[getFieldKey(row.code, opt.otereField)]" style="width: 200px;"></vxe-input>
</template>
<template v-if="opt.extraFields && formData[getFieldKey(row.code, item.field)] === opt.label">
<template v-for="(ccopt, ccind) in opt.extraFields" :key="ccind">
<span>{{ ccopt.label }}: </span> <span>{{ ccopt.label }}: </span>
<vxe-input v-model="formData[row.code + '_'+ ccopt.field]" style="width: 200px;"></vxe-input> <vxe-input v-model="formData[getFieldKey(row.code, ccopt.field)]" style="width: 200px;"></vxe-input>
</template>
</template> </template>
</vxe-radio> </template>
</vxe-radio-group> </vxe-radio>
<span v-if="item.unit" class="unit"> {{ item.unit }}</span> </vxe-radio-group>
</span> <span v-if="item.unit" class="unit"> {{ item.unit }}</span>
<div v-else-if="item.type === 'checkbox-group'"> </span>
<span class="checkbox-group">
<vxe-checkbox-group v-model="formData[row.code+'_'+item.field]"> <!-- 多选组 -->
<vxe-checkbox v-for="(opt, optIndex) in item.options" :key="optIndex" :label="opt"> <div v-else-if="item.type === 'checkbox-group'">
{{ opt }} <span class="checkbox-group">
</vxe-checkbox> <vxe-checkbox-group v-model="formData[getFieldKey(row.code, item.field)]">
<template v-if="item.otherOption"> <vxe-checkbox v-for="(opt, optIndex) in item.options" :key="optIndex" :label="opt">
<vxe-checkbox label="其他"> {{ opt }}
其他: </vxe-checkbox>
<vxe-input v-model="formData[row.code + '_'+ item.otherField]" style="width: 200px;" <template v-if="item.otherOption">
:disabled="!(formData[row.code+'_'+item.field]?.indexOf('其他')>-1)"> <vxe-checkbox label="其他">
</vxe-input> 其他:
</vxe-checkbox> <vxe-input
v-model="formData[getFieldKey(row.code, item.otherField)]"
</template> style="width: 200px;"
</vxe-checkbox-group> :disabled="!(formData[getFieldKey(row.code, item.field)]?.includes('其他'))"
</span> ></vxe-input>
</div> </vxe-checkbox>
<template v-else-if="item.type=='textarea'"> </template>
<vxe-textarea v-model="formData[row.code +'_'+ item.field]" :rows="item.rows" :style="{width:item.width}"> </vxe-checkbox-group>
</vxe-textarea> </span>
</template> </div>
<template v-else>
<vxe-input :type="item.type" v-model="formData[row.code +'_'+ item.field]" size="mini" class="table-input" :style="{width:item.width}"> <!-- 文本域 -->
</vxe-input> <template v-else-if="item.type === 'textarea'">
<vxe-textarea
v-model="formData[getFieldKey(row.code, item.field)]"
:rows="item.rows"
:style="{width: item.width}"
></vxe-textarea>
</template>
<!-- 其他输入类型 -->
<template v-else>
<div class="input-wrapper">
<vxe-input
:type="item.type"
v-model="formData[getFieldKey(row.code, item.field)]"
size="mini"
class="table-input"
:style="{width: item.width}"
:disabled="!item.hasRight"
@blur="handleInputBlur(row.code, item.field, item.matchedFormula?.formula)"
/>
<span v-if="item.unit" class="unit"> {{ item.unit }}</span> <span v-if="item.unit" class="unit"> {{ item.unit }}</span>
</template>
<!-- 帮助图标 -->
<span
v-if="showHelpIcon(row.code, item.field, item)"
class="help-icon"
@click.stop="toggleTooltip(row.code, item.field)"
title="点击查看校验规则"
>
?
</span>
<!-- 错误图标 -->
<span
v-if="inputErrors[getFieldKey(row.code, item.field)]"
class="error-icon"
@click.stop="toggleErrorTooltip(row.code, item.field)"
title="点击查看错误详情"
>
</span>
<!-- 帮助提示 -->
<div
v-if="showTooltip && hoveredKey === getFieldKey(row.code, item.field)"
class="tooltip"
@click.stop
>
{{ item.matchedFormula?.des || '暂无校验规则' }}
</div>
<!-- 错误提示 -->
<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>
</template> </template>
</template>
</div> </div>
</template> </template>
</vxe-column> </vxe-column>
<vxe-column field="remarks" title="备注" width="200"> <vxe-column field="remarks" title="备注" width="200">
<template #default="{ row }"> <template #default="{ row }">
<vxe-textarea :rows="row.remarks.rows" v-model="formData[row.code+'_'+row.remarks.field]" style="height:100%;"> <vxe-textarea
</vxe-textarea> :rows="row.remarks.rows"
v-model="formData[getFieldKey(row.code, row.remarks.field)]"
style="height:100%;"
></vxe-textarea>
</template> </template>
</vxe-column> </vxe-column>
</vxe-table> </vxe-table>
...@@ -267,212 +336,295 @@ ...@@ -267,212 +336,295 @@
<script lang="ts" setup> <script lang="ts" setup>
import HistoryFillCheck from './check/historyFillCheck.vue' import HistoryFillCheck from './check/historyFillCheck.vue'
import { tableFormData } from '../../data/tb8.data'
import { tableFormData } from '../../data/tb8.data'; import { ref, reactive, nextTick, onMounted, computed } from 'vue'
import { ref, reactive,nextTick,onMounted,toRaw } from 'vue' import { VxeUI } from 'vxe-table'
import { VxeUI,VxeToolbarInstance,VxeToolbarPropTypes } from 'vxe-table' import { batchSaveOrUpdate, queryRecord, batchSaveOrUpdateBeforeDelete } from '../../record/BaosongTaskRecord.api'
import { batchSaveOrUpdate, queryRecord,batchSaveOrUpdateBeforeDelete } from '../../record/BaosongTaskRecord.api'
import { queryAllTplItemForUser, findUserRightForTplItem } from '../../alloc/BaosongTaskAlloc.api' import { queryAllTplItemForUser, findUserRightForTplItem } from '../../alloc/BaosongTaskAlloc.api'
import { allTplItems } from '../../tpl/BaosongTplItem.api' import { allTplItems } from '../../tpl/BaosongTplItem.api'
import { getTblvalidFormula } from '../../tpl/BaosongDataValid.api' import { getTblvalidFormula } from '../../tpl/BaosongDataValid.api'
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router'
const route = useRoute()
const tableRef = ref()
const tplItemMap = ref<Record<string, TplItemInfo>>({})
const historyFillCheckRef = ref<any>(null)
const route = useRoute(); // 查询参数
const tableRef = ref();
const tplItemMap = ref({});
const historyFillCheckRef = ref<any>(null);
const queryParam = ref({ const queryParam = ref({
taskId:-1, taskId: -1,
taskName:'', taskName: '',
tplId:-1, tplId: -1,
tplName:'', tplName: '',
tplCode:'' tplCode: ''
}) })
// 权限相关状态 // 状态变量
const loading = ref(false)
const formData = reactive<Record<string, any>>({})
const formValues = ref<FormData[]>([])
// 权限和验证相关
const userAllocItems = ref<string[]>([]) const userAllocItems = ref<string[]>([])
const validFormula = ref<any[]>([]) const validFormula = ref<FormulaItem[]>([])
const validationResultsList = ref<any[]>([]) const validationResultsList = ref<ValidationResult[]>([])
const drawerVisible = ref(false) const drawerVisible = ref(false)
const historyDrawerVisible = ref(false) const historyDrawerVisible = ref(false)
// 工具提示状态
const showTooltip = ref(false)
const hoveredKey = ref('')
const showErrorTooltip = ref(false)
const hoveredErrorKey = ref('')
const inputErrors = ref<Record<string, InputError>>({})
const isInitialized = ref(false)
// 验证公式提示
const validationTooltipVisible = ref(false) const validationTooltipVisible = ref(false)
const validationTooltipPosition = ref({ left: 0, top: 0 }) const validationTooltipPosition = ref({ left: 0, top: 0 })
const validationTooltipContent = ref('') const validationTooltipContent = ref('')
// 接口定义
interface FormData { interface FormData {
id: number | null id: number | null
taskid: number taskid: number
tplid: number tplid: number
itemid?: number itemid?: number
itempid?:number itempid?: number
content: string content: string
tplcode:string tplcode: string
rind:number rind: number
} }
onMounted(async ()=>{
if (route.query.taskId) {
queryParam.value.taskId = Number(route.query.taskId);
}
if (route.query.taskName) {
queryParam.value.taskName = String(route.query.taskName);
}
if (route.query.tplId) {
queryParam.value.tplId = Number(route.query.tplId);
}
if (route.query.tplName) {
queryParam.value.tplName = String(route.query.tplName);
}
if (route.query.tplCode) {
queryParam.value.tplCode = String(route.query.tplCode);
}
// 获取权限和验证公式
try {
userAllocItems.value = await findUserRightForTplItem({
tplid: queryParam.value.tplId,
taskid: queryParam.value.taskId
})
validFormula.value = await getTblvalidFormula({ interface TplItemInfo {
tplid: queryParam.value.tplId, pid: number
}) itemid: number
formTp: string
code: string
}
interface FormulaItem {
formula: string
des: string
[key: string]: any
}
interface InputError {
message: string
formula: string
error?: string
}
interface ValidationResult {
field: string
description: string
formula: string
isValid: boolean
fieldValue: any
rowCode: string
}
// 计算属性
const fieldKeys = computed(() => Object.keys(formData))
// 生命周期钩子
onMounted(async () => {
await initializePage()
})
// 初始化页面
const initializePage = async () => {
try {
await setQueryParams()
// 并行获取权限和验证公式
await Promise.all([
fetchUserRights(),
fetchValidationFormulas()
])
console.log('获取到的权限:', userAllocItems.value.length)
console.log('获取到的公式:', validFormula.value.length)
await setTplItemMap()
setFormItemRight()
await setData()
isInitialized.value = true
// 延迟刷新帮助图标
setTimeout(() => {
refreshHelpIcons()
}, 300)
} catch (error) { } catch (error) {
console.error('获取权限或验证公式失败:', error) console.error('初始化页面失败:', error)
showErrorMessage('初始化页面失败', error)
} }
}
await setTplItemMap() // 设置查询参数
await setData(); const setQueryParams = () => {
}) const params = route.query
if (params.taskId) queryParam.value.taskId = Number(params.taskId)
if (params.taskName) queryParam.value.taskName = String(params.taskName)
if (params.tplId) queryParam.value.tplId = Number(params.tplId)
if (params.tplName) queryParam.value.tplName = String(params.tplName)
if (params.tplCode) queryParam.value.tplCode = String(params.tplCode)
}
// 获取用户权限
const fetchUserRights = async () => {
userAllocItems.value = await findUserRightForTplItem({
tplid: queryParam.value.tplId,
taskid: queryParam.value.taskId
})
}
const loading = ref(false) // 获取验证公式
const formData = reactive({}); const fetchValidationFormulas = async () => {
const formValues = ref<FormData[]>([]) validFormula.value = await getTblvalidFormula({
tplid: queryParam.value.tplId,
})
}
// 保存批量数据
const saveBatch = async () => { const saveBatch = async () => {
try { try {
loading.value = true
await getFillDatas() await getFillDatas()
if(formValues.value.length > 0) {
if (formValues.value.length > 0) {
await batchSaveOrUpdateBeforeDelete(formValues.value) await batchSaveOrUpdateBeforeDelete(formValues.value)
VxeUI.modal.message({ content: '保存成功', status: 'success' }) VxeUI.modal.message({ content: '保存成功', status: 'success' })
} else { } else {
VxeUI.modal.message({ content: '没有需要保存的数据', status: 'warning' }) VxeUI.modal.message({ content: '没有需要保存的数据', status: 'warning' })
} }
} catch (error) { } catch (error) {
VxeUI.modal.message({ content: `保存失败: ${error.message}`, status: 'error' }) showErrorMessage('保存失败', error)
} finally { } finally {
loading.value = false loading.value = false
} }
} }
const getFillDatas = async() => { // 获取填充数据
const getFillDatas = async () => {
try { try {
formValues.value = [] formValues.value = []
for (const strKey in formData) { for (const strKey in formData) {
const valData = formData[strKey] const valData = formData[strKey]
if (valData!==undefined&&valData!=="") { if (valData !== undefined && valData !== "") {
let st = strKey.indexOf("_"); const st = strKey.indexOf("_")
let t1 = strKey.substring(0,st); const pcode = strKey.substring(0, st)
let t2 = strKey.substring(st+1); const field = strKey.substring(st + 1)
await setFormValues(t1,t2,valData,1) await setFormValues(pcode, field, valData, 1)
} }
} }
} catch (error) { } catch (error) {
console.log(error) console.error('获取填充数据失败:', error)
} finally { }
}
} }
// 设置表单值
const setFormValues = async (pcode,code,valData,rind) => { const setFormValues = async (pcode: string, code: string, valData: any, rind: number) => {
if(!valData) return; if (!valData) return
let vals = Array.isArray(valData) ? valData.join(',') : valData
let strKey = pcode+"_"+code const strKey = `${pcode}_${code}`
const item = tplItemMap.value[strKey]; const item = tplItemMap.value[strKey]
const { pid, itemid } = item ?? {};
if (!item) {
console.warn(`未找到对应的模板项: ${strKey}`)
return
}
let tempForm: FormData = { const vals = Array.isArray(valData) ? valData.join(',') : String(valData)
const tempForm: FormData = {
id: null, id: null,
rind:rind, rind,
taskid: queryParam.value.taskId, taskid: queryParam.value.taskId,
tplid: queryParam.value.tplId, tplid: queryParam.value.tplId,
tplcode: code, tplcode: code,
itemid: itemid, itemid: item.itemid,
itempid: pid, itempid: item.pid,
content:vals content: vals
}; }
formValues.value.push(tempForm) formValues.value.push(tempForm)
} }
async function setData() {
// 加载数据
const setData = async () => {
try { try {
loading.value = true; loading.value = true
const taskId = queryParam.value.taskId;
const tplid = queryParam.value.tplId;
Object.keys(formData).forEach(key => delete formData[key]); // 清空表单数据
Object.keys(formData).forEach(key => delete formData[key])
await setTplItemMap(); await setTplItemMap()
const recordData = await queryRecord({ taskid: taskId, tplid: tplid });
const valueObj = {}; // 查询记录数据
for (const data of recordData) { const recordData = await queryRecord({
const key = `${data.itempid}_${data.itemid}_${data.rind}`; taskid: queryParam.value.taskId,
valueObj[key] = data.content; tplid: queryParam.value.tplId
} })
for (const strKey of Object.keys(tplItemMap.value)) {
const item = tplItemMap.value[strKey]; // 构建数据映射
if (!item) continue; const valueObj: Record<string, string> = {}
recordData.forEach((data: any) => {
const { pid, itemid, formTp } = item; const key = `${data.itempid}_${data.itemid}_${data.rind}`
const dataVal = valueObj[`${pid}_${itemid}_1`]; valueObj[key] = data.content
})
if (!dataVal) continue;
// 设置表单数据
Object.keys(tplItemMap.value).forEach(strKey => {
const item = tplItemMap.value[strKey]
const { pid, itemid, formTp } = item
const dataKey = `${pid}_${itemid}_1`
const dataVal = valueObj[dataKey]
if (formTp === 'checkbox') { if (dataVal !== undefined) {
formData[strKey] = dataVal?.split(",") || []; if (formTp === 'checkbox') {
} else { formData[strKey] = dataVal.split(",") || []
formData[strKey] = dataVal || ""; } else {
formData[strKey] = dataVal || ""
}
} }
} })
} catch (error) { } catch (error) {
VxeUI.modal.message({ showErrorMessage('加载数据失败', error)
content: `加载数据失败: ${error.message}`,
status: 'error'
});
} finally { } finally {
loading.value = false; loading.value = false
} }
} }
// 设置模板项映射
async function setTplItemMap() { const setTplItemMap = async () => {
try { try {
const tplid = queryParam.value.tplId const tplItems = await allTplItems({
const tplItem = await allTplItems({ tplid: queryParam.value.tplId,
tplid: tplid,
}) })
tplItem.forEach(item => { const map: Record<string, TplItemInfo> = {}
let strKey = item.pcode + "_" + item.xmlcode; tplItems.forEach(item => {
tplItemMap.value[strKey] = {pid:item.pid,itemid:item.id,formTp:item.formTp,code:item.xmlcode}; const strKey = `${item.pcode}_${item.xmlcode}`
map[strKey] = {
pid: item.pid,
itemid: item.id,
formTp: item.formTp,
code: item.xmlcode
}
}) })
tplItemMap.value = map
} catch (error) { } catch (error) {
VxeUI.modal.message({ content: `加载数据失败`, status: 'error' }) showErrorMessage('加载模板项失败', error)
} finally {
} }
}
// 工具函数
const getFieldKey = (pcode: string | undefined, field: string): string => {
return pcode ? `${pcode}_${field}` : field
} }
// 校验数据 // 校验数据
...@@ -492,7 +644,7 @@ const performValidation = () => { ...@@ -492,7 +644,7 @@ const performValidation = () => {
process.push('开始校验') process.push('开始校验')
process.push(`找到 ${validFormula.value.length} 个验证公式`) process.push(`找到 ${validFormula.value.length} 个验证公式`)
validFormula.value.forEach((formulaItem: any) => { validFormula.value.forEach((formulaItem: FormulaItem) => {
process.push(`开始校验公式: ${formulaItem.des}`) process.push(`开始校验公式: ${formulaItem.des}`)
const result = evaluateFormula(formulaItem.formula, formulaItem.des, process) const result = evaluateFormula(formulaItem.formula, formulaItem.des, process)
if (result) { if (result) {
...@@ -503,7 +655,7 @@ const performValidation = () => { ...@@ -503,7 +655,7 @@ const performValidation = () => {
} }
// 解析和执行验证公式 // 解析和执行验证公式
const evaluateFormula = (formula: string, description: string, process: string[]): any => { const evaluateFormula = (formula: string, description: string, process: string[]): ValidationResult | null => {
try { try {
const fieldMatch = formula.match(/\[(\w+)\]/) const fieldMatch = formula.match(/\[(\w+)\]/)
if (!fieldMatch) { if (!fieldMatch) {
...@@ -524,11 +676,11 @@ const evaluateFormula = (formula: string, description: string, process: string[] ...@@ -524,11 +676,11 @@ const evaluateFormula = (formula: string, description: string, process: string[]
return null return null
} }
const strKey = `${row.code}_${fieldName}` const strKey = getFieldKey(row.code, fieldName)
const fieldValue = formData[strKey] const fieldValue = formData[strKey]
// 检查是否有空字段规则 // 检查是否有空字段规则
const emptyFieldRule = validFormula.value.find((f: any) => const emptyFieldRule = validFormula.value.find((f: FormulaItem) =>
f.formula.includes(fieldName) && f.des.includes('空字段') f.formula.includes(fieldName) && f.des.includes('空字段')
) )
...@@ -538,7 +690,7 @@ const evaluateFormula = (formula: string, description: string, process: string[] ...@@ -538,7 +690,7 @@ const evaluateFormula = (formula: string, description: string, process: string[]
} }
const expression = formula.replace(/\[(\w+)\]/g, (_, field) => { const expression = formula.replace(/\[(\w+)\]/g, (_, field) => {
const value = formData[`${row.code}_${field}`] const value = formData[getFieldKey(row.code, field)]
return value !== undefined ? `Number(${value})` : '0' return value !== undefined ? `Number(${value})` : '0'
}) })
...@@ -559,13 +711,24 @@ const evaluateFormula = (formula: string, description: string, process: string[] ...@@ -559,13 +711,24 @@ const evaluateFormula = (formula: string, description: string, process: string[]
} }
} }
// 处理校验结果点击,定位到表格 // 处理校验结果点击
const handleValidationResultClick = (result: any) => { const handleValidationResultClick = (result: ValidationResult) => {
const message = `字段 ${result.field} 的校验结果: ${result.isValid ? '通过' : '失败'}`
const status = result.isValid ? 'success' : 'error'
VxeUI.modal.message({ content: message, status })
// 滚动到对应字段
scrollToField(result)
}
// 滚动到字段位置
const scrollToField = (result: ValidationResult) => {
const row = tableFormData.find((r: any) => r.code === result.rowCode) const row = tableFormData.find((r: any) => r.code === result.rowCode)
if (row) { if (row) {
const fieldItem = row.content.find((c: any) => c.field === result.field) const fieldItem = row.content.find((c: any) => c.field === result.field)
if (fieldItem) { if (fieldItem) {
const strKey = `${row.code}_${result.field}` const strKey = getFieldKey(row.code, result.field)
const inputElement = document.querySelector(`[data-field="${strKey}"]`) as HTMLElement const inputElement = document.querySelector(`[data-field="${strKey}"]`) as HTMLElement
if (inputElement) { if (inputElement) {
inputElement.scrollIntoView({ behavior: 'smooth', block: 'center' }) inputElement.scrollIntoView({ behavior: 'smooth', block: 'center' })
...@@ -580,7 +743,7 @@ const handleValidationResultClick = (result: any) => { ...@@ -580,7 +743,7 @@ const handleValidationResultClick = (result: any) => {
} }
// 显示验证公式帮助 // 显示验证公式帮助
const showValidationHelp = (formulaItem: any, event: MouseEvent) => { const showValidationHelp = (formulaItem: FormulaItem, event: MouseEvent) => {
const rect = (event.target as HTMLElement).getBoundingClientRect() const rect = (event.target as HTMLElement).getBoundingClientRect()
validationTooltipPosition.value = { validationTooltipPosition.value = {
left: rect.left + rect.width / 2, left: rect.left + rect.width / 2,
...@@ -590,8 +753,12 @@ const showValidationHelp = (formulaItem: any, event: MouseEvent) => { ...@@ -590,8 +753,12 @@ const showValidationHelp = (formulaItem: any, event: MouseEvent) => {
validationTooltipVisible.value = true validationTooltipVisible.value = true
} }
// 关闭验证公式帮助 // 关闭所有提示
const closeTooltip = () => { const closeAllTooltips = () => {
showTooltip.value = false
hoveredKey.value = ''
showErrorTooltip.value = false
hoveredErrorKey.value = ''
validationTooltipVisible.value = false validationTooltipVisible.value = false
} }
...@@ -605,26 +772,228 @@ const closeHistoryDrawer = () => { ...@@ -605,26 +772,228 @@ const closeHistoryDrawer = () => {
historyDrawerVisible.value = false historyDrawerVisible.value = false
} }
// 显示帮助图标
const showHelpIcon = (rowCode: string, field: string, item: any): boolean => {
if (item.hasValidFormula !== undefined) {
return item.hasValidFormula === true
}
const key = getFieldKey(rowCode, field)
const hasRight = userAllocItems.value.includes(key)
if (!hasRight) return false
const formulaResult = findEarliestFormulaForField(validFormula.value, field)
return !!formulaResult.formula
}
// 设置表单项权限
const setFormItemRight = () => {
console.log('开始设置表单权限...')
console.log('userAllocItems 数量:', userAllocItems.value.length)
console.log('validFormula 数量:', validFormula.value.length)
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 formulaResult = findEarliestFormulaForField(validFormula.value, item.field)
item.hasValidFormula = !!formulaResult.formula
item.matchedFormula = formulaResult.formula || null
} else {
item.hasValidFormula = false
item.matchedFormula = null
}
}
})
}
})
console.log('表单权限设置完成')
}
// 查找字段对应的最早公式
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 refreshHelpIcons = () => {
console.log('刷新帮助图标...')
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)
const hasRight = userAllocItems.value.includes(key)
if (hasRight) {
const formulaResult = findEarliestFormulaForField(validFormula.value, item.field)
item.hasValidFormula = !!formulaResult.formula
item.matchedFormula = formulaResult.formula || null
} else {
item.hasValidFormula = false
item.matchedFormula = null
}
}
})
}
})
nextTick(() => {
console.log('帮助图标刷新完成')
})
}
// 输入框失去焦点处理
const handleInputBlur = (rowCode: string, field: string, formula?: string) => {
if (!formula) return
const key = getFieldKey(rowCode, field)
const value = formData[key]
if (!value || value === '') {
delete inputErrors.value[key]
return
}
validateFieldFormula(rowCode, field, formula)
}
// 验证字段公式
const validateFieldFormula = (rowCode: string, field: string, formula: string) => {
const key = getFieldKey(rowCode, field)
try {
const expression = buildExpression(formula, rowCode)
const isValid = eval(expression)
if (!isValid) {
inputErrors.value[key] = {
message: "公式校验失败,请检查填写内容",
formula
}
} else {
delete inputErrors.value[key]
}
} catch (error: any) {
inputErrors.value[key] = {
message: "公式校验失败,请检查填写内容",
formula,
error: error.message
}
}
}
// 构建表达式
const buildExpression = (formula: string, rowCode: string): string => {
const reservedWords = ['and', 'or', 'not', 'equal', 'less', 'greater', 'if', 'else', 'true', 'false']
// 提取字段名
const fieldNames = formula.match(/\b[A-Za-z][A-Za-z0-9_]*\b/g) || []
const uniqueFields = [...new Set(fieldNames.filter(f =>
!reservedWords.includes(f.toLowerCase())
))]
// 按长度降序排序,避免替换时出现部分匹配
uniqueFields.sort((a, b) => b.length - a.length)
let expression = formula
for (const fieldName of uniqueFields) {
const key = getFieldKey(rowCode, fieldName)
const value = formData[key]
if (value !== undefined && value !== '') {
expression = expression.replace(
new RegExp(`\\b${fieldName}\\b`, 'g'),
`Number(${value})`
)
}
}
return expression
}
// 工具提示控制
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
}
}
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 showErrorMessage = (title: string, error: any) => {
const message = error instanceof Error ? error.message : String(error)
VxeUI.modal.message({
content: `${title}: ${message}`,
status: 'error'
})
}
</script> </script>
<style lang="less" scoped>
/* 基础字体和排版 */ <style lang="less" scoped>
.bank-report-table { .bank-report-table {
font-family: "SimSun", "宋体", serif; font-family: "SimSun", "宋体", serif;
font-size: 12px; font-size: 12px;
color: #000; color: #000;
margin: 5px auto; margin: 5px auto;
width: 90%; /* 统一使用一个宽度 */ width: 90%;
height:80vh height: 80vh;
} position: relative;
}
/* 表格样式 */
.custom-table, .attachment-table { /* 表格样式 */
width: 100%; .custom-table {
width: 100%;
border: 1px solid #000; border: 1px solid #000;
border-collapse: collapse; /* 统一边框处理 */ border-collapse: collapse;
.vxe-header--column,
.vxe-body--column {
border-right: 1px solid #000;
border-bottom: 1px solid #000;
padding: 5px;
}
} }
/* 加载遮罩层样式 */ /* 加载遮罩层 */
.loading-overlay { .loading-overlay {
position: absolute; position: absolute;
top: 0; top: 0;
...@@ -650,7 +1019,7 @@ const closeHistoryDrawer = () => { ...@@ -650,7 +1019,7 @@ const closeHistoryDrawer = () => {
border: 3px solid #f3f3f3; border: 3px solid #f3f3f3;
border-top: 3px solid #3498db; border-top: 3px solid #3498db;
border-radius: 50%; border-radius: 50%;
animation: spin 2s linear infinite; animation: spin 1s linear infinite;
} }
@keyframes spin { @keyframes spin {
...@@ -713,20 +1082,20 @@ const closeHistoryDrawer = () => { ...@@ -713,20 +1082,20 @@ const closeHistoryDrawer = () => {
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
transition: background-color 0.2s; transition: background-color 0.2s;
}
&:hover {
.result-item:hover { background-color: #f5f5f5;
background-color: #f5f5f5; }
}
&.success {
.result-item.success { background-color: #f6ffed;
background-color: #f6ffed; border-left: 4px solid #52c41a;
border-left: 4px solid #52c41a; }
}
&.error {
.result-item.error { background-color: #fff2f0;
background-color: #fff2f0; border-left: 4px solid #ff4d4f;
border-left: 4px solid #ff4d4f; }
} }
.result-field { .result-field {
...@@ -768,99 +1137,168 @@ const closeHistoryDrawer = () => { ...@@ -768,99 +1137,168 @@ const closeHistoryDrawer = () => {
white-space: pre-wrap; white-space: pre-wrap;
} }
/* 表格单元格样式 */ /* 内容单元格 */
.custom-table .vxe-header--column, .content-cell {
.custom-table .vxe-body--column, line-height: 1.8;
.attachment-table .vxe-header--column, }
.attachment-table .vxe-body--column {
border-right: 1px solid #000; /* 输入框包装器 */
border-bottom: 1px solid #000; .input-wrapper {
padding: 5px; position: relative;
} display: inline-block;
}
/* 内容单元格 */
.content-cell { /* 输入框样式 */
line-height: 1.8; .table-input,
} .vxe-input {
height: 24px;
/* 输入框样式 */ line-height: 24px;
.table-input, min-width: 150px;
.vxe-input { margin: 0 2px;
height: 24px; padding: 0 5px;
line-height: 30px; border: 1px solid #d9d9d9;
min-width: 150px; border-radius: 2px;
margin: 0 2px; background: #fff;
padding: 0 5px; text-align: left;
border: none; /* 去掉多余的边框,只留底部边框 */
border-bottom: 1px solid #333; &:disabled {
background: transparent; background-color: #f5f5f5;
text-align: center; cursor: not-allowed;
} }
}
/* 表单元素的标签和图标 */
.vxe-radio--label, /* 表单组件样式 */
.vxe-checkbox--label { .vxe-radio-group,
font-size: 12px; .vxe-checkbox-group {
} display: inline-flex;
flex-wrap: wrap;
.vxe-radio--icon, gap: 8px;
.vxe-checkbox--icon { margin-right: 5px;
font-size: 12px; max-width: 100%;
} }
/* 单选框组和复选框组布局 */ .vxe-radio,
.vxe-radio-group, .vxe-checkbox {
.vxe-checkbox-group { margin: 2px 5px;
display: inline-block; white-space: nowrap;
margin-right: 5px; }
max-width: 99%;
}
/* 其他辅助样式 */
.radio-group, .radio-group,
.checkbox-group { .checkbox-group {
display: inline-block; display: inline-block;
margin-right: 5px; margin-right: 5px;
max-width: 99%; max-width: 99%;
} }
.vxe-radio,
.vxe-checkbox {
margin: 5px 5px 5px 30px;
white-space: nowrap;
}
/* 附件部分样式 */ /* 单位样式 */
.attachments { .unit {
margin-top: 20px; margin-left: 4px;
width: 100%; color: #666;
} font-size: 12px;
}
.attachments h4 { /* 图标样式 */
font-size: 14px; .help-icon {
font-weight: bold; margin-left: 5px;
margin-bottom: 10px; cursor: pointer;
} color: #1890ff;
font-weight: bold;
font-size: 14px;
display: inline-flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
line-height: 20px;
background: #e6f7ff;
border-radius: 50%;
transition: all 0.3s;
opacity: 0;
animation: fadeIn 0.5s forwards;
animation-delay: 0.3s;
&:hover {
background: #bae7ff;
transform: scale(1.1);
}
}
.attachment-table { .error-icon {
width: 100%; margin-left: 5px;
border: 1px solid #000; cursor: pointer;
border-collapse: collapse; /* 统一边框处理 */ color: #ff4d4f;
} font-size: 16px;
display: inline-flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
line-height: 20px;
transition: all 0.3s;
&:hover {
transform: scale(1.1);
}
}
/* 无用或重复定义已优化移除 */ @keyframes fadeIn {
from {
opacity: 0;
transform: scale(0.8);
}
to {
opacity: 1;
transform: scale(1);
}
}
/* 其他特殊块 */ /* 提示框样式 */
blockquote { .tooltip, .error-tooltip {
padding: 0 5px; position: absolute;
color: black; top: 100%;
cursor: pointer; 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);
}
</style> .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: 10px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #8b0000 transparent;
}
}
<style scoped> /* 额外字段样式 */
.extra-fields-container { .extra-fields-container {
margin-left: 40px; margin-left: 40px;
margin-top: 8px; margin-top: 8px;
...@@ -883,8 +1321,15 @@ blockquote { ...@@ -883,8 +1321,15 @@ blockquote {
margin-top: 8px; margin-top: 8px;
} }
.unit { /* 响应式调整 */
margin-left: 8px; @media (max-width: 1200px) {
color: #888; .bank-report-table {
width: 95%;
}
.table-input,
.vxe-input {
min-width: 120px;
}
} }
</style> </style>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论