suochencheng 7 роки тому
батько
коміт
4e440bf33a

+ 10 - 0
src/main/java/com/izouma/awesomeadmin/model/TableField.java

@@ -146,6 +146,8 @@ public class TableField {
 
     private String optionsValue;
 
+    private Boolean logicalKey;
+
 
     public void setId(Integer id) {
         this.id = id;
@@ -370,5 +372,13 @@ public class TableField {
     public void setOptionsValue(String optionsValue) {
         this.optionsValue = optionsValue;
     }
+
+    public Boolean getLogicalKey() {
+        return logicalKey;
+    }
+
+    public void setLogicalKey(Boolean logicalKey) {
+        this.logicalKey = logicalKey;
+    }
 }
 

+ 1 - 1
src/main/java/com/izouma/awesomeadmin/util/DatabaseUtil.java

@@ -44,7 +44,7 @@ public class DatabaseUtil {
                 url = "jdbc:sqlserver://" + dataSourceInfo.getUrl() + ";DatabaseName=" + dataSourceInfo.getDatabaseName();
                 user = dataSourceInfo.getUsername();
                 password = dataSourceInfo.getPassword();
-                sql = "select * from sys.tables order by name";
+                sql = "select * from sysobjects where xtype='U' OR  xtype='V'  order by  xtype , name";
             }
 
         }

+ 47 - 1
src/main/resources/templates/FormTemplate.vm

@@ -272,12 +272,58 @@
             onSave() {
                 this.${esc.d}refs.form.validate((valid) => {
                     if (valid) {
-                        this.submit();
+                        this.logicalValidate();
                     } else {
                         return false;
                     }
                 });
             },
+            logicalValidate() {
+                var data = JSON.parse(JSON.stringify(this.formData));
+
+                var logicalData = {
+                #foreach($field in $model.fields)
+                    #if(${field.logicalKey})
+                        ${field.modelName}:data.${field.modelName},
+                    #end
+                #end
+            }
+
+                if (JSON.stringify(logicalData) == '{}') {
+                    this.submit();
+                } else {
+                    this.${esc.d}http.get({
+                        url: '/${display.uncapitalize($model.className)}/getOne',
+                        data: logicalData
+                    }).then(res => {
+                        if (res.success) {
+
+                            var logicalFlag = true;
+
+                            if (res.data) {
+                                if (this.formData.id) {
+                                    if (res.data.id != this.formData.id) {
+                                        logicalFlag = false;
+                                    }
+                                } else {
+                                    logicalFlag = false;
+                                }
+
+                            }
+
+                            if (logicalFlag) {
+                                this.submit();
+                            } else {
+                                this.${esc.d}message.warning('逻辑关键字:'+'#foreach($field in $model.fields)#if(${field.logicalKey})${field.remark},#end#end'+'验证失败')
+                            }
+
+
+                        } else {
+                            this.${esc.d}message.warning('逻辑关键字:'+'#foreach($field in $model.fields)#if(${field.logicalKey})${field.remark},#end#end'+'验证失败')
+                        }
+                    });
+                }
+            },
             submit() {
                 var data = JSON.parse(JSON.stringify(this.formData));
                 this.${esc.d}http.post({

+ 6 - 1
src/main/vue/src/pages/GenCode.vue

@@ -59,7 +59,7 @@
                 <el-tabs value="1" type="border-card">
                     <el-tab-pane label="字段" name="1">
                         <el-table :data="fields">
-                            <el-table-column prop="name" label="字段名" align="center">
+                            <el-table-column prop="name" label="字段名" min-width="100" align="center">
                                 <template slot-scope="{row}">
                                     <el-input v-model="row.name"></el-input>
                                 </template>
@@ -170,6 +170,11 @@
                         <el-table :data="fields">
                             <el-table-column prop="name" label="字段" align="center">
                             </el-table-column>
+                            <el-table-column prop="logicalKey" label="逻辑关键字"  align="center">
+                                <template slot-scope="{row}">
+                                    <el-checkbox v-model="row.logicalKey"></el-checkbox>
+                                </template>
+                            </el-table-column>
                             <el-table-column prop="required" label="必填" width="50" align="center">
                                 <template slot-scope="{row}">
                                     <el-checkbox v-model="row.required"></el-checkbox>