rabin 1 year ago
parent
commit
fba41b880f
8 changed files with 155 additions and 33 deletions
  1. 1 1
      assets/layadmin/html/inc/script.html
  2. 62 4
      database/admin.php
  3. 18 4
      database/group.php
  4. 6 6
      database/role.php
  5. 12 0
      database/top.php
  6. 47 16
      src/Database.php
  7. 5 1
      src/Lib/Input.php
  8. 4 1
      src/Menu.php

+ 1 - 1
assets/layadmin/html/inc/script.html

@@ -39,4 +39,4 @@
 <script type="text/javascript" src="../script/lib/excel/excel.js?v16"></script>
 
 <!-- 加载主要js,很乱,后续优化 -->
-<script type="text/javascript" src="../script/lib/manage/main.js?v210"></script>
+<script type="text/javascript" src="../script/lib/manage/main.js?v211"></script>

+ 62 - 4
database/admin.php

@@ -13,6 +13,9 @@ $status = array
 
 $cur = Dever::load('manage/auth.data', false);
 
+# 获取top权限
+//$auth = Dever::tops();
+
 $desc = '';
 if($cur && $cur['role'] > 1)
 {
@@ -602,7 +605,7 @@ return array
 		'role'		=> array
 		(
 			'type' 		=> 'varchar-100',
-			'name' 		=> '角色名称',
+			'name' 		=> '所属角色',
 			'default' 	=> '1',
 			'desc' 		=> '请选择角色',
 			'match' 	=> 'is_string',
@@ -614,13 +617,14 @@ return array
 		'group'		=> array
 		(
 			'type' 		=> 'int-11',
-			'name' 		=> '分组',
+			'name' 		=> '所属部门',
 			'default' 	=> '1',
-			'desc' 		=> '请选择分组',
+			'desc' 		=> '请选择所属部门',
 			'match' 	=> 'is_numeric',
 			'option' 	=> $group,
 			'update'	=> 'select',
-			//'list'		=> true,
+			'list'		=> true,
+			'edit'		=> true,
 			# 取代option,从接口里读取选项
 			//'update_search' => 'goods/lib/manage.search_sku',
 		),
@@ -742,6 +746,12 @@ return array
 			'edit' => array('编辑', 'name,reorder'),
 		),
 		*/
+
+		'button' => array
+        (
+            //'新增兑换码' => array('fast', 1, 'config&where_id=1'),
+            '部门设置' => array('list', 'group&oper_parent=admin'),
+        ),
 	),
 	
 	# 更新表结构
@@ -754,6 +764,54 @@ return array
 		),
 		'version' => 2,
 	),
