dever 7 years ago
parent
commit
6b6cc68391

File diff suppressed because it is too large
+ 0 - 568
assets/public/datetime/jquery.datetimepicker.css


File diff suppressed because it is too large
+ 0 - 0
assets/public/datetime/jquery.datetimepicker.min.js


+ 25 - 0
database/admin.php

@@ -149,6 +149,31 @@ return array
 			'desc' 		=> '请输入邮箱',
 			'match' 	=> Dever::rule('email'),
 			'update'	=> 'text',
+			/*
+			* 列表页搜索选项,这里的search的值为
+			* fulltext:全文检索,模糊匹配
+			* text:精确匹配
+			* exp:大小判断,仅能选择一项
+			* select:选择器,需要option项
+			* group:组选择器,需要option项
+			* exist:是否存在,需要exist项,基本配置为
+			$source_id = array
+			(
+				'yes' => '有值',
+				'no' => '没有值',
+				'no|2832' => '没有值或者有值为2832',
+				'yes|2832' => '有值或者有值为2829',
+				'2832' => '查找',
+			);
+			* 如果search的值为数组,则认为是接口,需要从接口获取数据后再进行查找
+			* 如'search'	=> array
+			(
+				'api' => 'passport/user-all',//接口地址,最好是获取多条数据的地址
+				'col' => 'name',//要查询的字段
+				'result' => 'id',//返回的字段
+			),
+			* 就是将本字段email当做passport/user-one的name字段来查找id
+			*/
 			'search'	=> 'fulltext',
 			'list'		=> true,
 			# 在手机版或者小屏幕下,列表页的表格是否展示,1为展示,2、3、4、5、6均为在一定宽度下展示,详细参考:https://github.com/nadangergeo/RWD-Table-Patterns

+ 216 - 106
src/Database.php

@@ -1,5 +1,6 @@
 <?php
 # 此类很大,以后优化,放到Database目录中,拆分为工厂模式
+# 必须要优化了...当时为了快速实现直接扔这一个里面了,近期优化
 namespace Manage\Src;
 
 use Dever;
@@ -438,13 +439,7 @@ class Database
                     $config['manage']['search_child'][$k] = $v['search_parent'];
                 }
 
