笔记保存功能

This commit is contained in:
daihh
2022-11-10 12:55:41 +08:00
parent 4b68fec949
commit c3999a247f
2 changed files with 49 additions and 23 deletions

View File

@@ -1,7 +1,7 @@
<template>
<!--机构树-->
<div>
<el-dialog title="择组织机构" :append-to-body="true" :visible.sync="dlgShow" :before-close="handleClose" :close-on-click-modal="false" width="500px" custom-class="g-dialog">
<el-dialog title="择组织机构" :append-to-body="true" :visible.sync="dlgShow" :before-close="handleClose" :close-on-click-modal="false" width="500px" custom-class="g-dialog">
<div>
<!--
<el-input placeholder="" v-model="orgName">

View File

@@ -72,7 +72,7 @@ export default {
imgContent:[],
fileBaseUrl: process.env.VUE_APP_FILE_BASE_URL,
isShowList:false,
isShowTip:'',
isShowTip:'',
radio: '1',
editdata:{
content:'',
@@ -84,24 +84,44 @@ export default {
histdata:[],
id:'',
timer:null,
localStorageKey:'note-local-key',
localStorageJson:'',
rowNum:16
};
},
mounted(){
this.id = this.$route.query.id;
this.notedetail();
this.timer = setInterval(()=>{
this.savedata(1);
},30000);
let screenWidth = window.screen.availWidth;
if (screenWidth <= 1440) {
this.editContent = 'edit-content-low';
this.rowNum = 11;
}
//检查是事本地存在
this.localStorageJson= localStorage.getItem(this.localStorageKey);
if(this.localStorageJson){ //存在本地数据
this.loadLocalJson();
}
this.timer = setInterval(()=>{this.savedata(1);},30000);
},
methods:{
loadLocalJson(){ //加载本地的数据
let $this=this;
this.$confirm('您有未保存的笔记,是否加载?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let entity=JSON.parse($this.localStorageJson);
$this.editdata = entity;
$this.editdata.openTypeBackups = entity.openType;
$this.histId = entity.id;
}).catch(() => {
localStorage.removeItem(this.localStorageKey);
});
},
toCoursePage(){
if(this.editdata.type==1){
this.$router.push('/course/detail?id='+this.editdata.courseId);
@@ -110,9 +130,9 @@ export default {
imgDel(index) {
this.imgContent.splice(index,1);
},
timeDel() {
this.editdata.playTime = '';
},
timeDel() {
this.editdata.playTime = '';
},
comeback(){
clearInterval(this.timer);
this.timer = null;
@@ -126,7 +146,6 @@ export default {
this.editdata = res.result;
this.editdata.openTypeBackups = res.result.openType;
this.histId = res.result.id;
this.hist();
})
},
@@ -170,41 +189,45 @@ export default {
},
savedata(num){
if(this.editdata.openTypeBackups == 1 && this.editdata.openType == 9) {
this.$message({
message: '仅支持公开笔记转私密笔记!',
type: 'warning'
});
this.$message({ message: '仅支持公开笔记转私密笔记!', type: 'warning' });
this.editdata.openType == 1;
}
if(num == 1) {
this.editdata.isAuto = true;
}
if(this.imgContent.length > 0) {
this.editdata.content = this.imgContent.join();
}
apiNote.update(this.editdata).then(res=>{
if(res.status == 200) {
sessionStorage.setItem('isShowTip','');
localStorage.removeItem(this.localStorageKey); //清空本地缓存
if(num ==1) {//自动保存
this.editdata.sysVersion += 1;
this.isShowTip = '笔记自动保存成功';
setTimeout(()=>{
this.isShowTip = '';
},10000*2)
setTimeout(()=>{ this.isShowTip = ''; },10000*2)
} else {
this.notedetail()
this.$message({message: '笔记保存成功',type: 'success',center: true});
// 跳转到笔记列表
//跳转到笔记列表
clearInterval(this.timer);
this.timer = null;
this.$router.go(-1);
}
}else{
if(num ==1){
console.log('笔记保存失败:'+res.message);
}else{
this.$message({message: '笔记保存失败:'+res.message,type: 'error',center: true});
}
}
}).catch(()=>{
let saveJsonStr = JSON.stringify(this.editdata);
//本地保存
localStorage.setItem(this.localStorageKey,saveJsonStr);
this.isShowTip = '当前网络异常,内容已离线保存,请尝试连接网络后重新保存!';
setTimeout(()=>{ this.isShowTip = ''; },10000 * 2)
sessionStorage.setItem('isShowTip',this.editdata.content);
//this.$message({message: '当前网络异常,内容已离线保存,请尝试连接网络后重新保存!',type: 'warning',center: true});
setTimeout(()=>{ this.isShowTip = ''; },10000 * 2);
})
}
},
@@ -215,8 +238,11 @@ export default {
this.timer = null
},
destroyed(){
clearInterval(this.timer)
this.timer = null
if(this.timer!=null){
clearInterval(this.timer)
this.timer = null
}
}
}