当前位置:网站首页>Fastadmin TP installation uses Baidu rich text editor ueeditor
Fastadmin TP installation uses Baidu rich text editor ueeditor
2022-07-25 16:23:00 【Bitter summer Bluegrass】
1、 To download UEditor
Baidu rich text editor UEditor 1.4.3 edition , The latest version of the online document is missing, as if
2、 Upload to the project directory
For example, I upload to public/assets Next
3、 Reference and initialize the page you need to use
<!-- html -->
<textarea id="c-remark" name="row[remark]" style="height:300px;">{$row.remark|htmlentities}</textarea>
<!-- js -->
<!-- Remember to change your path -->
<script type="text/javascript" charset="utf-8" src="__CDN__/assets/addons/ueditorbjq/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__CDN__/assets/addons/ueditorbjq/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__CDN__/assets/addons/ueditorbjq/lang/zh-cn/zh-cn.js"></script>
<script> var ue = UE.getEditor('c-remark'); </script>
At this time, you should see the effect , However, you can see in the console that the upload configuration is wrong and the upload function cannot be used , Move on 
4、 Modify background configuration
Create a new in the root directory of the rich text editor config.json
{
"imageActionName": "uploadimage",
"imageFieldName": "upfile",
"imageMaxSize": 2048000,
"imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
"imageCompressEnable": true,
"imageCompressBorder": 1600,
"imageInsertAlign": "none",
"imageUrlPrefix": "https://xxxxxxx/uploads/", // Change to your domain name address
"imagePathFormat": "/{yyyy}{mm}{dd}/{time}{rand:6}" // Change to your upload rules
// Remember to delete the notes
}
5、 Modify the server unified request interface path
modify ueditor.config.js Of 33 Office , take serverUrl Change to your upload address
// Server unified request interface path
, serverUrl: "/api/upload/index"
6、 Add upload method
I was in /api/upload/index, Adjust according to your own
public function index()
{
$action = $this->request->param('action');
switch($action){
case 'config':
$result = file_get_contents(ROOT_PATH.'/public/assets/addons/ueditorbjq/config.json');
break;
case 'uploadimage':
$file = $this->request->file('upfile');
if($file){
$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
$res = $info->getInfo();
$res['state'] = 'SUCCESS';
$res['url'] = $info->getSaveName();
$result = json_encode($res);
}
break;
default:
break;
}
return $result;
}
7、 Modify a single image upload cross domain
When you upload an image, you will find that it is cross domain
Official documentation :
Revised as follows :
use Ajax Upload to solve this problem
First we need to modify ueditor.all.js, Reference here doAjax, newly added doAjaxFile Function to upload files :
function doAjaxFile(url, ajaxOptions) {
console.log('doAjaxFile-----------------------------------------------------------')
console.log(url)
console.log(ajaxOptions)
var xhr = creatAjaxRequest(),
// If the timeout
timeIsOut = false,
// Default parameters
defaultAjaxOptions = {
method: 'POST',
// Timeout time . The default is 5000, The unit is ms
timeout: 15000,
// Is it an asynchronous request . true For asynchronous requests , false Request for synchronization
async: true,
// Request data to carry .
data: {
},
processData: false,
contentType: false,
cache: false,
onsuccess:function() {
},
onerror:function() {
}
};
if (typeof url === "object") {
ajaxOptions = url;
url = ajaxOptions.url;
}
if (!xhr || !url) return;
var ajaxOpts = ajaxOptions ? utils.extend(defaultAjaxOptions,ajaxOptions) : defaultAjaxOptions;
// Timeout detection
var timerID = setTimeout(function() {
if (xhr.readyState != 4) {
timeIsOut = true;
xhr.abort();
clearTimeout(timerID);
}
}, ajaxOpts.timeout);
var method = ajaxOpts.method.toUpperCase();
var str = url + (url.indexOf("?")==-1?"?":"&")
xhr.open(method, str, ajaxOpts.async);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (!timeIsOut && xhr.status == 200) {
ajaxOpts.onsuccess(xhr);
} else {
ajaxOpts.onerror(xhr);
}
}
};
// xhr.upload.addEventListener("progress", function(event) {
// if(event.lengthComputable){
// progress.style.width = Math.ceil(event.loaded * 100 / event.total) + "%";
// }
// }, false);
xhr.send(ajaxOpts.data);
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
And then in UE.Ajax New function in :
sendfile:function(url, opts) {
doAjaxFile(url, opts);
}
Finally, replace the code of the following function :
domUtils.on(input, 'change', function())
Revised document :
Remember to replace these two files at the same time .
边栏推荐
- Solve win10 disk occupation of 100%
- mysql 表写锁
- 百度富文本编辑器UEditor 图片宽度100%自适应,手机端
- MySQL table write lock
- Visual studio 2022 view class diagram
- 只有1000元能买什么理财产品赚钱?
- R语言ggplot2可视化线图(line)、自定义配置标题文本相关内容颜色和图例(legend)颜色相匹配(和分组线图的颜色相匹配、match colors of groups)
- 开发者如何为React Native选择合适的数据库
- MySQL显式锁
- Simple rotation map and hamster beating
猜你喜欢

Quickly deploy mqtt clusters on AWS using terraform

2W word detailed data Lake: concept, characteristics, architecture and cases
![[image hiding] digital image watermarking method technology based on hybrid dwt-hd-svd with matlab code](/img/2a/b5214e9fa206f1872293c9b9d7bdb6.png)
[image hiding] digital image watermarking method technology based on hybrid dwt-hd-svd with matlab code
![[JS advanced] JS regular correlation functions and regular objects_ 02](/img/a0/27bf3f5146a5774eb3167a69d1e3cf.png)
[JS advanced] JS regular correlation functions and regular objects_ 02

2w字详解数据湖:概念、特征、架构与案例

Today, I went to oppo for an interview and was asked numbly

Win11自带画图软件怎么显示标尺?

EMQX Cloud 更新:日志分析增加更多参数,监控运维更省心

Verifiable random function VRF

终极套娃 2.0 | 云原生交付的封装
随机推荐
How does win11's own drawing software display the ruler?
Permission management - role assignment menu
用递归进行数组求和
mysql 表读锁
泰雷兹推出解决方案,助力SAP客户控制云端数据
Use huggingface to quickly load pre training models and datasets in moment pool cloud
权限管理-删除菜单(递归)
C Music
Verifiable random function VRF
Quickly deploy mqtt clusters on AWS using terraform
Implementation of recommendation system collaborative filtering in spark
MySQL隐式锁
Sum arrays with recursion
从业务需求出发,开启IDC高效运维之路
如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
哪个led显示屏厂家更好
C # simulation lottery
Upgrade esxi6.7.0 to 7.0u3f (updated on July 12, 2022)
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
MySQL tutorial 67- filter duplicate data using distinct