Browse Source

添加条件判断公式

yangg 9 tháng trước cách đây
mục cha
commit
c1d371559c

+ 1 - 1
.env.development

@@ -2,5 +2,5 @@
 ENV = 'development'
 port = 8080
 # base api
-VUE_APP_BASE_API = 'http://192.168.1.178:8084'
+VUE_APP_BASE_API = 'http://58.246.234.210:8084'
 #192.168.1.178

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/index.html


+ 0 - 1
dist/static/css/chunk-0015e75a.06d8cf6b.css

@@ -1 +0,0 @@
-.search-list-form[data-v-b2268d60]{padding:20px}.pagination-container[data-v-b2268d60]{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:end;-ms-flex-pack:end;justify-content:flex-end}

+ 0 - 0
dist/static/css/chunk-3730d73d.68741a84.css → dist/static/css/chunk-09c6c984.68741a84.css


+ 0 - 0
dist/static/css/chunk-7fd4e7e4.775a21e3.css → dist/static/css/chunk-2a3a8f9f.775a21e3.css


+ 0 - 0
dist/static/css/chunk-980050cc.ce959b8e.css → dist/static/css/chunk-76756389.ce959b8e.css


+ 1 - 0
dist/static/css/chunk-7a88741c.8e5a92cc.css

@@ -0,0 +1 @@
+.search-list-form[data-v-1984a276]{padding:20px}.pagination-container[data-v-1984a276]{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:end;-ms-flex-pack:end;justify-content:flex-end}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/app.c2cf4e86.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-0015e75a.6f17f677.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-09c6c984.e9fe1c69.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/static/js/chunk-2a3a8f9f.de398433.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-3730d73d.a6e025e5.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-40b85d4b.d193046e.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-52f685c2.39ffce79.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-52f685c2.e1cf8e28.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-5b1b00c6.871a533c.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-5b1b00c6.d2ea1a71.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-76756389.f9d06e27.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-7a88741c.9065085d.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-980050cc.89f32864.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-libs.9ba6ec80.js


+ 1 - 1
src/views/applet/index.vue

@@ -40,7 +40,7 @@
       </el-table-column> -->
       <el-table-column label="操作">
         <template slot-scope="scope">
-          <el-button type="primary" @click="handleEdit(scope.$index, scope.row)"
+          <el-button type="primary" v-if="scope.row.examine=='0'||scope.row.examine=='2'" @click="handleEdit(scope.$index, scope.row)"
             >审核</el-button
           >
           <!-- <el-button

+ 18 - 6
src/views/document/com/components/Formula/dataInfo.vue

@@ -17,7 +17,10 @@
             <!-- <el-button style="margin-top: 10px" @click="InsertTableData"
               >插入表格数据</el-button
             > -->
-            <el-button style="margin-top: 10px" @click="InsertModule"
+            <el-button
+              style="margin-top: 10px"
+              type="primary"
+              @click="InsertModule"
               >插入模块变量</el-button
             >
           </div>
@@ -27,12 +30,21 @@
               格式一:[T][模块引用名][属性引用名] <span>*</span>其中
               [T]表示的是模块引用。
             </div>
-         <!--    <div>
-              格式二:[R][表名][Sheet名称][row,col] <span>*</span>其中
-              [R]表示引用的是原始数据。 其中row,col表示excel表中的行、列序号
-            </div> -->
             <div>目前仅支持+、-、*、/ 四种计算符合</div>
-            <div>示例 [T][模块01][attr01]+[T][模块01][attr02]</div>
+            <div>示例: [T][模块01][attr01]+[T][模块01][attr02]</div>
+            <div>
+              格式二:[T][模块引用名][属性引用名]
+              IF(判断条件,true值,false值)<span>*</span>其中
+              [T]表示的是模块引用。
+            </div>
+            <div>
+              示例: [T][图文][测试1]+IF([T][图文][测试1]>30,[T][图文][测试2],11)
+            </div>
+            <div>
+              嵌套示例: [T][图文][测试1] + IF([T][图文][测试2] > 50,
+              IF([T][图文][测试1] > 30, [T][图文][测试3], 20),
+              IF([T][图文][测试3] > 40, 15, [T][图文][测试2]) )
+            </div>
           </div>
         </el-form-item>
         <el-form-item label="保留小数点:">

+ 104 - 26
src/views/document/com/components/TextArea/index.vue

