Browse Source

fix:优化共通table模版驼峰穿参,登录不再切换数据源

韩帛霖 1 year ago
parent
commit
e0cc6d51e2

+ 2 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java

@@ -104,9 +104,9 @@ public class SysLoginController {
             DataSource dataSource = dataSourceService.selectById(sysTenant.getDatasourceId());
             DataSource dataSource = dataSourceService.selectById(sysTenant.getDatasourceId());
             ajax.put("dataSource", dataSource);
             ajax.put("dataSource", dataSource);
             //调用数据引擎服务切换数据源接口
             //调用数据引擎服务切换数据源接口
-            restTemplate.postForEntity(DATA_ENGINE_IP, dataSource, DataSource.class);
+            // restTemplate.postForEntity(DATA_ENGINE_IP, dataSource, DataSource.class);
             //调用表单引擎服务切换数据源接口
             //调用表单引擎服务切换数据源接口
-            restTemplate.postForEntity(DRAG_FORM_IP, dataSource, DataSource.class);
+            // restTemplate.postForEntity(DRAG_FORM_IP, dataSource, DataSource.class);
         }
         }
         return ajax;
         return ajax;
     }
     }

+ 61 - 31
ruoyi-ui/src/views/tablelist/commonTable/listInfo.vue

@@ -16,7 +16,7 @@
           '?updateSupport=' +
           '?updateSupport=' +
           upload.updateSupport +
           upload.updateSupport +
           '&tableName=' +
           '&tableName=' +
-          tableName
+          tableName+'&sqlKey=' + sqlkey
         "
         "
         :disabled="upload.isUploading"
         :disabled="upload.isUploading"
         :on-progress="handleFileUploadProgress"
         :on-progress="handleFileUploadProgress"
@@ -38,7 +38,7 @@
             :underline="false"
             :underline="false"
             style="font-size: 12px; vertical-align: baseline"
             style="font-size: 12px; vertical-align: baseline"
             @click="importTemplate"
             @click="importTemplate"
-            >下载模板
+          >下载模板
           </el-link>
           </el-link>
         </div>
         </div>
       </el-upload>
       </el-upload>
@@ -60,7 +60,7 @@
           icon="el-icon-plus"
           icon="el-icon-plus"
           size="mini"
           size="mini"
           @click="handleAdd"
           @click="handleAdd"
-          >新增
+        >新增
         </el-button>
         </el-button>
       </el-col>
       </el-col>
       <el-col :span="1.5">
       <el-col :span="1.5">
@@ -71,7 +71,7 @@
           size="mini"
           size="mini"
           :disabled="single"
           :disabled="single"
           @click="handleUpdate"
           @click="handleUpdate"
-          >修改
+        >修改
         </el-button>
         </el-button>
       </el-col>
       </el-col>
       <el-col :span="1.5">
       <el-col :span="1.5">
@@ -82,7 +82,7 @@
           size="mini"
           size="mini"
           :disabled="multiple"
           :disabled="multiple"
           @click="handleDelete"
           @click="handleDelete"
-          >删除
+        >删除
         </el-button>
         </el-button>
       </el-col>
       </el-col>
       <el-col :span="1.5">
       <el-col :span="1.5">
@@ -91,7 +91,7 @@
           icon="el-icon-upload2"
           icon="el-icon-upload2"
           size="mini"
           size="mini"
           @click="upload.open = true"
           @click="upload.open = true"
-          >导入
+        >导入
         </el-button>
         </el-button>
       </el-col>
       </el-col>
       <el-col :span="1.5">
       <el-col :span="1.5">
@@ -101,7 +101,7 @@
           icon="el-icon-download"
           icon="el-icon-download"
           size="mini"
           size="mini"
           @click="handleExport"
           @click="handleExport"
-          >导出
+        >导出
         </el-button>
         </el-button>
       </el-col>
       </el-col>
       <right-toolbar
       <right-toolbar
@@ -114,7 +114,7 @@
       :data="tableList"
       :data="tableList"
       @selection-change="handleSelectionChange"
       @selection-change="handleSelectionChange"
     >
     >
-      <el-table-column type="selection" width="55" align="center" />
+      <el-table-column type="selection" width="55" align="center"/>
       <!-- <span v-for="(key, val) in columns" :key="key">
       <!-- <span v-for="(key, val) in columns" :key="key">
         <el-table-column :label="key" align="center" :prop="val" />
         <el-table-column :label="key" align="center" :prop="val" />
       </span> -->
       </span> -->
