|
@@ -10,6 +10,7 @@ import {
|
|
|
fetchGetRoleAllList,
|
|
|
fetchGetUserList
|
|
|
} from '@/service/api';
|
|
|
+import { fetchGetDepartmentList } from '@/service/api/system-department';
|
|
|
import { useTable } from '@/components/zt/Table/hooks/useTable';
|
|
|
import { $t } from '@/locales';
|
|
|
import { useModalFrom } from '@/components/zt/ModalForm/hooks/useModalForm';
|
|
@@ -67,18 +68,26 @@ const columns: NaiveUI.TableColumn<InternalRowData>[] = [
|
|
|
}
|
|
|
}
|
|
|
];
|
|
|
+
|
|
|
const [registerTable, { refresh, setTableLoading }] = useTable({
|
|
|
- schemas: [
|
|
|
- {
|
|
|
- field: 'username',
|
|
|
- label: '用户名',
|
|
|
- component: 'NInput'
|
|
|
- }
|
|
|
- ],
|
|
|
- inline: false,
|
|
|
- size: 'small',
|
|
|
- labelPlacement: 'left',
|
|
|
- isFull: false
|
|
|
+ searchFormConfig: {
|
|
|
+ schemas: [
|
|
|
+ {
|
|
|
+ field: 'username',
|
|
|
+ label: '用户名',
|
|
|
+ component: 'NInput'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ inline: false,
|
|
|
+ size: 'small',
|
|
|
+ labelPlacement: 'left',
|
|
|
+ isFull: false
|
|
|
+ },
|
|
|
+ tableConfig: {
|
|
|
+ keyField: 'userId',
|
|
|
+ title: '用户列表',
|
|
|
+ showAddButton: true
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
async function handleDelete(row: Recordable) {
|
|
@@ -86,133 +95,149 @@ async function handleDelete(row: Recordable) {
|
|
|
await fetchDeleteUser(row.userId);
|
|
|
refresh();
|
|
|
}
|
|
|
-const [registerModalForm, { openModal, closeModal, getFieldsValue, setFieldsValue, updateSchema }] = useModalFrom({
|
|
|
- modalConfig: {
|
|
|
- title: '用户 ',
|
|
|
- width: 800
|
|
|
- },
|
|
|
- formConfig: {
|
|
|
- schemas: [
|
|
|
- {
|
|
|
- field: 'userId',
|
|
|
- label: '',
|
|
|
- component: 'NInput',
|
|
|
- show: false
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'username',
|
|
|
- label: '用户名',
|
|
|
- component: 'NInput',
|
|
|
- required: true,
|
|
|
- rules: [
|
|
|
- {
|
|
|
- required: true,
|
|
|
- message: '请输入用户名',
|
|
|
- trigger: ['blur', 'input'],
|
|
|
- validator: (rule, value) => {
|
|
|
- return new Promise<void>((resolve, reject) => {
|
|
|
- if (value.length < 2) {
|
|
|
- console.log(rule);
|
|
|
+const [registerModalForm, { openModal, closeModal, getFieldsValue, setFieldsValue, updateSchema, setModalLoading }] =
|
|
|
+ useModalFrom({
|
|
|
+ modalConfig: {
|
|
|
+ title: '用户 ',
|
|
|
+ width: 800,
|
|
|
+ isShowHeaderText: true
|
|
|
+ },
|
|
|
+ formConfig: {
|
|
|
+ schemas: [
|
|
|
+ {
|
|
|
+ field: 'userId',
|
|
|
+ label: '',
|
|
|
+ component: 'NInput',
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'username',
|
|
|
+ label: '用户名',
|
|
|
+ component: 'NInput',
|
|
|
+ required: true,
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '请输入用户名',
|
|
|
+ trigger: ['blur', 'input'],
|
|
|
+ validator: (rule, value) => {
|
|
|
+ return new Promise<void>((resolve, reject) => {
|
|
|
+ if (value.length < 2) {
|
|
|
+ console.log(rule);
|
|
|
|
|
|
- reject(new Error('用户名不能低于2位'));
|
|
|
- }
|
|
|
- if (value.length > 20) {
|
|
|
- reject(new Error('用户名不能高于20位'));
|
|
|
- }
|
|
|
- resolve();
|
|
|
- });
|
|
|
+ reject(new Error('用户名不能低于2位'));
|
|
|
+ }
|
|
|
+ if (value.length > 20) {
|
|
|
+ reject(new Error('用户名不能高于20位'));
|
|
|
+ }
|
|
|
+ resolve();
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'deptIds',
|
|
|
+ label: '归属部门',
|
|
|
+ component: 'ApiTreeSelect',
|
|
|
+ required: true,
|
|
|
+ componentProps: {
|
|
|
+ api: fetchGetDepartmentList,
|
|
|
+ labelFeild: 'deptName',
|
|
|
+ valueFeild: 'deptId',
|
|
|
+ immediate: true,
|
|
|
+ resultFeild: 'data',
|
|
|
+ multiple: true
|
|
|
}
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'password',
|
|
|
- label: '密码',
|
|
|
- component: 'NInput',
|
|
|
- required: true,
|
|
|
- componentProps: {
|
|
|
- type: 'password',
|
|
|
- showPasswordOn: 'click'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'comfirmPassword',
|
|
|
- label: '确认密码',
|
|
|
- component: 'NInput',
|
|
|
- required: true,
|
|
|
- componentProps: {
|
|
|
- type: 'password',
|
|
|
- showPasswordOn: 'click'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'email',
|
|
|
- label: '邮箱',
|
|
|
- component: 'NInput',
|
|
|
- required: true,
|
|
|
- rules: [
|
|
|
- {
|
|
|
- pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
|
|
|
- type: 'email',
|
|
|
- message: '请输入正确的邮箱地址',
|
|
|
- trigger: ['blur', 'input']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'password',
|
|
|
+ label: '密码',
|
|
|
+ component: 'NInput',
|
|
|
+ required: true,
|
|
|
+ componentProps: {
|
|
|
+ type: 'password',
|
|
|
+ showPasswordOn: 'click'
|
|
|
}
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'mobile',
|
|
|
- label: '手机号',
|
|
|
- component: 'NInput',
|
|
|
- required: true,
|
|
|
- componentProps: {
|
|
|
- maxlength: 11
|
|
|
},
|
|
|
- rules: [
|
|
|
- {
|
|
|
- pattern: /^1[3456789]\d{9}$/,
|
|
|
- message: '请输入正确的手机号',
|
|
|
- trigger: ['blur', 'input']
|
|
|
+ {
|
|
|
+ field: 'comfirmPassword',
|
|
|
+ label: '确认密码',
|
|
|
+ component: 'NInput',
|
|
|
+ required: true,
|
|
|
+ componentProps: {
|
|
|
+ type: 'password',
|
|
|
+ showPasswordOn: 'click'
|
|
|
}
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'roleIdList',
|
|
|
- label: '角色',
|
|
|
- component: 'ApiSelect',
|
|
|
- required: true,
|
|
|
- componentProps: {
|
|
|
- api: () => fetchGetRoleAllList(),
|
|
|
- labelFeild: 'roleName',
|
|
|
- valueFeild: 'roleId',
|
|
|
- multiple: true
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'status',
|
|
|
- label: '状态',
|
|
|
- component: 'NRadioGroup',
|
|
|
- required: true,
|
|
|
- componentProps: {
|
|
|
- options: [
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'email',
|
|
|
+ label: '邮箱',
|
|
|
+ component: 'NInput',
|
|
|
+ required: true,
|
|
|
+ rules: [
|
|
|
{
|
|
|
- label: '启用',
|
|
|
- value: 1
|
|
|
- },
|
|
|
+ pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
|
|
|
+ type: 'email',
|
|
|
+ message: '请输入正确的邮箱地址',
|
|
|
+ trigger: ['blur', 'input']
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'mobile',
|
|
|
+ label: '手机号',
|
|
|
+ component: 'NInput',
|
|
|
+ required: true,
|
|
|
+ componentProps: {
|
|
|
+ maxlength: 11
|
|
|
+ },
|
|
|
+ rules: [
|
|
|
{
|
|
|
- label: '禁用',
|
|
|
- value: 0
|
|
|
+ pattern: /^1[3456789]\d{9}$/,
|
|
|
+ message: '请输入正确的手机号',
|
|
|
+ trigger: ['blur', 'input']
|
|
|
}
|
|
|
]
|
|
|
},
|
|
|
- defaultValue: 1
|
|
|
+ {
|
|
|
+ field: 'roleIdList',
|
|
|
+ label: '角色',
|
|
|
+ component: 'ApiSelect',
|
|
|
+ required: true,
|
|
|
+ componentProps: {
|
|
|
+ api: () => fetchGetRoleAllList(),
|
|
|
+ labelFeild: 'roleName',
|
|
|
+ valueFeild: 'roleId',
|
|
|
+ multiple: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'status',
|
|
|
+ label: '状态',
|
|
|
+ component: 'NRadioGroup',
|
|
|
+ required: true,
|
|
|
+ componentProps: {
|
|
|
+ options: [
|
|
|
+ {
|
|
|
+ label: '启用',
|
|
|
+ value: 1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '禁用',
|
|
|
+ value: 0
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ defaultValue: 1
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ labelWidth: 120,
|
|
|
+ gridProps: {
|
|
|
+ cols: '1'
|
|
|
}
|
|
|
- ],
|
|
|
- labelWidth: 120,
|
|
|
- gridProps: {
|
|
|
- cols: '1'
|
|
|
}
|
|
|
- }
|
|
|
-});
|
|
|
+ });
|
|
|
async function handleSubmit() {
|
|
|
const form = await getFieldsValue();
|
|
|
if (form.userId) {
|
|
@@ -225,8 +250,10 @@ async function handleSubmit() {
|
|
|
}
|
|
|
|
|
|
async function edit(row: Recordable) {
|
|
|
- const res = await fetchDetaileUser(row.userId);
|
|
|
+ setModalLoading(true);
|
|
|
openModal(row);
|
|
|
+ const res = await fetchDetaileUser(row.userId);
|
|
|
+ setModalLoading(false);
|
|
|
setFieldsValue({ ...res.data, userId: row.userId });
|
|
|
updateSchema([
|
|
|
{ field: 'password', required: false },
|
|
@@ -237,19 +264,9 @@ async function edit(row: Recordable) {
|
|
|
|
|
|
<template>
|
|
|
<LayoutTable>
|
|
|
- <ZTable
|
|
|
- :table-config="{
|
|
|
- api: fetchGetUserList,
|
|
|
- columns: columns,
|
|
|
- keyField: 'userId',
|
|
|
- title: '用户列表',
|
|
|
- showAddButton: true
|
|
|
- }"
|
|
|
- @register="registerTable"
|
|
|
- @add="openModal"
|
|
|
- >
|
|
|
+ <ZTable :columns="columns" :api="fetchGetUserList" @register="registerTable" @add="openModal">
|
|
|
<template #op="{ row }">
|
|
|
- <NButton v-if="row.userId != 1" size="small" ghost type="primary" @click="edit(row)">编辑</NButton>
|
|
|
+ <NButton size="small" ghost type="primary" @click="edit(row)">编辑</NButton>
|
|
|
<NPopconfirm v-if="row.userId != 1" @positive-click="handleDelete(row)">
|
|
|
<template #trigger>
|
|
|
<NButton size="small" type="error" ghost>删除</NButton>
|