当前位置:网站首页>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 .
边栏推荐
- Typescript learning 2 - Interface
- tkinter模块高级操作(一)—— 透明按钮、透明文本框、自定义按钮及自定义文本框
- LVGL 7.11 tileview界面循环切换
- 如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
- Exclusive lock
- 哪个led显示屏厂家更好
- Test Driven Development (TDD) online practice room | classes open on September 17
- 02. Limit the parameter props to a list of types
- Product upgrade observation station in June
- 国债年化利率太低了,有比国债逆回购年化利率还要高的理财产品吗?
猜你喜欢

fastadmin tp 安装使用百度富文本编辑器UEditor

Talk about how to use redis to realize distributed locks?

论文笔记:Highly accurate protein structure prediction with AlphaFold (AlphaFold 2 & appendix)

Quickly deploy mqtt clusters on AWS using terraform

用递归进行数组求和
![[zeloengine] summary of pit filling of reflection system](/img/7a/c85ba66c5dd05908b2d784fab306a2.png)
[zeloengine] summary of pit filling of reflection system

食品安全丨无处不在的冷冻食品,你真的了解吗?
![[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training](/img/d4/bcc577f320a893c7006177993b2e7a.png)
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training

How to build an enterprise level OLAP data engine for massive data and high real-time requirements?

Waterfall flow layout
随机推荐
Google Earth Engine——全球建筑物GlobalMLBuildingFootprints矢量集合下载
测试框架-unittest-跳过测试
MyBaits
Exclusive lock
The presentation logic of mail sending and receiving inbox outbox and reply to the problem of broken chain
01.一个更简单的方法来传递大量的props
The annualized interest rate of treasury bonds is too low. Is there a financial product with a higher annualized interest rate than the reverse repurchase of treasury bonds?
Leetcode:528. select randomly according to the weight [ordinary random failure + prefix and dichotomy]
[image hiding] digital image watermarking method technology based on hybrid dwt-hd-svd with matlab code
MySQL 悲观锁
Typescript learning 2 - Interface
Shared lock
R语言偏相关性计算(Partial Correlation)、使用ggm包的pcor函数计算偏相关性(Partial Correlations)
R语言使用gt包和gtExtras包漂亮地显示表格数据:gt_bar_plot函数和gt_plt_bar_pct函数可视化百分比条形图、原始数据的百分比条形、缩放后的数据的百分比条形、指定数据对齐宽度
[image denoising] image denoising based on bicube interpolation and sparse representation matlab source code
mysql 查看是否锁表
从业务需求出发,开启IDC高效运维之路
今天去 OPPO 面试,被问麻了
MYSQL导入sqllite表格的两种方法
解决Win10磁盘占用100%