authorityPowerEdit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 11:26:07
  4. * @LastEditTime: 2022-03-17 12:05:58
  5. * @LastEditors: your name
  6. * @Description:权限项
  7. * @FilePath: \Foshan4A2.0\src\views\authorityManagement\components\authorityPower.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">
  15. 编辑权限项
  16. <!-- <span class="isqy">
  17. <span>是否启用</span>
  18. <el-radio v-model="radio" :label="1">是</el-radio>
  19. <el-radio v-model="radio" :label="0">否</el-radio>
  20. </span> -->
  21. </div>
  22. <div v-is="['appupdate_box_save']" class="btn">
  23. <!-- <el-button @click="deleteAuth" class="r24" type="danger">删除</el-button> -->
  24. <el-button @click="saveBtn('form')" type="primary">保存</el-button>
  25. </div>
  26. </div>
  27. <div class="addApp-form-content dialog-public-background">
  28. <el-form :inline="true" ref="form" :rules="rules" class="form" :model="form">
  29. <el-form-item prop="name" label="权限项名称">
  30. <el-input placeholder="请输入权限项名称" v-model.trim="form.name"></el-input>
  31. </el-form-item>
  32. <el-form-item prop="id" label="标识符">
  33. <el-input placeholder="请输入标识符" v-model.trim="form.id"></el-input>
  34. </el-form-item>
  35. <el-form-item prop="desc" label="描述">
  36. <el-input style="width: 640px" placeholder="请输入描述" v-model.trim="form.desc"></el-input>
  37. </el-form-item>
  38. </el-form>
  39. </div>
  40. </div>
  41. <div class="power-content flex-wrap">
  42. <div :class="!openRole && !OpenGroup ? '' : 'r24'" class="flex1 part">
  43. <Organization :defaultProps="defaultProps" :checkedKeys="checkedKeys" @getTreeData="getTreeData" :orgType="orgType" :orgList="orgList" :data="data" nodekey="AuthId" title="上级权限项" />
  44. </div>
  45. <!--有角色-->
  46. <template v-if="openRole">
  47. <div class="r24 flex1 part">
  48. <Rulesofcompetency :disabled="disabled" @getData="getData" :authTo="authTo" title="权限规则" />
  49. </div>
  50. <div v-is="['appupdate_edit_card']" class="flex1 part">
  51. <Rolelist @checkChange="checkChange" :roleType="roleType" needType="1" :checkBoxList="checkBoxList" :number="8" title="角色" />
  52. </div>
  53. </template>
  54. <!--有岗位-->
  55. <template v-else-if="OpenGroup">
  56. <div class="r24 flex1 part">
  57. <Rulesofcompetency :disabled="disabled" @getData="getData" :authTo="authTo" title="权限规则" />
  58. </div>
  59. <div v-is="['appupdate_edit_card']" class="flex1 part">
  60. <Rolelist @checkChange="checkChange" :roleType="roleType" :checkBoxList="checkBoxList" :number="8" title="账号授权" />
  61. </div>
  62. </template>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import Rolelist from "@/components/rolelist";
  68. import Rulesofcompetency from "@/components/rulesofcompetency";
  69. import Organization from "@/components/organization";
  70. import {
  71. GetAuthDetails,
  72. QueryRole,
  73. GetUserList,
  74. EditAuth,
  75. DeleteAuth,
  76. } from "@/api/apiAuthority";
  77. import treeData from "../minixs/treeData";
  78. import { mapGetters } from "vuex";
  79. import { lengthValidator } from '@/utils/validate';
  80. export default {
  81. name: "AuthorityPower",
  82. components: { Rolelist, Rulesofcompetency, Organization },
  83. mixins: [treeData],
  84. data () {
  85. return {
  86. radio: 1,
  87. form: {
  88. //应用表单
  89. name: "",
  90. id: "",
  91. desc: "",
  92. },
  93. rules: {
  94. //表单验证
  95. name: [
  96. { required: true, message: "请输入权限项名称", trigger: "blur" },
  97. { validator: lengthValidator, max: 128, message: '长度在 1 到 128 个字符', trigger: ['change', 'blur'] }
  98. ],
  99. id: [
  100. { required: true, message: "请输入标识符", trigger: "blur" },
  101. { validator: lengthValidator, max: 32, message: '长度在 1 到 32 个字符', trigger: ['change', 'blur'] }
  102. ],
  103. desc: [
  104. { validator: lengthValidator, max: 256, message: '长度在 1 到 256 个字符', trigger: ['change', 'blur'] }
  105. ]
  106. },
  107. defaultProps: {
  108. children: "children",
  109. label: "AuthName",
  110. },
  111. AppId: null, //参数类型
  112. UpAuthId: null,
  113. data: [],
  114. openRole: null,
  115. OpenGroup: null,
  116. roleList: [],
  117. title: "角色",
  118. editRoles: [],
  119. checkBoxList: [],
  120. authTo: {},
  121. rulesObj: {},
  122. msgDatas: [],
  123. roleType: '',
  124. orgType: '',
  125. checkedKeys: [],
  126. disabled: true,
  127. orgList: []
  128. };
  129. },
  130. computed: {
  131. ...mapGetters(["systemSet"]),
  132. },
  133. watch: {
  134. dataList: {
  135. handler (val) {
  136. const arr = [val];
  137. this.decompose(arr, this.UpAuthId);
  138. this.dataObj.disabled = true
  139. this.data = [this.dataObj];
  140. this.checkedKeys = [this.UpAuthId];
  141. },
  142. deep: true,
  143. },
  144. },
  145. created () {
  146. const { AuthId, Status, UpAuthId } = this.$route.query;
  147. const { OpenRole, OpenGroup } =
  148. typeof this.systemSet === "string"
  149. ? JSON.parse(this.systemSet)
  150. : this.systemSet; //1是请求角色 0是请求用户
  151. this.radio = Status;
  152. this.AppId = AuthId;
  153. this.UpAuthId = UpAuthId;
  154. this.openRole = OpenRole;
  155. this.OpenGroup = OpenGroup;
  156. this.getAuthTree();
  157. this.getAuthDetails(AuthId);
  158. },
  159. mounted () {
  160. if (this.openRole) {
  161. this.roleType = 'onlyRole';
  162. } else if (this.OpenGroup) {
  163. this.roleType = 'account';
  164. }
  165. this.orgType = 'auth';
  166. },
  167. methods: {
  168. //获取指定数据
  169. decompose (data, id) {
  170. for (let i = 0; i < data.length; i++) {
  171. if (data[i].AuthId == id) {
  172. this.dataObj = data[i];
  173. delete this.dataObj.children;
  174. } else if (data[i].children && data[i].children.length > 0) {
  175. this.decompose(data[i].children, id);
  176. }
  177. }
  178. },
  179. //保存
  180. saveBtn (formName) {
  181. this.$refs[formName].validate((valid) => {
  182. if (valid) {
  183. this.editAuth();
  184. } else {
  185. console.log("error submit!!");
  186. return false;
  187. }
  188. });
  189. },
  190. //获取权限树回调
  191. getTreeData (arr) {
  192. const { AuthId, UpAuthId } = arr[0];
  193. this.AppId = AuthId;
  194. this.UpAuthId = UpAuthId;
  195. },
  196. //获取权限规则
  197. getData (obj) {
  198. this.rulesObj = obj;
  199. },
  200. //获取应用详情
  201. async getAuthDetails (id) {
  202. try {
  203. const res = await GetAuthDetails({
  204. AuthId: id,
  205. });
  206. if (res.code === 0) {
  207. const {
  208. AuthDesc,
  209. AuthName,
  210. AuthIdent,
  211. RoleInfo,
  212. AuthTo,
  213. UserInfo,
  214. AuthStatus,
  215. } = res.returnData;
  216. this.form.name = AuthName;
  217. this.form.id = AuthIdent;
  218. this.form.desc = AuthDesc;
  219. this.radio = AuthStatus;
  220. if (AuthTo) {
  221. this.authTo = AuthTo;
  222. this.$store.dispatch("auth/changeAuthId", AuthTo.AuthId);
  223. this.$store.dispatch("auth/changeAuthArrs", [AuthTo]);
  224. }
  225. if (this.openRole) {
  226. if (RoleInfo && RoleInfo.length) {
  227. RoleInfo.forEach((item) => {
  228. if (item.IsSelected) {
  229. this.msgDatas.push(item);
  230. if (this.disabled) {
  231. this.disabled = false
  232. }
  233. }
  234. });
  235. this.checkBoxList = this.msgDatas;
  236. } else {
  237. this.msgDatas = [];
  238. }
  239. } else if (this.OpenGroup) {
  240. if (UserInfo && UserInfo.length) {
  241. UserInfo.forEach((item) => {
  242. if (item.IsSelected) {
  243. this.msgDatas.push(item);
  244. }
  245. });
  246. this.checkBoxList = this.msgDatas;
  247. } else {
  248. this.msgDatas = [];
  249. }
  250. }
  251. } else {
  252. this.$message.error(res.message);
  253. }
  254. } catch (error) {
  255. console.log("出错了", error);
  256. }
  257. },
  258. //角色列表
  259. async queryRole () {
  260. try {
  261. const res = await QueryRole({
  262. QueryName: "",
  263. });
  264. if (res.code === 0) {
  265. const arr = res.returnData;
  266. arr.forEach((item) => {
  267. item.name = item.RoleName;
  268. });
  269. this.roleList = arr;
  270. } else {
  271. this.$message.error(res.message);
  272. }
  273. } catch (error) {
  274. console.log("出错了", error);
  275. }
  276. },
  277. //账号列表
  278. async getUserList () {
  279. try {
  280. const res = await GetUserList({
  281. QueryName: "",
  282. });
  283. if (res.code === 0) {
  284. const arr = res.returnData;
  285. arr.forEach((item) => {
  286. item.name = item.UserName;
  287. });
  288. this.roleList = arr;
  289. } else {
  290. this.$message.error(res.message);
  291. }
  292. } catch (error) {
  293. console.log("出错了", error);
  294. }
  295. },
  296. //角色选取
  297. checkChange (arr) {
  298. this.msgDatas = arr;
  299. if (arr.length) {
  300. this.disabled = false
  301. } else {
  302. this.disabled = true
  303. }
  304. },
  305. //权限新增保存
  306. async editAuth () {
  307. try {
  308. const datas = this.msgDatas;
  309. if (datas && datas.length) {
  310. datas.forEach((item) => {
  311. item.IsSelected = 1;
  312. });
  313. }
  314. // const rulesKeys = Object.keys(this.rulesObj);
  315. // if (rulesKeys.length && !datas.length) {
  316. // this.$message.error('请选中数据后再提交当前规则');
  317. // return;
  318. // }
  319. const res = await EditAuth({
  320. AuthName: this.form.name,
  321. AuthIdent: this.form.id,
  322. AuthDesc: this.form.desc,
  323. UpAuthId: this.UpAuthId,
  324. AuthId: this.AppId,
  325. RoleInfo: this.openRole ? datas : [],
  326. UserInfo: this.openRole ? [] : datas,
  327. AuthTo: this.rulesObj,
  328. AuthStatus: this.radio,
  329. });
  330. if (res.code === 0) {
  331. this.$message.success(res.message);
  332. this.$store.dispatch("tagsView/delView", this.$route);
  333. this.$router.push("/authority");
  334. } else {
  335. this.$message.error(res.message);
  336. }
  337. } catch (error) {
  338. console.log("出错了", error);
  339. }
  340. },
  341. //删除权限
  342. async deleteAuth () {
  343. try {
  344. const res = await DeleteAuth({
  345. AuthId: this.AppId,
  346. });
  347. if (res.code === 0) {
  348. this.$message.success(res.message);
  349. setTimeout(() => {
  350. this.$router.push("/authority");
  351. }, 2000);
  352. } else {
  353. this.$message.error(res.message);
  354. }
  355. } catch (error) {
  356. console.log("出错了", error);
  357. }
  358. },
  359. },
  360. };
  361. </script>
  362. <style lang="scss" scoped>
  363. .authorityPower {
  364. padding: 0 64px;
  365. padding-top: 32px;
  366. }
  367. .addApp-form {
  368. background: #ffffff;
  369. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  370. border-radius: 16px;
  371. padding: 32px 32px 40px 32px;
  372. .title {
  373. font-size: 24px;
  374. font-family: Microsoft YaHei;
  375. font-weight: bold;
  376. color: #303133;
  377. .isqy {
  378. span {
  379. font-weight: 400;
  380. font-size: 14px;
  381. margin: 0 28px 0 42px;
  382. }
  383. }
  384. }
  385. .addApp-form-content {
  386. margin-top: 40px;
  387. ::v-deep .form {
  388. .el-form-item {
  389. margin-bottom: 0;
  390. margin-right: 40px;
  391. }
  392. .el-input__inner {
  393. height: 32px;
  394. line-height: 32px;
  395. min-width: 184px;
  396. }
  397. .content {
  398. .el-form-item__content {
  399. flex: 1;
  400. }
  401. .el-form-item__label {
  402. margin-left: 27px;
  403. }
  404. }
  405. }
  406. }
  407. }
  408. .power-content {
  409. margin-top: 24px;
  410. .part {
  411. height: 704px;
  412. }
  413. }
  414. </style>