Pārlūkot izejas kodu

fix(System): format code

Lind 4 gadi atpakaļ
vecāks
revīzija
8ae05031c3

+ 6 - 3
src/components/BaseCrud/model.ts

@@ -1,9 +1,10 @@
 import type { Option } from '@/components/BaseCrud/index';
 import { Store } from 'jetlinks-store';
 import SystemConst from '@/utils/const';
+import { model } from '@formily/reactive';
 
-export const CurdModel = <Option>{
-  model: 'edit',
+export const CurdModel = model<Option>({
+  model: 'add',
   current: undefined,
   visible: false,
 
@@ -11,16 +12,18 @@ export const CurdModel = <Option>{
     Store.set(SystemConst.BASE_CURD_MODAL_VISIBLE, true);
     Store.set(SystemConst.BASE_CURD_CURRENT, {});
     Store.set(SystemConst.BASE_CURD_MODEL, 'add');
+    this.model = 'add';
   },
 
   update(current: any) {
     Store.set(SystemConst.BASE_CURD_MODEL, 'edit');
     Store.set(SystemConst.BASE_CURD_MODAL_VISIBLE, true);
     Store.set(SystemConst.BASE_CURD_CURRENT, current);
+    this.model = 'edit';
   },
 
   close() {
     Store.set(SystemConst.BASE_CURD_MODAL_VISIBLE, false);
     Store.set(SystemConst.BASE_CURD_CURRENT, {});
   },
-};
+});

+ 6 - 10
src/pages/system/Role/index.tsx

@@ -7,6 +7,7 @@ import BaseCrud from '@/components/BaseCrud';
 import { CurdModel } from '@/components/BaseCrud/model';
 import BaseService from '@/utils/BaseService';
 import { useIntl } from '@@/plugin-locale/localeExports';
+import { observer } from '@formily/react';
 
 const menu = (
   <Menu>
@@ -18,7 +19,7 @@ const menu = (
 
 const service = new BaseService<RoleItem>('dimension');
 
-const Role: React.FC = () => {
+const Role: React.FC = observer(() => {
   const intl = useIntl();
   const actionRef = useRef<ActionType>();
 
@@ -164,12 +165,12 @@ const Role: React.FC = () => {
         type: 'string',
         'x-decorator': 'FormItem',
         'x-component': 'Input',
-        'x-component-props': {},
+        'x-component-props': {
+          disabled: CurdModel.model === 'edit',
+        },
         'x-decorator-props': {},
         name: 'id',
         required: true,
-        _designableId: '1jq1ln7nzji',
-        'x-index': 0,
       },
       name: {
         title: intl.formatMessage({
@@ -183,8 +184,6 @@ const Role: React.FC = () => {
         'x-decorator-props': {},
         name: 'name',
         required: true,
-        _designableId: '9vf50ad9n1h',
-        'x-index': 1,
       },
       describe: {
         type: 'string',
@@ -200,8 +199,6 @@ const Role: React.FC = () => {
         'x-decorator-props': {},
         name: 'password',
         required: false,
-        _designableId: 'weg6kt6izlt',
-        'x-index': 2,
       },
       typeId: {
         type: 'string',
@@ -212,7 +209,6 @@ const Role: React.FC = () => {
         default: 'role',
       },
     },
-    _designableId: 'zd740kqp5hf',
   };
 
   return (
@@ -231,5 +227,5 @@ const Role: React.FC = () => {
       />
     </PageContainer>
   );
-};
+});
 export default Role;

+ 24 - 26
src/pages/system/User/index.tsx

@@ -6,7 +6,7 @@ import {
   CloseCircleOutlined,
   PlayCircleOutlined,
 } from '@ant-design/icons';
-import { Menu, Tooltip, Popconfirm, message } from 'antd';
+import { Menu, 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';
@@ -15,6 +15,8 @@ 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 '@/pages/system/User/Authorization';
 
 const menu = (
   <Menu>
@@ -154,7 +156,7 @@ const User = observer(() => {
             <EditOutlined />
           </Tooltip>
         </a>,
-        <a onClick={() => console.log('授权')}>
+        <a key="auth" onClick={() => console.log('授权')}>
           <Tooltip
             title={intl.formatMessage({
               id: 'pages.data.option.authorize',
@@ -164,11 +166,11 @@ const User = observer(() => {
             <KeyOutlined />
           </Tooltip>
         </a>,
-        <a href={record.id} target="_blank" rel="noopener noreferrer" key="view">
+        <a key="changeState">
           <Popconfirm
             title={intl.formatMessage({
-              id: 'pages.data.option.disabled.tips',
-              defaultMessage: '确认禁用?',
+              id: `pages.data.option.${record.status ? 'disabled' : 'enabled'}`,
+              defaultMessage: `确认${record.status ? '禁用' : '启用'}?`,
             })}
             onConfirm={async () => {
               await service.update({
@@ -198,38 +200,36 @@ const User = observer(() => {
     },
   ];
 
-  const schema = {
+  const schema: ISchema = {
     type: 'object',
     properties: {
-      name: {
+      username: {
         title: intl.formatMessage({
-          id: 'pages.system.user.name',
-          defaultMessage: '名',
+          id: 'pages.table.username',
+          defaultMessage: '用户名',
         }),
         type: 'string',
         'x-decorator': 'FormItem',
         'x-component': 'Input',
-        'x-component-props': {},
+        'x-component-props': {
+          disabled: model === 'edit',
+        },
         'x-decorator-props': {},
-        name: 'name',
+        name: 'username',
         required: true,
-        _designableId: '1jq1ln7nzji',
-        'x-index': 0,
       },
-      username: {
+      name: {
         title: intl.formatMessage({
-          id: 'pages.table.username',
-          defaultMessage: '用户名',
+          id: 'pages.system.user.name',
+          defaultMessage: '名',
         }),
         type: 'string',
         'x-decorator': 'FormItem',
         'x-component': 'Input',
         'x-component-props': {},
         'x-decorator-props': {},
-        name: 'username',
+        name: 'name',
         required: true,
-        _designableId: '9vf50ad9n1h',
-        'x-index': 1,
       },
       password: {
         type: 'string',
@@ -242,7 +242,7 @@ const User = observer(() => {
         'x-component-props': {
           checkStrength: true,
         },
-        'x-hidden': model === 'edit',
+        // 'x-hidden': model === 'edit',
         'x-reactions': [
           {
             dependencies: ['.confirmPassword'],
@@ -257,8 +257,6 @@ const User = observer(() => {
         'x-decorator-props': {},
         name: 'password',
         required: false,
-        _designableId: 'weg6kt6izlt',
-        'x-index': 2,
       },
       confirmPassword: {
         type: 'string',
@@ -268,7 +266,7 @@ const User = observer(() => {
         }),
         'x-decorator': 'FormItem',
         'x-component': 'Password',
-        'x-hidden': model === 'edit',
+        // 'x-hidden': model === 'edit',
         'x-component-props': {
           checkStrength: true,
         },
@@ -286,11 +284,8 @@ const User = observer(() => {
         'x-decorator-props': {},
         name: 'confirmPassword',
         required: false,
-        _designableId: 'mhsm2fk573e',
-        'x-index': 3,
       },
     },
-    _designableId: 'zd740kqp5hf',
   };
 
   return (
@@ -306,6 +301,9 @@ const User = observer(() => {
         menu={menu}
         schema={schema}
       />
+      <Drawer title="授权" width="70vw" visible={true}>
+        <Authorization />
+      </Drawer>
     </PageContainer>
   );
 });