|
@@ -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>
|