rabin 1 month ago
parent
commit
5957963455
5 changed files with 171 additions and 158 deletions
  1. 8 139
      api/Page/Data.php
  2. 1 1
      api/Page/View.php
  3. 7 0
      lib/Common.php
  4. 135 1
      lib/Page.php
  5. 20 17
      table/manage/admin.php

+ 8 - 139
api/Page/Data.php

@@ -4,7 +4,6 @@ use Manage\Lib\Page;
 # 数据获取
 class Data extends Page
 {
-    private $recycler = false;
     private $expand = false;
     public function __construct($load = '')
     {
@@ -44,6 +43,14 @@ class Data extends Page
         if ($ids) {
             $where['id'] = array('in', $ids);
         }
+        $set['num'] = Dever::input('pgnum', '', '', 10);
+        $order_col = Dever::input('order_col');
+        if ($order_col) {
+            $order_value = Dever::input('order_value');
+            if ($order_value) {
+                $set['order'] = $order_col . ' ' . $order_value . ', id desc';
+            }
+        }
         if (isset($this->config['data'])) {
             $result = Dever::call($this->config['data'], array($where, $set));
             $data = array_merge($data, $result);
@@ -67,14 +74,6 @@ class Data extends Page
 
     private function data($where, $set = array())
     {
-        $set['num'] = Dever::input('pgnum', '', '', 10);
-        $order_col = Dever::input('order_col');
-        if ($order_col) {
-            $order_value = Dever::input('order_value');
-            if ($order_value) {
-                $set['order'] = $order_col . ' ' . $order_value . ', id desc';
-            }
-        }
         if (isset($this->config['tree'])) {
             return $this->db->tree($where, $this->config['tree'], array($this, 'handleData'));
         }
@@ -221,134 +220,4 @@ class Data extends Page
             }
         }
     }
-
-    private function button($key = 'button', $data = array())
-    {
-        $result = array();
-        if (!isset($this->config[$key])) {
-            $num = 0;
-            if (isset($this->db->config['manage']['update']['field'])) {
-                $num = count($this->db->config['manage']['update']['field']);
-            } elseif (isset($this->db->config['struct']) && $this->db->config['struct']) {
-                $num = count($this->db->config['struct']);
-            }
-            $fast = 'fast';
-            if ($num > 8) {
-                $fast = '';
-            }
-            if ($key == 'button') {
-                $this->config[$key] = array('新增' => $fast . 'add');
-            } else {
-                $this->config[$key] = array('编辑' => $fast . 'edit', '删除' => 'recycle');
-            }
-        }
-        $sort = 1;
-        foreach ($this->config[$key] as $k => $v) {
-            $d = '';
-            $p = '';
-            $i = '';
-            if (is_array($v)) {
-                if (isset($v[3]) && $data) {
-                    $d = $v[3];
-                    parse_str($d, $t);
-                    $state = true;
-                    foreach ($t as $k1 => $v1) {
-                        if (!isset($data[$k1]) || (isset($data[$k1]) && $data[$k1] != $v1)) {
-                            $state = false;
-                        }
-                    }
-                    if (!$state) {
-                        continue;
-                    }
-                }
-                if (isset($v[2])) {
-                    $i = $v[2];
-                }
-                if (isset($v[1])) {
-                    $p = $v[1];
-                }
-                $v = $v[0];
-            }
-            if (strstr($v, 'add')) {
-                $icon = 'Plus';
-                $button = 'primary';
-            } elseif (strstr($v, 'edit')) {
-                $icon = 'Edit';
-                $button = 'primary';
-            } elseif (strstr($v, 'view')) {
-                $icon = 'View';
-                $button = '';
-            } elseif ($v == 'delete') {
-                if ($key == 'button') {
-                    if (isset($this->config['layout'])) {
-                        continue;
-                    }
-                    $this->config['selection'] = true;
-                }
-                $icon = 'Delete';
-                $button = 'danger';
-            } elseif ($v == 'recycle') {
-                if ($key == 'button') {
-                    if (isset($this->config['layout'])) {
-                        continue;
-                    }
-                    $this->config['selection'] = true;
-                }
-                $icon = 'Delete';
-                $button = 'danger';
-            } elseif ($v == 'oper') {
-                if ($key == 'button') {
-                    if (isset($this->config['layout'])) {
-                        continue;
-                    }
-                    $this->config['selection'] = true;
-                }
-                $icon = 'Notification';
-                $button = 'warning';
-            } elseif ($v == 'api') {
-                if ($key == 'button') {
-                    if (isset($this->config['layout'])) {
-                        continue;
-                    }
-                    $this->config['selection'] = true;
-                }
-                $p = Dever::url($p);
-                $icon = 'Notification';
-                $button = 'warning';
-            } elseif ($v == 'link') {
-                $icon = 'Link';
-                $button = 'success';
-            } elseif ($v == 'route') {
-                $icon = 'Link';
-                $button = 'success';
-            } elseif ($v == 'recover') {
-                $icon = 'CirclePlus';
-                $button = 'info';
-            } else {
-                continue;
-            }
-            # 权限验证
-            $sort++;
-            $func = $this->getFunc($v, $k, $sort, $p);
-            if ($this->menu && $this->menu['show'] == 1 && !$func) {
-                continue;
-            }
-            if ($i) {
-                $icon = $i;
-            }
-            $result[] = array
-            (
-                'name' => $k,
-                'type' => $v,
-                'param' => $p,
-                'icon' => $icon,
-                'button' => $button,
-                'func' => $func,
-            );
-            if (!$this->recycler && $v == 'recycle') {
-                $this->recycler = true;
-            }
-        }
-        return $result;
-    }
 }

