فهرست منبع

fix(user): fix user bug

Lind 3 سال پیش
والد
کامیت
a17d6acb5e
3فایلهای تغییر یافته به همراه157 افزوده شده و 89 حذف شده
  1. 54 38
      src/components/SearchComponent/index.tsx
  2. 57 10
      src/pages/system/User/Save/index.tsx
  3. 46 41
      src/pages/system/User/index.tsx

+ 54 - 38
src/components/SearchComponent/index.tsx

@@ -14,7 +14,7 @@ import {
 import { createForm } from '@formily/core';
 import GroupNameControl from '@/components/SearchComponent/GroupNameControl';
 import { DeleteOutlined, DoubleRightOutlined } from '@ant-design/icons';
-import { Button, Dropdown, Input as AInput, Menu, message, Popconfirm, Popover } from 'antd';
+import { Button, Dropdown, Menu, message, Popconfirm, Popover, Typography } from 'antd';
 import { useState } from 'react';
 import type { ProColumns } from '@jetlinks/pro-table';
 import type { EnumData } from '@/utils/typings';
@@ -24,8 +24,8 @@ import _ from 'lodash';
 import { useIntl } from '@@/plugin-locale/localeExports';
 
 const ui2Server = (source: SearchTermsUI): SearchTermsServer => [
-  { terms: source.terms1, type: source.type },
-  { terms: source.terms2 },
+  { terms: source.terms1 },
+  { terms: source.terms2, type: source.type },
 ];
 
 const server2Ui = (source: SearchTermsServer): SearchTermsUI => ({
@@ -61,7 +61,6 @@ const SearchComponent = <T extends Record<string, any>>({ field, onSearch, targe
   const [expand, setExpand] = useState<boolean>(true);
   const initForm = server2Ui([{ terms: [defaultTerm], type: 'and' }, { terms: [defaultTerm] }]);
   const [logVisible, setLogVisible] = useState<boolean>(false);
-  const [alias, setAlias] = useState<string>('');
   const [aliasVisible, setAliasVisible] = useState<boolean>(false);
   const [initParams, setInitParams] = useState<SearchTermsUI>(initForm);
   const [history, setHistory] = useState([]);
@@ -71,6 +70,8 @@ const SearchComponent = <T extends Record<string, any>>({ field, onSearch, targe
     initialValues: initParams,
   });
 
+  const historyForm = createForm();
+
   const queryHistory = async () => {
     const response = await service.history.query(`${target}-search`);
     if (response.status === 200) {
@@ -211,33 +212,38 @@ const SearchComponent = <T extends Record<string, any>>({ field, onSearch, targe
     setInitParams(log);
   };
   const historyDom = (
-    <Menu>
-      {history.map((item: SearchHistory) => (
-        <Menu.Item onClick={() => handleHistory(item)} key={item.id}>
-          <div
-            style={{
-              display: 'flex',
-              justifyContent: 'space-between',
-              alignItems: 'center',
-            }}
-          >
-            <span style={{ marginRight: '5px' }}>{item.name}</span>
-            <Popconfirm
-              onConfirm={async () => {
-                const response = await service.history.remove(`${target}-search`, item.key);
-                if (response.status === 200) {
-                  message.success('操作成功');
-                  const temp = history.filter((h: any) => h.key !== item.key);
-                  setHistory(temp);
-                }
+    <Menu style={{ width: '176px' }}>
+      {history.length > 0 ? (
+        history.map((item: SearchHistory) => (
+          <Menu.Item onClick={() => handleHistory(item)} key={item.id}>
+            <div
+              style={{
+                display: 'flex',
+                justifyContent: 'space-between',
+                alignItems: 'center',
+                width: '148px',
               }}
-              title={'确认删除吗?'}
             >
-              <DeleteOutlined />
-            </Popconfirm>
-          </div>
-        </Menu.Item>
-      ))}
+              <Typography.Text ellipsis={{ tooltip: item.name }}>{item.name}</Typography.Text>
+              <Popconfirm
+                onConfirm={async () => {
+                  const response = await service.history.remove(`${target}-search`, item.key);
+                  if (response.status === 200) {
+                    message.success('操作成功');
+                    const temp = history.filter((h: any) => h.key !== item.key);
+                    setHistory(temp);
+                  }
+                }}
+                title={'确认删除吗?'}
+              >
+                <DeleteOutlined />
+              </Popconfirm>
+            </div>
+          </Menu.Item>
+        ))
+      ) : (
+        <Menu.Item>暂无数据</Menu.Item>
+      )}
     </Menu>
   );
 
@@ -266,8 +272,10 @@ const SearchComponent = <T extends Record<string, any>>({ field, onSearch, targe
 
   const handleSaveLog = async () => {
     const value = await form.submit<SearchTermsUI>();
+    const value2 = await historyForm.submit<{ alias: string }>();
+    console.log(value2, 'test');
     const response = await service.history.save(`${target}-search`, {
-      name: alias,
+      name: value2.alias,
       content: JSON.stringify(value),
     });
     if (response.status === 200) {
@@ -279,7 +287,7 @@ const SearchComponent = <T extends Record<string, any>>({ field, onSearch, targe
   };
 
   const resetForm = async () => {
-    const temp = initParams;
+    const temp = initForm;
     temp.terms1 = temp.terms1.map(() => defaultTerm);
     temp.terms2 = temp.terms2.map(() => defaultTerm);
     setInitParams(temp);
@@ -298,6 +306,8 @@ const SearchComponent = <T extends Record<string, any>>({ field, onSearch, targe
               visible={logVisible}
               onVisibleChange={async (visible) => {
                 setLogVisible(visible);
+                const value = form.values;
+                setInitParams(value);
                 if (visible) {
                   await queryHistory();
                 }
@@ -309,20 +319,26 @@ const SearchComponent = <T extends Record<string, any>>({ field, onSearch, targe
             </Dropdown.Button>
             <Popover
               content={
-                <>
-                  <AInput.TextArea
-                    rows={3}
-                    value={alias}
-                    onChange={(e) => setAlias(e.target.value)}
+                <Form style={{ width: '217px' }} form={historyForm}>
+                  <SchemaField
+                    schema={{
+                      type: 'object',
+                      properties: {
+                        alias: {
+                          'x-decorator': 'FormItem',
+                          'x-component': 'Input.TextArea',
+                          maxLength: 50,
+                        },
+                      },
+                    }}
                   />
                   <Button onClick={handleSaveLog} type="primary" className={styles.saveLog}>
                     保存
                   </Button>
-                </>
+                </Form>
               }
               visible={aliasVisible}
               onVisibleChange={(visible) => {
-                setAlias('');
                 setInitParams(form.values);
                 setAliasVisible(visible);
               }}

+ 57 - 10
src/pages/system/User/Save/index.tsx

@@ -92,10 +92,18 @@ const Save = (props: Props) => {
         type: 'string',
         'x-decorator': 'FormItem',
         'x-component': 'Input',
-        'x-component-props': {},
-        'x-decorator-props': {},
         name: 'name',
-        required: true,
+        'x-validator': [
+          {
+            max: 50,
+            message: '最多可输入50个字符',
+          },
+          {
+            required: true,
+            message: '请输入姓名',
+          },
+        ],
+        // required: true,
       },
       username: {
         title: intl.formatMessage({
@@ -108,7 +116,16 @@ const Save = (props: Props) => {
         'x-component-props': {
           disabled: model === 'edit',
         },
-        'x-decorator-props': {},
+        'x-validator': [
+          {
+            max: 50,
+            message: '最多可输入50个字符',
+          },
+          {
+            required: true,
+            message: '请输入用户名',
+          },
+        ],
         name: 'username',
         required: true,
       },
@@ -124,20 +141,34 @@ const Save = (props: Props) => {
           checkStrength: true,
           placeholder: '********',
         },
-        required: model === 'add',
+        maxLength: 128,
+        minLength: 6,
         'x-reactions': [
           {
             dependencies: ['.confirmPassword'],
             fulfill: {
               state: {
                 selfErrors:
-                  '{{$deps[0] && $self.value && $self.value !==$deps[0] ? "确认密码不匹配" : ""}}',
+                  '{{$deps[0] && $self.value && $self.value !==$deps[0] ? "两次密码输入不一致" : ""}}',
               },
             },
           },
         ],
-        'x-decorator-props': {},
         name: 'password',
+        'x-validator': [
+          {
+            max: 128,
+            message: '密码最多可输入128位',
+          },
+          {
+            min: 6,
+            message: '密码不能少于6位',
+          },
+          {
+            required: model === 'add',
+            message: '请输入密码',
+          },
+        ],
       },
       confirmPassword: {
         type: 'string',
@@ -151,20 +182,35 @@ const Save = (props: Props) => {
           checkStrength: true,
           placeholder: '********',
         },
+        maxLength: 128,
+        minLength: 6,
+        'x-validator': [
+          {
+            max: 128,
+            message: '密码最多可输入128位',
+          },
+          {
+            min: 6,
+            message: '密码不能少于6位',
+          },
+          {
+            required: model === 'add',
+            message: '请输入确认密码',
+          },
+        ],
         'x-reactions': [
           {
             dependencies: ['.password'],
             fulfill: {
               state: {
                 selfErrors:
-                  '{{$deps[0] && $self.value && $self.value !== $deps[0] ? "确认密码不匹配" : ""}}',
+                  '{{$deps[0] && $self.value && $self.value !== $deps[0] ? "两次密码输入不一致" : ""}}',
               },
             },
           },
         ],
         'x-decorator-props': {},
         name: 'confirmPassword',
-        required: model === 'add',
       },
       roleIdList: {
         title: '角色',
@@ -240,10 +286,10 @@ const Save = (props: Props) => {
           defaultMessage: '操作成功',
         }),
       );
+      props.close();
     } else {
       message.error('操作失败!');
     }
-    props.close();
   };
 
   return (
@@ -256,6 +302,7 @@ const Save = (props: Props) => {
       visible={model !== 'query'}
       onCancel={props.close}
       onOk={save}
+      width="30vw"
     >
       <Form form={form} labelCol={4} wrapperCol={18}>
         <SchemaField schema={schema} scope={{ useAsyncDataSource, getRole, getOrg }} />

+ 46 - 41
src/pages/system/User/index.tsx

@@ -6,12 +6,11 @@ import ProTable from '@jetlinks/pro-table';
 import { Button, Card, message, Popconfirm, Tooltip } from 'antd';
 import {
   CloseCircleOutlined,
+  DeleteOutlined,
   EditOutlined,
-  KeyOutlined,
   PlayCircleOutlined,
   PlusOutlined,
 } from '@ant-design/icons';
-import autzModel from '@/components/Authorization/autz';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { useRef, useState } from 'react';
 import Save from './Save';
@@ -28,14 +27,6 @@ const User = observer(() => {
   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>[] = [
@@ -53,12 +44,12 @@ const User = observer(() => {
       copyable: true,
       ellipsis: true,
       align: 'center',
-      tip: intl.formatMessage({
-        id: 'pages.system.name.tips',
-        defaultMessage: '姓名过长会自动收缩',
-      }),
-      sorter: true,
-      defaultSortOrder: 'ascend',
+      // tip: intl.formatMessage({
+      //   id: 'pages.system.name.tips',
+      //   defaultMessage: '姓名过长会自动收缩',
+      // }),
+      // sorter: true,
+      // defaultSortOrder: 'ascend',
       formItemProps: {
         rules: [
           {
@@ -80,10 +71,10 @@ const User = observer(() => {
       copyable: true,
       ellipsis: true,
       align: 'center',
-      tip: intl.formatMessage({
-        id: 'pages.system.userName.tips',
-        defaultMessage: '用户名过长会自动收缩',
-      }),
+      // tip: intl.formatMessage({
+      //   id: 'pages.system.userName.tips',
+      //   defaultMessage: '用户名过长会自动收缩',
+      // }),
       formItemProps: {
         rules: [
           {
@@ -102,9 +93,9 @@ const User = observer(() => {
         defaultMessage: '状态',
       }),
       dataIndex: 'status',
-      filters: true,
+      // filters: true,
       align: 'center',
-      onFilter: true,
+      // onFilter: true,
       valueType: 'select',
       valueEnum: {
         all: {
@@ -131,6 +122,14 @@ const User = observer(() => {
       },
     },
     {
+      title: '创建时间',
+      dataIndex: 'createTime',
+      align: 'center',
+      sorter: true,
+      hideInTable: true,
+      defaultSortOrder: 'descend',
+    },
+    {
       title: intl.formatMessage({
         id: 'pages.data.option',
         defaultMessage: '操作',
@@ -149,23 +148,6 @@ const User = observer(() => {
             <EditOutlined />
           </Tooltip>
         </a>,
-        <a
-          key="auth"
-          onClick={() => {
-            autzModel.autzTarget.id = record.id;
-            autzModel.autzTarget.name = record.name;
-            autzModel.visible = true;
-          }}
-        >
-          <Tooltip
-            title={intl.formatMessage({
-              id: 'pages.data.option.authorize',
-              defaultMessage: '授权',
-            })}
-          >
-            <KeyOutlined />
-          </Tooltip>
-        </a>,
         <a key="changeState">
           <Popconfirm
             title={intl.formatMessage({
@@ -196,6 +178,19 @@ const User = observer(() => {
             </Tooltip>
           </Popconfirm>
         </a>,
+        <a key="delete">
+          <Popconfirm
+            onConfirm={async () => {
+              await service.remove(record.id);
+              actionRef.current?.reload();
+            }}
+            title="确认删除?"
+          >
+            <Tooltip title="删除">
+              <DeleteOutlined />
+            </Tooltip>
+          </Popconfirm>
+        </a>,
       ],
     },
   ];
@@ -211,10 +206,13 @@ const User = observer(() => {
         />
       </Card>
       <ProTable<UserItem>
+        actionRef={actionRef}
         params={param}
         columns={columns}
         search={false}
-        request={async (params = {}) => service.query(params)}
+        request={async (params) =>
+          service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
+        }
         toolBarRender={() => [
           <Button
             onClick={() => {
@@ -231,7 +229,14 @@ const User = observer(() => {
           </Button>,
         ]}
       />
-      <Save model={model} close={() => setMode('query')} data={current} />
+      <Save
+        model={model}
+        close={() => {
+          setMode('query');
+          actionRef.current?.reload();
+        }}
+        data={current}
+      />
     </PageContainer>
   );
 });