PermissionSettings.vue 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <el-dialog class="settingDialog" title="角色权限配置" width="750px" :visible.sync="visible">
  3. <div class="roleSettings">
  4. <div class="roleName">
  5. <div class="roleNameLeft">
  6. <p>角色名称</p>
  7. <el-input placeholder="请输入内容" v-model="role.name" :disabled="true"></el-input>
  8. </div>
  9. <p style="color:#338AFB" v-if="role.is_system == 0" @click="disableRoleAction(role.id)">删除该角色</p>
  10. </div>
  11. <div class="roleMain" >
  12. <div class="roleMainLeft" >
  13. <p class="roletitle">选择权限</p>
  14. <div class="roleMainLeftBox">
  15. <!--<el-tree-->
  16. <!--:props="defaultProps"-->
  17. <!--:data="data"-->
  18. <!--:default-checked-keys="data"-->
  19. <!--node-key="id"-->
  20. <!--ref="tree"-->
  21. <!--default-expand-all-->
  22. <!--show-checkbox-->
  23. <!--&gt;-->
  24. <!--&lt;!&ndash; <span class="custom-tree-node" slot-scope="{ node, data }">-->
  25. <!--<span>{{ data.name }}</span>-->
  26. <!--</span>&ndash;&gt;-->
  27. <!--</el-tree>-->
  28. <el-tree v-loading="loading" :props="treeProps" :data="purviews" :default-checked-keys="default_checkeds" node-key="id"
  29. ref="tree" default-expand-all show-checkbox>
  30. <span class="custom-tree-node" slot-scope="{ node, data }">
  31. <span>{{ data.name }}</span>
  32. </span>
  33. </el-tree>
  34. </div>
  35. </div>
  36. <!--<div class="roleMainRight">-->
  37. <!--<div class="hasChoose">已选择权限</div>-->
  38. <!--<el-tree-->
  39. <!--:props="treeProps" :data="check_purviews" node-key="id" ref="tree" default-expand-all-->
  40. <!--&gt;</el-tree>-->
  41. <!--</div>-->
  42. </div>
  43. </div>
  44. <div slot="footer" class="dialog-footer">
  45. <el-button @click="hide">取 消</el-button>
  46. <el-button type="primary" @click="submitAction" :loading="submitLoading">保 存</el-button>
  47. </div>
  48. </el-dialog>
  49. </template>
  50. <script>
  51. import { editPurview, getEditPurviewInitData, setRoleStatus } from '@/api/role/role'
  52. export default {
  53. data() {
  54. return {
  55. visible: false,
  56. loading: true,
  57. submitLoading:false,
  58. role_id: 0,
  59. name: '',
  60. role: {
  61. name:"",
  62. },
  63. purviews: [],
  64. treeProps: {
  65. label: 'name',
  66. children: 'childs'
  67. },
  68. default_checkeds: [],
  69. check_purviews: [],
  70. defaultProps: {
  71. children: 'children',
  72. label: 'label'
  73. }
  74. }
  75. },
  76. methods: {
  77. disableRoleAction: function(id) {
  78. this.$msgbox({
  79. title: '提示',
  80. message: '是否确定要移除该角色',
  81. showCancelButton: true,
  82. confirmButtonText: '确定',
  83. cancelButtonText: '取消',
  84. type: 'warning',
  85. beforeClose: (action, instance, done) => {
  86. if (action === "confirm") {
  87. instance.confirmButtonLoading = true;
  88. instance.confirmButtonText = "移除中...";
  89. setRoleStatus(id, false)
  90. .then(rs => {
  91. done();
  92. instance.confirmButtonLoading = false;
  93. const resp = rs.data
  94. if (resp.state === 1) {
  95. this.$emit('delete')
  96. } else {
  97. this.$message.error(resp.msg)
  98. }
  99. })
  100. .catch(err => {
  101. done();
  102. this.$message.error(err);
  103. instance.confirmButtonLoading = false;
  104. })
  105. }else{
  106. done();
  107. }
  108. }
  109. })
  110. },
  111. submitAction: function() {
  112. if (this.role_id <= 0) {
  113. return
  114. }
  115. var checkeds = this.$refs.tree.getCheckedKeys(true)
  116. var ids = []
  117. var func_ids = []
  118. if (checkeds.length > 0) {
  119. this.purviews.forEach(purview => {
  120. if (purview.childs != null && purview.childs.length > 0) {
  121. purview.childs.forEach(childs => {
  122. if (childs.childs == null) {
  123. if (checkeds.indexOf(childs.id) != -1) {
  124. if (ids.indexOf(purview.id) == -1) {
  125. ids.push(purview.id)
  126. }
  127. ids.push(childs.id)
  128. }
  129. } else {
  130. console.log(childs.name)
  131. if (childs.name == '透析记录') {
  132. childs.childs.forEach(child => {
  133. if (checkeds.indexOf(child.id) != -1) {
  134. if (func_ids.indexOf(childs.id) == -1) {
  135. func_ids.push(childs.id)
  136. }
  137. func_ids.push(child.id)
  138. }
  139. })
  140. } else {
  141. childs.childs.forEach(child => {
  142. if (checkeds.indexOf(child.id) != -1) {
  143. if (ids.indexOf(childs.id) == -1) {
  144. ids.push(childs.id)
  145. }
  146. ids.push(child.id)
  147. }
  148. })
  149. }
  150. }
  151. })
  152. } else {
  153. if (checkeds.indexOf(purview.id) != -1) {
  154. ids.push(purview.id)
  155. }
  156. }
  157. })
  158. }
  159. var idsStr = ''
  160. if (ids.length > 0) {
  161. idsStr = ids.join(',')
  162. }
  163. var funcIdsStr = ''
  164. if (func_ids.length > 0) {
  165. funcIdsStr = func_ids.join(',')
  166. }
  167. this.submitLoading = true
  168. editPurview(this.role_id, idsStr, funcIdsStr).then(rs => {
  169. var resp = rs.data
  170. this.submitLoading = false
  171. if (resp.state === 1) {
  172. this.hide()
  173. } else {
  174. this.$message.error(resp.msg)
  175. }
  176. }).catch(err => {
  177. this.submitLoading = false
  178. this.$message.error(err)
  179. })
  180. },
  181. show(role_id) {
  182. this.loading = true
  183. this.visible = true
  184. this.default_checkeds = []
  185. this.purviews = []
  186. var id = parseInt(role_id)
  187. if (id <= 0) {
  188. this.$message.error('参数错误')
  189. return
  190. }
  191. this.role_id = role_id
  192. getEditPurviewInitData(this.role_id).then(rs => {
  193. var resp = rs.data
  194. if (resp.state === 1) {
  195. this.role = resp.data.role
  196. this.purviews.push(...resp.data.purviews)
  197. // 初始化默认选中项
  198. var role_purview_ids = resp.data.role_purview_ids
  199. var checkeds = []
  200. if (role_purview_ids.length > 0) {
  201. var ids = role_purview_ids.split(',')
  202. this.purviews.forEach(purview => {
  203. if (purview.childs != null && purview.childs.length > 0) {
  204. purview.childs.forEach(childs => {
  205. if (childs.childs != null && childs.childs.length > 0) {
  206. childs.childs.forEach(child => {
  207. if (ids.indexOf(child.id + '') != -1) {
  208. checkeds.push(child.id)
  209. }
  210. })
  211. }else{
  212. if (ids.indexOf(childs.id + '') != -1) {
  213. checkeds.push(childs.id)
  214. }
  215. }
  216. })
  217. } else {
  218. if (ids.indexOf(purview.id + '') != -1) {
  219. checkeds.push(purview.id)
  220. }
  221. }
  222. })
  223. }
  224. this.$nextTick(() => {
  225. this.default_checkeds = checkeds
  226. })
  227. this.loading = false
  228. } else {
  229. this.loading = false
  230. this.$message.error(resp.msg)
  231. }
  232. }).catch(err => {
  233. this.loading = false
  234. this.$message.error(err)
  235. })
  236. },
  237. hide() {
  238. this.visible =false
  239. }
  240. }, created() {
  241. }
  242. }
  243. </script>
  244. <style lang="scss" scoped>
  245. .roleSettings {
  246. .roleName {
  247. display: flex;
  248. align-items: center;
  249. justify-content: space-between;
  250. }
  251. .roleNameLeft {
  252. display: flex;
  253. align-items: center;
  254. p {
  255. width: 100px;
  256. }
  257. }
  258. .roleMain {
  259. display: flex;
  260. justify-content: space-between;
  261. margin-top: 18px;
  262. .roleMainLeft {
  263. display: flex;
  264. .roletitle {
  265. width: 74px;
  266. }
  267. .roleMainLeftBox {
  268. width: 500px;
  269. height: 706px;
  270. overflow-y: auto;
  271. border: 1px solid rgba(234, 238, 240, 1);
  272. border-radius: 4px;
  273. padding: 20px 0 0 10px;
  274. }
  275. }
  276. .roleMainRight {
  277. width: 280px;
  278. height: 706px;
  279. overflow-y: auto;
  280. border: 1px solid rgba(235, 238, 240, 1);
  281. color: #303133;
  282. .hasChoose {
  283. height: 42px;
  284. line-height: 42px;
  285. padding-left: 20px;
  286. background: #f6f8f9;
  287. }
  288. }
  289. }
  290. }
  291. </style>
  292. <style lang="scss">
  293. .settingDialog {
  294. .el-dialog__body {
  295. max-height: 600px !important;
  296. }
  297. }
  298. </style>