staffEdit.vue 20 KB

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