+ 1 - 1
api/Page/View.php

@@ -11,7 +11,7 @@ class View extends Page
     public function get()
     {
         $this->checkFunc();
-        $data = Dever::call($this->config, $this);
+        $data = Dever::call($this->config, array($this));
         return $data;
     }
 }

+ 7 - 0
lib/Common.php

@@ -35,6 +35,13 @@ class Common
         return false;
     }
 
+    # 获取页面类
+    public function page($load, $config = array(), $key = 'list', $input = true)
+    {
+        $page = new Page($key, $load, $input, $config);
+        return $page;
+    }
+
     # 获取当前使用的系统 一般为数据库隔离使用
     public function system($info = array())
     {

+ 135 - 1
lib/Page.php

@@ -7,11 +7,12 @@ class Page extends Auth
     protected $key;
     protected $id = 0;
     protected $input = false;
+    protected $recycler = false;
     protected $menu = array();
     protected $config = array();
     protected $field = array();
     public $info = array();
-    public function __construct($key = '', $load = '', $input = true)
+    public function __construct($key = '', $load = '', $input = true, $config = array())
     {
         parent::__construct();
         $this->key = $key;
@@ -25,6 +26,9 @@ class Page extends Auth
             $this->checkMenu($this->menu['id'], false);
         }
         $this->config = $this->db->config['manage'][$key] ?? array();
+        if ($config) {
+            $this->config = array_merge($this->config, $config);
+        }
         if ($this->id && !strstr($this->id, ',')) {
             $this->info = $this->db->find($this->id);
         }
@@ -439,4 +443,134 @@ class Page extends Auth
     {
         return $this->input ? Dever::input($key) : $value;
     }
+
+    public function button($key = 'button', $data = array())
+    {
+        $result = array();
+        if (!isset($this->config[$key])) {
+            $num = 0;
+            if (isset($this->db->config['manage']['update']['field'])) {
+                $num = count($this->db->config['manage']['update']['field']);
+            } elseif (isset($this->db->config['struct']) && $this->db->config['struct']) {
+                $num = count($this->db->config['struct']);
+            }
+            $fast = 'fast';
+            if ($num > 8) {
+                $fast = '';
+            }
+            if ($key == 'button') {
+                $this->config[$key] = array('新增' => $fast . 'add');
+            } else {
+                $this->config[$key] = array('编辑' => $fast . 'edit', '删除' => 'recycle');
+            }
+        }
+        $sort = 1;
+        foreach ($this->config[$key] as $k => $v) {
+            $d = '';
+            $p = '';
+            $i = '';
+            if (is_array($v)) {
+                if (isset($v[3]) && $data) {
+                    $d = $v[3];
+                    parse_str($d, $t);
+                    $state = true;
+                    foreach ($t as $k1 => $v1) {
+                        if (!isset($data[$k1]) || (isset($data[$k1]) && $data[$k1] != $v1)) {
+                            $state = false;
+                        }
+                    }
+                    if (!$state) {
+                        continue;
+                    }
+                }
+                if (isset($v[2])) {
+                    $i = $v[2];
+                }
+                if (isset($v[1])) {
+                    $p = $v[1];
+                }
+                $v = $v[0];
+            }
+            if (strstr($v, 'add')) {
+                $icon = 'Plus';
+                $button = 'primary';
+            } elseif (strstr($v, 'edit')) {
+                $icon = 'Edit';
+                $button = 'primary';
+            } elseif (strstr($v, 'view')) {
+                $icon = 'View';
+                $button = '';
+            } elseif ($v == 'delete') {
+                if ($key == 'button') {
+                    if (isset($this->config['layout'])) {
+                        continue;
+                    }
+                    $this->config['selection'] = true;
+                }
+                $icon = 'Delete';
+                $button = 'danger';
+            } elseif ($v == 'recycle') {
+                if ($key == 'button') {
+                    if (isset($this->config['layout'])) {
+                        continue;
+                    }
+                    $this->config['selection'] = true;
+                }
+                $icon = 'Delete';
+                $button = 'danger';
+            } elseif ($v == 'oper') {
+                if ($key == 'button') {
+                    if (isset($this->config['layout'])) {
+                        continue;
+                    }
+                    $this->config['selection'] = true;
+                }
+                $icon = 'Notification';
+                $button = 'warning';
+            } elseif ($v == 'api') {
+                if ($key == 'button') {
+                    if (isset($this->config['layout'])) {
+                        continue;
+                    }
+                    $this->config['selection'] = true;
+                }
+                $p = Dever::url($p);
+                $icon = 'Notification';
+                $button = 'warning';
+            } elseif ($v == 'link') {
+                $icon = 'Link';
+                $button = 'success';
+            } elseif ($v == 'route') {
+                $icon = 'Link';
+                $button = 'success';
+            } elseif ($v == 'recover') {
+                $icon = 'CirclePlus';
+                $button = 'info';
+            } else {
+                continue;
+            }
+            # 权限验证
+            $sort++;
+            $func = $this->getFunc($v, $k, $sort, $p);
+            if ($this->menu && $this->menu['show'] == 1 && !$func) {
+                continue;
+            }
+            if ($i) {
+                $icon = $i;
+            }
+            $result[] = array
+            (
+                'name' => $k,
+                'type' => $v,
+                'param' => $p,
+                'icon' => $icon,
+                'button' => $button,
+                'func' => $func,
+            );
+            if (!$this->recycler && $v == 'recycle') {
+                $this->recycler = true;
+            }
+        }
+        return $result;
+    }
 }

