authorityPowerAdd.vue 11 KB

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