笔记保存功能

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> <template>
<!--机构树--> <!--机构树-->
<div> <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> <div>
<!-- <!--
<el-input placeholder="" v-model="orgName"> <el-input placeholder="" v-model="orgName">

View File

@@ -84,24 +84,44 @@ export default {
histdata:[], histdata:[],
id:'', id:'',
timer:null, timer:null,
localStorageKey:'note-local-key',
localStorageJson:'',
rowNum:16 rowNum:16
}; };
}, },
mounted(){ mounted(){
this.id = this.$route.query.id; this.id = this.$route.query.id;
this.notedetail(); this.notedetail();
this.timer = setInterval(()=>{
this.savedata(1);
},30000);
let screenWidth = window.screen.availWidth; let screenWidth = window.screen.availWidth;
if (screenWidth <= 1440) { if (screenWidth <= 1440) {
this.editContent = 'edit-content-low'; this.editContent = 'edit-content-low';
this.rowNum = 11; this.rowNum = 11;
} }
//检查是事本地存在
this.localStorageJson= localStorage.getItem(this.localStorageKey);
if(this.localStorageJson){ //存在本地数据
this.loadLocalJson();
}
this.timer = setInterval(()=>{this.savedata(1);},30000);
}, },
methods:{ 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(){ toCoursePage(){
if(this.editdata.type==1){ if(this.editdata.type==1){
this.$router.push('/course/detail?id='+this.editdata.courseId); this.$router.push('/course/detail?id='+this.editdata.courseId);
@@ -126,7 +146,6 @@ export default {
this.editdata = res.result; this.editdata = res.result;
this.editdata.openTypeBackups = res.result.openType; this.editdata.openTypeBackups = res.result.openType;
this.histId = res.result.id; this.histId = res.result.id;
this.hist(); this.hist();
}) })
}, },
@@ -170,28 +189,22 @@ export default {
}, },
savedata(num){ savedata(num){
if(this.editdata.openTypeBackups == 1 && this.editdata.openType == 9) { if(this.editdata.openTypeBackups == 1 && this.editdata.openType == 9) {
this.$message({ this.$message({ message: '仅支持公开笔记转私密笔记!', type: 'warning' });
message: '仅支持公开笔记转私密笔记!',
type: 'warning'
});
this.editdata.openType == 1; this.editdata.openType == 1;
} }
if(num == 1) { if(num == 1) {
this.editdata.isAuto = true; this.editdata.isAuto = true;
} }
if(this.imgContent.length > 0) { if(this.imgContent.length > 0) {
this.editdata.content = this.imgContent.join(); this.editdata.content = this.imgContent.join();
} }
apiNote.update(this.editdata).then(res=>{ apiNote.update(this.editdata).then(res=>{
if(res.status == 200) { if(res.status == 200) {
sessionStorage.setItem('isShowTip',''); localStorage.removeItem(this.localStorageKey); //清空本地缓存
if(num ==1) {//自动保存 if(num ==1) {//自动保存
this.editdata.sysVersion += 1; this.editdata.sysVersion += 1;
this.isShowTip = '笔记自动保存成功'; this.isShowTip = '笔记自动保存成功';
setTimeout(()=>{ setTimeout(()=>{ this.isShowTip = ''; },10000*2)
this.isShowTip = '';
},10000*2)
} else { } else {
this.notedetail() this.notedetail()
this.$message({message: '笔记保存成功',type: 'success',center: true}); this.$message({message: '笔记保存成功',type: 'success',center: true});
@@ -200,11 +213,21 @@ export default {
this.timer = null; this.timer = null;
this.$router.go(-1); this.$router.go(-1);
} }
}else{
if(num ==1){
console.log('笔记保存失败:'+res.message);
}else{
this.$message({message: '笔记保存失败:'+res.message,type: 'error',center: true});
}
} }
}).catch(()=>{ }).catch(()=>{
let saveJsonStr = JSON.stringify(this.editdata);
//本地保存
localStorage.setItem(this.localStorageKey,saveJsonStr);
this.isShowTip = '当前网络异常,内容已离线保存,请尝试连接网络后重新保存!'; this.isShowTip = '当前网络异常,内容已离线保存,请尝试连接网络后重新保存!';
setTimeout(()=>{ this.isShowTip = ''; },10000 * 2) //this.$message({message: '当前网络异常,内容已离线保存,请尝试连接网络后重新保存!',type: 'warning',center: true});
sessionStorage.setItem('isShowTip',this.editdata.content); setTimeout(()=>{ this.isShowTip = ''; },10000 * 2);
}) })
} }
}, },
@@ -215,11 +238,14 @@ export default {
this.timer = null this.timer = null
}, },
destroyed(){ destroyed(){
if(this.timer!=null){
clearInterval(this.timer) clearInterval(this.timer)
this.timer = null this.timer = null
} }
} }
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>