Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
layui.define([ 'form', 'laydate', 'table','codeApi'], function(exports) {
    var form = layui.form;
    var codeApi = layui.codeApi;
    var index = layui.index;
    var view = {
            init:function(){
                Lib.initGenrealForm($("#updateForm"),form);
                this.initSubmit();
            },
            initSubmit:function(){
                var that = this;
                toolbar = {
                        html:function() { //获取选中数据
                            codeApi.previewHtml(function(data){
                                that.openCode(data)
                            });
                        },
                        js:function() { //获取选中数目
                            codeApi.previewJs(function(data){
                                that.openCode(data)
                            });
                            
                        },
                        java:function() { //获取选中数目
                            codeApi.previewJava(function(data){
                                that.openCode(data)
                            });
                            
                        },
                        sql:function() { //获取选中数目
                            codeApi.previewSql(function(data){
                                that.openCode(data)
                            });
                            
                        },
                        gen:function(){
                            codeApi.gen(function(){
                                Common.info("代码生成成功,请刷新工程");
                                
                            });
                        },
                        cancel:function(){
                            Lib.closeFrame();
                        }
                        
                    };
                $('.ext-toolbar').on('click', function() {
                    var type = $(this).data('type');
                    toolbar[type] ? toolbar[type].call(this) : '';
                });
                
                $(".addVerify").click(function(){
                        var _this = $(this),verifyGroup = _this.parent('.verifyGroup');
                        layer.open({
                              title: '添加校验类型',
                              content: '<div class="layui-form">'+
                                                      '<div class="layui-form-item">'+
                                                                '<input type="checkbox" class="verify" title="必填" value="required"/>'+
                                                                '<input type="checkbox" class="verify" title="邮箱"value="email" />'+
                                                                '<input type="checkbox" class="verify" title="手机" value="phone"/>'+
                                                    '</div>'+
                                                    '<div class="layui-form-item">'+
                                                        '<input type="checkbox" class="verify" title="数字"value="number" />'+
                                                        '<input type="checkbox" class="verify" title="日期" value="date"/>'+
                                                          '<input type="checkbox" class="verify" title="日期范围" value="dateRange"/>'+
                                                          '<input type="checkbox" class="verify" title="日期时间" value="datetime"/>'+
                                                          '<input type="checkbox" class="verify" title="日期时间范围" value="datetimeRange"/>'+
                                                        '<input type="checkbox" class="verify" title="网址" value="url"/>'+
                                                    '</div>'+
                                                    '<div class="layui-form-item">'+
                                                        '<input type="checkbox" class="verify" title="身份证"value="identity" />'+
                                                    '</div>'+
                                            '</div>',
                              success: function(layero, index){
                                   
                                  //初始化赋值
                                   var inputs = verifyGroup.find('input');
                                   var verifys = $('.verify');
                                   for (var i = 0; i < inputs.length; i++) {
                                        for (var j = 0;j< verifys.length;j++) {
                                            if(inputs[i].value == verifys[j].value){
                                                $(verifys[j]).attr("checked",true);
                                            }
                                        }
                                    }
                                   form.render();
                              },
                              yes: function(index, layero){
                                    var verifys = $('.verify:checked');
                                    
                                    //清空并重新赋值
                                    verifyGroup.find('.verifybtn').remove();
                                    for (var i = 0; i < verifys.length; i++) {
                                        
                                        var name = 'entity.list[' + verifyGroup.data('index')+'].verifyList'+'['+i+'].name';
                                        var btn =  '<button class="layui-btn layui-btn-xs verifybtn" type="button" >'+$(verifys[i]).attr('title')+
                                                                '<input type="text" name="'+name +'"  value="'+$(verifys[i]).val()+'" hidden>'+
                                                         '</button>'
                                        verifyGroup.append(btn);
                                    }
                                    
                                    layer.close(index);
                              }
                        });
                });
                
            },
            openCode:function(data){
                var tab=[];
                for(var key in data){
                    var title = key;
                    var content = this.formatCode(key,data[key]);
                    tab.push({"title":title,"content":content}); 
                }
                var index = layer.tab({
                      area: ['600px', '500px'],
                      tab:tab,
                      success: function(layero, index){
                          layui.use('code', function(){ //加载code模块
                              layui.code({
                                  about: false
                              }); //引用code方法
                        });
                      }
                });
                layer.full(index);
                
            },
            formatCode:function( name,content){
                if(name.indexOf(".html")){
                    content =  $('<div/>').text(content).html(); 
                }
                
                content = "<pre class='layui-code'>"+content+"<pre>";
                return content;
            }
                
    }
    
    
    
     exports('edit',view);
    
});