roleView.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <!--
  2. 人员授权管理-角色视图
  3. @Author:laiyh
  4. @Date: 2020-08-03
  5. -->
  6. <template>
  7. <dg-row gutter="1rem">
  8. <dg-col :span="12">
  9. <dg-card shadow="never" header="角色列表">
  10. <!-- 角色搜索栏 -->
  11. <search-bar
  12. :conditionForm="roleConditionForm"
  13. @submitSearch="receiveRoleSearch"
  14. @submitCurrentApp="getCurrentApp"
  15. ></search-bar>
  16. <!-- 角色列表 -->
  17. <new-table
  18. ref="table"
  19. :tableHeader="roleTableHeader"
  20. :tableUrl="roleTableUrl"
  21. :condition="roleCondition"
  22. @handleRowClick="handleRoleRowClick"
  23. >
  24. </new-table>
  25. </dg-card>
  26. </dg-col>
  27. <dg-col :span="12">
  28. <dg-card shadow="never" header="人员列表">
  29. <!-- 角色搜索栏 -->
  30. <search-bar
  31. :conditionForm="userConditionForm"
  32. @submitSearch="receiveUserSearch"
  33. @submitDefaultSearch="receiveUserDefaultCondition"
  34. ></search-bar>
  35. <!-- 角色操作栏 -->
  36. <operate-bar :pageOptList="userOptList" @submitPageOpt="receviceOpt"></operate-bar>
  37. <!-- 角色列表 -->
  38. <dg-table
  39. ref="userTable"
  40. :condition="userCondition"
  41. :url="userTableUrl"
  42. row-key="id"
  43. border
  44. @selection-change="handleSelectChange"
  45. :before-quest="handleBeforeQuest"
  46. lazyLoad
  47. >
  48. <dg-table-column type="selection" reserve-selection width="50"></dg-table-column>
  49. <!-- <dg-table-column type="index" label="序号" width="70"></dg-table-column> -->
  50. <dg-table-column prop="name" align="center" width="120" label="姓名"></dg-table-column>
  51. <dg-table-column prop="idcard" align="center" label="身份证号码"></dg-table-column>
  52. <!-- <dg-table-column prop="orgName" align="center" label="单位名称"></dg-table-column> -->
  53. <dg-table-column prop="userType" align="center" label="用户类型" enum='UserTypeEnum'></dg-table-column>
  54. <dg-table-column prop="policeCategory" align="center" code="T_MD_POLICE_TYPE" label="警种"></dg-table-column>
  55. <dg-table-column prop="policeBusiness" align="center" label="业务域标签"></dg-table-column>
  56. <dg-table-column label="权限有效期" width="120" align="center">
  57. <template slot-scope="scope">
  58. <a href="javascript:;" @click="handleValidateChoose(scope.row)">{{ scope.row.activeTime }}</a>
  59. </template>
  60. </dg-table-column>
  61. </dg-table>
  62. </dg-card>
  63. </dg-col>
  64. </dg-row>
  65. </template>
  66. <script>
  67. import newTable from '@/components/new-table';
  68. import TermValid from './term-validity';
  69. import * as roleAuthApi from '@/api/role-auth-info';
  70. import searchBar from '@/components/search-bar';
  71. import operateBar from '@/components/operate-bar';
  72. import { searchOpt } from '@/mixins/page-opt';
  73. import { userConditionForm } from './DataConfig';
  74. export default {
  75. name: 'role-list',
  76. components: {
  77. newTable,
  78. searchBar,
  79. operateBar
  80. },
  81. mixins: [searchOpt],
  82. // 接收父页面传过来的属性
  83. props: {},
  84. // 页面数据绑定
  85. data() {
  86. return {
  87. roleCondition: {},
  88. roleConditionForm: [
  89. {
  90. label: '应用系统名称',
  91. name: 'appId',
  92. op: '=',
  93. value: '',
  94. component: 'SelectApp',
  95. apiUrl: roleAuthApi.roleViewApplication,
  96. valueName: 'id',
  97. labelName: 'name'
  98. },
  99. {
  100. label: '角色名称',
  101. name: 'name',
  102. op: 'like',
  103. value: '',
  104. component: 'ElInput',
  105. attr: {
  106. style: 'width: 150px'
  107. }
  108. }
  109. ],
  110. roleTableHeader: [
  111. { label: '角色名称', prop: 'name' },
  112. { label: '角色层级', prop: 'roleLevel', code: 'DM_ROLE_LEVEL' },
  113. { label: '应用系统名称', prop: 'appName' },
  114. { label: '警种', prop: 'policeCategory', code: 'T_MD_POLICE_TYPE' },
  115. { label: '业务域标签', prop: 'roleBusiness', code: 'DM_POLICE_BUSINESS' }
  116. ],
  117. roleTableUrl: roleAuthApi.getRoleListByAppid,
  118. userConditionForm: [
  119. {
  120. label: '单位名称',
  121. name: 'orgId',
  122. op: '=',
  123. value: '',
  124. apiName: 'getOrgTree',
  125. nodeKey: 'id',
  126. type: 'APP',
  127. component: 'SelectOrgTree',
  128. placeholder: '请选择单位名称',
  129. defaultSelectRoot: true
  130. },
  131. {
  132. label: '姓名',
  133. name: 'name',
  134. op: 'like',
  135. value: '',
  136. component: 'ElInput',
  137. attr: {
  138. style: 'width: 130px'
  139. }
  140. }
  141. ],
  142. userOptList: ['保存'],
  143. userCondition: {
  144. roleId: {
  145. value: '',
  146. op: '='
  147. },
  148. orgId: {
  149. value: '',
  150. op: '='
  151. },
  152. name: {
  153. value: '',
  154. op: 'like'
  155. }
  156. },
  157. userTableUrl: roleAuthApi.userTableUrl,
  158. checkUserList: [],
  159. deleteIds: [],
  160. // 点击动作object
  161. saveRoleAuthParams: {
  162. appId: '', // 应用id
  163. orgId: '', // 机构id
  164. roleId: '', // 角色id
  165. appOrgId: '', // 应用绑定的机构id
  166. staffList: '',
  167. staffJson: '',
  168. delStaffJson: ''
  169. },
  170. page: 0,
  171. size: 10,
  172. total: 0,
  173. updateUsers: []
  174. };
  175. },
  176. // 计算属性
  177. computed: {},
  178. // 方法
  179. methods: {
  180. receviceOpt(opt, row) {
  181. if (opt == '保存') {
  182. this.handleSave();
  183. }
  184. },
  185. getCurrentApp(item) {
  186. this.currentAppItem = item;
  187. },
  188. receiveRoleSearch(val) {
  189. this.roleCondition = val;
  190. this.handleSearch();
  191. this.saveRoleAuthParams.appOrgId = this.currentAppItem.appOrgId;
  192. this.saveRoleAuthParams.appId = this.currentAppItem.id;
  193. },
  194. receiveUserDefaultCondition(val) {
  195. for (const key in val) {
  196. this.userCondition[key].value = val[key].value;
  197. }
  198. this.saveRoleAuthParams.orgId = this.userCondition.orgId.value;
  199. },
  200. loadUserTable() {
  201. this.selectUserList = [];
  202. this.$refs.userTable.searchForm();
  203. },
  204. receiveUserSearch(val) {
  205. for (const key in val) {
  206. this.userCondition[key].value = val[key].value;
  207. }
  208. this.saveRoleAuthParams.orgId = this.userCondition.orgId.value;
  209. if (!this.handleValid()) return;
  210. this.loadUserTable();
  211. },
  212. async handleRoleRowClick({ id, appId }) {
  213. this.saveRoleAuthParams.roleId = this.userCondition.roleId.value = id;
  214. this.saveRoleAuthParams.appId = appId;
  215. this.$refs.userTable.clearAll();
  216. await this.getUserChecked();
  217. this.loadUserTable();
  218. },
  219. getUserChecked() {
  220. return new Promise((resolve) => {
  221. const { orgId, roleId, appId } = this.saveRoleAuthParams;
  222. // 获取人员列表选中记录
  223. const queryCheckedParams = {
  224. orgId,
  225. roleId,
  226. appId,
  227. type: 'role'
  228. };
  229. roleAuthApi.getChecked(queryCheckedParams).then((res) => {
  230. this.checkUserList = res;
  231. resolve(res);
  232. });
  233. });
  234. },
  235. handleValid() {
  236. if (!this.saveRoleAuthParams.roleId) {
  237. this.$message.warning('请选择角色!');
  238. return false;
  239. }
  240. if (!this.saveRoleAuthParams.orgId) {
  241. this.$message.warning('请选择单位名称!');
  242. return false;
  243. }
  244. return true;
  245. },
  246. // 用户列表数据渲染前整合数据
  247. handleBeforeQuest(res) {
  248. const { content, totalElements } = res.data;
  249. let _content = content.map((item) => {
  250. return {
  251. ...item,
  252. activeTime: '长期'
  253. };
  254. });
  255. this.currentPageContent = _content;
  256. if (this.checkUserList.length > 0) {
  257. let rowKeys = [];
  258. for (let j = 0; j < _content.length; j++) {
  259. const cItem = _content[j];
  260. const index = this.checkUserList.findIndex((item) => item.id == cItem.id);
  261. if (index > -1) {
  262. _content[j].activeTime = this.checkUserList[index].activeTime;
  263. rowKeys.push(this.checkUserList[index].id);
  264. }
  265. }
  266. setTimeout(() => {
  267. this.$refs.userTable.setCheck(rowKeys);
  268. }, 500);
  269. }
  270. this.Usertotal = totalElements;
  271. const result = {
  272. data: {
  273. content: _content,
  274. totalElements
  275. }
  276. };
  277. return result;
  278. },
  279. handleSelectChange(selection) {
  280. this.selectUserList = this.$lodash.cloneDeep(selection);
  281. },
  282. handleSave() {
  283. if (!this.handleValid()) return;
  284. if (this.Usertotal == 0) {
  285. this.$message.warning("没有可保存的数据!");
  286. return;
  287. }
  288. const { roleId, orgId } = this.saveRoleAuthParams;
  289. const delUserIds = this.checkUserList
  290. .filter((item) => !this.selectUserList.map((sItem) => sItem.id).includes(item.id))
  291. .map((item) => item.id);
  292. const addUserIds = this.selectUserList
  293. .filter((item) => !this.checkUserList.map((cItem) => cItem.id).includes(item.id))
  294. .map((item) => item.id);
  295. // 剔除掉被删除的再过滤出修改过的,与check接口比较
  296. const updateUserIncludeDel = this.updateUsers.filter((item) => !delUserIds.includes(item.id));
  297. const updateUsers = updateUserIncludeDel
  298. .filter((item) => {
  299. const index = this.selectUserList.findIndex((sItem) => sItem.id == item.id);
  300. if (index > -1) {
  301. if (item.activeTime !== this.selectUserList[index].activeTime) {
  302. return item;
  303. }
  304. }
  305. })
  306. .map((item) => {
  307. return {
  308. id: item.id,
  309. activeTime: item.activeTime
  310. };
  311. });
  312. const saveParams = {
  313. roleId,
  314. orgId,
  315. addUserIds,
  316. delUserIds,
  317. updateUsers: updateUsers
  318. };
  319. // 保存
  320. roleAuthApi
  321. .savePersion(saveParams)
  322. .then(() => {
  323. this.$message.success('保存成功');
  324. })
  325. .catch((err) => {
  326. this.$message.error(err);
  327. });
  328. },
  329. // 有效期选择
  330. handleValidateChoose(row) {
  331. const that = this;
  332. const layer = that.$dgLayer({
  333. title: '有效期选择',
  334. area: ['540px', '300px'],
  335. shade: [0.4, '#FFF'],
  336. content: TermValid,
  337. props: {
  338. operatorRow: row
  339. },
  340. on: {
  341. success: function (res) {
  342. layer.closeAll(layer.dialogIndex);
  343. row.activeTime = res.activeTime;
  344. const index = that.updateUsers.findIndex((item) => item.id == res.id);
  345. if (index > -1) {
  346. that.updateUsers[index] = res;
  347. } else {
  348. that.updateUsers.push(res);
  349. }
  350. }
  351. }
  352. });
  353. }
  354. },
  355. // 创建组件时调用
  356. created() {}
  357. };
  358. </script>
  359. <style lang="scss" scoped>
  360. @import url('./index.scss');
  361. </style>