manage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <ibps-layout ref="layout">
  3. <div slot="west">
  4. <ibps-tree
  5. ref="tree"
  6. :width="width"
  7. :height="height"
  8. :loading="loading"
  9. :data="treeData"
  10. :options="treeOptions"
  11. :contextmenus="treeContextmenus"
  12. title="菜单管理"
  13. @action-event="handleTreeAction"
  14. @node-click="handleNodeClick"
  15. @expand-collapse="handleExpandCollapse"
  16. >
  17. <el-select
  18. slot="searchForm"
  19. v-model="systemId"
  20. placeholder="请先设置子系统"
  21. @change="changeSystem"
  22. >
  23. <el-option
  24. v-for="item in subsystemList"
  25. :key="item.id"
  26. :label="item.name"
  27. :value="item.id"
  28. />
  29. </el-select>
  30. </ibps-tree>
  31. <ibps-container
  32. :margin-left="width+'px'"
  33. class="page"
  34. >
  35. <edit
  36. v-if="show==='edit'"
  37. :id="id"
  38. :parent-id="parentId"
  39. :system-id="systemId"
  40. @callback="search"
  41. />
  42. <el-alert
  43. v-else
  44. :closable="false"
  45. title="请选择左边菜单右键进行操作!"
  46. type="warning"
  47. show-icon
  48. style="height:50px;"
  49. />
  50. </ibps-container>
  51. <!-- 导入定义 -->
  52. <import-Menu
  53. :id="systemId"
  54. :resource-id="resourceId"
  55. :visible="importFormVisible"
  56. @callback="search"
  57. @close="visible => importFormVisible = visible"
  58. />
  59. <!--移动节点-->
  60. <move-node
  61. :id="id"
  62. :visible="moveNodeVisible"
  63. :system-id="systemId"
  64. :data="treeData"
  65. @callback="search"
  66. @close="visible => moveNodeVisible = visible"
  67. />
  68. <node-sort
  69. :data="sortData"
  70. :visible="nodeSortVisible"
  71. title="菜单排序"
  72. @close="visible => nodeSortVisible = visible"
  73. @callback="search"
  74. />
  75. <!-- API 授权申请 -->
  76. <client-grant
  77. :title="title"
  78. :client-key="clientKey"
  79. :grant-type="grantType"
  80. :visible="apiGrantVisible"
  81. @callback="search"
  82. @close="visible => apiGrantVisible = visible"
  83. />
  84. </div>
  85. </ibps-layout>
  86. </template>
  87. <script>
  88. import { getTreeData, remove, exportXml, updateNode } from '@/api/platform/auth/resources'
  89. import { findAllSubsystem } from '@/api/platform/auth/subsystem'
  90. import ClientGrant from '@/views/platform/auth/client/grant/index'
  91. import ActionUtils from '@/utils/action'
  92. import FixHeight from '@/mixins/height'
  93. import Edit from './edit'
  94. import MoveNode from './move-node'
  95. import NodeSort from './sort'
  96. import ImportMenu from './import'
  97. export default {
  98. components: {
  99. Edit,
  100. MoveNode,
  101. NodeSort,
  102. ClientGrant,
  103. ImportMenu
  104. },
  105. mixins: [FixHeight],
  106. data () {
  107. return {
  108. show: '',
  109. width: 360,
  110. height: document.clientHeight,
  111. id: '',
  112. title: '',
  113. parentId: '',
  114. // 移动节点
  115. moveNodeVisible: false,
  116. importFormVisible: false,
  117. apiGrantVisible: false,
  118. subsystemList: [],
  119. systemId: '',
  120. resourceId: '',
  121. sortData: '',
  122. nodeSortVisible: false,
  123. clientKey: '',
  124. grantType: '',
  125. // 树配置
  126. loading: false,
  127. treeOptions: { 'rootPId': '-1', showIcon: true },
  128. treeContextmenus: [
  129. { icon: 'add',
  130. label: '添加',
  131. value: 'add',
  132. rights: function (menu, data, isRoot) {
  133. if (isRoot) return true
  134. return data.isFolder
  135. } },
  136. // { icon: 'edit', label: '编辑', value: 'edit', rights: ['node'] },
  137. { icon: 'remove', label: '删除', value: 'remove', rights: ['node'] },
  138. { type: 'divided' },
  139. { icon: 'export', label: '导出', value: 'export' },
  140. { icon: 'import', label: '导入', value: 'import' },
  141. { type: 'divided' },
  142. { icon: 'ticket', label: '接口授权', value: 'authApiGrant', rights: ['node'] },
  143. { type: 'divided', rights: ['node'] },
  144. { icon: 'arrows-v', label: '移动节点', value: 'moveNode', rights: ['node'] },
  145. { icon: 'sort', label: '节点排序', value: 'nodeSort' },
  146. { icon: 'refresh',
  147. label: '更新数据',
  148. value: 'nodeUpdate',
  149. rights: function (menu, data, isRoot) {
  150. return isRoot
  151. } }
  152. ],
  153. treeData: []
  154. }
  155. },
  156. created () {
  157. this.loadSubsystemData()
  158. },
  159. methods: {
  160. loadSubsystemData () {
  161. findAllSubsystem().then(response => {
  162. this.subsystemList = response.data
  163. this.systemId = this.subsystemList && this.subsystemList.length > 0 ? this.subsystemList[0].id : ''
  164. this.loadTreeData()
  165. })
  166. },
  167. changeSystem (value) {
  168. this.systemId = value
  169. this.loadTreeData()
  170. },
  171. loadTreeData () {
  172. this.loading = true
  173. getTreeData({
  174. systemId: this.systemId
  175. }).then(response => {
  176. this.loading = false
  177. this.treeData = response.data
  178. }).catch(() => {
  179. this.loading = false
  180. })
  181. },
  182. // 查询
  183. search () {
  184. this.loadTreeData()
  185. },
  186. handleTreeAction (command, position, selection, data) {
  187. if (position === 'toolbar') {
  188. if (command === 'refresh') {
  189. this.loadTreeData()
  190. }
  191. } else {
  192. const id = data.id
  193. switch (command) {
  194. // 组织负责人
  195. case 'add':// 添加
  196. this.handleEdit('', id)
  197. break
  198. // case 'edit':// 编辑
  199. // this.handleEdit(id)
  200. // break
  201. case 'remove':// 删除
  202. ActionUtils.removeRecord(id).then((ids) => {
  203. if (data.children && this.$utils.isNotEmpty(data.children)) {
  204. ActionUtils.removeRecord(id, '是否删除子菜单?不删除则子菜单层次会转换到该菜单层次!').then((ids) => {
  205. this.handleRemove(ids, true)
  206. }).catch(() => {
  207. this.handleRemove(ids)
  208. })
  209. } else {
  210. this.handleRemove(ids)
  211. }
  212. }).catch(() => { })
  213. break
  214. case 'export':// 导出
  215. this.handleExport(id, this.systemId, data.name)
  216. break
  217. case 'import':// 导入
  218. this.handImport(id)
  219. break
  220. case 'authApiGrant':// 接口授权
  221. this.title = '接口授权申请'
  222. this.clientKey = data.alias
  223. this.grantType = 'res'
  224. this.handleApiGrant()
  225. break
  226. case 'moveNode':// 移动节点
  227. this.handleMoveNode(id)
  228. break
  229. case 'nodeSort':// 节点排序
  230. this.handleNodeSort(data)
  231. break
  232. case 'nodeUpdate':// 更新数据
  233. this.handleNodeUpdate(this.systemId)
  234. break
  235. default:
  236. break
  237. }
  238. }
  239. },
  240. /**
  241. * 接口授权申请
  242. */
  243. handleApiGrant () {
  244. this.apiGrantVisible = true
  245. },
  246. // 导入
  247. handImport (resourceId) {
  248. this.resourceId = resourceId
  249. this.importFormVisible = true
  250. },
  251. handleExport (resourceId, systemId, name) {
  252. exportXml({
  253. resourceId: resourceId,
  254. systemId: systemId
  255. }).then(response => {
  256. ActionUtils.exportFile(response.data, name + '.xml')
  257. }).catch(() => {})
  258. },
  259. // 添加 编辑
  260. handleEdit (id = '', parentId) {
  261. if (this.id === id) {
  262. this.show = ''
  263. }
  264. setTimeout(() => {
  265. this.show = 'edit'
  266. this.id = id
  267. this.parentId = parentId
  268. }, 0)
  269. },
  270. // 处理删除
  271. handleRemove (ids, cascade) {
  272. remove({ resourceIds: ids, cascade: cascade || false }).then(response => {
  273. ActionUtils.removeSuccessMessage()
  274. this.loadTreeData()
  275. }).catch(() => {})
  276. },
  277. // 移动节点
  278. handleMoveNode (id = '') {
  279. this.moveNodeVisible = true
  280. this.id = id
  281. },
  282. handleNodeSort (data) {
  283. if (this.$utils.isEmpty(data.children)) {
  284. ActionUtils.warning('无子节点排序')
  285. return
  286. }
  287. if (data.children.length === 1) {
  288. ActionUtils.warning('只有一个节点无需排序')
  289. } else {
  290. this.nodeSortVisible = true
  291. this.sortData = data.children
  292. }
  293. },
  294. // 树点击
  295. handleNodeClick (data) {
  296. if (data.id === '0' || data.id === 0) {
  297. this.show = ''
  298. } else {
  299. this.show = 'edit'
  300. this.id = data.id
  301. }
  302. },
  303. handleExpandCollapse (isExpand) {
  304. this.width = isExpand ? 360 : 30
  305. },
  306. handleNodeUpdate (systemId) {
  307. this.loading = true
  308. updateNode({ systemId: systemId }).then(response => {
  309. this.loadTreeData()
  310. }).catch((err) => {
  311. this.loading = false
  312. console.error(err)
  313. })
  314. }
  315. }
  316. }
  317. </script>