百度自帶的自動備份功能enableAutoSave存在問題,
比如第一個文章他自動備份了.等發(fā)表第二個文章時,結(jié)果把第一個文章的內(nèi)容自動填充進(jìn)去了.關(guān)鍵你還不知情!出現(xiàn)過多次這種情況了.
一, 百度原版的 ,具體使用方法,看這里個文章
Ueditor百度編輯器內(nèi)容自動保存到本地防數(shù)據(jù)丟失 https://blog.csdn.net/viqecel/article/details/118600417
二,本人用ajax寫了一個更好用的.特點(diǎn)是,不會自動填充,而是根據(jù)時間,選擇不同版本,手工復(fù)制進(jìn)去即可.
默認(rèn)備份文件名為小時分鐘,比如9月5號13點(diǎn)48分,過了這一分鐘后,后端會自動新建一個txt備份,如果一分鐘內(nèi)有多個版本,則替換掉舊的內(nèi)容.效果圖如下:點(diǎn)擊查看后,進(jìn)一個備份列表面.選擇版本即可.可以自動刪除一周以前的備份.
彈窗提醒效果
后臺效果
點(diǎn)擊查看到的.備份文件列表頁
備份的txt文件內(nèi)容截圖.
三,js代碼
//如果是百度編輯器,要先引入他的js
<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.config.js?q=100"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.all.min.js?q=1010"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
function beifen() {
var title = $('#title').val();
var txt=UE.getEditor("m2cs").getContent();//m2cs為編輯器id,getContent可讀取編輯器的內(nèi)容
$.post("{:U('beifen')}", {'title':title,'content':txt}, function(v){
if( v == 1 ){
show_alert("通用參數(shù)的html源碼已備份到臨時文件中!");
}else{
show_alert("備份異常");
}
});
};
UE.getEditor('m2cs').addListener('focus',function(editor){
UE.getEditor('m2cs').addListener('contentChange',function(editor){
beifen();//百度自帶的監(jiān)聽方法 得到焦點(diǎn),或內(nèi)容變化.會觸發(fā)自動備份.當(dāng)然可以自定義
});
});
// 聲明show_alert 彈窗函數(shù)
function show_alert(message){
var alert2 = $('#alert');
alert2.html(message);
alert2.css('display','block');
var timer_alert = setTimeout("hide_alert()",6000);
};
// 聲明隱藏的函數(shù)
function hide_alert(){
var alert2 = $('#alert');
alert2.css('display','none');
}
四,html彈窗代碼文章來源:http://www.zghlxwxcb.cn/news/detail-695626.html
<div id="alert" style=" width:150px; position:
fixed; bottom: 0; left: 0;
=right: 0; margin: auto; padding: 10px;
box-sizing: border-box; border-radius: 5px;
box-shadow: 0 0 10px; text-align: center;
word-wrap:break-word; display: none;
background-color:rgba(0, 40, 80, 0.8);
color: #ffffff; font-size: 12px;z-index:9999999999"></div>
五,PHP后端代碼示例文章來源地址http://www.zghlxwxcb.cn/news/detail-695626.html
//自動備份
function beifen(){
$title=I('title');
$content=I('content');
$cache=RUNTIME_PATH.'admin_type_edit_auto_html_beifen/'.date("m-d-H-i").'.txt';//文件存在就替換內(nèi)容.不存在就新建
$ok=file_put_contents($cache,'-------標(biāo)題-------- '.$title.' ===============復(fù)制后,編輯框中,點(diǎn)擊HTML按鈕,粘貼后,再點(diǎn)擊一次html即可恢復(fù)備份================='.$content);
if($ok){
echo 1;
}else{
echo 2;
}
}
//備份文件列表
function beifen_list(){
//先刪除7天以前所有文件
$this->del_file_by_time(RUNTIME_PATH.'admin_type_edit_auto_html_beifen/',7);
$cache=RUNTIME_PATH.'admin_type_edit_auto_html_beifen/';
$arrFiles = scandir($cache);//列出文件名
unset($arrFiles[0]);
unset($arrFiles[1]);
rsort($arrFiles);
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">';
foreach($arrFiles as $v){
echo '<a target="_blank"href="/Runtime/admin_type_edit_auto_html_beifen/'.$v.'">'.$v.'</a> <br/> ';
}
}
//遍歷并刪除文件的方法
function del_file_by_time($dir,$n)
{
if(is_dir($dir)){
if($dh=opendir($dir)){
while (false !== ($file = readdir($dh))){
if($file!="." && $file!=".."){
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)){
$filedate=filemtime($fullpath);
$minutes=round((time()-$filedate)/86400);
if($minutes>$n)
unlink($fullpath); //刪除文件
}
}
}
}
closedir($dh);
}
}
到了這里,關(guān)于AJAX + PHP 編輯器內(nèi)容自動備份草稿保存到本地 (適用ueditor百度編輯器或其它) 內(nèi)容變化后自動觸發(fā)備份txt文件的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!