organizationAdd.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 11:26:07
  4. * @LastEditTime: 2022-03-15 11:50: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">新增组织</div>
  15. <div v-is="['organ_btn_save']" 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="请输入组织名称" v-model="form.name"></el-input>
  23. </el-form-item>
  24. <el-form-item prop="id" label="组织类型">
  25. <el-select v-model="form.id" placeholder="请选择">
  26. <el-option label="集团内" :value="1"></el-option>
  27. <el-option label="集团外" :value="0"></el-option>
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item prop="app" label="描述">
  31. <el-input style="width: 835px" placeholder="请输入描述" v-model="form.app"></el-input>
  32. </el-form-item>
  33. <div class="top24">
  34. <el-form-item prop="oneCode" label="1级编码">
  35. <el-input placeholder="最多输入2个字符" v-model="form.oneCode"></el-input>
  36. </el-form-item>
  37. <el-form-item prop="twoCode" class="twoCode" label="2级编码">
  38. <el-input placeholder="最多输入3个字符" style="width: 202px" v-model="form.twoCode"></el-input>
  39. </el-form-item>
  40. <el-form-item prop="threeCode" label="3级编码">
  41. <el-input placeholder="最多输入8个字符" v-model="form.threeCode"></el-input>
  42. </el-form-item>
  43. <el-form-item prop="fourCode" label="4级编码">
  44. <el-input placeholder="最多输入2个字符" v-model="form.fourCode"></el-input>
  45. </el-form-item>
  46. <el-form-item prop="fiveCode" label="5级编码">
  47. <el-input placeholder="最多输入2个字符" v-model="form.fiveCode"></el-input>
  48. </el-form-item>
  49. </div>
  50. </el-form>
  51. </div>
  52. </div>
  53. <div class="power-content flex-wrap">
  54. <div class="flex1 part">
  55. <Organization :defaultProps="defaultProps" :data="data" nodekey="OrganId" :checkedKeys="checkedKeys" title="上级组织" />
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import Permissiontree from "@/components/permissiontree";
  62. import Rulesofcompetency from "@/components/rulesofcompetency";
  63. import Organization from "@/components/organization";
  64. import Permissionlist from "@/components/permissionlist";
  65. import Rolelist from "@/components/rolelist";
  66. import treeData from "../minixs/treeData";
  67. import roleData from "../minixs/roleData";
  68. import { mapGetters } from "vuex";
  69. import { RoleAuths } from "@/api/apiAuthority";
  70. import { newOrgan } from "@/api/postInterface";
  71. import { lengthValidator } from '@/utils/validate'
  72. export default {
  73. name: "AuthorityPower",
  74. mixins: [treeData, roleData],
  75. components: {
  76. Rulesofcompetency,
  77. Organization,
  78. Permissiontree,
  79. Permissionlist,
  80. Rolelist,
  81. },
  82. data () {
  83. return {
  84. Status: null,
  85. AppId: null,
  86. form: {
  87. //应用表单
  88. name: "",
  89. id: "",
  90. app: "",
  91. oneCode: "",
  92. twoCode: "",
  93. threeCode: "",
  94. fourCode: "",
  95. fiveCode: ""
  96. },
  97. title: "角色",
  98. rules: {
  99. //表单验证
  100. name: [
  101. { required: true, message: "请输入组织名称", trigger: "blur" },
  102. { validator: lengthValidator, max: 32, message: '最多输入32个字符', trigger: ['change', 'blur'] }
  103. ],
  104. id: [{ required: true, message: "请输入标识符", trigger: "blur" }],
  105. app: [{ validator: lengthValidator, max: 128, message: '最多输入128个字符', trigger: ['change', 'blur'] }],
  106. oneCode: [{ validator: lengthValidator, max: 2, message: '最多输入2个字符', trigger: ['change', 'blur'] }],
  107. twoCode: [{ validator: lengthValidator, max: 3, message: '最多输入3个字符', trigger: ['change', 'blur'] }],
  108. threeCode: [{ validator: lengthValidator, max: 8, message: '最多输入8个字符', trigger: ['change', 'blur'] }],
  109. fourCode: [{ validator: lengthValidator, max: 2, message: '最多输入2个字符', trigger: ['change', 'blur'] }],
  110. fiveCode: [{ validator: lengthValidator, max: 2, message: '最多输入2个字符', trigger: ['change', 'blur'] }],
  111. },
  112. defaultProps: {
  113. children: "children",
  114. label: "OrganName",
  115. },
  116. checkedKeys: [], //上级组织选中
  117. RoleList: [],
  118. checkedBoxs: [],
  119. arrs: [],
  120. queryType: null, //权限树类型
  121. openRole: null,
  122. OpenGroup: null,
  123. dataObj: {}, //上级权限指定树数据
  124. data: [], //上级权限
  125. roleList: [], //角色
  126. checkRoles: [], //选中的角色
  127. checkTrees: [], //上级权限选中树数据
  128. rulesObj: {}, //权限规则数据
  129. };
  130. },
  131. computed: {
  132. ...mapGetters(["systemSet"]),
  133. },
  134. watch: {
  135. //监听上级组织数据
  136. dataList: {
  137. handler (val) {
  138. const arr = [val];
  139. this.decompose(arr, this.AppId);
  140. this.data = [this.dataObj];
  141. this.checkedKeys = [this.AppId];
  142. },
  143. deep: true,
  144. },
  145. },
  146. created () {
  147. const { OrganId, Status } = this.$route.query;
  148. const { OpenRole, OpenGroup } =
  149. typeof this.systemSet === "string"
  150. ? JSON.parse(this.systemSet)
  151. : this.systemSet; //1是请求角色 0是请求用户
  152. this.Status = Status;
  153. this.AppId = OrganId;
  154. this.openRole = OpenRole;
  155. this.OpenGroup = OpenGroup;
  156. this.getOrganTree();
  157. },
  158. methods: {
  159. //获取指定数据
  160. decompose (data, id) {
  161. for (let i = 0; i < data.length; i++) {
  162. if (data[i].OrganId == id) {
  163. if (data[i].children && data[i].children.length) {
  164. delete data[i].children;
  165. }
  166. this.dataObj = data[i];
  167. } else if (data[i].children && data[i].children.length > 0) {
  168. this.decompose(data[i].children, id);
  169. }
  170. }
  171. },
  172. //权限树点击
  173. nodeClick (obj) {
  174. const arr = this.$store.getters.authArrs;
  175. arr.push(obj);
  176. this.$store.dispatch("auth/changeAuthArrs", arr);
  177. },
  178. //角色点击回调
  179. checkClick (item) {
  180. this.roleAuths(item.RoleId);
  181. },
  182. //岗位点击回调
  183. checkGroup (item) {
  184. this.groupAuths(item.GroupId);
  185. },
  186. //根据角色查看权限列表
  187. async roleAuths (id) {
  188. try {
  189. let params = {
  190. RoleId: id,
  191. };
  192. const res = await RoleAuths(params);
  193. if (res.code === 0) {
  194. this.RoleList = res.returnData;
  195. } else {
  196. this.$message.error(res.message);
  197. }
  198. } catch (error) {
  199. console.log("出错了", error);
  200. }
  201. },
  202. //角色选取
  203. checkChange (arr) {
  204. const datas = [];
  205. for (let i = 0; i < arr.length; i++) {
  206. datas.push(this.arrs[arr[i]]);
  207. }
  208. datas.forEach((item) => {
  209. item.IsSelected = "1";
  210. });
  211. this.checkRoles = datas;
  212. },
  213. //获取权限规则
  214. getData (obj) {
  215. this.rulesObj = obj;
  216. },
  217. //保存
  218. saveBtn (formName) {
  219. this.$refs[formName].validate((valid) => {
  220. if (valid) {
  221. this.saveOrgan();
  222. } else {
  223. console.log("error submit!!");
  224. return false;
  225. }
  226. });
  227. },
  228. //组织新增保存
  229. async saveOrgan () {
  230. try {
  231. const datas = [];
  232. this.checkTrees.forEach((item) => {
  233. datas.push(item.AuthList);
  234. });
  235. const res = await newOrgan({
  236. OrganName: this.form.name,
  237. OrganType: this.form.id,
  238. OrganDesc: this.form.app,
  239. OrganUpid: this.AppId,
  240. RoleList: this.openRole ? this.checkRoles : [],
  241. AuthList: this.openRole ? [] : datas,
  242. GroupList: this.OpenGroup ? this.checkRoles : [],
  243. L1: this.form.oneCode,
  244. L2: this.form.twoCode,
  245. L3: this.form.threeCode,
  246. L4: this.form.fourCode,
  247. L5: this.form.fiveCode
  248. });
  249. if (res.code === 0) {
  250. this.$message.success(res.message);
  251. this.$store.dispatch("tagsView/delView", this.$route);
  252. this.$router.push("/organization");
  253. } else {
  254. this.$message.error(res.message);
  255. }
  256. } catch (error) {
  257. console.log("出错了", error);
  258. }
  259. },
  260. },
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. .authorityPower {
  265. padding: 0 64px;
  266. padding-top: 32px;
  267. }
  268. .addApp-form {
  269. background: #ffffff;
  270. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  271. border-radius: 16px;
  272. padding: 32px 32px 40px 32px;
  273. .title {
  274. font-size: 24px;
  275. font-family: Microsoft YaHei;
  276. font-weight: bold;
  277. color: #303133;
  278. .isqy {
  279. span {
  280. font-weight: 400;
  281. font-size: 14px;
  282. margin: 0 28px 0 42px;
  283. }
  284. }
  285. }
  286. .addApp-form-content {
  287. margin-top: 40px;
  288. ::v-deep .form {
  289. .el-form-item {
  290. margin-bottom: 0;
  291. margin-right: 40px;
  292. }
  293. .el-input__inner {
  294. height: 32px;
  295. line-height: 32px;
  296. min-width: 184px;
  297. }
  298. .content {
  299. .el-form-item__content {
  300. flex: 1;
  301. }
  302. .el-form-item__label {
  303. margin-left: 27px;
  304. }
  305. }
  306. .top24 {
  307. margin-top: 24px;
  308. .el-form-item__label {
  309. margin-left: 16px;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. .power-content {
  316. margin-top: 24px;
  317. // min-height: 58vh;
  318. .part {
  319. height: 704px;
  320. }
  321. }
  322. </style>