index.vue 7.9 KB

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