Bladeren bron

fix(dueros): dueros table

lind 3 jaren geleden
bovenliggende
commit
195bf6f6e4

+ 17 - 2
src/pages/Northbound/DuerOS/Detail/index.tsx

@@ -534,14 +534,29 @@ const Save = () => {
           },
         },
       },
+      description: {
+        title: '说明',
+        'x-component': 'Input.TextArea',
+        'x-decorator': 'FormItem',
+        'x-component-props': {
+          rows: 3,
+          showCount: true,
+          maxLength: 200,
+          placeholder: '请输入说明',
+        },
+      },
     },
   };
 
   const handleSave = async () => {
     const data: any = await form.submit();
     const productName = Store.get('product-list')?.find((item: any) => item.id === data.id)?.name;
-    await service.savePatch({ ...data, productName });
-    message.success('保存成功!');
+    const resp: any = await service.savePatch({ ...data, productName });
+    if (resp.status === 200) {
+      message.success('保存成功!');
+    } else {
+      message.error('保存失败!');
+    }
     history.back();
   };
   return (

+ 69 - 15
src/pages/Northbound/DuerOS/index.tsx

@@ -4,13 +4,15 @@ import { useRef, useState } from 'react';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { PermissionButton, ProTableCard } from '@/components';
 import {
+  CloseCircleOutlined,
   DeleteOutlined,
   EditOutlined,
   ExclamationCircleFilled,
+  PlayCircleOutlined,
   PlusOutlined,
 } from '@ant-design/icons';
 import { useIntl } from '@@/plugin-locale/localeExports';
-import { message, Space } from 'antd';
+import { Badge, message, Space } from 'antd';
 import { DuerOSItem } from '@/pages/Northbound/DuerOS/types';
 import DuerOSCard from '@/components/ProTableCard/CardItems/duerOs';
 import { history } from '@@/core/history';
@@ -53,10 +55,64 @@ export default () => {
           })}
       </PermissionButton>,
       <PermissionButton
+        style={{ padding: 0 }}
+        isPermission={permission.action}
+        type="link"
+        key="changeState"
+        popConfirm={{
+          title: intl.formatMessage({
+            id: `pages.data.option.${
+              record.state?.value === 'enabled' ? 'disabled' : 'enabled'
+            }.tips`,
+            defaultMessage: `确认${record.state?.value === 'enabled' ? '禁用' : '启用'}?`,
+          }),
+          onConfirm: async () => {
+            const map = {
+              disabled: 'enable',
+              enabled: 'disable',
+            };
+            const resp = await service.changeState(record.id, map[record.state?.value]);
+            if (resp.status === 200) {
+              message.success(
+                intl.formatMessage({
+                  id: 'pages.data.option.success',
+                  defaultMessage: '操作成功!',
+                }),
+              );
+            } else {
+              message.error('操作失败!');
+            }
+
+            actionRef.current?.reload();
+          },
+        }}
+        tooltip={{
+          title: intl.formatMessage({
+            id: `pages.data.option.${record.state?.value === 'enabled' ? 'disabled' : 'enabled'}`,
+            defaultMessage: record.state?.value === 'enabled' ? '禁用' : '启用',
+          }),
+        }}
+      >
+        {record.state?.value === 'enabled' ? (
+          <>
+            {' '}
+            <CloseCircleOutlined /> {type === 'card' && '禁用'}
+          </>
+        ) : (
+          <>
+            <PlayCircleOutlined /> {type === 'card' && '启用'}
+          </>
+        )}
+      </PermissionButton>,
+      <PermissionButton
         key={'delete'}
         type={'link'}
         style={{ padding: 0 }}
         isPermission={permission.delete}
+        disabled={record.state?.value === 'enabled'}
+        tooltip={{
+          title: record.state?.value === 'disabled' ? '删除' : '请先禁用该用户,再删除。',
+        }}
         popConfirm={{
           title: '确认删除?',
           onConfirm: async () => {
@@ -65,9 +121,6 @@ export default () => {
             actionRef.current?.reload();
           },
         }}
-        tooltip={{
-          title: '删除',
-        }}
       >
         <DeleteOutlined />
       </PermissionButton>,
@@ -98,18 +151,19 @@ export default () => {
       renderText: (data) => data.text,
     },
     {
-      title: intl.formatMessage({
-        id: 'pages.cloud.duerOS.manufacturerName',
-        defaultMessage: '厂家名称',
-      }),
-      dataIndex: 'manufacturerName',
+      title: '说明',
+      dataIndex: 'description',
     },
     {
-      title: intl.formatMessage({
-        id: 'pages.cloud.duerOS.version',
-        defaultMessage: '动作数量',
-      }),
-      dataIndex: 'version',
+      title: '状态',
+      dataIndex: 'state',
+      renderText: (data) => {
+        const map = {
+          disabled: <Badge status="error" text="禁用" />,
+          enabled: <Badge status="success" text="正常" />,
+        };
+        return map[data.value];
+      },
     },
     {
       title: intl.formatMessage({
@@ -160,7 +214,7 @@ export default () => {
         headerTitle={
           <Space>
             <PermissionButton
-              isPermission={true}
+              isPermission={permission.add}
               onClick={() => {
                 history.push(getMenuPathByCode(MENUS_CODE['Northbound/DuerOS/Detail']));
               }}

+ 3 - 0
src/pages/Northbound/DuerOS/service.ts

@@ -16,6 +16,9 @@ class Service extends BaseService<DuerOSItem> {
         paging: false,
       },
     });
+
+  public changeState = (id: string, state: 'enable' | 'disable') =>
+    request(`/${SystemConst.API_BASE}/dueros/product/${id}/_${state}`, { method: 'POST' });
 }
 
 export default Service;