Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
csbr-daop
/
fe-data-trusted-space
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
2e461c2c
authored
2025-07-29 10:09:36 +0800
by
lxs
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
数据定价计算方式更新
1 parent
c0101796
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
28 deletions
src/views/data_pricing/calculateConfig.vue
src/views/data_pricing/calculateConfig.vue
View file @
2e461c2
...
...
@@ -600,7 +600,7 @@ const setTableRowData = (dGuid, rIndex) => {
rowData
.
dataFields
.
map
(
t
=>
{
t
.
damFieldTable
=
JSON
.
parse
(
JSON
.
stringify
(
damFieldOptions
));
const
match
=
damFieldOptions
.
find
(
d
=>
d
.
chName
==
t
.
fieldName
);
if
(
match
)
{
if
(
match
)
{
t
.
chName
=
match
.
chName
;
t
.
enName
=
match
.
enName
;
}
...
...
@@ -856,17 +856,13 @@ const calculatePrice = (pData) => {
// 3. 提取变量名
const
variableRegex
=
/
[\u
4e00-
\u
9fa5a-zA-Z_
][\u
4e00-
\u
9fa5a-zA-Z0-9_
]
*/g
;
const
variableNames
=
modelFormula
.
match
(
variableRegex
)
||
[];
const
uniqueVariables
=
[...
new
Set
(
variableNames
)];
const
variableNames
=
[...
new
Set
(
modelFormula
.
match
(
variableRegex
)
||
[])];
// 4. 构建变量映射
const
variables
=
{};
uniqueVariables
.
forEach
(
name
=>
{
// 过滤数学函数
if
(
!
mathFunctions
.
includes
(
name
))
{
const
dim
=
pData
.
find
(
d
=>
d
.
dimensionalityName
===
name
);
variables
[
name
]
=
dim
?
parseFloat
(
dim
.
sNum
)
||
0
:
0
;
}
variableNames
.
forEach
(
name
=>
{
const
dim
=
pData
.
find
(
d
=>
d
.
dimensionalityName
===
name
);
variables
[
name
]
=
dim
?
parseFloat
(
dim
.
sNum
)
||
0
:
0
;
});
// 5. 替换变量为数值(考虑边界情况)
...
...
@@ -875,35 +871,38 @@ const calculatePrice = (pData) => {
expression
=
expression
.
replace
(
new
RegExp
(
name
,
'g'
),
variables
[
name
]);
});
// 7. 表达式安全检查
// 7.1 检查是否只包含允许的字符
const
sanitizedExpr
=
expression
.
replace
(
allowedOperators
,
''
);
if
(
sanitizedExpr
.
length
>
0
)
{
console
.
error
(
'公式包含非法字符:'
,
sanitizedExpr
);
// 6. 表达式规范化(不丢失括号)
expression
=
expression
.
replace
(
/
\s
+/g
,
''
)
// 去空格
.
replace
(
/
\^
/g
,
'**'
)
// 幂运算转换
.
replace
(
/"|'/g
,
''
)
// 去引号(不破坏括号)
.
replace
(
/
(\d)\(
/g
,
'$1*('
)
// 处理隐式乘法
.
replace
(
/
\)\(
/g
,
')*('
);
// 括号间乘法
// 7. 验证括号配对
const
balance
=
expression
.
split
(
''
).
reduce
((
acc
,
char
)
=>
{
if
(
char
===
'('
)
acc
++
;
if
(
char
===
')'
)
acc
--
;
return
acc
;
},
0
);
if
(
balance
!==
0
)
{
console
.
error
(
'括号不匹配'
);
return
NaN
;
}
// 8. 执行计算
try
{
// 8.1 转换运算符
expression
=
expression
.
replace
(
/
\s
+/g
,
''
)
// 去除空格
.
replace
(
/
\^
/g
,
'**'
)
// 转换幂运算
.
replace
(
/÷/g
,
'/'
)
// 转换除法符号
.
replace
(
/×/g
,
'*'
)
// 转换乘法符号
.
replace
(
/
(\d
+
)\(
/g
,
'$1*('
)
// 处理隐式乘法
.
replace
(
/
\)\(
/g
,
')*('
);
// 处理括号间乘法
// 8.2 安全计算
// 8. 安全计算
try
{
const
result
=
new
Function
(
'return '
+
expression
)();
const
roundedResult
=
Math
.
round
(
parseFloat
(
result
)
*
100
)
/
100
;
dataTransactionPrice
.
value
=
roundedResult
.
toFixed
(
2
);
return
roundedResult
;
}
catch
(
error
)
{
console
.
error
(
'
公式
计算错误:'
,
{
console
.
error
(
'计算错误:'
,
{
error
,
original
Formula
:
modelFormula
,
processed
Formula
:
expression
original
:
modelFormula
,
processed
:
expression
});
return
NaN
;
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment