index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="organization-container">
  3. <div class="left">
  4. <TreeParts :treeData="resourcetree_data" :title="'资源'" :fieldNames="{
  5. key: 'menuId',
  6. title: 'menuName',
  7. children: 'children',
  8. }" @nodeClick="onNodeClick" @addBtnClick="onAddBtnClick" @deleteBtnClick="onDeleteBtnClick" />
  9. </div>
  10. <div class="right">
  11. <a-card title="详情" style="height: 100%;">
  12. <ResourceForm :resource_form="resource_form" @save="orgFromSave" @reset="orgFromReset">
  13. <template #actions>
  14. <a-button @click="orgFromSave">保存</a-button>
  15. <a-button @click="orgFromReset">重置</a-button>
  16. </template>
  17. </ResourceForm>
  18. </a-card>
  19. </div>
  20. <Modal :visible.sync="resourcevisible" @ok="orgFromSave" @cancel="orgFromCancel" :title="'新增'">
  21. <ResourceForm :resource_form="resource_form"></ResourceForm>
  22. </Modal>
  23. </div>
  24. </template>
  25. <script setup>
  26. import { ref, reactive, onMounted } from 'vue';
  27. import { Message } from '@arco-design/web-vue';
  28. import TreeParts from '../TreeParts.vue';
  29. import ResourceForm from './ResourceForm.vue';
  30. import Modal from '../Modal.vue';
  31. import {
  32. QueryResourceTree, QueryResourceDetail, UpdateResource, CreateResource, DeleteResource
  33. } from '../../../apis/permission/resource';
  34. const resourcevisible = ref(false);
  35. const is_edit_mode = ref(true);
  36. const resourcetree_data = ref([]);
  37. const resource_form = reactive({
  38. parentName: '',
  39. status: 0,
  40. menuName: '',
  41. icon: '',
  42. menuType: '0',
  43. description: '',
  44. perms: '',
  45. component: '',
  46. });
  47. const getResourceTree = async () => {
  48. const { code, data: { rows } } = await QueryResourceTree();
  49. if (code == 200) {
  50. resourcetree_data.value = rows;
  51. }
  52. }
  53. // 树节点操作相关
  54. const onNodeClick = async (id) => {
  55. const { data: { data } } = await QueryResourceDetail(id);
  56. resource_form.resourceId = id;
  57. resource_form.parentId = data.parentId;
  58. resource_form.parentName = data.parentName;
  59. resource_form.menuName = data.menuName;
  60. resource_form.status = data.status;
  61. resource_form.icon = data.icon;
  62. resource_form.menuType = data.menuType;
  63. resource_form.description = data.description;
  64. resource_form.perms = data.perms;
  65. resource_form.component = data.component;
  66. // 多余的参数
  67. resource_form.orderNum = 0;
  68. resource_form.path = '';
  69. }
  70. const onAddBtnClick = (nodeData) => {
  71. resource_form.resourceId = null;
  72. resource_form.parentId = nodeData.menuId
  73. resource_form.parentName = nodeData.menuName;
  74. resource_form.menuName = '';
  75. resource_form.status = '0';
  76. resource_form.icon = '';
  77. resource_form.menuType = '0';
  78. resource_form.description = '';
  79. resource_form.perms = '';
  80. resource_form.component = '';
  81. // 多余的参数
  82. resource_form.orderNum = 0;
  83. resource_form.path = '';
  84. resourcevisible.value = true;
  85. is_edit_mode.value = false;
  86. }
  87. const onDeleteBtnClick = async ({ menuId }) => {
  88. const { code } = await DeleteResource(menuId);
  89. if (code === 200) {
  90. Message.success({
  91. title: '删除',
  92. content: '删除成功',
  93. });
  94. }
  95. getResourceTree();
  96. }
  97. const orgFromSave = async () => {
  98. console.log('is_edit_mode.value', is_edit_mode.value)
  99. console.log('resource_form.resourceId', resource_form.resourceId)
  100. const data = {
  101. ...resource_form,
  102. menuId: (is_edit_mode.value && resource_form.resourceId) ? resource_form.resourceId[0] : null
  103. }
  104. const apiCall = is_edit_mode.value ? UpdateResource : CreateResource;
  105. const { code } = await apiCall(data);
  106. if (code === 200) {
  107. const action = is_edit_mode.value ? '编辑' : '新增';
  108. Message.success({
  109. title: `${action}用户`,
  110. content: `${action}成功`,
  111. });
  112. getResourceTree()
  113. resourcevisible.value = false;
  114. }
  115. }
  116. const orgFromReset = () => {
  117. resource_form.resourceId = null;
  118. resource_form.parentName = '';
  119. resource_form.status = 0;
  120. resource_form.resourceName = '';
  121. resource_form.leader = '';
  122. resource_form.orderNum = '';
  123. resource_form.address = '';
  124. }
  125. const orgFromCancel = () => {
  126. is_edit_mode.value = true;
  127. resourcevisible.value = false;
  128. }
  129. onMounted(() => {
  130. getResourceTree();
  131. })
  132. </script>
  133. <style lang="css" scoped>
  134. .organization-container {
  135. display: flex;
  136. justify-content: space-between;
  137. height: calc(100% - 40px);
  138. width: 100%;
  139. }
  140. .left {
  141. width: 30%;
  142. height: 100%;
  143. background-color: #fff;
  144. /* TODO优化 使用滚动组件 */
  145. overflow-y: auto;
  146. }
  147. .right {
  148. width: 69%;
  149. height: 100%;
  150. background-color: #fff;
  151. }
  152. </style>