GithubHelp home page GithubHelp logo

wang-editor-v4's Introduction

laravel-admin 插件 wangEditor V4 版本富文本编辑器

======

2022-07-30 更新
laravel-admin extension wangEditor 5 富文本编辑器插件 beta 版

======

首先声明,此插件是参照 https://github.com/laravel-admin-extensions/wangEditor 进行修改而来

其次,在原有基础上做了些改进,同一页面支持多个富文本编辑器,且可单独配置改富文本编辑器的配置项。

laravel-admin 插件的富文本编辑器插件本人相中了 wangEditor ,但是相关的插件好像许久都没人维护了,奈何就自己动手吧,根据 wangEditor 的插件的源码与 laravel-admin 中扩展开发的文档,完成了此V4版本的 wangEditor 富文本编辑器插件。

V4版本与V3相比,还是好用很多了。


使用方法,此插件仅使用与 laravel-admin 1.* 版本

1.安装扩展 composer require jonexyz/wang-editor-v4

2.发布静态资源包 php artisan vendor:publish --tag=jonexyz-wangEditorV4

3.配置富文本编辑器配置,参考如下 其中 default 表示默认配置, title 表示对字段为 title 的表单进行单独的富文本编辑器设置,

'extensions' => [

        'wang-editor-v4' => [
            'enable' => true,
            'config' => [
                'default'=>[
                    'uploadImgServer' => '/'.env('ADMIN_ROUTE_PREFIX', 'admin').'/upload',
                    'uploadImgMaxSize' => 3 * 1024 * 1024, // 将图片大小限制为 3M
                    'uploadFileName' => 'images[]', //定义上传的filename,即上传图片的名称
                    'height'=>500
                ],
                'title'=>[
                    'height'=>100,
                    'menus' => [
                        'head',
                        'bold',
                        'fontSize',

                    ]
                ]
            ]
        ]
    ]

4.修改 \app\Admin\bootstrap.php 中设置删除数组中的 editor 字段

5.在form表单中使用它:

$form->editor('content');

6.图片上传默认使用base64格式化后与文本内容一起存入数据库,如果要上传图片到本地接口,可参照如下代码,另还需设置插件上传路径参数 uploadImgServer

<?php

namespace App\Admin\Controllers;

use Illuminate\Http\Request;
use Encore\Admin\Controllers\AdminController;

class CommonController extends AdminController
{
    public function upload(Request $request)
    {
        $type = $request->get('type');

        $dir_path = 'uploads/' . config('admin.upload.directory.image'); // 文件存储路径
        $rule = ['jpg', 'png', 'gif']; //允许的图片后缀


        if ($request->hasFile('images')) {

            $files = $request->file('images'); //接前台图片

            $path = [];
            foreach ($files as $file) {

                $clientName = $file->getClientOriginalName();
                // $tmpName = $file->getFileName();
                // $realPath = $file->getRealPath();
                $size = $file->getSize();
                $entension = $file->getClientOriginalExtension();
                if (!in_array($entension, $rule)) {
                    continue;
                }
                $newName = md5(date("Y-m-d H:i:s") . $clientName) . "." . $entension;
                $path[] = [
                    'path' => $file->move($dir_path, $newName),
                    'file_name' => $clientName,
                    'size' => $size
                ];
                //$namePath = $url_path . '/' . $newName;
                //return $path;

            }

            $insert_data = [];
            foreach ($path as $p) {
                $file_path = str_replace("\\", "/", $p['path']->getPathname());
                $data[] = config('APP.URL') . '/' . $file_path;
                $insert_data[] = [
                    'file_name' => $p['file_name'],
                    'path' => $file_path,
                    'size' => $p['size'],
                    'created_at' => date('Y-m-d H:i:s'),
                    'updated_at' => date('Y-m-d H:i:s')
                ];
            }


            return $res = ['errno' => 0, 'data' => $data];
        }

    }
}

水平有限,如有不当支持见谅。

avatar

wang-editor-v4's People

Contributors

jonexyz avatar

Stargazers

 avatar  avatar BrickCarrier avatar  avatar 展白 avatar Kane Young avatar David lu avatar yema avatar Colin avatar Troy avatar test avatar zhao avatar KwenChan avatar yueyanzhao avatar  avatar jxlwqq avatar

Watchers

James Cloos avatar  avatar

wang-editor-v4's Issues

此版本兼容上传视频吗

您好,感谢提供的wang-editor-v4的插件。
我现在在kindeditor和wangeditor之间徘徊,个人比较偏向wangEditor。但是目前使用的wangeditorV3版本,该版本是不支持上传本地视频的。由于需求的问题,被迫放弃。
我查看文档发现wang-editor的v4.6.3 开始支持上传视频了
此插件兼容视频吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.