rabin 3 years ago
parent
commit
307335f868
1 changed files with 53 additions and 20 deletions
  1. 53 20
      src/Database.php

+ 53 - 20
src/Database.php

@@ -64,6 +64,16 @@ class Database
      * @return mixed
      */
     public function __construct()
+    {
+        $this->setting();
+
+        $this->top = Dever::input('top');
+        if ($this->top) {
+            Dever::load('manage/top.update_action', $this->top);
+        }
+    }
+
+    public function setting()
     {
         $this->project = Dever::input('project');
         $this->table = Dever::input('table');
@@ -72,10 +82,7 @@ class Database
         $this->id = Dever::input('update_where_id', Dever::input('where_id'));
         $this->name = $this->project . '/' . $this->table;
 
-        $this->top = Dever::input('top');
-        if ($this->top) {
-            Dever::load('manage/top.update_action', $this->top);
-        }
+        return $this;
     }
 
     /**
@@ -100,7 +107,7 @@ class Database
      *
      * @return array
      */
-    public function url($key = false, $id = 0, $table = false, $suffix = '')
+    public function url($key = false, $id = 0, $table = false, $suffix = '', $project = '')
     {
         $table = $table ? $table : $this->table;
 
@@ -142,7 +149,7 @@ class Database
 
         if (isset($config[$key])) {
             if (strpos($config[$key], '{param}')) {
-                $param = $this->getUrlParam($key, $table, $suffix, $state);
+                $param = $this->getUrlParam($key, $table, $suffix, $state, $project);
                 $config[$key] = str_replace('{param}', $param, $config[$key]);
             }
             return Dever::url($config[$key]);
@@ -155,13 +162,14 @@ class Database
      *
      * @return string
      */
-    private function getUrlParam($key, $table, $suffix, $state)
+    private function getUrlParam($key, $table, $suffix, $state, $project = '')
     {
-        if (isset($this->param[$key])) {
-            return $this->param[$key];
+        $index = $key . '_' . $project . '_' . $table;
+        if (isset($this->param[$index])) {
+            return $this->param[$index];
         }
         $param = '';
-        $array = array('project', 'search', 'add', 'list', 'update', 'edit', 'listData');
+        $array = array('project', 'search', 'add', 'list', 'update', 'edit');
         if (in_array($key, $array) && !strstr($table, 'oper_')) {
             $where = Dever::preInput('search_');
             if ($where) {
@@ -196,13 +204,20 @@ class Database
         if ($page_type) {
             $param .= '&page_type=' . $page_type . '';
         }
-        $project = Dever::input('oper_project', $this->project);
+        if (!$project) {
+            if ($key == 'add' || $key == 'update') {
+                $project = $this->project;
+            } else {
+                $project = Dever::input('oper_project', $this->project);
+            }
+        }
+        
         $param = 'project=' . $project . $param . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id . $state . $suffix;
 
         //echo $key . "\r\n";
         //echo $param ."\r\n";
 
-        $this->param[$key] = $param;
+        $this->param[$index] = $param;
 
         return $param;
     }
@@ -361,26 +376,44 @@ class Database
             'search_param' => '',
         );
 
-        $info['parent'] = Dever::input('oper_parent');
+        # 此处为了兼容旧版本的一些设置
+        $info['parent'] = Dever::input('oper_table', Dever::input('oper_parent'));
+
+        # 返回上一页
         if ($info['parent']) {
             $oper = Dever::preInput('oper_');
             if ($oper) {
                 $info['parent'] .= '&' . str_replace('oper_', '', http_build_query($oper));
-                //$info['parent'] .= '&' . http_build_query($oper);
             }
-            if ($top = Dever::input('top_parent')) {
-                $info['parent'] .= '&oper_parent=' . $top;
+            $top = Dever::preInput('top_');
+            if ($top) {
+                $top_query = http_build_query($top);
+                if (strstr($top_query, '.')) {
+                    foreach ($top as $k => $v) {
+                        $temp = explode('.', $v);
+                        $k = str_replace('top_', '', $k);
+                        $info['parent'] .= '&oper_' . $k . '=' . $temp[0];
+                        if (isset($temp[1])) {
+                            $info['parent'] .= '&top_' . $k . '=' . $temp[1];
+                        }
+                    }
+                } else {
+                    $info['parent'] .= '&' . str_replace('top_', 'oper_', $top_query);
+                }
             }
-            //$info['parent'] = 'location.href=\'' . $this->url(Dever::input('oper_index', 11), 0, $info['parent']) . '\'';
-            $info['parent'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['parent']);
+            $info['parent_project'] = Dever::input('oper_project');
+
+            $info['parent'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['parent'], '', $info['parent_project']);
             $info['parent_state'] = '';
         } else {
             $info['parent_state'] = 'display:none';
         }
 
-        $info['save'] = Dever::input('oper_save_jump');
+        # 保存页面
+        $info['save'] = Dever::input('oper_save_table', Dever::input('oper_save_jump'));
         if ($info['save']) {
-            $info['list'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['save']);
+            $info['save_project'] = Dever::input('oper_save_project');
+            $info['list'] = $this->url(Dever::input('oper_index', 'list'), 0, $info['save'], '', $info['save_project']);
         }
 
         $search = Dever::preInput('search_');