<template> <el-card> <el-row type="flex" justify="space-between"> <el-col :span="1.5" style="display: flex; align-items: center;"> <el-form label-width="100px" style="display: flex; align-items: center;"> <el-form-item style="text-align: center;margin: 0 0 0 -100px;"> <el-button size="mini" type="primary" v-if="activeName=='basic' || activeName=='cloum'" @click="submitForm()">保存</el-button> <el-button size="mini" @click="close()">返回</el-button> </el-form-item> </el-form> </el-col> </el-row> <el-tabs v-model="activeName"> <el-tab-pane label="基本信息" name="basic"> <basic-info-form ref="basicInfo" :info="info" /> </el-tab-pane> <el-tab-pane label="字段信息" name="cloum"> <el-row type="flex" style="margin-bottom: 20px;" v-if="activeName=='cloum'" :gutter="10" justify="end"> <el-col :span="1.5" style="display: flex; align-items: center;"> <el-button style="background-color: #FFE9ED;color: #E58481;border: 1px solid #E58481;" type="warning" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:post:add']">新增</el-button> </el-col> <el-col :span="1.5" style="display: flex; align-items: center;"> <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['system:post:remove']" style="background-color: #FFD6B0;color: #EA551A;border: 1px solid #F4AD6B;">删除</el-button> </el-col> <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> --> </el-row> <el-table ref="dragTable" @row-dblclick="dbSelectedZd" align="center" :data="cloumns" row-key="columnId" :max-height="tableHeight" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55" align="center" /> <el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" align="center" /> <el-table-column label="字段列名" prop="columnName" min-width="10%" :show-overflow-tooltip="true" align="center" /> <el-table-column label="字段描述" min-width="10%" align="center"> <template slot-scope="scope"> <el-input v-model="scope.row.columnComment"></el-input> </template> </el-table-column> <el-table-column label="物理类型" prop="columnType" align="center" min-width="10%" :show-overflow-tooltip="true" /> <el-table-column label="字段显示规则" align="center" prop="mask" min-width="13%" /> <el-table-column label="排序" min-width="8%" align="center" prop="sort" /> <el-table-column label="输入字段" min-width="10%" align="center"> <template slot-scope="scope"> <el-checkbox true-label="Y" false-label="N" v-model="scope.row.isIn"></el-checkbox> </template> </el-table-column> <el-table-column label="显示字段" min-width="10%" align="center"> <template slot-scope="scope"> <el-checkbox true-label="Y" false-label="N" v-model="scope.row.isOut"></el-checkbox> </template> </el-table-column> <el-table-column label="查询" min-width="8%" align="center"> <template slot-scope="scope"> <el-checkbox true-label="1" false-label="0" v-model="scope.row.isQuery"></el-checkbox> </template> </el-table-column> <el-table-column label="关联HR字段" min-width="13%" align="center" prop="hrParentId"> <template slot-scope="scope"> <div> {{scope.row.hrParentId | zdFn}} </div> </template> </el-table-column> <el-table-column label="缺省值" min-width="10%" align="center" prop="defaultValue" /> <el-table-column label="外键" min-width="10%" align="center" prop="foreignKey"> <template slot-scope="scope"> <div> {{scope.row.foreignKey | zdFn}} </div> </template> </el-table-column> <el-table-column label="必填" min-width="8%" align="center"> <template slot-scope="scope"> <el-checkbox true-label="1" false-label="0" v-model="scope.row.isRequired"></el-checkbox> </template> </el-table-column> <el-table-column label="显示类型" min-width="12%" align="center"> <template slot-scope="scope"> <el-select v-model="scope.row.htmlType"> <el-option label="文本框" value="input" /> <el-option label="文本域" value="textarea" /> <el-option label="下拉框" value="select" /> <el-option label="单选框" value="radio" /> <el-option label="复选框" value="checkbox" /> <el-option label="日期控件" value="datetime" /> <el-option label="图片上传" value="imageUpload" /> <el-option label="文件上传" value="fileUpload" /> <el-option label="富文本控件" value="editor" /> <el-option label="hr" value="hr" /> </el-select> </template> </el-table-column> <el-table-column label="字典类型" min-width="12%" align="center"> <template slot-scope="scope"> <el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择"> <el-option v-for="dict in dictOptions" :key="dict.dictType" :label="dict.dictName" :value="dict.dictType"> <span style="float: left">{{ dict.dictName }}</span> <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span> </el-option> </el-select> </template> </el-table-column> </el-table> <!-- 添加或修改岗位对话框 --> <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="openZd" width="70vw" append-to-body> <el-form ref="formZd" :model="formZd" :rules="rulesZd" label-width="120px"> <el-row> <el-col :span="8"> <el-form-item label="字段名:" prop="columnName"> <el-input :disabled="this.formZd.columnId" v-model="formZd.columnName" placeholder="请输入字段名" /> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="字段描述:" prop="columnComment"> <el-input v-model="formZd.columnComment" placeholder="请输入字段描述" /> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="物理类型:" prop="columnType"> <el-input v-model="formZd.columnType" placeholder="请输入物理类型" /> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="8"> <el-form-item label="字段显示规则:" prop="mask"> <el-input v-model="formZd.mask" placeholder="请输入字段显示规则" /> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="排序:" prop="sort"> <el-input-number style="width: 100%;" v-model="formZd.sort" placeholder="请输入排序" /> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="正则表达式:" prop="regular"> <el-input v-model="formZd.regular" placeholder="请输入正则表达式" /> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="8"> <el-form-item label="外键(FK):" prop="foreignKey"> <!-- <el-select style="width: 100%;" filterable v-model="formZd.foreignKey" placeholder="请选择外键(FK)" clearable size="small"> <el-option v-for="dict in columList" :key="dict.columnId" :label="dict.columnName" :value="dict.columnId" /> </el-select> --> <div style="cursor: pointer;" @click="fkzdFn"> <el-input readonly style="width: 100%;" v-model="ForeName" placeholder="请选择外键(FK)" /> </div> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="关联HR字段:" prop="hrParentId"> <el-select style="width: 100%;" v-model="formZd.hrParentId" placeholder="请选择关联HR字段" clearable> <el-option v-for="dict in columHRList" :key="dict.columnId" :label="dict.columnName" :value="dict.columnId" /> </el-select> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="缺省值:" prop="defaultValue"> <el-input v-model="formZd.defaultValue" placeholder="请输入缺省值" /> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="8"> <el-form-item label="行数:" prop="numRows"> <el-input-number style="width: 100%;" v-model="formZd.numRows" placeholder="请输入行数" /> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="列数:" prop="numColumns"> <el-input-number style="width: 100%;" v-model="formZd.numColumns" placeholder="请输入列数" /> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="字段翻译器:" prop="fieldTranslator"> <el-input v-model="formZd.fieldTranslator" placeholder="请输入字段翻译器" /> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="8"> <el-form-item label="扩展属性:" prop="extendedAttributes"> <el-input v-model="formZd.extendedAttributes" placeholder="请输入扩展属性" /> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="查询方式:" prop="queryType"> <el-select style="width: 100%;" v-model="formZd.queryType"> <el-option label="=" value="EQ" /> <el-option label="!=" value="NE" /> <el-option label=">" value="GT" /> <el-option label=">=" value="GTE" /> <el-option label="<" value="LT" /> <el-option label="<=" value="LTE" /> <el-option label="LIKE" value="LIKE" /> <el-option label="BETWEEN" value="BETWEEN" /> </el-select> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="显示类型:" prop="htmlType"> <el-select style="width: 100%;" v-model="formZd.htmlType"> <el-option label="文本框" value="input" /> <el-option label="文本域" value="textarea" /> <el-option label="下拉框" value="select" /> <el-option label="单选框" value="radio" /> <el-option label="复选框" value="checkbox" /> <el-option label="日期控件" value="datetime" /> <el-option label="图片上传" value="imageUpload" /> <el-option label="文件上传" value="fileUpload" /> <el-option label="富文本控件" value="editor" /> <el-option label="hr" value="hr" /> </el-select> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="8"> <el-form-item label="字典类型:" prop="dictType"> <template slot-scope="scope"> <el-select style="width: 100%;" v-model="formZd.dictType" clearable filterable placeholder="请选择"> <el-option v-for="dict in dictOptions" :key="dict.dictType" :label="dict.dictName" :value="dict.dictType"> <span style="float: left">{{ dict.dictName }}</span> <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span> </el-option> </el-select> </template> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="显示字段" prop="isOut"> <el-checkbox true-label="Y" false-label="N" v-model="formZd.isOut"></el-checkbox> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="输入字段" prop="isIn"> <el-checkbox true-label="Y" false-label="N" v-model="formZd.isIn"></el-checkbox> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="8"> <el-form-item label="查询条件" prop="isQuery"> <el-checkbox true-label="1" false-label="0" v-model="formZd.isQuery"></el-checkbox> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="必填" prop="isRequired"> <el-checkbox true-label="1" false-label="0" v-model="formZd.isRequired"></el-checkbox> </el-form-item> </el-col> </el-row> </el-form> <div slot="footer" class="dialog-footer"> <el-button type="primary" @click="submitFormZd">确 定</el-button> <el-button @click="cancel">取 消</el-button> </div> </el-dialog> </el-tab-pane> <!-- <el-tab-pane label="生成信息" name="genInfo"> <gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/> </el-tab-pane> --> <el-tab-pane label="关联表" name="genInfo"> <el-row style="margin-bottom: 20px;" type="flex" :gutter="10" justify="end"> <el-col :span="1.5"> <el-button @click="handleAdd_gl" icon="el-icon-plus" size="mini" style="background-color: #FFE9ED;color: #E58481;border: 1px solid #E58481;">新增</el-button> </el-col> <el-col :span="1.5"> <el-button icon="el-icon-delete" @click="handleDel_gl" size="mini" style="background-color: #FFD6B0;color: #EA551A;border: 1px solid #F4AD6B;" :disabled="multiple1">删除</el-button> </el-col> </el-row> <el-table ref="dragTable" @row-dblclick="dbSelected" v-loading="loading" :data="postList" row-key="columnId" align="center" :max-height="tableHeight" @selection-change="handleSelectionChange1"> <el-table-column type="selection" width="55" align="center" /> <el-table-column label="id" width="60" align="center" prop="id" /> <el-table-column label="可用" align="center" prop="isDel"> <template slot-scope="scope"> <el-checkbox true-label="Y" disabled false-label="N" v-model="scope.row.isDel"></el-checkbox> </template> </el-table-column> <el-table-column label="序号" align="center" prop="sort" /> <el-table-column label="描述" align="center" prop="description" /> <el-table-column label="关联表" align="center" prop="tableName" /> <el-table-column label="字段(关联到主表PK)" width="160px" align="center" prop="columnName" /> <el-table-column label="显示条件" align="center" prop="displayConditions" /> <el-table-column label="关联方式" align="center" prop="relationType"> <template slot-scope="scope"> {{scope.row.relationType | relationTypeFn}} </template> </el-table-column> <el-table-column label="内嵌编辑" align="center" prop="embedEdit"> <template slot-scope="scope"> {{scope.row.embedEdit | embedEditFn}} </template> </el-table-column> <el-table-column label="修改人" align="center" prop="updateBy" /> <el-table-column label="修改时间" align="center" prop="updateTime" /> </el-table> <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="tabList" /> </el-tab-pane> <el-tab-pane label="数据库SQL" name="genSql"> <el-row type="flex" justify="end"> <el-button @click="zxCreaBtn" size="mini" style="background-color: #FFE9ED;color: #E58481;border: 1px solid #E58481;">执行创建语句</el-button> <el-button @click="sxCreaBtn" size="mini" style="background-color: #FFD6B0;color: #EA551A;border: 1px solid #F4AD6B;">刷新创建语句</el-button> </el-row> <el-form> <el-form-item label="创建语句:" style="margin-top: 20px;"> <el-input class="resizeNone" v-model="tableSqlData.createSql" type="textarea" /> </el-form-item> <el-form-item label="修改日志:"> <el-input class="resizeNone" v-model="tableSqlData.createLog" type="textarea" /> </el-form-item> </el-form> </el-tab-pane> </el-tabs> <!-- 添加或修改岗位对话框 --> <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body> <el-form ref="form" :model="form" :rules="rules" label-width="100px"> <el-form-item label="描述:" prop="postName"> <el-input v-model="form.description" placeholder="请输入描述" /> </el-form-item> <el-form-item label="关联表:" prop="relationParentId"> <el-select style="width: 100%;" v-model="form.relationParentId" placeholder="请选择关联表" @change="relationFn" v-loadmore="loadMore"> <el-option v-for="item in tableList.rows" :key="item.tableId" :label="item.tableComment" :value="item.tableId"> </el-option> </el-select> </el-form-item> <el-form-item label="字段:" prop="relationChildId"> <el-select style="width: 100%;" v-model="form.relationChildId" placeholder="请选择字段" v-loadmore="loadMore"> <el-option v-for="item in genList" v-if="item.foreignKey" :key="item.columnId" :label="item.columnName" :value="item.columnId"> </el-option> </el-select> </el-form-item> <el-form-item label="显示条件:" prop="displayConditions"> <el-input v-model="form.displayConditions" controls-position="right" placeholder="请输入显示条件" /> </el-form-item> <el-form-item label="关联方式:" prop="relationType"> <el-select style="width: 100%;" v-model="form.relationType" placeholder="请选择关联方式" clearable size="small"> <el-option v-for="dict in relationType" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" /> </el-select> </el-form-item> <el-form-item label="内嵌编辑:" prop="embedEdit"> <el-select style="width: 100%;" v-model="form.embedEdit" placeholder="岗位状态" clearable size="small"> <el-option v-for="dict in embedEdit" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" /> </el-select> </el-form-item> <el-form-item label="序号:" prop="sort"> <el-input-number style="width: 100%;" v-model="form.sort" controls-position="right" :min="0" /> </el-form-item> <el-form-item label="是否可用:" prop="isDel"> <el-checkbox true-label="Y" false-label="N" v-model="form.isDel"></el-checkbox> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button type="primary" @click="addGlfn">确 定</el-button> <el-button @click="cancel">取 消</el-button> </div> </el-dialog> <!-- 快速搜索对话框 --> <el-dialog :close-on-click-modal="false" :title="titleopenquery" :visible.sync="openquery" width="1200px" append-to-body> <el-form ref="formquery" @row-dblclick="dbSelectedZd" :model="formquery" :rules="rules" label-width="100px"> <dynamic-forms :ref="item.columnName" :config="formquery.fixedData" @inputs = "changeFn" :formConfig="item" v-for="(item,index) in queryData.queryList" :key='index' /> <el-form-item style="display: inline-block;"> <el-button type="primary" @click="handleQuery">搜索</el-button> <el-button @click="openquery = false">取消</el-button> </el-form-item> </el-form> <el-table stripe @row-dblclick="tableBtn" :data="postListquery.rows" @selection-change="handleSelectionChange"> <el-table-column :label="item.columnComment" align="center" :prop="item.columnName" v-for="(item,index) in postListquery.tableHeadList" :key="index" /> </el-table> <pagination v-show="totalquery>0" :total="totalquery" :page.sync="aliemg.pageNo" :limit.sync="aliemg.pageSize" @pagination="getLisail" /> </el-dialog> </el-card> </template> <script> import { getGenTable, updateGenTable, delPost, tabList, listTable, addGenTable, setGenTable, delGenTable, listAllColumnsByTableId, genTableColumnList, tableSql, zxImplement, getReload, addGenTableColumn, delGenTableColumn, setGenTableColumn, getGenTableColumn, getByIdWithForeignKey, listIndexfou, tableQuery, qurGenTable } from "@/api/tool/gen"; import { optionselect as getDictOptionselect } from "@/api/system/dict/type"; import { listMenu as getMenuTreeselect } from "@/api/system/menu"; import basicInfoForm from "./basicInfoForm"; import genInfoForm from "./genInfoForm"; import Sortable from 'sortablejs' let _this = '' export default { name: "GenEdit", components: { basicInfoForm, genInfoForm }, data() { _this = this return { ForeName: '', totalquery:0, // 多行查询 titleopenquery:'快速查询', // 获取输入框的参数 queryLisr:{ table:'gen_table_column' }, aliemg:{ table:'gen_table_column', orderBy:'create_time desc', pageNo:1, pageSize:10, fixedData:{ condition:'' } }, postListquery:{}, queryData: {}, openquery:false, formquery:{}, // 字段信息 tableSqlData: [], columList: [], columHRList: [], foreignKey: [], openZd: false, formZd: { columnId: '' }, rulesZd: { columnName: [{ required: true, message: "请输入字段名", trigger: "blur" }], columnComment: [{ required: true, message: "请输入字段描述", trigger: "blur" }], columnType: [{ required: true, message: "请输入物理类型", trigger: "blur" }], mask: [{ required: true, message: "请输入字段显示规则", trigger: "blur" }], sort: [{ required: true, message: "请输入序号", trigger: "blur" }], }, loadingZd: '', // 关联表 title: "", loading: false, open: false, form: {}, rules: { relationParentId: [{ required: true, message: "请选择关联表", trigger: "blur" }], relationChildId: [{ required: true, message: "请选择字段", trigger: "blur" }], relationType: [{ required: true, message: "请选择关联条件", trigger: "blur" }], }, postList: [], total: 1, tableList: {}, // 关联方式 // 内嵌编辑 genList: [], glbParams: { pageNum: 1, pageSize: 10, }, // 关联表查询参数 queryParams: { relationParentId: this.$route.params && this.$route.params.tableId, pageNum: 1, pageSize: 10, }, // 选中选项卡的 name activeName: "basic", // 表格的高度 tableHeight: document.documentElement.scrollHeight - 245 + "px", // 表信息 tables: [], // 表列信息 cloumns: [], // 字典信息 dictOptions: [], // 菜单信息 menus: [], // 表详细信息 info: {}, // 选中数组 ids: [], ids1: [], // 非单个禁用 single: true, single1: true, // 非多个禁用 multiple: true, multiple1: true, // 关联方式 relationType: [], // 内嵌编辑 embedEdit: [], }; }, filters: { zdFn(data) { let is = '' for (let item of _this.columList) { if (item.columnId == data) { is = item.columnName } } return is }, relationTypeFn(data) { let is = '' for (let item of _this.relationType) { if (item.dictValue == data) { is = item.dictLabel } } return is }, embedEditFn(data) { let is = '' for (let item of _this.embedEdit) { if (item.dictValue == data) { is = item.dictLabel } } return is }, }, created() { const tableId = this.$route.params && this.$route.params.tableId; if (tableId) { // 获取表详细信息 getGenTable(tableId).then(res => { this.cloumns = res.data.rows; this.info = res.data.info; this.tables = res.data.tables; }); //查询数据库sql tableSql(tableId).then(res => { if (res.data) { this.tableSqlData = res.data } }) /** 查询字典下拉列表 */ getDictOptionselect().then(response => { this.dictOptions = response.data; }); // 关联HR字段 genTableColumnList({ tableId, htmlType: 'HR' }).then(response => { this.columHRList = response.rows; }); // 关联字段 listAllColumnsByTableId({ tableId }).then(response => { this.columList = response.data; }); // 关联表数据 listTable(this.glbParams).then(response => { this.tableList = response; }); /** 查询菜单下拉列表 */ // getMenuTreeselect().then(response => { // this.menus = this.handleTree(response.data, "menuId"); // }); // 关联方式 this.getDicts("relation_type").then(response => { this.relationType = response.data; }); // 内嵌编辑 this.getDicts("embed_edit").then(response => { this.embedEdit = response.data; }); } this.tabList() }, methods: { tableBtn(row){ this.openquery = false this.ForeName = row.column_name this.formZd.foreignKey = row.column_id }, fkzdFn() { this.queryedit() this.getLisail() this.openquery = true }, changeFn(obj) { console.log(obj) for(let key in obj){ this.formquery.fixedData[key] = obj[key] } }, // 快速查询 queryedit(){ this.loading = true; tableQuery(this.queryLisr).then(response => { let data = response.data this.queryData = data this.loading = false; }) }, handleQuery(){ for(let item of this.queryData.queryList){ if(item.htmlType == 'checkbox' || item.htmlType == 'imageUpload' || item.htmlType == 'fileUpload'){ this.formquery[item.columnName] = this.$refs[item.columnName][0].config } else{ this.formquery[item.columnName] = this.$refs[item.columnName][0].config[item.columnName] } } this.aliemg.fixedData.condition = this.formquery this.getLisail() }, // 快速查询列表 getLisail() { this.loading = true; listIndexfou(this.aliemg).then(response => { if(response.data){ // this.tableDataalid = response.data.tableHeadList; this.postListquery = response.data this.postListquery.rows.filter(route => { if(route.table_id.name){ route.table_id = route.table_id.name } }) this.totalquery = response.data.total; } this.loading = false; } ); }, submitFormZd() { this.$refs["formZd"].validate(valid => { if (valid) { const tableId = this.$route.params && this.$route.params.tableId; this.formZd.tableId = tableId if (this.formZd.columnId != undefined) { setGenTableColumn(this.formZd).then(response => { this.msgSuccess("修改成功"); this.openZd = false; // 获取表详细信息 getGenTable(tableId).then(res => { this.cloumns = res.data.rows; this.info = res.data.info; this.tables = res.data.tables; }); }); } else { addGenTableColumn(this.formZd).then(response => { this.msgSuccess("新增成功"); this.openZd = false; // 获取表详细信息 getGenTable(tableId).then(res => { this.cloumns = res.data.rows; this.info = res.data.info; this.tables = res.data.tables; }); }); } } }); }, sxCreaBtn() { const tableId = this.$route.params && this.$route.params.tableId getReload({ tableId, createSql: this.tableSqlData.createSql, createLog: this.tableSqlData.createLog, id: this.tableSqlData.id }).then(res => { this.msgSuccess('刷新成功') //查询数据库sql tableSql(tableId).then(res => { if (res.data) { this.tableSqlData = res.data } }) }) }, zxCreaBtn() { const _this = this this.$confirm('是否确认执行创建语句?', "警告", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }).then(function() { return zxImplement({ tableId: _this.$route.params && _this.$route.params.tableId, createSql: _this.tableSqlData.createSql, createLog: _this.tableSqlData.createLog, id: _this.tableSqlData.id }) }).then(res => { _this.msgSuccess('执行成功') }) }, dbSelectedZd(row) { this.reset(); const id = row.columnId getByIdWithForeignKey(id).then(response => { let data = response.data data.foreignKey = data.foreignKey ? data.foreignKey - 0 : '' this.formZd = data; console.log(data,8890) if(data.fkInfo){ this.ForeName = data.fkInfo.value } this.openZd = true; this.title = "修改字段信息"; }); }, dbSelected(row) { this.reset(); const id = row.id qurGenTable(id).then(response => { let data = response.data data.relationType = data.relationType + "" data.embedEdit = data.embedEdit?(data.embedEdit + ""): data.embedEdit getGenTable(data.relationParentId).then(res => { this.genList = res.data.rows; this.form = data; this.open = true; this.title = "修改关联表"; }); }); }, addGlfn() { this.$refs["form"].validate(valid => { if (valid) { let datas = JSON.parse(JSON.stringify(this.form)) datas.relationParentId = this.info.tableId if (this.form.id != undefined) { setGenTable(datas).then(response => { this.msgSuccess("修改成功"); this.open = false; this.tabList(); }); } else { addGenTable(datas).then(response => { this.msgSuccess("新增成功"); this.open = false; this.tabList(); }); } } }); }, relationFn(data) { getGenTable(data).then(res => { this.genList = res.data.rows; }); }, loadMore() { const _this = this let num = _this.tableList.total % 10 == 0 ? _this.tableList.total / 10 : ((_this.tableList.total - _this.tableList .total % 10) / 10 + 1) console.log(num, 1) if (this.glbParams.pageNum < num) { this.glbParams.pageNum++ // 关联表数据 listTable(this.glbParams).then(response => { let data = response data.rows = _this.tableList.rows.concat(data.rows) _this.tableList = data; }); } }, // 取消按钮 cancel() { this.open = false; this.reset(); this.openZd = false; this.resetZd(); }, // 关联表数据 tabList() { this.loading = true; tabList(this.queryParams).then(response => { this.postList = response.rows; this.total = response.total; this.loading = false; }); }, /** 新增按钮操作 */ handleAdd_gl() { this.reset(); this.open = true; console.log(this.form) this.title = "新增关联表"; }, handleDel_gl(row) { const ids = row.id || this.ids1; console.log(ids, 1223) this.$confirm('是否确认删除id为"' + ids + '"的数据项?', "警告", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }).then(function() { return delGenTable(ids); }).then(() => { this.tabList(); this.msgSuccess("删除成功"); }) }, // 表单重置 reset() { this.form = { isDel: 'N' }; this.resetForm("form"); }, resetZd() { this.formZd = { columnId: '' }; this.resetForm("formZd"); }, /** 提交按钮 */ submitForm() { let isInFlag = 0 let isOutFlag = 0 console.log(this.cloumns,333) for(let item of this.cloumns){ if(item.isIn=='Y'){ isInFlag++ } if(item.isOut=='Y'){ isOutFlag++ } } if(isInFlag>1){ this.msgError('"输入字段"最多只能选择一个!') return } if(isOutFlag>1){ this.msgError('"显示字段"最多只能选择一个!') return } const basicForm = this.$refs.basicInfo.$refs.basicInfoForm; // const genForm = this.$refs.genInfo.$refs.genInfoForm; Promise.all([basicForm].map(this.getFormPromise)).then(res => { const validateResult = res.every(item => !!item); if (validateResult) { const genTable = Object.assign({}, basicForm.model); genTable.columns = this.cloumns; // genTable.params = { // treeCode: genTable.treeCode, // treeName: genTable.treeName, // treeParentCode: genTable.treeParentCode, // parentMenuId: genTable.parentMenuId // }; updateGenTable(genTable).then(res => { this.msgSuccess(res.msg); if (res.code === 200) { this.close(); } }); } else { this.msgError("表单校验未通过,请重新检查提交内容"); } }); }, getFormPromise(form) { return new Promise(resolve => { form.validate(res => { resolve(res); }); }); }, /** 关闭按钮 */ close() { this.$store.dispatch("tagsView/delView", this.$route); this.$router.push({ path: "/tool/gen", query: { t: Date.now() } }) }, // 多选框选中数据 handleSelectionChange(selection) { this.ids = selection.map(item => item.columnId) this.single = selection.length != 1 this.multiple = !selection.length }, // 多选框选中数据 handleSelectionChange1(selection) { this.ids1 = selection.map(item => item.id) this.single1 = selection.length != 1 this.multiple1 = !selection.length }, /** 删除按钮操作 */ handleDelete(row) { const ids = row.id || this.ids; const tableId = this.$route.params && this.$route.params.tableId; this.$confirm('是否确认删除字段编号为"' + ids + '"的数据项?', "警告", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }).then(function() { return delGenTableColumn(ids); }).then(() => { // 获取表详细信息 getGenTable(tableId).then(res => { this.cloumns = res.data.rows; this.info = res.data.info; this.tables = res.data.tables; }); this.msgSuccess("删除成功"); }) }, handleAdd() { this.resetZd(); this.openZd = true; this.title = "新增字段信息"; } }, mounted() { const el = this.$refs.dragTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0]; const sortable = Sortable.create(el, { handle: ".allowDrag", onEnd: evt => { const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0]; this.cloumns.splice(evt.newIndex, 0, targetRow); for (let index in this.cloumns) { this.cloumns[index].sort = parseInt(index) + 1; } } }); } }; </script> <style lang="scss"> .pagination-container { height: 35px; } .resizeNone { width: 60vw; border-radius: 3px; .el-textarea__inner { //el_input中的隐藏属性 resize: none; //主要是这个样式 height: 200px; } } </style>