rabin 4 years ago
parent
commit
3c4f45ba7b
6 changed files with 135 additions and 11 deletions
  1. 16 1
      assets/html/show.html
  2. 24 1
      database/file.php
  3. 10 2
      lib/Store/Core.php
  4. 7 2
      src/Qiniu.php
  5. 6 4
      src/Save.php
  6. 72 1
      src/View.php

+ 16 - 1
assets/html/show.html

@@ -30,6 +30,8 @@
   	<input type="hidden" class="file_key" value="<{$key}>">
   	<input type="hidden" class="file_pg" value="<{$search_pg}>">
   	<input type="hidden" class="file_cur" value="<{$cur}>">
+    <input type="hidden" class="upload_search_value" value="<{$upload_search_value}>">
+    <input type="hidden" class="upload_search" value="<{$upload_search}>">
   	<div class="layui-inline"><div class="layui-input-inline"><input type="text" style="width: 100%;" class="layui-input file_filename" value="<{$search_name}>" autocomplete="new-password" placeholder="<{$name}>"></div></div>
 
   	<div class="layui-inline" style="display: none;"><div class="layui-input-inline"><input type="text" style="width: 100%;"  class="layui-input file_tag" value="<{$search_tag}>" autocomplete="new-password" placeholder="标签"></div></div>
@@ -40,7 +42,13 @@
   		<{endloop}>
   	</select></div></div>
 
-  	<div class="layui-inline" class="file-search" onclick="showUploadFilesSearch($(this))"><div class="layui-input-inline"><button type="button" class="layui-btn"><i class="fa fa-save"></i> 搜索</button></div></div>
+  	<div class="layui-inline" class="file-search" id="showUploadFilesSearch" onclick="showUploadFilesSearch($(this), 1, false)"><div class="layui-input-inline"><button type="button" class="layui-btn"><i class="fa fa-save"></i> 搜索</button></div></div>
+
+    <div class="layui-inline" class="file-search" onclick="showUploadFilesUpload($(this))"><div class="layui-input-inline"><button type="button" class="layui-btn"><i class="fa fa-save"></i> 上传</button></div></div>
+
+    <div class="layui-inline" class="file-search" id="showUploadFilesSearch2" onclick="showUploadFilesSearch($(this), 2, false)"><div class="layui-input-inline"><button type="button" class="layui-btn layui-btn-danger"><i class="fa fa-submit"></i> 回收站</button></div></div>
+
+    <div class="layui-inline" class="file-search" id="showUploadFilesSearch" onclick="showUploadFilesSearch($(this), 1, true)"><div class="layui-input-inline"><button type="button" class="layui-btn layui-btn-normal"><i class="fa fa-save"></i> 全部图库</button></div></div>
 
   </div>
   <div class="layui-card-body">
@@ -50,6 +58,13 @@
       <li class="<{if($v1.check):}>layui-anim-yes<{else:}>layui-anim-no<{endif}>">
         <div class="layui-anim" data-anim="layui-anim-up" onclick="showUploadFilesSet($(this), '<{$v1.name}>','<{$v1.url}>','<{$v1.id}>')"><img src="<{$v1.pic}>" style="max-width: 150px;max-height: 100px;margin-left: 10px;"/></div>
         <div class="code"><{$v1.source_name}></div>
+        <div class="code" ><a style="color:<{$v1.stateColor}>;cursor: pointer;" onclick="showUploadFilesSetState($(this), '<{$v1.stateUrl}>')">[<{$v1.stateName}>]</a>
+
+        <{if($v1.state == 1):}>
+        <a class="code" style="color:blue;cursor: pointer;" onclick="showUploadFilesSetValue($(this), '<{$v1.valueUrl}>', 't<{$v1.id}>', '<{$v1.value}>')">[附加值]</a>
+        <{endif}>
+        </div>
+
       </li>
       <{endloop}>
     </ul>

+ 24 - 1
database/file.php

@@ -138,6 +138,28 @@ return array
 			//'search'	=> 'fulltext',
 			//'list'		=> true,
 		),
