Browse Source

Merge branch 'lph'

lph 1 year ago
parent
commit
4f860262ad

+ 2 - 2
ruoyi-ui/.env.development

@@ -11,7 +11,7 @@ VUE_APP_BASE_API = '/dev-api'
 VUE_CLI_BABEL_TRANSPILE_MODULES = true
 
 #数据引擎模块IP
-VUE_APP_BASE_API2 = 'http://192.168.110.52:8099/'
+VUE_APP_BASE_API2 = 'http://192.168.110.70:8099/'
 
 #表单引擎模块IP
-VUE_APP_BASE_API3 = 'http://192.168.110.52:8088/'
+VUE_APP_BASE_API3 = 'http://192.168.110.70:8088/'

+ 188 - 82
ruoyi-ui/src/views/tableMange/index.vue

@@ -51,6 +51,9 @@
               width="50"
               class-name="allowDrag"
             >
+              <!-- <template slot-scope="scope">
+                <el-input v-model="scope.row.fieldDescription"></el-input>
+              </template> -->
             </el-table-column>
             <el-table-column prop="fieldName" label="数据字段">
             </el-table-column>
@@ -121,7 +124,7 @@
                 </el-select>
               </template>
             </el-table-column>
-            <el-table-column prop="relationShowField" label="关联显示字段">
+            <!-- <el-table-column prop="relationShowField" label="关联显示字段">
               <template slot-scope="scope">
                 <el-select
                   v-model="scope.row.relationShowField"
@@ -140,7 +143,7 @@
                   </el-option>
                 </el-select>
               </template>
-            </el-table-column>
+            </el-table-column> -->
             <el-table-column prop="isShow" label="是否显示">
               <template slot-scope="scope">
                 <el-switch v-model="scope.row.isShow"> </el-switch>
@@ -595,6 +598,7 @@ export default {
             isSearch: false,
             isExport: true,
             relationTableList: this.relationTableList,
+            tableName: this.tableName,
             children: [],
           };
         });
@@ -623,14 +627,29 @@ export default {
           fieldDescription: item.fieldDescription,
         };
       });
+      let relationTableList = row.relationTableList.filter(
+        (item) => row.relationTable != item.tableName
+      );
       row.children = row.relaFieldNameList.map((item, index) => {
         return {
           id: row.relationTable + " " + item.fieldName,
           fieldName: item.fieldName,
           fieldDescription: item.fieldDescription,
-          isSearch: false,
+          relationTable: "",
+          relationFieldName: "",
+          relaFieldNameList: [],
+          disableRelaFieldName: false,
+          relationType: "",
+          relationShowField: [],
+          relationShowFiledList: [],
+          disableRelaType: false,
           isShow: true,
+          isSearch: false,
           isExport: true,
+          relationTableList,
+          tableName: row.relationTable,
+          children: [],
+          isChildren: true,
         };
       });
       row.disableRelaFieldName = true;
@@ -704,58 +723,84 @@ export default {
     // 获取路由表单数据
     async getMenuList() {
       let res = await getMenuList();
-      console.log(res);
       this.menus = this.handleTree(res.data, "menuId");
     },
+    // 校验字段合法性
+    validateField(tableFieldList, validateParams) {
+      if (!tableFieldList.length) {
+        return;
+      }
+      for (let i = 0; i < tableFieldList.length; i++) {
+        let temp = tableFieldList[i];
+        if (!temp.fieldDescription.trim() && temp.isShow) {
+          //描述字段不能为空
+          validateParams.isFieldDescrib = true;
+        }
+        if (temp.children.length) {
+          this.validateField(temp.children, validateParams);
+        }
+      }
+    },
+    // 递归拼接查询语句
+    getSQLString(tableFieldList, fieldArr, tableArr) {
+      for (let i = 0; i < tableFieldList.length; i++) {
+        let temp = tableFieldList[i];
+        if (temp.isShow) {
+          // console.log("字段描述:", temp.fieldDescription);
+          // if (!temp.fieldDescription) {
+          //   console.log("有空的字段描述");
+          //   //字段描述不能为空
+          //   return true;
+          // }
+          let tempArr = temp.tableName + "." + temp.fieldName;
+          if (temp.isChildren) {
+            tempArr += " as " + temp.tableName + "_" + temp.fieldName;
+          }
+          fieldArr.push(tempArr);
+        }
+        if (temp.relationTable && temp.relationFieldName && temp.relationType) {
+          // fieldArr.push(temp.relationTable + "." + temp.relationFieldName);
+          tableArr.push(
+            temp.relationType +
+              " " +
+              temp.relationTable +
+              " AS " +
+              temp.relationTable +
+              " ON " +
+              temp.relationTable +
+              "." +
+              temp.relationFieldName +
+              " = " +
+              temp.tableName +
+              "." +
+              temp.fieldName
+          );
+        }
+        if (temp.children.length) {
+          this.getSQLString(temp.children, fieldArr, tableArr);
+        }
+      }
+    },
     // 拼接查询sql语句
     getSQLStr() {
-      let sqlType = this.databaseType;
+      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);
+      this.getSQLString(this.tableFieldList, fieldNameArr, relaTypeArr);
+      // console.log("discriISEmpty:", discriISEmpty);
+      // if (discriISEmpty) {
+      //   return false;
+      // }
 
-          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 +
+        this.tableName +
         " AS " +
-        mainTableName;
+        this.tableName;
       if (relaTypeArr.length) {
         sql += " " + relaTypeArr.join(" ");
       }
@@ -775,42 +820,83 @@ export default {
       });
       return resArr;
     },
