index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <!--角色管理-->
  2. <template>
  3. <div class="app-container role">
  4. <div class="role_n" v-if="pageType==1">
  5. <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true" class="form-box" >
  6. <el-form-item label="角色名称" prop="roleName" style="margin-left:20px;">
  7. <el-input
  8. v-model="queryParams.roleName"
  9. placeholder="请输入角色名称"
  10. clearable
  11. size="small"
  12. />
  13. </el-form-item>
  14. <el-form-item label="状态" prop="status">
  15. <el-select
  16. v-model="queryParams.status"
  17. placeholder="角色状态"
  18. clearable
  19. size="small"
  20. >
  21. <el-option
  22. v-for="dict in statusOptions"
  23. :key="dict.dictValue"
  24. :label="dict.dictLabel"
  25. :value="dict.dictValue"
  26. />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item style="float: right;">
  30. <el-col :span="1.5">
  31. <p class="add-button-one-120"
  32. @click="handleAdd"
  33. v-hasPermi="['system:role:add']"
  34. ><i class="el-icon-plus"></i>新增角色</p>
  35. </el-col>
  36. </el-form-item>
  37. <el-form-item>
  38. <p class="inquire-button-one" @click="handleQuery">查询</p>
  39. <p class="reset-button-one" @click="resetQuery">重置</p>
  40. </el-form-item>
  41. </el-form>
  42. <el-table v-loading="loading" border :data="roleList" class="table-box" v-if="pageType==1">
  43. <el-table-column label="序号" width="100" align="center" type="index"/>
  44. <el-table-column label="名称" prop="roleName" align="center" :show-overflow-tooltip="true" width="200"/>
  45. <el-table-column label="数据范围" prop="dataScope" align="center" :show-overflow-tooltip="true" width="296">
  46. <template slot-scope="scope">
  47. <p v-for="(item,index) in optionsDataList" :key="index" v-if="scope.row.dataScope == item.type">{{item.value}}</p>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="对应身份" prop="postNameStr" align="center" :show-overflow-tooltip="true"/>
  51. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180" v-if="tableButtonType">
  52. <template slot-scope="scope" v-if="scope.row.roleId !== 1">
  53. <div class="table-button-box">
  54. <p class="table-button-null"></p>
  55. <p class="table-button-p"
  56. @click="copyButton(scope.row)"
  57. v-hasPermi="['system:dict:edit']"
  58. >复制</p>
  59. <p class="table-button-p"
  60. @click="handleUpdate(scope.row)"
  61. v-hasPermi="['system:role:edit']"
  62. >编辑</p>
  63. <p class="table-button-p"
  64. @click="handleDelete(scope.row)"
  65. v-hasPermi="['system:role:remove']"
  66. >删除</p>
  67. <p class="table-button-null"></p>
  68. </div>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. <pagination :page-sizes="[20, 30, 40, 50]"
  73. v-if="pageType==1"
  74. v-show="total>0"
  75. :total="total"
  76. layout="total, prev, pager, next, sizes, jumper"
  77. :page.sync="queryParams.pageNum"
  78. :limit.sync="queryParams.pageSize"
  79. @pagination="getList"
  80. />
  81. </div>
  82. <!--编辑-->
  83. <add-page v-if="pageType == 2" :propsData="propsData"></add-page>
  84. </div>
  85. </template>
  86. <script>
  87. import { listRole, getRole, delRole, addRole, updateRole, dataScope, changeRoleStatus } from "@/api/system/role";
  88. import addPage from "./addPage.vue"
  89. export default {
  90. components: {
  91. addPage
  92. },
  93. name: "Role",
  94. data() {
  95. return {
  96. tableButtonType:this.hasPermiDom(['system:dict:edit','system:role:edit','system:role:remove']),
  97. // 遮罩层
  98. loading: true,
  99. // 显示搜索条件
  100. showSearch: true,
  101. // 总条数
  102. total: 0,
  103. // 状态数据字典
  104. statusOptions: [],
  105. // 查询参数
  106. queryParams: {
  107. pageNum: 1,
  108. pageSize:20,
  109. roleName: null,
  110. status: null
  111. },
  112. roleList:[],
  113. pageType:1,
  114. //组件传参数据
  115. propsData:{},
  116. //数据范围(1:全部, 2:部门及下级, 3:本部门, 4:仅本人,5:自定义)
  117. optionsDataList:[
  118. {type: 1, value: "所有数据",},
  119. {type: 2, value: "本部门及下级部门数据",},
  120. {type: 3, value: "本部门",},
  121. {type: 4, value: "当前账号数据",},
  122. {type: 5, value: "自定义",},
  123. ],
  124. };
  125. },
  126. created() {
  127. this.getList();
  128. this.getDicts("sys_normal_disable").then(response => {
  129. this.statusOptions = response.data;
  130. });
  131. },
  132. methods: {
  133. goPage(type){
  134. if(this.pageType != type){
  135. if(type == 1){
  136. this.$set(this,'pageType',type);
  137. }else if(type == 3){
  138. this.$set(this,'pageType',1);
  139. this.resetQuery();
  140. }
  141. }
  142. },
  143. /** 查询角色列表 */
  144. getList() {
  145. this.loading = true;
  146. listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
  147. response => {
  148. this.roleList = response.rows;
  149. this.total = response.total;
  150. this.loading = false;
  151. }
  152. );
  153. },
  154. /** 搜索按钮操作 */
  155. handleQuery() {
  156. this.queryParams.pageNum = 1;
  157. this.getList();
  158. },
  159. /** 重置按钮操作 */
  160. resetQuery() {
  161. this.$set(this,"form",
  162. {
  163. pageNum: 1,
  164. pageSize:20,
  165. roleName: null,
  166. status: null
  167. }
  168. );
  169. this.handleQuery();
  170. },
  171. /** 新增按钮操作 */
  172. handleAdd() {
  173. let obj = {
  174. type:1,
  175. title:"新增角色",
  176. };
  177. this.$set(this,'propsData',obj);
  178. this.$set(this,'pageType',2);
  179. },
  180. /** 修改按钮操作 */
  181. handleUpdate(row) {
  182. getRole(row.roleId).then(response => {
  183. let obj = {
  184. type:2,
  185. roleId:response.role.roleId,
  186. name:response.role.roleName,
  187. key:response.role.roleKey,
  188. dataScope:response.role.dataScope,
  189. viewDeptIds:response.role.viewDeptIds,
  190. list:response.checkedKeys,
  191. title:"编辑角色",
  192. };
  193. this.$set(this,'propsData',obj);
  194. this.$set(this,'pageType',2);
  195. });
  196. },
  197. /** 复制按钮 */
  198. copyButton(row){
  199. getRole(row.roleId).then(response => {
  200. let obj = {
  201. type:3,
  202. dataScope:response.role.dataScope,
  203. viewDeptIds:response.role.viewDeptIds,
  204. list:response.checkedKeys,
  205. title:"复制角色",
  206. };
  207. this.$set(this,'propsData',obj);
  208. this.$set(this,'pageType',2);
  209. });
  210. },
  211. /** 删除按钮操作 */
  212. handleDelete(row) {
  213. this.$confirm('是否确认删除角色?', "警告", {
  214. confirmButtonText: "确定",
  215. cancelButtonText: "取消",
  216. type: "warning"
  217. }).then(function() {
  218. return delRole(row.roleId);
  219. }).then(() => {
  220. this.getList();
  221. this.msgSuccess("删除成功");
  222. }).catch(() => {});
  223. },
  224. }
  225. };
  226. </script>
  227. <style scoped lang="scss">
  228. .role {
  229. display: flex!important;
  230. flex-direction: column;
  231. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  232. .role_n{
  233. display: flex!important;
  234. flex-direction: column;
  235. flex: 1;
  236. padding:11px 20px 20px!important;
  237. }
  238. .form-box{
  239. margin-top:12px;
  240. // display: flex;
  241. .null-p{
  242. flex:1;
  243. }
  244. }
  245. .button-box{
  246. width:390px;
  247. display: flex;
  248. }
  249. }
  250. </style>