index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div class="common-box">
  3. <!--条件-->
  4. <el-form :model="listQuery" ref="queryForm" :inline="true">
  5. <el-form-item label="角色编码">
  6. <el-input
  7. v-model="listQuery.roleId"
  8. placeholder="请输入角色编码"
  9. ></el-input>
  10. </el-form-item>
  11. <el-form-item label="角色名称">
  12. <el-input
  13. v-model="listQuery.roleName"
  14. placeholder="请输入角色名称"
  15. ></el-input>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" @click="handleSearch()">查询</el-button
  19. ><el-button @click="reset()">重置</el-button>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button
  23. type="primary"
  24. class="lake-Blue"
  25. icon="el-icon-plus"
  26. @click="handleAddOrEdit(0, null, 'create')"
  27. >新增
  28. </el-button>
  29. </el-form-item>
  30. </el-form>
  31. <!--列表-->
  32. <div>
  33. <el-table
  34. v-loading="listLoading"
  35. :data="list"
  36. element-loading-text="加载中"
  37. fit
  38. stripe
  39. >
  40. <template slot="empty">
  41. <img src="@/assets/nopage.png" alt />
  42. <p>暂无数据</p>
  43. </template>
  44. <el-table-column
  45. fixed
  46. type="index"
  47. label="序号"
  48. width="60"
  49. ></el-table-column>
  50. <el-table-column label="角色编码" prop="roleId" />
  51. <el-table-column label="角色名称" prop="roleName" />
  52. <el-table-column label="说明" :v-if="true" prop="dscr" />
  53. <el-table-column fixed="right" label="操作">
  54. <template slot-scope="scope">
  55. <el-button
  56. icon="el-icon-edit"
  57. style="color: #52c8cc"
  58. type="text"
  59. @click="handleAddOrEdit(scope.$index, scope.row, 'update')"
  60. >编辑</el-button
  61. >
  62. <el-button
  63. icon="el-icon-delete"
  64. style="color: #ce4745"
  65. type="text"
  66. @click="handleDelete(scope.row, 'deleted')"
  67. >删除</el-button
  68. >
  69. <el-button
  70. icon="el-icon-setting"
  71. style="color: #e6a23c"
  72. type="text"
  73. @click="handlePrivilege(scope.row)"
  74. >设置权限</el-button
  75. >
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. </div>
  80. <!--分页-->
  81. <yl-pagination
  82. v-show="total > 0"
  83. :total="total"
  84. :page.sync="listQuery.current"
  85. :limit.sync="listQuery.size"
  86. @pagination="getData"
  87. />
  88. <!--添加/修改-->
  89. <el-dialog
  90. :title="textMap[dialogStatus]"
  91. :visible.sync="dialogFormVisible"
  92. width="420px"
  93. :close-on-click-modal="false"
  94. >
  95. <el-form
  96. ref="dataForm"
  97. :rules="rules"
  98. :model="temp"
  99. label-position="right"
  100. label-width="80px"
  101. style="width: 370px; margin-left: 10px"
  102. >
  103. <!-- <el-form-item label="角色编码" prop="roleId">
  104. <el-input v-model.trim="temp.roleId" />
  105. </el-form-item> -->
  106. <el-form-item label="角色名称" prop="roleName">
  107. <el-input v-model.trim="temp.roleName" />
  108. </el-form-item>
  109. <el-form-item label="说明" prop="dscr">
  110. <el-input v-model.trim="temp.dscr" />
  111. </el-form-item>
  112. </el-form>
  113. <div slot="footer" class="dialog-footer">
  114. <el-button @click="dialogFormVisible = false">取消</el-button>
  115. <el-button type="primary" @click="commitData()">确认</el-button>
  116. </div>
  117. </el-dialog>
  118. <!-- 设置权限 -->
  119. <el-dialog
  120. v-if="dialogPrivilegeFormVisible"
  121. title="设置权限"
  122. :visible.sync="dialogPrivilegeFormVisible"
  123. width="400px"
  124. :close-on-click-modal="false"
  125. >
  126. <el-form
  127. ref="dataPrivilegeForm"
  128. :rules="rules"
  129. :model="tempPrivilege"
  130. label-position="left"
  131. label-width="80px"
  132. >
  133. <funTree
  134. ref="funtree"
  135. :defaultMenu="defaultMenu"
  136. :allMenu="menuData"
  137. :checkBoxShow="true"
  138. :reload="reload"
  139. />
  140. </el-form>
  141. <div slot="footer" class="dialog-footer">
  142. <el-button @click="dialogPrivilegeFormVisible = false">取消</el-button>
  143. <el-button type="primary" @click="commitPrivilegeData()"
  144. >确认</el-button
  145. >
  146. </div>
  147. </el-dialog>
  148. </div>
  149. </template>
  150. <script>
  151. import {
  152. getRoleData,
  153. getMenuButtonData,
  154. setRole,
  155. setRoleMenu
  156. } from "@/api/system/role";
  157. import ylPagination from "@/components/yl-pagination";
  158. import FunTree from "@/views/components/funTree";
  159. export default {
  160. components: {
  161. ylPagination,
  162. FunTree
  163. },
  164. data() {
  165. return {
  166. reload: "",
  167. roleId: "",
  168. defaultMenu: [],
  169. menuData: [], //菜单
  170. list: null, //列表
  171. total: 0, //分页
  172. listLoading: true,
  173. listQuery: {
  174. //条件查询
  175. roleName: "",
  176. current: 1,
  177. size: 10,
  178. roleId: ""
  179. },
  180. roles: [],
  181. dialogFormVisible: false, //是否对话框
  182. dialogStatus: "",
  183. textMap: {
  184. update: "编辑",
  185. create: "添加"
  186. },
  187. temp: {},
  188. dialogPrivilegeFormVisible: false, //角色对话框
  189. tempPrivilege: {
  190. //权限表单
  191. },
  192. rules: {
  193. roleId: [
  194. {
  195. required: true,
  196. message: "角色编码不能为空",
  197. trigger: "blur"
  198. }
  199. ],
  200. roleName: [
  201. {
  202. required: true,
  203. message: "角色名称不能为空",
  204. trigger: "blur"
  205. }
  206. ]
  207. }
  208. };
  209. },
  210. created() {
  211. this.getData();
  212. },
  213. methods: {
  214. // 重置页面
  215. reset() {
  216. this.listQuery.roleId = "";
  217. this.listQuery.roleName = "";
  218. this.getData();
  219. },
  220. // 查询
  221. handleSearch() {
  222. this.listQuery.current = 1;
  223. this.getData();
  224. },
  225. //获取列表数据
  226. getData() {
  227. this.listLoading = true;
  228. getRoleData(this.listQuery)
  229. .then((response) => {
  230. this.list = response.data.records;
  231. this.total = response.data.total;
  232. this.listLoading = false;
  233. })
  234. .catch((err) => {
  235. this.listLoading = false;
  236. });
  237. },
  238. //提交角色表单数据
  239. commitData() {
  240. this.$refs["dataForm"].validate((valid) => {
  241. if (valid) {
  242. this.$confirm("确认提交", "提示", {
  243. confirmButtonText: "确定",
  244. cancelButtonText: "取消",
  245. type: "warning"
  246. }).then(() => {
  247. setRole(this.temp).then((response) => {
  248. this.$message({
  249. message: "操作成功",
  250. type: "success"
  251. });
  252. this.dialogFormVisible = false;
  253. this.getData();
  254. });
  255. });
  256. }
  257. });
  258. },
  259. // 菜单提交
  260. commitPrivilegeData() {
  261. if (
  262. this.$refs.funtree.$refs.tree.getCheckedNodes(false, true).length == 0
  263. ) {
  264. this.$message({
  265. message: "请选择至少一级菜单",
  266. type: "error"
  267. });
  268. return;
  269. }
  270. let commitList = new Array();
  271. for (
  272. let i = 0;
  273. i < this.$refs.funtree.$refs.tree.getCheckedNodes(false, true).length;
  274. i++
  275. ) {
  276. let entity = {
  277. roleId: this.roleId,
  278. menuId: this.$refs.funtree.$refs.tree.getCheckedNodes(false, true)[i]
  279. .id,
  280. penartId: this.$refs.funtree.$refs.tree.getCheckedNodes(false, true)[
  281. i
  282. ].parentId,
  283. type: this.$refs.funtree.$refs.tree.getCheckedNodes(false, true)[i]
  284. .menuType
  285. };
  286. commitList.push(entity);
  287. }
  288. setRoleMenu(commitList).then((response) => {
  289. this.$message({
  290. message: "操作成功",
  291. type: "success"
  292. });
  293. this.dialogPrivilegeFormVisible = false;
  294. });
  295. },
  296. //添加/修改对话框
  297. handleAddOrEdit(index, row, type) {
  298. if (type === "update") {
  299. this.temp = {
  300. id: row.id,
  301. // roleId: row.roleId,
  302. roleName: row.roleName,
  303. dscr: row.dscr,
  304. type: "updt"
  305. };
  306. } else {
  307. this.temp = {
  308. id: "",
  309. // roleId: "",
  310. roleName: "",
  311. dscr: "",
  312. type: "add"
  313. };
  314. }
  315. this.dialogStatus = type;
  316. this.dialogFormVisible = true;
  317. this.$nextTick(() => {
  318. this.$refs["dataForm"].clearValidate();
  319. });
  320. },
  321. // 打开设置权限对话框
  322. handlePrivilege(row) {
  323. this.roleId = row.roleId;
  324. this.defaultMenu = [];
  325. getMenuButtonData({ roleId: row.roleId }).then((response) => {
  326. let data = response.data;
  327. data.forEach((item, index) => {
  328. if (item.cho == 0) {
  329. this.defaultMenu.push(item);
  330. }
  331. });
  332. if (data && data.length > 0) {
  333. this.menuData = data;
  334. this.dialogPrivilegeFormVisible = true;
  335. }
  336. });
  337. },
  338. //删除
  339. handleDelete(row, status) {
  340. this.$confirm("确认删除", "提示", {
  341. confirmButtonText: "确定",
  342. cancelButtonText: "取消",
  343. type: "warning"
  344. }).then(() => {
  345. this.temp = {
  346. id: row.id,
  347. roleId: row.roleId,
  348. roleName: row.roleName,
  349. dscr: row.dscr,
  350. type: "del"
  351. };
  352. setRole(this.temp).then((response) => {
  353. this.$message({
  354. message: "操作成功",
  355. type: "success"
  356. });
  357. // 解决element el-pagination分页最后一页数据清空了页码显示正确,但是列表为空
  358. const totalPage = Math.ceil((this.total - 1) / this.listQuery.size);
  359. const currentPage =
  360. this.listQuery.current > totalPage
  361. ? totalPage
  362. : this.listQuery.current;
  363. this.listQuery.current = currentPage < 1 ? 1 : currentPage;
  364. this.getData();
  365. });
  366. });
  367. }
  368. }
  369. //--------------------method
  370. };
  371. </script>
  372. <style scoped>
  373. </style>