+
+		'search'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> 'search',
+			'default' 	=> '',
+			'desc' 		=> 'search',
+			'match' 	=> 'is_string',
+			//'search'	=> 'fulltext',
+			//'list'		=> true,
+		),
+
+		'value'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '附加值',
+			'default' 	=> '',
+			'desc' 		=> '附加值',
+			'match' 	=> 'is_string',
+			//'search'	=> 'fulltext',
+			//'list'		=> true,
+		),
 		
 		'ext'		=> array
 		(
@@ -264,9 +286,10 @@ return array
 		(
 			'option' => array
 			(
-				'state' => 1,
+				'state' => 'yes',
 				'upload' => 'yes',
 				'cate' => 'yes',
+				'search' => 'yes',
 				'source_name' => array('yes', 'like'),
 				//'source_name' => array('yes', 'like', 'and('),
 				//'name' => array('yes', 'like', 'or)'),

+ 10 - 2
lib/Store/Core.php

@@ -349,10 +349,14 @@ class Core
 		if ($this->size) {
 			$param['set_size'] = $this->size;
 		}
+
+		if (isset($this->data['search']) && $this->data['search']) {
+			$param['search'] = $this->data['search'];
+		}
 		
 		$this->id = $param['where_id'] = $id;
 
-		Dever::load('upload/file-update', $param);
+		Dever::db('upload/file')->update($param);
 	}
 
 	protected function insert()
@@ -381,7 +385,11 @@ class Core
 
 		//file_put_contents(DEVER_PATH . 'data/test', var_export($param,true));
 
-		$this->id = Dever::load('upload/file-insert', $param);
+		if (isset($this->data['search']) && $this->data['search']) {
+			$param['search'] = $this->data['search'];
+		}
+
+		$this->id = Dever::db('upload/file')->insert($param);
 	}
 
 	private function img()

+ 7 - 2
src/Qiniu.php

@@ -30,7 +30,7 @@ class Qiniu
 		return 'ok'; 
 	}
 
-    private function initFile($key, $file, $source, $width = false, $height = false, $size = false)
+    private function initFile($key, $file, $source, $width = false, $height = false, $size = false, $search = '')
     {
         $temp = explode('/', $file);
         $name = $temp[count($temp) - 1];
@@ -57,6 +57,10 @@ class Qiniu
             $data['size'] = $size;
         }
         $data['upload'] = $key;
+        if ($search) {
+            $data['search'] = $search;
+        }
+        
         if ($info) {
             $data['where_id'] = $info['id'];
             Dever::db('upload/file')->update($data);
@@ -71,6 +75,7 @@ class Qiniu
         $file = Dever::input('file');
         $key = Dever::input('key');
         $source = Dever::input('source');
+        $search = Dever::input('search');
 
         $config = Dever::db('upload/upload')->one($key);
 
@@ -82,7 +87,7 @@ class Qiniu
                     $this->convert($key, $file, $config, $yun);
                 }
             }
-            $this->initFile($key, $file, $source);
+            $this->initFile($key, $file, $source, false, false, false, $search);
         }
     }
 

+ 6 - 4
src/Save.php

@@ -33,10 +33,11 @@ class Save
 		Dever::outDiy($this->output);
 	}
 
-	private function upload($file = false, $key = 1)
+	private function upload($file = false, $key = 1, $search = '')
 	{
 		$image['file'] 	= Dever::input('file', $file);
 		$image['key'] 	= Dever::input('key', $key);
+		$image['search'] = Dever::input('search', $search);
 		
 		//file_put_contents(DEVER_PATH . 'web/data/upload.txt', var_export($image, true)); 
 		if ($image['file']) {
@@ -59,7 +60,7 @@ class Save
 		}
 	}
 
-	public function copy($file = false, $key = 1, $state = false)
+	public function copy($file = false, $key = 1, $state = false, $search = '')
 	{
 		if (Dever::input('file') && $state == false) {
 			$this->upload();
@@ -67,6 +68,7 @@ class Save
 		} else {
 			$image['file'] 	= $file;
 			$image['key'] 	= $key;
+			$image['search'] = $search;
 			$handle = new Handle($image);
 
 			$this->output = $handle->copy();
@@ -75,12 +77,12 @@ class Save
 		}
 	}
 
