index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. //数据范围列表
  117. optionsDataList:[
  118. {type: '1', value: "所有数据",},
  119. {type: '2', value: "本部门及指定部门数据",},
  120. {type: '3', value: "本部门及下级部门数据",},
  121. {type: '4', value: "当前账号数据",},
  122. ],
  123. };
  124. },
  125. created() {
  126. this.getList();
  127. this.getDicts("sys_normal_disable").then(response => {
  128. this.statusOptions = response.data;
  129. });
  130. },
  131. methods: {
  132. goPage(type){
  133. if(this.pageType != type){
  134. if(type == 1){
  135. this.$set(this,'pageType',type);
  136. }else if(type == 3){
  137. this.$set(this,'pageType',1);
  138. this.resetQuery();
  139. }
  140. }
  141. },
  142. /** 查询角色列表 */
  143. getList() {
  144. this.loading = true;
  145. listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
  146. response => {
  147. this.roleList = response.rows;
  148. this.total = response.total;
  149. this.loading = false;
  150. }
  151. );
  152. },
  153. /** 搜索按钮操作 */
  154. handleQuery() {
  155. this.queryParams.pageNum = 1;
  156. this.getList();
  157. },
  158. /** 重置按钮操作 */
  159. resetQuery() {
  160. this.$set(this,"form",
  161. {
  162. pageNum: 1,
  163. pageSize:20,
  164. roleName: null,
  165. status: null
  166. }
  167. );
  168. this.handleQuery();
  169. },
  170. /** 新增按钮操作 */
  171. handleAdd() {
  172. let obj = {
  173. type:1,
  174. title:"新增角色",
  175. };
  176. this.$set(this,'propsData',obj);
  177. this.$set(this,'pageType',2);
  178. },
  179. /** 修改按钮操作 */
  180. handleUpdate(row) {
  181. getRole(row.roleId).then(response => {
  182. let obj = {
  183. type:2,
  184. roleId:response.role.roleId,
  185. name:response.role.roleName,
  186. key:response.role.roleKey,
  187. dataScope:response.role.dataScope,
  188. viewDeptIds:response.role.viewDeptIds,
  189. list:response.checkedKeys,
  190. title:"编辑角色",
  191. };
  192. this.$set(this,'propsData',obj);
  193. this.$set(this,'pageType',2);
  194. });
  195. },
  196. /** 复制按钮 */
  197. copyButton(row){
  198. getRole(row.roleId).then(response => {
  199. let obj = {
  200. type:3,
  201. dataScope:response.role.dataScope,
  202. viewDeptIds:response.role.viewDeptIds,
  203. list:response.checkedKeys,
  204. title:"复制角色",
  205. };
  206. this.$set(this,'propsData',obj);
  207. this.$set(this,'pageType',2);
  208. });
  209. },
  210. /** 删除按钮操作 */
  211. handleDelete(row) {
  212. this.$confirm('是否确认删除角色?', "警告", {
  213. confirmButtonText: "确定",
  214. cancelButtonText: "取消",
  215. type: "warning"
  216. }).then(function() {
  217. return delRole(row.roleId);
  218. }).then(() => {
  219. this.getList();
  220. this.msgSuccess("删除成功");
  221. }).catch(() => {});
  222. },
  223. }
  224. };
  225. </script>
  226. <style scoped lang="scss">
  227. .role {
  228. display: flex!important;
  229. flex-direction: column;
  230. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  231. .role_n{
  232. display: flex!important;
  233. flex-direction: column;
  234. flex: 1;
  235. padding:11px 20px 20px!important;
  236. }
  237. .form-box{
  238. margin-top:12px;
  239. // display: flex;
  240. .null-p{
  241. flex:1;
  242. }
  243. }
  244. .button-box{
  245. width:390px;
  246. display: flex;
  247. }
  248. }
  249. </style>