Explorar o código

fix(设备管理): 修改删除提示

xieyonghong %!s(int64=3) %!d(string=hai) anos
pai
achega
5e358490d8

+ 1 - 0
src/locales/zh-CN/pages.ts

@@ -251,6 +251,7 @@ export default {
   'pages.device.instance.status.notActive': '未启用',
   'pages.device.instance.status.offLine': '离线',
   'pages.device.instance.status.onLine': '在线',
+  'pages.device.instance.deleteTip': '已启用的设备无法删除',
   'pages.device.instanceDetail.deviceType': '设备类型',
   'pages.device.instanceDetail.transportProtocol': '链接协议',
   'pages.device.instanceDetail.protocolName': '消息协议',

+ 1 - 0
src/pages/device/Instance/Save/index.tsx

@@ -76,6 +76,7 @@ const Save = (props: Props) => {
           props.reload();
         }
         props.close(resp.result);
+        form.resetFields();
       }
     }
   };

+ 52 - 39
src/pages/device/Instance/index.tsx

@@ -83,42 +83,46 @@ const Instance = () => {
         <EyeOutlined />
       </Tooltip>
     </Link>,
-    <a href={record.id} target="_blank" rel="noopener noreferrer" key="view">
-      <Popconfirm
+    <Popconfirm
+      title={intl.formatMessage({
+        id: `pages.data.option.${record.state.value !== 'notActive' ? 'disabled' : 'enabled'}.tips`,
+        defaultMessage: '确认禁用?',
+      })}
+      onConfirm={async () => {
+        if (record.state.value !== 'notActive') {
+          await service.undeployDevice(record.id);
+        } else {
+          await service.deployDevice(record.id);
+        }
+        message.success(
+          intl.formatMessage({
+            id: 'pages.data.option.success',
+            defaultMessage: '操作成功!',
+          }),
+        );
+        actionRef.current?.reload();
+      }}
+    >
+      <Tooltip
         title={intl.formatMessage({
-          id: 'pages.data.option.disabled.tips',
-          defaultMessage: '确认禁用?',
+          id: `pages.data.option.${record.state.value !== 'notActive' ? 'disabled' : 'enabled'}`,
+          defaultMessage: record.state.value !== 'notActive' ? '禁用' : '启用',
         })}
-        onConfirm={async () => {
-          if (record.state.value !== 'notActive') {
-            await service.undeployDevice(record.id);
-          } else {
-            await service.deployDevice(record.id);
-          }
-          message.success(
-            intl.formatMessage({
-              id: 'pages.data.option.success',
-              defaultMessage: '操作成功!',
-            }),
-          );
-          actionRef.current?.reload();
-        }}
       >
-        <Tooltip
-          title={intl.formatMessage({
-            id: `pages.data.option.${record.state.value !== 'notActive' ? 'disabled' : 'enabled'}`,
-            defaultMessage: record.state.value !== 'notActive' ? '禁用' : '启用',
-          })}
-        >
+        <Button type={'link'}>
           {record.state.value !== 'notActive' ? <StopOutlined /> : <CheckCircleOutlined />}
-        </Tooltip>
-      </Popconfirm>
-    </a>,
-
-    <a key={'delete'}>
-      <Popconfirm
-        title="确认删除"
-        onConfirm={async () => {
+        </Button>
+      </Tooltip>
+    </Popconfirm>,
+    <Popconfirm
+      title={intl.formatMessage({
+        id:
+          record.state.value === 'notActive'
+            ? 'pages.data.option.remove.tips'
+            : 'pages.device.instance.deleteTip',
+      })}
+      onConfirm={async () => {
+        if (record.state.value === 'notActive') {
           await service.remove(record.id);
           message.success(
             intl.formatMessage({
@@ -127,13 +131,22 @@ const Instance = () => {
             }),
           );
           actionRef.current?.reload();
-        }}
+        } else {
+          message.error(intl.formatMessage({ id: 'pages.device.instance.deleteTip' }));
+        }
+      }}
+    >
+      <Tooltip
+        title={intl.formatMessage({
+          id: 'pages.data.option.remove',
+          defaultMessage: '删除',
+        })}
       >
-        <Tooltip title={'删除'}>
+        <Button type={'link'}>
           <DeleteOutlined />
-        </Tooltip>
-      </Popconfirm>
-    </a>,
+        </Button>
+      </Tooltip>
+    </Popconfirm>,
   ];
 
   const columns: ProColumns<DeviceInstance>[] = [
@@ -349,8 +362,8 @@ const Instance = () => {
             ...params,
             sorts: [
               {
-                name: 'id',
-                order: 'ascend',
+                name: 'createTime',
+                order: 'desc',
               },
             ],
           })

+ 6 - 3
src/pages/device/Product/Save/index.tsx

@@ -30,7 +30,7 @@ const Save = (props: Props) => {
     // 特殊处理deviceType字段
     if (data) {
       if (typeof data.deviceType !== 'string') {
-        data.deviceType = data.deviceType?.value;
+        data.deviceTypeId = data.deviceType?.value;
       }
     }
     return data;
@@ -71,13 +71,16 @@ const Save = (props: Props) => {
   const handleSave = async () => {
     const formData = await form.validateFields();
     if (formData) {
-      const res = await service.update(formData);
+      const { deviceTypeId, ...extraFormData } = formData;
+      extraFormData.deviceType = formData.deviceTypeId;
+      const res = await service.update(extraFormData);
       if (res.status === 200) {
         message.success('保存成功');
         if (props.reload) {
           props.reload();
         }
         props.close();
+        form.resetFields();
       }
     }
   };
@@ -215,7 +218,7 @@ const Save = (props: Props) => {
           <Col span={24}>
             <Form.Item
               label={intlFormat('pages.device.instanceDetail.deviceType', '设备类型')}
-              name={'deviceType'}
+              name={'deviceTypeId'}
               rules={[
                 {
                   required: true,

+ 18 - 13
src/pages/device/Product/index.tsx

@@ -17,7 +17,6 @@ import { Link, useHistory } from 'umi';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { useEffect, useRef, useState } from 'react';
-import encodeQuery from '@/utils/encodeQuery';
 import Save from '@/pages/device/Product/Save';
 import SearchComponent from '@/components/SearchComponent';
 import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
@@ -131,15 +130,16 @@ const Product = observer(() => {
       })}
       key={'edit'}
     >
-      <a
+      <Button
         key="warning"
         onClick={() => {
           setCurrent(record);
           setVisible(true);
         }}
+        type={'link'}
       >
         <EditOutlined />
-      </a>
+      </Button>
     </Tooltip>,
     <Tooltip
       title={intl.formatMessage({
@@ -148,7 +148,7 @@ const Product = observer(() => {
       })}
       key={'download'}
     >
-      <a key="download">
+      <Button type={'link'}>
         <DownloadOutlined
           onClick={async () => {
             await message.success(
@@ -159,13 +159,13 @@ const Product = observer(() => {
             );
           }}
         />
-      </a>
+      </Button>
     </Tooltip>,
     <Popconfirm
       key={'state'}
       title={intl.formatMessage({
         id: `pages.data.option.${record.state ? 'disabled' : 'enabled'}.tips`,
-        defaultMessage: '是否删除?',
+        defaultMessage: '是否启用?',
       })}
       onConfirm={() => {
         changeDeploy(record.id, record.state ? 'undeploy' : 'deploy');
@@ -177,16 +177,13 @@ const Product = observer(() => {
           defaultMessage: record.state ? '禁用' : '启用',
         })}
       >
-        <a key="state">{record.state ? <StopOutlined /> : <PlayCircleOutlined />}</a>
+        <Button type={'link'}>{record.state ? <StopOutlined /> : <PlayCircleOutlined />}</Button>
       </Tooltip>
     </Popconfirm>,
     <Popconfirm
       key="unBindUser"
       title={intl.formatMessage({
-        id:
-          record.state === 1
-            ? 'pages.device.productDetail.deleteTip'
-            : 'page.system.menu.table.delete',
+        id: record.state === 1 ? 'pages.device.productDetail.deleteTip' : 'page.table.isDelete',
         defaultMessage: '是否删除?',
       })}
       onConfirm={async () => {
@@ -199,7 +196,7 @@ const Product = observer(() => {
     >
       <Tooltip
         title={intl.formatMessage({
-          id: 'pages.data.option.remove.tips',
+          id: 'pages.data.option.remove',
           defaultMessage: '删除',
         })}
         key={'remove'}
@@ -255,7 +252,15 @@ const Product = observer(() => {
         // }}
         params={queryParam}
         request={(params = {}) =>
-          service.query(encodeQuery({ ...params, sorts: { createTime: 'ascend' } }))
+          service.query({
+            ...params,
+            sorts: [
+              {
+                name: 'createTime',
+                order: 'desc',
+              },
+            ],
+          })
         }
         rowKey="id"
         search={false}

+ 2 - 1
src/pages/device/Product/typings.d.ts

@@ -14,7 +14,8 @@ export type ProductItem = {
   createTime: number;
   updateTime: number;
   creatorId: string;
-  deviceType: string | DeviceType;
+  deviceType: DeviceType;
+  deviceTypeId?: string;
   count?: number;
   messageProtocol: string;
   metadata: string;