huwhois 11 달 전
부모
커밋
4000e5758b
3개의 변경된 파일124개의 추가작업 그리고 40개의 파일을 삭제
  1. 33 9
      app/sys/controller/Article.php
  2. 7 5
      app/sys/controller/Base.php
  3. 84 26
      view/sys/article/index.html

+ 33 - 9
app/sys/controller/Article.php

@@ -12,12 +12,16 @@ declare(strict_types=1);
 namespace app\sys\controller;
 
 // 引入框架内置类
-use think\facade\View;
+use think\Exception;
+use think\facade\Db;
 use think\facade\Config;
+use think\facade\View;
+
 
 use app\common\model\Category as CategoryModel;
 use app\common\model\Article as ArticleModel;
 use app\common\facade\FileUtils;
+use app\common\utils\ReUtils;
 use app\common\model\FileManager as FileManagerModel;
 
 class Article extends Base
@@ -60,7 +64,7 @@ class Article extends Base
             $params['content'] =  isset($params['content']) ? $params['content'] : '';
             if ($content_type == 0) {
                 $username = $this->getSysUser()->username;
-                $params['content'] = $this->saveRomteImage($params['content'],(int)$params['id'],(int) $params['cjid'], $username);
+                $params['content'] = $this->saveRomteImage($params['content'], (int)$params['id'], (int) $params['cjid'], $username);
             }
 
             $params['keywords'] = trim($params['keywords']);
@@ -101,27 +105,27 @@ class Article extends Base
         }
     }
 
-    protected function saveRomteImage($content, $infoid=0, $cjid=0, $username='system')
+    protected function saveRomteImage($content, $infoid = 0, $cjid = 0, $username = 'system')
     {
-        $content = stripslashes ($content);
+        $content = stripslashes($content);
         $img_array = [];
         // 匹配所有远程图片
         $pattern = '/src="(http[s]:\/\/.*)"/isU';
-        preg_match_all ($pattern,$content,$img_array);
-        
+        preg_match_all($pattern, $content, $img_array);
+
         // 删除重复 url
-        $img_arrays = array_unique ($img_array[1]);
+        $img_arrays = array_unique($img_array[1]);
 
         foreach ($img_arrays as $value) {
             $file = FileUtils::downloadUrlImg($value);
-            
+
             $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
 
             FileManagerModel::saveFileInfo($file, $savename, $file->getOriginalName, $infoid, $cjid, $username);
 
             // 删除临时文件
             @unlink($file->getRealPath());
-            
+
             $filename = Config::get('filesystem.disks.public.url') . '/' . str_replace('\\', '/', $savename);
 
             // dump($filename);
@@ -130,4 +134,24 @@ class Article extends Base
 
         return $content;
     }
+
+    public function move()
+    {
+        $ids = $this->request->param('ids');
+        $cid = $this->request->param('cid');
+
+        $tablename = ArticleModel::getTable();
+
+        $idss = implode(',', $ids);
+
+        $sql = "update " . $tablename . " set cid=". $cid ." where id IN (" . $idss . ");";
+
+        try {
+            Db::execute($sql);
+        } catch (Exception $e) {
+            return ReUtils::error();
+        }
+
+        return ReUtils::success();
+    }
 }

+ 7 - 5
app/sys/controller/Base.php

@@ -62,15 +62,17 @@ abstract class Base
     //  */
     // protected $pageSize = 0;
 
-    // /**
-    //  * 系统设置
-    //  * @var array
-    //  */
-    // protected $system = [];
+    /**
+     * 系统设置
+     * @var array
+     */
+    protected $system = [];
     /**
      * 用户信息
      */
     protected $sysUser;
