From fa5aee05d219940576c11a38ed3da135268c13b6 Mon Sep 17 00:00:00 2001
From: licp <lichunping@guanfang.com.cn>
Date: 星期三, 26 六月 2024 17:39:50 +0800
Subject: [PATCH] 完成公式计算
---
src/main.js | 8
src/util/eccelFounctionList.js | 1
src/components/do/b1-inspect-order-plan/Inspection.vue | 261 ++++++++++----------------------
src/util/excelFountion.js | 167 +++++++++++++++-----
4 files changed, 206 insertions(+), 231 deletions(-)
diff --git a/src/components/do/b1-inspect-order-plan/Inspection.vue b/src/components/do/b1-inspect-order-plan/Inspection.vue
index 629895c..3a03d0d 100644
--- a/src/components/do/b1-inspect-order-plan/Inspection.vue
+++ b/src/components/do/b1-inspect-order-plan/Inspection.vue
@@ -482,7 +482,7 @@
<script>
import ValueTable from '../../tool/value-table.vue'
import file from '../../../util/file'
- import excelFountion from '../../../util/excelFountion'
+ import excelFunction from '../../../util/excelFountion'
export default {
props: ['sonLaboratory', 'orderId', 'state'],
components: {
@@ -627,7 +627,7 @@
this.componentData.entity.sonLaboratory = this.sonLaboratory;
this.id = this.orderId;
this.getUserInfo()
- // excelFountion.handel('SUM(MAX(SUM(A1,B1,C1),2,3)*2-MIN(A1:D3),1,2)')
+ // excelFunction.compute('SUM(MAX(SUM(A1,B1,C1),2,3)*2-MIN(A1:D3),1,2)')
},
mounted() {
this.getTypeDicts()
@@ -1198,7 +1198,7 @@
}
})
})
- if (item.methodName == '鑷畾涔夋柟娉�' && item.v.ps != undefined && item.v.ps.value == '缁撹') {
+ if (item.v.ps != undefined && item.v.ps.value == '缁撹') {
if (this.currentSample.insProduct.find(m => m.id == item.i)) {
let ask = this.currentSample.insProduct.find(m => m.id == item.i).ask?this.currentSample.insProduct.find(m => m.id == item.i).ask.split('&'):null;
let res = Object.values(comValue)[0]
@@ -1237,87 +1237,86 @@
} else {
item.v.v = 0
}
- console.log(this.param)
this.saveInsContext()
}
} else {
- let comResult = 0;
- switch (item.methodName) {
- case 'AVERAGE':
- let num = 0
- for (var a in comValue) {
- num += comValue[a]
- }
- comResult = num / Object.keys(comValue).length
- break;
- case 'SUM':
- let sum = 0
- for (var a in comValue) {
- sum += comValue[a]
- }
- comResult = sum
- break;
- case 'MEDIAN':
- let arr = []
- for (var a in comValue) {
- arr.push(comValue[a])
- }
- comResult = this.median(arr)
- break;
- case 'APS':
- let arr0 = []
- for (var a in comValue) {
- arr0.push(comValue[a])
- }
- comResult = Math.abs(arr0[0])
- break;
- // case 'MAX':
- // let arr1 = []
- // for (var a in comValue) {
- // arr1.push(eval(comValue[a]))
- // }
- // comResult = Math.max(...arr1)
- // break;
- // case 'MIN':
- // let arr2 = []
- // for (var a in comValue) {
- // arr2.push(eval(comValue[a]))
- // }
- // comResult = Math.median(...arr2)
- // break;
- default:
- let valueList = [];
- item.valueList.forEach(a => {
- valueList.push({
- name: `${this.comparisonList.find(e=>e.value==a.c).label}${a.r+1}`,
- value: 0,
- })
- })
- for (var a in comValue) {
- valueList.forEach(b => {
- if (b.name == a) {
- b.value = comValue[a]
- }
- })
- }
- let str = item.v.f.replace(/=/g, ' ');
- valueList.forEach(b => {
- str = str.replace(b.name, b.value)
- })
- str = str.replaceAll('MAX', 'Math.max')
- str = str.replaceAll('MIN', 'Math.min')
- str = str.replaceAll('锛�', ',')
- try {
- if(this.getInspectionValueType(item.i)==1){
- comResult = eval(str)
- }else{
- comResult = str
- }
- } catch (error) {
+ let comResult = excelFunction.compute(item.v.f.replace(/=/g, ' '),comValue);
+ // switch (item.methodName) {
+ // case 'AVERAGE':
+ // let num = 0
+ // for (var a in comValue) {
+ // num += comValue[a]
+ // }
+ // comResult = num / Object.keys(comValue).length
+ // break;
+ // case 'SUM':
+ // let sum = 0
+ // for (var a in comValue) {
+ // sum += comValue[a]
+ // }
+ // comResult = sum
+ // break;
+ // case 'MEDIAN':
+ // let arr = []
+ // for (var a in comValue) {
+ // arr.push(comValue[a])
+ // }
+ // comResult = this.median(arr)
+ // break;
+ // case 'APS':
+ // let arr0 = []
+ // for (var a in comValue) {
+ // arr0.push(comValue[a])
+ // }
+ // comResult = Math.abs(arr0[0])
+ // break;
+ // // case 'MAX':
+ // // let arr1 = []
+ // // for (var a in comValue) {
+ // // arr1.push(eval(comValue[a]))
+ // // }
+ // // comResult = Math.max(...arr1)
+ // // break;
+ // // case 'MIN':
+ // // let arr2 = []
+ // // for (var a in comValue) {
+ // // arr2.push(eval(comValue[a]))
+ // // }
+ // // comResult = Math.median(...arr2)
+ // // break;
+ // default:
+ // let valueList = [];
+ // item.valueList.forEach(a => {
+ // valueList.push({
+ // name: `${this.comparisonList.find(e=>e.value==a.c).label}${a.r+1}`,
+ // value: 0,
+ // })
+ // })
+ // for (var a in comValue) {
+ // valueList.forEach(b => {
+ // if (b.name == a) {
+ // b.value = comValue[a]
+ // }
+ // })
+ // }
+ // let str = item.v.f.replace(/=/g, ' ');
+ // valueList.forEach(b => {
+ // str = str.replace(b.name, b.value)
+ // })
+ // str = str.replaceAll('MAX', 'Math.max')
+ // str = str.replaceAll('MIN', 'Math.min')
+ // str = str.replaceAll('锛�', ',')
+ // try {
+ // if(this.getInspectionValueType(item.i)==1){
+ // comResult = eval(str)
+ // }else{
+ // comResult = str
+ // }
+ // } catch (error) {
- }
- break;
- }
+ // }
+ // break;
+ // }
list.forEach(a => {
if (a[0].r == item.r && comResult != '') {
for (var b in a) {
@@ -1407,107 +1406,7 @@
handleExcelMethod() {
if (this.excelMethodList.length > 0) {
this.excelMethodList.map(item => {
- item.methodName = item.v.f.split('=').length > 1 && item.v.f.split('=')[1].split('(') && item.v.f.split(
- '=')[1].split('(')[0] ? item.v.f.split('=')[1].split('(')[0] : '鑷畾涔夋柟娉�';
- let valueList = [];
- if(item.v.f.includes('MAX') || item.v.f.includes('MIN')){
- item.methodName = '鑷畾涔夋柟娉�'
- let regex = /[=\+\-\*\%\/\^\s]/g
- let mode = item.v.f.replace(regex, ' ').split(' ');
- let that = this
- if(item.v.f.includes('MAX')){
- item.v.f = Judgment(item.v.f, 'MAX')
- }
- if(item.v.f.includes('MIN')){
- item.v.f = Judgment(item.v.f, 'MIN')
- }
- function Judgment(f,type) {
- let newF = f
- let mode4 = mode.filter(m => m&&m.includes(type))
- mode4.forEach(m => {
- let mode0 = m
- if(mode0.includes(':')){
- let r0 = null;
- let c0 = null;
- let r1 = null;
- let c1 = null;
- let mode1 = mode0.split('(')[1].split(')')[0];
- let start = mode1.split(':')[0]
- let end = mode1.split(':')[1]
- c0 = that.comparisonList.find(j => j.label == start.split('')[0]).value
- r0 = start.replace(/[a-zA-Z]/g, "") - 1
- c1 = that.comparisonList.find(j => j.label == end.split('')[0]).value
- r1 = end.replace(/[a-zA-Z]/g, "") - 1
- let valueList0 = []
- for (let i = Number(r0); i <= Number(r1); i++) {
- for (let u = Number(c0); u <= Number(c1); u++) {
- valueList0.push({
- r: i,
- c: u
- })
- }
- }
- let valueList1 = []
- valueList0.forEach(v => {
- let r = '';
- let c = '';
- r = v.r +1;
- c = that.comparisonList.find(j => j.value == v.c).label
- valueList1.push(c+r)
- })
- let mode3 = type+'('+valueList1.join(',')+')'
- newF = newF.replace(mode0, mode3)
- valueList = [...valueList,...valueList0]
- }else{
- let mode1 = mode0.replace(type, '').replace(/[=\+\-\*\%\(\)\/\^\s]/g, '');
- let modeList = mode1.split(',');
- modeList.filter(m => m && !Number(m)).forEach(m => {
- let r = m.replace(/[a-zA-Z]/g, "") - 1
- let c = that.comparisonList.find(j => j.label == m.split('')[0]).value
- valueList.push({
- c,
- r
- })
- })
- }
- })
- return newF
- }
- }else if (item.v.f.includes(':')) {
- valueList = [];
- let r0 = null;
- let c0 = null;
- let r1 = null;
- let c1 = null;
- let mode = item.v.f.split('(')[1].split(')')[0];
- let start = mode.split(':')[0]
- let end = mode.split(':')[1]
- c0 = this.comparisonList.find(j => j.label == start.split('')[0]).value
- r0 = start.replace(/[a-zA-Z]/g, "") - 1
- c1 = this.comparisonList.find(j => j.label == end.split('')[0]).value
- r1 = end.replace(/[a-zA-Z]/g, "") - 1
- for (let i = Number(r0); i <= Number(r1); i++) {
- for (let u = Number(c0); u <= Number(c1); u++) {
- valueList.push({
- r: i,
- c: u
- })
- }
- }
- } else {
- valueList = []
- let regex = /[=\+\-\*\%\(\)\/\^\s]/g
- let mode = item.v.f.replace(regex, ' ').split(' ');
- mode.filter(m => m && !Number(m)&&m!='undefined').forEach(m => {
- let r = m.replace(/[a-zA-Z]/g, "") - 1
- let c = this.comparisonList.find(j => j.label == m.split('')[0]).value
- valueList.push({
- c,
- r
- })
- })
- }
- item.valueList = valueList;
+ item.valueList = excelFunction.changeParameter(item.v.f);
return item;
})
}
diff --git a/src/main.js b/src/main.js
index ef61e96..a051bd2 100644
--- a/src/main.js
+++ b/src/main.js
@@ -15,17 +15,17 @@
Vue.prototype.PROJECT = '妫�娴嬩腑蹇�'
// Vue.prototype.PROJECT = '瑁呭鐢电紗'
//鏈湴
-Vue.prototype.LOCATIONVUE = "http://127.0.0.1:80";
+// Vue.prototype.LOCATIONVUE = "http://127.0.0.1:80";
// const javaApi = 'http://127.0.0.1:8001';
-const javaApi = 'http://192.168.0.104:8001';
+// const javaApi = 'http://192.168.0.104:8001';
//浜�
// Vue.prototype.LOCATIONVUE = "http://114.132.189.42:8080";
// const javaApi = 'http://114.132.189.42:1234';
//妫�娴嬩腑蹇冩寮忓簱
-// Vue.prototype.LOCATIONVUE = "http://10.1.200.86:8080";
-// const javaApi = 'http://10.1.200.86:8001';
+Vue.prototype.LOCATIONVUE = "http://10.1.200.86:8080";
+const javaApi = 'http://10.1.200.86:8001';
//瑁呭鐢电紗娴嬭瘯搴�
// Vue.prototype.LOCATIONVUE = "http://10.16.173.59";
diff --git a/src/util/eccelFounctionList.js b/src/util/eccelFounctionList.js
new file mode 100644
index 0000000..336ce12
--- /dev/null
+++ b/src/util/eccelFounctionList.js
@@ -0,0 +1 @@
+export {}
diff --git a/src/util/excelFountion.js b/src/util/excelFountion.js
index b8c51a1..406c872 100644
--- a/src/util/excelFountion.js
+++ b/src/util/excelFountion.js
@@ -1,42 +1,5 @@
-let f = 'SUM(MAX(1,2,3)*2-MIN(1,2,3),1,2)'
-function changeParameter(f){
- let regex = /[=\+\-\*\%\(\)\/\^\s]/g;
- let fouList = [
- "SUM",
- 'MAX',
- 'MIN'
- ]
- f = f.replace(regex, ',')
- fouList.forEach(item=>{
- f = f.replaceAll(item,',')
- })
- let arr = f.split(',').filter(item=>{
- return item&& /[a-zA-Z]/.test(item)
- });
- let arr2 = []
- arr.forEach(item=>{
- if(item.includes(':')){
-
- let r0 = getIdFromColumnName(item.split(':')[0]).r;
- let c0 = getIdFromColumnName(item.split(':')[0]).c;
- let r1 = getIdFromColumnName(item.split(':')[1]).r;
- let c1 = getIdFromColumnName(item.split(':')[1]).c;
- for (let i = Number(r0); i <= Number(r1); i++) {
- for (let u = Number(c0); u <= Number(c1); u++) {
- arr2.push({
- r: i,
- c: u
- })
- }
- }
- }else{
- arr2.push(getIdFromColumnName(item))
- }
- })
- return arr2;
-}
function SUM(...val){
let num = 0;
if(val&&val.length>0){
@@ -44,7 +7,6 @@
num+=item;
})
}
- console.log('SUM',num)
return num;
}
function MAX(...val){
@@ -52,7 +14,6 @@
if(val&&val.length>0){
max = Math.max(...val)
}
- console.log('MAX',max)
return max;
}
function MIN(...val){
@@ -60,13 +21,23 @@
if(val&&val.length>0){
min = Math.min(...val)
}
- console.log('MIN',min)
return min;
}
-function handel(f){
- console.log(changeParameter(f))
- // console.log(eval(f))
+
+function AVERAGE(...val){
+ let num = 0;
+ if(val&&val.length>0){
+ val.forEach(item=>{
+ num+=item;
+ })
+ }
+ return num/val.length;
}
+
+function APS(val){
+ return Math.abs(val);
+}
+
/**
@@ -88,7 +59,6 @@
letter += String.fromCharCode(65 + (i % 26));
return letter + (parseInt(cellId[1]) + 1);
}
-console.log("getColumnNameFromId",getColumnNameFromId([1,1]))//B2
/**
* 鏍规嵁鍒楀悕鑾峰彇鍧愭爣
* @param {Object} id
@@ -128,9 +98,114 @@
return id;
}
-console.log("getIdFromColumnName",getIdFromColumnName("B2",true))//[1,1]
+// 鑾峰彇鍙傛暟鍒楄〃
+function changeParameter(f){
+ let arr = getABCList(f)
+ let arr2 = []
+ arr.forEach(item=>{
+ if(item.includes(':')){
+ let r0 = getIdFromColumnName(item.split(':')[0]).r;
+ let c0 = getIdFromColumnName(item.split(':')[0]).c;
+ let r1 = getIdFromColumnName(item.split(':')[1]).r;
+ let c1 = getIdFromColumnName(item.split(':')[1]).c;
+ for (let i = Number(r0); i <= Number(r1); i++) {
+ for (let u = Number(c0); u <= Number(c1); u++) {
+ arr2.push({
+ r: i,
+ c: u
+ })
+ }
+ }
+ }else{
+ arr2.push(getIdFromColumnName(item))
+ }
+ })
+ return arr2;
+}
+function getABCList(f){
+ let regex = /[=\+\-\*\%\(\)\/\^\s]/g;
+ let fouList = [
+ "SUM",
+ 'MAX',
+ 'MIN',
+ 'AVERAGE',
+ 'APS',
+ ]
+ f = f.replace(regex, ',')
+ fouList.forEach(item=>{
+ f = f.replaceAll(item,',')
+ })
+ let arr = f.split(',').filter(item=>{
+ return item&& /[a-zA-Z]/.test(item)&&item!='undefined'&&item!='null'
+ });
+ return arr;
+}
+
+function getAllCell(f){
+ let arr = changeParameter(f)
+ let arr0 = {}
+ arr.forEach(item=>{
+ arr0[getColumnNameFromId(`${item.c}`+'-'+`${item.r}`)] = null
+ })
+ return arr0;
+}
+
+// 璁$畻鍏紡
+function compute(f,comValue){
+ let str = f
+ // 鑾峰彇鍗曞厓鏍煎搴斿��
+ let arr = getAllCell(f)
+ for (var a in comValue) {
+ if(comValue[a]){
+ arr[a] = comValue[a]
+ }
+ }
+ // 瑙f瀽鍏紡鍙傛暟锛岀壒鍒槸甯︼細鐨�
+ let arr0 = getABCList(f)
+ let obj = {}
+ arr0.forEach(item=>{
+ if(item.includes(':')){
+ let arr1 = []
+ let r0 = getIdFromColumnName(item.split(':')[0]).r;
+ let c0 = getIdFromColumnName(item.split(':')[0]).c;
+ let r1 = getIdFromColumnName(item.split(':')[1]).r;
+ let c1 = getIdFromColumnName(item.split(':')[1]).c;
+ for (let i = Number(r0); i <= Number(r1); i++) {
+ for (let u = Number(c0); u <= Number(c1); u++) {
+ arr1.push({
+ r: i,
+ c: u
+ })
+ }
+ }
+ let arr2 = []
+ arr1.forEach(m=>{
+ arr2.push(getColumnNameFromId(`${m.c}`+'-'+`${m.r}`))
+ })
+ obj[item.split(':').join('-')] = arr2.join(',')
+ }else{
+ obj[item] = item
+ }
+ })
+ str = str.replaceAll(':', '-')
+ // 鏇挎崲鍙傛暟
+ for (var a in obj) {
+ str = str.replaceAll(a, obj[a])
+ }
+ // 璁$畻
+ try{
+ for (var a in arr) {
+ str = str.replaceAll(a, arr[a])
+ }
+ return eval(str)
+ }catch(e){
+ console.log('e',e)
+ return 0
+ }
+}
export default {
- handel
+ compute,
+ changeParameter
}
--
Gitblit v1.9.3