index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <!--
  2. - Copyright (c) 2018-2025, lengleng All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions are met:
  6. -
  7. - Redistributions of source code must retain the above copyright notice,
  8. - this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. - notice, this list of conditions and the following disclaimer in the
  11. - documentation and/or other materials provided with the distribution.
  12. - Neither the name of the pig4cloud.com developer nor the names of its
  13. - contributors may be used to endorse or promote products derived from
  14. - this software without specific prior written permission.
  15. - Author: lengleng (wangiegie@gmail.com)
  16. -->
  17. <template>
  18. <div class="app-container calendar-list-container">
  19. <basic-container>
  20. <avue-crud :option="option"
  21. ref="crud"
  22. v-model="form"
  23. :page="page"
  24. @on-load="getList"
  25. :table-loading="listLoading"
  26. @search-change="handleFilter"
  27. @refresh-change="handleRefreshChange"
  28. @row-update="update"
  29. @row-save="create"
  30. :before-open="handleOpenBefore"
  31. :data="list">
  32. <template slot="menuLeft">
  33. <el-button v-if="sys_user_add"
  34. class="filter-item"
  35. @click="handleCreate"
  36. size="small"
  37. type="primary"
  38. icon="el-icon-edit">添加</el-button>
  39. </template>
  40. <template slot="username"
  41. slot-scope="scope">
  42. <span>{{scope.row.username}}</span>
  43. </template>
  44. <template slot="role"
  45. slot-scope="scope">
  46. <span v-for="(role,index) in scope.row.roleList"
  47. :key="index">
  48. <el-tag>{{role.roleDesc}} </el-tag>&nbsp;&nbsp;
  49. </span>
  50. </template>
  51. <template slot="deptId"
  52. slot-scope="scope">
  53. {{scope.row.deptName}}
  54. </template>
  55. <template slot="lockFlag"
  56. slot-scope="scope">
  57. <el-tag>{{scope.label}}</el-tag>
  58. </template>
  59. <template slot="menu"
  60. slot-scope="scope">
  61. <el-button v-if="sys_user_edit"
  62. size="small"
  63. type="success"
  64. @click="handleUpdate(scope.row,scope.index)">编辑
  65. </el-button>
  66. <el-button v-if="sys_user_del"
  67. size="small"
  68. type="danger"
  69. @click="deletes(scope.row,scope.index)">删除
  70. </el-button>
  71. </template>
  72. <template slot="deptIdForm"
  73. slot-scope="scope">
  74. <avue-crud-input v-model="form.deptId"
  75. type="tree"
  76. placeholder="请选择所属部门"
  77. :node-click="getNodeData"
  78. :dic="treeDeptData"
  79. :props="defaultProps"></avue-crud-input>
  80. </template>
  81. <template slot="roleForm"
  82. slot-scope="scope">
  83. <avue-crud-select v-model="role"
  84. multiple
  85. placeholder="请选择角色,要先选择部门"
  86. :dic="rolesOptions"
  87. :props="roleProps"></avue-crud-select>
  88. </template>
  89. </avue-crud>
  90. </basic-container>
  91. </div>
  92. </template>
  93. <script>
  94. import { fetchList, getObj, addObj, putObj, delObj } from "@/api/user";
  95. import { deptRoleList, fetchDeptTree } from "@/api/role";
  96. import { tableOption } from '@/const/crud/user';
  97. import { mapGetters } from "vuex";
  98. import { constants } from 'fs';
  99. import { connect } from 'tls';
  100. export default {
  101. name: "table_user",
  102. data () {
  103. return {
  104. option: tableOption,
  105. treeDeptData: [],
  106. checkedKeys: [],
  107. roleProps: {
  108. label: "roleDesc",
  109. value: 'roleId'
  110. },
  111. defaultProps: {
  112. label: "name",
  113. value: 'id',
  114. },
  115. page: {
  116. total: 0, // 总页数
  117. currentPage: 1, // 当前页数
  118. pageSize: 20, // 每页显示多少条,
  119. isAsc: false//是否倒序
  120. },
  121. list: [],
  122. listLoading: true,
  123. role: [],
  124. form: {},
  125. rolesOptions: [],
  126. };
  127. },
  128. computed: {
  129. ...mapGetters(["permissions"])
  130. },
  131. watch: {
  132. role () {
  133. this.form.role = this.role
  134. }
  135. },
  136. filters: {
  137. statusFilter (status) {
  138. const statusMap = {
  139. 0: "有效",
  140. 1: "无效",
  141. 9: "锁定"
  142. };
  143. return statusMap[status];
  144. }
  145. },
  146. created () {
  147. this.sys_user_add = this.permissions["sys_user_add"];
  148. this.sys_user_edit = this.permissions["sys_user_edit"];
  149. this.sys_user_del = this.permissions["sys_user_del"];
  150. },
  151. methods: {
  152. getList (page, params) {
  153. this.listLoading = true;
  154. fetchList(Object.assign({
  155. page: page.currentPage,
  156. limit: page.pageSize
  157. }, params)).then(response => {
  158. this.list = response.data.data.records;
  159. this.page.total = response.data.data.total
  160. this.listLoading = false;
  161. });
  162. },
  163. getNodeData (data) {
  164. deptRoleList().then(response => {
  165. this.rolesOptions = response.data.data;
  166. });
  167. },
  168. handleDept () {
  169. fetchDeptTree().then(response => {
  170. this.treeDeptData = response.data.data;
  171. });
  172. },
  173. handleFilter (param) {
  174. this.page.page = 1;
  175. this.getList(this.page, param);
  176. },
  177. handleRefreshChange () {
  178. this.getList(this.page)
  179. },
  180. handleCreate () {
  181. this.$refs.crud.rowAdd();
  182. },
  183. handleOpenBefore (show, type) {
  184. window.boxType = type;
  185. this.handleDept();
  186. if (['edit', 'views'].includes(type)) {
  187. this.role = [];
  188. for (var i = 0; i < this.form.roleList.length; i++) {
  189. this.role[i] = this.form.roleList[i].roleId;
  190. }
  191. deptRoleList().then(response => {
  192. this.rolesOptions = response.data;
  193. });
  194. } else if (type === 'add') {
  195. this.role = [];
  196. }
  197. show();
  198. },
  199. handleUpdate (row, index) {
  200. this.$refs.crud.rowEdit(row, index);
  201. this.form.password = undefined
  202. },
  203. create (row, done, loading) {
  204. addObj(this.form).then(() => {
  205. this.getList();
  206. done();
  207. this.$notify({
  208. title: "成功",
  209. message: "创建成功",
  210. type: "success",
  211. duration: 2000
  212. });
  213. }).catch(() => {
  214. loading();
  215. });
  216. },
  217. update (row, index, done, loading) {
  218. putObj(this.form).then(() => {
  219. this.getList();
  220. done();
  221. this.$notify({
  222. title: "成功",
  223. message: "修改成功",
  224. type: "success",
  225. duration: 2000
  226. });
  227. }).catch(() => {
  228. loading();
  229. });
  230. },
  231. deletes (row, index) {
  232. this.$confirm(
  233. "此操作将永久删除该用户(用户名:" + row.username + "), 是否继续?",
  234. "提示",
  235. {
  236. confirmButtonText: "确定",
  237. cancelButtonText: "取消",
  238. type: "warning"
  239. }
  240. ).then(() => {
  241. delObj(row.userId)
  242. .then(() => {
  243. this.list.splice(index, 1);
  244. this.$notify({
  245. title: "成功",
  246. message: "删除成功",
  247. type: "success",
  248. duration: 2000
  249. });
  250. })
  251. .cache(() => {
  252. this.$notify({
  253. title: "失败",
  254. message: "删除失败",
  255. type: "error",
  256. duration: 2000
  257. });
  258. });
  259. });
  260. }
  261. }
  262. };
  263. </script>