rabin 2 years ago
parent
commit
6c243ce335
2 changed files with 55 additions and 38 deletions
  1. 54 37
      src/Database.php
  2. 1 1
      src/Lib/Input.php

+ 54 - 37
src/Database.php

@@ -3637,18 +3637,6 @@ class Database
 
         $value['update'] = $value['update'] ? $value['update'] : 'text';
 
-        if (isset($value['match']) && $value['match'] != 'option') {
-            if (is_string($value['match']) && strpos($value['match'], '/') !== false) {
-                if (strstr($value['match'], 'option||')) {
-                    $value['valid'] = 'validate[custom[' . $key . ']]';
-                } else {
-                    $value['valid'] = 'validate[required,custom[' . $key . ']]';
-                }
-            } else {
-                $value['valid'] = 'validate[required]';
-            }
-        }
-
         if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
             $value['value'] = $value['update'];
             $value['update'] = 'hidden';
@@ -3669,6 +3657,18 @@ class Database
      */
     public function update_html($param, $key, $index, $data, &$result, $prefix = '', $ext = 'update')
     {
+        if (isset($param['match']) && $param['match'] != 'option') {
+            if (is_string($param['match']) && strpos($param['match'], '/') !== false) {
+                if (strstr($param['match'], 'option||')) {
+                    $param['valid'] = 'validate[custom[' . $key . ']]';
+                } else {
+                    $param['valid'] = 'validate[required,custom[' . $key . ']]';
+                }
+            } else {
+                $param['valid'] = 'validate[required]';
+            }
+        }
+        
         if (isset($param['name']) && isset($param['update']) && $param['update'] != 'hidden' && $param['update'] != 'load') {
             $result .= Html::pageLeft($param);
         }
@@ -3773,36 +3773,53 @@ class Database
                     $table .= '<table class="layui-table">';
                     $table_header = '<thead><tr>';
                     $table_body = '<tbody>';
-                    $table_body .= '<tr class="table_copy" style="display:none;">';
-                    foreach ($param['update'] as $hk => $hv) {
-                        if (isset($hv['col'])) {
-                            $hk = $hv['col'];
-                        }
-                        if ($this->id && $hk === 'id') {
-                            $hv['update'] = 'hidden';
+                    $table_key = '';
+                    if (isset($param['option'])) {
+                        if (!isset($param['value'])) {
+                            $table_body .= '<tr>';
+                            $table_key = '1';
+                            $table_up = 'update';
                         }
-                        if (isset($hv['update']) && $hv['update'] && (!isset($hv['tab']) || (isset($hv['tab']) && $hv['tab'] <= 0))) {
-                            $n = $hv['name'];
-                            unset($hv['name']);
-                            $s = '';
-                            $hv['ext'] = $param['name'] . '_c_-1_i_' . $hk;
-                            if ($hv['update'] == 'linkage') {
-                                $hv['update_width'] = '30%';
+                    } else {
+                        $table_body .= '<tr class="table_copy" style="display:none;">';
+                        $table_key = '-1';
+                        $table_up = 'up';
+                    }
+
+                    if ($table_key) {
+                        foreach ($param['update'] as $hk => $hv) {
+                            if (isset($hv['col'])) {
+                                $hk = $hv['col'];
                             }
-                            $this->update_html($hv, $hk, $hk, array(), $s, '', 'up');
-                            if ($hv['update'] == 'hidden') {
-                                $table_header .= '<td style="display:none;">'.$n.'</td>';
-                                $table_body .= '<td style="display:none;">'.$s.'</td>';
-                            } else {
-                                $table_header .= '<td>'.$n.'</td>';
-                                $table_body .= '<td>'.$s.'</td>';
+                            if ($this->id && $hk === 'id') {
+                                $hv['update'] = 'hidden';
+                            }
+                            if (isset($hv['update']) && $hv['update'] && (!isset($hv['tab']) || (isset($hv['tab']) && $hv['tab'] <= 0))) {
+                                $n = $hv['name'];
+                                unset($hv['name']);
+                                $s = '';
+                                $hv['ext'] = $param['name'] . '_c_'.$table_key.'_i_' . $hk;
+                                if ($hv['update'] == 'linkage') {
+                                    $hv['update_width'] = '30%';
+                                }
+                                $this->update_html($hv, $hk, $hk, array(), $s, '', $table_up);
+                                if ($hv['update'] == 'hidden') {
+                                    $table_header .= '<td style="display:none;">'.$n.'</td>';
+                                    $table_body .= '<td style="display:none;">'.$s.'</td>';
+                                } else {
+                                    $table_header .= '<td>'.$n.'</td>';
+                                    $table_body .= '<td>'.$s.'</td>';
+                                }
                             }
                         }
-                    }
-                    $table_header .= '<td>操作</td>';
-                    $table_body .= '<td><a href="javascript:;" onclick="var self = $(this);var index = layer.confirm(\'确定进行此项操作吗?\', function(i, l){self.parent().parent().remove();layer.close(index);});" class="layui-btn layui-btn-xs">删除</a></td>';
-                    $table_body .= '</tr>';
 
+                        if ($table_key == '-1') {
+                            $table_header .= '<td>操作</td>';
+                            $table_body .= '<td><a href="javascript:;" onclick="var self = $(this);var index = layer.confirm(\'确定进行此项操作吗?\', function(i, l){self.parent().parent().remove();layer.close(index);});" class="layui-btn layui-btn-xs">删除</a></td>';
+                        }
+                        $table_body .= '</tr>';
+                    }
+                    
                     if (isset($param['value']) && $param['value']) {
                         if (!is_array($param['value'])) {
                             $param['value'] = Dever::json_decode($param['value']);

+ 1 - 1
src/Lib/Input.php

@@ -167,7 +167,7 @@ class Input
         }
 
         $param['button'] = '';
-        if (isset($param['update_type']) && $param['update_type'] == 2) {
+        if (isset($param['update_type']) && $param['update_type'] == 2 && !isset($param['option'])) {
             $param['button'] = '<a href="javascript:;" onclick="append($(this), \''.$param['ext'].'\')" style="margin-left:5px;" class="layui-btn layui-btn-xs layui-btn-normal">新增</a>';
         }