|
@@ -16,7 +16,6 @@
|
|
|
<el-select
|
|
|
v-model="tableName"
|
|
|
placeholder="请选择数据表"
|
|
|
- clearable
|
|
|
filterable
|
|
|
@change="getList"
|
|
|
class="mb10"
|
|
@@ -38,8 +37,10 @@
|
|
|
border
|
|
|
ref="dragTable"
|
|
|
:max-height="tableHeight"
|
|
|
- row-key="sort"
|
|
|
+ row-key="id"
|
|
|
+ :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
|
|
|
>
|
|
|
+ >
|
|
|
<!-- <el-table-column type="selection" width="55" align="center" /> -->
|
|
|
<!-- <span v-for="(key, val) in columns" :key="val">
|
|
|
<el-table-column :label="key" align="center" :prop="val" />
|
|
@@ -62,13 +63,17 @@
|
|
|
<template slot-scope="scope">
|
|
|
<el-select
|
|
|
v-model="scope.row.relationTable"
|
|
|
+ :disabled="
|
|
|
+ !scope.row.relationTableList ||
|
|
|
+ !scope.row.relationTableList.length
|
|
|
+ "
|
|
|
placeholder="请选择关联的表"
|
|
|
clearable
|
|
|
filterable
|
|
|
@change="ralationTableChange(scope.row)"
|
|
|
>
|
|
|
<el-option
|
|
|
- v-for="item in relationTableList"
|
|
|
+ v-for="item in scope.row.relationTableList"
|
|
|
:key="item.tableName"
|
|
|
:label="item.tableComment"
|
|
|
:value="item.tableName"
|
|
@@ -77,7 +82,7 @@
|
|
|
</el-select>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column prop="relationFieldName" label="关联字段">
|
|
|
+ <el-table-column prop="relationFieldName" label="关联条件字段">
|
|
|
<template slot-scope="scope">
|
|
|
<el-select
|
|
|
v-model="scope.row.relationFieldName"
|
|
@@ -116,6 +121,26 @@
|
|
|
</el-select>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
+ <el-table-column prop="relationShowField" label="关联显示字段">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-select
|
|
|
+ v-model="scope.row.relationShowField"
|
|
|
+ :disabled="!scope.row.disableRelaFieldName"
|
|
|
+ placeholder="请选择"
|
|
|
+ clearable
|
|
|
+ filterable
|
|
|
+ multiple
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in scope.row.relaFieldNameList"
|
|
|
+ :key="item.fieldName"
|
|
|
+ :label="item.fieldDescription"
|
|
|
+ :value="item.fieldName + ' ' + item.fieldDescription"
|
|
|
+ >
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
<el-table-column prop="isShow" label="是否显示">
|
|
|
<template slot-scope="scope">
|
|
|
<el-switch v-model="scope.row.isShow"> </el-switch>
|
|
@@ -236,11 +261,130 @@
|
|
|
</el-card>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
- <el-dialog title="效果预览" v-model="isShowPreview" width="50%">
|
|
|
- <span></span>
|
|
|
+ <el-dialog title="效果预览" :visible.sync="isShowPreview" width="50%">
|
|
|
+ <el-form label-width="80px" size="normal" :inline="true">
|
|
|
+ <el-form-item label="超级查询">
|
|
|
+ <el-input placeholder="请输入" clearable />
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ icon="el-icon-search"
|
|
|
+ size="mini"
|
|
|
+ @click="() => {}"
|
|
|
+ >搜索</el-button
|
|
|
+ >
|
|
|
+ <el-button icon="el-icon-refresh" size="mini" @click="() => {}"
|
|
|
+ >重置</el-button
|
|
|
+ >
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <el-row :gutter="10" class="mb8">
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ plain
|
|
|
+ icon="el-icon-plus"
|
|
|
+ size="mini"
|
|
|
+ @click="() => {}"
|
|
|
+ >新增
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="success"
|
|
|
+ plain
|
|
|
+ icon="el-icon-edit"
|
|
|
+ size="mini"
|
|
|
+ :disabled="false"
|
|
|
+ @click="() => {}"
|
|
|
+ >修改
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="danger"
|
|
|
+ plain
|
|
|
+ icon="el-icon-delete"
|
|
|
+ size="mini"
|
|
|
+ :disabled="false"
|
|
|
+ @click="() => {}"
|
|
|
+ >删除
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button plain icon="el-icon-upload2" size="mini" @click="() => {}"
|
|
|
+ >导入
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="warning"
|
|
|
+ plain
|
|
|
+ icon="el-icon-download"
|
|
|
+ size="mini"
|
|
|
+ @click="() => {}"
|
|
|
+ >导出
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <right-toolbar
|
|
|
+ showSearch.sync="true"
|
|
|
+ @queryTable="() => {}"
|
|
|
+ ></right-toolbar>
|
|
|
+ </el-row>
|
|
|
+ <el-table :data="tableDataList" @selection-change="() => {}">
|
|
|
+ <el-table-column
|
|
|
+ type="selection"
|
|
|
+ width="55"
|
|
|
+ align="center"
|
|
|
+ ></el-table-column>
|
|
|
+ <!-- <span v-for="(key, val) in columns" :key="key">
|
|
|
+ <el-table-column :label="key" align="center" :prop="val" />
|
|
|
+ </span> -->
|
|
|
+ <el-table-column
|
|
|
+ v-for="item in columns"
|
|
|
+ :key="item.key"
|
|
|
+ :label="item.value"
|
|
|
+ align="center"
|
|
|
+ :prop="item.key"
|
|
|
+ />
|
|
|
+ <el-table-column
|
|
|
+ label="操作"
|
|
|
+ align="center"
|
|
|
+ class-name="small-padding fixed-width"
|
|
|
+ >
|
|
|
+ <!-- <template slot-scope="scope"> -->
|
|
|
+ <template>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-edit"
|
|
|
+ @click="() => {}"
|
|
|
+ >修改
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-delete"
|
|
|
+ @click="() => {}"
|
|
|
+ >删除
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <pagination
|
|
|
+ v-show="total > 0"
|
|
|
+ :total="total"
|
|
|
+ :page.sync="queryParams.pageNum"
|
|
|
+ :limit.sync="queryParams.pageSize"
|
|
|
+ @pagination="pageList"
|
|
|
+ />
|
|
|
<template #footer>
|
|
|
<span>
|
|
|
<el-button @click="isShowPreview = false">关闭</el-button>
|
|
|
+ <el-button type="primary" @click="createHandle">确认创建</el-button>
|
|
|
</span>
|
|
|
</template>
|
|
|
</el-dialog>
|
|
@@ -256,7 +400,12 @@ import {
|
|
|
getInfoBySqlKey,
|
|
|
addTableData,
|
|
|
} from "@/api/tablelist/commonTable";
|
|
|
-import { getFormName, getListName } from "@/api/dragform/form.js";
|
|
|
+import {
|
|
|
+ getFormName,
|
|
|
+ getListName,
|
|
|
+ dragTablePreview,
|
|
|
+} from "@/api/dragform/form.js";
|
|
|
+import { addDragTable } from "@/api/tablelist/commonTable.js";
|
|
|
import { getMenuList } from "@/api/menu.js";
|
|
|
import Queryfrom from "@/views/tablelist/commonTable/queryfrom.vue";
|
|
|
import { mapState } from "vuex";
|
|
@@ -274,22 +423,6 @@ export default {
|
|
|
templateInfo: {},
|
|
|
// 排序方式 默认降序
|
|
|
sortState: true,
|
|
|
- // 共通查询参数接受子组件的参数
|
|
|
- queryParams: {
|
|
|
- pageNum: 1, // 第几页
|
|
|
- pageSize: 10, // 每页大小
|
|
|
- orderByColumn: "", // 根据某列排序
|
|
|
- isAsc: this.sortState ? "DESC" : "ASC", // desc(降序)或 asc(升序)
|
|
|
- // 基本查询参数
|
|
|
- basicMap: {
|
|
|
- tableName: "",
|
|
|
- },
|
|
|
- // 当前表字段筛选参数
|
|
|
- queryMap: {
|
|
|
- // 当前查询基本参数
|
|
|
- // ... key : value 当前页面的筛选条件
|
|
|
- },
|
|
|
- },
|
|
|
// 列信息
|
|
|
columns: {},
|
|
|
// 查询条件
|
|
@@ -383,6 +516,17 @@ export default {
|
|
|
|
|
|
// 预览弹窗相关
|
|
|
isShowPreview: false, //弹窗显示与隐藏
|
|
|
+ queryParams: {
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ orderByColumn: "",
|
|
|
+ isAsc: "DESC",
|
|
|
+ basicMap: {
|
|
|
+ sql: "",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ loading: false, //表格加载
|
|
|
+ tableDataList: [], //数据
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -418,11 +562,6 @@ export default {
|
|
|
} else {
|
|
|
this.relationTableList = [];
|
|
|
}
|
|
|
- console.log(
|
|
|
- this.tableList.filter((item) => item.tableName != val),
|
|
|
- "12341"
|
|
|
- );
|
|
|
- console.log(this.relationTableList, "this.relationTableList");
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
@@ -437,8 +576,9 @@ export default {
|
|
|
|
|
|
// 获取当前表单结构信息
|
|
|
getListName(data).then((res) => {
|
|
|
- this.tableFieldList = res.map((item) => {
|
|
|
+ this.tableFieldList = res.map((item, index) => {
|
|
|
return {
|
|
|
+ id: item.fieldName,
|
|
|
fieldName: item.fieldName,
|
|
|
fieldDescription: item.fieldDescription,
|
|
|
relationTable: "",
|
|
@@ -446,10 +586,14 @@ export default {
|
|
|
relaFieldNameList: [],
|
|
|
disableRelaFieldName: false,
|
|
|
relationType: "",
|
|
|
+ relationShowField: [],
|
|
|
+ relationShowFiledList: [],
|
|
|
disableRelaType: false,
|
|
|
isShow: true,
|
|
|
isSearch: false,
|
|
|
isExport: true,
|
|
|
+ relationTableList: this.relationTableList,
|
|
|
+ children: [],
|
|
|
};
|
|
|
});
|
|
|
});
|
|
@@ -461,6 +605,7 @@ export default {
|
|
|
row.relationType = "";
|
|
|
row.disableRelaFieldName = false;
|
|
|
row.disableRelaType = false;
|
|
|
+ row.children = [];
|
|
|
return;
|
|
|
}
|
|
|
// 获取关联表的字段
|
|
@@ -476,13 +621,24 @@ export default {
|
|
|
fieldDescription: item.fieldDescription,
|
|
|
};
|
|
|
});
|
|
|
+ row.children = row.relaFieldNameList.map((item, index) => {
|
|
|
+ return {
|
|
|
+ id: row.relationTable + " " + item.fieldName,
|
|
|
+ fieldName: item.fieldName,
|
|
|
+ fieldDescription: item.fieldDescription,
|
|
|
+ isSearch: false,
|
|
|
+ isShow: true,
|
|
|
+ isExport: true,
|
|
|
+ };
|
|
|
+ });
|
|
|
row.disableRelaFieldName = true;
|
|
|
},
|
|
|
// 关联字段回调
|
|
|
- async relationFieldChange(row) {
|
|
|
+ relationFieldChange(row) {
|
|
|
if (!row.relationFieldName) {
|
|
|
row.relationType = "";
|
|
|
row.disableRelaType = false;
|
|
|
+ row.relaFieldNameList = [];
|
|
|
return;
|
|
|
}
|
|
|
row.disableRelaType = true;
|
|
@@ -491,7 +647,7 @@ export default {
|
|
|
// 勾选框回调
|
|
|
handleSelectionChange(selection) {
|
|
|
this.ids = selection.map((item) => item.id);
|
|
|
- this.single = selection.length != 1;
|
|
|
+ // this.single = selection.length != 1;
|
|
|
this.multiple = !selection.length;
|
|
|
},
|
|
|
// 分页查询
|
|
@@ -549,27 +705,151 @@ export default {
|
|
|
console.log(res);
|
|
|
this.menus = this.handleTree(res.data, "menuId");
|
|
|
},
|
|
|
+ // 拼接查询sql语句
|
|
|
+ getSQLStr() {
|
|
|
+ let sqlType = this.databaseType;
|
|
|
+ let sql = "";
|
|
|
+ // mysql
|
|
|
+ sql += "SELECT ";
|
|
|
+ let fieldNameArr = [],
|
|
|
+ relaTypeArr = [];
|
|
|
+ let mainTableName = this.tableName;
|
|
|
+ this.tableFieldList
|
|
|
+ .filter((item) => item.isShow)
|
|
|
+ .map((item, index, arr) => {
|
|
|
+ //主表查询
|
|
|
+ fieldNameArr.push(mainTableName + "." + item.fieldName);
|
|
|
+
|
|
|
+ if (
|
|
|
+ item.relationTable &&
|
|
|
+ item.relationShowField.length &&
|
|
|
+ item.relationType &&
|
|
|
+ item.relationFieldName
|
|
|
+ ) {
|
|
|
+ //关联表字段查询
|
|
|
+ item.relationShowField.map((val) => {
|
|
|
+ fieldNameArr.push(item.relationTable + "." + val.split(" ")[0]);
|
|
|
+ });
|
|
|
+ //关联方式
|
|
|
+ relaTypeArr.push(
|
|
|
+ item.relationType +
|
|
|
+ " " +
|
|
|
+ item.relationTable +
|
|
|
+ " AS " +
|
|
|
+ item.relationTable +
|
|
|
+ " ON " +
|
|
|
+ item.relationTable +
|
|
|
+ "." +
|
|
|
+ item.relationFieldName +
|
|
|
+ " = " +
|
|
|
+ this.tableName +
|
|
|
+ "." +
|
|
|
+ item.fieldName
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sql +=
|
|
|
+ fieldNameArr.join(",") +
|
|
|
+ " FROM " +
|
|
|
+ mainTableName +
|
|
|
+ " AS " +
|
|
|
+ mainTableName;
|
|
|
+ if (relaTypeArr.length) {
|
|
|
+ sql += " " + relaTypeArr.join(" ");
|
|
|
+ }
|
|
|
+
|
|
|
+ return sql;
|
|
|
+ },
|
|
|
+ // 处理列表信息
|
|
|
+ columnsHandler(columns) {
|
|
|
+ let resArr = [];
|
|
|
+ columns.forEach((item) => {
|
|
|
+ for (const key in item) {
|
|
|
+ let tempObj = {};
|
|
|
+ tempObj.key = key;
|
|
|
+ tempObj.value = item[key];
|
|
|
+ resArr.push(tempObj);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return resArr;
|
|
|
+ },
|
|
|
+ // 获取列表信息
|
|
|
+ getColumns() {
|
|
|
+ let columns = [];
|
|
|
+ this.tableFieldList.forEach((item) => {
|
|
|
+ if (item.isShow) {
|
|
|
+ let tempObj = {};
|
|
|
+ tempObj[item.fieldName] = item.fieldDescription;
|
|
|
+ columns.push(tempObj);
|
|
|
+ if (item.children.length) {
|
|
|
+ item.children
|
|
|
+ .filter((val) => val.isShow)
|
|
|
+ .map((child) => {
|
|
|
+ let tempObj = {};
|
|
|
+ tempObj[child.fieldName] = child.fieldDescription;
|
|
|
+ columns.push(tempObj);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return columns;
|
|
|
+ },
|
|
|
// 预览结果回调
|
|
|
async previewHandle() {
|
|
|
- // 发送请求获取预览数据
|
|
|
+ this.$refs.formData.validate(async (valid) => {
|
|
|
+ if (valid) {
|
|
|
+ if (!this.tableName) {
|
|
|
+ this.$message.error("请选择数据表");
|
|
|
+ }
|
|
|
+ // 拼接预览的sql查询语句
|
|
|
+ this.queryParams.basicMap.sql = this.getSQLStr();
|
|
|
+ // 获取表头信息
|
|
|
+ let tempColumns = this.getColumns();
|
|
|
+ this.columns = this.columnsHandler(tempColumns);
|
|
|
+ console.log(this.columns);
|
|
|
+ this.queryParams.isAsc = this.formData.isAsc;
|
|
|
+ // 发送请求获取预览数据
|
|
|
+ let res = await dragTablePreview(this.queryParams);
|
|
|
+ this.tableDataList = [];
|
|
|
+ res.rows.forEach((item) => {
|
|
|
+ this.tableDataList.push(item.resultMap);
|
|
|
+ });
|
|
|
+ console.log(this.tableDataList);
|
|
|
+ console.log(this.columns);
|
|
|
+ this.total = res.total;
|
|
|
+ this.isShowPreview = true;
|
|
|
+ } else {
|
|
|
+ this.$message.warning("请完善表单");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
// 创建回调
|
|
|
async createHandle() {
|
|
|
- this.$refs.formData.validate((valid) => {
|
|
|
+ this.$refs.formData.validate(async (valid) => {
|
|
|
if (valid) {
|
|
|
let data = {
|
|
|
dtName: this.formData.menuName,
|
|
|
tableKey: this.formData.routePath, // 暂定
|
|
|
dtTableName: this.tableName,
|
|
|
- dtColumnName: {}, //列字段标题名称(存储显示字段信息
|
|
|
+ dtColumnName: [], //列字段标题名称(存储显示字段信息
|
|
|
timeFormat: this.formData.timeFormate,
|
|
|
searchFieldList: [], //搜索字段数组
|
|
|
- tableSql: "select * from test", // 暂定
|
|
|
+ tableSql: this.getSQLStr(), // 暂定
|
|
|
tableExportField: {}, //导出字段名及列名
|
|
|
};
|
|
|
this.tableFieldList.forEach((item) => {
|
|
|
if (item.isShow) {
|
|
|
- data.dtColumnName[item.fieldName] = item.fieldDescription;
|
|
|
+ let tempObj = {};
|
|
|
+ tempObj[item.fieldName] = item.fieldDescription;
|
|
|
+ data.dtColumnName.push(tempObj);
|
|
|
+ if (item.children.length) {
|
|
|
+ item.children.map((child) => {
|
|
|
+ let tempObj = {};
|
|
|
+ tempObj[child.fieldName] = child.fieldDescription;
|
|
|
+ data.dtColumnName.push(tempObj);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
if (item.isSearch) {
|
|
|
data.searchFieldList.push(item.fieldName);
|
|
@@ -579,6 +859,9 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
console.log(data);
|
|
|
+ let res = await addDragTable(data);
|
|
|
+ this.$message.success("创建成功");
|
|
|
+ console.log(res);
|
|
|
} else {
|
|
|
this.$message.warning("请完善表单");
|
|
|
return false;
|