roleView.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. persionListData: [],
  144. userCondition: {
  145. roleId: {
  146. value: '',
  147. op: '='
  148. },
  149. orgId: {
  150. value: '',
  151. op: '='
  152. },
  153. name: {
  154. value: '',
  155. op: 'like'
  156. }
  157. },
  158. userTableUrl: roleAuthApi.userTableUrl,
  159. checkUserList: [],
  160. deleteIds: [],
  161. // 点击动作object
  162. saveRoleAuthParams: {
  163. appId: '', // 应用id
  164. orgId: '', // 机构id
  165. roleId: '', // 角色id
  166. appOrgId: '', // 应用绑定的机构id
  167. staffList: '',
  168. staffJson: '',
  169. delStaffJson: ''
  170. },
  171. page: 0,
  172. size: 10,
  173. total: 0,
  174. updateUsers: []
  175. };
  176. },
  177. // 计算属性
  178. computed: {},
  179. // 方法
  180. methods: {
  181. receviceOpt(opt, row) {
  182. if (opt == '保存') {
  183. this.handleSave();
  184. }
  185. },
  186. getCurrentApp(item) {
  187. this.currentAppItem = item;
  188. },
  189. receiveRoleSearch(val) {
  190. this.roleCondition = val;
  191. this.handleSearch();
  192. this.saveRoleAuthParams.appOrgId = this.currentAppItem.appOrgId;
  193. this.saveRoleAuthParams.appId = this.currentAppItem.id;
  194. },
  195. receiveUserDefaultCondition(val) {
  196. for (const key in val) {
  197. this.userCondition[key].value = val[key].value;
  198. }
  199. this.saveRoleAuthParams.orgId = this.userCondition.orgId.value;
  200. },
  201. loadUserTable() {
  202. this.selectUserList = [];
  203. this.$refs.userTable.searchForm();
  204. },
  205. receiveUserSearch(val) {
  206. for (const key in val) {
  207. this.userCondition[key].value = val[key].value;
  208. }
  209. this.saveRoleAuthParams.orgId = this.userCondition.orgId.value;
  210. if (!this.handleValid()) return;
  211. this.loadUserTable();
  212. },
  213. async handleRoleRowClick({ id, appId }) {
  214. this.saveRoleAuthParams.roleId = this.userCondition.roleId.value = id;
  215. this.saveRoleAuthParams.appId = appId;
  216. this.$refs.userTable.clearAll();
  217. await this.getUserChecked();
  218. this.loadUserTable();
  219. },
  220. getUserChecked() {
  221. return new Promise((resolve) => {
  222. const { orgId, roleId, appId } = this.saveRoleAuthParams;
  223. // 获取人员列表选中记录
  224. const queryCheckedParams = {
  225. orgId,
  226. roleId,
  227. appId,
  228. type: 'role'
  229. };
  230. roleAuthApi.getChecked(queryCheckedParams).then((res) => {
  231. this.checkUserList = res;
  232. resolve(res);
  233. });
  234. });
  235. },
  236. handleValid() {
  237. if (!this.saveRoleAuthParams.roleId) {
  238. this.$message.warning('请选择角色!');
  239. return false;
  240. }
  241. if (!this.saveRoleAuthParams.orgId) {
  242. this.$message.warning('请选择单位名称!');
  243. return false;
  244. }
  245. return true;
  246. },
  247. // 用户列表数据渲染前整合数据
  248. handleBeforeQuest(res) {
  249. const { content, totalElements } = res.data;
  250. let _content = content.map((item) => {
  251. return {
  252. ...item,
  253. activeTime: '长期'
  254. };
  255. });
  256. this.currentPageContent = _content;
  257. if (this.checkUserList.length > 0) {
  258. let rowKeys = [];
  259. for (let j = 0; j < _content.length; j++) {
  260. const cItem = _content[j];
  261. const index = this.checkUserList.findIndex((item) => item.id == cItem.id);
  262. if (index > -1) {
  263. _content[j].activeTime = this.checkUserList[index].activeTime;
  264. rowKeys.push(this.checkUserList[index].id);
  265. }
  266. }
  267. setTimeout(() => {
  268. this.$refs.userTable.setCheck(rowKeys);
  269. }, 500);
  270. }
  271. this.Usertotal = totalElements;
  272. const result = {
  273. data: {
  274. content: _content,
  275. totalElements
  276. }
  277. };
  278. return result;
  279. },
  280. handleSelectChange(selection) {
  281. this.selectUserList = this.$lodash.cloneDeep(selection);
  282. },
  283. handleSave() {
  284. if (!this.handleValid()) return;
  285. if (this.Usertotal == 0) {
  286. this.$message.warning("没有可保存的数据!");
  287. return;
  288. }
  289. const { roleId, orgId } = this.saveRoleAuthParams;
  290. const delUserIds = this.checkUserList
  291. .filter((item) => !this.selectUserList.map((sItem) => sItem.id).includes(item.id))
  292. .map((item) => item.id);
  293. const addUserIds = this.selectUserList
  294. .filter((item) => !this.checkUserList.map((cItem) => cItem.id).includes(item.id))
  295. .map((item) => item.id);
  296. // 剔除掉被删除的再过滤出修改过的,与check接口比较
  297. const updateUserIncludeDel = this.updateUsers.filter((item) => !delUserIds.includes(item.id));
  298. const updateUsers = updateUserIncludeDel
  299. .filter((item) => {
  300. const index = this.selectUserList.findIndex((sItem) => sItem.id == item.id);
  301. if (index > -1) {
  302. if (item.activeTime !== this.selectUserList[index].activeTime) {
  303. return item;
  304. }
  305. }
  306. })
  307. .map((item) => {
  308. return {
  309. id: item.id,
  310. activeTime: item.activeTime
  311. };
  312. });
  313. const saveParams = {
  314. roleId,
  315. orgId,
  316. addUserIds,
  317. delUserIds,
  318. updateUsers: updateUsers
  319. };
  320. // 保存
  321. roleAuthApi
  322. .savePersion(saveParams)
  323. .then(() => {
  324. this.$message.success('保存成功');
  325. })
  326. .catch((err) => {
  327. this.$message.error(err);
  328. });
  329. },
  330. // 有效期选择
  331. handleValidateChoose(row) {
  332. const that = this;
  333. const layer = that.$dgLayer({
  334. title: '有效期选择',
  335. area: ['540px', '300px'],
  336. shade: [0.4, '#FFF'],
  337. content: TermValid,
  338. props: {
  339. operatorRow: row
  340. },
  341. on: {
  342. success: function (res) {
  343. layer.closeAll(layer.dialogIndex);
  344. row.activeTime = res.activeTime;
  345. const index = that.updateUsers.findIndex((item) => item.id == res.id);
  346. if (index > -1) {
  347. that.updateUsers[index] = res;
  348. } else {
  349. that.updateUsers.push(res);
  350. }
  351. }
  352. }
  353. });
  354. }
  355. },
  356. // 创建组件时调用
  357. created() {}
  358. };
  359. </script>
  360. <style lang="scss" scoped>
  361. @import url('./index.scss');
  362. </style>