+ 20 - 17
table/manage/admin.php

@@ -45,6 +45,8 @@ return array
             'mobile' => array
             (
                 'sort' => true,
+                # 多余字符按照...提示
+                'tip' => true,
             ),
             'role',
             /*
@@ -236,6 +238,24 @@ return array
         # 要更新的字段
         'field'    => array
         (
+            'avatar' => array
+            (
+                'type' => 'upload',
+                # 这里传入上传规则id
+                'upload' => '1',
+                # 如果上传规则是上传到云端,配置了这个将直接上传至云端,不做本地上传
+                'yun' => false,
+                # 是否支持多选
+                'multiple' => false,
+                # 仅上传一条
+                'limit' => 1,
+                # 提示
+                'tip' => '2222',
+                # 展示类型 默认为list 列表 input 可输入地址 pic图片模式
+                'style' => 'pic',
+                # 上传后影响的字段 这个目前仅有name字段
+                //'upload_name' => 'name',
+            ),
             'name' => array
             (
                 'type' => 'text',
@@ -455,23 +475,6 @@ return array
             ),
             # 定义另外一个表或者方法里的字段,带有"."就是方法,调用manage/role里的upload配置,这里也可以自行配置
             //'manage/role' => 'upload',
-            /*
-            'avatar' => array
-            (
-                'type' => 'upload',
-                # 这里传入上传规则id
-                'upload' => '1',
-                # 如果上传规则是上传到云端,配置了这个将直接上传至云端,不做本地上传
-                'yun' => false,
-                # 是否支持多选
-                'multiple' => false,
-                # 提示
-                'tip' => '',
-                # 展示类型 默认为list 列表 input 可输入地址 pic图片模式
-                'style' => 'input',
-                # 上传后影响的字段 这个目前仅有name字段
-                'upload_name' => 'name',
-            ),*/
         ),
 
         # 是否开启控制功能