-    // 获取列表信息
-    getColumns() {
-      let columns = [];
-      this.tableFieldList.forEach((item) => {
-        if (item.isShow) {
+    // 递归获取列表信息
+    getCol(
+      tableFieldList,
+      columns,
+      searchFieldList = [],
+      tableExportField = {}
+    ) {
+      if (!tableFieldList.length) return;
+      for (let i = 0; i < tableFieldList.length; i++) {
+        let temp = tableFieldList[i];
+        if (temp.isShow) {
           let tempObj = {};
-          tempObj[item.fieldName] = item.fieldDescription;
+          tempObj[temp.fieldName] = temp.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);
-              });
-          }
         }
-      });
+        if (temp.isSearch) {
+          searchFieldList.push(temp.fieldName);
+        }
+        if (temp.isExport) {
+          tableExportField[temp.fieldName] = temp.fieldDescription;
+        }
+        if (temp.children) {
+          this.getCol(
+            temp.children,
+            columns,
+            searchFieldList,
+            tableExportField
+          );
+        }
+      }
+    },
+    // 获取列表信息
+    getColumns() {
+      let columns = [];
+      this.getCol(this.tableFieldList, 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("请选择数据表");
+            return;
+          }
+          // 检验表单合法性
+          let validateParams = {
+            isFieldDescrib: false,
+          };
+          this.validateField(this.tableFieldList, validateParams);
+          console.log(validateParams);
+          if (validateParams.isFieldDescrib) {
+            this.$message.error("需要显示的字段描述不能为空");
+            return;
           }
           // 拼接预览的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);
@@ -832,38 +918,58 @@ export default {
     async createHandle() {
       this.$refs.formData.validate(async (valid) => {
         if (valid) {
+          // 检验表单合法性
+          let validateParams = {
+            isFieldDescrib: false,
+          };
+          this.validateField(this.tableFieldList, validateParams);
+          console.log(validateParams);
+          if (validateParams.isFieldDescrib) {
+            this.$message.error("需要显示的字段描述不能为空");
+            return;
+          }
+
           let uuid = uuidv4();
+          let columns = [],
+            searchFieldList = [],
+            tableExportField = {};
+          this.getCol(
+            this.tableFieldList,
+            columns,
+            searchFieldList,
+            tableExportField
+          );
           let data = {
             dtName: this.formData.menuName,
             tableKey: this.formData.routePath, //  暂定
             dtTableName: this.tableName,
             sqlKey: uuid,
-            dtColumnName: [], //列字段标题名称(存储显示字段信息
+            dtColumnName: columns, //列字段标题名称(存储显示字段信息
             timeFormat: this.formData.timeFormate,
-            searchFieldList: [], //搜索字段数组
+            searchFieldList: searchFieldList, //搜索字段数组
             tableSql: this.getSQLStr(), //  暂定
-            tableExportField: {}, //导出字段名及列名
+            tableExportField: tableExportField, //导出字段名及列名
           };
-          this.tableFieldList.forEach((item) => {
-            if (item.isShow) {
-              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);
-            }
-            if (item.isExport) {
-              data.tableExportField[item.fieldName] = item.fieldDescription;
-            }
-          });
+          // this.tableFieldList.forEach((item) => {
+          //   if (item.isShow) {
+          //     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);
+          //   }
+          //   if (item.isExport) {
+          //     data.tableExportField[item.fieldName] = item.fieldDescription;
+          //   }
+          // });
           if (!data.searchFieldList.length) {
             this.$message.warning("请至少选择一个包含查询字段");
             return false;

+ 63 - 34
ruoyi-ui/src/views/tablelist/commonTable/listInfo.vue

@@ -38,7 +38,7 @@
             :underline="false"
             style="font-size: 12px; vertical-align: baseline"
             @click="importTemplate"
-          >下载模板
+            >下载模板
           </el-link>
         </div>
       </el-upload>
@@ -60,7 +60,7 @@
           icon="el-icon-plus"
           size="mini"
           @click="handleAdd"
-        >新增
+          >新增
         </el-button>
       </el-col>
       <el-col :span="1.5">
@@ -71,7 +71,7 @@
           size="mini"
           :disabled="single"
           @click="handleUpdate"
-        >修改
+          >修改
         </el-button>
       </el-col>
       <el-col :span="1.5">
@@ -82,7 +82,7 @@
           size="mini"
           :disabled="multiple"
           @click="handleDelete"
-        >删除
+          >删除
         </el-button>
       </el-col>
       <el-col :span="1.5">
@@ -91,7 +91,7 @@
           icon="el-icon-upload2"
           size="mini"
           @click="upload.open = true"
-        >导入
+          >导入
         </el-button>
       </el-col>
       <el-col :span="1.5">
@@ -101,7 +101,7 @@
           icon="el-icon-download"
           size="mini"
           @click="handleExport"
-        >导出
+          >导出
         </el-button>
       </el-col>
       <right-toolbar
@@ -114,10 +114,17 @@
       :data="tableList"
       @selection-change="handleSelectionChange"
     >
-      <el-table-column type="selection" width="55" align="center"/>
-      <span v-for="(key, val) in columns" :key="key">
-        <el-table-column :label="key" align="center" :prop="val"/>
-      </span>
+      <el-table-column type="selection" width="55" align="center" />
+      <!-- <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"
@@ -129,14 +136,14 @@
             type="text"
             icon="el-icon-edit"
             @click="handleUpdate(scope.row)"
-          >修改
+            >修改
           </el-button>
           <el-button
             size="mini"
             type="text"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
-          >删除
+            >删除
           </el-button>
         </template>
       </el-table-column>
@@ -180,12 +187,12 @@ import {
   getInfoBySqlKey,
   addTableData,
 } from "@/api/tablelist/commonTable";
-import {getToken} from "@/utils/auth";
+import { getToken } from "@/utils/auth";
 import Queryfrom from "@/views/tablelist/commonTable/queryfrom.vue";
 
 export default {
   name: "listInfo",
-  components: {Queryfrom},
+  components: { Queryfrom },
   data() {
     return {
       // 遮罩层
@@ -222,7 +229,7 @@ export default {
         // 是否更新已经存在的数据
         updateSupport: 0,
         // 设置上传的请求头部
-        headers: {Authorization: "Bearer " + getToken()},
+        headers: { Authorization: "Bearer " + getToken() },
         // 上传的地址
         url: process.env.VUE_APP_BASE_API3 + "common/uploadData",
       },
@@ -270,13 +277,34 @@ export default {
     this.sqlkey = this.$route.query.sqlkey;
   },
   methods: {
+    // 下划线命名转驼峰命名
+    toUpperCase(str) {
+      let nstr = str.replace(/(?:_)+([^_])/g, function ($0, $1) {
+        return $1.toUpperCase();
+      });
+      nstr = nstr.replace(nstr[0], nstr[0].toLowerCase());
+      return nstr;
+    },
+    // 处理列表信息
+    columnsHandler(columns) {
+      let resArr = [];
+      columns.forEach((item) => {
+        for (const key in item) {
+          let tempObj = {};
+          tempObj.key = this.toUpperCase(key);
+          tempObj.value = item[key];
+          resArr.push(tempObj);
+        }
+      });
+      return resArr;
+    },
     /** 查询列表 */
     getList(queryParams) {
       this.loading = true;
       // 序列化当前查询参数列表
       this.queryParams.queryMap = queryParams.queryMap;
       // 获取当前表单结构信息
-      dragTableInfo({queryMap: {sqlkey: this.sqlkey}})
+      dragTableInfo({ queryMap: { sqlkey: this.sqlkey } })
         .then((res) => {
           // 得到当前模版信息 --- sql columns queryWhere
           this.templateInfo = res.data.resultMap;
@@ -285,14 +313,16 @@ export default {
           // 得到查询条件
           this.queryFromWhere = res.data.resultMap.where;
           //  得到当前列表信息
-          let test = []
+          let test = [];
           test = JSON.parse(this.templateInfo.template.dtColumnName);
-          test.forEach(item => {
-            this.columns = {
-              ...this.columns,
-              ...item,
-            }
-          })
+          this.columns = this.columnsHandler(test);
+          // test.forEach((item) => {
+          //   this.columns = {
+          //     ...this.columns,
+          //     ...item,
+          //   };
+          // });
+          console.log(this.columns);
         })
         .finally((fes) => {
           if (this.templateInfo == {}) return;
@@ -321,9 +351,9 @@ export default {
       this.$refs.mychild.pageList(
         row == undefined
           ? {
-            limit: this.queryParams.pageSize,
-            page: this.queryParams.pageNum,
-          }
+              limit: this.queryParams.pageSize,
+              page: this.queryParams.pageNum,
+            }
           : row
       );
     },
@@ -351,7 +381,7 @@ export default {
     handleAdd(row) {
       // this.reset();
       this.defaultValue = {};
-      getInfoBySqlKey(this.sqlkey).then(({data}) => {
+      getInfoBySqlKey(this.sqlkey).then(({ data }) => {
         const htmlCode = data.dfHtmlTemplate;
         this.iframeUrl = "data:text/html;charset=utf-8," + encodeURI(htmlCode);
         this.jsonData = JSON.parse(data.dfVueTemplate);
@@ -365,7 +395,7 @@ export default {
     },
     /** 修改按钮操作 */
     handleUpdate(row) {
-      getInfoBySqlKey(this.sqlkey).then(({data}) => {
+      getInfoBySqlKey(this.sqlkey).then(({ data }) => {
         const htmlCode = data.dfHtmlTemplate;
         this.iframeUrl = "data:text/html;charset=utf-8," + encodeURI(htmlCode);
         Object.assign(this.defaultValue, row);
@@ -444,8 +474,7 @@ export default {
           this.$refs.mychild.pageList();
           this.$modal.msgSuccess("删除成功");
         })
-        .catch(() => {
-        });
+        .catch(() => {});
     },
     /** 导出按钮操作 */
     handleExport() {
@@ -478,7 +507,7 @@ export default {
     importTemplate() {
       this.download(
         process.env.VUE_APP_BASE_API3 +
-        `dragform/common/exportTemplate?tableName=${this.tableName}&sqlkey=${this.sqlkey}`,
+          `dragform/common/exportTemplate?tableName=${this.tableName}&sqlkey=${this.sqlkey}`,
         {},
         `下载模版名称${new Date().getTime()}.xlsx`
       );
@@ -494,10 +523,10 @@ export default {
       this.$refs.upload.clearFiles();
       this.$alert(
         "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
-        response.msg +
-        "</div>",
+          response.msg +
+          "</div>",
         "导入结果",
-        {dangerouslyUseHTMLString: true}
+        { dangerouslyUseHTMLString: true }
       );
       this.$refs.mychild.pageList({
         limit: this.queryParams.pageSize,

+ 1 - 1
ruoyi-ui/vue.config.js

@@ -35,7 +35,7 @@ module.exports = {
     proxy: {
       // detail: https://cli.vuejs.org/config/#devserver-proxy
       [process.env.VUE_APP_BASE_API]: {
-        target: `http://192.168.110.52:8080`,
+        target: `http://192.168.110.70:8080`,
         changeOrigin: true,
         pathRewrite: {
           ['^' + process.env.VUE_APP_BASE_API]: ''