authorityPowerEdit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 11:26:07
  4. * @LastEditTime: 2022-03-16 15:15:12
  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" :data="data" nodekey="AuthId" title="上级权限项" />
  44. </div>
  45. <!--有角色-->
  46. <template v-if="openRole">
  47. <div class="r24 flex1 part">
  48. <Rulesofcompetency @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 @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: 32, message: '长度在 1 到 32 个字符', 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: 128, message: '长度在 1 到 128 个字符', 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. };
  127. },
  128. computed: {
  129. ...mapGetters(["systemSet"]),
  130. },
  131. watch: {
  132. dataList: {
  133. handler (val) {
  134. const arr = [val];
  135. this.decompose(arr, this.UpAuthId);
  136. this.data = [this.dataObj];
  137. this.checkedKeys = [this.UpAuthId];
  138. },
  139. deep: true,
  140. },
  141. },
  142. created () {
  143. const { AuthId, Status, UpAuthId } = this.$route.query;
  144. const { OpenRole, OpenGroup } =
  145. typeof this.systemSet === "string"
  146. ? JSON.parse(this.systemSet)
  147. : this.systemSet; //1是请求角色 0是请求用户
  148. this.radio = Status;
  149. this.AppId = AuthId;
  150. this.UpAuthId = UpAuthId;
  151. this.openRole = OpenRole;
  152. this.OpenGroup = OpenGroup;
  153. this.getAuthTree();
  154. this.getAuthDetails(AuthId);
  155. },
  156. mounted () {
  157. if (this.openRole) {
  158. this.roleType = 'onlyRole';
  159. } else if (this.OpenGroup) {
  160. this.roleType = 'account';
  161. }
  162. this.orgType = 'auth';
  163. },
  164. methods: {
  165. //获取指定数据
  166. decompose (data, id) {
  167. for (let i = 0; i < data.length; i++) {
  168. if (data[i].AuthId == id) {
  169. this.dataObj = data[i];
  170. delete this.dataObj.children;
  171. } else if (data[i].children && data[i].children.length > 0) {
  172. this.decompose(data[i].children, id);
  173. }
  174. }
  175. },
  176. //保存
  177. saveBtn (formName) {
  178. this.$refs[formName].validate((valid) => {
  179. if (valid) {
  180. this.editAuth();
  181. } else {
  182. console.log("error submit!!");
  183. return false;
  184. }
  185. });
  186. },
  187. //获取权限树回调
  188. getTreeData (arr) {
  189. const { AuthId, UpAuthId } = arr[0];
  190. this.AppId = AuthId;
  191. this.UpAuthId = UpAuthId;
  192. },
  193. //获取权限规则
  194. getData (obj) {
  195. this.rulesObj = obj;
  196. },
  197. //获取应用详情
  198. async getAuthDetails (id) {
  199. try {
  200. const res = await GetAuthDetails({
  201. AuthId: id,
  202. });
  203. if (res.code === 0) {
  204. const {
  205. AuthDesc,
  206. AuthName,
  207. AuthIdent,
  208. RoleInfo,
  209. AuthTo,
  210. UserInfo,
  211. AuthStatus,
  212. } = res.returnData;
  213. this.form.name = AuthName;
  214. this.form.id = AuthIdent;
  215. this.form.desc = AuthDesc;
  216. this.radio = AuthStatus;
  217. if (AuthTo) {
  218. this.authTo = AuthTo;
  219. this.$store.dispatch("auth/changeAuthId", AuthTo.AuthId);
  220. this.$store.dispatch("auth/changeAuthArrs", [AuthTo]);
  221. }
  222. if (this.openRole) {
  223. if (RoleInfo && RoleInfo.length) {
  224. RoleInfo.forEach((item) => {
  225. if (item.IsSelected) {
  226. this.msgDatas.push(item);
  227. }
  228. });
  229. this.checkBoxList = this.msgDatas;
  230. } else {
  231. this.msgDatas = [];
  232. }
  233. } else if (this.OpenGroup) {
  234. if (UserInfo && UserInfo.length) {
  235. UserInfo.forEach((item) => {
  236. if (item.IsSelected) {
  237. this.msgDatas.push(item);
  238. }
  239. });
  240. this.checkBoxList = this.msgDatas;
  241. } else {
  242. this.msgDatas = [];
  243. }
  244. }
  245. } else {
  246. this.$message.error(res.message);
  247. }
  248. } catch (error) {
  249. console.log("出错了", error);
  250. }
  251. },
  252. //角色列表
  253. async queryRole () {
  254. try {
  255. const res = await QueryRole({
  256. QueryName: "",
  257. });
  258. if (res.code === 0) {
  259. const arr = res.returnData;
  260. arr.forEach((item) => {
  261. item.name = item.RoleName;
  262. });
  263. this.roleList = arr;
  264. } else {
  265. this.$message.error(res.message);
  266. }
  267. } catch (error) {
  268. console.log("出错了", error);
  269. }
  270. },
  271. //账号列表
  272. async getUserList () {
  273. try {
  274. const res = await GetUserList({
  275. QueryName: "",
  276. });
  277. if (res.code === 0) {
  278. const arr = res.returnData;
  279. arr.forEach((item) => {
  280. item.name = item.UserName;
  281. });
  282. this.roleList = arr;
  283. } else {
  284. this.$message.error(res.message);
  285. }
  286. } catch (error) {
  287. console.log("出错了", error);
  288. }
  289. },
  290. //角色选取
  291. checkChange (arr) {
  292. this.msgDatas = arr;
  293. },
  294. //权限新增保存
  295. async editAuth () {
  296. try {
  297. const datas = this.msgDatas;
  298. if (datas && datas.length) {
  299. datas.forEach((item) => {
  300. item.IsSelected = 1;
  301. });
  302. }
  303. const rulesKeys = Object.keys(this.rulesObj);
  304. if (rulesKeys.length && !datas.length) {
  305. this.$message.error('请选中数据后再提交当前规则');
  306. return;
  307. }
  308. const res = await EditAuth({
  309. AuthName: this.form.name,
  310. AuthIdent: this.form.id,
  311. AuthDesc: this.form.desc,
  312. UpAuthId: this.UpAuthId,
  313. AuthId: this.AppId,
  314. RoleInfo: this.openRole ? datas : [],
  315. UserInfo: this.openRole ? [] : datas,
  316. AuthTo: this.rulesObj,
  317. AuthStatus: this.radio,
  318. });
  319. if (res.code === 0) {
  320. this.$message.success(res.message);
  321. this.$store.dispatch("tagsView/delView", this.$route);
  322. this.$router.push("/authority");
  323. } else {
  324. this.$message.error(res.message);
  325. }
  326. } catch (error) {
  327. console.log("出错了", error);
  328. }
  329. },
  330. //删除权限
  331. async deleteAuth () {
  332. try {
  333. const res = await DeleteAuth({
  334. AuthId: this.AppId,
  335. });
  336. if (res.code === 0) {
  337. this.$message.success(res.message);
  338. setTimeout(() => {
  339. this.$router.push("/authority");
  340. }, 2000);
  341. } else {
  342. this.$message.error(res.message);
  343. }
  344. } catch (error) {
  345. console.log("出错了", error);
  346. }
  347. },
  348. },
  349. };
  350. </script>
  351. <style lang="scss" scoped>
  352. .authorityPower {
  353. padding: 0 64px;
  354. padding-top: 32px;
  355. }
  356. .addApp-form {
  357. background: #ffffff;
  358. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  359. border-radius: 16px;
  360. padding: 32px 32px 40px 32px;
  361. .title {
  362. font-size: 24px;
  363. font-family: Microsoft YaHei;
  364. font-weight: bold;
  365. color: #303133;
  366. .isqy {
  367. span {
  368. font-weight: 400;
  369. font-size: 14px;
  370. margin: 0 28px 0 42px;
  371. }
  372. }
  373. }
  374. .addApp-form-content {
  375. margin-top: 40px;
  376. ::v-deep .form {
  377. .el-form-item {
  378. margin-bottom: 0;
  379. margin-right: 40px;
  380. }
  381. .el-input__inner {
  382. height: 32px;
  383. line-height: 32px;
  384. min-width: 184px;
  385. }
  386. .content {
  387. .el-form-item__content {
  388. flex: 1;
  389. }
  390. .el-form-item__label {
  391. margin-left: 27px;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. .power-content {
  398. margin-top: 24px;
  399. .part {
  400. height: 704px;
  401. }
  402. }
  403. </style>