-                if (isset($v['search'])) {
-                    /*
-                    if(strpos($v['search'], 'order') !== false)
-                    {
-                    $config['manage']['search']['order'][$k] = $v['name'];
-                    }
-                     */
+                if (isset($v['search']) && is_string($v['search'])) {
 
                     if (strpos($v['search'], 'time') !== false) {
                         $config['manage']['search']['time'][$k] = $v['name'];
@@ -456,8 +451,6 @@ class Database
 
                     if (strpos($v['search'], 'exp') !== false) {
                         $config['manage']['search']['exp'][$k] = $v['name'];
-
-                        isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like');
                     }
 
                     if (strpos($v['search'], 'fulltext') !== false) {
@@ -466,6 +459,11 @@ class Database
                         isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like');
                     }
 
+                    if (isset($v['exist']) && strpos($v['search'], 'exist') !== false) {
+                        $config['manage']['search']['exist'][$k]['option'] = $v['exist'];
+                        $config['manage']['search']['exist'][$k]['lang'] = $v['name'];
+                    }
+
                     if (isset($v['option']) && strpos($v['search'], 'select') !== false) {
                         $config['manage']['search']['select'][$k]['option'] = $v['option'];
                         $config['manage']['search']['select'][$k]['lang'] = $v['name'];
@@ -489,6 +487,11 @@ class Database
                             $config['manage']['search']['mul'][$k]['default'] = $v['default'];
                         }
                     }
+                } elseif (isset($v['search']) && is_array($v['search'])) {
+                    if (isset($v['search']['api'])) {
+                        $config['manage']['search']['api'][$k] = $v['search'];
+                        $config['manage']['search']['api'][$k]['lang'] = $v['name'];
+                    }
                 }
 
                 /*
@@ -959,6 +962,12 @@ class Database
                 }
             }
 
+            if (isset($config['manage']['search']['exist'])) {
+                foreach ($config['manage']['search']['exist'] as $k => $v) {
+                    $this->list_search_select($result, $search, $prefix . 'exist_' . $k, $v['lang'], $this->option($v['option']), '');
+                }
+            }
+
             if (isset($config['manage']['search']['group'])) {
                 foreach ($config['manage']['search']['group'] as $k => $v) {
                     $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
@@ -971,30 +980,24 @@ class Database
                 }
             }
 
-            /*排序加到列表表头中
-            if(isset($config['manage']['search']['order']))
-            {
-            $this->list_search_select($result, $search, $prefix . 'order', '选择排序', $config['manage']['search']['order']);
-            $this->list_search_select($result, $search, $prefix . 'desc', false, array('asc' => '正序','desc' => '倒序'));
+            if (isset($config['manage']['search']['api'])) {
+                foreach ($config['manage']['search']['api'] as $k => $v) {
+                    $value = array();
+                    $value['name'] = $prefix . 'api_' . $k;
+                    $value['class'] = 'form-control';
+                    if (isset($search[$value['name']])) {
+                        $value['value'] = $search[$value['name']];
+                    }
+                    if (strpos($v['lang'], '-') !== false) {
+                        $t = explode('-', $v['lang']);
+                        $v['lang'] = $t[0];
+                    }
+                    $value['placeholder'] = $v['lang'];
+                    $result .= Html::text($value, false) . '&nbsp;';
+                }
             }
-             */
 
             if (isset($config['manage']['search']['fulltext'])) {
-                //$result .= '<br />';
-
-                /*
-                $this->list_search_select($result, $search, $prefix . 'fulltext', '选择检索项', $config['manage']['search']['fulltext']);
-
-                $this->list_search_select($result, $search, $prefix . 'fulltext_type', '', array
-                (
-                1 => '精确匹配',
-                2 => '模糊匹配',
-                3 => '大于',
-                4 => '大于等于',
-                5 => '小于',
-                6 => '小于等于',
-                ), 1);
-                 */
 
                 foreach ($config['manage']['search']['fulltext'] as $k => $v) {
                     $value = array();
@@ -1012,6 +1015,29 @@ class Database
                 }
             }
 
+            if (isset($config['manage']['search']['exp'])) {
+                $result .= '<br />';
+
+                $this->list_search_select($result, $search, $prefix . 'exp_col', '选择检索项', $config['manage']['search']['exp']);
+
+                $this->list_search_select($result, $search, $prefix . 'exp_type', '', array
+                (
+                3 => '大于',
+                4 => '大于等于',
+                5 => '小于',
+                6 => '小于等于',
+                ), 1);
+
+                $value = array();
+                $value['name'] = $prefix . 'exp_value';
+                $value['class'] = 'form-control';
+                if (isset($search[$value['name']])) {
+                    $value['value'] = $search[$value['name']];
+                }
+                $value['placeholder'] = '填写值';
+                $result .= Html::text($value, false) . '&nbsp;';
+            }
+
             # 列表页按钮
             if (isset($config['manage']['search_button'])) {
                 $btn .= $this->button_list($config['manage']['search_button']);
@@ -1131,7 +1157,7 @@ class Database
                             $v['level'] = $config['level'];
                         }
 
-                        if (isset($v['search']) && strpos($v['search'], 'order') !== false) {
+                        if (isset($v['search']) && is_string($v['search']) && strpos($v['search'], 'order') !== false) {
                             $link = Dever::url();
                             $order = 'search_order_' . $k . '';
                             if (strpos($link, $order) !== false) {
@@ -1281,101 +1307,150 @@ class Database
     }
 
     /**
-     * 列表页数据列表
+     * 列表页数据列表 检索
      *
      * @return array
      */
-    public function list_tbody($excel = false)
+    private function list_tbody_search($config, $param, $high, $search)
     {
-        # 新增权限
-        if (Dever::load('manage/auth.oper', 1) == false) {
-            Dever::alert('你没有权限');
-        }
-
-        $config = $this->config();
-
-        $high = array();
-        
-        $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
-
-        $param = array();
-
-        $parent = 0;
-        if ($search) {
-            $fulltext = Dever::preInput('search_fulltext_');
-            if ($fulltext) {
-                # like改为instr
-                $search['search_fulltext_type'] = 2;
-                $fix = '';
-                /*
-                if ($search['search_fulltext_type'] == 2) {
-                    $fix = '%';
-                }
-                */
-
-                foreach ($fulltext as $k => $v) {
-                    if ($v) {
-                        $k = str_replace('search_fulltext_', '', $k);
-                        $param['option_' . $k] = $fix . $v . $fix;
-                        unset($search[$k]);
-
-                        # 设定检索高亮
-                        $high[$k] = $v;
+        # 根据api的数据检索到id
+        $api = Dever::preInput('search_api_');
+        if ($api) {
+            foreach ($api as $k => $v) {
+                if ($v) {
+                    unset($search[$k]);
+                    $k = str_replace('search_api_', '', $k);
+                    # 设定检索高亮
+                    $high[$k] = $v;
+                    if (isset($config['manage']['search']['api'][$k]['api'])) {
+                        $col = $config['manage']['search']['api'][$k]['col'];
+                        $option = array($col => $v);
+                        $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
+                        $result = $config['manage']['search']['api'][$k]['result'];
+                        if (is_array($v)) {
+                            if (isset($v[$result])) {
+                                $v = $v[$result];
+                            } else {
+                                if ($result == 'id') {
+                                    $v = array_keys($v);
+                                } else {
+                                    $t = array();
+                                    foreach ($v as $k1 => $v1) {
+                                        $t[] = $v1[$result];
+                                    }
+                                    $v = $t;
+                                }
+                                
+                                $param['option'][$k] = array('yes', 'in');
+                            }
+                        }
                     }
-
+                    $param['option_' . $k] = $v;
                 }
-
-                if ($param) {
-                    $param['search_type'] = $search['search_fulltext_type'];
-                }
-                $this->search = true;
             }
+        }
 
-            $order = Dever::preInput('search_order_');
-            if ($order) {
-                foreach ($order as $k => $v) {
-                    $k = str_replace('search_order_', '', $k);
-                    $param['order'][0][$k] = $v;
+        # 检索有无值
+        $exist = Dever::preInput('search_exist_');
+        if ($exist) {
+            foreach ($exist as $k => $v) {
+                if ($v) {
                     unset($search[$k]);
+                    $k = str_replace('search_exist_', '', $k);
+                    if ($v == 'yes') {
+                        # 有值
+                        $param['option'][$k] = array('yes', '!=');
+                        $param['option_' . $k] = 'null';
+                    } elseif ($v == 'no') {
+                        # 无值
+                        $param['option_' . $k] = 'null';
+                    } elseif (strpos($v, '|')) {
+                        # 有无值或者自定义的值
+                        $temp = explode('|', $v);
+                        $param['option'][$k] = array('yes', '=', 'and(');
+                        $param['option_' . $k] = $temp[1];
+                        if ($temp[0] == 'yes') {
+                            $param['option'][$k . '_t1'] = array('yes-' . $k, '!=', 'or)');
+                        } else {
+                            $param['option'][$k . '_t1'] = array('yes-' . $k, '=', 'or)');
+                        }
+                        $param['option_' . $k . '_t1'] = 'null';
+                    } else {
+                        # 自定义的值
+                        $param['option_' . $k] = $v;
+                    }
                 }
             }
-            foreach ($search as $k => $v) {
+        }
+        $fulltext = Dever::preInput('search_fulltext_');
+        if ($fulltext) {
+            # like改为instr 不再需要%
+            $search['search_fulltext_type'] = 2;
+            $fix = '';
+            foreach ($fulltext as $k => $v) {
                 if ($v) {
-                    if (strpos($k, 'option_') !== false) {
-                        //Dever::setInput(str_replace('search_', '', $k), $v);
-                        if (is_array($v)) {
-                            if ($v[0] == 0) {
-                                continue;
-                            }
-                            $v = str_replace(',0', '', implode(',', $v));
-                            $t = explode(',', $v);
-                            $parent = end($t);
-                            $v .= '%';
-                        }
-                        $param[str_replace('search_', '', $k)] = $v;
-                        $this->search = true;
-                    } elseif ($k == 'search_limit') {
-                        $num = $this->getNumConfig($config);
-                        if ($num) {
-                            $param['page'][0] = $num[$v];
-                        }
-                    }
+                    unset($search[$k]);
+                    $k = str_replace('search_fulltext_', '', $k);
+                    $param['option_' . $k] = $fix . $v . $fix;
+
+                    # 设定检索高亮
+                    $high[$k] = $v;
                 }
             }
 
-            //$search = Dever::preInput('option_');
+            if ($param) {
+                $param['search_type'] = $search['search_fulltext_type'];
+            }
+            $this->search = true;
+        }
 
-            //print_r($search);die;
+        $exp = Dever::preInput('search_exp_');
+        if ($exp) {
+            $k = $search['search_exp_col'];
+            $v = $search['search_exp_value'];
+            $param['option_' . $k] = $v;
+            $param['search_type'] = $search['search_exp_type'];
+
+            $this->search = true;
         }
 
-        if (empty($param['page'])) {
-            $num = $this->getNumConfig($config);
-            if ($num) {
-                $param['page'][0] = $num[0];
+        $order = Dever::preInput('search_order_');
+        if ($order) {
+            foreach ($order as $k => $v) {
+                $k = str_replace('search_order_', '', $k);
+                $param['order'][0][$k] = $v;
+                unset($search[$k]);
+            }
+        }
+        foreach ($search as $k => $v) {
+            if ($v) {
+                if (strpos($k, 'option_') !== false) {
+                    //Dever::setInput(str_replace('search_', '', $k), $v);
+                    if (is_array($v)) {
+                        if ($v[0] == 0) {
+                            continue;
+                        }
+                        $v = str_replace(',0', '', implode(',', $v));
+                        $t = explode(',', $v);
+                        $parent = end($t);
+                        $v .= '%';
+                    }
+                    $param[str_replace('search_', '', $k)] = $v;
+                    $this->search = true;
+                } elseif ($k == 'search_limit') {
+                    $num = $this->getNumConfig($config);
+                    if ($num) {
+                        $param['page'][0] = $num[$v];
+                    }
+                }
             }
         }
 
-        # 批量更新
+        return array($param, $high);
+    }
+
+    private function list_tbody_mul($param)
+    {
         $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
 
         if (Dever::input('method') == 'mul' && $mul && $mul['mul_type'] > 0) {
@@ -1400,9 +1475,44 @@ class Database
 
             }
 
-            //print_r($param);die;
             Dever::alert('reload');
         }
+    }
+
+    /**
+     * 列表页数据列表
+     *
+     * @return array
+     */
+    public function list_tbody($excel = false)
+    {
+        # 新增权限
+        if (Dever::load('manage/auth.oper', 1) == false) {
+            Dever::alert('你没有权限');
+        }
+
+        $config = $this->config();
+
+        $high = array();
+        
+        $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
+
+        $param = array();
+
+        $parent = 0;
+        if ($search) {
+            list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
+        }
+
+        if (empty($param['page'])) {
+            $num = $this->getNumConfig($config);
+            if ($num) {
+                $param['page'][0] = $num[0];
+            }
+        }
+
+        # 批量更新
+        $this->list_tbody_mul($param);
 
         $result = array();
 

Some files were not shown because too many files changed in this diff