rabin 2 months ago
parent
commit
8dbe762f06
11 changed files with 172 additions and 102 deletions
  1. 2 2
      api/Admin.php
  2. 1 1
      api/Login.php
  3. 114 61
      api/Page/Update.php
  4. 4 1
      lib/Auth.php
  5. 42 30
      lib/Page.php
  6. 2 0
      manage/admin.php
  7. 1 1
      manage/menu.php
  8. 3 3
      manage/role.php
  9. 1 1
      table/admin.php
  10. 1 1
      table/group_role.php
  11. 1 1
      table/role.php

+ 2 - 2
api/Admin.php

@@ -115,7 +115,7 @@ class Admin extends Auth
         if ($this->user['module_data'] && !strstr($this->user['module_data'], $module_id . '-' . $data_id)) {
             Dever::error('无模块权限');
         }
-        $result = Dever::load('common')->token($this->user['id'], $this->user['mobile'], $this->user['select']['partition'], $this->user['select']['system_id'], $this->user['select']['info_id'], $module_id, $data_id);
+        $result = Dever::load('common', 'manage')->token($this->user['id'], $this->user['mobile'], $this->user['select']['partition'], $this->user['select']['system_id'], $this->user['select']['info_id'], $module_id, $data_id);
         return $result;
     }
 
@@ -129,7 +129,7 @@ class Admin extends Auth
             $data['name'] = $username;
         }
         if ($password) {
-            $data += Dever::load('common')->createPwd($password);
+            $data += Dever::load('common', 'manage')->createPwd($password);
         }
         $state = false;
         if ($data) {

+ 1 - 1
api/Login.php

@@ -128,6 +128,6 @@ class Login
     }
     public function loadMenu()
     {
-        return Dever::load('menu')->init();
+        return Dever::load('menu', 'manage')->init();
     }
 }

+ 114 - 61
api/Page/Update.php

@@ -3,7 +3,7 @@ use Dever;
 use Manage\Lib\Page;
 ini_set("memory_limit", -1);
 set_time_limit(0);
