当前位置:网站首页>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 .
边栏推荐
- 阿唐的小帮手
- MyBaits
- 今天睡眠质量记录84分
- leetcode:154. 寻找旋转排序数组中的最小值 II【关于旋转排序数组的中后定位二分法】
- Emqx cloud update: more parameters are added to log analysis, which makes monitoring, operation and maintenance easier
- Implementation of recommendation system collaborative filtering in spark
- 递归菜单查询(递归:自己查自己)
- High score technical document sharing of ink Sky Wheel - Database Security (48 in total)
- Is the win11 dynamic tile gone? Method of restoring dynamic tile in Win 11
- Waterfall flow layout
猜你喜欢

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

可验证随机函数 VRF

Use huggingface to quickly load pre training models and datasets in moment pool cloud

使用 Terraform 在 AWS 上快速部署 MQTT 集群

Upgrade esxi6.7.0 to 7.0u3f (updated on July 12, 2022)

MyBaits

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

【图像去噪】基于双立方插值和稀疏表示实现图像去噪matlab源码

Emqx cloud update: more parameters are added to log analysis, which makes monitoring, operation and maintenance easier

I interviewed 8 companies and got 5 offers in a week. Share my experience
随机推荐
MySQL self incrementing lock
Exclusive lock
Permission management - delete menu (recursive)
Paper notes: highly accurate protein structure prediction with alphafold (alphafold 2 & appendix)
Lazy loading of pictures
没错,请求DNS服务器还可以使用UDP协议
如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
Shared lock
Win11动态磁贴没了?Win11中恢复动态磁贴的方法
[wechat applet] detailed explanation of applet host environment
MyBaits
I interviewed 8 companies and got 5 offers in a week. Share my experience
Implementation of recommendation system collaborative filtering in spark
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
食品安全丨无处不在的冷冻食品,你真的了解吗?
Equivalent change of resistance circuit (Ⅱ)
MYSQL导入sqllite表格的两种方法
02. Limit the parameter props to a list of types
mysql 表写锁
权限管理-删除菜单(递归)