From 5059821ea07ab6753071d415f2a7671f1f44be72 Mon Sep 17 00:00:00 2001 From: daihh Date: Tue, 25 Oct 2022 19:37:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ajax.js | 4 +-- src/components/Course/myNote.vue | 57 +++++++++++++++++++------------ src/utils/tools.js | 2 +- src/views/portal/course/Index.vue | 4 ++- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/api/ajax.js b/src/api/ajax.js index e0ca277e..a2f0ecd6 100644 --- a/src/api/ajax.js +++ b/src/api/ajax.js @@ -68,10 +68,10 @@ const formRequest=axios.create({ console.log('err' + error) let { message } = error; if (message == "Network Error") { - message = "后端接口连接异常"; + message = "网络异常,接口连接异常"; } else if (message.includes("timeout")) { - message = "系统接口请求超时"; + message = "网络异常或接口错误,请求超时"; } else if (message.includes("Request failed with status code")) { message = "系统接口" + message.substr(message.length - 3) + "异常"; diff --git a/src/components/Course/myNote.vue b/src/components/Course/myNote.vue index b94cddea..d224422e 100644 --- a/src/components/Course/myNote.vue +++ b/src/components/Course/myNote.vue @@ -100,6 +100,10 @@ export default { type: Object, default: () => { } }, + current:{ //当前是否是可编辑的 + type: Boolean, + default: false + }, height:{ type: Number, default: 200 @@ -112,7 +116,9 @@ export default { name: 'MyNote', data() { return { - inAnimationText:'笔记保存成功,U币+2', + inAnimationText:'笔记保存成功,U币+5', + localSaveHandle:null,//本地保存的timeout对象 + localKey:'NOTE_TEXT',//本地存储的key isEdit:false, inputHeight:70, listHeight:170, @@ -122,7 +128,6 @@ export default { btnPlayTime:false,//是否显示添加视频时间 radio: '1', notetab: 1, - autoSave: null, mynoteData: { type: 1, //我发布的是1 我导入的是2 content: '', @@ -152,8 +157,7 @@ export default { watch: { //内容的高度 height(val){ - - //$this.controlHeight=h- + //$this.controlHeight=h- this.listHeight=val-95; this.inputHeight=(val-220); @@ -161,13 +165,14 @@ export default { if(this.inputRows>20){ this.inputRows=20; } - //console.log(this.inputHeight,this.inputRows,this.listHeight,'my note height'); - if(this.inputHeight>500){ this.inputHeight=500; } }, + isedit(val){ + this.isEdit=val; + }, selected:{ handler(val,old){ this.$emit('change',this.selected) @@ -181,10 +186,7 @@ export default { this.mynoteData.courseName = this.data.name; // this.mynoteData.contentId = this.data.id; } - }, - // intTimeNote(val) { - // this.mynoteData.playTime = val; - // } + } }, methods: { handleClick(){ @@ -194,8 +196,7 @@ export default { //这里应该加上内容的id this.$emit('onPlayVideo',conId,time); }, - - // 取消编辑 + //取消编辑 editCancel(){ this.isEdit = false; // 关闭编辑框 this.getMyNote(); // 重新渲染对应课程的笔记列表 @@ -205,7 +206,6 @@ export default { let h = Math.floor(result / 3600); let m = Math.floor((result / 60 % 60)); let s = Math.floor((result % 60)); - let res = ''; if (h > 0) { res += `${h}:${m}:${s}`; @@ -225,10 +225,14 @@ export default { timeDel() { this.mynoteData.playTime = 0; }, - autoSaveNote() { - this.autoSave = setInterval(() => { - localStorage.setItem("NOTE_TEXT", this.mynoteData.content); - }, 10000); + autoSaveNote(){ + let $this=this; + if(this.notetab==1){ + localStorage.setItem($this.localKey, $this.mynoteData.content); + } + // this.localSaveHandle = setInterval(() => { + + // }, 10000); }, noteEdit(note) { this.isEdit = true; @@ -334,6 +338,7 @@ export default { } else { this.mynoteData.content = this.content_new; //赋值笔记内容 let curOpenType=this.mynoteData.openType; + let $this=this; apiNote.save(this.mynoteData).then(res => { if (res.status == 200) { if (!this.mynoteData.id) { @@ -345,8 +350,8 @@ export default { return } setTimeout(() => { - localStorage.setItem("NOTE_TEXT", ''); - // clearInterval(this.autoSave); + localStorage.setItem($this.localKey, ''); + // clearInterval(this.localSaveHandle); that.getMyNote(); that.notetabType(2); that.mynoteData = { @@ -378,13 +383,21 @@ export default { } } + }).catch(function(error) { + // + this.$message.error('当前网络异常,内容已离线保存'); + // + localStorage.setItem(this.localKey, this.mynoteData.content); }) - } + } } }, beforeDestroy() { - // clearInterval(this.autoSave); - this.autoSave = null; + if(this.localSaveHandle!=null){ + clearInterval(this.localSaveHandle); + clearTimeout(this.localSaveHandle) + } + this.localSaveHandle = null; }, } diff --git a/src/utils/tools.js b/src/utils/tools.js index ff7a56f4..800c681c 100644 --- a/src/utils/tools.js +++ b/src/utils/tools.js @@ -406,7 +406,7 @@ export function translate(field) { export function formatUserNumber(num) { let rsNum =0; if(num<5){ - return 0; + return num; } if(num<95){ rsNum=Math.round((num+5)/10)*10; diff --git a/src/views/portal/course/Index.vue b/src/views/portal/course/Index.vue index 0fb6aac9..4b26ac96 100644 --- a/src/views/portal/course/Index.vue +++ b/src/views/portal/course/Index.vue @@ -88,7 +88,9 @@
- 录播课 + 录播课 + 线下课 + 学习项目