From b92da8323b1b7b21ceee2ea75ca8cc92a8b2d915 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 12 Apr 2020 19:50:28 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96initData=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=88=B7=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/authority/role.vue | 19 ++++++++----- src/views/system/dept.vue | 14 +++------- src/views/system/menu.vue | 52 +++++++++++++++--------------------- 3 files changed, 38 insertions(+), 47 deletions(-) diff --git a/src/views/authority/role.vue b/src/views/authority/role.vue index aa4ee51..e8b9291 100644 --- a/src/views/authority/role.vue +++ b/src/views/authority/role.vue @@ -6,6 +6,7 @@ ref="crud" v-model="form" :permission="permissionList" + :before-open="beforeOpen" @row-del="rowDel" @row-update="rowUpdate" @row-save="rowSave" @@ -227,13 +228,13 @@ return ids; } }, - mounted() { - getRoleTree().then(res => { - const column = this.findObject(this.option.column, "parentId"); - column.dicData = res.data.data; - }); - }, methods: { + initData(){ + getRoleTree().then(res => { + const column = this.findObject(this.option.column, "parentId"); + column.dicData = res.data.data; + }); + }, submit() { const menuList = this.$refs.treeMenu.getCheckedKeys(); const dataScopeList = this.$refs.treeDataScope.getCheckedKeys(); @@ -308,6 +309,12 @@ this.selectionList = []; this.$refs.crud.toggleSelection(); }, + beforeOpen(done, type) { + if (["add", "edit"].includes(type)) { + this.initData(); + } + done(); + }, handleRole() { if (this.selectionList.length !== 1) { this.$message.warning("只能选择一条数据"); diff --git a/src/views/system/dept.vue b/src/views/system/dept.vue index d1f60b8..0a1bfac 100644 --- a/src/views/system/dept.vue +++ b/src/views/system/dept.vue @@ -204,9 +204,6 @@ return ids.join(","); } }, - mounted() { - this.initData(); - }, methods: { initData() { getDeptTree().then(res => { @@ -226,8 +223,6 @@ }, rowSave(row, loading, done) { add(row).then((res) => { - // 下拉框数据重载 - this.initData(); // 获取新增数据的相关字段 const data = res.data.data; row.id = data.id; @@ -246,8 +241,6 @@ }, rowUpdate(row, index, loading, done) { update(row).then(() => { - // 下拉框数据重载 - this.initData(); // 数据回调进行刷新 loading(row); this.$message({ @@ -269,8 +262,6 @@ return remove(row.id); }) .then(() => { - // 下拉框数据重载 - this.initData(); // 数据回调进行刷新 loading(row); this.$message({ @@ -300,8 +291,6 @@ this.$refs.crud.toggleSelection(); // 表格数据重载 this.onLoad(this.page); - // 下拉框数据重载 - this.initData(); this.$message({ type: "success", message: "操作成功!" @@ -328,6 +317,9 @@ this.$refs.crud.toggleSelection(); }, beforeOpen(done, type) { + if (["add", "edit"].includes(type)) { + this.initData(); + } if (["edit", "view"].includes(type)) { getDept(this.form.id).then(res => { this.form = res.data.data; diff --git a/src/views/system/menu.vue b/src/views/system/menu.vue index 4c38629..bd2fb7a 100644 --- a/src/views/system/menu.vue +++ b/src/views/system/menu.vue @@ -237,9 +237,6 @@ return ids.join(","); } }, - mounted() { - this.initData(); - }, methods: { initData() { getMenuTree().then(res => { @@ -259,8 +256,6 @@ }, rowSave(row, loading, done) { add(row).then((res) => { - // 下拉框数据重载 - this.initData(); // 获取新增数据的相关字段 const data = res.data.data; row.id = data.id; @@ -277,8 +272,6 @@ }, rowUpdate(row, index, loading, done) { update(row).then(() => { - // 下拉框数据重载 - this.initData(); // 数据回调进行刷新 loading(row); this.$message({ @@ -300,8 +293,6 @@ return remove(row.id); }) .then(() => { - // 下拉框数据重载 - this.initData(); // 数据回调进行刷新 loading(row); this.$message({ @@ -310,25 +301,6 @@ }); }); }, - searchReset() { - this.query = {}; - this.parentId = 0; - this.onLoad(this.page); - }, - searchChange(params, done) { - this.query = params; - this.parentId = ''; - this.page.currentPage = 1; - this.onLoad(this.page, params); - done(); - }, - selectionChange(list) { - this.selectionList = list; - }, - selectionClear() { - this.selectionList = []; - this.$refs.crud.toggleSelection(); - }, handleDelete() { if (this.selectionList.length === 0) { this.$message.warning("请选择至少一条数据"); @@ -350,15 +322,35 @@ this.$refs.crud.toggleSelection(); // 表格数据重载 this.onLoad(this.page); - // 下拉框数据重载 - this.initData(); this.$message({ type: "success", message: "操作成功!" }); }); }, + searchReset() { + this.query = {}; + this.parentId = 0; + this.onLoad(this.page); + }, + searchChange(params, done) { + this.query = params; + this.parentId = ''; + this.page.currentPage = 1; + this.onLoad(this.page, params); + done(); + }, + selectionChange(list) { + this.selectionList = list; + }, + selectionClear() { + this.selectionList = []; + this.$refs.crud.toggleSelection(); + }, beforeOpen(done, type) { + if (["add", "edit"].includes(type)) { + this.initData(); + } if (["edit", "view"].includes(type)) { getMenu(this.form.id).then(res => { this.form = res.data.data;