companyMenuConfig.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="app-container">
  3. <el-tabs v-model="activeName" @tab-click="handleClick" >
  4. <el-form ref="form14" :model="form14" :rules="rules14" label-width="180px">
  5. <el-form-item label="菜单权限">
  6. <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
  7. <el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
  8. <el-checkbox v-model="menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox>
  9. <el-tree
  10. class="tree-border"
  11. :data="menuOptions"
  12. show-checkbox
  13. ref="menu"
  14. node-key="id"
  15. :check-strictly="!menuCheckStrictly"
  16. empty-text="加载中,请稍后"
  17. :props="defaultProps"
  18. ></el-tree>
  19. </el-form-item>
  20. <div class="footer">
  21. <el-button type="primary" @click="submitForm14">提 交</el-button>
  22. </div>
  23. </el-form>
  24. </el-tabs>
  25. </div>
  26. </template>
  27. <script>
  28. import Editor from '@/components/Editor/wang';
  29. import { getConfigByKey,updateConfigByKey, clearCache } from "@/api/system/config";
  30. import { listCompany } from "@/api/company/company";
  31. import Material from '@/components/Material'
  32. import {treeselect as menuTreeselect} from "@/api/company/companyMenu";
  33. export default {
  34. name: "Config",
  35. components: {
  36. Material,
  37. Editor
  38. },
  39. watch: {
  40. photoArr: function(val) {
  41. this.form1.certs = val.join(',')
  42. },
  43. images: function(val) {
  44. this.form7.images = val.join(',')
  45. }
  46. },
  47. data() {
  48. return {
  49. menuCheckStrictly: true,
  50. defaultProps: {
  51. children: "children",
  52. label: "label"
  53. },
  54. // 菜单列表
  55. menuOptions: [],
  56. menuExpand: false,
  57. menuNodeAll: false,
  58. companyOptions:[],
  59. activeName:"companymenu.config",
  60. configId:null,
  61. configKey:null,
  62. form14:{},
  63. rules14:{}
  64. };
  65. },
  66. created() {
  67. this.getConfigByKey(this.activeName);
  68. this.getMenuTreeselect();
  69. },
  70. methods: {
  71. handleClick(tab, event){
  72. console.log(tab.name)
  73. this.getConfigByKey(tab.name);
  74. },
  75. /** 查询菜单树结构 */
  76. getMenuTreeselect() {
  77. menuTreeselect().then(response => {
  78. this.menuOptions = response.data;
  79. });
  80. },
  81. // 树权限(展开/折叠)
  82. handleCheckedTreeExpand(value, type) {
  83. if (type == 'menu') {
  84. let treeList = this.menuOptions;
  85. for (let i = 0; i < treeList.length; i++) {
  86. this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
  87. }
  88. } else if (type == 'dept') {
  89. let treeList = this.deptOptions;
  90. for (let i = 0; i < treeList.length; i++) {
  91. this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
  92. }
  93. }
  94. },
  95. // 树权限(全选/全不选)
  96. handleCheckedTreeNodeAll(value, type) {
  97. if (type == 'menu') {
  98. this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []);
  99. } else if (type == 'dept') {
  100. this.$refs.dept.setCheckedNodes(value ? this.deptOptions: []);
  101. }
  102. },
  103. // 树权限(父子联动)
  104. handleCheckedTreeConnect(value, type) {
  105. if (type == 'menu') {
  106. this.menuCheckStrictly = value ? true: false;
  107. } else if (type == 'dept') {
  108. this.deptCheckStrictly = value ? true: false;
  109. }
  110. },
  111. getCompanyOptions() {
  112. listCompany().then(response=>{
  113. this.companyOptions = response.rows
  114. })
  115. },
  116. handleSuccess(response, file) {
  117. // 上传成功后的回调函数
  118. this.myloading.close();
  119. this.form7.videoUrl = response.url;
  120. this.$refs.upload.clearFiles();
  121. },
  122. getConfigByKey(key){
  123. getConfigByKey(key).then(response => {
  124. if(key == "companymenu.config"){
  125. this.getCompanyOptions();
  126. console.log(response.data.configId)
  127. this.configId=response.data.configId;
  128. this.configKey=response.data.configKey;
  129. if(response.data.configValue != null) {
  130. this.form14 = JSON.parse(response.data.configValue);
  131. // 回显选中的菜单
  132. this.$nextTick(() => {
  133. if (this.form14.menuIds && this.form14.menuIds.length > 0) {
  134. this.$refs.menu.setCheckedKeys(this.form14.menuIds);
  135. }
  136. });
  137. } else {
  138. this.form14 = { menuIds: [] };
  139. }
  140. }
  141. });
  142. },
  143. submitForm14(){
  144. this.form14.menuIds = this.getMenuAllCheckedKeys();
  145. var param={configId:this.configId,configKey:this.configKey,configValue:JSON.stringify(this.form14)}
  146. updateConfigByKey(param).then(response => {
  147. if (response.code === 200) {
  148. this.msgSuccess("修改成功");
  149. }
  150. });
  151. },
  152. // 所有菜单节点数据
  153. getMenuAllCheckedKeys() {
  154. // 目前被选中的菜单节点
  155. let checkedKeys = this.$refs.menu.getHalfCheckedKeys();
  156. // 半选中的菜单节点
  157. let halfCheckedKeys = this.$refs.menu.getCheckedKeys();
  158. checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  159. return checkedKeys;
  160. },
  161. /** 清理缓存按钮操作 */
  162. handleClearCache() {
  163. clearCache().then(response => {
  164. if (response.code === 200) {
  165. this.msgSuccess("清理成功");
  166. }
  167. });
  168. },
  169. }
  170. };
  171. </script>
  172. <style scoped>
  173. .footer{
  174. width: 100%;
  175. display: flex;
  176. align-items: flex-end;
  177. justify-content: flex-end;
  178. }
  179. </style>