Przeglądaj źródła

fix(device): merge sc

Lind 3 lat temu
rodzic
commit
bd6ef98d11

+ 5 - 1
src/app.tsx

@@ -111,9 +111,13 @@ export async function getInitialState(): Promise<{
  * @param url
  * @param options
  */
+const filterUrl = ['/authorize/captcha/config', '/authorize/login'];
 const requestInterceptor = (url: string, options: RequestOptionsInit) => {
   // const {params} = options;
-  const authHeader = { 'X-Access-Token': Token.get() || '' };
+  let authHeader = {};
+  if (!filterUrl.some((fUrl) => url.includes(fUrl))) {
+    authHeader = { 'X-Access-Token': Token.get() || '' };
+  }
   return {
     url: `${url}`,
     options: {

+ 16 - 14
src/pages/device/Instance/Detail/Functions/index.tsx

@@ -13,24 +13,26 @@ const Functions = () => {
       <Tabs>
         <Tabs.TabPane tab={'精简模式'} key={1}>
           <Tabs tabPosition="left">
-            {functionList.map((fn) => {
-              return (
-                <Tabs.TabPane tab={fn.name} key={fn.id}>
-                  <FnForm data={fn} />
-                </Tabs.TabPane>
-              );
-            })}
+            {functionList &&
+              functionList.map((fn) => {
+                return (
+                  <Tabs.TabPane tab={fn.name} key={fn.id}>
+                    <FnForm data={fn} />
+                  </Tabs.TabPane>
+                );
+              })}
           </Tabs>
         </Tabs.TabPane>
         <Tabs.TabPane tab={'高级模式'} key={2}>
           <Tabs tabPosition="left">
-            {functionList.map((fn) => {
-              return (
-                <Tabs.TabPane tab={fn.name} key={fn.id}>
-                  <AModel data={fn} />
-                </Tabs.TabPane>
-              );
-            })}
+            {functionList &&
+              functionList.map((fn) => {
+                return (
+                  <Tabs.TabPane tab={fn.name} key={fn.id}>
+                    <AModel data={fn} />
+                  </Tabs.TabPane>
+                );
+              })}
           </Tabs>
         </Tabs.TabPane>
       </Tabs>

+ 1 - 2
src/pages/device/Instance/Detail/Info/index.tsx

@@ -112,8 +112,7 @@ const Info = observer(() => {
           if (data) {
             InstanceModel.detail = {
               ...InstanceModel.detail,
-              name: data?.name,
-              description: data?.describe,
+              ...data,
             };
           }
         }}

+ 34 - 18
src/pages/device/Instance/Detail/index.tsx

@@ -1,9 +1,8 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import { InstanceModel, service } from '@/pages/device/Instance';
 import { history, useParams } from 'umi';
-import { Badge, Button, Card, Divider, message, Tooltip } from 'antd';
+import { Badge, Button, Card, Descriptions, Divider, message, Tooltip } from 'antd';
 import { useEffect, useState } from 'react';
-import { statusMap } from '@/pages/device/Product';
 import { observer } from '@formily/react';
 import Log from '@/pages/device/Instance/Detail/Log';
 import Alarm from '@/pages/device/components/Alarm';
@@ -17,6 +16,7 @@ import type { DeviceMetadata } from '@/pages/device/Product/typings';
 import MetadataAction from '@/pages/device/components/Metadata/DataBaseAction';
 import { Store } from 'jetlinks-store';
 import SystemConst from '@/utils/const';
+import { getMenuPathByCode, MENUS_CODE } from '@/utils/menu';
 
 export const deviceStatus = new Map();
 deviceStatus.set('online', <Badge status="success" text={'在线'} />);
@@ -151,7 +151,23 @@ const InstanceDetail = observer(() => {
       onBack={history.goBack}
       onTabChange={setTab}
       tabList={list}
-      // content={<Info />}
+      content={
+        <Descriptions size="small" column={4}>
+          <Descriptions.Item label={'ID'}>{InstanceModel.detail.id}</Descriptions.Item>
+          <Descriptions.Item label={'所属产品'}>
+            <Button
+              type={'link'}
+              size={'small'}
+              onClick={() => {
+                const url = getMenuPathByCode(MENUS_CODE['device/Product']);
+                history.push(`${url}?id=${InstanceModel.detail.productId}`);
+              }}
+            >
+              {InstanceModel.detail.productName}
+            </Button>
+          </Descriptions.Item>
+        </Descriptions>
+      }
       title={
         <>
           {InstanceModel.detail.name}
@@ -159,21 +175,21 @@ const InstanceDetail = observer(() => {
           {deviceStatus.get(InstanceModel.detail.state?.value)}
         </>
       }
-      extra={[
-        statusMap[0],
-        <Button key="2">
-          {intl.formatMessage({
-            id: 'pages.device.productDetail.disable',
-            defaultMessage: '停用',
-          })}
-        </Button>,
-        <Button key="1" type="primary">
-          {intl.formatMessage({
-            id: 'pages.device.productDetail.setting',
-            defaultMessage: '应用配置',
-          })}
-        </Button>,
-      ]}
+      // extra={[
+      //   statusMap[0],
+      //   <Button key="2">
+      //     {intl.formatMessage({
+      //       id: 'pages.device.productDetail.disable',
+      //       defaultMessage: '停用',
+      //     })}
+      //   </Button>,
+      //   <Button key="1" type="primary">
+      //     {intl.formatMessage({
+      //       id: 'pages.device.productDetail.setting',
+      //       defaultMessage: '应用配置',
+      //     })}
+      //   </Button>,
+      // ]}
     >
       {list.find((k) => k.key === tab)?.component}
     </PageContainer>

+ 2 - 3
src/pages/device/Instance/Save/index.tsx

@@ -67,7 +67,6 @@ const Save = (props: Props) => {
 
   const handleSave = async () => {
     const values = await form.validateFields();
-    console.log(values);
     if (values) {
       const resp = (await service.update(values)) as any;
       if (resp.status === 200) {
@@ -75,7 +74,7 @@ const Save = (props: Props) => {
         if (props.reload) {
           props.reload();
         }
-        props.close(resp.result);
+        props.close(values);
         form.resetFields();
       }
     }
@@ -203,7 +202,7 @@ const Save = (props: Props) => {
                 options={productList}
                 onSelect={(_: any, node: any) => {
                   form.setFieldsValue({
-                    productName: node.name,
+                    productName: node.label,
                   });
                 }}
               />

+ 22 - 17
src/pages/device/Instance/index.tsx

@@ -4,7 +4,7 @@ import type { DeviceInstance } from '@/pages/device/Instance/typings';
 import moment from 'moment';
 import { Badge, Button, Dropdown, Menu, message, Popconfirm, Tooltip } from 'antd';
 import { useRef, useState } from 'react';
-import { Link } from 'umi';
+import { useHistory } from 'umi';
 import {
   CheckCircleOutlined,
   DeleteOutlined,
@@ -28,6 +28,7 @@ import { ProTableCard } from '@/components';
 import SystemConst from '@/utils/const';
 import Token from '@/utils/token';
 import DeviceCard from '@/components/ProTableCard/CardItems/device';
+import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
 
 export const statusMap = new Map();
 statusMap.set('在线', 'success');
@@ -63,26 +64,29 @@ const Instance = () => {
   const [current, setCurrent] = useState<Partial<DeviceInstance>>({});
   const [searchParams, setSearchParams] = useState<any>({});
   const [bindKeys, setBindKeys] = useState<any[]>([]);
+  const history = useHistory<Record<string, string>>();
   const intl = useIntl();
 
   const tools = (record: DeviceInstance) => [
-    <Link
-      onClick={() => {
-        InstanceModel.current = record;
-      }}
-      to={`/device/instance/detail/${record.id}`}
-      key="link"
+    <Tooltip
+      title={intl.formatMessage({
+        id: 'pages.data.option.detail',
+        defaultMessage: '查看',
+      })}
+      key={'detail'}
     >
-      <Tooltip
-        title={intl.formatMessage({
-          id: 'pages.data.option.detail',
-          defaultMessage: '查看',
-        })}
-        key={'detail'}
+      <Button
+        type={'link'}
+        style={{ padding: 0 }}
+        onClick={() => {
+          InstanceModel.current = record;
+          const url = getMenuPathByParams(MENUS_CODE['device/Instance/Detail'], record.id);
+          history.push(url);
+        }}
       >
         <EyeOutlined />
-      </Tooltip>
-    </Link>,
+      </Button>
+    </Tooltip>,
     <Popconfirm
       title={intl.formatMessage({
         id: `pages.data.option.${record.state.value !== 'notActive' ? 'disabled' : 'enabled'}.tips`,
@@ -109,7 +113,7 @@ const Instance = () => {
           defaultMessage: record.state.value !== 'notActive' ? '禁用' : '启用',
         })}
       >
-        <Button type={'link'}>
+        <Button type={'link'} style={{ padding: 0 }}>
           {record.state.value !== 'notActive' ? <StopOutlined /> : <CheckCircleOutlined />}
         </Button>
       </Tooltip>
@@ -142,7 +146,7 @@ const Instance = () => {
           defaultMessage: '删除',
         })}
       >
-        <Button type={'link'}>
+        <Button type={'link'} style={{ padding: 0 }}>
           <DeleteOutlined />
         </Button>
       </Tooltip>
@@ -344,6 +348,7 @@ const Instance = () => {
         field={columns}
         target="device-instance"
         onSearch={(data) => {
+          console.log(data);
           // 重置分页数据
           actionRef.current?.reset?.();
           setSearchParams(data);

+ 1 - 8
src/pages/device/Product/Detail/BaseInfo/index.tsx

@@ -167,14 +167,7 @@ const BaseInfo = () => {
         ]}
         bordered
       >
-        <Descriptions.Item
-          label={intl.formatMessage({
-            id: 'pages.device.category',
-            defaultMessage: '产品ID',
-          })}
-        >
-          {productModel.current?.id}
-        </Descriptions.Item>
+        <Descriptions.Item label={'ID'}>{productModel.current?.id}</Descriptions.Item>
         <Descriptions.Item
           label={intl.formatMessage({
             id: 'pages.device.productDetail.classifiedName',

+ 17 - 11
src/pages/device/Product/index.tsx

@@ -13,7 +13,7 @@ import {
 import Service from '@/pages/device/Product/service';
 import { observer } from '@formily/react';
 import { model } from '@formily/reactive';
-import { Link, useHistory } from 'umi';
+import { useHistory } from 'umi';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { useEffect, useRef, useState } from 'react';
@@ -92,7 +92,6 @@ const Product = observer(() => {
    * @param data
    */
   const searchFn = (data: any) => {
-    actionRef.current?.reset?.();
     setQueryParam(data);
   };
 
@@ -112,15 +111,16 @@ const Product = observer(() => {
       })}
       key={'detail'}
     >
-      <Link
+      <Button
+        type={'link'}
         onClick={() => {
           productModel.current = record;
+          history.push(`${getMenuPathByParams(MENUS_CODE['device/Product/Detail'], record.id)}`);
         }}
-        to={`${getMenuPathByParams(MENUS_CODE['device/Product/Detail'], record.id)}`}
-        key="link"
+        style={{ padding: 0 }}
       >
         <EyeOutlined />
-      </Link>
+      </Button>
     </Tooltip>,
     <Tooltip
       title={intl.formatMessage({
@@ -136,6 +136,7 @@ const Product = observer(() => {
           setVisible(true);
         }}
         type={'link'}
+        style={{ padding: 0 }}
       >
         <EditOutlined />
       </Button>
@@ -147,7 +148,7 @@ const Product = observer(() => {
       })}
       key={'download'}
     >
-      <Button type={'link'}>
+      <Button type={'link'} style={{ padding: 0 }}>
         <DownloadOutlined
           onClick={async () => {
             await message.success(
@@ -176,7 +177,9 @@ const Product = observer(() => {
           defaultMessage: record.state ? '禁用' : '启用',
         })}
       >
-        <Button type={'link'}>{record.state ? <StopOutlined /> : <PlayCircleOutlined />}</Button>
+        <Button style={{ padding: 0 }} type={'link'}>
+          {record.state ? <StopOutlined /> : <PlayCircleOutlined />}
+        </Button>
       </Tooltip>
     </Popconfirm>,
     <Popconfirm
@@ -200,9 +203,9 @@ const Product = observer(() => {
         })}
         key={'remove'}
       >
-        <a key="delete">
+        <Button type={'link'} style={{ padding: 0 }}>
           <DeleteOutlined />
-        </a>
+        </Button>
       </Tooltip>
     </Popconfirm>,
   ];
@@ -260,7 +263,7 @@ const Product = observer(() => {
         onReset={() => {
           // 重置分页及搜索参数
           actionRef.current?.reset?.();
-          setQueryParam({});
+          searchFn({});
         }}
       />
       <ProTableCard<ProductItem>
@@ -302,6 +305,9 @@ const Product = observer(() => {
               defaultMessage: '新增',
             })}
           </Button>,
+          <Button onClick={() => {}} key={'import'} type={'primary'}>
+            导入
+          </Button>,
         ]}
         cardRender={(record) => <ProductCard {...record} actions={tools(record)} />}
       />

+ 5 - 0
src/pages/system/Department/Assets/deivce/bind.tsx

@@ -122,6 +122,11 @@ const Bind = observer((props: Props) => {
           actionRef.current?.reset?.();
           setSearchParam(data);
         }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParam({});
+        }}
         target="department-assets-device"
       />
       <ProTable<DeviceItem>

+ 5 - 0
src/pages/system/Department/Assets/deivce/index.tsx

@@ -201,6 +201,11 @@ export default observer(() => {
           actionRef.current?.reset?.();
           setSearchParam(data);
         }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParam({});
+        }}
         target="department-assets-device"
       />
       <ProTable<DeviceItem>

+ 5 - 3
src/pages/system/Department/Assets/product/bind.tsx

@@ -110,6 +110,11 @@ const Bind = observer((props: Props) => {
           actionRef.current?.reset?.();
           setSearchParam(data);
         }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParam({});
+        }}
         target="department-assets-product"
       />
       <ProTable<ProductItem>
@@ -117,9 +122,6 @@ const Bind = observer((props: Props) => {
         columns={columns}
         rowKey="id"
         search={false}
-        pagination={{
-          pageSize: 5,
-        }}
         rowSelection={{
           selectedRowKeys: Models.bindKeys,
           onChange: (selectedRowKeys, selectedRows) => {

+ 5 - 0
src/pages/system/Department/Assets/product/index.tsx

@@ -142,6 +142,11 @@ export default observer(() => {
           actionRef.current?.reset?.();
           setSearchParam(data);
         }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParam({});
+        }}
         target="department-assets-product"
       />
       <ProTable<ProductItem>

+ 5 - 0
src/pages/system/Department/Assets/productCategory/bind.tsx

@@ -109,6 +109,11 @@ const Bind = observer((props: Props) => {
           actionRef.current?.reset?.();
           setSearchParam(data);
         }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParam({});
+        }}
         target="department-assets-category"
       />
       <ProTable<ProductCategoryItem>

+ 5 - 0
src/pages/system/Department/Assets/productCategory/index.tsx

@@ -162,6 +162,11 @@ export default observer(() => {
           actionRef.current?.reset?.();
           setSearchParam(data);
         }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParam({});
+        }}
         target="department-assets-category"
       />
       <ProTable<ProductCategoryItem>

+ 5 - 0
src/pages/system/Department/Member/bind.tsx

@@ -84,6 +84,11 @@ const Bind = observer((props: Props) => {
           actionRef.current?.reset?.();
           setSearchParam(data);
         }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParam({});
+        }}
         target="department-user"
       />
       <ProTable

+ 5 - 0
src/pages/system/Department/Member/index.tsx

@@ -162,6 +162,11 @@ const Member = observer(() => {
           actionRef.current?.reset?.();
           setSearchParam(data);
         }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParam({});
+        }}
         target="department-user"
       />
       <ProTable<MemberItem>

+ 11 - 6
src/pages/system/Department/index.tsx

@@ -1,24 +1,23 @@
 // 部门管理
 import { PageContainer } from '@ant-design/pro-layout';
-import ProTable from '@jetlinks/pro-table';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
+import ProTable from '@jetlinks/pro-table';
 import { useEffect, useRef, useState } from 'react';
-import { useIntl } from 'umi';
+import { Link, useIntl, useLocation } from 'umi';
 import { Button, message, Popconfirm, Tooltip } from 'antd';
 import {
+  DeleteOutlined,
   EditOutlined,
-  PlusOutlined,
+  MedicineBoxOutlined,
   PlusCircleOutlined,
+  PlusOutlined,
   TeamOutlined,
-  MedicineBoxOutlined,
-  DeleteOutlined,
 } from '@ant-design/icons';
 import Service from '@/pages/system/Department/service';
 import type { ISchema } from '@formily/json-schema';
 import type { DepartmentItem } from '@/pages/system/Department/typings';
 import { observer } from '@formily/react';
 import { model } from '@formily/reactive';
-import { Link, useLocation } from 'umi';
 import Save from './save';
 import SearchComponent from '@/components/SearchComponent';
 
@@ -193,6 +192,12 @@ export default observer(() => {
         }),
         'x-decorator': 'FormItem',
         'x-component': 'NumberPicker',
+        'x-validator': [
+          {
+            pattern: /^[0-9]*[1-9][0-9]*$/,
+            message: '请输入大于0的整数',
+          },
+        ],
       },
     },
   };

+ 6 - 0
src/pages/system/Menu/Detail/edit.tsx

@@ -164,6 +164,12 @@ export default (props: EditProps) => {
                       id: 'page.system.menu.sort',
                       defaultMessage: '排序',
                     })}
+                    rules={[
+                      {
+                        pattern: /^[0-9]*[1-9][0-9]*$/,
+                        message: '请输入大于0的整数',
+                      },
+                    ]}
                   >
                     <InputNumber style={{ width: '100%' }} disabled={disabled} />
                   </Form.Item>

+ 10 - 4
src/pages/system/Menu/index.tsx

@@ -191,9 +191,7 @@ export default observer(() => {
    * @param data
    */
   const searchFn = (data: any) => {
-    setParam({
-      terms: data,
-    });
+    setParam(data);
   };
 
   // const modalCancel = () => {
@@ -222,7 +220,15 @@ export default observer(() => {
 
   return (
     <PageContainer>
-      <SearchComponent field={columns} onSearch={searchFn} />
+      <SearchComponent
+        field={columns}
+        onSearch={searchFn}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          searchFn({});
+        }}
+      />
       <ProTable<MenuItem>
         columns={columns}
         actionRef={actionRef}

+ 0 - 1
src/utils/menu.ts

@@ -211,7 +211,6 @@ export const saveMenusCache = (routes: MenuItem[]) => {
 export const getMenuPathByCode = (code: string): string => {
   const menusStr = localStorage.getItem(MENUS_DATA_CACHE) || '{}';
   const menusData = JSON.parse(menusStr);
-  console.log(code, menusData);
   return menusData[code];
 };