staffEdit.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <!--
  2. * @Author: your name
  3. * @Date: 2022-02-10 14:49:20
  4. * @LastEditTime: 2022-02-11 10:34:04
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 编辑职员
  7. * @FilePath: \Foshan4A4.0\src\views\staffManagement\compontents\staffEdit.vue
  8. -->
  9. <template>
  10. <div class="authorityPower">
  11. <!--编辑职员-->
  12. <div class="addApp-form">
  13. <div class="addApp-form-title flex">
  14. <div class="title">编辑职员</div>
  15. <div class="btn">
  16. <el-button @click="saveBtn('form')" type="primary">保存</el-button>
  17. </div>
  18. </div>
  19. <div class="addApp-form-content dialog-public-background">
  20. <el-form :inline="true" ref="form" :rules="rules" class="form" :model="form">
  21. <el-form-item prop="name" label="职员名称">
  22. <el-input placeholder="请输入职员名称" maxlength="32" v-model="form.name"></el-input>
  23. </el-form-item>
  24. <el-form-item prop="loginName" label="职员登录名">
  25. <el-input placeholder="请输入职员登录名" maxlength="32" v-model="form.loginName"></el-input>
  26. </el-form-item>
  27. <el-form-item style="margin-right: 16px" label="登录密码">
  28. <el-input placeholder="*******" disabled maxlength="32" v-model="form.loginPwd"></el-input>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button size="small" type="primary" @click="reSetPassWord">重置密码</el-button>
  32. </el-form-item>
  33. <el-form-item label="描述">
  34. <el-input style="width: 25.65vw" maxlength="200" placeholder="请输入描述" v-model="form.app"></el-input>
  35. </el-form-item>
  36. </el-form>
  37. </div>
  38. </div>
  39. <div class="power-content flex-wrap">
  40. <div class="r24 flex1 part">
  41. <Organization ref="Organization" :defaultProps="defaultProps" :mainData="mainData" :vice="true" :data="data" @getTreeData="getOrgan" @radioChange="radioChange" :checkedKeys="orgCheckedKeys" :radioCheck="radioNum" nodekey="OrganId" title="选择组织" />
  42. </div>
  43. <!--开启多对多-->
  44. <template v-if="OpenAuthData">
  45. <div class="flex1 part">
  46. <Rolelist @checkChange="accountChange" :checkBoxList="checkBoxList" :roleType="roleType" :active="true" class="hucRole" :number="4" title="账号列表" />
  47. </div>
  48. </template>
  49. <!--未开启多对多-->
  50. <template v-else>
  51. <!--有账号组 无角色-->
  52. <template v-if="OpenGroup && !openRole">
  53. <div class="r24 flex1 part">
  54. <Usergroup title="用户组树" />
  55. </div>
  56. <div class="r24 flex1 part">
  57. <Permissiontree ref="Permissiontree" :queryType="queryType" :queryId="treeId" :checkedKeys="checkedBoxs" :isMainJob="isMainJob" @nodeClick="nodeClick" @getTreeData="getTreeData" title="权限树" />
  58. </div>
  59. <div class="flex1 part">
  60. <Rulesofcompetency style="height: 512px" class="hucPower" :authList="authList" :authTo="authTo" @getData="getData" title="权限规则" />
  61. <Loginpolicy style="margin-top: 24px; height: calc(100% - 24px - 512px)" :imageSize="120" :checkedList="checkedList" @getCheckedList="getCheckedList" title="登录策略" />
  62. </div>
  63. </template>
  64. <!--有角色 无账号组-->
  65. <template v-if="openRole && !OpenGroup">
  66. <div class="r24 flex1 part">
  67. <Rolelist @checkChange="checkChange" @checkClick="checkClick" :checkBoxList="roleCheckBoxs" :dataList="arrs" :active="true" class="hucRole" :number="8" title="角色列表" />
  68. </div>
  69. <div class="flex1 part">
  70. <Permissionlist style="height: 376px" :imageSize="120" :RoleList="RoleList" :check="true" class="hucPower" title="权限列表" />
  71. <Loginpolicy style="margin-top: 24px; height: calc(100% - 24px - 376px)" :imageSize="120" :checkedList="checkedList" @getCheckedList="getCheckedList" title="登录策略" />
  72. </div>
  73. </template>
  74. <!--有角色 有账号组-->
  75. <template v-if="openRole && OpenGroup">
  76. <div class="r24 flex1 part">
  77. <Usergroup title="用户组树" />
  78. </div>
  79. <div class="r24 flex1 part">
  80. <Rolelist @checkChange="checkChange" @checkClick="checkClick" :checkBoxList="roleCheckBoxs" :dataList="arrs" :active="true" class="hucRole" :number="8" title="角色列表" />
  81. </div>
  82. <div class="flex1 part">
  83. <Permissionlist style="height: 376px" :imageSize="120" :RoleList="RoleList" :check="true" class="hucPower" title="权限列表" />
  84. <Loginpolicy style="margin-top: 24px; height: calc(100% - 24px - 376px)" :imageSize="120" :checkedList="checkedList" @getCheckedList="getCheckedList" title="登录策略" />
  85. </div>
  86. </template>
  87. <!--无账号组 无角色-->
  88. <template v-if="!OpenGroup && !openRole">
  89. <div class="r24 flex1 part">
  90. <Permissiontree ref="Permissiontree" :queryType="queryType" :queryId="treeId" :checkedKeys="checkedBoxs" :isMainJob="isMainJob" @nodeClick="nodeClick" @getTreeData="getTreeData" title="权限树" />
  91. </div>
  92. <div class="flex1 part">
  93. <Rulesofcompetency style="height: 512px" class="hucPower" :authList="authList" :authTo="authTo" @getData="getData" title="权限规则" />
  94. <Loginpolicy style="margin-top: 24px; height: calc(100% - 24px - 512px)" :imageSize="120" :checkedList="checkedList" @getCheckedList="getCheckedList" title="登录策略" />
  95. </div>
  96. </template>
  97. </template>
  98. </div>
  99. </div>
  100. </template>
  101. <script>
  102. import Permissiontree from "@/components/permissiontree";
  103. import Rulesofcompetency from "@/components/rulesofcompetency";
  104. import Organization from "@/components/organization";
  105. import Permissionlist from "@/components/permissionlist";
  106. import Rolelist from "@/components/rolelist";
  107. import Loginpolicy from "@/components/loginpolicy";
  108. import Usergroup from "@/components/usergrouptree";
  109. import treeData from "../minixs/treeData";
  110. import { mapGetters } from "vuex";
  111. import { RoleAuths } from "@/api/apiAuthority";
  112. import {
  113. newstaffmod,
  114. postList,
  115. organgitpost,
  116. jbdetpop,
  117. Staffdetails,
  118. } from "@/api/postInterface";
  119. import { pwdProduce } from "@/utils/validate";
  120. export default {
  121. name: "AuthorityPower",
  122. mixins: [treeData],
  123. components: {
  124. Rulesofcompetency,
  125. Organization,
  126. Permissiontree,
  127. Permissionlist,
  128. Rolelist,
  129. Loginpolicy,
  130. Usergroup
  131. },
  132. data () {
  133. return {
  134. Status: null,
  135. AppId: null,
  136. form: {
  137. //应用表单
  138. name: "",
  139. loginName: "",
  140. loginPwd: "",
  141. app: "",
  142. },
  143. title: "角色",
  144. rules: {
  145. //表单验证
  146. name: [{ required: true, message: "请输入职员名称", trigger: "blur" }],
  147. loginName: [
  148. { required: true, message: "请输入职员登录名", trigger: "blur" },
  149. ],
  150. loginPwd: [
  151. { required: true, message: "请输入职员登录密码", trigger: "blur" },
  152. ],
  153. },
  154. defaultProps: {
  155. children: "children",
  156. label: "OrganName",
  157. },
  158. treeId: null, //根据组织获取权限树的组织ID
  159. checkedKeys: [], //上级组织选中
  160. RoleList: [],
  161. checkedBoxs: [],
  162. arrs: [],
  163. authArrs: [],//
  164. OfficerId: null,
  165. authId: [], //权限树默认选中ID
  166. authList: [],
  167. authTo: {},
  168. orgTypes: [],
  169. checkBoxList: [], //副岗默认选中
  170. checkedList: [], //登录策略默认选中的数据
  171. radioCheck: null, //主岗默认选中
  172. radioNum: null, //主岗已选中
  173. roleDatas: [], //接口详情返回的角色列表数据
  174. roleCheckBoxs: [], //角色列表默认选中数据
  175. groupCheckBoxs: [], //权限组列表默认选中数据
  176. orgCheckedKeys: [], //组织树默认选中
  177. loginCheckBoxs: [], //登录策略数据
  178. mainData: [], //主岗数据
  179. JobId: "", //选中主岗ID
  180. DepJobIds: [],//选中副岗ID集合
  181. lessData: [], //副岗数据
  182. lessCheckBoxs: [], //副岗选中数据联合主岗
  183. lessChecksData: [], //副岗选中数据
  184. queryType: null, //权限树类型
  185. openRole: null,
  186. OpenGroup: null,
  187. OpenAuthData: null,
  188. roleType: '',
  189. dataObj: {}, //上级权限指定树数据
  190. data: [], //上级权限
  191. roleList: [], //角色
  192. checkRoles: [], //选中的角色
  193. checkTrees: [], //上级权限选中树数据
  194. rulesObj: {}, //权限规则数据
  195. isMainJob: true, //是否主岗
  196. oldOrganId: "",
  197. onCheckedArr: [],//当前显示选中权限组
  198. alljobArr: [],//全部岗位
  199. };
  200. },
  201. computed: {
  202. ...mapGetters(["systemSet"]),
  203. },
  204. watch: {
  205. //监听上级组织数据
  206. dataList: {
  207. handler (val) {
  208. this.data = [val];
  209. },
  210. deep: true,
  211. },
  212. mainData: {
  213. handler (arr) {
  214. if (this.radioCheck) {
  215. let ids = null;
  216. arr.forEach((item, index) => {
  217. if (item.JobId == this.radioCheck) {
  218. ids = index;
  219. }
  220. })
  221. this.radioNum = ids;
  222. }
  223. },
  224. deep: true,
  225. }
  226. },
  227. created () {
  228. const { OrganId, Status, OfficerId } = this.$route.query;
  229. const { OpenRole, PwdLengthBegin, PwdLengthEnd, PwdStruc, OpenGroup, UserOfficerMulti } =
  230. typeof this.systemSet === "string"
  231. ? JSON.parse(this.systemSet)
  232. : this.systemSet; //1是请求角色 0是请求用户
  233. // this.form.loginPwd = pwdProduce(PwdLengthBegin, PwdLengthEnd, PwdStruc);
  234. this.Status = Status;
  235. this.OfficerId = OfficerId;
  236. this.openRole = OpenRole;
  237. this.OpenGroup = OpenGroup;
  238. this.OpenAuthData = UserOfficerMulti;
  239. // if (!OpenRole) {
  240. // if (OrganId == -1) {
  241. // this.queryType = "all";
  242. // } else {
  243. // this.queryType = "origin";
  244. // }
  245. // }
  246. this.getOfficerDetails(OfficerId);
  247. },
  248. methods: {
  249. //职员详情查询
  250. async getOfficerDetails (id) {
  251. try {
  252. let params = {
  253. OfficerId: id,
  254. };
  255. const res = await Staffdetails(params);
  256. if (res.code === 0) {
  257. const obj = res.returnData;
  258. const {
  259. AuthList,
  260. DepJobList,
  261. JobId,
  262. OrganId,
  263. OfficerDesc,
  264. OfficerLoginName,
  265. OfficerName,
  266. RoleList,
  267. TacList,
  268. GroupList,
  269. UserList
  270. } = obj;
  271. this.form.name = OfficerName;
  272. this.form.loginName = OfficerLoginName;
  273. this.form.app = OfficerDesc;
  274. this.orgCheckedKeys = [OrganId];
  275. this.oldOrganId = OrganId;
  276. this.roleDatas = RoleList;
  277. this.radioCheck = JobId;
  278. this.JobId = JobId;
  279. this.lessChecksData = DepJobList;
  280. this.isMainJob = false;
  281. this.getJobListByOrgan(OrganId);
  282. if (this.OpenAuthData) {
  283. this.roleType = 'account';
  284. }
  285. if (AuthList && AuthList.length) {
  286. AuthList.forEach((item) => {
  287. this.authId.push(item.AuthId);
  288. });
  289. this.authList = _.cloneDeep(AuthList);
  290. this.authTo = AuthList[0];
  291. this.checkedBoxs = this.authId;
  292. }
  293. if (RoleList && RoleList.length) {
  294. const [checkRoles, checkBoxs] = [[], []];
  295. RoleList.forEach((item, index) => {
  296. if (item.IsSelected == 1) {
  297. checkRoles.push(item);
  298. checkBoxs.push(index);
  299. }
  300. });
  301. if (checkRoles.length && checkBoxs.length) {
  302. this.checkRoles = checkRoles;
  303. this.roleAuths(RoleList[0].RoleId);
  304. }
  305. }
  306. if (GroupList && GroupList.length) {
  307. const [checkRoles, checkBoxs] = [[], []];
  308. GroupList.forEach((item, index) => {
  309. if (item.IsSelected == 1) {
  310. checkRoles.push(item);
  311. checkBoxs.push(index);
  312. }
  313. });
  314. if (checkRoles.length && checkBoxs.length) {
  315. this.checkRoles = checkRoles;
  316. this.groupAuths(GroupList[0].GroupId);
  317. }
  318. }
  319. if (UserList && UserList.length) {
  320. const datas = [];
  321. UserList.forEach(item => {
  322. datas.push(item.UserId);
  323. })
  324. this.checkBoxList = datas;
  325. }
  326. this.checkedList = TacList;
  327. this.loginCheckBoxs = TacList;
  328. } else {
  329. this.$message.error(res.message);
  330. }
  331. } catch (error) {
  332. console.log("出错了", error);
  333. }
  334. },
  335. //获取选中的树数据
  336. getTreeData (arr) {
  337. this.checkTrees = arr;
  338. },
  339. // 默认选中
  340. defaultChecked (arr, id) {
  341. const datas = []
  342. this.onCheckedArr = [];
  343. arr.forEach((item, index) => {
  344. this.checkRoles.forEach(p => {
  345. if (item[id] == p[id]) {
  346. datas.push(index)
  347. this.onCheckedArr.push(item);
  348. }
  349. })
  350. })
  351. if (this.openRole) {
  352. this.roleCheckBoxs = datas;
  353. } else if (this.OpenGroup) {
  354. this.groupCheckBoxs = datas;
  355. }
  356. },
  357. //获取组织选中的数据
  358. getOrgan (arr) {
  359. const { OrganId } = arr[0];
  360. this.AppId = OrganId;
  361. this.getJobListByOrgan(OrganId);
  362. },
  363. //获取指定数据
  364. decompose (data, id) {
  365. for (let i = 0; i < data.length; i++) {
  366. if (data[i].OrganId == id) {
  367. this.dataObj = data[i];
  368. } else if (data[i].children && data[i].children.length > 0) {
  369. this.decompose(data[i].children, id);
  370. }
  371. }
  372. },
  373. //权限树点击
  374. nodeClick (obj) {
  375. const arr = this.$store.getters.authArrs;
  376. arr.push(obj);
  377. this.$store.dispatch("auth/changeAuthArrs", arr);
  378. },
  379. //根据主岗查询角色
  380. radioChange (val) {
  381. const { JobId } = this.mainData[val];
  382. this.JobId = JobId;
  383. this.radioCheck = null;
  384. },
  385. //根据岗位获取角色
  386. async getRoleByJob (id, index) {
  387. try {
  388. let params = {
  389. JobId: id,
  390. };
  391. const res = await jbdetpop(params);
  392. if (res.code === 0) {
  393. const datas = res.returnData;
  394. const arrs = [];
  395. datas.forEach((item) => {
  396. item.name = item.RoleName;
  397. if (item.IsSelected == 1) {
  398. arrs.push(item);
  399. }
  400. });
  401. if (index == 1) {
  402. this.arrs = arrs;
  403. this.lessCheckBoxs.push(arrs);
  404. } else if (index == 2) {
  405. if (arrs.length) {
  406. this.lessCheckBoxs.push(arrs);
  407. const msgs = this.lessCheckBoxs.flat();
  408. const uninqMsgs = _.unionBy(msgs, "RoleId");
  409. this.arrs = uninqMsgs;
  410. }
  411. }
  412. } else {
  413. this.$message.error(res.message);
  414. }
  415. } catch (error) {
  416. console.log("出错了", error);
  417. }
  418. },
  419. //根据组织查询岗位列表-主岗
  420. async getJobListByOrgan (id) {
  421. try {
  422. let params = {
  423. OrganId: id,
  424. };
  425. const res = await organgitpost(params);
  426. if (res.code === 0) {
  427. const datas = res.returnData;
  428. datas.forEach((item) => {
  429. item.name = item.JobName;
  430. });
  431. this.mainData = datas;
  432. } else {
  433. this.$message.error(res.message);
  434. }
  435. } catch (error) {
  436. console.log("出错了", error);
  437. }
  438. },
  439. //角色点击回调
  440. checkClick (item) {
  441. this.roleAuths(item.RoleId);
  442. },
  443. //账号组点击回调
  444. checkGroup (item) {
  445. this.groupAuths(item.GroupId)
  446. },
  447. //根据角色查看权限列表
  448. async roleAuths (id) {
  449. try {
  450. let params = {
  451. RoleId: id,
  452. };
  453. const res = await RoleAuths(params);
  454. if (res.code === 0) {
  455. this.RoleList = res.returnData;
  456. } else {
  457. this.$message.error(res.message);
  458. }
  459. } catch (error) {
  460. console.log("出错了", error);
  461. }
  462. },
  463. //账号列表选取
  464. accountChange (arr) {
  465. this.checkBoxList = arr;
  466. },
  467. //角色选取
  468. checkChange (arr) {
  469. const datas = [];
  470. for (let i = 0; i < arr.length; i++) {
  471. if (this.openRole) {
  472. datas.push(this.arrs[arr[i]]);
  473. }
  474. else {
  475. datas.push(this.authArrs[arr[i]]);
  476. }
  477. }
  478. this.checkRoles = datas;
  479. this.onCheckedArr = datas;
  480. },
  481. //获取权限规则
  482. getData (obj) {
  483. this.rulesObj = obj;
  484. },
  485. //获取登录策略回调
  486. getCheckedList (arr) {
  487. this.loginCheckBoxs = arr;
  488. },
  489. //保存
  490. saveBtn (formName) {
  491. this.$refs[formName].validate((valid) => {
  492. if (valid) {
  493. this.saveOrgan();
  494. } else {
  495. console.log("error submit!!");
  496. return false;
  497. }
  498. });
  499. },
  500. //组织新增保存
  501. async saveOrgan () {
  502. try {
  503. if (this.JobId) {
  504. if (!this.AppId) {
  505. this.$message.error("请选中一个组织后再新增");
  506. return false;
  507. }
  508. } else {
  509. this.AppId = this.oldOrganId
  510. }
  511. const datas = [];
  512. const checks = [];
  513. this.checkTrees.forEach((item) => {
  514. datas.push(item.AuthList);
  515. });
  516. if (this.OpenGroup && !this.openRole) {
  517. this.checkRoles = this.onCheckedArr;
  518. }
  519. this.checkRoles.forEach(item => {
  520. if (item) {
  521. checks.push(item);
  522. }
  523. });
  524. const res = await newstaffmod({
  525. OfficerName: this.form.name,
  526. OfficerDesc: this.form.app,
  527. OfficerLoginName: this.form.loginName,
  528. OfficerPwd: this.form.loginPwd,
  529. RoleList: this.openRole ? checks : [],
  530. AuthList: this.openRole ? [] : datas,
  531. TacList: this.loginCheckBoxs,
  532. DepJobList: this.lessChecksData,
  533. GroupList: this.OpenGroup ? checks : [],
  534. JobId: this.JobId,
  535. Status: Number(this.Status),
  536. OrganId: this.AppId,
  537. OfficerId: this.OfficerId,
  538. UserList: this.checkBoxList
  539. });
  540. if (res.code === 0) {
  541. this.$message.success(res.message);
  542. this.$store.dispatch("tagsView/delView", this.$route);
  543. this.$router.push("/staff");
  544. } else {
  545. this.$message.error(res.message);
  546. }
  547. } catch (error) {
  548. console.log("出错了", error);
  549. }
  550. },
  551. reSetPassWord () {
  552. const { PwdLengthBegin, PwdLengthEnd, PwdStruc } =
  553. typeof this.systemSet === "string"
  554. ? JSON.parse(this.systemSet)
  555. : this.systemSet; //1是请求角色 0是请求用户
  556. this.form.loginPwd = pwdProduce(PwdLengthBegin, PwdLengthEnd, PwdStruc);
  557. },
  558. }
  559. }
  560. </script>
  561. <style lang="scss" scoped>
  562. .authorityPower {
  563. padding: 0 64px;
  564. padding-top: 32px;
  565. }
  566. .addApp-form {
  567. background: #ffffff;
  568. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  569. border-radius: 16px;
  570. padding: 32px 32px 40px 32px;
  571. .title {
  572. font-size: 24px;
  573. font-family: Microsoft YaHei;
  574. font-weight: bold;
  575. color: #303133;
  576. .isqy {
  577. span {
  578. font-weight: 400;
  579. font-size: 14px;
  580. margin: 0 28px 0 42px;
  581. }
  582. }
  583. }
  584. .addApp-form-content {
  585. margin-top: 40px;
  586. ::v-deep .form {
  587. .el-form-item {
  588. margin-bottom: 0;
  589. margin-right: 40px;
  590. &:last-child {
  591. margin-right: 0;
  592. }
  593. }
  594. .el-input__inner {
  595. height: 32px;
  596. line-height: 32px;
  597. min-width: 184px;
  598. }
  599. .content {
  600. .el-form-item__content {
  601. flex: 1;
  602. }
  603. .el-form-item__label {
  604. margin-left: 27px;
  605. }
  606. }
  607. }
  608. }
  609. }
  610. .power-content {
  611. margin-top: 24px;
  612. min-height: 68vh;
  613. .part {
  614. height: 750px;
  615. }
  616. }
  617. </style>