fix: formula calc
Some checks failed
Synchronize to Gitee / repo-sync (push) Has been cancelled
Typos Checking / Spell Check with Typos (push) Has been cancelled

This commit is contained in:
xinxin.wu
2025-12-10 19:06:43 +08:00
committed by zhao
parent ad78f79216
commit 79f0eed414
5 changed files with 45 additions and 25 deletions

View File

@@ -104,6 +104,23 @@
}
}
function normalizeNumber(val: any): number | null {
if (val === null || val === undefined || val === '') return null;
// 已经是 number 直接返回
if (typeof val === 'number') return val;
let str = String(val).trim();
// 是否是百分比格式(可能带千分位)
if (str.endsWith('%')) {
str = str.slice(0, -1); // 去掉 %
}
// 去除千分位 ","
str = str.replace(/,/g, '');
// 转数字
const num = Number(str);
if (Number.isNaN(num)) return null;
return num;
}
function getFieldValue(fieldId: string) {
// 父级字段
if (!props.isSubTableRender) {
@@ -112,24 +129,12 @@
const pathMatch = props.path.match(/^([^[]+)\[(\d+)\]\.(.+)$/);
if (pathMatch) {
const [, tableKey, rowIndexStr, currentFieldId] = pathMatch;
const [, tableKey, rowIndexStr] = pathMatch;
const rowIndex = parseInt(rowIndexStr, 10);
if (fieldId === currentFieldId) {
const row = props.formDetail?.[tableKey]?.[rowIndex];
return row?.[fieldId];
}
const row = props.formDetail?.[tableKey]?.[rowIndex];
return row?.[fieldId];
const rawValue = row?.[fieldId];
return normalizeNumber(rawValue);
}
const paths = props.path.split('.');
const tableKey = paths[0];
const rowIndex = Number(paths[1]);
const row = props.formDetail?.[tableKey]?.[rowIndex];
return row?.[fieldId];
}
function safeParseFormula(formulaString: string) {

View File

@@ -580,7 +580,7 @@ export const priceTableDefaultFieldConfig: FormCreateField = {
id: '',
type: FieldTypeEnum.SUB_PRICE,
icon: 'iconicon_table',
name: 'crmFormDesign.priceTable',
name: 'crmFormDesign.quotationTable',
fieldWidth: 1,
showLabel: true,
description: '',

View File

@@ -205,7 +205,7 @@ export default {
'crmFormDesign.tip.PLAN_TO_RECORD':
'When performing plan to record operations, fill the plan form field content into the record form fields',
'crmFormDesign.productTable': 'Product Table',
'crmFormDesign.priceTable': 'Price Table',
'crmFormDesign.quotationTable': 'Quotation Table',
'crmFormDesign.sum': 'Sum',
'crmFormDesign.fixedCol': 'Fixed Column',
'crmFormDesign.fixedColNum': 'Fixed',

View File

@@ -196,7 +196,7 @@ export default {
'crmFormDesign.tip.OPPORTUNITY_TO_RECORD': '在商机模块写跟进记录时,将商机的表单字段内容填充到记录表单字段',
'crmFormDesign.tip.PLAN_TO_RECORD': '在进行计划转记录操作时,将计划的表单字段内容填充到记录表单字段',
'crmFormDesign.productTable': '产品表格',
'crmFormDesign.priceTable': '价表格',
'crmFormDesign.quotationTable': '价表格',
'crmFormDesign.sum': '汇总',
'crmFormDesign.fixedCol': '固定列',
'crmFormDesign.fixedColNum': '固定前',

View File

@@ -26,7 +26,7 @@
</div>
<n-scrollbar class="my-[4px] max-h-[416px] px-[4px]">
<div v-if="layoutType === 'columnHeaderSet'">
<div class="mb-[4px] flex h-[24px] items-center justify-between text-[12px]">
<div class="mb-[4px] flex h-[24px] items-center justify-between pr-[8px] text-[12px]">
<div class="one-line-text font-medium text-[var(--text-n1)]">
{{ t('crmTable.columnSetting.tableHeaderDisplaySettings') }}
</div>
@@ -34,7 +34,11 @@
{{ t('crmTable.columnSetting.resetDefault') }}
</n-button>
</div>
<div v-for="element in notAllowSortCachedColumns" :key="element.key" class="crm-table-column-setting-item">
<div
v-for="element in notAllowSortCachedColumns"
:key="element.key"
class="crm-table-column-setting-item pr-[8px]"
>
<div class="flex flex-1 items-center gap-[8px] overflow-hidden">
<CrmIcon type="iconicon_move" class="cursor-not-allowed text-[var(--text-n6)]" :size="12" />
<CrmIcon
@@ -44,9 +48,14 @@
}`"
:size="12"
/>
<span class="one-line-text ml-[8px] text-[12px]">
<n-tooltip trigger="hover" placement="top">
<template #trigger>
<span class="one-line-text ml-[8px] text-[12px]">
{{ t(element.title as string) }}
</span>
</template>
{{ t(element.title as string) }}
</span>
</n-tooltip>
</div>
<n-switch
v-model:value="element.showInTable"
@@ -75,9 +84,14 @@
:size="12"
@click="toggleFixedColumn(element)"
/>
<span class="one-line-text ml-[8px] text-[12px]">
<n-tooltip trigger="hover" placement="top">
<template #trigger>
<span class="one-line-text ml-[8px] text-[12px]">
{{ t(element.title as string) }}
</span>
</template>
{{ t(element.title as string) }}
</span>
</n-tooltip>
</div>
<n-switch
v-model:value="element.showInTable"
@@ -129,7 +143,7 @@
</template>
<script setup lang="ts">
import { NButton, NPopover, NRadioButton, NRadioGroup, NScrollbar, NSkeleton, NSwitch } from 'naive-ui';
import { NButton, NPopover, NRadioButton, NRadioGroup, NScrollbar, NSkeleton, NSwitch, NTooltip } from 'naive-ui';
import { VueDraggable } from 'vue-draggable-plus';
import { SpecialColumnEnum, TableKeyEnum } from '@lib/shared/enums/tableEnum';
@@ -242,6 +256,7 @@
padding: 0 !important;
.crm-table-column-setting-item {
padding: 5px 8px;
max-width: 300px;
border-radius: @border-radius-small;
@apply flex items-center justify-between;
&:hover {