SchoolMenuManage.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="school-menu-manage">
  3. <div class="part-box part-box-filter part-box-flex">
  4. <el-form ref="FilterForm" label-position="left" inline>
  5. <el-form-item label="学校:">
  6. <school-select
  7. v-model="schoolId"
  8. placeholder="请选择学校"
  9. :clearable="false"
  10. style="width:100%;"
  11. @change="search"
  12. ></school-select>
  13. </el-form-item>
  14. </el-form>
  15. <div class="part-box-action">
  16. <el-button
  17. type="primary"
  18. :disabled="fetching"
  19. :loading="loading"
  20. @click="save"
  21. >保存</el-button
  22. >
  23. </div>
  24. </div>
  25. <div class="part-box part-box-pad">
  26. <privilege-set
  27. v-if="menus && menus.length"
  28. ref="PrivilegeSet"
  29. :menus="menus"
  30. ></privilege-set>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import {
  36. schoolMenuTree,
  37. schoolSelectedMenuTree,
  38. updateSchoolMenu
  39. } from "../api";
  40. import PrivilegeSet from "../../base/components/PrivilegeSet";
  41. export default {
  42. name: "school-menu-manage",
  43. components: { PrivilegeSet },
  44. data() {
  45. return {
  46. schoolId: "",
  47. menus: [],
  48. loading: false,
  49. fetching: false,
  50. defaultProps: {
  51. label: "name"
  52. }
  53. };
  54. },
  55. mounted() {
  56. this.getPrivileges();
  57. },
  58. methods: {
  59. async getPrivileges() {
  60. const needHideModules = ["common", "customer"];
  61. const data = await schoolMenuTree();
  62. const menus = data || [];
  63. this.menus = menus
  64. .filter(item => !needHideModules.includes(item.url))
  65. .map(item => {
  66. item.parentId = null;
  67. return item;
  68. });
  69. this.$nextTick(() => {
  70. this.$refs.PrivilegeSet.buildTableData([]);
  71. });
  72. },
  73. async search() {
  74. if (!this.schoolId) return;
  75. this.fetching = true;
  76. const data = await schoolSelectedMenuTree(this.schoolId).catch(() => {});
  77. this.fetching = false;
  78. const privilegeIds = data || [];
  79. this.$refs.PrivilegeSet.buildTableData(privilegeIds);
  80. },
  81. async save() {
  82. if (!this.schoolId) {
  83. this.$message.error("学校必须选择!");
  84. return;
  85. }
  86. if (this.loading) return;
  87. this.loading = true;
  88. const privilegeIds = this.$refs.PrivilegeSet.getSelectedPrivilegeIds();
  89. const res = await updateSchoolMenu({
  90. schoolId: this.schoolId,
  91. privilegeIds: privilegeIds
  92. });
  93. this.loading = false;
  94. if (!res) return;
  95. this.$message.success("修改成功!");
  96. }
  97. }
  98. };
  99. </script>