huwhois 2 vuotta sitten
vanhempi
commit
9046f80552

+ 4 - 3
app/sys/controller/Article.php

@@ -18,6 +18,7 @@ use think\facade\Config;
 use app\common\model\Category as CategoryModel;
 use app\common\model\Article as ArticleModel;
 use app\common\service\FileService;
+use app\common\facade\FileUtils;
 
 /**
  * 文章管理控制器
@@ -87,6 +88,8 @@ class Article extends Base
                 $data->content_type = $content_type;
             }
 
+            $data->cjid = time();
+
             $categories = CategoryModel::field('id, parent_id, name')->select();
 
             View::assign('category_tree', list_tree($categories));
@@ -100,8 +103,6 @@ class Article extends Base
 
     protected function saveRomteImage($content)
     {
-        $fileService = new FileService();
-
         $content = stripslashes ($content);
         $img_array = [];
         // 匹配所有远程图片
@@ -112,7 +113,7 @@ class Article extends Base
         $img_arrays = array_unique ($img_array[1]);
 
         foreach ($img_arrays as $value) {
-            $file = $fileService->downloadUrlImg($value);
+            $file = FileUtils::downloadUrlImg($value);
             
             $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
             

BIN
public/static/images/success.gif


BIN
public/static/images/success.png


+ 1 - 0
view/sys/article/save.html

@@ -7,6 +7,7 @@
 <article class="cl pd-20">
     <form action="{:url('save')}" method="post" class="form form-horizontal" id="form-save">
         <input type="hidden" name="id" value="{$data['id']}">
+        <input type="hidden" name="cjid" value="{$data['cjid']}">
         <input type="hidden" name="content_type" value="{$data['content_type']}">
         <div class="row cl">
             <label class="form-label col-xs-4 col-sm-2">

+ 28 - 327
view/sys/article/savemd.html

@@ -22,8 +22,8 @@
 
     #dialog {
         position: fixed;
-        height: 400px;
-        width: 800px;
+        height: 300px;
+        width: 600px;
         background: #FFFFFF;
         z-index: 5;
         left: 30%;
@@ -32,15 +32,6 @@
         display: none;
     }
 
-    #showImg {
-        height: 160px;
-        width: 160px;
-        position: absolute;
-        border: 0.5px solid gainsboro;
-        bottom: 80px;
-        left: 35%;
-    }
-
     #cancel {
         border: 0px none #FFECEC;
         background: #999999;
@@ -68,85 +59,12 @@
     #insert:hover {
         background: #CB474D;
     }
-
-    #online {
-        width: 100%;
-        height: 224px;
-        padding: 10px 0 0 0;
-    }
-
-    #online #imageList {
-        width: 100%;
-        height: 100%;
-        overflow-x: hidden;
-        overflow-y: auto;
-        position: relative;
-        margin-left: 20px;
-    }
-
-    #online ul {
-        display: block;
-        list-style: none;
-        margin: 0;
-        padding: 0;
-    }
-
-    #online li {
-        float: left;
-        display: block;
-        list-style: none;
-        padding: 0;
-        width: 113px;
-        height: 113px;
-        margin: 0 0 9px 9px;
-        background-color: #eee;
-        overflow: hidden;
-        cursor: pointer;
-        position: relative;
-    }
-
-    #online li img {
-        cursor: pointer;
-    }
-
-    #online li .icon {
-        cursor: pointer;
-        width: 113px;
-        height: 113px;
-        position: absolute;
-        top: 0;
-        left: 0;
-        z-index: 2;
-        border: 0;
-        background-repeat: no-repeat;
-    }
-
-    #online li .icon:hover {
-        width: 107px;
-        height: 107px;
-        border: 3px solid #1094fa;
-    }
-
-    #online li.selected .icon {
-        background-image: url(/static/images/success.png);
-        background-image: url(images/success.gif)\9;
-        background-position: 75px 75px;
-    }
-
-    #online li.clearFloat {
-        float: none;
-        clear: both;
-        display: block;
-        width: 0;
-        height: 0;
-        margin: 0;
-        padding: 0;
-    }
 </style>
 
 <article class="cl pd-20">
     <form action="{:url('save')}" method="post" class="form form-horizontal" id="form-save">
         <input type="hidden" name="id" value="{$data['id']}">
+        <input type="hidden" name="cjid" value="{$data['cjid']}">
         <input type="hidden" name="content_type" value="{$data['content_type']}">
         <div class="row cl">
             <label class="form-label col-xs-4 col-sm-2">
@@ -288,97 +206,12 @@
         <img src="/static/images/X.png" style="height: 25px;width: 25px;position: absolute;right: 10px;top: 10px;cursor: pointer;"
             onclick="f_cancel()" />
     </div>
-
-    <div id="tab-img" class="HuiTab" style="margin-top: 40px;">
-        <div class="tabBar clearfix">
-            <span>本地上传</span>
-            <span>网络文件上传</span>
-            <a onclick="onlinepicture(1)"><span>服务器图片选择</span></a>
-        </div>
-        <div class="tabCon">
-            <div class="step1 active" style="margin-left:30px;">
-                <form id="form-uploadimg" method="post" action="" enctype="multipart/form-data">
-                    <div class="row cl" style="margin-top:20px;">
-                        <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>图片要求: </label>
-                        <div class="formControls col-xs-8 col-sm-8">
-                            格式 jpg,png,gif,jpeg,webp; 大小不超过4M.
-                        </div>
-                        <div class="col-3"> </div>
-                    </div>
-                    <div class="row cl">
-                        <label class="form-label col-xs-2 col-sm-2">
-                            <span class="c-red">*</span>本地上传:</label>
-                        <div class="formControls col-xs-4 col-sm-4">
-                            <input type="file" class="input-text" name="upload_file" id="upload_file">
-                        </div>
-                        <div class="formControls col-xs-2 col-sm-2">
-                            <button class="btn btn-primary radius" type="button" onCLick="uploadImg()">上传</button>
-                        </div>
-                        <div style="width: 200px;height: 200px;">
-                            <img id="view-picture" src="/static/images/upload_picture.png" alt="图片"
-                                title="图片" style="max-width: 200px;max-height: 200px;">
-                        </div>
-                        <div class="col-3"> </div>
-                    </div>
-                </form>
-            </div>
-            <!-- 本地上传end -->
-        </div>
-        <div class="tabCon">
-            <div class="step2" style="margin-left:30px;">
-                <form id="form-uploadurlimg" method="post" action="" enctype="multipart/form-data">
-                    <div class="row cl" style="margin-top:20px;">
-                        <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>图片要求: </label>
-                        <div class="formControls col-xs-8 col-sm-8">
-                            格式 jpg,png,gif,jpeg,webp; 大小不超过4M.
-                        </div>
-                        <div class="col-3"> </div>
-                    </div>
-                    <div class="row cl" style="margin-top:20px;">
-                        <label class="form-label col-xs-2 col-sm-2">
-                            <span class="c-red">*</span>图片地址:</label>
-                        <div class="formControls col-xs-8 col-sm-8">
-                            <input type="text" class="input-text" name="url_file" id="url_file">
-                        </div>
-                        <div class="formControls col-xs-2 col-sm-2">
-                            <button class="btn btn-primary radius" type="button" onCLick="uploadUrlImg()">确定</button>
-                        </div>
-                        <div style="width: 200px;height: 200px;">
-                            <img id="view-picture-url" src="/static/images/upload_picture.png" alt="图片"
-                                title="图片" style="max-width: 200px;max-height: 200px;">
-                        </div>
-                        <div class="col-3"> </div>
-                    </div>
-                </form>
-            </div>
-            <!-- 网络图片 -->
-        </div>
-        <!-- 在线图片 -->
-        <div class="tabCon">
-            <form id="form-uploadonlineimg" method="post" action="" enctype="multipart/form-data">
-                <div class="row cl" style="margin-top:20px;" id="online">
-                    <div id="imageList">
-                        <ul class="list">
-                            <!-- <li>
-                                    <img width="170" height="113" src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg?noCache=1634567323"
-                                     _src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg">
-                                    <span class="icon"></span>
-                                </li>
-                                 -->
-                            <li class="clearFloat"></li>
-                        </ul>
-                    </div>
-                </div>
-                <div class="row cl">
-                    <label class="form-label col-xs-2 col-sm-2">
-                        <span class="c-red">*</span>图片地址:</label>
-                    <div class="formControls col-xs-8 col-sm-8">
-                        <input type="text" class="input-text" name="online_file" id="online_file">
-                    </div>
-                    <div class="col-3"> </div>
-                </div>
-            </form>
+    <div class="row cl" style="margin-top:40px;">
+        <div style="width: 160px;height: 160px;margin: 0 auto;display: table-cell;vertical-align: middle;text-align: center;">
+            <img id="view-picture" src="/static/images/upload_picture.png" alt="图片"
+                title="图片" style="max-width: 120px;max-height: 120px;" onclick="addPicture()">
         </div>
+        <input type="text" class="input-text" name="picture" id="picture" value="">
     </div>
     <div style="position: absolute;bottom: 1px;width: 100%;height: 40px;border-top: 1px solid gray;">
         <button id="cancel" onclick="f_cancel()">取消</button>
@@ -395,40 +228,27 @@
 <script type="text/javascript" src="/static/plugins/jquery.validation/1.14.0/validate-methods.js"></script>
 
 <script type="text/javascript">
-    jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
-        var $tab_menu = $(tabBar);
-        // 初始化操作
-        $tab_menu.removeClass(class_name);
-        $(tabBar).eq(i).addClass(class_name);
-        $(tabCon).hide();
-        $(tabCon).eq(i).show();
-
-        $tab_menu.bind(tabEvent, function () {
-            $tab_menu.removeClass(class_name);
-            $(this).addClass(class_name);
-            var index = $tab_menu.index(this);
-            $(tabCon).hide();
-            $(tabCon).eq(index).show()
-        })
-    }
-
     var editor = ace.edit('mdeditor');//编辑框
 
     editor.setTheme('ace/theme/chrome');
     editor.getSession().setMode('ace/mode/markdown');
     editor.renderer.setShowPrintMargin(false);
 
+    //左侧插入,用户插入一些特定方法
+    function insertText(val) {
+        editor.insert(val); //光标位置插入
+    }
+
     //添加标题图
     function addTitlePic() {
-        layer.open({
-            type: 2,
-            area: ['700px', '500px'],
-            fix: false, //不固定
-            maxmin: true,
-            shade: 0.4,
-            title: '添加标题图',
-            content: '{:url("file_manager/uploadimg", ["_layer"=>true,"img_id"=>"titlepic"])}'
-        });
+        let url = '{:url("file_manager/uploadimg", ["_layer"=>true,"img_id"=>"titlepic","infoid"=>$data.id,"cjid"=>$data.cjid])}'
+        layer_show('添加标题图', url, 800, 500);
+    }
+
+    // 上传图片
+    function addPicture() {
+        let url = '{:url("file_manager/uploadimg", ["_layer"=>true,"img_id"=>"picture","infoid"=>$data.id,"cjid"=>$data.cjid])}'
+        layer_show('插入图片', url, 800, 500);
     }
 
     //插入图片弹窗取消
@@ -439,139 +259,20 @@
     function showDialog() {
         $('#dialog').show();
     }
-
-    //左侧插入,用户插入一些特定方法
-    function insertText(val) {
-        editor.insert(val); //光标位置插入
-    }
-
-    // 文档图片插入地址
-    var imgUrl = "";
-
+    
     //插入图片
     function insert() {
         $('#dialog').hide();
-        insertText('![这里写图片描述](' + imgUrl + ')')
-    }
 
-    //上传图片到服务器,返回图片地址
-    function uploadFile() {
-        imgUrl = 'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white.png';
-        $('#showImg').attr('src', 'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white.png');
-    }
-
-    //本地上传图片
-    function uploadImg() {
-        if ($("#upload_file").val() == '') {
-            layer.msg("请选择要上传的文件", {
-                icon: 6,
-                time: 1000
-            });
-            return false;
-        } else {
-            var formData = new FormData($("#form-uploadimg")[0]);
-            $.ajax({
-                url: '{:url("file_manager/uploadimg")}',
-                type: 'POST',
-                async: true,
-                cache: false,
-                data: formData,
-                processData: false,
-                contentType: false,
-                dataType: "json",
-                success: function (res) {
-                    if (res.code == 0) {
-                        console.log(res);
-                        imgUrl = res.picture_url + res.picname;
-                        $("#view-picture").attr('src', imgUrl);
-                    } else {
-                        layer.msg(res.msg, {
-                            icon: 5,
-                            time: 1000
-                        });
-                        return false;
-                    }
-                }
-            });
-        }
-    }
-
-    // 网络图片
-    function uploadUrlImg() {
-        if ($("#url_file").val() == '') {
-            layer.msg("请选择要上传的地址", {
-                icon: 6,
-                time: 1000
-            });
-            return false;
-        } else {
-            var formData = new FormData($("#form-uploadurlimg")[0]);
-            $.ajax({
-                url: '{:url("file_manager/uploadurlimg")}',
-                type: 'POST',
-                async: true,
-                cache: false,
-                data: formData,
-                processData: false,
-                contentType: false,
-                dataType: "json",
-                success: function (res) {
-                    if (res.code == 0) {
-                        console.log(res);
-                        imgUrl = res.picture_url + res.picname;
-                        $("#view-picture-url").attr('src', imgUrl);
-                    } else {
-                        layer.msg(res.msg, {
-                            icon: 5,
-                            time: 1000
-                        });
-                        return false;
-                    }
-                }
-            });
-        }
-    }
+        // 文档图片插入地址
+        var imgUrl = $("#picture").val();
+        
+        insertText('![这里写图片描述](' + imgUrl + ')')
 
-    // 获取服务器图片
-    function onlinepicture(page) {
-        var data = { "page": page };
-        $.ajax({
-            url: '{:url("file_manager/onlineimg")}',
-            type: 'GET',
-            async: true,
-            cache: false,
-            data: 'page=' + page,
-            processData: false,
-            contentType: false,
-            dataType: "json",
-            success: function (res) {
-                if (res.code == 0) {
-                    html_str = "";
-                    res.list.forEach(element => {
-                        html_str += '<li><img width="170" height="113" src="' + element.url + '?noCache=' + element.mtime + '"';
-                        html_str += '_src="' + element.url + '">';
-                        html_str += '<span class="icon"></span></li>';
-                    });
-                    $('ul.list').prepend(html_str);
-                }
-            }
-        });
+        $("#picture").val('');
+        $("#view-picture").attr('src', '/static/images/upload_picture.png');
     }
 
-    $(function () {
-        $.Huitab("#tab-img .tabBar span", "#tab-img .tabCon", "current", "click", "0");
-        $(document).on("click", "#online li", function () {
-            $("#online li").removeClass('selected');
-
-            $(this).addClass('selected');
-
-            imgUrl = $(this).children('img').attr('_src');
-
-            $("#online_file").val(imgUrl);
-        })
-    });
-
-
     function validator(params) {
         return $("#form-save").validate({
             debug: true,

+ 30 - 18
view/sys/file_manager/database_picture.html

@@ -64,32 +64,44 @@
     }
 
     #online li.clearFloat {
-        float: none;
+        float: left;
         clear: both;
         display: block;
-        width: 0;
-        height: 0;
-        margin: 0;
+        width: 113px;
+        height: 113px;
+        margin: 0 0 9px 9px;
         padding: 0;
     }
 </style>
-<form id="form-uploadurlimg" method="post" action="" enctype="multipart/form-data">
-    <div class="cl mt-20" id="online">
-        <div id="imageList">
-            <ul class="list">
-                <!-- <li>
-                    <img width="170" height="113" src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg?noCache=1634567323"
-                     _src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg">
-                    <span class="icon"></span>
-                </li>
-                 -->
-                <li class="clearFloat"></li>
-            </ul>
-        </div>
+
+<div class="cl mt-20" id="online">
+    <div id="imageList">
+        <ul class="list">
+            <!-- <li>
+                <img width="170" height="113" src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg?noCache=1634567323"
+                 _src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg">
+                <span class="icon"></span>
+            </li>
+             -->
+            <li class="clearFloat"></li>
+        </ul>
     </div>
-</form>
+</div>
 
 <script type="text/javascript">
+    $(function () {
+        $.Huitab("#tab-img .tabBar span", "#tab-img .tabCon", "current", "click", "0");
+        $(document).on("click", "#online li", function () {
+            $("#online li").removeClass('selected');
+            
+            $(this).addClass('selected');
+            
+            img = $(this).children('img').attr('_src');
+            
+            $("#online_file").val(img);
+        });
+    });
+    
     function onlinepicture() {
         let infoid = $("input[name='infoid']").val();
         let cjid = $("input[name='cjid']").val();

+ 7 - 28
view/sys/file_manager/uploadimg.html

@@ -1,19 +1,13 @@
-<!-- <div class="cl pd-5 bg-1 bk-gray">
-        <a href="{:url('/file_manager/selectpicture')}" class="btn btn-default radius sethumb">
-            <i class="Hui-iconfont">&#xe600;</i> 站内选择 </a>&nbsp;&nbsp;
-        <a href="javascript:void(0);" class="btn btn-primary radius sethumb">
-            <i class="Hui-iconfont">&#xe600;</i> 本地上传 </a>&nbsp;&nbsp;
-        <a href="{:url('/file_manager/onlinepicture')}" class="btn btn-default radius sethumb">
-            <i class="Hui-iconfont">&#xe600;</i> 网络图片 </a>&nbsp;&nbsp;
-    </div> -->
-<!-- 本地上传 -->
 <div id="tab-img" class="HuiTab">
     <div class="tabBar clearfix">
         <span>本地上传</span>
         <span>网络文件上传</span>
         <span>服务器图片选择</span>
         <input type="hidden" name="layer" id="layer" value="{$layer}">
+        <input type="hidden" name="infoid" value={$infoid}>
+        <input type="hidden" name="cjid" value={$cjid}>
     </div>
+    <!-- 本地上传 -->
     <div class="tabCon">
         <div class="step1 active" style="margin-left:30px;">
             <form id="form-uploadimg" method="post" action="" enctype="multipart/form-data">
@@ -36,7 +30,7 @@
                     <input type="hidden" name="img_id" value={$img_id}>
                     <input type="hidden" name="infoid" value={$infoid}>
                     <input type="hidden" name="cjid" value={$cjid}>
-                    <div class="formControls col-sm-8">
+                    <div class="formControls col-sm-12">
                         <div class="skin-minimal">
                             <div class="check-box">
                                 <input type="checkbox" name="thumb" value="true" {$thumb ? 'checked' : "" }>
@@ -45,9 +39,7 @@
                                     style="width: 80px;">缩略图宽度
                                 <input type="text" class="input-text" name="height" value={$height}
                                     style="width: 80px;">缩略图高度
-                            </div>
-                            <div class="check-box">
-                                <input type="checkbox" name="original" value="true" {$original ? 'checked' : "" }>
+                                <input type="checkbox" name="original" value="true" {$original ? 'checked' : "" } style="margin-left: 20px;">
                                 <label for="overwrite">保留原图</label>
                             </div>
                         </div>
@@ -85,9 +77,7 @@
             </div>
             <div class="row cl" style="margin-top:20px;">
                 <input type="hidden" name="img_id" value={$img_id}>
-                <input type="hidden" name="infoid" value={$infoid}>
-                <input type="hidden" name="cjid" value={$cjid}>
-                <div class="formControls col-xs-12 col-sm-8">
+                <div class="formControls col-xs-12 col-sm-12">
                     <div class="skin-minimal">
                         <div class="check-box">
                             <input type="checkbox" name="thumb" value="{$thumb}" {$thumb ? 'checked' : "" }>
@@ -95,9 +85,7 @@
                             <input type="text" class="input-text" name="width" value={$width} style="width: 80px;">缩略图宽度
                             <input type="text" class="input-text" name="height" value={$height}
                                 style="width: 80px;">缩略图高度
-                        </div>
-                        <div class="check-box">
-                            <input type="checkbox" name="original" value="{$original}" {$original ? 'checked' : "" }>
+                            <input type="checkbox" name="original" value="{$original}" {$original ? 'checked' : "" } style="margin-left: 20px;">
                             <label for="overwrite">保留原图</label>
                         </div>
                     </div>
@@ -173,15 +161,6 @@
 
     $(function () {
         $.Huitab("#tab-img .tabBar span", "#tab-img .tabCon", "current", "click", "0");
-        $(document).on("click", "#online li", function () {
-            $("#online li").removeClass('selected');
-
-            $(this).addClass('selected');
-
-            img = $(this).children('img').attr('_src');
-
-            $("#online_file").val(img);
-        });
 
         $("#database_picture").click(function () {
             $(".online-picture").css('display', 'none');