|
|
@@ -1,36 +1,42 @@
|
|
|
+import Service from '@/pages/system/User/serivce';
|
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
|
-import { useEffect, useRef, useState } from 'react';
|
|
|
+import SearchComponent from '@/components/SearchComponent';
|
|
|
+import type { ActionType, ProColumns } from '@jetlinks/pro-table';
|
|
|
+import ProTable from '@jetlinks/pro-table';
|
|
|
+import { Button, Card, message, Popconfirm, Tooltip } from 'antd';
|
|
|
import {
|
|
|
+ CloseCircleOutlined,
|
|
|
EditOutlined,
|
|
|
KeyOutlined,
|
|
|
- CloseCircleOutlined,
|
|
|
PlayCircleOutlined,
|
|
|
+ PlusOutlined,
|
|
|
} from '@ant-design/icons';
|
|
|
-import { Tooltip, Popconfirm, message, Drawer } from 'antd';
|
|
|
-import type { ProColumns, ActionType } from '@jetlinks/pro-table';
|
|
|
-import BaseCrud from '@/components/BaseCrud';
|
|
|
-import { CurdModel } from '@/components/BaseCrud/model';
|
|
|
-import BaseService from '@/utils/BaseService';
|
|
|
-import { observer } from '@formily/react';
|
|
|
-import { Store } from 'jetlinks-store';
|
|
|
-import SystemConst from '@/utils/const';
|
|
|
-import { useIntl } from '@@/plugin-locale/localeExports';
|
|
|
-import type { ISchema } from '@formily/json-schema';
|
|
|
-import Authorization from '@/components/Authorization';
|
|
|
import autzModel from '@/components/Authorization/autz';
|
|
|
-// import SearchComponent from '@/components/SearchComponent';
|
|
|
+import { useIntl } from '@@/plugin-locale/localeExports';
|
|
|
+import { useRef, useState } from 'react';
|
|
|
+import Save from './Save';
|
|
|
+import { observer } from '@formily/react';
|
|
|
+
|
|
|
+export const service = new Service('user');
|
|
|
|
|
|
-export const service = new BaseService<UserItem>('user');
|
|
|
const User = observer(() => {
|
|
|
const intl = useIntl();
|
|
|
const actionRef = useRef<ActionType>();
|
|
|
|
|
|
- const [model1, setModel] = useState(CurdModel.model);
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- const modelSubscription = Store.subscribe(SystemConst.BASE_CURD_MODEL, setModel);
|
|
|
- return () => modelSubscription.unsubscribe();
|
|
|
- }, [CurdModel.model]);
|
|
|
+ const [model, setMode] = useState<'add' | 'edit' | 'query'>('query');
|
|
|
+ const [current, setCurrent] = useState<Partial<UserItem>>({});
|
|
|
+ const edit = async (record: UserItem) => {
|
|
|
+ setMode('edit');
|
|
|
+ setCurrent(record);
|
|
|
+ // const response: Response<UserItem> = await service.queryDetail(record.id);
|
|
|
+ // if (response.status === 200) {
|
|
|
+ // const temp = response.result as UserItem;
|
|
|
+ // temp.orgIdList = (temp.orgList as { id: string, name: string }[]).map((item) => item.id);
|
|
|
+ // temp.roleIdList = (temp.roleList as { id: string, name: string }[]).map(item => item.id);
|
|
|
+ // state.model = 'edit';
|
|
|
+ // state.current = temp;
|
|
|
+ // }
|
|
|
+ };
|
|
|
|
|
|
const columns: ProColumns<UserItem>[] = [
|
|
|
{
|
|
|
@@ -133,14 +139,7 @@ const User = observer(() => {
|
|
|
align: 'center',
|
|
|
width: 200,
|
|
|
render: (text, record) => [
|
|
|
- <a
|
|
|
- key="editable"
|
|
|
- onClick={() => {
|
|
|
- CurdModel.update(record);
|
|
|
- CurdModel.model = 'edit';
|
|
|
- setModel('edit');
|
|
|
- }}
|
|
|
- >
|
|
|
+ <a key="editable" onClick={() => edit(record)}>
|
|
|
<Tooltip
|
|
|
title={intl.formatMessage({
|
|
|
id: 'pages.data.option.edit',
|
|
|
@@ -201,132 +200,39 @@ const User = observer(() => {
|
|
|
},
|
|
|
];
|
|
|
|
|
|
- const schema: ISchema = {
|
|
|
- type: 'object',
|
|
|
- properties: {
|
|
|
- username: {
|
|
|
- title: intl.formatMessage({
|
|
|
- id: 'pages.system.username',
|
|
|
- defaultMessage: '用户名',
|
|
|
- }),
|
|
|
- type: 'string',
|
|
|
- 'x-decorator': 'FormItem',
|
|
|
- 'x-component': 'Input',
|
|
|
- 'x-component-props': {
|
|
|
- disabled: model1 === 'edit',
|
|
|
- },
|
|
|
- 'x-decorator-props': {},
|
|
|
- name: 'username',
|
|
|
- required: true,
|
|
|
- },
|
|
|
- name: {
|
|
|
- title: intl.formatMessage({
|
|
|
- id: 'pages.system.name',
|
|
|
- defaultMessage: '姓名',
|
|
|
- }),
|
|
|
- type: 'string',
|
|
|
- 'x-decorator': 'FormItem',
|
|
|
- 'x-component': 'Input',
|
|
|
- 'x-component-props': {},
|
|
|
- 'x-decorator-props': {},
|
|
|
- name: 'name',
|
|
|
- required: true,
|
|
|
- },
|
|
|
- password: {
|
|
|
- type: 'string',
|
|
|
- title: intl.formatMessage({
|
|
|
- id: 'pages.system.password',
|
|
|
- defaultMessage: '密码',
|
|
|
- }),
|
|
|
- 'x-decorator': 'FormItem',
|
|
|
- 'x-component': 'Password',
|
|
|
- 'x-component-props': {
|
|
|
- checkStrength: true,
|
|
|
- },
|
|
|
- // 'x-hidden': model === 'edit',
|
|
|
- 'x-reactions': [
|
|
|
- {
|
|
|
- dependencies: ['.confirmPassword'],
|
|
|
- fulfill: {
|
|
|
- state: {
|
|
|
- errors:
|
|
|
- '{{$deps[0] && $self.value && $self.value !==$deps[0] ? "确认密码不匹配" : ""}}',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- ],
|
|
|
- 'x-decorator-props': {},
|
|
|
- name: 'password',
|
|
|
- required: false,
|
|
|
- },
|
|
|
- confirmPassword: {
|
|
|
- type: 'string',
|
|
|
- title: intl.formatMessage({
|
|
|
- id: 'pages.system.confirmPassword',
|
|
|
- defaultMessage: '确认密码?',
|
|
|
- }),
|
|
|
- 'x-decorator': 'FormItem',
|
|
|
- 'x-component': 'Password',
|
|
|
- // 'x-hidden': model === 'edit',
|
|
|
- 'x-component-props': {
|
|
|
- checkStrength: true,
|
|
|
- },
|
|
|
- 'x-reactions': [
|
|
|
- {
|
|
|
- dependencies: ['.password'],
|
|
|
- fulfill: {
|
|
|
- state: {
|
|
|
- errors:
|
|
|
- '{{$deps[0] && $self.value && $self.value !== $deps[0] ? "确认密码不匹配" : ""}}',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- ],
|
|
|
- 'x-decorator-props': {},
|
|
|
- name: 'confirmPassword',
|
|
|
- required: false,
|
|
|
- },
|
|
|
- },
|
|
|
- };
|
|
|
-
|
|
|
- intl.formatMessage({
|
|
|
- id: 'pages.system.user',
|
|
|
- defaultMessage: '默认值',
|
|
|
- });
|
|
|
+ const [param, setParam] = useState({});
|
|
|
return (
|
|
|
<PageContainer>
|
|
|
- <BaseCrud<UserItem>
|
|
|
- actionRef={actionRef}
|
|
|
+ <Card style={{ marginBottom: '20px' }}>
|
|
|
+ <SearchComponent
|
|
|
+ field={columns}
|
|
|
+ onSearch={(data) => setParam({ terms: data })}
|
|
|
+ target="user"
|
|
|
+ />
|
|
|
+ </Card>
|
|
|
+ <ProTable<UserItem>
|
|
|
+ params={param}
|
|
|
columns={columns}
|
|
|
search={false}
|
|
|
- service={service}
|
|
|
- title={intl.formatMessage({
|
|
|
- id: 'pages.system.user',
|
|
|
- defaultMessage: '用户管理',
|
|
|
- })}
|
|
|
- moduleName="user"
|
|
|
- schema={schema}
|
|
|
+ request={async (params = {}) => service.query(params)}
|
|
|
+ toolBarRender={() => [
|
|
|
+ <Button
|
|
|
+ onClick={() => {
|
|
|
+ setMode('add');
|
|
|
+ }}
|
|
|
+ key="button"
|
|
|
+ icon={<PlusOutlined />}
|
|
|
+ type="primary"
|
|
|
+ >
|
|
|
+ {intl.formatMessage({
|
|
|
+ id: 'pages.data.option.add',
|
|
|
+ defaultMessage: '新增',
|
|
|
+ })}
|
|
|
+ </Button>,
|
|
|
+ ]}
|
|
|
/>
|
|
|
- <Drawer
|
|
|
- title={intl.formatMessage({
|
|
|
- id: 'pages.data.option.authorize',
|
|
|
- defaultMessage: '授权',
|
|
|
- })}
|
|
|
- width="50vw"
|
|
|
- visible={autzModel.visible}
|
|
|
- onClose={() => {
|
|
|
- autzModel.visible = false;
|
|
|
- }}
|
|
|
- >
|
|
|
- <Authorization
|
|
|
- close={() => {
|
|
|
- autzModel.visible = false;
|
|
|
- }}
|
|
|
- target={autzModel.autzTarget}
|
|
|
- />
|
|
|
- </Drawer>
|
|
|
+ <Save model={model} close={() => setMode('query')} data={current} />
|
|
|
</PageContainer>
|
|
|
);
|
|
|
});
|
|
|
-
|
|
|
export default User;
|