@@ -136,14 +136,14 @@
             type="text"
             type="text"
             icon="el-icon-edit"
             icon="el-icon-edit"
             @click="handleUpdate(scope.row)"
             @click="handleUpdate(scope.row)"
-            >修改
+          >修改
           </el-button>
           </el-button>
           <el-button
           <el-button
             size="mini"
             size="mini"
             type="text"
             type="text"
             icon="el-icon-delete"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
             @click="handleDelete(scope.row)"
-            >删除
+          >删除
           </el-button>
           </el-button>
         </template>
         </template>
       </el-table-column>
       </el-table-column>
@@ -188,12 +188,12 @@ import {
   addTableData,
   addTableData,
   batchEdit,
   batchEdit,
 } from "@/api/tablelist/commonTable";
 } from "@/api/tablelist/commonTable";
-import { getToken } from "@/utils/auth";
+import {getToken} from "@/utils/auth";
 import Queryfrom from "@/views/tablelist/commonTable/queryfrom.vue";
 import Queryfrom from "@/views/tablelist/commonTable/queryfrom.vue";
 
 
 export default {
 export default {
   name: "listInfo",
   name: "listInfo",
-  components: { Queryfrom },
+  components: {Queryfrom},
   data() {
   data() {
     return {
     return {
       // 遮罩层
       // 遮罩层
@@ -230,7 +230,7 @@ export default {
         // 是否更新已经存在的数据
         // 是否更新已经存在的数据
         updateSupport: 0,
         updateSupport: 0,
         // 设置上传的请求头部
         // 设置上传的请求头部
-        headers: { Authorization: "Bearer " + getToken() },
+        headers: {Authorization: "Bearer " + getToken()},
         // 上传的地址
         // 上传的地址
         url: process.env.VUE_APP_BASE_API3 + "common/uploadData",
         url: process.env.VUE_APP_BASE_API3 + "common/uploadData",
       },
       },
@@ -279,12 +279,40 @@ export default {
   },
   },
   methods: {
   methods: {
     // 下划线命名转驼峰命名
     // 下划线命名转驼峰命名
-    toUpperCase(str) {
-      let nstr = str.replace(/(?:_)+([^_])/g, function ($0, $1) {
-        return $1.toUpperCase();
-      });
-      nstr = nstr.replace(nstr[0], nstr[0].toLowerCase());
-      return nstr;
+    toUnderScoreCase(str) {
+      if (str === null) {
+        return null;
+      }
+      let sb = '';
+      // 前置字符是否大写
+      let preCharIsUpperCase = true;
+      // 当前字符是否大写
+      let curreCharIsUpperCase = true;
+      // 下一字符是否大写
+      let nexteCharIsUpperCase = true;
+      for (let i = 0; i < str.length; i++) {
+        let c = str.charAt(i);
+        if (i > 0) {
+          preCharIsUpperCase = isUpperCase(str.charAt(i - 1));
+        } else {
+          preCharIsUpperCase = false;
+        }
+
+        curreCharIsUpperCase = isUpperCase(c);
+
+        if (i < (str.length - 1)) {
+          nexteCharIsUpperCase = isUpperCase(str.charAt(i + 1));
+        }
+
+        if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
+          sb += SEPARATOR;
+        } else if ((i !== 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
+          sb += SEPARATOR;
+        }
+        sb += c.toLowerCase();
+      }
+
+      return sb;
     },
     },
     // 处理列表信息
     // 处理列表信息
     columnsHandler(columns) {
     columnsHandler(columns) {
@@ -292,7 +320,7 @@ export default {
       columns.forEach((item) => {
       columns.forEach((item) => {
         for (const key in item) {
         for (const key in item) {
           let tempObj = {};
           let tempObj = {};
-          tempObj.key = this.toUpperCase(key);
+          tempObj.key = this.toUnderScoreCase(key);
           tempObj.value = item[key];
           tempObj.value = item[key];
           resArr.push(tempObj);
           resArr.push(tempObj);
         }
         }
@@ -305,7 +333,7 @@ export default {
       // 序列化当前查询参数列表
       // 序列化当前查询参数列表
       queryParams && (this.queryParams.queryMap = queryParams.queryMap);
       queryParams && (this.queryParams.queryMap = queryParams.queryMap);
       // 获取当前表单结构信息
       // 获取当前表单结构信息
-      dragTableInfo({ queryMap: { sqlkey: this.sqlkey } })
+      dragTableInfo({queryMap: {sqlkey: this.sqlkey}})
         .then((res) => {
         .then((res) => {
           // 得到当前模版信息 --- sql columns queryWhere
           // 得到当前模版信息 --- sql columns queryWhere
           this.templateInfo = res.data.resultMap;
           this.templateInfo = res.data.resultMap;
@@ -331,6 +359,7 @@ export default {
           if (this.templateInfo == {}) return;
           if (this.templateInfo == {}) return;
           // 调用查询需要携带当前table的唯一标识
           // 调用查询需要携带当前table的唯一标识
           this.queryParams.queryMap.sqlkey = this.sqlkey;
           this.queryParams.queryMap.sqlkey = this.sqlkey;
+          this.queryParams.orderByColumn = this.toUnderScoreCase(this.queryParams.orderByColumn);
           // 根据sql语句查询当前表数据
           // 根据sql语句查询当前表数据
           unionListTableData(this.queryParams).then((res) => {
           unionListTableData(this.queryParams).then((res) => {
             this.tableList = [];
             this.tableList = [];
@@ -354,9 +383,9 @@ export default {
       this.$refs.mychild.pageList(
       this.$refs.mychild.pageList(
         row == undefined
         row == undefined
           ? {
           ? {
-              limit: this.queryParams.pageSize,
-              page: this.queryParams.pageNum,
-            }
+            limit: this.queryParams.pageSize,
+            page: this.queryParams.pageNum,
+          }
           : row
           : row
       );
       );
     },
     },
@@ -386,7 +415,7 @@ export default {
     handleAdd(row) {
     handleAdd(row) {
       // this.reset();
       // this.reset();
       this.defaultValue = {};
       this.defaultValue = {};
-      getInfoBySqlKey(this.sqlkey).then(({ data }) => {
+      getInfoBySqlKey(this.sqlkey).then(({data}) => {
         // const htmlCode = data.dfHtmlTemplate;
         // const htmlCode = data.dfHtmlTemplate;
         // this.iframeUrl = "data:text/html;charset=utf-8," + encodeURI(htmlCode);
         // this.iframeUrl = "data:text/html;charset=utf-8," + encodeURI(htmlCode);
         if (!data || !data.dfVueTemplate) {
         if (!data || !data.dfVueTemplate) {
@@ -404,7 +433,7 @@ export default {
     },
     },
     /** 修改按钮操作 */
     /** 修改按钮操作 */
     handleUpdate(row) {
     handleUpdate(row) {
-      getInfoBySqlKey(this.sqlkey).then(({ data }) => {
+      getInfoBySqlKey(this.sqlkey).then(({data}) => {
         // const htmlCode = data.dfHtmlTemplate;
         // const htmlCode = data.dfHtmlTemplate;
         // this.iframeUrl = "data:text/html;charset=utf-8," + encodeURI(htmlCode);
         // this.iframeUrl = "data:text/html;charset=utf-8," + encodeURI(htmlCode);
         if (!data || !data.dfVueTemplate) {
         if (!data || !data.dfVueTemplate) {
@@ -488,7 +517,8 @@ export default {
           this.$refs.mychild.pageList();
           this.$refs.mychild.pageList();
           this.$modal.msgSuccess("删除成功");
           this.$modal.msgSuccess("删除成功");
         })
         })
-        .catch(() => {});
+        .catch(() => {
+        });
     },
     },
     /** 导出按钮操作 */
     /** 导出按钮操作 */
     handleExport() {
     handleExport() {
@@ -521,7 +551,7 @@ export default {
     importTemplate() {
     importTemplate() {
       this.download(
       this.download(
         process.env.VUE_APP_BASE_API3 +
         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`
         `下载模版名称${new Date().getTime()}.xlsx`
       );
       );
@@ -537,10 +567,10 @@ export default {
       this.$refs.upload.clearFiles();
       this.$refs.upload.clearFiles();
       this.$alert(
       this.$alert(
         "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
         "<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({
       this.$refs.mychild.pageList({
         limit: this.queryParams.pageSize,
         limit: this.queryParams.pageSize,