From 54b57b3bc288bdae91853baffd610d7236c9c4e7 Mon Sep 17 00:00:00 2001
From: yujialong <479214531@qq.com>
Date: Tue, 19 Apr 2022 11:45:16 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E4=BF=9D=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/course/AddCurriculum.vue | 61 +++++++++++++++++++++---------
1 file changed, 44 insertions(+), 17 deletions(-)
diff --git a/src/views/course/AddCurriculum.vue b/src/views/course/AddCurriculum.vue
index ee807df..af0b94d 100644
--- a/src/views/course/AddCurriculum.vue
+++ b/src/views/course/AddCurriculum.vue
@@ -10,7 +10,7 @@
确定
+ @click="saveAdd">确定
@@ -352,10 +352,19 @@ export default {
assessmentData: [],
assessmentTotal: 0,
multipleAssessment: [],
- submiting: false // 新增编辑防抖标识
+ submiting: false, // 新增编辑防抖标识
+ loadIns: null,
+ updateTime: 0
};
},
watch: {
+ // 监听信息是否有更改,有的话页面离开的时候要询问是否要保存
+ form: {
+ handler(){
+ this.updateTime++
+ },
+ deep:true
+ },
configSearch: function(val) {
clearTimeout(this.searchTimer);
this.searchTimer = setTimeout(() => {
@@ -375,15 +384,25 @@ export default {
},
methods: {
goback() {
- if (this.isDetail) {
- this.$router.back();
- } else {
- this.$confirm("确定返回?未更新的信息将不会保存。", "提示", {
- type: "warning"
- }).then(() => {
- this.$router.back();
- }).catch(() => {});
- }
+ const id = this.form.cid
+ const updateTime = this.updateTime
+ // 更改了信息才需要提示
+ if ((id && updateTime > 1) || (!id && updateTime)) {
+ this.$confirm(`编辑的内容未保存,是否保存?`, '提示', {
+ type: 'warning'
+ }).then(() => {
+ this.saveAdd(1)
+ }).catch(() => {
+ this.backPage()
+ })
+ } else {
+ this.backPage()
+ }
+ },
+ // 返回上一页
+ backPage() {
+ this.$router.back()
+ this.loadIns.close()
},
getInfoData() {
this.$post(`${this.api.curriculumDetail}?cid=${this.form.cid}`).then(res => {
@@ -603,8 +622,8 @@ export default {
this.$message.info("已取消移除");
});
},
- saveAdd(form) {
- this.$refs[form].validate((valid) => {
+ saveAdd(fromBack) {
+ this.$refs.form.validate((valid) => {
if (valid) {
if (this.submiting) return false
if (!this.form.coverUrl) {
@@ -642,26 +661,34 @@ export default {
this.form.systemIdByAssessment.sort((a, b) => a.sort - b.sort)
}
this.submiting = true
+ this.loadIns = this.$loading({
+ lock: true,
+ text: 'Loading',
+ spinner: 'el-icon-loading',
+ background: 'rgba(0, 0, 0, 0.7)'
+ })
if (this.form.cid) {
this.$post(this.api.modifyCourse, this.form).then((res) => {
this.$message.success("编辑成功");
- this.$router.back();
+ this.backPage()
}).catch((res) => {
this.submiting = false
+ this.loadIns.close()
});
} else {
this.$post(this.api.createCurriculum, this.form).then((res) => {
- this.$confirm("课程创建成功,是否马上进行课程内容设置?", "提示", {
+ !fromBack ? this.$confirm("课程创建成功,是否马上进行课程内容设置?", "提示", {
type: "success",
confirmButtonText: "马上设置",
cancelButtonText: "稍后操作"
}).then(() => {
this.$router.push(`/contentSettings?cid=${res.cid}`);
}).catch(() => {
- this.$router.back();
- });
+ this.backPage()
+ }) : this.backPage()
}).catch((res) => {
this.submiting = false
+ this.loadIns.close()
});
}
} else {