|
|
@@ -69,7 +69,10 @@
|
|
|
<el-card class="box-card" v-show="editShow" style="width: 320px">
|
|
|
<div slot="header" class="clearfix">
|
|
|
<span>配置</span>
|
|
|
- <el-button style="float: right; padding: 3px 0" type="text" @click="editShow = false"
|
|
|
+ <el-button
|
|
|
+ style="float: right; padding: 3px 0"
|
|
|
+ type="text"
|
|
|
+ @click="editShow = false"
|
|
|
>关闭</el-button
|
|
|
>
|
|
|
</div>
|
|
|
@@ -180,6 +183,22 @@
|
|
|
<el-option key="append" label="追加" value="append" />
|
|
|
<el-option key="replace" label="替换" value="replace" />
|
|
|
</el-select>
|
|
|
+ <el-input
|
|
|
+ v-model.number="domObj.units.decimalPlace"
|
|
|
+ placeholder="小数位"
|
|
|
+ size="mini"
|
|
|
+ style="width: 120px; margin-left: 8px; flex-shrink: 0"
|
|
|
+ >
|
|
|
+ </el-input>
|
|
|
+ <el-select
|
|
|
+ v-model="domObj.units.takeValueMethod"
|
|
|
+ placeholder="取值方法"
|
|
|
+ size="mini"
|
|
|
+ style="width: 100px; margin-left: 8px; flex-shrink: 0"
|
|
|
+ >
|
|
|
+ <el-option key="1" label="四舍五入" value="1" />
|
|
|
+ <el-option key="2" label="去尾" value="2" />
|
|
|
+ </el-select>
|
|
|
</div>
|
|
|
|
|
|
<!-- 已组装公式标签展示 -->
|
|
|
@@ -247,7 +266,7 @@
|
|
|
editShow: false,
|
|
|
visible: false,
|
|
|
templateDivRef: '',
|
|
|
- domObj: {},
|
|
|
+ domObj: { units: {} },
|
|
|
idList: [],
|
|
|
opSelectOptions: ['+', '-', '*', '/', '%', '(', ')'],
|
|
|
equationUnit: {
|
|
|
@@ -267,6 +286,7 @@
|
|
|
calculation() {
|
|
|
this.getValue();
|
|
|
let equation = [];
|
|
|
+
|
|
|
this.list.forEach((item) => {
|
|
|
equation.push({
|
|
|
id: item.id,
|
|
|
@@ -275,32 +295,58 @@
|
|
|
});
|
|
|
equation.forEach((item) => {
|
|
|
for (const key in item.equation) {
|
|
|
- let data = this.getObjValue(); //每次计算都获取最新的值
|
|
|
+ let { data, units } = this.getObjValue(); //每次计算都获取最新的值
|
|
|
let value = '';
|
|
|
if (item.equation[key].length) {
|
|
|
item.equation[key].forEach((equationItem) => {
|
|
|
- if (equationItem.type == 'symbol') {
|
|
|
+ if (
|
|
|
+ equationItem.type == 'symbol' ||
|
|
|
+ equationItem.type == 'value'
|
|
|
+ ) {
|
|
|
value += equationItem.value;
|
|
|
} else if (equationItem.type == 'id') {
|
|
|
value += Number(data[equationItem.value]) || 0;
|
|
|
- } else {
|
|
|
- value += equationItem.value;
|
|
|
}
|
|
|
});
|
|
|
+ if (units[key]?.decimalPlace) {
|
|
|
+ if (units[key]?.takeValueMethod) {
|
|
|
+ value =
|
|
|
+ units[key]?.takeValueMethod == 1
|
|
|
+ ? parseFloat(eval(value).toFixed(units[key].decimalPlace))
|
|
|
+ : this.truncateToFixedManual(
|
|
|
+ eval(value),
|
|
|
+ units[key].decimalPlace
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ value = parseFloat(
|
|
|
+ eval(value).toFixed(units[key].decimalPlace)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ value = parseFloat(eval(value).toFixed(2));
|
|
|
+ }
|
|
|
if (this.$refs['customTextRef' + item.id][0]) {
|
|
|
this.$refs['customTextRef' + item.id][0].equationValue({
|
|
|
domId: key,
|
|
|
- value: eval(value)
|
|
|
+ value
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
+ truncateToFixedManual(num, decimalPlaces) {
|
|
|
+ let factor = Math.pow(10, decimalPlaces);
|
|
|
+ return Math.floor(num * factor) / factor;
|
|
|
+ },
|
|
|
getObjValue() {
|
|
|
this.getValue();
|
|
|
let data = {};
|
|
|
+ let units = {};
|
|
|
this.list.forEach((item) => {
|
|
|
+ units = { ...item.units, ...units };
|
|
|
+
|
|
|
if (item.type == 'customText') {
|
|
|
data = { ...item.valueObj, ...data };
|
|
|
} else {
|
|
|
@@ -311,7 +357,7 @@
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
- return data || {};
|
|
|
+ return { data: data || {}, units: units || {} };
|
|
|
},
|
|
|
|
|
|
setEquation() {
|
|
|
@@ -414,7 +460,8 @@
|
|
|
this.$refs['customTextRef' + item.id][0].init({
|
|
|
form: item.value,
|
|
|
valueObj: item.valueObj,
|
|
|
- equation: item.equation
|
|
|
+ equation: item.equation,
|
|
|
+ units: item.units
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
@@ -449,11 +496,12 @@
|
|
|
},
|
|
|
getValue() {
|
|
|
this.list.forEach((item, index) => {
|
|
|
- let { form, valueObj, equation } =
|
|
|
+ let { form, valueObj, equation, units } =
|
|
|
this.$refs['customTextRef' + item.id][0].getValue();
|
|
|
this.$set(this.list[index], 'value', form);
|
|
|
this.$set(this.list[index], 'valueObj', valueObj);
|
|
|
this.$set(this.list[index], 'equation', equation);
|
|
|
+ this.$set(this.list[index], 'units', units);
|
|
|
});
|
|
|
return this.list;
|
|
|
}
|