index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <a-row :gutter="10">
  3. <a-col :xs="24" :sm="24" :md="24" :lg="5" :xl="5">
  4. <a-card :bordered="false" :loading="cardLoading">
  5. <a-tree
  6. v-if="treeData.length > 0"
  7. v-model:expandedKeys="defaultExpandedKeys"
  8. :tree-data="treeData"
  9. :field-names="treeFieldNames"
  10. @select="treeSelect"
  11. :block-node="true"
  12. >
  13. </a-tree>
  14. <a-empty v-else :image="Empty.PRESENTED_IMAGE_SIMPLE" />
  15. </a-card>
  16. </a-col>
  17. <a-col :xs="24" :sm="24" :md="24" :lg="19" :xl="19">
  18. <a-card :bordered="false" style="margin-bottom: 10px">
  19. <a-form ref="searchFormRef" name="advanced_search" class="ant-advanced-search-form" :model="searchFormState">
  20. <a-row :gutter="24">
  21. <a-col :span="8">
  22. <a-form-item name="searchKey" label="名称关键词">
  23. <a-input v-model:value="searchFormState.searchKey" placeholder="请输入角色名称关键词"></a-input>
  24. </a-form-item>
  25. </a-col>
  26. <a-col :span="8">
  27. <a-button type="primary" @click="table.refresh(true)">
  28. <template #icon><SearchOutlined /></template>
  29. 查询
  30. </a-button>
  31. <a-button class="snowy-buttom-left" @click="reset">
  32. <template #icon><redo-outlined /></template>
  33. 重置
  34. </a-button>
  35. </a-col>
  36. </a-row>
  37. </a-form>
  38. </a-card>
  39. <a-card :bordered="false">
  40. <s-table
  41. ref="table"
  42. :columns="columns"
  43. :data="loadData"
  44. :expand-row-by-click="true"
  45. :alert="options.alert.show"
  46. bordered
  47. :row-key="(record) => record.id"
  48. :row-selection="options.rowSelection"
  49. @resizeColumn="handleResizeColumn"
  50. >
  51. <template #operator class="table-operator">
  52. <a-space>
  53. <a-button
  54. type="primary"
  55. @click="formRef.onOpen(undefined, searchFormState.category, searchFormState.orgId)"
  56. >
  57. <template #icon><plus-outlined /></template>
  58. 新增角色
  59. </a-button>
  60. <xn-batch-delete :selectedRowKeys="selectedRowKeys" @batchDelete="deleteBatchRole" />
  61. </a-space>
  62. </template>
  63. <template #bodyCell="{ column, record }">
  64. <template v-if="column.dataIndex === 'category'">
  65. {{ $TOOL.dictTypeData('ROLE_CATEGORY', record.category) }}
  66. </template>
  67. <template v-if="column.dataIndex === 'action'">
  68. <a @click="formRef.onOpen(record)">编辑</a>
  69. <a-divider type="vertical" />
  70. <a-popconfirm title="确定删除此角色?" :disabled="record.isBuiltin === '1'" @confirm="removeOrg(record)">
  71. <a-button type="link" danger :disabled="record.isBuiltin === '1'" size="small">删除</a-button>
  72. </a-popconfirm>
  73. <a-divider type="vertical" />
  74. <a-dropdown>
  75. <a class="ant-dropdown-link">
  76. 授权
  77. <DownOutlined />
  78. </a>
  79. <template #overlay>
  80. <a-menu>
  81. <a-menu-item>
  82. <a @click="grantResourceFormRef.onOpen(record)">授权资源</a>
  83. </a-menu-item>
  84. <a-menu-item>
  85. <a @click="grantMobileResourceFormRef.onOpen(record)">授权移动端资源</a>
  86. </a-menu-item>
  87. <a-menu-item>
  88. <a @click="grantPermissionFormRef.onOpen(record)">授权权限</a>
  89. </a-menu-item>
  90. <a-menu-item>
  91. <a @click="openRoleUserSelector(record)">授权用户</a>
  92. </a-menu-item>
  93. </a-menu>
  94. </template>
  95. </a-dropdown>
  96. </template>
  97. </template>
  98. </s-table>
  99. </a-card>
  100. </a-col>
  101. </a-row>
  102. <grantResourceForm ref="grantResourceFormRef" @successful="table.refresh()" />
  103. <grantMobileResourceForm ref="grantMobileResourceFormRef" @successful="table.refresh()" />
  104. <grantPermissionForm ref="grantPermissionFormRef" @successful="table.refresh()" />
  105. <Form ref="formRef" @successful="table.refresh()" />
  106. <user-selector-plus
  107. ref="userselectorPlusRef"
  108. :org-tree-api="selectorApiFunction.orgTreeApi"
  109. :user-page-api="selectorApiFunction.userPageApi"
  110. :checked-user-list-api="selectorApiFunction.checkedUserListApi"
  111. @onBack="userCallBack"
  112. />
  113. </template>
  114. <script setup name="sysRole">
  115. import { Empty } from 'ant-design-vue'
  116. import { isEmpty } from 'lodash-es'
  117. import roleApi from '@/api/sys/roleApi'
  118. import orgApi from '@/api/sys/orgApi'
  119. import userCenterApi from '@/api/sys/userCenterApi'
  120. import GrantResourceForm from './grantResourceForm.vue'
  121. import GrantMobileResourceForm from './grantMobileResourceForm.vue'
  122. import GrantPermissionForm from './grantPermissionForm.vue'
  123. import UserSelectorPlus from '@/components/Selector/userSelectorPlus.vue'
  124. import Form from './form.vue'
  125. const columns = [
  126. {
  127. title: '角色名称',
  128. dataIndex: 'name',
  129. resizable: true,
  130. width: 150
  131. },
  132. {
  133. title: '分类',
  134. dataIndex: 'category',
  135. width: 100
  136. },
  137. {
  138. title: '排序',
  139. dataIndex: 'sortCode',
  140. width: 100
  141. },
  142. {
  143. title: '操作',
  144. dataIndex: 'action',
  145. align: 'center',
  146. width: 100,
  147. fixed: 'right'
  148. }
  149. ]
  150. const selectedRowKeys = ref([])
  151. // 列表选择配置
  152. const options = {
  153. alert: {
  154. show: false,
  155. clear: () => {
  156. selectedRowKeys.value = ref([])
  157. }
  158. },
  159. rowSelection: {
  160. onChange: (selectedRowKey, selectedRows) => {
  161. selectedRowKeys.value = selectedRowKey
  162. }
  163. }
  164. }
  165. // 定义tableDOM
  166. const table = ref()
  167. const formRef = ref()
  168. const grantResourceFormRef = ref()
  169. const grantMobileResourceFormRef = ref()
  170. const grantPermissionFormRef = ref()
  171. const userselectorPlusRef = ref()
  172. const searchFormRef = ref()
  173. const searchFormState = ref({})
  174. // 默认展开的节点
  175. const defaultExpandedKeys = ref([])
  176. const treeData = ref([])
  177. // 替换treeNode 中 title,key,children
  178. const treeFieldNames = { children: 'children', title: 'name', key: 'id' }
  179. const cardLoading = ref(true)
  180. // 记录数据
  181. const recordCacheData = ref({})
  182. // 表格查询 返回 Promise 对象
  183. const loadData = (parameter) => {
  184. let param = Object.assign(parameter, searchFormState.value)
  185. return roleApi.rolePage(param).then((res) => {
  186. return res
  187. })
  188. }
  189. // 重置
  190. const reset = () => {
  191. searchFormRef.value.resetFields()
  192. table.value.refresh(true)
  193. }
  194. // 加载左侧的树
  195. orgApi.orgTree().then((res) => {
  196. cardLoading.value = false
  197. if (res !== null) {
  198. // 树中插入全局角色类型
  199. const globalRoleType = [
  200. {
  201. id: 'GLOBAL',
  202. parentId: '-1',
  203. name: '全局'
  204. }
  205. ]
  206. treeData.value = globalRoleType.concat(res)
  207. if (isEmpty(defaultExpandedKeys.value)) {
  208. // 默认展开2级
  209. treeData.value.forEach((item) => {
  210. // 因为0的顶级
  211. if (item.parentId === '0') {
  212. defaultExpandedKeys.value.push(item.id)
  213. // 取到下级ID
  214. if (item.children) {
  215. item.children.forEach((items) => {
  216. defaultExpandedKeys.value.push(items.id)
  217. })
  218. }
  219. }
  220. })
  221. }
  222. }
  223. })
  224. // 点击树查询
  225. const treeSelect = (selectedKeys) => {
  226. if (selectedKeys.length > 0) {
  227. if (selectedKeys[0] === 'GLOBAL') {
  228. searchFormState.value.category = selectedKeys[0]
  229. delete searchFormState.value.orgId
  230. } else {
  231. searchFormState.value.orgId = selectedKeys.toString()
  232. delete searchFormState.value.category
  233. }
  234. } else {
  235. delete searchFormState.value.category
  236. delete searchFormState.value.orgId
  237. }
  238. table.value.refresh(true)
  239. }
  240. // 可伸缩列
  241. const handleResizeColumn = (w, col) => {
  242. col.width = w
  243. }
  244. // 删除
  245. const removeOrg = (record) => {
  246. let params = [
  247. {
  248. id: record.id
  249. }
  250. ]
  251. roleApi.roleDelete(params).then(() => {
  252. table.value.refresh(true)
  253. })
  254. }
  255. // 批量删除
  256. const deleteBatchRole = (params) => {
  257. roleApi.roleDelete(params).then(() => {
  258. table.value.clearRefreshSelected()
  259. })
  260. }
  261. // 打开用户选择器
  262. const openRoleUserSelector = (record) => {
  263. // 打开人员选择器的时候,缓存一个记录数据
  264. recordCacheData.value = record
  265. // 查询接口,查到这个角色是多少个用户都有它
  266. const param = {
  267. id: record.id
  268. }
  269. roleApi.roleOwnUser(param).then((data) => {
  270. userselectorPlusRef.value.showUserPlusModal(data)
  271. })
  272. }
  273. // 人员选择器回调
  274. const userCallBack = (value) => {
  275. const param = {
  276. id: recordCacheData.value.id,
  277. grantInfoList: value.map((item) => {
  278. return item.id
  279. })
  280. }
  281. roleApi.roleGrantUser(param).then(() => {})
  282. }
  283. // 传递设计器需要的API
  284. const selectorApiFunction = {
  285. orgTreeApi: (param) => {
  286. return roleApi.roleOrgTreeSelector(param).then((data) => {
  287. return Promise.resolve(data)
  288. })
  289. },
  290. userPageApi: (param) => {
  291. return roleApi.roleUserSelector(param).then((data) => {
  292. return Promise.resolve(data)
  293. })
  294. },
  295. checkedUserListApi: (param) => {
  296. return userCenterApi.userCenterGetUserListByIdList(param).then((data) => {
  297. return Promise.resolve(data)
  298. })
  299. }
  300. }
  301. </script>
  302. <style scoped>
  303. .ant-form-item {
  304. margin-bottom: 0 !important;
  305. }
  306. .primaryAdd {
  307. margin-right: 10px;
  308. }
  309. .snowy-buttom-left {
  310. margin-left: 8px;
  311. }
  312. </style>