chengkun
2025-08-29 a370f8c298c691b18f713d4db19919162fbd3299
提交
3 files modified
1 files added
114 ■■■■■ changed files
app/admin/controller/Blog.php 18 ●●●●● patch | view | raw | blame | history
app/admin/validate/Blog.php 19 ●●●●● patch | view | raw | blame | history
app/admin/view/blog/add.html 71 ●●●●● patch | view | raw | blame | history
public/static/admin/js/blog/add.js 6 ●●●●● patch | view | raw | blame | history
app/admin/controller/Blog.php
@@ -60,7 +60,7 @@
    }
    
    /**
     * 上传图片
     * 上传封面图片
     * @return Json
     */
    public function upload_cover_img(): Json {
@@ -98,4 +98,20 @@
        }
        return json($result);
    }
    public function save_blog() {
        try {
            if (!request()->isPost()) {
                throw new Exception('请求方式错误');
            }
            $data = request()->post();
        } catch (Exception $exc) {
            $result = [
                'code'    => $exc->getCode(),
                'message' => $exc->getMessage(),
            ];
        }
        return json($result);
    }
}
app/admin/validate/Blog.php
New file
@@ -0,0 +1,19 @@
<?php
namespace app\admin\validate;
use think\Validate;
class Blog extends Validate {
    protected $rule    = [
        'title'      => 'require',
        'menu_index' => 'require',
    ];
    protected $message = [
        'title.require'      => '请填写菜单名称',
        'menu_index.require' => '请填写菜单索引',
    ];
}
app/admin/view/blog/add.html
@@ -104,7 +104,7 @@
                                    <template v-if="addBlogForm.cover_img">
                                        <div>
                                            <img :src="addBlogForm.cover_img" class="avatar" />
                                            <el-button type="danger" icon="Delete"></el-button>
                                            <!-- <el-button type="danger" icon="Delete"></el-button> -->
                                        </div>
                                    </template>
                                    <el-icon v-else class="avatar-uploader-icon">
@@ -256,75 +256,6 @@
        config: toolbarConfigEn,
        mode: 'default', // or 'simple'
    })
</script>
<script>
    /**
     * 富文本编辑器
     */
    // var E = window.wangEditor
    // const editor = new E('#editer_data')
    // var textarea = $('#content')
    // editor.config.onchange = function (html) {
    //     // 监控变化,同步更新到 textarea
    //     textarea.val(html)
    // }
    // // editor.config.onblur = function (html) {
    // //     // 编辑区域失去焦点后的操作,保存内容
    // //     save_reading_data();
    // // }
    // //设置提示文字
    // editor.config.placeholder = '请输入文章内容...'
    // //设置编辑区域z-index
    // editor.config.zIndex = 100
    // // 自定义菜单配置
    // editor.config.menus = [
    //     'bold',
    //     'fontSize',
    //     'italic',
    //     'underline',
    //     'strikeThrough',
    //     'indent',
    //     'lineHeight',
    //     'foreColor',
    //     'backColor',
    //     'link',
    //     'list',
    //     'justify',
    //     'image',
    // ]
    // //粘贴内容去掉图片
    // editor.config.pasteIgnoreImg = true
    // // 配置粘贴文本的内容处理
    // editor.config.pasteTextHandle = function (pasteStr) {
    //     // 对粘贴的文本进行处理,然后返回处理后的结果
    //     return pasteStr.replace(/<[^>]+>/g, "");
    // }
    // //上传图片服务端地址
    // editor.config.uploadImgServer = "/admin/upload/index_v1.html"
    // // 隐藏“网络图片”tab
    // editor.config.showLinkImg = false
    // // 将图片大小限制为 10M
    // editor.config.uploadImgMaxSize = 20 * 1024 * 1024
    // // 限制一次最多上传 20 张图片
    // editor.config.uploadImgMaxLength = 20
    // //编辑器初始化
    // editor.create()
    // // 初始化 textarea 的值
    // textarea.val(editor.txt.html())
    ////////////////////////////////////////富文本编辑器-end//////////////////////////////////
</script>
</html>
public/static/admin/js/blog/add.js
@@ -29,6 +29,7 @@
            }
        },
        /////上传图片成功后/////
        handleCoverImgSuccess(response, uploadFile) {
            if (response.code != 200) {
                this.$message({
@@ -39,12 +40,9 @@
                return false;
            }
            this.addBlogForm.cover_img = response.data.url;
            // console.log(response,uploadFile);
            // this.addBlogForm.cover_img = arguments[0].url;
        },
        handleRemove(){},
        /////上传图片之前/////
        beforeCoverImgUpload(rawFile) {
            // console.log(rawFile);
            if (rawFile.type !== 'image/jpeg') {