优化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"
v-model="form"
:permission="permissionList"
:before-open="beforeOpen"
@row-del="rowDel"
@row-update="rowUpdate"
@row-save="rowSave"
@ -227,13 +228,13 @@
return ids;
}
},
mounted() {
methods: {
initData(){
getRoleTree().then(res => {
const column = this.findObject(this.option.column, "parentId");
column.dicData = res.data.data;
});
},
methods: {
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("只能选择一条数据");

@ -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;

@ -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;

Loading…
Cancel
Save