Explorar o código

fix bug 自定义算法限制问题

liujiejie hai 5 meses
pai
achega
f17d1ca409

+ 28 - 17
src/views/performance/components/custonAsCom/dataTable.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2024-10-28 16:46:38
- * @LastEditTime: 2024-12-20 15:05:57
+ * @LastEditTime: 2024-12-25 09:15:05
  * @LastEditors: bogon
  * @Description: In User Settings Edit
  * @FilePath: /performance-test/src/views/performance/components/custonAsCom/dataTable.vue
@@ -113,33 +113,45 @@ export default {
       "setUpdateTriggerGetData",
     ]),
     async getIndexDbData() {
-      // this.loading = true;
+      this.loading = true;
       const jsonData = await getDataFromIndexedDB();
       this.tabData = jsonData;
       this.activeName = jsonData && jsonData[0] && String(jsonData[0].fileId);
       this.loading = false;
     },
-    // removeTab(targetName) {
-    //   //this.tabData 循环判断每一项的filename 如果和filename相等的情况下就在indexeddb中删除这一项
-    //   // this.setTriggerGetData(true);
-    //   // this.setUpdateTriggerGetData(true);
-    // },
+
     // 删除 tab 方法
     removeTab(targetName) {
       // 1. 在 tabData 中删除对应的 tab
       const index = this.tabData.findIndex((tab) => tab.fileId === targetName);
       console.log(this.tabData, targetName, "targetName");
       if (index !== -1) {
-        // 删除 tabData 中的对应项
-        const data = this.tabData;
-        const removedTab = data.splice(index, 1)[0]; // 获取被删除的 tab 数据
-
-        // 2. 更新 IndexedDB
-        this.updateDataInIndexedDB(removedTab);
+        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
+          confirmButtonText: "确定",
+          cancelButtonText: "取消",
+          type: "warning",
+        })
+          .then(() => {
+            // 删除 tabData 中的对应项
+            const data = this.tabData;
+            const removedTab = data.splice(index, 1)[0]; // 获取被删除的 tab 数据
+            // 2. 更新 IndexedDB
+            this.updateDataInIndexedDB(removedTab);
 
-        // 3. 触发需要更新的状态
-        this.setTriggerGetData(true);
-        this.setUpdateTriggerGetData(true);
+            // 3. 触发需要更新的状态
+            this.setTriggerGetData(true);
+            this.setUpdateTriggerGetData(true);
+            this.$message({
+              type: "success",
+              message: "删除成功!",
+            });
+          })
+          .catch(() => {
+            this.$message({
+              type: "info",
+              message: "已取消删除",
+            });
+          });
       }
     },
 