-	public function copys($file, $key = 1)
+	public function copys($file, $key = 1, $search = '')
 	{
 		$file = urldecode($file);
 		$file = explode(',', $file);
 		foreach ($file as $v) {
-			$copy = $this->copy($v, $key, true);
+			$copy = $this->copy($v, $key, true, $search);
 			if (isset($copy['url'])) {
 				$result[] = $copy['url'];
 			} else {

+ 72 - 1
src/View.php

@@ -50,7 +50,7 @@ class View
         Dever::out($data);
     }
     
-    public function files()
+    public function files($view)
     {
         $data = array();
 
@@ -58,12 +58,15 @@ class View
         $cate = Dever::input('cate', 1);
         $name = Dever::input('name');
         $tag = Dever::input('tag');
+        $state = Dever::input('state', 1);
+        $upload_search = Dever::input('upload_search');
         $data['cur'] = Dever::input('cur');
         $data['value'] = Dever::input('value');
         $data['search_pg'] = Dever::input('pg', 1);
 
         $param = array();
         $param['upload'] = $key;
+        $param['state'] = $state;
         if ($name) {
             $param['source_name'] = $name;
             $param['name'] = $name;
@@ -72,9 +75,15 @@ class View
             $param['cate'] = $cate;
         }
 
+        if ($upload_search) {
+            $param['search'] = $upload_search;
+        }
+
         $data['search_cate'] = $cate;
         $data['search_tag'] = $tag;
         $data['search_name'] = $name;
+        $data['search_name'] = $name;
+        $data['upload_search'] = $upload_search;
         $data['key'] = $key;
 
         if (strstr($key, '_')) {
@@ -113,6 +122,26 @@ class View
                     $data['file'][$k]['url'] = $v['file'];
                 }
 
+                $data['file'][$k]['value_array'] = array();
+                if ($v['value']) {
+                    parse_str($v['value'], $data['file'][$k]['value_array']);
+                }
+
+                if (!$view) {
+                    if ($v['state'] == 1) {
+                        $data['file'][$k]['stateColor'] = 'red';
+                        $data['file'][$k]['stateName'] = '删除';
+                        $data['file'][$k]['stateUrl'] = Dever::url('view.setState?id=' . $v['id'] . '&state=2', 'upload');
+                    } else {
+                        $data['file'][$k]['stateColor'] = 'blue';
+                        $data['file'][$k]['stateName'] = '恢复';
+                        $data['file'][$k]['stateUrl'] = Dever::url('view.setState?id=' . $v['id'] . '&state=1', 'upload');
+                    }
+
+                    $data['file'][$k]['valueUrl'] = Dever::url('view.setValue?id=' . $v['id'], 'upload');
+                }
+                
+
                 $data['file'][$k]['check'] = false;
                 if ($data['value'] && $data['value'] == $v['id']) {
                     $data['file'][$k]['check'] = true;
@@ -138,10 +167,52 @@ class View
             }
         }
 
+        if ($view) {
+            return $data;
+        }
+
         $data = Dever::render('show', $data);
         Dever::out($data);
     }
 
+    public function setState()
+    {
+        $id = Dever::input('id');
+        $state = Dever::input('state');
+
+        $where['where_id'] = $id;
+        $where['state'] = $state;
+        Dever::db('upload/file')->update($where);
+
+        return 'ok';
+    }
+
+    public function setValue()
+    {
+        $id = Dever::input('id');
+        $value = Dever::input('value');
+
+        $where['where_id'] = $id;
+        $where['value'] = $value;
+        Dever::db('upload/file')->update($where);
+
+        return 'ok';
+    }
+
+    # 根据key search 查找文件
+    public function search($key = 1, $search)
+    {
+        $key = Dever::input('key', $key);
+        $search = Dever::input('search', $search);
+
+        Dever::setInput('key', $key);
+        Dever::setInput('upload_search', $search);
+
+        $data = $this->files(true);
+
+        return $data['file'];
+    }
+
     public function kindeditorFile()
     {
         $key = Dever::input('key');