@@ -282,11 +282,48 @@ export default {
           let point = _this.com.attrs[i].data.point;
           formual = await _this.getRemote(formual);
 
-          _this.com.attrs[i].content = eval(formual).toFixed(point);
-          data = data.replace(
-            "{{" + attrId + "}}",
-            eval(formual).toFixed(point)
-          );
+          // 定义一个安全的评估函数
+          const safeEval = (formula) => {
+            // 定义允许使用的数学函数和 IF 函数
+            const mathFunctions = {
+              abs: Math.abs,
+              ceil: Math.ceil,
+              floor: Math.floor,
+              max: Math.max,
+              min: Math.min,
+              round: Math.round,
+              sqrt: Math.sqrt,
+              IF: (condition, trueValue, falseValue) =>
+                condition ? trueValue : falseValue,
+              // 添加其他需要的数学函数
+            };
+
+            // 创建一个新的函数,将数学函数作为参数传入
+            const func = new Function(
+              ...Object.keys(mathFunctions),
+              `return ${formula}`
+            );
+
+            // 执行函数,传入数学函数作为参数
+            return func(...Object.values(mathFunctions));
+          };
+
+          try {
+            const result = safeEval(formual);
+            _this.com.attrs[i].content = result.toFixed(point);
+            data = data.replace(
+              "{{" + _this.com.attrs[i].id + "}}",
+              result.toFixed(point)
+            );
+          } catch (error) {
+            console.error("处理公式时出错:", error);
+            console.error("错误的公式:", formual);
+            _this.com.attrs[i].content = "计算错误";
+            data = data.replace(
+              "{{" + _this.com.attrs[i].id + "}}",
+              "计算错误"
+            );
+          }
 
           /* let formual = await _this.analysisFormual(_this.com.attrs[i]);
           formual = await _this.getRemote(formual);
@@ -494,33 +531,74 @@ export default {
     //分析公式
     async analysisFormual(attrs) {
       let _this = this;
-      // console.log("开始分析公式:", attrs.formula);
-      var pattern = /(\[.*?\]){3}/;
-      var formual = attrs.formula;
-      var reg = new RegExp(pattern);
-      while (true) {
-        var items = formual.match(reg);
-        if (items == null) break;
-        let itemName = items[0];
-        // console.log("处理项:", itemName);
-        try {
-          let data = await _this.getFormualData(itemName, attrs.data);
-          // console.log(`获取到的数据: ${itemName} = ${data}`);
-          if (data === null || data === undefined || isNaN(data)) {
-            console.warn(`获取到的数据无效: ${itemName}`);
-            formual = formual.replace(itemName, "(0)");
-          } else {
-            formual = formual.replace(itemName, `(${parseFloat(data)})`);
+      console.log("开始分析公式:", attrs.formula);
+      let formual = attrs.formula;
+
+      // 处理 [T][...][...] 引用
+      const tPattern = /\[T\]\[(.*?)\]\[(.*?)\]/g;
+      formual = await this.replaceAsync(
+        formual,
+        tPattern,
+        async (match, p1, p2) => {
+          try {
+            let data = await _this.getModuleData(p1, p2);
+            console.log(`获取到的数据: ${match} = ${data}`);
+            if (data === null || data === undefined || isNaN(data)) {
+              console.warn(`获取到的数据无效: ${match}`);
+              return "0";
+            } else {
+              return `${parseFloat(data)}`;
+            }
+          } catch (error) {
+            console.error(`处理 ${match} 时出错:`, error);
+            return "0";
           }
-        } catch (error) {
-          console.error(`处理 ${itemName} 时出错:`, error);
-          formual = formual.replace(itemName, "(0)");
         }
+      );
+
+      // 处理嵌套的 IF 语句
+      const ifPattern = /IF\s*\((.*?),(.*?),(.*?)\)/g;
+      let depth = 0;
+      while (formual.match(ifPattern) && depth < 10) {
+        formual = formual.replace(
+          ifPattern,
+          (match, condition, trueValue, falseValue) => {
+            // 递归处理嵌套的 IF 语句
+            if (trueValue.includes("IF(") || falseValue.includes("IF(")) {
+              return `(${condition} ? (${trueValue}) : (${falseValue}))`;
+            }
+            return `(${condition} ? ${trueValue} : ${falseValue})`;
+          }
+        );
+        depth++;
       }
-      /*  console.log("分析后的公式:", formual); */
+
+      console.log("分析后的公式:", formual);
       return formual;
     },
 
+    // 辅助方法:异步替换
+    async replaceAsync(str, regex, asyncFn) {
+      const promises = [];
+      str.replace(regex, (match, ...args) => {
+        const promise = asyncFn(match, ...args);
+        promises.push(promise);
+      });
+      const data = await Promise.all(promises);
+      return str.replace(regex, () => data.shift());
+    },
+
+    // 辅助方法:异步替换
+    async replaceAsync(str, regex, asyncFn) {
+      const promises = [];
+      str.replace(regex, (match, ...args) => {
+        const promise = asyncFn(match, ...args);
+        promises.push(promise);
+      });
+      const data = await Promise.all(promises);
+      return str.replace(regex, () => data.shift());
+    },
+
     async getFormualData(formualItem, data) {
       let _this = this;
       // console.log("开始获取公式数据:", formualItem);

+ 2 - 1
src/views/document/com/editor.vue

@@ -335,7 +335,8 @@ export default {
     },
     /* 选择分类 */
     enableSelect(item) {
-      item.selDisabled = false;
+      item.selDisabled = true;
+      console.log(item);
       this.$forceUpdate();
     },
     /* 获取分类名称 */

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác