ソースを参照

Merge remote-tracking branch 'origin/master'

侯茂昌 1 年間 前
コミット
70a21ab4d0

+ 4 - 0
ruoyi-ui/src/utils/index.js

@@ -421,3 +421,7 @@ export const $ = name => document.querySelector(name)
 
 export const getContainerSize = dom => ({ width: dom.getBoundingClientRect().width, height: dom.getBoundingClientRect().height })
 
+// 驼峰转下划线
+export function toUnderline(str = '') {
+  return str.replace(/([A-Z])/g, '_$1').toLowerCase()
+}

+ 37 - 27
ruoyi-ui/src/views/relateTable/components/RelateTableCard.vue

@@ -31,7 +31,6 @@
                     type="text"
                     icon="el-icon-edit"
                     @click="handleUpdate(scope.row)"
-
                   >修改
                   </el-button>
                 </el-dropdown-item>
@@ -98,6 +97,7 @@ import {inputDisableComplete} from "@/utils/other";
 import {dragGroupTableInfo} from "@/api/relateTable/index"
 
 import {camelCase} from "@/utils";
+import { async } from "@/components/updateModule/k-form-design/lib/k-form-design.common";
 export default {
   name: "RelateTableCard",
   props: ["cardData", "index", "tableKey", "sort"],
@@ -155,7 +155,6 @@ export default {
       preRow:{}
     };
   },
-
   computed: {
     // currentValues
     cardDataWatcher: function(){
@@ -200,7 +199,6 @@ export default {
     // 请求数据
     async gettableListHandler(tableKey, paramsContion = [], defaultVal ={}){
       const res = await dragTableInfo({queryMap: {tableKey : tableKey }})
-      console.log(123456);
       this.getTableHandle(res, paramsContion = [],defaultVal = {})
     },
     async getTableHandle(res){
@@ -222,7 +220,7 @@ export default {
           JSON.parse(this.templateInfo.template.dtColumnName)
         );
       
-        if (this.templateInfo !== {}) {
+        if (this.templateInfo) {
             this.tableCondition = this.templateInfo.querySql.tableCondition
             this.tableCondition = this.tableCondition.split('AND')
 
@@ -235,20 +233,21 @@ export default {
               this.queryParams.orderByColumn || ""
             );
             // 根据sql语句查询当前表数据
-           
-            if(this.newsort == 0){
-              this.getDataHandler()
-              // this.queryParams.queryMap.sqlkey = this.templateInfo.template.sqlKey;
-            }else{
+            this.contion = this.templateInfo.template.dtTableName + '.' + this.templateInfo.template.primaryKey
 
+            this.$nextTick(async ()=>{
+              if(this.newsort == 0){
+             await this.getDataHandler()
+            }else{
               if(this.myContion){
-                this.getDataHandler(this.myContion,this.preRow)
-              }
+                await this.getDataHandler(this.myContion,this.preRow)
+              } else {
+                // this.$emit('getDefaultCardData', this.index)
+              } 
             }
-            let k;
-             
-            // console.log('conditions', this.tableCondition);
-           this.contion = this.templateInfo.template.dtTableName + '.' + this.templateInfo.template.primaryKey
+            })
+            
+            // let k;
             // this.tableCondition.forEach((item, i) => {
             //   let val = item.split('=')
             //   if(i!==0){
@@ -269,20 +268,17 @@ export default {
       // console.log(contion);
       this.myContion=contion;
       this.preRow=list;
-      console.log(list);
+      // console.log(list);
       if(contion){
         let key = contion.split('.')
         this.queryParams.queryMap['#{' + contion] = "'" + list[key[1]] + "'";
       }
       this.queryParams.queryMap.sqlkey = this.templateInfo.template.sqlKey;
       
-      // contion?.forEach(item => {
-      //   this.queryParams.queryMap['#{' + item.key + '.' + item.value] = "'" + list[item.value] + "'";
-      // })
       this.tableList = [];
       let tableLists = await unionListTableData(this.queryParams)
       if(tableLists.code == 200){
-         
+        this.$emit('getDefaultCardData', this.index)
           tableLists.rows.forEach((item) => {
             this.tableList.push(item.resultMap);
           });
@@ -349,6 +345,9 @@ export default {
     getNextCardData(){
       this.handleCurrentChange(this.row)
     },
+    getDefaultCard(){
+      this.handleCurrentChange(this.tableList[0])
+    },
     // 使用提交数据类型的按钮获取数据
     tempSubBtn(getData) {
       getData()
@@ -360,7 +359,7 @@ export default {
         });
     },
      //提交编辑结果按钮回调
-     editConfirmHandler() {
+    editConfirmHandler() {
       this.$refs.addFromRef
         .getData()
         .then(async (values) => {
@@ -404,7 +403,11 @@ export default {
             }
           }
           // this.tableList = []
-          this.$emit('getChildData', this.index)
+          if(this.index == 0){
+            this.getDataHandler()
+          } else {
+            this.$emit('getChildData', this.index)
+          }
           // this.getDataHandler(this.contion, this.row)
           // this.gettableListHandler(this.tableKey)
           this.defaultValue = {};
@@ -419,25 +422,32 @@ export default {
     // 取消按钮
     cancel() {
       this.open = false;
+      this.defaultVal = {}
       // this.reset();
     },
     /** 修改按钮操作 */
     handleUpdate(row) {
-      console.log(row)
+      let obj = {}
+      for(let key in row) {
+        let modifiedTable = key.replace(/[A-Z]/g, (match) => `_${match}`).toLowerCase();
+        obj[modifiedTable] = row[key];
+      }
+
       getInfoBySqlKey(this.templateInfo.template.sqlKey).then(({data}) => {
         if (!data || !data.dfVueTemplate) {
           this.$message.error("当前表格未绑定表单!");
           return;
         }
-        Object.assign(this.defaultValue, row);
-
-        // console.log('123', this.defaultValue)
+        Object.assign(this.defaultValue, obj);
+        console.log(this.defaultValue)
         this.jsonData = JSON.parse(data.dfVueTemplate);
+        console.log('123', this.jsonData)
         this.open = true;
         this.title = "修改信息";
         // this.form.password = this.initPassword;
         this.$nextTick(() => {
-          this.$refs.addFromRef.setData(row);
+          console.log(this.$refs.addFromRef);
+          this.$refs.addFromRef.setData(obj);
         });
       });
       return;

+ 22 - 11
ruoyi-ui/src/views/relateTable/relateTableEdit.vue

@@ -12,6 +12,7 @@
               :ref="'childComponent' + index"
               @updateData="updateDataList"
               @getChildData="getChildData"
+              @getDefaultCardData="getDefaultCardData"
               :tableKey="cardData.tableKey"
               :sort="cardData.sort"
               :cardData="cardData"
@@ -161,21 +162,23 @@ export default {
       this.tableLists = JSON.parse(res.msg)
     },
     updateDataList(row,index) {
-      // let tableKey = this.tableLists[index+1].tableKey
+      if(index == 0){
+        this.tableLists.forEach((item, i) => {
+          if(i !== 0){
+            this.$refs['childComponent'+i][0].tableList = []
+            this.$refs['childComponent'+i][0].total = 0
+          }
+        })
+      }
       let beforeChild = this.$refs['childComponent'+index][0]
       index++
-      // console.log(beforeChild);
       const chlid = this.$refs['childComponent'+index][0]
-      // console.log(chlid);
       if(!chlid) return
-      // let contion = beforeChild.condition
-      // let tableList = beforeChild.tableList[0]
-      // console.log(contion,tableList);
       chlid.getDataHandler(beforeChild.contion,row)
     },
-    // 
+    // 新增数据调用
     getChildData(index) {
-      console.log(index);
+      // console.log(index);
       let targetRef = 'childComponent'
       if(index == 0){
         targetRef += index
@@ -183,11 +186,19 @@ export default {
         targetRef += (index - 1)
       }
       this.$nextTick(()=>{
-        console.log( this.$refs[targetRef][0]);
-
         this.$refs[targetRef][0].getNextCardData()
       })
-    }
+    },
+    getDefaultCardData(index){
+      let currentChild = this.$refs['childComponent'+index][0]
+
+      this.$nextTick(() => {
+        
+        let nextChild = this.$refs['childComponent' + (index+1)][0]
+
+        nextChild.getDataHandler(currentChild.contion, currentChild.tableList[0])
+      })
+    },
   },
 };
 </script>