authorityPowerEdit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 11:26:07
  4. * @LastEditTime: 2022-03-02 18:22:02
  5. * @LastEditors: Please set LastEditors
  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="manageTitle">
  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')" size="small" 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="form.name"></el-input>
  31. </el-form-item>
  32. <el-form-item prop="id" label="标识符">
  33. <el-input placeholder="请输入标识符" v-model="form.id"></el-input>
  34. </el-form-item>
  35. <el-form-item label="描述">
  36. <el-input style="width: 640px" maxlength="200" placeholder="请输入描述" v-model="form.app"></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="isClass ? '' :'r24'" class="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" :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 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 { checkPermission } from '@/utils/add-is-class';
  71. import {
  72. GetAuthDetails,
  73. QueryRole,
  74. GetUserList,
  75. EditAuth,
  76. DeleteAuth,
  77. } from "@/api/apiAuthority";
  78. import treeData from "../minixs/treeData";
  79. import { mapGetters } from "vuex";
  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. app: "",
  92. },
  93. rules: {
  94. //表单验证
  95. name: [
  96. { required: true, message: "请输入权限项名称", trigger: "blur" },
  97. ],
  98. id: [{ required: true, message: "请输入标识符", trigger: "blur" }],
  99. },
  100. defaultProps: {
  101. children: "children",
  102. label: "AuthName",
  103. },
  104. AppId: null, //参数类型
  105. UpAuthId: null,
  106. data: [],
  107. openRole: null,
  108. OpenGroup: null,
  109. roleList: [],
  110. title: "角色",
  111. editRoles: [],
  112. checkBoxList: [],
  113. authTo: {},
  114. rulesObj: {},
  115. msgDatas: [],
  116. roleType: '',
  117. orgType: '',
  118. checkedKeys: []
  119. };
  120. },
  121. computed: {
  122. ...mapGetters(["systemSet"]),
  123. isClass () {
  124. const le = checkPermission(['appupdate_edit_card']);
  125. return le;
  126. }
  127. },
  128. watch: {
  129. dataList: {
  130. handler (val) {
  131. const arr = [val];
  132. this.data = arr;
  133. this.checkedKeys = [this.UpAuthId];
  134. },
  135. deep: true,
  136. },
  137. },
  138. created () {
  139. const { AuthId, Status, UpAuthId } = this.$route.query;
  140. const { OpenRole, OpenGroup } =
  141. typeof this.systemSet === "string"
  142. ? JSON.parse(this.systemSet)
  143. : this.systemSet; //1是请求角色 0是请求用户
  144. this.radio = Status;
  145. this.AppId = AuthId;
  146. this.UpAuthId = UpAuthId;
  147. this.openRole = OpenRole;
  148. this.OpenGroup = OpenGroup;
  149. this.getAuthTree();
  150. this.getAuthDetails(AuthId);
  151. },
  152. mounted () {
  153. if (this.openRole) {
  154. this.roleType = 'onlyRole';
  155. } else if (this.OpenGroup) {
  156. this.roleType = 'account';
  157. }
  158. this.orgType = 'auth';
  159. },
  160. methods: {
  161. //获取指定数据
  162. decompose (data, id) {
  163. for (let i = 0; i < data.length; i++) {
  164. if (data[i].AuthId == id) {
  165. this.dataObj = data[i];
  166. delete this.dataObj.children;
  167. } else if (data[i].children && data[i].children.length > 0) {
  168. this.decompose(data[i].children, id);
  169. }
  170. }
  171. },
  172. //保存
  173. saveBtn (formName) {
  174. this.$refs[formName].validate((valid) => {
  175. if (valid) {
  176. this.editAuth();
  177. } else {
  178. return false;
  179. }
  180. });
  181. },
  182. //获取权限树回调
  183. getTreeData (arr) {
  184. const { AuthId, UpAuthId } = arr[0];
  185. this.AppId = AuthId;
  186. this.UpAuthId = UpAuthId;
  187. },
  188. //获取权限规则
  189. getData (obj) {
  190. this.rulesObj = obj;
  191. },
  192. //获取应用详情
  193. async getAuthDetails (id) {
  194. try {
  195. const res = await GetAuthDetails({
  196. AuthId: id,
  197. });
  198. if (res.code === 0) {
  199. const {
  200. AuthDesc,
  201. AuthName,
  202. AuthIdent,
  203. RoleInfo,
  204. AuthTo,
  205. UserInfo,
  206. AuthStatus,
  207. } = res.returnData;
  208. this.form.name = AuthName;
  209. this.form.id = AuthIdent;
  210. this.form.app = AuthDesc;
  211. this.radio = AuthStatus;
  212. if (AuthTo) {
  213. this.authTo = AuthTo;
  214. this.$store.dispatch("auth/changeAuthId", AuthTo.AuthId);
  215. this.$store.dispatch("auth/changeAuthArrs", [AuthTo]);
  216. }
  217. if (this.openRole) {
  218. if (RoleInfo && RoleInfo.length) {
  219. RoleInfo.forEach((item) => {
  220. if (item.IsSelected) {
  221. this.msgDatas.push(item);
  222. }
  223. });
  224. this.checkBoxList = this.msgDatas;
  225. } else {
  226. this.msgDatas = [];
  227. }
  228. } else if (this.OpenGroup) {
  229. if (UserInfo && UserInfo.length) {
  230. UserInfo.forEach((item) => {
  231. if (item.IsSelected) {
  232. this.msgDatas.push(item);
  233. }
  234. });
  235. this.checkBoxList = this.msgDatas;
  236. } else {
  237. this.msgDatas = [];
  238. }
  239. }
  240. } else {
  241. this.$message.error(res.message);
  242. }
  243. } catch (error) {
  244. this.$message.error("失败");
  245. }
  246. },
  247. //角色列表
  248. async queryRole () {
  249. try {
  250. const res = await QueryRole({
  251. QueryName: "",
  252. });
  253. if (res.code === 0) {
  254. const arr = res.returnData;
  255. arr.forEach((item) => {
  256. item.name = item.RoleName;
  257. });
  258. this.roleList = arr;
  259. } else {
  260. this.$message.error(res.message);
  261. }
  262. } catch (error) {
  263. this.$message.error("失败");
  264. }
  265. },
  266. //账号列表
  267. async getUserList () {
  268. try {
  269. const res = await GetUserList({
  270. QueryName: "",
  271. });
  272. if (res.code === 0) {
  273. const arr = res.returnData;
  274. arr.forEach((item) => {
  275. item.name = item.UserName;
  276. });
  277. this.roleList = arr;
  278. } else {
  279. this.$message.error(res.message);
  280. }
  281. } catch (error) {
  282. this.$message.error("失败");
  283. }
  284. },
  285. //角色选取
  286. checkChange (arr) {
  287. this.msgDatas = arr;
  288. },
  289. //权限新增保存
  290. async editAuth () {
  291. try {
  292. const datas = this.msgDatas;
  293. if (datas && datas.length) {
  294. datas.forEach((item) => {
  295. item.IsSelected = 1;
  296. });
  297. }
  298. const res = await EditAuth({
  299. AuthName: this.form.name,
  300. AuthIdent: this.form.id,
  301. AuthDesc: this.form.app,
  302. UpAuthId: this.UpAuthId,
  303. AuthId: this.AppId,
  304. RoleInfo: this.openRole ? datas : [],
  305. UserInfo: this.openRole ? [] : datas,
  306. AuthTo: this.rulesObj,
  307. AuthStatus: this.radio,
  308. });
  309. if (res.code === 0) {
  310. this.$message.success(res.message);
  311. this.$store.dispatch("tagsView/delView", this.$route);
  312. this.$router.push("/authority");
  313. } else {
  314. this.$message.error(res.message);
  315. }
  316. } catch (error) {
  317. this.$message.error("失败");
  318. }
  319. },
  320. //删除权限
  321. async deleteAuth () {
  322. try {
  323. const res = await DeleteAuth({
  324. AuthId: this.AppId,
  325. });
  326. if (res.code === 0) {
  327. this.$message.success(res.message);
  328. setTimeout(() => {
  329. this.$router.push("/authority");
  330. }, 2000);
  331. } else {
  332. this.$message.error(res.message);
  333. }
  334. } catch (error) {
  335. this.$message.error("失败");
  336. }
  337. },
  338. },
  339. };
  340. </script>
  341. <style lang="scss" scoped>
  342. .authorityPower {
  343. padding: 24px;
  344. }
  345. .addApp-form {
  346. background: #ffffff;
  347. border-radius: 4px;
  348. padding: 30px 68px 30px 24px;
  349. .addApp-form-title {
  350. line-height: 32px;
  351. .title {
  352. font-size: 24px;
  353. font-family: Microsoft YaHei;
  354. font-weight: bold;
  355. color: #303133;
  356. }
  357. .isqy {
  358. span {
  359. font-weight: 400;
  360. font-size: 14px;
  361. margin: 0 28px 0 42px;
  362. }
  363. }
  364. }
  365. .addApp-form-content {
  366. margin-top: 30px;
  367. ::v-deep .form {
  368. .el-form-item {
  369. margin-bottom: 0;
  370. margin-right: 40px;
  371. }
  372. .el-input__inner {
  373. height: 32px;
  374. line-height: 32px;
  375. min-width: 184px;
  376. }
  377. .content {
  378. .el-form-item__content {
  379. flex: 1;
  380. }
  381. .el-form-item__label {
  382. margin-left: 27px;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. .power-content {
  389. margin-top: 24px;
  390. .part {
  391. height: 704px;
  392. }
  393. }
  394. </style>