@@ -150,7 +162,6 @@ export default {
         // 创建事务,指定操作对象存储空间
         const transaction = db.transaction(["files"], "readwrite");
         const store = transaction.objectStore("files");
-
         // 使用 getAll 获取所有数据
         const getRequest = store.getAll();
         getRequest.onsuccess = () => {

+ 52 - 45
src/views/performance/components/custonAsCom/luckySheet.vue

@@ -46,7 +46,7 @@ export default {
   methods: {
     async initSheetData() {
       const jsonData = await getDataFromIndexedDB();
-      console.log(jsonData, "jsonData");
+
       if (jsonData && jsonData.length > 0) {
         this.sheetName = [...jsonData].filter(
           (item) => item.fileId == this.$route.query.id
@@ -65,15 +65,18 @@ export default {
         formattedData.unshift(headers);
         //4.  将 JSON 数据转换为 Luckysheet 格式
         this.initLuckySheet(formattedData);
+      } else {
+        this.$message.warning("暂无数据,请先进行数据导入");
+        this.$router.push("/home/performance/customAnalysis");
       }
     },
-    initLuckySheet(formattedData) {
+    async initLuckySheet(formattedData) {
       const options = {
         container: "luckysheet",
         showReturnIcon: false, // 假设有这个选项
         data: [
           {
-            name: this.sheetName, //工作表名称
+            name: await this.truncateString(this.sheetName), //工作表名称
             index: 0, //工作表索引
             status: 1, //激活状态
             order: 0, //工作表的下标
@@ -131,6 +134,7 @@ export default {
         lang: "zh", // 语言设置
         showtoolbar: true, // 是否显示工具栏
         chart: {
+          //
           // 配置图表
           enable: false, // 启用图表功能
         },
@@ -140,46 +144,6 @@ export default {
       };
       luckysheet.create(options);
     },
-    // async saveData() {
-    //   // 获取当前表格的数据
-    //   const data = luckysheet.getAllSheets()[0].data; // 目前只需处理第一个工作表的数据
-    //   const formattedData = [];
-    //   // 获取表头 (假设表头在第一行,行索引为0)
-    //   const headers = data[0].map((cell) => (cell && cell.v ? cell.v : "")); // 提取表头内容
-    //   // 遍历数据行,从第二行开始 (行索引为1)
-    //   for (let i = 1; i < data.length; i++) {
-    //     const row = data[i];
-    //     const rowData = {};
-    //     // 遍历每一列,并根据表头动态生成键值对
-    //     for (let j = 0; j < headers.length; j++) {
-    //       if (row[j] && (row[j].v || row[j].v == 0)) {
-    //         rowData[headers[j]] = row[j].v || 0;
-    //       }
-    //     }
-    //     // 如果行数据不为空,加入到结果数组中
-    //     if (Object.keys(rowData).length) {
-    //       formattedData.push(rowData);
-    //     }
-    //   }
-
-    //   this.sheetData = JSON.stringify(formattedData, null, 2);
-    //   await initDatabase()
-    //     .then((database) => {
-    //       // 调用 storeSetData 方法
-    //       let fileData = {
-    //         filename: format(new Date(), "yyyyMMdd-HH:mm:ss") + this.sheetName,
-    //         fileData: JSON.parse(this.sheetData),
-    //         fileOldName: this.sheetName,
-    //         fileId: new Date().getTime(),
-    //       };
-    //       storeSetData(database, "files", "fileDataArray", fileData, () => {
-    //         this.$router.push("/home/performance/customAnalysis");
-    //       });
-    //     })
-    //     .catch((error) => {
-    //       console.error("数据库初始化失败,无法继续存储数据。", error);
-    //     });
-    // },
     async saveData() {
       // 获取所有工作表
       const sheets = luckysheet.getAllSheets();
@@ -204,7 +168,6 @@ export default {
             formattedData.push(rowData);
           }
         }
-
         // 生成唯一的 fileData
         const fileData = {
           filename:
@@ -213,7 +176,6 @@ export default {
           fileOldName: sheet.name + "_" + ind,
           fileId: new Date().getTime() + "_" + ind,
         };
-
         allFileData.push(fileData); // 将当前工作表的文件数据加入到数组中
       });
 
@@ -232,6 +194,51 @@ export default {
           console.error("数据库初始化失败,无法继续存储数据。", error);
         });
     },
+    truncateString(str) {
+      return new Promise((resolve, reject) => {
+        // 如果字符串长度超过30
+        if (str.length > 30) {
+          this.$confirm(
+            "sheet页名长度已超过31个字符,可能会影响后续对函数的使用,是否需要进行自动截取?",
+            "提示",
+            {
+              confirmButtonText: "确定",
+              cancelButtonText: "取消",
+              type: "warning",
+            }
+          )
+            .then(() => {
+              const suffixes = [".csv", ".xlsx", ".xls"];
+              let truncatedFilename = str;
+
+              // 查找文件名中的后缀位置并进行截取
+              for (let suffix of suffixes) {
+                const suffixIndex = str.lastIndexOf(suffix);
+
+                // 如果找到了后缀,进行截取
+                if (suffixIndex !== -1) {
+                  // 截取文件名,确保不超过31个字符
+                  truncatedFilename =
+                    str.slice(0, 31 - suffix.length) + str.slice(suffixIndex);
+                  break;
+                }
+              }
+              resolve(truncatedFilename);
+            })
+            .catch(() => {
+              // 用户取消时返回原始的str
+              this.$message({
+                type: "info",
+                message: "已取消删除",
+              });
+              resolve(str);
+            });
+        } else {
+          // 字符串长度不超过30,直接返回原字符串
+          resolve(str);
+        }
+      });
+    },
   },
 };
 </script>

+ 30 - 12
src/views/performance/customAnalysis.vue

@@ -337,9 +337,13 @@ export default {
       this.loading = true;
       try {
         // 1. 验证表单
-        if (!(await this.validateForm(formName))) return;
+        if (!(await this.validateForm(formName))) {
+          this.loading = false;
+          return;
+        }
         if (Number(this.ruleForm.max) < Number(this.ruleForm.min)) {
           this.$message.error("开始行不可以大于结束行");
+          this.loading = false;
           return;
         }
 
@@ -349,34 +353,47 @@ export default {
 
         if (!region.length) {
           console.warn("当前选择的列未找到数据");
+          this.loading = false;
           return;
         }
-        if (region[0].length > 1000 && this.ruleForm.type.length > 2) {
-          this.$message.warning(
-            "由于列数据过长,为了保证页面操作流畅,每次最多选择2个特征值进行计算。请分批次选择。"
+        let newDatas = [];
+        if (region[0].length > 400) {
+          if (!Number(this.ruleForm.min) || !Number(this.ruleForm.max)) {
+            this.$message.warning("每次最多选择范围在400条内。请输入数据范围");
+            this.loading = false;
+            return;
+          }
+          newDatas = region[0].slice(
+            Number(this.ruleForm.min) - 1,
+            Number(this.ruleForm.max) - 1
           );
-          return;
+          if (newDatas.length > 400) {
+            this.$message.warning(
+              "由于列数据过长,为了保证页面操作流畅,每次最多选择范围在400条内。请分批次选择。"
+            );
+            this.loading = false;
+            return;
+          }
+        } else {
+          newDatas = region[0];
+          this.loading = false;
         }
         // 3. 调用算法接口
-        // console.log(region, "region[0]");
-        const resData = await this.fetchAlgorithmData(region[0]);
-
+        const resData = await this.fetchAlgorithmData(newDatas);
         // 4. 筛选和处理数据
         const filteredData = this.filterResponseData(resData);
-
         // 5. 构建导出数据
         const resObj = this.buildExportData(indexeddbData, filteredData);
         this.storeData(resObj);
         this.resetForm();
-        this.$message.success("成功");
         this.loading = false;
+        this.$message.success("成功");
       } catch (error) {
         console.error("提交过程中发生错误:", error);
         this.$message.error(error);
         this.loading = false;
       }
     },
-
     async validateForm(formName) {
       try {
         const valid = await this.$refs[formName].validate();
@@ -576,10 +593,11 @@ export default {
           Papa.parse(text, {
             header: true, // 第一行作为表头
             complete: (results) => {
+              const newData = results.data.slice(0, results.data.length - 1);
               const fileData = {
                 filename: format(new Date(), "yyyyMMdd-HH:mm:ss") + file.name,
                 fileOldName: file.name,
-                fileData: results.data,
+                fileData: newData,
                 fileId:
                   new Date().getTime() + "_" + Math.floor(Math.random() * 1000),
               };