优化initData加载刷新逻辑

dev
smallchill 6 years ago
parent ab2531369c
commit b92da8323b
  1. 11
      src/views/authority/role.vue
  2. 14
      src/views/system/dept.vue
  3. 52
      src/views/system/menu.vue

@ -6,6 +6,7 @@
ref="crud" ref="crud"
v-model="form" v-model="form"
:permission="permissionList" :permission="permissionList"
:before-open="beforeOpen"
@row-del="rowDel" @row-del="rowDel"
@row-update="rowUpdate" @row-update="rowUpdate"
@row-save="rowSave" @row-save="rowSave"
@ -227,13 +228,13 @@
return ids; return ids;
} }
}, },
mounted() { methods: {
initData(){
getRoleTree().then(res => { getRoleTree().then(res => {
const column = this.findObject(this.option.column, "parentId"); const column = this.findObject(this.option.column, "parentId");
column.dicData = res.data.data; column.dicData = res.data.data;
}); });
}, },
methods: {
submit() { submit() {
const menuList = this.$refs.treeMenu.getCheckedKeys(); const menuList = this.$refs.treeMenu.getCheckedKeys();
const dataScopeList = this.$refs.treeDataScope.getCheckedKeys(); const dataScopeList = this.$refs.treeDataScope.getCheckedKeys();
@ -308,6 +309,12 @@
this.selectionList = []; this.selectionList = [];
this.$refs.crud.toggleSelection(); this.$refs.crud.toggleSelection();
}, },
beforeOpen(done, type) {
if (["add", "edit"].includes(type)) {
this.initData();
}
done();
},
handleRole() { handleRole() {
if (this.selectionList.length !== 1) { if (this.selectionList.length !== 1) {
this.$message.warning("只能选择一条数据"); this.$message.warning("只能选择一条数据");

@ -204,9 +204,6 @@
return ids.join(","); return ids.join(",");
} }
}, },
mounted() {
this.initData();
},
methods: { methods: {
initData() { initData() {
getDeptTree().then(res => { getDeptTree().then(res => {
@ -226,8 +223,6 @@
}, },
rowSave(row, loading, done) { rowSave(row, loading, done) {
add(row).then((res) => { add(row).then((res) => {
//
this.initData();
// //
const data = res.data.data; const data = res.data.data;
row.id = data.id; row.id = data.id;
@ -246,8 +241,6 @@
}, },
rowUpdate(row, index, loading, done) { rowUpdate(row, index, loading, done) {
update(row).then(() => { update(row).then(() => {
//
this.initData();
// //
loading(row); loading(row);
this.$message({ this.$message({
@ -269,8 +262,6 @@
return remove(row.id); return remove(row.id);
}) })
.then(() => { .then(() => {
//
this.initData();
// //
loading(row); loading(row);
this.$message({ this.$message({
@ -300,8 +291,6 @@
this.$refs.crud.toggleSelection(); this.$refs.crud.toggleSelection();
// //
this.onLoad(this.page); this.onLoad(this.page);
//
this.initData();
this.$message({ this.$message({
type: "success", type: "success",
message: "操作成功!" message: "操作成功!"
@ -328,6 +317,9 @@
this.$refs.crud.toggleSelection(); this.$refs.crud.toggleSelection();
}, },
beforeOpen(done, type) { beforeOpen(done, type) {
if (["add", "edit"].includes(type)) {
this.initData();
}
if (["edit", "view"].includes(type)) { if (["edit", "view"].includes(type)) {
getDept(this.form.id).then(res => { getDept(this.form.id).then(res => {
this.form = res.data.data; this.form = res.data.data;

@ -237,9 +237,6 @@
return ids.join(","); return ids.join(",");
} }
}, },
mounted() {
this.initData();
},
methods: { methods: {
initData() { initData() {
getMenuTree().then(res => { getMenuTree().then(res => {
@ -259,8 +256,6 @@
}, },
rowSave(row, loading, done) { rowSave(row, loading, done) {
add(row).then((res) => { add(row).then((res) => {
//
this.initData();
// //
const data = res.data.data; const data = res.data.data;
row.id = data.id; row.id = data.id;
@ -277,8 +272,6 @@
}, },
rowUpdate(row, index, loading, done) { rowUpdate(row, index, loading, done) {
update(row).then(() => { update(row).then(() => {
//
this.initData();
// //
loading(row); loading(row);
this.$message({ this.$message({
@ -300,8 +293,6 @@
return remove(row.id); return remove(row.id);
}) })
.then(() => { .then(() => {
//
this.initData();
// //
loading(row); loading(row);
this.$message({ 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() { handleDelete() {
if (this.selectionList.length === 0) { if (this.selectionList.length === 0) {
this.$message.warning("请选择至少一条数据"); this.$message.warning("请选择至少一条数据");
@ -350,15 +322,35 @@
this.$refs.crud.toggleSelection(); this.$refs.crud.toggleSelection();
// //
this.onLoad(this.page); this.onLoad(this.page);
//
this.initData();
this.$message({ this.$message({
type: "success", type: "success",
message: "操作成功!" 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) { beforeOpen(done, type) {
if (["add", "edit"].includes(type)) {
this.initData();
}
if (["edit", "view"].includes(type)) { if (["edit", "view"].includes(type)) {
getMenu(this.form.id).then(res => { getMenu(this.form.id).then(res => {
this.form = res.data.data; this.form = res.data.data;

Loading…
Cancel
Save