-# 更新页
+# 更新页 项目着急上线 以后优化并封装
 class Update extends Page
 {
     public function __construct($load = '', $input = true)
@@ -119,7 +119,9 @@ class Update extends Page
                 foreach ($remote as $k => $v) {
                     $data['update'][$v[0]]['remote'] = Dever::url($v[1], array('value' => '', 'table' => $this->db->config['load'], 'id' => false));
                     if (isset($v[2]) && isset($data['option'][$v[2]]) && $data['option'][$v[2]] && $m = Dever::issets($data['option'][$v[2]][0], 'id')) {
-                        $result = Dever::call($v[1], array($m, $this->db->config['load'], false), 'api');
+                        $path = 'api';
+                        if (strstr($v[1], 'mapi')) $path = 'manage';
+                        $result = Dever::call($v[1], array($m, $this->db->config['load'], false), $path);
                         if ($result) {
                             $this->setUpdate($info, $data, $result);
                         }
@@ -136,7 +138,7 @@ class Update extends Page
         $data['desc'] = $this->config['desc'] ?? '';
         $data['drag'] = $this->config['drag'] ?? false;
         $this->layout($data);
-        $this->control($data);
+        $data['control'] = $this->control($data);
         $this->tab($data, 'step');
         if (!$data['step']) {
             $this->tab($data);
@@ -156,7 +158,7 @@ class Update extends Page
             }
         }
         foreach ($info as $k => $v) {
-            if ($v == null) {
+            if ($v === null) {
                 $v = '';
             }
             if (isset($data['field'][$k])) {
@@ -190,7 +192,9 @@ class Update extends Page
                     if ($field[$k]['type'] == 'cascader' && !isset($field[$k]['option'])) {
                         
                     } else {
-                        $result = Dever::call($remote[$k][1], array($v, $this->db->config['load'], $info['id'] ?? false), 'api');
+                        $path = 'api';
+                        if (strstr($remote[$k][1], 'mapi')) $path = 'manage';
+                        $result = Dever::call($remote[$k][1], array($v, $this->db->config['load'], $info['id'] ?? false), $path);
                         if ($result) {
                             $this->setUpdate($info, $data, $result);
                         }
@@ -244,34 +248,60 @@ class Update extends Page
 
     private function control(&$data)
     {
-        $data['control'] = array();
-        if (isset($this->config['control']) && $data['control'] = $this->config['control']) {
-            foreach ($data['control'] as $k => $v) {
-                foreach ($data['update'] as $k1 => $v1) {
-                    if ($v1['key'] == $k) {
-                        $show = true;
-                        foreach ($v as $k2 => $v2) {
-                            if (is_array($v2)) {
-                                $temp = false;
-                                foreach ($v2 as $k3 => $v3) {
-                                    if (is_array($data['field'][$k2]) && in_array($v3, $data['field'][$k2])) {
-                                        $temp = true;
-                                    } elseif ($data['field'][$k2] == $v3) {
-                                        $temp = true;
-                                    }
-                                }
-                                $show = $temp;
-                            } else {
-                                if (is_array($data['field'][$k2]) && !in_array($v2, $data['field'][$k2])) {
-                                    $show = false;
-                                } elseif ($data['field'][$k2] != $v2) {
-                                    $show = false;
-                                }
+        $result = array();
+        if (isset($this->config['control']) && $this->config['control']) {
+            foreach ($this->config['control'] as $k => $v) {
+                if (is_string($v)) {
+                    parse_str($v, $v);
+                }
+                if (strstr($k, ',')) {
+                    $k = explode(',', $k);
+                    foreach ($k as $k2) {
+                        if (isset($data['update'])) $this->controlShow($data, $k2, $v);
+                        $result[$k2] = $v;
+                    }
+                } else {
+                    if (isset($data['update'])) $this->controlShow($data, $k, $v);
+                    $result[$k] = $v;
+                }
+            }
+        }
+        return $result;
+    }
+
+    private function controlShow(&$data, $k, $v)
+    {
+        foreach ($data['update'] as $k1 => $v1) {
+            if ($v1['key'] == $k) {
+                $show = true;
+                foreach ($v as $k2 => $v2) {
+                    if (is_array($v2)) {
+                        $temp = false;
+                        foreach ($v2 as $k3 => $v3) {
+                            if (is_array($data['field'][$k2]) && in_array($v3, $data['field'][$k2])) {
+                                $temp = true;
+                            } elseif ($data['field'][$k2] == $v3) {
+                                $temp = true;
                             }
                         }
-                        $data['update'][$k1]['show'] = $show;
+                        $show = $temp;
+                    } else {
+                        if (is_array($data['field'][$k2]) && !in_array($v2, $data['field'][$k2])) {
+                            $show = false;
+                        } elseif ($data['field'][$k2] != $v2) {
+                            $show = false;
+                        }
                     }
-                } 
+                }
+                $data['update'][$k1]['show'] = $show;
+                if ($show == false && isset($data['update'][$k1]['field'])) {
+                    # 对重新命名的字段删除
+                    if ($data['update'][$k1]['type'] == 'editor') {
+                        $data['field'][$v1['key']] = '';
+                    } else {
+                        unset($data['field'][$v1['key']]);
+                    }
+                }
             }
         }
     }
@@ -358,6 +388,7 @@ class Update extends Page
             if (isset($input['id']) && $input['id'] > 0) {
                 $id = $input['id'];
             }
+            $control = $this->control($data);
             foreach ($update as $k => $v) {
                 if (isset($input[$v['key']])) {
                     if (isset($v['rules'])) {
@@ -388,7 +419,7 @@ class Update extends Page
                             $other[$v['key']] = array($v['where'], $v['content']['field'], $v['content']['drag'], $input[$v['key']]);
                         }
                     } else {
-                        $this->doData($data, $v['key'], $input[$v['key']], $this->config['field']);
+                        $this->doData($data, $v['key'], $input[$v['key']], $this->config['field'], $control);
                     }
                 } elseif ($id) {
                     $data[$v['key']] = '';
@@ -401,7 +432,9 @@ class Update extends Page
                 Dever::error('无效数据');
             }
             if ($data) {
-                $this->exists($id, $data, $this->config['field']);
+                if (isset($this->config['check']) && $this->config['check']) {
+                    $this->exists($this->db, $this->config['check'], $id, $data, $this->config['field']);
+                }
                 $result = $this->start($id, $data);
                 if ($result == 'end') {
                     return '操作成功';
@@ -431,7 +464,7 @@ class Update extends Page
         }
     }
 
-    private function doData(&$data, $key, $value, $field = array())
+    private function doData(&$data, $key, $value, $field = array(), $control = array())
     {
         if (is_array($value)) {
             if (isset($value[0])) {
@@ -441,7 +474,20 @@ class Update extends Page
             }
         }
         if (isset($field[$key]) && isset($field[$key]['field'])) {
-            $key = $field[$key]['field'];
+            if ($control && isset($control[$key])) {
+                # 如果有重命名字段并且是控制项,需要单独设置
+                $state = true;
+                foreach ($control[$key] as $k => $v) {
+                    if ($data[$k] != $v) {
+                        $state = false;
+                    }
+                }
+                if ($state) {
+                    $key = $field[$key]['field'];
+                }
+            } else {
+                $key = $field[$key]['field'];
+            }
         }
         if ($value && isset($field[$key]) && $handle = Dever::issets($field[$key], 'handle')) {
             $value = Dever::call($handle, array($value));
@@ -454,37 +500,40 @@ class Update extends Page
         } elseif (isset($field[$key]) && isset($field[$key]['type']) && $field[$key]['type'] == 'date' && $value) {
             $value = \Dever\Helper\Date::mktime($value);
         }
+        /*
+        if (empty($data[$key])) {
+            $data[$key] = trim($value);
+        }
+        */
         $data[$key] = trim($value);
     }
 
-    private function exists($id, $data, $field)
+    private function exists($db, $check, $id, $data, $field)
     {
-        if (isset($this->config['check']) && $this->config['check']) {
-            $check = explode(',', $this->config['check']);
-            $where = array();
-            $name = array();
-            foreach ($check as $k => $v) {
-                if (isset($data[$v]) && $data[$v]) {
-                    if (isset($field[$v]) && isset($field[$v]['name'])) {
-                        $n = $field[$v]['name'];
-                    } elseif (isset($this->db->config['struct'][$v])) {
-                        $n = $this->db->config['struct'][$v]['name'];
-                    } else {
-                        $n = $v;
-                    }
-                    $where[$v] = $data[$v];
-                    $name[] = $n;
+        $check = explode(',', $check);
+        $where = array();
+        $name = array();
+        foreach ($check as $k => $v) {
+            if (isset($data[$v]) && $data[$v]) {
+                if (isset($field[$v]) && isset($field[$v]['name'])) {
+                    $n = $field[$v]['name'];
+                } elseif (isset($db->config['struct'][$v])) {
+                    $n = $db->config['struct'][$v]['name'];
+                } else {
+                    $n = $v;
                 }
+                $where[$v] = $data[$v];
+                $name[] = $n;
             }
-            if ($where) {
-                if ($id) {
-                    $where['id'] = array('!=', $id);
-                }
-                $info = $this->db->find($where);
-                if ($info) {
-                    $name = implode('、', $name);
-                    Dever::error($name . '已存在');
-                }
+        }
+        if ($where) {
+            if ($id) {
+                $where['id'] = array('!=', $id);
+            }
+            $info = $db->find($where);
+            if ($info) {
+                $name = implode('、', $name);
+                Dever::error($name . '已存在');
             }
         }
     }
@@ -570,12 +619,16 @@ class Update extends Page
                     if ($drag) {
                         $value[$drag] = $k1+1;
                     }
+                    $db = Dever::db($k);
+                    if (isset($db->config['manage']['update']['check'])) {
+                        $this->exists($db, $db->config['manage']['update']['check'], $value['id'], $value, $db->config['manage']['update']['field']);
+                    }
                     if (isset($value['id']) && $value['id'] > 0) {
                         $id = $value['id'];
                         unset($value['id']);
-                        Dever::db($k)->update($id, $value);
+                        $db->update($id, $value);
                     } else {
-                        Dever::db($k)->insert($value);
+                        $db->insert($value);
                     }
                 }
             }

+ 4 - 1
lib/Auth.php

@@ -9,7 +9,7 @@ class Auth
     protected $info;
     protected $func;
     public $data = array();
-    public function __construct()
+    public function __construct($set = false)
     {
         $info = Dever::load('common', 'manage')->auth();
         if (!$info && $this->login) {
@@ -60,6 +60,9 @@ class Auth
             $this->user['select'] = array('partition' => 'no', 'system_id' => 1, 'info_id' => 1, 'module_id' => 1, 'data_id' => 1);
         }
         $this->checkModule($this->user['select']['module_id']);
+        if ($set) {
+            Dever::$data['muser'] = $this->user;
+        }
     }
 
     # 设置功能权限

+ 42 - 30
lib/Page.php

@@ -1,6 +1,6 @@
 <?php namespace Manage\Lib;
 use Dever;
-# 通用页面
+# 通用页面 项目着急上线 以后优化并封装
 class Page extends Auth
 {
     protected $db;
@@ -165,10 +165,10 @@ class Page extends Auth
                 );
             }
             foreach ($set['rules'] as $k => $v) {
-                if (isset($v['required']) && $v['required'] && !$data && $data !== 0) {
+                if (isset($v['required']) && $v['required'] && !$data && $data !== '0') {
                     Dever::error($v['message']);
                 }
-                if ($data || $data === 0) {
+                if ($data || $data === '0') {
                     if (isset($v['pattern']) && $v['pattern'] && !preg_match('/' . $v['pattern'] . '/', $data)) {
                         Dever::error($v['message']);
                     }
@@ -383,12 +383,7 @@ class Page extends Auth
             $value['width'] = 'auto';
         }
         if (isset($value['upload']) && Dever::project('upload')) {
-            $upload['cate_id'] = 1;
-            $upload['group_key'] = $this->db->config['table'] . '-' . $value['key'];
-            $upload['group_name'] = $this->db->config['name'];
-            $upload['user_token'] = Dever::load('common', 'manage')->getToken();
-            $upload['user_table'] = $this->user['table'];
-            $upload['user_id'] = $this->user['id'];
+            $upload = $this->getUpload($value['key']);
             if (is_array($value['upload'])) {
                 $upload += $value['upload'];
             } else {
@@ -412,24 +407,7 @@ class Page extends Auth
             }
         }
         if (isset($value['editorMenu'])) {
-            if (isset($value['editorMenu']['uploadImage'])) {
-                if (!is_array($value['editorMenu']['uploadImage'])) {
-                    $value['editorMenu']['uploadImage'] = array('upload' => $value['editorMenu']['uploadImage']);
-                }
-                $value['editorMenu']['uploadImage']['server'] = Dever::url('upload/save.wangEditor', array('id' => $value['editorMenu']['uploadImage']['upload']));
-                if (empty($value['editorMenu']['uploadImage']['fieldName'])) {
-                    $value['editorMenu']['uploadImage']['fieldName'] = 'file';
-                }
-            }
-             if (isset($value['editorMenu']['uploadVideo'])) {
-                if (!is_array($value['editorMenu']['uploadVideo'])) {
-                    $value['editorMenu']['uploadVideo'] = array('upload' => $value['editorMenu']['uploadVideo']);
-                }
-                $value['editorMenu']['uploadVideo']['server'] = Dever::url('upload/save.wangEditor', array('id' => $value['editorMenu']['uploadVideo']['upload']));
-                if (empty($value['editorMenu']['uploadImage']['fieldName'])) {
-                    $value['editorMenu']['uploadImage']['fieldName'] = 'file';
-                }
-            }
+            $this->setEditorUpload($value, ['uploadImage', 'uploadVideo']);
         }
 
         if (isset($value['date_type']) && $value['date_type'] == 'datetimerange' && empty($value['default_time'])) {
@@ -437,6 +415,35 @@ class Page extends Auth
         }
     }
 
+    private function getUpload($key)
+    {
+        $upload['cate_id'] = 1;
+        $upload['group_key'] = $this->db->config['table'] . '-' . $key;
+        $upload['group_name'] = $this->db->config['name'];
+        $upload['user_token'] = Dever::load('common', 'manage')->getToken();
+        $upload['user_table'] = $this->user['table'];
+        $upload['user_id'] = $this->user['id'];
+        return $upload;
+    }
+
+    private function setEditorUpload(&$value, $key)
+    {
+        $upload = $this->getUpload($value['key']);
+        foreach ($key as $k) {
+            if ($v = Dever::issets($value['editorMenu'], $k)) {
+                if (!is_array($v)) {
+                    $v = array('upload' => $v);
+                }
+                $upload['id'] = $v['upload'];
+                $v['server'] = Dever::url('upload/save.wangEditor', $upload, true);
+                if (empty($v['fieldName'])) {
+                    $v['fieldName'] = 'file';
+                }
+                $value['editorMenu'][$k] = $v;
+            }
+        }
+    }
+
     private function setDisable(&$value, $disable)
     {
         if (isset($value['disable'])) {
@@ -546,10 +553,15 @@ class Page extends Auth
                 if (isset($v[3]) && $data) {
                     $d = $v[3];
                     parse_str($d, $t);
-                    $state = true;
+                    $state = false;
                     foreach ($t as $k1 => $v1) {
-                        if (!isset($data[$k1]) || (isset($data[$k1]) && $data[$k1] != $v1)) {
-                            $state = false;
+                        if (isset($data[$k1])) {
+                            $v1 = explode(',', $v1);
+                            foreach ($v1 as $v2) {
+                                if ($data[$k1] == $v2) {
+                                    $state = true;
+                                }
+                            }
                         }
                     }
                     if (!$state) {

+ 2 - 0
manage/admin.php

@@ -150,6 +150,7 @@ return array
             //'编辑' => array('fastedit'),
             # 打开其他表的新增
             //'新增子菜单' => array('fastadd', 'platform/admin'),
+            //'新增子菜单' => array('fastadd', array('path' => 'place_user_log/wallet', 'field' => array('uid' => 'id'))),
             '删除' => 'recycle',//删除到回收站
             //'彻底删除' => 'delete',
             //'操作' => array('oper', 'role'),
@@ -157,6 +158,7 @@ return array
             //'详情' => array('view', 'platform/admin?type=view&id=id'),
             //'链接跳转' => array('link', 'https://www.baidu.com/'),
             # 第三个参数可以自定义图标:https://element-plus.org/zh-CN/component/icon.html#icon-collection
+            # 第四个参数是判断是否展示该按钮,字段名=字段值& 如name=1&id=2
             //'路由跳转' => array('route', 'manage/menu?test=1', 'ChatLineSquare'),
             //'管理账户列表' => array('route', array('path' => 'set_group/group_user', 'param' => array('set' => array('module_id' => 2, 'relation_id' => 'id')))),
         ),

+ 1 - 1
manage/menu.php

@@ -20,7 +20,7 @@ return array
             # 关键字段,一般为id或者key
             'key' => 'id',
             # 获取数据
-            'data' => 'module.getTree',
+            'data' => 'manage/module.getTree',
             # 默认展开
             'active' => 1,
             # 对应的where条件的key

+ 3 - 3
manage/role.php

@@ -9,16 +9,16 @@ return array
             'name',
             'module' => array
             (
-                'show' => 'Dever::load("role")->showModule("{module}")',
+                'show' => 'Dever::load("role", "manage")->showModule("{module}")',
             ),
             'menu' => array
             (
-                'show' => 'Dever::load("role")->showMenu("{menu}")',
+                'show' => 'Dever::load("role", "manage")->showMenu("{menu}")',
             ),
             /*
             'auth' => array
             (
-                'show' => 'Dever::load("role")->showFunc("{auth}")',
+                'show' => 'Dever::load("role", "manage")->showFunc("{auth}")',
             ),*/
             'cdate',
         ),

+ 1 - 1
table/admin.php

@@ -29,7 +29,7 @@ return array
             'name'      => '角色',
             'type'      => 'varchar(100)',
             # 该字段的值 radio、select、checkbox有效,定义从哪个表获取数据
-            'value'    => 'role',
+            'value'    => 'manage/role',
             /*
             'value'    => 'manage/role',//跟role一样,但可以调取别的app的方法
             'value'    => 'Dever::call("manage/role.get")',//调用某个类的方法

+ 1 - 1
table/group_role.php

@@ -24,7 +24,7 @@ return array
         (
             'name'      => '权限',
             'type'      => 'text',
-            'value'    => 'Dever::call("role.getAuthData")',
+            'value'    => 'Dever::call("manage/role.getAuthData")',
         ),
     ),
     'default' => array

+ 1 - 1
table/role.php

@@ -23,7 +23,7 @@ return array
         (
             'name'      => '权限',
             'type'      => 'text',
-            'value'    => 'Dever::call("role.getAuthData")',
+            'value'    => 'Dever::call("manage/role.getAuthData")',
         ),
     ),
     'default' => array