audit-unit-server.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import axios from '@/common/services/axios-instance'
  2. import pickValues from '@/common/services/pick-values'
  3. import sdUserPicker from '@/common/components/sd-user-picker.vue'
  4. import sdGroupPicker from '@/common/components/sd-group-picker.vue'
  5. function extendNode(item, options = {}, isLeaf) {
  6. // 按穿梭组件的要求添加属性
  7. const type = item.props?.type?.startsWith('G') ? 'Group' : 'User'
  8. let code = item.id
  9. if (item.props.type === 'U') {
  10. code = item.props.account
  11. }
  12. // 记录/出现次数
  13. // fullpathId
  14. item.title = item.text
  15. item.isLeaf = item.leaf
  16. item.code = code
  17. item.name = options.levPath && item.props?.levPath ? item.props.levPath : item.text
  18. item.type = type
  19. item.fullpathId = item.props?.fullpathId
  20. // 如果是leaf是false,且fullpathId长度大于等于2
  21. const fullpathIdLength = item.props?.fullpathId?.split('/').length
  22. if (!item.leaf && fullpathIdLength >= 2) {
  23. item.isLeaf = true
  24. }
  25. if (isLeaf) {
  26. item.isLeaf = isLeaf
  27. }
  28. return item
  29. }
  30. class AddressBook {
  31. selectGroup(option = {}) {
  32. return pickValues(sdGroupPicker, option)
  33. }
  34. selectUser(option = {}) {
  35. return pickValues(sdUserPicker, option)
  36. }
  37. getRootNode(params) {
  38. return axios // 获取部门下用户
  39. .get(`api/framework/v1/group-manager/group/root-node`, { params })
  40. .then((res) => [extendNode(res.data)])
  41. }
  42. getChildNodes(id, options = {}) {
  43. let type, isContainSub, hierarchical, levPath, secretLevel
  44. // 8.0.16后参数放到object里了,并且兼容之前的方式
  45. if (typeof arguments[1] === 'object') {
  46. ;({ type = 'GU', isContainSub = false, hierarchical, levPath, secretLevel } = options)
  47. } else {
  48. ;[id, type = 'GU', isContainSub = false, hierarchical, levPath] = arguments
  49. }
  50. const paramsU = {}
  51. const paramsD = {}
  52. paramsU.isContainSub = isContainSub
  53. paramsD.parent = id
  54. if (hierarchical === undefined) {
  55. hierarchical = ''
  56. } else if (hierarchical) {
  57. hierarchical = '1'
  58. } else {
  59. hierarchical = '0'
  60. }
  61. if (secretLevel) {
  62. paramsU.securityLevel = secretLevel
  63. }
  64. if (type === 'U') {
  65. return axios // 获取部门下用户
  66. .get(
  67. `api/framework/v1/user-manager/users/${id}/users?orderBy=${encodeURIComponent(
  68. 'weight asc,id asc'
  69. )}`,
  70. { params: { ...paramsU, hierarchical } }
  71. )
  72. .then((res) => res.data.map((item) => extendNode(item, { levPath })))
  73. } else {
  74. return axios // 获取部门下的部门
  75. .get(`api/framework/v1/group-manager/group/getChildren`, {
  76. params: { ...paramsD, hierarchical },
  77. })
  78. .then((res) => res.data.map((item) => extendNode(item, { levPath })))
  79. }
  80. }
  81. getUserGroups() {
  82. return axios // 获取群组
  83. .get(`api/framework/v1/usergroup-manager/usergroups/groupnodes`)
  84. .then((res) => res.data.map((item) => extendNode(item)))
  85. }
  86. getDepUserGroupsMembers(parentId, options = {}) {
  87. const params = {}
  88. if (options.secretLevel) {
  89. params.securityLevel = options.secretLevel
  90. }
  91. return axios // 获取部门群组下的用户
  92. .get(`api/framework/v1/user-manager/groups/${parentId}/users`, { params })
  93. .then((res) => res.data.map((item) => extendNode(item)))
  94. }
  95. getUserGroupsMembers(userGroupId, options = {}) {
  96. const params = {}
  97. if (options.secretLevel) {
  98. params.securityLevel = options.secretLevel
  99. }
  100. return axios // 获取群组下的用户
  101. .get(`api/framework/v1/usergroup-manager/usergroups/${userGroupId}/members`, { params })
  102. .then((res) => res.data.map((item) => extendNode(item)))
  103. }
  104. getRoles(params = {}) {
  105. return axios // 获取角色
  106. .get(`api/framework/v1/role-manager/roles/${encodeURI('code ASC')}`, { params })
  107. .then((res) => {
  108. res.data.forEach((item) => {
  109. item.title = item.name // 按树的要求添加属性
  110. item.key = item.code
  111. item.slots = { icon: 'G' }
  112. })
  113. return res.data
  114. })
  115. }
  116. getRolesMembers(roleCode) {
  117. return axios // 获取角色下的用户
  118. .get(`api/framework/v1/user-manager/roles/${roleCode}/users`)
  119. .then((res) => res.data.map((item) => extendNode(item)))
  120. }
  121. // 查询
  122. usersQuery(str, ids = [], options = {}) {
  123. const param = {
  124. expressions: [
  125. {
  126. dataType: 'exps',
  127. op: 'or',
  128. expressionsValue: [
  129. {
  130. dataType: 'str',
  131. name: 'name',
  132. op: 'like',
  133. stringValue: `%${str}%`,
  134. },
  135. {
  136. dataType: 'str',
  137. name: 'account',
  138. op: 'like',
  139. stringValue: `%${str}%`,
  140. },
  141. ],
  142. },
  143. ],
  144. ids,
  145. }
  146. if (options.secretLevel) {
  147. param.securityLevel = options.secretLevel
  148. }
  149. param.hierarchical = options.hierarchical
  150. if (param.hierarchical === undefined) {
  151. param.hierarchical = ''
  152. } else if (param.hierarchical) {
  153. param.hierarchical = '1'
  154. } else {
  155. param.hierarchical = '0'
  156. }
  157. param.rootIds = options.rootIds
  158. return axios
  159. .post('api/framework/v1/user-manager/users_query', param)
  160. .then((res) => res.data.map((item) => extendNode(item)))
  161. }
  162. // 查询
  163. groupsQuery(str, options = {}) {
  164. let hierarchical, levPath
  165. if (typeof arguments[1] === 'object') {
  166. ;({ hierarchical, levPath } = options)
  167. } else {
  168. ;[str, hierarchical, levPath] = arguments
  169. }
  170. if (hierarchical === undefined) {
  171. hierarchical = undefined
  172. } else if (hierarchical) {
  173. hierarchical = '1'
  174. } else {
  175. hierarchical = '0'
  176. }
  177. const param = {
  178. expressions: [
  179. {
  180. dataType: 'str',
  181. name: 'name',
  182. op: 'like',
  183. stringValue: `%${str}%`,
  184. },
  185. ],
  186. orderBy: 'name asc',
  187. hierarchical,
  188. maxResults: -1,
  189. }
  190. return axios
  191. .post('api/framework/v1/group-manager/groups_query', param, {
  192. headers: {
  193. 'Content-Type': 'application/json',
  194. },
  195. })
  196. .then((res) => {
  197. const allCode = ['100000', '100001']
  198. // 只保留props下nodePath转为数组后第一个code为100000或100001的数据
  199. const data = res.data.filter((item) => {
  200. const setData = JSON.parse(item.props.nodePath || '[]')
  201. return allCode.includes(setData[0].code)
  202. })
  203. return data.map((item) => extendNode(item, { levPath }, true))
  204. })
  205. }
  206. getFullPath(id) {
  207. return axios
  208. .get(`api/framework/v1/group-manager/groups/${id}/fullpath`)
  209. .then((res) => res.data.map((item) => extendNode(item)))
  210. }
  211. getGroupTree({ expandedKey, rootNode, hierarchical, levPath }) {
  212. if (rootNode && rootNode.code && rootNode.name) {
  213. rootNode = Promise.resolve([
  214. { text: rootNode.name, checkable: true, type: 'Group', isLeaf: false, ...rootNode },
  215. ])
  216. } else {
  217. rootNode = this.getRootNode({
  218. hierarchical: hierarchical === undefined ? '' : hierarchical ? '1' : '0',
  219. })
  220. }
  221. return rootNode.then((data) => {
  222. let p = Promise.resolve()
  223. if (expandedKey && expandedKey[0]) {
  224. // 设置了默认展开节点,获取每层树节点
  225. p = this.getFullPath(expandedKey[0]).then((items) => {
  226. if (!items.length) return
  227. const index = items.findIndex((item) => item.code === data[0].code)
  228. if (index !== -1) {
  229. // 根节点在fullpath路径里,从fullpath截取
  230. items.splice(index + 1, 99)
  231. } else {
  232. // 如果不是分级授权,路径信息里没有绝对根节点,这种情况下自己拼上根节点
  233. items = [...items, ...data]
  234. }
  235. const pArray = items.map((item) =>
  236. this.getChildNodes(item.code, {
  237. type: 'G',
  238. isContainSub: false,
  239. hierarchical,
  240. levPath,
  241. })
  242. )
  243. return Promise.all(pArray).then((items) => {
  244. const tree = items.reduce((a, b) => {
  245. // 通过fullpathId找到父节点
  246. if (a.length !== 0) {
  247. const node = b.find((item) => a[0].props.fullpathId.endsWith(item.code))
  248. if (node) node.children = a
  249. }
  250. return b
  251. })
  252. return tree
  253. })
  254. })
  255. }
  256. return p.then((tree) => {
  257. data[0].children = tree
  258. return data
  259. })
  260. })
  261. }
  262. // 根据群组名称检查是否已经存在个人用户群组
  263. checkExistGroupByName(groupName) {
  264. return axios
  265. .get(`api/framework/v1/usergroup-manager/usergroups/check?groupName=${groupName}`)
  266. .then((res) => res)
  267. }
  268. // 删除个人用户群组
  269. delGroupById(params) {
  270. return axios
  271. .delete(`api/framework/v1/page/oaPersonalUserGroup`, { params: params })
  272. .then((res) => res)
  273. }
  274. }
  275. export default new AddressBook()