|
@@ -1,92 +1,135 @@
|
|
|
-<!--
|
|
|
- * @Author: your name
|
|
|
- * @Date: 2024-11-06 14:48:36
|
|
|
- * @LastEditTime: 2024-11-06 16:57:25
|
|
|
- * @LastEditors: bogon
|
|
|
- * @Description: In User Settings Edit
|
|
|
- * @FilePath: /performance-test/src/views/performance/components/custonAsCom/AssociatedFields.vue
|
|
|
--->
|
|
|
<template>
|
|
|
<div class="associtedFieldsContent">
|
|
|
<el-row type="flex" class="row-bg" justify="end">
|
|
|
- <el-button type="primary" @click="drawer = true">新建关联</el-button>
|
|
|
+ <el-button type="primary" @click="handleDrawer">新建关联</el-button>
|
|
|
</el-row>
|
|
|
- <el-table :data="tableData" border style="width: 100%">
|
|
|
- <el-table-column prop="date" label="关联表1" width="300">
|
|
|
+ <el-table :data="relatedFieldsData || []" border style="width: 100%">
|
|
|
+ <el-table-column prop="tableFileName1" label="关联表1"> </el-table-column>
|
|
|
+ <el-table-column prop="tableFileName2" label="关联表2"> </el-table-column>
|
|
|
+ <el-table-column prop="tableFileName1" label="表1关联字段" align="center">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <div v-for="(item, ind) in scope.row.relatedFields?.formSelection1">
|
|
|
+ <span style="display: inline-block">{{ item.label }}</span>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column prop="name" label="关联表2" width="300">
|
|
|
+ <el-table-column prop="address" label="" align="center">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <i
|
|
|
+ style="font-size: 24px; color: #ffc107"
|
|
|
+ class="el-icon-connection"
|
|
|
+ ></i>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="tableFileName2" label="表2关联字段" align="center">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <div v-for="(item, ind) in scope.row.relatedFields?.formSelection2">
|
|
|
+ <span>{{ item.label }}</span>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column prop="address" label="关联字段"></el-table-column>
|
|
|
</el-table>
|
|
|
<el-drawer
|
|
|
title="新建关联"
|
|
|
:visible.sync="drawer"
|
|
|
direction="rtl"
|
|
|
+ width="50%"
|
|
|
:before-close="handleClose"
|
|
|
>
|
|
|
<el-card class="box-card">
|
|
|
<div slot="header" class="clearfix">
|
|
|
- <span>关联图表1</span>
|
|
|
- </div>
|
|
|
- <el-select
|
|
|
- v-model="dataChart1"
|
|
|
- placeholder="请选择"
|
|
|
- @change="handleSelectData1"
|
|
|
- >
|
|
|
- <el-option
|
|
|
- v-for="item in options"
|
|
|
- :key="item.id"
|
|
|
- :label="item.label"
|
|
|
- :value="item.id"
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ icon="el-icon-circle-plus-outline"
|
|
|
+ @click="
|
|
|
+ formSelection1.push({ label: '', fileData: [], id: '' });
|
|
|
+ formSelection2.push({ label: '', fileData: [], id: '' });
|
|
|
+ "
|
|
|
+ >添加关联字段</el-button
|
|
|
>
|
|
|
- </el-option>
|
|
|
- </el-select>
|
|
|
- <el-table
|
|
|
- ref="multipleTable"
|
|
|
- :data="tableDataChart1"
|
|
|
- tooltip-effect="dark"
|
|
|
- style="width: 100%; margin-top: 20px"
|
|
|
- @selection-change="handleSelectionChange1"
|
|
|
- >
|
|
|
- <el-table-column type="selection" width="55"> </el-table-column>
|
|
|
- <el-table-column label="字段">
|
|
|
- <template slot-scope="scope">{{ scope.row.label }}</template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
- </el-card>
|
|
|
+ <el-form
|
|
|
+ :model="ruleForm"
|
|
|
+ :rules="rules"
|
|
|
+ ref="ruleForm"
|
|
|
+ class="demo-ruleForm"
|
|
|
+ label-position="left"
|
|
|
+ >
|
|
|
+ <el-form-item label="关联表名" prop="name">
|
|
|
+ <el-input v-model="ruleForm.name"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
|
|
|
- <el-card class="box-card">
|
|
|
- <div slot="header" class="clearfix">
|
|
|
- <span>关联图表2</span>
|
|
|
+ <div class="flexs">
|
|
|
+ <div class="flexsCenter">
|
|
|
+ <div style="color: #928c8c; margin: 0 0 10px 0">关联表1</div>
|
|
|
+ <el-select
|
|
|
+ v-model="dataChart1"
|
|
|
+ placeholder="请选择"
|
|
|
+ @change="handleSelectData1"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in options"
|
|
|
+ :key="item.id"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.id"
|
|
|
+ >
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ <template v-for="(item, ind) in formSelection1">
|
|
|
+ <el-select
|
|
|
+ style="margin: 5px 0"
|
|
|
+ :key="ind + 'select'"
|
|
|
+ v-model="formSelection1[ind].id"
|
|
|
+ placeholder="请先进行数据配置"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in tableDataChart1"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.id"
|
|
|
+ :key="item.id"
|
|
|
+ ></el-option>
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+ <div class="flexsCenter">
|
|
|
+ <div style="color: #928c8c; margin: 0 0 10px 0">关联表2</div>
|
|
|
+ <el-select
|
|
|
+ v-model="dataChart2"
|
|
|
+ placeholder="请选择"
|
|
|
+ @change="handleSelectData2"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in options"
|
|
|
+ :key="item.id"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.id"
|
|
|
+ >
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ <template v-for="(item, ind) in formSelection2">
|
|
|
+ <el-select
|
|
|
+ style="margin: 5px 0"
|
|
|
+ :key="ind + 'select'"
|
|
|
+ v-model="formSelection2[ind].id"
|
|
|
+ placeholder="请先进行数据配置"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in tableDataChart2"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.id"
|
|
|
+ :key="item.id"
|
|
|
+ ></el-option>
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- <el-select
|
|
|
- v-model="dataChart2"
|
|
|
- placeholder="请选择"
|
|
|
- @change="handleSelectData2"
|
|
|
- >
|
|
|
- <el-option
|
|
|
- v-for="item in options"
|
|
|
- :key="item.id"
|
|
|
- :label="item.label"
|
|
|
- :value="item.id"
|
|
|
- >
|
|
|
- </el-option>
|
|
|
- </el-select>
|
|
|
- <el-table
|
|
|
- ref="multipleTable"
|
|
|
- :data="tableDataChart2"
|
|
|
- tooltip-effect="dark"
|
|
|
- style="width: 100%; margin-top: 20px"
|
|
|
- @selection-change="handleSelectionChange"
|
|
|
- >
|
|
|
- <el-table-column type="selection" width="55"> </el-table-column>
|
|
|
- <el-table-column label="字段">
|
|
|
- <template slot-scope="scope">{{ scope.row.label }}</template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
</el-card>
|
|
|
<el-row type="flex" class="row-bg" justify="center">
|
|
|
- <el-button type="primary" @click="submitAssociated" style="width: 200px"
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ @click="submitAssociated('ruleForm')"
|
|
|
+ style="width: 200px"
|
|
|
>确定关联</el-button
|
|
|
>
|
|
|
</el-row>
|
|
@@ -97,60 +140,182 @@
|
|
|
import {
|
|
|
getDataFromIndexedDB,
|
|
|
checkObjectStoreExists,
|
|
|
+ storeSetData,
|
|
|
+ initDatabase,
|
|
|
} from "@/utils/indexedDb";
|
|
|
+import { mapMutations, mapState } from "vuex";
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- tableData: [],
|
|
|
+ ruleForm: {
|
|
|
+ name: "",
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ name: [{ required: true, message: "请输入表名称", trigger: "blur" }],
|
|
|
+ },
|
|
|
drawer: false,
|
|
|
options: [],
|
|
|
dataChart1: [],
|
|
|
dataChart2: [],
|
|
|
+ tableFileName1: "",
|
|
|
+ tableFileName2: "",
|
|
|
+ formSelection1: [{ label: "", fileData: [], id: "" }],
|
|
|
+ formSelection2: [{ label: "", fileData: [], id: "" }],
|
|
|
tableDataChart1: [],
|
|
|
tableDataChart2: [],
|
|
|
- multipleSelection1: [],
|
|
|
- multipleSelection2: [],
|
|
|
};
|
|
|
},
|
|
|
- async created() {
|
|
|
- //判断indexedDb中是否存在这个数据表
|
|
|
- checkObjectStoreExists("FileDataDB", "files")
|
|
|
- .then((exists) => {
|
|
|
- if (exists) {
|
|
|
- console.log("对象存储 'files' 存在!");
|
|
|
- this.getIndexDbData();
|
|
|
+ async created() {},
|
|
|
+ computed: {
|
|
|
+ ...mapState("dragChart", {
|
|
|
+ relatedFieldsData: "relatedFieldsData",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapMutations("dragChart", [
|
|
|
+ "setRelatedFieldsData",
|
|
|
+ "setTriggerGetData",
|
|
|
+ "setUpdateTriggerGetData",
|
|
|
+ ]),
|
|
|
+ async saveDatas(data) {
|
|
|
+ await initDatabase()
|
|
|
+ .then((database) => {
|
|
|
+ // 调用 storeSetData 方法
|
|
|
+ let fileData = {
|
|
|
+ filename: this.ruleForm.name + "关联表",
|
|
|
+ fileData: data,
|
|
|
+ fileOldName: this.ruleForm.name + "关联表",
|
|
|
+ fileId: new Date().getTime(),
|
|
|
+ };
|
|
|
+ storeSetData(database, "files", "fileDataArray", fileData, () => {
|
|
|
+ this.setRelatedFieldsData({
|
|
|
+ tableFileName1: this.tableFileName1,
|
|
|
+ tableFileName2: this.tableFileName2,
|
|
|
+ relatedFields: {
|
|
|
+ formSelection1: this.formSelection1,
|
|
|
+ formSelection2: this.formSelection2,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ this.setTriggerGetData(true);
|
|
|
+ this.setUpdateTriggerGetData(true);
|
|
|
+ this.ruleForm.name = "";
|
|
|
+ this.formSelection1 = [{ label: "", fileData: [], id: "" }];
|
|
|
+ this.formSelection2 = [{ label: "", fileData: [], id: "" }];
|
|
|
+ this.drawer = false;
|
|
|
+ this.$message({
|
|
|
+ type: "success",
|
|
|
+ message: `关联完成,关联表可在数据表格中查看。`,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("数据库初始化失败,无法继续存储数据。", error);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ filterDataRecursively(filterNodeData, ind) {
|
|
|
+ if (ind >= this.formSelection2.length) {
|
|
|
+ // 终止条件:当 ind 超过 formSelection2 长度时,返回当前的 filterNodeData
|
|
|
+ return filterNodeData;
|
|
|
+ }
|
|
|
+ const data = [];
|
|
|
+ filterNodeData.forEach((fileData1) => {
|
|
|
+ const result = this.formSelection2[ind].fileData.find((fileData2) => {
|
|
|
+ return (
|
|
|
+ fileData1[this.formSelection1[ind].label] !== undefined &&
|
|
|
+ fileData2[this.formSelection2[ind].label] !== undefined &&
|
|
|
+ fileData1[this.formSelection1[ind].label] + "" ===
|
|
|
+ fileData2[this.formSelection2[ind].label] + ""
|
|
|
+ );
|
|
|
+ });
|
|
|
+ if (result) {
|
|
|
+ data.push({
|
|
|
+ ...fileData1,
|
|
|
+ ...result,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 递归调用并返回筛选结果
|
|
|
+ return this.filterDataRecursively(data, ind + 1);
|
|
|
+ },
|
|
|
+ submitAssociated(formName) {
|
|
|
+ this.$refs[formName].validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ // 初始化表格数据
|
|
|
+ this.tableDataChart1.forEach((item) => {
|
|
|
+ this.formSelection1.forEach((val) => {
|
|
|
+ if (val.id === item.id) {
|
|
|
+ val.fileData = item.fileData;
|
|
|
+ val.label = item.label;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ this.tableDataChart2.forEach((item) => {
|
|
|
+ this.formSelection2.forEach((val) => {
|
|
|
+ if (val.id === item.id) {
|
|
|
+ val.fileData = item.fileData;
|
|
|
+ val.label = item.label;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (
|
|
|
+ this.formSelection1[0].fileData.length <= 0 ||
|
|
|
+ this.formSelection2[0].fileData.length <= 0
|
|
|
+ ) {
|
|
|
+ console.log("sssss", this.formSelection1, this.formSelection2);
|
|
|
+ this.$message({
|
|
|
+ type: "warning",
|
|
|
+ message: `至少需要关联1组字段。`,
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 初步过滤数据
|
|
|
+ let filterNodeData = [];
|
|
|
+ this.formSelection1.forEach((fileAttribut1, ind) => {
|
|
|
+ fileAttribut1.fileData.forEach((fileData1) => {
|
|
|
+ if (ind === 0) {
|
|
|
+ const result = this.formSelection2[ind].fileData.find(
|
|
|
+ (fileData2) => {
|
|
|
+ return (
|
|
|
+ fileData1[fileAttribut1.label] !== undefined &&
|
|
|
+ fileData2[this.formSelection2[ind].label] !== undefined &&
|
|
|
+ fileData1[fileAttribut1.label] + "" ===
|
|
|
+ fileData2[this.formSelection2[ind].label] + ""
|
|
|
+ );
|
|
|
+ }
|
|
|
+ );
|
|
|
+ if (result) {
|
|
|
+ filterNodeData.push({
|
|
|
+ ...fileData1,
|
|
|
+ ...result,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ // 递归筛选
|
|
|
+ filterNodeData = this.filterDataRecursively(filterNodeData, 1);
|
|
|
+ this.saveDatas(filterNodeData);
|
|
|
} else {
|
|
|
- this.loading = false;
|
|
|
- console.log("对象存储 'files' 不存在!");
|
|
|
+ console.log("error submit!!");
|
|
|
+ return false;
|
|
|
}
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- console.error("检查对象存储时出错:", error);
|
|
|
});
|
|
|
- },
|
|
|
- methods: {
|
|
|
- submitAssociated() {
|
|
|
- console.log(
|
|
|
- this.multipleSelection2,
|
|
|
- this.multipleSelection1,
|
|
|
- "multipleSelection2"
|
|
|
- );
|
|
|
+
|
|
|
+ // console.log(filterNodeData, "filterNodeData");
|
|
|
},
|
|
|
//select 选择
|
|
|
handleSelectData1() {
|
|
|
const obj = this.options.find((item) => item.id === this.dataChart1);
|
|
|
+ this.tableFileName1 = obj.fileOldName;
|
|
|
this.tableDataChart1 = obj.children;
|
|
|
+ this.formSelection1 = [{ label: "", fileData: [], id: "" }];
|
|
|
},
|
|
|
handleSelectData2() {
|
|
|
const obj = this.options.find((item) => item.id === this.dataChart2);
|
|
|
+ this.tableFileName2 = obj.fileOldName;
|
|
|
this.tableDataChart2 = obj.children;
|
|
|
- },
|
|
|
- //表格选择
|
|
|
- handleSelectionChange1(val) {
|
|
|
- this.multipleSelection1 = val;
|
|
|
- },
|
|
|
- handleSelectionChange(val) {
|
|
|
- this.multipleSelection2 = val;
|
|
|
+ this.formSelection2 = [{ label: "", fileData: [], id: "" }];
|
|
|
},
|
|
|
handleClose(done) {
|
|
|
this.$confirm("确认关闭?")
|
|
@@ -159,10 +324,8 @@ export default {
|
|
|
})
|
|
|
.catch((_) => {});
|
|
|
},
|
|
|
-
|
|
|
async getIndexDbData() {
|
|
|
const jsonData = await getDataFromIndexedDB();
|
|
|
-
|
|
|
this.options = jsonData.map((item) => {
|
|
|
return {
|
|
|
label: item.filename,
|
|
@@ -175,7 +338,23 @@ export default {
|
|
|
})),
|
|
|
};
|
|
|
});
|
|
|
- console.log(jsonData, "this.data");
|
|
|
+ },
|
|
|
+ handleDrawer() {
|
|
|
+ this.drawer = true;
|
|
|
+ //判断indexedDb中是否存在这个数据表
|
|
|
+ checkObjectStoreExists("FileDataDB", "files")
|
|
|
+ .then((exists) => {
|
|
|
+ if (exists) {
|
|
|
+ // console.log("对象存储 'files' 存在!");
|
|
|
+ this.getIndexDbData();
|
|
|
+ } else {
|
|
|
+ this.loading = false;
|
|
|
+ // console.log("对象存储 'files' 不存在!");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("检查对象存储时出错:", error);
|
|
|
+ });
|
|
|
},
|
|
|
},
|
|
|
};
|
|
@@ -189,4 +368,18 @@ export default {
|
|
|
margin: 0 auto;
|
|
|
margin-bottom: 20px;
|
|
|
}
|
|
|
+::v-deep .el-drawer {
|
|
|
+ width: 50% !important;
|
|
|
+}
|
|
|
+.flexs {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ .flexsCenter {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ ::v-deep .el-input--suffix .el-input__inner {
|
|
|
+ width: 250px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|