index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <template>
  2. <div id="roleInfoManagement">
  3. <search-box ref="search_box" :formList="formList" @search="search" @init="init" />
  4. <table-list
  5. :tableSets="tableSet"
  6. :tableData="tableData"
  7. :navText="navText"
  8. @addClick="addClick"
  9. :loading="loading"
  10. >
  11. <template slot="btn" slot-scope="props">
  12. <el-button type="text" @click="addClick(props.scope.row, 2)"
  13. >详情</el-button
  14. >
  15. <el-button type="text" @click="addClick(props.scope.row, 0)"
  16. >修改</el-button
  17. >
  18. <el-button type="text" @click="del(props.scope.row)">删除</el-button>
  19. </template>
  20. </table-list>
  21. <pagination
  22. :total="total"
  23. :pageSize="pageSize"
  24. :currentPage="currentPage"
  25. @handleSizeChange="handleSizeChange"
  26. @handleCurrentChange="handleCurrentChange"
  27. />
  28. <el-dialog
  29. :visible.sync="dialogVisible"
  30. width="460px"
  31. :show-close="false"
  32. :close-on-click-modal="false"
  33. >
  34. <div slot="title" class="hearders">
  35. <div class="leftTitle">
  36. {{ statusPop === 1 ? "添加" : statusPop === 0 ? "修改" : "详情" }}
  37. </div>
  38. <div class="rightBoxs">
  39. <img src="@/assets/images/Close@2x.png" alt="" @click="close" />
  40. </div>
  41. </div>
  42. <div>
  43. <el-form
  44. label-position="right"
  45. label-width="80px"
  46. :model="listData"
  47. :rules="rules"
  48. ref="listData"
  49. >
  50. <el-form-item
  51. v-for="(items, indexs) in listitem"
  52. :key="indexs"
  53. :label="items.label"
  54. :prop="items.prop"
  55. >
  56. <el-radio-group
  57. v-if="items.scope === 'status'"
  58. v-model="listData[items.prop]"
  59. >
  60. <el-radio
  61. v-for="(item, index) in items.options"
  62. :key="index"
  63. :label="item.value"
  64. :disabled="statusPop === 2"
  65. >{{ item.label }}</el-radio
  66. >
  67. </el-radio-group>
  68. <div v-else-if="items.scope === 'tree'">
  69. <el-checkbox
  70. v-model="menuExpand"
  71. @change="handleCheckedTreeExpand($event, 'menu')"
  72. >展开/折叠</el-checkbox
  73. >
  74. <el-checkbox
  75. v-model="menuNodeAll"
  76. @change="handleCheckedTreeNodeAll($event, 'menu')"
  77. >全选/全不选</el-checkbox
  78. >
  79. <el-checkbox
  80. v-model="listData.menuCheckStrictly"
  81. @change="handleCheckedTreeConnect($event, 'menu')"
  82. >父子联动</el-checkbox
  83. >
  84. <el-tree
  85. class="tree-border"
  86. :data="menuOptions"
  87. show-checkbox
  88. ref="menu"
  89. node-key="id"
  90. :check-strictly="!listData.menuCheckStrictly"
  91. empty-text="加载中,请稍后"
  92. :props="defaultProps"
  93. ></el-tree>
  94. </div>
  95. <el-input
  96. :disabled="statusPop === 2"
  97. v-else-if="items.scope === 'textarea'"
  98. type="textarea"
  99. v-model="listData[items.prop]"
  100. ></el-input>
  101. <el-input-number
  102. style="width: 100%"
  103. :disabled="statusPop === 2"
  104. v-else-if="items.scope === 'numberIndex'"
  105. v-model="listData[items.prop]"
  106. controls-position="right"
  107. :min="0"
  108. :max="99"
  109. ></el-input-number>
  110. <el-input
  111. :disabled="statusPop === 2"
  112. v-else
  113. v-model="listData[items.prop]"
  114. ></el-input>
  115. </el-form-item>
  116. </el-form>
  117. </div>
  118. <span slot="footer" class="dialog-footer">
  119. <el-button @click="close">取 消</el-button>
  120. <el-button
  121. type="primary"
  122. v-if="statusPop !== 2"
  123. @click="submit('listData')"
  124. >确 定</el-button
  125. >
  126. </span>
  127. </el-dialog>
  128. </div>
  129. </template>
  130. <script>
  131. import searchBox from "@/components/searchBox";
  132. import tableList from "@/components/tableList";
  133. import pagination from "@/components/pagination";
  134. export default {
  135. components: { searchBox, tableList, pagination },
  136. data() {
  137. return {
  138. loading: false, //当前表单加载是否加载动画
  139. navText: {
  140. title: "角色管理",
  141. index: 0,
  142. ch: "种",
  143. num: false,
  144. choice: false,
  145. addHide: false,
  146. backFatherBtn: {
  147. status: false,
  148. title: "未定义",
  149. },
  150. },
  151. //搜索
  152. formList: [
  153. {
  154. label: "角色名称",
  155. prop: "roleName",
  156. placeholder: "请输入角色名称",
  157. },
  158. {
  159. label: "权限字符",
  160. prop: "roleKey",
  161. placeholder: "请输入权限字符",
  162. },
  163. {
  164. label: "状态",
  165. prop: "status",
  166. placeholder: "请选择状态",
  167. scope: "select",
  168. options: [
  169. {
  170. label: "启用",
  171. value: "1",
  172. },
  173. {
  174. label: "停用",
  175. value: "0",
  176. },
  177. ],
  178. },
  179. ],
  180. // 表单
  181. tableSet: [
  182. {
  183. label: "角色编号",
  184. prop: "roleId",
  185. hidden: true,
  186. },
  187. {
  188. label: "角色名称",
  189. prop: "roleName",
  190. hidden: true,
  191. },
  192. {
  193. label: "权限字符",
  194. prop: "roleKey",
  195. hidden: true,
  196. },
  197. {
  198. label: "显示顺序",
  199. prop: "roleSort",
  200. hidden: true,
  201. },
  202. {
  203. label: "状态",
  204. prop: "status",
  205. hidden: true,
  206. scope: "status",
  207. },
  208. {
  209. label: "创建时间",
  210. prop: "createTime",
  211. hidden: true,
  212. },
  213. ],
  214. tableData: [], //表单数据
  215. total: 0, //一共多少条
  216. pageSize: 10, //每页多少条数据
  217. currentPage: 1, //当前页码
  218. menuExpand: false,
  219. menuNodeAll: false,
  220. defaultProps: {
  221. children: "children",
  222. label: "label",
  223. },
  224. menuOptions: [], //菜单列表
  225. // 弹窗字段
  226. listitem: [
  227. {
  228. label: "角色名称",
  229. prop: "roleName",
  230. },
  231. {
  232. label: "权限字符",
  233. prop: "roleKey",
  234. },
  235. {
  236. label: "角色顺序",
  237. prop: "roleSort",
  238. scope: "numberIndex",
  239. },
  240. {
  241. label: "状态",
  242. prop: "status",
  243. scope: "status",
  244. options: [
  245. {
  246. label: "启用",
  247. value: "1",
  248. },
  249. {
  250. label: "关闭",
  251. value: "0",
  252. },
  253. ],
  254. },
  255. {
  256. label: "菜单权限",
  257. prop: "menuIds",
  258. scope: "tree",
  259. },
  260. {
  261. label: "备注",
  262. prop: "remark",
  263. scope: "textarea",
  264. },
  265. ],
  266. // 弹窗数据
  267. listData: {},
  268. statusPop: -1,
  269. dialogVisible: false,
  270. //表单验证
  271. rules: {
  272. roleName: [
  273. { required: true, message: "请输入岗位名称", trigger: "blur" },
  274. ],
  275. roleKey: [
  276. { required: true, message: "请输入岗位编码", trigger: "blur" },
  277. ],
  278. roleSort: [
  279. { required: true, message: "请输入岗位顺序", trigger: "blur" },
  280. ],
  281. status: [{ required: true, message: "请选择状态", trigger: "change" }],
  282. // remark: [{ required: true, message: "请填写备注", trigger: "blur" }],
  283. },
  284. };
  285. },
  286. mounted() {
  287. this.search();
  288. },
  289. methods: {
  290. search(v,os) {
  291. this.loading = true;
  292. if(os){
  293. this.currentPage = 1
  294. }
  295. if(v === undefined){
  296. v = {}
  297. }
  298. var data = {
  299. roleKey: v.roleKey,
  300. roleName: v.roleName,
  301. statusArray: v.status === undefined ? "0,1" : v.status,
  302. pageSize: this.pageSize,
  303. pageNum: this.currentPage,
  304. };
  305. this.$api.obtainRoleList(data).then((res) => {
  306. this.tableData = res.rows.sort(this.sortBy("postSort", true));
  307. this.total = res.total;
  308. this.navText.index = res.total;
  309. });
  310. this.loading = false;
  311. },
  312. init() {
  313. this.search();
  314. },
  315. del(v) {
  316. this.$confirm("此操作将删除该岗位, 是否继续?", "提示", {
  317. confirmButtonText: "确定",
  318. cancelButtonText: "取消",
  319. type: "warning",
  320. })
  321. .then(() => {
  322. var data = JSON.parse(JSON.stringify(v));
  323. data.menuIds = [];
  324. data.status = "-1";
  325. this.$api.editRole(data).then((res) => {
  326. if (res.code === 200) {
  327. this.$message.success("删除成功");
  328. this.search();
  329. this.dialogVisible = false;
  330. }
  331. });
  332. })
  333. .catch(() => {
  334. this.$message({
  335. type: "info",
  336. message: "已取消删除",
  337. });
  338. });
  339. },
  340. addClick(v, int) {
  341. var self = this;
  342. self.initData();
  343. if (v === undefined) {
  344. self.statusPop = 1;
  345. self.getMenuList();
  346. self.dialogVisible = true;
  347. self.$nextTick(() => {
  348. self.$refs.listData.clearValidate();
  349. });
  350. } else {
  351. self.statusPop = int;
  352. var data = v.roleId;
  353. self.$api.obtainRoleId(data).then(async (res) => {
  354. if (res.code === 200) {
  355. const getCheckList = await self.getUserMenuList(v.roleId);
  356. self.menuOptions = getCheckList.menus;
  357. getCheckList.checkedKeys.forEach((v) => {
  358. self.$nextTick(() => {
  359. self.$refs.menu[0].setChecked(v, true, false);
  360. });
  361. });
  362. self.listData = res.data;
  363. self.dialogVisible = true;
  364. self.$nextTick(() => {
  365. self.$refs.listData.clearValidate();
  366. });
  367. }
  368. });
  369. }
  370. },
  371. getMenuList() {
  372. this.$api.enutreeselect().then((res) => {
  373. this.menuOptions = res.data;
  374. });
  375. },
  376. getUserMenuList(v) {
  377. return new Promise((resolve, reject) => {
  378. this.$api.roleMenuTreeselect(v).then((result) => {
  379. resolve(result);
  380. });
  381. });
  382. },
  383. submit(formName) {
  384. this.$refs[formName].validate((valid) => {
  385. if (valid) {
  386. this.rulesTableSumbit();
  387. } else {
  388. return false;
  389. }
  390. });
  391. },
  392. rulesTableSumbit() {
  393. this.listData.menuIds = this.getMenuAllCheckedKeys();
  394. var data = this.listData;
  395. if (this.statusPop === 1) {
  396. this.$api.addRole(data).then((res) => {
  397. if (res.code === 200) {
  398. this.$message.success("新增成功");
  399. this.search();
  400. this.dialogVisible = false;
  401. }
  402. });
  403. }
  404. if (this.statusPop === 0) {
  405. this.$api.editRole(data).then((res) => {
  406. if (res.code === 200) {
  407. this.$message.success("修改成功");
  408. this.search();
  409. this.dialogVisible = false;
  410. }
  411. });
  412. }
  413. },
  414. close() {
  415. this.initData();
  416. this.dialogVisible = false;
  417. },
  418. initData() {
  419. this.menuExpand = false;
  420. this.menuNodeAll = false;
  421. this.listData = {
  422. roleId: undefined,
  423. roleName: undefined,
  424. roleKey: undefined,
  425. roleSort: 0,
  426. status: "",
  427. menuIds: [],
  428. deptIds: [],
  429. menuCheckStrictly: true,
  430. deptCheckStrictly: true,
  431. remark: undefined,
  432. };
  433. },
  434. sortBy(attr, rev) {
  435. //第二个参数没有传递 默认升序排列
  436. if (rev == undefined) {
  437. rev = 1;
  438. } else {
  439. rev = rev ? 1 : -1;
  440. }
  441. return function (a, b) {
  442. a = a[attr];
  443. b = b[attr];
  444. if (a < b) {
  445. return rev * -1;
  446. }
  447. if (a > b) {
  448. return rev * 1;
  449. }
  450. return 0;
  451. };
  452. },
  453. // 树权限(展开/折叠)
  454. handleCheckedTreeExpand(value, type) {
  455. if (type == "menu") {
  456. let treeList = this.menuOptions;
  457. for (let i = 0; i < treeList.length; i++) {
  458. this.$refs.menu[0].store.nodesMap[treeList[i].id].expanded = value;
  459. }
  460. }
  461. },
  462. // 树权限(全选/全不选)
  463. handleCheckedTreeNodeAll(value, type) {
  464. console.log(this.$refs.menu);
  465. if (type == "menu") {
  466. this.$refs.menu[0].setCheckedNodes(value ? this.menuOptions : []);
  467. }
  468. },
  469. // 树权限(父子联动)
  470. handleCheckedTreeConnect(value, type) {
  471. if (type == "menu") {
  472. console.log(value);
  473. this.listData.menuCheckStrictly = value ? true : false;
  474. }
  475. },
  476. // 所有菜单节点数据
  477. getMenuAllCheckedKeys() {
  478. // 目前被选中的菜单节点
  479. let checkedKeys = this.$refs.menu[0].getCheckedKeys();
  480. // 半选中的菜单节点
  481. let halfCheckedKeys = this.$refs.menu[0].getHalfCheckedKeys();
  482. checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  483. return checkedKeys;
  484. },
  485. handleSizeChange(v) {
  486. this.pageSize = v;
  487. this.currentPage = 1;
  488. this.search(this.$refs.search_box.formData);
  489. },
  490. handleCurrentChange(v) {
  491. this.currentPage = v;
  492. this.search(this.$refs.search_box.formData);
  493. },
  494. },
  495. };
  496. </script>
  497. <style lang="less" scoped>
  498. /deep/.el-button {
  499. border-radius: 8px;
  500. }
  501. /deep/.el-dialog {
  502. border-radius: 8px;
  503. .el-dialog__header {
  504. padding: 0;
  505. .hearders {
  506. height: 40px;
  507. display: flex;
  508. align-items: center;
  509. justify-content: space-between;
  510. padding: 0px 18px 0px 20px;
  511. border-bottom: 1px solid #e2e2e2;
  512. .leftTitle {
  513. font-size: 14px;
  514. font-weight: bold;
  515. color: #2f4378;
  516. }
  517. .rightBoxs {
  518. display: flex;
  519. align-items: center;
  520. img {
  521. width: 14px;
  522. height: 14px;
  523. margin-left: 13px;
  524. cursor: pointer;
  525. }
  526. }
  527. }
  528. }
  529. .el-dialog__footer {
  530. padding: 0;
  531. .dialog-footer {
  532. padding: 0px 40px;
  533. height: 70px;
  534. border-top: 1px solid #e2e2e2;
  535. display: flex;
  536. align-items: center;
  537. justify-content: flex-end;
  538. }
  539. }
  540. }
  541. .imgBox {
  542. width: 100%;
  543. // height: 210px;
  544. border: 1px solid #e2e2e2;
  545. border-radius: 8px;
  546. padding: 8px 8px 3px;
  547. display: flex;
  548. flex-direction: column;
  549. align-items: center;
  550. .imgLabel {
  551. flex: 1;
  552. width: 100%;
  553. border: 1px dotted #e2e2e2;
  554. color: #999;
  555. font-size: 14px;
  556. cursor: pointer;
  557. border-radius: 8px;
  558. .msPhoto {
  559. display: flex;
  560. justify-content: center;
  561. align-items: center;
  562. max-width: 100%;
  563. max-height: 270px;
  564. img {
  565. max-width: 100%;
  566. max-height: 270px;
  567. }
  568. }
  569. .imgbbx {
  570. display: flex;
  571. flex-direction: column;
  572. align-items: center;
  573. justify-content: center;
  574. width: 100%;
  575. height: 100%;
  576. i {
  577. font-weight: bold;
  578. margin: 14px 0;
  579. font-size: 24px;
  580. }
  581. }
  582. }
  583. p {
  584. margin: 5px 0px;
  585. }
  586. }
  587. .tree-border {
  588. margin-top: 5px;
  589. border: 1px solid #e5e6e7;
  590. background: #ffffff none;
  591. border-radius: 4px;
  592. }
  593. </style>