+    protected $modelName;
+
 
     /**
      * 构造方法

+ 84 - 26
view/sys/article/index.html

@@ -1,33 +1,39 @@
 <article class="cl pd-10" style="min-width: 900px;">
     <div class="cl pd-5 bg-1 bk-gray mt-20">
         <span class="l">
-            <a href="javascript:;" onclick="del_all()" class="btn btn-danger radius">
+            <a href="javascript:void(0);" onclick="del_all()" class="btn btn-danger radius">
                 <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
-            <a class="btn btn-primary radius" href="{:url('save')}">
+            <a class="btn btn-success radius" href="{:url('save')}">
                 <i class="Hui-iconfont">&#xe600;</i> 添加文章</a>
-            <a class="btn btn-primary radius" href="{:url('save', ['content_type'=>1])}">
+            <a class="btn btn-success radius" href="{:url('save', ['content_type'=>1])}">
                 <i class="Hui-iconfont">&#xe600;</i> 添加MarkDown文章</a>
+            <a class="btn btn-primary radius" href="javascript:void(0);" onclick="moveArticle()">
+                <i class="Hui-iconfont">&#xe600;</i>移动到指定栏目</a>
         </span>
-        <span class="select-box inline ml-50">
-            <select name="cid" id="sel_option" class="select">
-                <option value="0" {eq name='cid' value="0" }selected{/eq}>所有栏目</option>
-                {foreach $category_tree as $value}
-                <option value="{$value.id}" {eq name='cid' value="$value.id" }selected{/eq}>{$value.name}</option>
-                {notempty name="value.child"}
-                {foreach $value.child as $val}
-                <option value="{$val.id}" {eq name='cid' value="$val.id" }selected{/eq}>--{$val.name}</option>
-                {notempty name="val.child"}
-                {foreach $val.child as $vo}
-                <option value="{$vo.id}" {eq name='cid' value="$vo.id" }selected{/eq}>&nbsp;&nbsp;└ --{$vo.name}
-                </option>
-                {/foreach}
-                {/notempty}
-                {/foreach}
-                {/notempty}
-                {/foreach}
-            </select>
+        <span class="r">
+            <span class="select-box inline ml-50">
+                <select name="cid" id="sel_option" class="select">
+                    <option value="0" {eq name='cid' value="0" }selected{/eq}>所有栏目</option>
+                    {foreach $category_tree as $value}
+                    <option value="{$value.id}" {eq name='cid' value="$value.id" }selected{/eq}>{$value.name}</option>
+                    {notempty name="value.child"}
+                    {foreach $value.child as $val}
+                    <option value="{$val.id}" {eq name='cid' value="$val.id" }selected{/eq}>--{$val.name}</option>
+                    {notempty name="val.child"}
+                    {foreach $val.child as $vo}
+                    <option value="{$vo.id}" {eq name='cid' value="$vo.id" }selected{/eq}>&nbsp;&nbsp;└ --{$vo.name}
+                    </option>
+                    {/foreach}
+                    {/notempty}
+                    {/foreach}
+                    {/notempty}
+                    {/foreach}
+                </select>
+            </span>
+            <span>
+                <button type="button" class="btn btn-success radius" onclick="search()">确&nbsp;定</button>
+            </span>
         </span>
-        <span class="r">共有数据:<strong id="total">{$list->total()}</strong>条</span>
     </div>
     <div id="edatalist">
         <table class="table table-border table-bordered table-bg">
@@ -55,8 +61,8 @@
                     </td>
                     <td>{$val.id}</td>
                     <td class="text-l">
-                        <a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}" style="text-decoration:none" title="浏览"
-                            target="_blank">{$val.title}</a>
+                        <a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}" style="text-decoration:none"
+                            title="浏览" target="_blank">{$val.title}</a>
                     </td>
                     <td>{$val.category_name}</td>
                     <td>{$val.username}</td>
@@ -83,11 +89,12 @@
         </table>
     </div>
     <div class="cl pd-5 bg-1 bk-gray mt-20 ">
+        <span>共有数据:<strong id="total">{$list->total()}</strong>条</span>
         <span class="r">{$list->render()|raw}</span>
     </div>
 </article>
 <script>
-    $("#sel_option").change(function () {
+    function search() {
         var cid = $("#sel_option").val();
         console.log(cid);
         if (cid) {
@@ -96,5 +103,56 @@
             window.location.href = '/sys/article/index';
         }
         return false;
-    })
+    }
+
+    function moveArticle() {
+        var checkbox = $('.text-c input[name="checkbox[]"]');
+        var ids = new Array();
+        checkbox.each(function (x) {
+            if (this.checked)
+                ids.push(this.value);
+        })
+
+        var length = ids.length;
+
+        if (length == 0) {
+            layer.msg('请选择要移动的选项', {
+                icon: 5,
+                time: 1000
+            });
+            return false;
+        }
+
+        var cid = $("#sel_option").val();
+
+        if (cid == 0) {
+            layer.msg('请选择要移动到的栏目', {
+                icon: 5,
+                time: 1000
+            });
+            return false;
+        }
+
+        layer.confirm('确认要移动选中项吗?', function (index) {
+            $.post('move', {
+                'ids': ids,
+                'cid': cid
+            }, function (data) {
+                if (data.code == 0) {
+                    layer.msg(data.msg, {
+                        icon: 1,
+                        time: 2000
+                    });
+                    window.location.reload();
+                } else {
+                    layer.msg(data.msg, {
+                        icon: 5,
+                        time: 2000
+                    });
+                    return false;
+                }
+            }, 'json');
+        });
+
+    }
 </script>