author-role-manage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <dg-row :gutter="10" class="role-edit-box">
  3. <dg-col :span="14">
  4. <dg-card shadow="never" header="角色信息">
  5. <el-form ref="form" :model="reportForm" label-suffix=":" inline>
  6. <el-form-item label="名称" prop="name.value"
  7. ><el-input
  8. clearable
  9. placeholder="请输入名称"
  10. v-model="reportForm.name.value"
  11. style="width: 160px"
  12. @keyup.enter.native="handleSearchClick"
  13. ></el-input
  14. ></el-form-item>
  15. <el-form-item label="层级" prop="role_level.value">
  16. <dg-select
  17. filterable
  18. clearable
  19. v-model="reportForm.role_level.value"
  20. placeholder="请选择层级"
  21. code="DM_ROLE_LEVEL"
  22. style="width: 160px"
  23. ></dg-select
  24. ></el-form-item>
  25. <el-form-item
  26. ><dg-button type="primary" icon="el-icon-search" @click="handleSearchClick"
  27. >查询</dg-button
  28. ></el-form-item
  29. >
  30. </el-form>
  31. <div class="u-table-top__btn">
  32. <dg-button type="primary" icon="el-icon-circle-plus-outline" @click="handleAddDialog('role')">
  33. 新增
  34. </dg-button>
  35. <dg-button type="primary" icon="el-icon-circle-plus-outline" @click="handleAddDialog('apply')">
  36. 新增申请
  37. </dg-button>
  38. </div>
  39. <Table
  40. ref="myRoleTable"
  41. :url="roleTableUrl"
  42. :headerData="titleData"
  43. :condition="reportForm"
  44. :maxheight="620"
  45. @handleRowClick="handleRowClick"
  46. >
  47. <dg-table-column label="操作" width="240" align="center">
  48. <template slot-scope="scope">
  49. <el-button type="text" @click="handleRoleEdit(scope.row, 'role', $event)">
  50. 修改
  51. </el-button>
  52. <el-button type="text" @click="handleRoleDelete(scope.row, 'role', $event)">
  53. 删除
  54. </el-button>
  55. <el-button type="text" @click="handleRoleEdit(scope.row, 'apply', $event)">
  56. 修改申请
  57. </el-button>
  58. <el-button type="text" @click="handleRoleDelete(scope.row, 'apply', $event)">
  59. 删除申请
  60. </el-button>
  61. </template>
  62. </dg-table-column>
  63. </Table>
  64. </dg-card>
  65. </dg-col>
  66. <dg-col :span="10">
  67. <dg-card shadow="never" header="资源信息">
  68. <div class="u-table-top__btn">
  69. <dg-button type="primary" icon="el-icon-folder-checked" @click="handleSaveMenu">保存</dg-button>
  70. </div>
  71. <!--树形表格-->
  72. <dg-table
  73. :data="tableData"
  74. :pagination="false"
  75. style="width: 100%; margin-bottom: 20px"
  76. row-key="id"
  77. border
  78. default-expand-all
  79. ref="table"
  80. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  81. @select="select"
  82. @select-all="selectAll"
  83. @selection-change="selectionChange"
  84. >
  85. <dg-table-column type="selection" width="50"> </dg-table-column>
  86. <dg-table-column prop="name" label="资源名称"> </dg-table-column>
  87. </dg-table>
  88. </dg-card>
  89. </dg-col>
  90. </dg-row>
  91. </template>
  92. <script>
  93. import Table from "@/components/table"
  94. import * as roleinfoManageApi from "@/api/roleinfo-manage"
  95. import * as appfunMenuApi from "@/api/common"
  96. import roleMange from "./role-manage.vue"
  97. export default {
  98. name: "",
  99. components: {
  100. Table
  101. },
  102. // 接收父节点的参数
  103. props: {
  104. appId: {
  105. type: String,
  106. default: ""
  107. }
  108. },
  109. data() {
  110. return {
  111. roleTableUrl: roleinfoManageApi.appRoleTableUrl,
  112. reportForm: {
  113. name: { value: "", op: "like" },
  114. role_level: { value: "", op: "=" },
  115. app_id: { value: "", op: "=" }
  116. },
  117. titleData: [
  118. { label: "角色名称", prop: "name" },
  119. { label: "角色层级", code: "DM_ROLE_LEVEL", prop: "rolelevelCode" },
  120. { label: "警种", prop: "policeCategory", code: "T_MD_POLICE_TYPE" }
  121. ],
  122. treeProps: {
  123. label: "label",
  124. children: "children"
  125. },
  126. tableData: [],
  127. selectArr: [],
  128. roleId: ""
  129. }
  130. },
  131. // 页面创建完成$data可访问 $el不可以访问
  132. created() {
  133. const that = this
  134. this.$set(this.reportForm.app_id, "value", this.appId)
  135. this.getAppfunMenu()
  136. },
  137. // 方法
  138. methods: {
  139. // 查询角色
  140. handleSearchClick() {
  141. this.$refs.myRoleTable.handleSearchClick()
  142. },
  143. // 新增
  144. handleAddDialog(createType = "role") {
  145. const that = this
  146. const { appId } = that
  147. const layer = that.$dgLayer({
  148. title: createType === "role" ? "新增角色" : "新增申请",
  149. area: ["550px", "650px"],
  150. shadow: [0.4, "#fff"],
  151. content: roleMange,
  152. props: {
  153. appId,
  154. type: "create",
  155. createType
  156. },
  157. on: {
  158. success(bool = false) {
  159. layer.close(layer.dialogIndex)
  160. if (bool) {
  161. that.reloadTable()
  162. }
  163. }
  164. }
  165. })
  166. },
  167. // 修改
  168. handleRoleEdit({ id }, createType = "role", event) {
  169. event.stopPropagation()
  170. const that = this
  171. const { appId } = that
  172. roleinfoManageApi.getRoleInfo(id).then(res => {
  173. const layer = that.$dgLayer({
  174. title: "修改角色",
  175. area: ["490px", "650px"],
  176. shadow: [0.4, "#fff"],
  177. content: roleMange,
  178. props: {
  179. appId,
  180. type: "update",
  181. createType,
  182. formData: res
  183. },
  184. on: {
  185. success(bool = false) {
  186. layer.close(layer.dialogIndex)
  187. if (bool) {
  188. that.reloadTable()
  189. }
  190. }
  191. }
  192. })
  193. })
  194. },
  195. // 删除、
  196. handleRoleDelete(row, createType = "role", event) {
  197. event.stopPropagation()
  198. const that = this
  199. const isRole = createType === "role"
  200. let message = isRole ? "是否确定删除角色" : "是否确定删除申请"
  201. message += row.name + "?"
  202. that.$confirm(message, "提示", {
  203. distinguishCancelAndClose: true,
  204. confirmButtonText: "确定",
  205. cancelButtonText: "取消"
  206. }).then(_ => {
  207. if (isRole) {
  208. roleinfoManageApi
  209. .deleteRole(row.id)
  210. .then(() => {
  211. that.reloadTable()
  212. that.$message.success("删除成功!")
  213. })
  214. .catch(() => {
  215. that.$message.error("删除失败")
  216. })
  217. }
  218. if (!isRole) {
  219. roleinfoManageApi
  220. .roleApply({
  221. operate: "30",
  222. roleSaveVo: row
  223. })
  224. .then(() => {
  225. that.reloadTable()
  226. that.$message.success("删除成功!")
  227. })
  228. .catch(() => {
  229. that.$message.error("删除失败")
  230. })
  231. }
  232. })
  233. },
  234. // 刷新表格
  235. reloadTable() {
  236. const that = this
  237. that.$refs.myRoleTable.$refs.grid.reload()
  238. },
  239. /*
  240. ************应用菜单start********************
  241. */
  242. // 应用菜单--应用关联
  243. getAppfunMenu() {
  244. const that = this
  245. const { appId } = that
  246. appfunMenuApi.getAppfunMenu(appId).then(res => {
  247. if (res && res.length > 0) {
  248. // that.tableData = that.loopTableData(res);
  249. that.tableData = res
  250. }
  251. })
  252. },
  253. // 循环设置菜单表格data
  254. loopTableData(resArr) {
  255. let arr = []
  256. // debugger;
  257. function loopData(resArr2) {
  258. if (resArr2 && resArr2.length > 0) {
  259. resArr2.forEach(item => {
  260. arr.push(item)
  261. if (item.children && item.children.length > 0) {
  262. loopData(item.children)
  263. }
  264. })
  265. }
  266. }
  267. loopData(resArr)
  268. return arr
  269. },
  270. // 应用菜单-角色关联
  271. handleRowClick({ row }) {
  272. const roleId = row.id
  273. const that = this
  274. that.roleId = row.id
  275. roleinfoManageApi
  276. .getMenuChecked(roleId)
  277. .then(res => {
  278. that.selectArr = []
  279. that.$refs.table.clearSelection() // 清空用户选择
  280. // 格式化tableData
  281. let tempTableData = that.loopTableData(that.tableData)
  282. if (res && res.length > 0) {
  283. that.loopSetChecked(res, tempTableData)
  284. }
  285. })
  286. .catch(error => {
  287. that.$message.error(error)
  288. })
  289. },
  290. // 递归设置勾选
  291. loopSetChecked(checkList, allList) {
  292. for (let i = 0; i < checkList.length; i++) {
  293. for (let j = 0; j < allList.length; j++) {
  294. if (checkList[i].funId === allList[j].id) {
  295. this.toggleSelection(allList[j], true)
  296. break
  297. }
  298. // else {
  299. // if (allList[j].children) {
  300. // this.loopSetChecked(checkList, allList[j].children);
  301. // break;
  302. // }
  303. // }
  304. }
  305. }
  306. },
  307. // 保存菜单
  308. handleSaveMenu() {
  309. const that = this
  310. if (!that.roleId) {
  311. that.$message.warning("请选择角色!")
  312. return
  313. }
  314. if (that.selectArr.length == 0) {
  315. that.$message.warning("请选择菜单!")
  316. return
  317. }
  318. let rsGridList = that.selectArr.map(el => {
  319. return { id: el.id }
  320. })
  321. console.log(rsGridList)
  322. roleinfoManageApi
  323. .saveRsGrid({
  324. rsGridLists: rsGridList,
  325. roleId: that.roleId
  326. })
  327. .then(() => {
  328. that.$message.success("保存成功")
  329. })
  330. .catch(error => {
  331. that.$message.error("保存失败")
  332. })
  333. },
  334. select(selection, row) {
  335. const that = this
  336. if (
  337. selection.some(el => {
  338. return row.id === el.id
  339. })
  340. ) {
  341. if (row.children) {
  342. loopRowChild(row.children, true)
  343. // row.children.map(j => {
  344. // this.toggleSelection(j, true);
  345. // });
  346. }
  347. } else {
  348. if (row.children) {
  349. // row.children.map(j => {
  350. // this.toggleSelection(j, false);
  351. // });
  352. loopRowChild(row.children, false)
  353. }
  354. }
  355. function loopRowChild(rows, flag) {
  356. rows.map(item => {
  357. if (item.children) {
  358. loopRowChild(item.children, flag)
  359. }
  360. that.toggleSelection(item, flag)
  361. })
  362. }
  363. },
  364. selectAll(selection) {
  365. const that = this
  366. // tabledata第一层只要有在selection里面就是全选
  367. const isSelect = selection.some(el => {
  368. const tableDataIds = this.tableData.map(j => j.id)
  369. return tableDataIds.includes(el.id)
  370. })
  371. // tableDate第一层只要有不在selection里面就是全不选
  372. const isCancel = !this.tableData.every(el => {
  373. const selectIds = selection.map(j => j.id)
  374. return selectIds.includes(el.id)
  375. })
  376. function loopRowChild(rows, flag) {
  377. rows.map(item => {
  378. if (item.children) {
  379. loopRowChild(item.children, flag)
  380. }
  381. that.toggleSelection(item, flag)
  382. })
  383. }
  384. if (isSelect) {
  385. selection.map(el => {
  386. if (el.children) {
  387. // el.children.map(j => {
  388. // this.toggleSelection(j, true);
  389. // });
  390. loopRowChild(el.children, true)
  391. }
  392. })
  393. }
  394. if (isCancel) {
  395. this.tableData.map(el => {
  396. if (el.children) {
  397. // el.children.map(j => {
  398. // this.toggleSelection(j, false);
  399. // });
  400. loopRowChild(el.children, false)
  401. }
  402. })
  403. }
  404. },
  405. selectionChange(selection) {
  406. this.selectArr = selection
  407. },
  408. toggleSelection(row, select) {
  409. if (row) {
  410. this.$nextTick(() => {
  411. this.$refs.table && this.$refs.table.toggleRowSelection(row, select)
  412. })
  413. }
  414. }
  415. /*
  416. *********应用菜单end**********
  417. */
  418. }
  419. }
  420. </script>
  421. <style lang="scss" scope>
  422. .role-edit-box {
  423. .text-right {
  424. text-align: right;
  425. }
  426. }
  427. </style>