index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <a-card class="account-page-card">
  3. <Action :btn_text="'新建用户组'" @searchClick="searchClick" @resetClick="resetClick" @createClick="createClick"
  4. @sizeChange="table_size_change" @refreshClick="refreshClick"></Action>
  5. <DataTable :data="table_data" :columns="table_columns" row-key="userId" :size="table_size" :loading="table_loading"
  6. :pagination="pagination_props" @pageChange="handlePageChange">
  7. <template #status="{ record }">
  8. <a-switch v-model="record.status" @change="statusChange(record)" checked-value="1" unchecked-value="0" />
  9. </template>
  10. <template #operationSlot="{ record }">
  11. <a-popconfirm content="确定重置该账号密码吗?" @ok="handleResetPassword(record)">
  12. <a-button type="text">重制密码</a-button>
  13. </a-popconfirm>
  14. <a-button type="text" @click="handleEdit(record, true)">编辑</a-button>
  15. <a-button type="text" @click="handlePermissionConfig(record, true)">权限配置</a-button>
  16. <a-button type="text" @click="handleDeptConfig(record, true)">部门配置</a-button>
  17. <a-popconfirm content="确定删除该条数据吗?" type="warning" @ok="handleDelete(record.userId)">
  18. <a-button type="text" status="warning">删除</a-button>
  19. </a-popconfirm>
  20. </template>
  21. </DataTable>
  22. </a-card>
  23. <Modal :visible.sync="edit_visible" @ok="editModalSave" @cancel="handleEdit(null, false)" :title="'编辑'">
  24. <AccountForm :edit_form="edit_form" />
  25. </Modal>
  26. <!-- TODO -->
  27. <PermissionConfigModal :visible.sync="permission_config_visible" @cancel="handlePermissionConfig(null, false)" />
  28. <DeptConfigModal :visible.sync="dept_config_visible" :dept_list="dept_list" :record="current_record" @ok=""
  29. @cancel="handleDeptConfig(null, false)" />
  30. </template>
  31. <script setup>
  32. import { ref, reactive, onMounted } from 'vue';
  33. import { Message } from '@arco-design/web-vue';
  34. import DataTable from '../../../views/permission/DataTable.vue';
  35. import Action from '../../../views/permission/Action.vue';
  36. import Modal from '../Modal.vue';
  37. import AccountForm from './AccountForm.vue';
  38. import PermissionConfigModal from './PermissionConfigModal.vue';
  39. import DeptConfigModal from './DeptConfigModal.vue';
  40. import { QueryRoleList, } from '../../../apis/permission/role';
  41. const keywords = ref('');
  42. // 表格相关
  43. const table_data = ref([]);
  44. const table_columns = ref([
  45. { title: '序号', slotName: 'index' },
  46. { title: '用户名', dataIndex: 'userName', titleSlotName: 'userName' },
  47. { title: '角色', dataIndex: 'roleName', titleSlotName: 'roleName' },
  48. { title: '所属部门', dataIndex: 'deptName', titleSlotName: 'deptName' },
  49. { title: '状态', dataIndex: 'status', slotName: 'status' },
  50. { title: '操作', dataIndex: 'operation', slotName: 'operationSlot' },
  51. ]);
  52. const pagination_props = ref({
  53. total: 10,
  54. current: 1,
  55. pageSize: 12,
  56. })
  57. const table_size = ref('medium');
  58. const table_loading = ref(false);
  59. // 编辑表单相关
  60. const edit_visible = ref(false);
  61. const edit_form = reactive({
  62. userName: '',
  63. userName: '',
  64. phone: '',
  65. email: '',
  66. pwd: '',
  67. role: []
  68. });
  69. // 权限配置相关
  70. const permission_config_visible = ref(false);
  71. const menu_permissions_list = ref([])
  72. const knowledge_permissions_list = ref([])
  73. const dialog_permissions_list = ref([])
  74. const agent_permissions_list = ref([])
  75. // 部门配置相关
  76. const dept_config_visible = ref(false);
  77. const current_record = ref(null);
  78. const dept_list = ref([
  79. {
  80. "address": null,
  81. "children": [
  82. {
  83. "address": "",
  84. "children": [],
  85. "code": null,
  86. "createTime": "Thu, 12 Sep 2024 14:56:43 GMT",
  87. "deptId": "2af7cb5e-1178-4adc-8abb-9780f7543081",
  88. "deptName": "成都",
  89. "email": "",
  90. "iconCls": null,
  91. "leader": "成都",
  92. "orderNum": 0,
  93. "parentId": "0",
  94. "parentName": "总部",
  95. "phone": "成都",
  96. "roles": [],
  97. "status": "",
  98. "updateTime": "Thu, 12 Sep 2024 14:56:43 GMT"
  99. },
  100. {
  101. "address": null,
  102. "children": [],
  103. "code": null,
  104. "createTime": "Sun, 22 May 2022 09:59:33 GMT",
  105. "deptId": "5477d9a9-e41e-485f-bb08-697e8facef88",
  106. "deptName": "南京分公司",
  107. "email": "ss@ada.com",
  108. "iconCls": null,
  109. "leader": "dd",
  110. "orderNum": 0,
  111. "parentId": "0",
  112. "parentName": "总部",
  113. "phone": "18905189016",
  114. "roles": [],
  115. "status": "0",
  116. "updateTime": "Tue, 12 Nov 2024 03:05:10 GMT"
  117. },
  118. {
  119. "address": null,
  120. "children": [
  121. {
  122. "address": "",
  123. "children": [
  124. {
  125. "address": "",
  126. "children": [],
  127. "code": null,
  128. "createTime": "Tue, 12 Nov 2024 03:09:57 GMT",
  129. "deptId": "c6ae93de-2436-4090-b567-ec4835c74112",
  130. "deptName": "成都",
  131. "email": "",
  132. "iconCls": null,
  133. "leader": "柔柔弱弱",
  134. "orderNum": 0,
  135. "parentId": "f86724f0-94d9-445c-9d95-3ec2540da0f8",
  136. "parentName": "太平洋派出所",
  137. "phone": "1234242342",
  138. "roles": [],
  139. "status": "",
  140. "updateTime": "Tue, 12 Nov 2024 06:58:15 GMT"
  141. }
  142. ],
  143. "code": null,
  144. "createTime": "Thu, 05 Sep 2024 03:15:13 GMT",
  145. "deptId": "f86724f0-94d9-445c-9d95-3ec2540da0f8",
  146. "deptName": "太平洋派出所",
  147. "email": "",
  148. "iconCls": null,
  149. "leader": "12",
  150. "orderNum": 0,
  151. "parentId": "ce627e90-57d6-4ed4-a789-1f3dd467ae7d",
  152. "parentName": "上海分公司",
  153. "phone": "12",
  154. "roles": [
  155. {
  156. "deptId": "f86724f0-94d9-445c-9d95-3ec2540da0f8",
  157. "roleId": "19f00d46-8f1b-45b5-b7b7-6197d7b8cb33",
  158. "roleName": "管理员1"
  159. }
  160. ],
  161. "status": "0",
  162. "updateTime": "Tue, 12 Nov 2024 06:58:07 GMT"
  163. }
  164. ],
  165. "code": null,
  166. "createTime": "Tue, 24 May 2022 23:54:10 GMT",
  167. "deptId": "ce627e90-57d6-4ed4-a789-1f3dd467ae7d",
  168. "deptName": "上海分公司",
  169. "email": null,
  170. "iconCls": null,
  171. "leader": "jack",
  172. "orderNum": 0,
  173. "parentId": "0",
  174. "parentName": "总部",
  175. "phone": null,
  176. "roles": [
  177. {
  178. "deptId": "ce627e90-57d6-4ed4-a789-1f3dd467ae7d",
  179. "roleId": "301ca518-2ed0-4092-a2ee-e46c24a42c8a",
  180. "roleName": "普通"
  181. }
  182. ],
  183. "status": "0",
  184. "updateTime": "Wed, 18 Sep 2024 09:58:16 GMT"
  185. }
  186. ],
  187. "code": null,
  188. "createTime": "Mon, 28 Nov 2016 10:34:54 GMT",
  189. "deptId": "0",
  190. "deptName": "总部",
  191. "email": null,
  192. "iconCls": "ext-icon-bricks",
  193. "leader": null,
  194. "orderNum": 100,
  195. "parentId": "",
  196. "parentName": "",
  197. "phone": null,
  198. "roles": [],
  199. "status": "0",
  200. "updateTime": "Mon, 28 Nov 2016 10:35:12 GMT"
  201. }
  202. ]);
  203. const getUserList = async () => {
  204. const params = {
  205. keyword: keywords.value,
  206. current: pagination_props.value.current,
  207. pageSize: pagination_props.value.pageSize,
  208. };
  209. table_loading.value = true
  210. const { code, data } = await QueryRoleList(params);
  211. if (code === 200) {
  212. pagination_props.value.total = data.total;
  213. table_data.value = data.rows;
  214. table_loading.value = false
  215. } else {
  216. table_loading.value = false
  217. }
  218. }
  219. const searchClick = (value) => {
  220. keywords.value = value;
  221. getUserList();
  222. }
  223. const resetClick = () => {
  224. keywords.value = '';
  225. getUserList();
  226. }
  227. const createClick = () => {
  228. edit_form.userName = '';
  229. edit_form.loginName = '';
  230. edit_form.phone = '';
  231. edit_form.email = '';
  232. edit_form.pwd = '';
  233. edit_form.role = [];
  234. edit_visible.value = true;
  235. }
  236. const refreshClick = () => {
  237. console.log('刷新')
  238. }
  239. // 切换页码
  240. const handlePageChange = (current) => {
  241. pagination_props.value.current = current;
  242. getUserList();
  243. };
  244. // TODO功能 状态切换拦截
  245. const beforeStatusChange = async () => {
  246. await new Promise((resolve, reject) => setTimeout(() => {
  247. resolve()
  248. }, 1000))
  249. }
  250. // 用户状态切换
  251. const statusChange = async (record) => {
  252. if (record?.dept) {
  253. const params = {
  254. userId: record.userId,
  255. status: record.status,
  256. };
  257. const { code } = await UserStatusSwitch(params)
  258. if (code === 200) {
  259. Message.success({
  260. title: '成功',
  261. content: '状态切换成功.',
  262. });
  263. }
  264. } else {
  265. }
  266. };
  267. //重置密码
  268. const handleResetPassword = async (record) => {
  269. const { code } = await ResetPassword(record.userId);
  270. if (code === 200) {
  271. Message.success({
  272. title: '重置密码',
  273. content: '该用户密码重置为000000',
  274. });
  275. }
  276. }
  277. const handleEdit = (record, visible) => {
  278. if (record) {
  279. edit_form.userName = record.userName;
  280. edit_form.loginName = record.loginName;
  281. edit_form.phone = record.phone;
  282. edit_form.email = record.email;
  283. edit_form.pwd = record.pwd;
  284. edit_form.role = record.role;
  285. }
  286. edit_visible.value = visible;
  287. }
  288. // 权限配置
  289. const handlePermissionConfig = async (record, visible) => {
  290. if (record) {
  291. const { code, data } = await QueryUserPermission(record.userId);
  292. if (code === 200) {
  293. const { knowledge, menu, dialog } = data;
  294. if (dialog && dialog.length > 0) dialog_permissions_list.value = dialog
  295. if (menu && menu.length > 0) menu_permissions_list.value = menu
  296. if (knowledge && knowledge.length > 0) knowledge_permissions_list.value = knowledge
  297. }
  298. }
  299. permission_config_visible.value = visible;
  300. }
  301. // 部门配置
  302. const handleDeptConfig = async (record, visible) => {
  303. if (record) {
  304. current_record.value = record;
  305. const { code, data: { rows } } = await QueryUserDept(record.userId);
  306. if (code === 200) {
  307. // TODO接口 机构接上再接这个
  308. console.log('rows', rows)
  309. // dept_list.value = rows;
  310. }
  311. }
  312. dept_config_visible.value = visible;
  313. }
  314. // 删除用户
  315. const handleDelete = async (userId) => {
  316. const { code } = await DeleteUser(userId);
  317. if (code === 200) {
  318. Message.success({
  319. title: '删除用户',
  320. content: '该用户已删除',
  321. });
  322. getUserList();
  323. }
  324. }
  325. const editModalSave = () => {
  326. edit_visible.value = false;
  327. }
  328. const table_size_change = (size) => {
  329. table_size.value = size;
  330. }
  331. onMounted(() => {
  332. getUserList()
  333. })
  334. </script>
  335. <style lang="css" scoped>
  336. .account-page-card {
  337. height: calc(100% - 40px);
  338. }
  339. </style>