+
+	/*
+	# 权限表
+
+	'end' => array
+	(
+		'insert' => array
+		(
+			'manage/top.sync',
+		),
+		'update' => array
+		(
+			'manage/top.sync',
+		),
+	),
+	
+	'top' => array
+	(
+		# 数据来源
+		'data' => 'find',
+		# 菜单名
+		'name' => '期权公司设置',
+		# 默认值
+		'value' => 1,
+		# 对应的字段值,设置这个之后,所有设置等于这个值的字段,都要遵循这个权限的控制
+		'key' => 'option/company_id',
+		# 本表中代表名称的字段
+		'col' => 'name',
+	),
+
+	# 需要设置top权限的表
+    'top' => 'option/company_id',
+
+    # 增加这个,为了给当前的list增加一个option $admin = Dever::load('manage/auth.info');
+    'top_option' => array
+    (
+        array
+        (
+            'value' => $auth,
+            'col' => 'company_id',
+        ),
+        array
+        (
+            'value' => Dever::load('manage/auth.authData'),
+            'col' => 'id',
+        ),
+    ),
+    */
 	
 	# 默认值
 	/*

+ 18 - 4
database/group.php

@@ -21,10 +21,11 @@ $config = array
 	# 表名
 	'name' => 'group',
 	# 显示给用户看的名称
-	'lang' => '管理组设置',
+	'lang' => '部门设置',
 	'order' => 8,
 	# 表类型 值为\innodb\myisam\,默认为innodb,仅在mysql类型有效
 	'type' => 'innodb',
+	'menu' => false,
 	# 数据结构
 	'struct' => array
 	(
@@ -42,9 +43,9 @@ $config = array
 		'name'		=> array
 		(
 			'type' 		=> 'varchar-50',
-			'name' 		=> '名称',
+			'name' 		=> '部门名称',
 			'default' 	=> '',
-			'desc' 		=> '请输入名称',
+			'desc' 		=> '请输入部门名称',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'search'	=> 'fulltext',
@@ -91,7 +92,20 @@ $config = array
 		'col' => 'name,state,cdate',
 		'value' => array
 		(
-			'"默认分组",1,' . DEVER_TIME,
+			'"默认部门",1,' . DEVER_TIME,
+		),
+		'insert' => false,
+		'edit' => false,
+
+		# 自定义快捷新增和编辑
+		'button' => array
+		(
+			'新增' => array('fast'),
+		),
+		# 快捷更新
+		'list_button' => array
+		(
+			'edit' => array('编辑'),
 		),
 	),
 

+ 6 - 6
database/role.php

@@ -273,9 +273,9 @@ $config = array
 		'auth'		=> array
 		(
 			'type' 		=> 'text-255',
-			'name' 		=> '左侧菜单',
+			'name' 		=> '功能权限',
 			'default' 	=> '',
-			'desc' 		=> '请选择左侧菜单',
+			'desc' 		=> '请选择功能权限',
 			'match' 	=> 'option',
 			'update'	=> 'checkbox',
 			//每个项对应的一个input以及父级更新的类型
@@ -287,11 +287,11 @@ $config = array
 		'top'		=> array
 		(
 			'type' 		=> 'text-255',
-			'name' 		=> '头部菜单',
+			'name' 		=> '数据权限',
 			'default' 	=> '',
-			'desc' 		=> '请选择头部菜单',
+			'desc' 		=> '请选择数据权限',
 			'match' 	=> 'option',
-			//'update'	=> 'checkbox',
+			'update'	=> 'checkbox',
 			'option'	=> $top,
 		),
 
@@ -302,7 +302,7 @@ $config = array
 			'default' 	=> '',
 			'desc' 		=> '数据权限',
 			'match' 	=> 'option',
-			'update'	=> 'checkbox',
+			//'update'	=> 'checkbox',
 			//每个项对应的一个input以及父级更新的类型
 			//'update_input' => '数量',
 			//'update_parent' => 'radio',

+ 12 - 0
database/top.php

@@ -117,6 +117,18 @@ return array
 			'type' => 'one',
 			'order' => array('id', 'desc'),
 		),
+
+		'getData' => array
+		(
+			'where' => array
+			(
+				'ids' => array('yes-id', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id', 'desc'),
+			'col' => '*',
+		),
 		
 		'keyId' => array
 		(

+ 47 - 16
src/Database.php

@@ -1397,6 +1397,8 @@ class Database
 
             $prefix = 'search_';
 
+            $top_result = '';
+
             $result .= $node[0];
 
             if (isset($config['manage']['search']['linkage'])) {
@@ -1481,7 +1483,12 @@ class Database
 
                     if (isset($v['option']) && $v['option']) {
                         $value['option'] = $this->option($v['option']);
-                        $result .= Html::select($value, false);
+                        $value['lang'] = $v['lang'];
+                        if (isset($v['top']) && $v['top']) {
+                            $top_result .= Html::select($value, false);
+                        } else {
+                            $result .= Html::select($value, false);
+                        }
                     } else {
                         $result .= Html::text($value, false);
                     }
@@ -1691,6 +1698,10 @@ class Database
             $result .= '<input type="hidden" value="'.$page_type.'" name="page_type" id="page_type" />';
         }
 
+        if ($top_result) {
+            $result = $top_result . $result;
+        }
+
         return $result;
     }
 
@@ -2140,7 +2151,10 @@ class Database
                         if ($v == 'no') {
                             $param['option_no'] = $config['manage']['search']['api'][$k]['no'];
                         } else {
-                            $option = array($col => $v);
+                            $option = array($col => $v, 'clear_top' => true);
+
+                            # 此处可以增加关联关系
+
                             $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
                             $result = $config['manage']['search']['api'][$k]['result'];
                             if ($v && is_array($v)) {
@@ -2314,16 +2328,23 @@ class Database
                     if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
                         
                     }
-                    $sync = $config['struct'][$k];
-                    if ($v[$vi['sync'][0]] > 0) {
-                        $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
+                    $struct = $config['struct'][$k];
+                    if (isset($struct['search_col']) && $struct['search_col']) {
+                        $param[$struct['search_col']] = $v;
                     } else {
-                        $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
-                        $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
-                    }
-                    
-                    if (isset($temp[2])) {
-                        $data[$k][$ki] = $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
+                        $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $struct['sync'][1] => $v));
+                        /*
+                        if ($v[$vi['sync'][0]] > 0) {
+                            $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
+                        } else {
+                            $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
+                            $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
+                        }*/
+                        
+                        if (isset($temp[2])) {
+                            $v = isset($load[$temp[2]]) ? $load[$temp[2]] : $struct['default'];
+                            $param[str_replace('search_', '', $k)] = $v;
+                        }
                     }
                     
                 } elseif (strpos($k, 'dever_') !== false) {
@@ -2475,7 +2496,17 @@ class Database
         if (isset($config['top_option']) && $config['top_option']) {
             if (isset($config['top_option'][0])) {
                 foreach ($config['top_option'] as $k => $v) {
-                    $param['option'][$v['col']] = array($v['value'], 'in');
+                    if (isset($v['join'])) {
+                        $param['join'][] = $v['join'];
+                        $col = 't_2.' . $v['col'];
+                        $param['option']['state'] = 'yes-t_1.state';
+                    } else {
+                        $col = $v['col'];
+                    }
+                    if ($v['value']) {
+                        $param['option'][$v['col']] = array('yes-' . $col, 'in');
+                        $param[$v['col']] = $v['value'];
+                    }
                 }
             } else {
                 $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
@@ -4080,11 +4111,11 @@ class Database
                         foreach ($update_add[$k] as $k1 => $v1) {
                             $col = $update_col[$k][$k1];
                             foreach ($v1 as $k2 => $v2) {
-                                if (isset($update_set[$k][$k1][$k2][$col])) {
-                                    $update_set[$k][$k1][$k2][$col] = $id;
+                                if (isset($update_set[$k][$k1][$k2]['set_' . $col])) {
+                                    $update_set[$k][$k1][$k2]['set_' . $col] = $id;
                                 }
-                                if (isset($v2[$col])) {
-                                    $v2[$col] = $id;
+                                if (isset($v2['add_' . $col])) {
+                                    $v2['add_' . $col] = $id;
                                 }
 
                                 $check = false;

+ 5 - 1
src/Lib/Input.php

@@ -762,6 +762,7 @@ class Input
                     $html .= '<input update_type="checked" class="checkbox-checkall ' . $param['name'] . ' update_value" type="' . $param['update'] . '" name="temp_' . $param['name'] . '[]" value="' . $param['parent'] . '"/> 全选 &nbsp;&nbsp;';
                 }
 
+                $i = 0;
                 foreach ($param['option'] as $k => $v) {
                     $check = '';
                     if (is_array($v)) {
@@ -781,12 +782,14 @@ class Input
                         } elseif (is_array($param['value']) && in_array($k, $param['value'])) {
                             $check = 'checked';
                         }
-                    } elseif (isset($param['default'])) {
+                    } elseif (isset($param['default']) && $param['default']) {
                         if (is_string($param['default']) && strpos(',' . $param['default'], ',' . $k) !== false) {
                             $check = 'checked';
                         } elseif (is_array($param['default']) && in_array($k, $param['default'])) {
                             $check = 'checked';
                         }
+                    } elseif ($param['update'] == 'radio' && $i == 0) {
+                        $check = 'checked';
                     }
 
                     $cjs = $js;
@@ -802,6 +805,7 @@ class Input
                     if (isset($param['bind'])) {
                         //$html .= '<script>$(document).ready(function(){$(".checkbox-checkall-'.$param['parent'].'").click();})</script>';
                     }
+                    $i++;
                 }
             }
         }

+ 4 - 1
src/Menu.php

@@ -406,7 +406,7 @@ class Menu
 
             if ($config) {
                 foreach ($config as $i => $j) {
-                    $this->sync('top', 'update', $j, $k, $i, $v, $top);
+                    //$this->sync('top', 'update', $j, $k, $i, $v, $top);
                     $this->sync('auth', 'update_action', $j, $k, $i, $v, $auth);
 
                     if (!isset($j['menu'])) {
@@ -575,6 +575,9 @@ class Menu
                             $type = $v[$data[$key]['type']];
                             $param['key'] = $data[$key]['key'] . '-' . $type . '_' . $v['id'];
                         } else {
+                            if (!isset($v['id'])) {
+                                print_r($parent);die;
+                            }
                             $param['key'] = $data[$key]['key'] . '_' . $v['id'];
                         }
                         $param['name'] = $v[$data[$key]['col']];