当前位置:网站首页>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 .
边栏推荐
- 国债年化利率太低了,有比国债逆回购年化利率还要高的理财产品吗?
- Intention lock
- 开发者如何为React Native选择合适的数据库
- Golang review summary
- MySQL pessimistic lock
- The presentation logic of mail sending and receiving inbox outbox and reply to the problem of broken chain
- EMQX Cloud 更新:日志分析增加更多参数,监控运维更省心
- Emqx cloud update: more parameters are added to log analysis, which makes monitoring, operation and maintenance easier
- MySQL乐观锁
- [zeloengine] summary of pit filling of reflection system
猜你喜欢

吴恩达逻辑回归2

如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?

Product dynamics - Android 13 high-efficiency adaptation new upgrade

leetcode:154. 寻找旋转排序数组中的最小值 II【关于旋转排序数组的中后定位二分法】

MyBaits

进程之间的通信(管道详解)
![[image denoising] image denoising based on bicube interpolation and sparse representation matlab source code](/img/39/716c62d6ca533a7e84704b2c55d072.png)
[image denoising] image denoising based on bicube interpolation and sparse representation matlab source code

解决Win10磁盘占用100%

一文理解分布式开发中的服务治理
![Leetcode:6127. Number of high-quality number pairs [bit operation finding rules + the sum of two numbers is greater than or equal to K + dichotomy]](/img/b5/5c7fc70b8025cf7ef21d645a3ac22e.png)
Leetcode:6127. Number of high-quality number pairs [bit operation finding rules + the sum of two numbers is greater than or equal to K + dichotomy]
随机推荐
[wechat applet] detailed explanation of applet host environment
百度富文本编辑器UEditor单张图片上传跨域
[image denoising] image denoising based on bicube interpolation and sparse representation matlab source code
fastadmin tp 安装使用百度富文本编辑器UEditor
Intention lock
MySQL全局锁
Use huggingface to quickly load pre training models and datasets in moment pool cloud
Emqx cloud update: more parameters are added to log analysis, which makes monitoring, operation and maintenance easier
百奥赛图与LiberoThera共同开发全人GPCR抗体药物取得里程碑式进展
共享锁(Shared Lock)
测试驱动开发(TDD)在线练功房 | 9月17日开课
权限管理-删除菜单(递归)
0x80131500打不开微软商店的解决办法
食品安全丨无处不在的冷冻食品,你真的了解吗?
邮件的收发的展现逻辑之收件箱发件箱以及回复断链的问题
Waterfall flow layout
使用Huggingface在矩池云快速加载预训练模型和数据集
mysql 查看是否锁表
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?
Communication between processes (pipeline details)