1
0

index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div class="page-container">
  3. <div class="content-container">
  4. <div class="main">
  5. <div class="table-nav">
  6. <div class="tags">
  7. <div class="tag" :style="isActive(1)" @click="toTab1">数据角色</div>
  8. <div class="tag" :style="isActive(2)" @click="toTab2">数据权限</div>
  9. </div>
  10. <div class="actions">
  11. <el-button type="primary" icon="el-icon-plus" size="mini " v-show="tabIndex == 1" @click="addRole" v-hasPermi="['system:dataPermissions:addRole']">添加</el-button>
  12. </div>
  13. </div>
  14. <!-- 数据角色表格 -->
  15. <el-table v-loading="loading" :data="roleList" border highlight-current-row @current-change="rowHandler" :cell-style="{ cursor: 'pointer' }" v-show="tabIndex == 1">
  16. <el-table-column label="名称" prop="dataRoleName" width="200">
  17. <template slot-scope="scope">
  18. <a href="javascript:void(0);" class="linked" @click="toTab2">{{ scope.row.dataRoleName }}</a>
  19. </template>
  20. </el-table-column>
  21. <el-table-column label="描述" prop="remark" />
  22. <el-table-column label="创建时间" prop="createTime" width="200" align="center" />
  23. <el-table-column label="操作" class-name="small-padding fixed-width" width="300" align="center">
  24. <template slot-scope="scope">
  25. <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="updRole(scope.row)" v-hasPermi="[' system:dataPermissions:updRole']">修改</el-button>
  26. <el-button size="mini" type="text" icon="el-icon-delete" @click.stop="delRole(scope.row)" v-hasPermi="['system:dataPermissions:delRole']">删除</el-button>
  27. <el-button size="mini" type="text" icon="el-icon-remove" @click.stop="setRole(scope.row)" v-hasPermi="['system:dataPermissions:disabledRole']" v-if="scope.row.status == 0"
  28. >禁用</el-button
  29. >
  30. <el-button
  31. size="mini"
  32. type="text"
  33. icon="el-icon-circle-plus"
  34. @click.stop="setRole(scope.row)"
  35. v-hasPermi="['system:dataPermissions:disabledRole']"
  36. v-if="scope.row.status == 1"
  37. >启用</el-button
  38. >
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. <pagination v-show="roleTotal > 0 && tabIndex == 1" :total="roleTotal" :page.sync="roleParams.pageNum" :limit.sync="roleParams.pageSize" @pagination="getRoleList" />
  43. <!-- 数据权限表格 -->
  44. <el-table
  45. v-loading="loading"
  46. :data="deptTreeList"
  47. border
  48. highlight-current-row
  49. row-key="id"
  50. :default-expand-all="true"
  51. :cell-style="{ cursor: 'pointer' }"
  52. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  53. v-show="tabIndex == 2"
  54. >
  55. <el-table-column label="机构名称" prop="label" />
  56. <el-table-column label="数据权限" class-name="small-padding fixed-width" width="300" align="center">
  57. <template slot-scope="scope">
  58. <input type="checkbox" :checked="authIds.includes(scope.row.id)" @change="checkboxClick(scope.row, $event)" :disabled="!checkPermi(['system:dataPermissions:updAuth'])" />
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. <!-- 编辑数据角色 -->
  63. <el-dialog :title="roleTitle" :visible.sync="roleShow" width="30%">
  64. <el-form ref="roleForm" :model="roleForm" :rules="roleRules" label-width="100px">
  65. <el-form-item label="名称" prop="dataRoleName">
  66. <div style="width: 200px"><el-input v-model="roleForm.dataRoleName" placeholder="请输入名称" /></div>
  67. </el-form-item>
  68. <el-form-item label="描述" prop="remark">
  69. <div style="width: 300px"><el-input maxlength="80" v-model="roleForm.remark" placeholder="请输入描述" /></div>
  70. </el-form-item>
  71. </el-form>
  72. <div slot="footer" class="dialog-footer">
  73. <el-button size="small" @click="roleCancel">取 消</el-button>
  74. <el-button type="primary" size="small" @click="roleSub">保 存</el-button>
  75. </div>
  76. </el-dialog>
  77. </div>
  78. </div>
  79. </div>
  80. </template>
  81. <script>
  82. import { roleAdd, roleList, roleUpd, roleDel, roleStatus, authUpd, deptList } from '@/api/system/dataPermissions.js'
  83. import { checkPermi } from '@/utils/permission'
  84. export default {
  85. name: 'dataPermissions',
  86. data() {
  87. return {
  88. loading: false,
  89. //tab索引
  90. tabIndex: 1,
  91. //角色数据
  92. roleList: [],
  93. //角色弹窗
  94. roleShow: false,
  95. //角色表单
  96. roleForm: {
  97. //角色名称
  98. dataRoleName: '',
  99. //角色描述
  100. remark: ''
  101. },
  102. //角色表单验证
  103. roleRules: {
  104. dataRoleName: [{ required: true, message: '名称不能为空', trigger: 'submit' }]
  105. },
  106. //角色总条数
  107. roleTotal: 0,
  108. // 角色查询参数
  109. roleParams: {
  110. pageNum: 1,
  111. pageSize: 10
  112. },
  113. //权限数据ids
  114. authIds: [],
  115. //部门数据
  116. deptList: [],
  117. //选中的角色id
  118. dataRoleId: 0,
  119. //弹窗标题
  120. roleTitle: ''
  121. }
  122. },
  123. created() {
  124. this.getRoleList()
  125. deptList().then((res) => {
  126. if (res.code === 200) {
  127. this.deptList = res.data
  128. }
  129. })
  130. },
  131. computed: {
  132. theme() {
  133. return this.$store.state.settings.theme
  134. },
  135. deptTreeList() {
  136. return this.dataRoleId ? this.deptList : []
  137. }
  138. },
  139. methods: {
  140. checkPermi,
  141. //动态选中样式
  142. isActive(index) {
  143. if (this.tabIndex != index) return {}
  144. return {
  145. color: this.theme
  146. }
  147. },
  148. //跳转到tab1
  149. toTab1() {
  150. this.tabIndex = 1
  151. },
  152. //跳转到tab2
  153. toTab2() {
  154. this.tabIndex = 2
  155. },
  156. //获取角色数据
  157. getRoleList() {
  158. if (!checkPermi(['system:dataPermissions:listRole'])) {
  159. return
  160. }
  161. roleList(this.roleParams).then((res) => {
  162. if (res.code === 200) {
  163. this.roleList = res.rows
  164. this.roleTotal = res.total
  165. }
  166. })
  167. },
  168. //添加角色
  169. addRole() {
  170. this.roleShow = true
  171. this.roleTitle = '角色添加'
  172. },
  173. //数据角色行选中
  174. rowHandler(e) {
  175. this.dataRoleId = e.dataRoleId
  176. if (e.deptIds && e.deptIds != '') {
  177. this.authIds = e.deptIds.split(',').map((item) => Number(item))
  178. } else {
  179. this.authIds = []
  180. }
  181. },
  182. //角色弹窗取消
  183. roleCancel() {
  184. this.resetRoleForm()
  185. this.roleShow = false
  186. },
  187. //角色弹窗提交
  188. roleSub() {
  189. this.$refs.roleForm.validate((valid) => {
  190. if (valid) {
  191. if (this.roleForm.dataRoleId) {
  192. roleUpd(this.roleForm).then((res) => {
  193. if (res.code == 200) {
  194. this.$msg({ message: '修改成功' })
  195. this.roleCancel()
  196. this.getRoleList()
  197. }
  198. })
  199. } else {
  200. roleAdd(this.roleForm).then((res) => {
  201. if (res.code == 200) {
  202. this.$msg({ message: '添加成功' })
  203. this.roleCancel()
  204. this.getRoleList()
  205. }
  206. })
  207. }
  208. } else {
  209. return false
  210. }
  211. })
  212. },
  213. //角色表单重置,
  214. resetRoleForm() {
  215. this.roleForm = {
  216. //角色名称
  217. dataRoleName: '',
  218. //角色描述
  219. remark: ''
  220. }
  221. },
  222. //修改角色
  223. updRole(row) {
  224. this.roleForm.dataRoleName = row.dataRoleName
  225. this.roleForm.remark = row.remark
  226. this.roleForm.dataRoleId = row.dataRoleId
  227. this.roleTitle = '角色修改'
  228. this.roleShow = true
  229. },
  230. //删除角色
  231. delRole(row) {
  232. this.$modal
  233. .confirm('确定要删除吗')
  234. .then(() => {
  235. roleDel(row.dataRoleId).then((res) => {
  236. if (res.code == 200) {
  237. this.$msg({ message: '删除成功' })
  238. this.getRoleList()
  239. }
  240. })
  241. })
  242. .catch(() => {})
  243. },
  244. //角色禁用
  245. setRole(row) {
  246. roleStatus({
  247. dataRoleId: row.dataRoleId,
  248. status: Math.abs(row.status - 1)
  249. }).then((res) => {
  250. if (res.code === 200) {
  251. this.$msg({ message: '操作成功' })
  252. row.status = Math.abs(row.status - 1)
  253. }
  254. })
  255. },
  256. //编辑权限
  257. checkboxClick(d, e) {
  258. let status = e.target.checked
  259. let ids = [...this.authIds]
  260. if (status) {
  261. ids.push(d.id)
  262. } else {
  263. ids = ids.filter((item) => item != d.id)
  264. }
  265. authUpd({ dataRoleId: this.dataRoleId, deptIds: ids.join(',') }).then((res) => {
  266. if (res.code === 200) {
  267. if (status) {
  268. this.authIds.push(d.id)
  269. } else {
  270. this.authIds = this.authIds.filter((item) => item != d.id)
  271. }
  272. let row = this.roleList.find((item) => item.dataRoleId == this.dataRoleId)
  273. row.deptIds = this.authIds.join(',')
  274. }
  275. })
  276. }
  277. }
  278. }
  279. </script>
  280. <style></style>