Browse Source

fix: 修改网关设备下发功能

100011797 3 years ago
parent
commit
45964b7f7c

+ 126 - 62
src/pages/device/Firmware/Task/Detail/index.tsx

@@ -1,9 +1,8 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import { observer } from '@formily/react';
-import { Badge, Card, message, Popconfirm } from 'antd';
+import { Badge, Card, message } from 'antd';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import ProTable from '@jetlinks/pro-table';
-import { Tooltip } from 'antd';
 import { useEffect, useRef, useState } from 'react';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { RedoOutlined, SearchOutlined } from '@ant-design/icons';
@@ -15,6 +14,8 @@ import styles from './index.less';
 import { model } from '@formily/reactive';
 import { useParams } from 'umi';
 import Details from './Details/index';
+import { PermissionButton } from '@/components';
+import usePermissions from '@/hooks/permission';
 
 const colorMap = new Map();
 colorMap.set('waiting', '#FF9000');
@@ -47,6 +48,7 @@ const Detail = observer(() => {
   const params = useParams<any>();
   const [visible, setVisible] = useState<boolean>(false);
   const [reason, setReason] = useState<string>('');
+  const { permission } = usePermissions('device/Firmware');
 
   const buttonImg = require('/public/images/firmware/button.png');
 
@@ -273,44 +275,81 @@ const Detail = observer(() => {
       render: (text: any, record: any) =>
         record?.state?.value === 'failed'
           ? [
-              <a
+              // <a
+              //   onClick={() => {
+              //     setVisible(true);
+              //     setReason(record?.errorReason || '');
+              //   }}
+              //   key="link"
+              // >
+              //   <Tooltip
+              //     title={intl.formatMessage({
+              //       id: 'pages.data.option.detail',
+              //       defaultMessage: '查看',
+              //     })}
+              //     key={'detail'}
+              //   >
+              //     <SearchOutlined />
+              //   </Tooltip>
+              // </a>,
+              <PermissionButton
+                key="link"
+                type={'link'}
+                style={{ padding: 0 }}
+                isPermission={permission.update}
+                tooltip={{
+                  title: '重试',
+                }}
                 onClick={() => {
                   setVisible(true);
                   setReason(record?.errorReason || '');
                 }}
-                key="link"
               >
-                <Tooltip
-                  title={intl.formatMessage({
-                    id: 'pages.data.option.detail',
-                    defaultMessage: '查看',
-                  })}
-                  key={'detail'}
-                >
-                  <SearchOutlined />
-                </Tooltip>
-              </a>,
+                <SearchOutlined />
+              </PermissionButton>,
               <>
                 {state.info?.mode?.value === 'push' ? (
-                  <Popconfirm
-                    key="refresh"
-                    onConfirm={async () => {
-                      const resp = await service.startOneTask([record.id]);
-                      if (resp.status === 200) {
-                        message.success('操作成功!');
-                        handleSearch();
-                        actionRef.current?.reload?.();
-                      }
+                  <PermissionButton
+                    key="patch"
+                    type={'link'}
+                    style={{ padding: 0 }}
+                    isPermission={permission.update}
+                    tooltip={{
+                      title: '重试',
+                    }}
+                    popConfirm={{
+                      title: '确认重试',
+                      onConfirm: async () => {
+                        const resp = await service.startOneTask([record.id]);
+                        if (resp.status === 200) {
+                          message.success('操作成功!');
+                          handleSearch();
+                          actionRef.current?.reload?.();
+                        }
+                      },
                     }}
-                    title={'确认重试'}
                   >
-                    <a>
-                      <Tooltip title={'重试'} key={'refresh'}>
-                        <RedoOutlined />
-                      </Tooltip>
-                    </a>
-                  </Popconfirm>
-                ) : null}
+                    <RedoOutlined />
+                  </PermissionButton>
+                ) : // <Popconfirm
+                //   key="refresh"
+                //   onConfirm={async () => {
+                //     const resp = await service.startOneTask([record.id]);
+                //     if (resp.status === 200) {
+                //       message.success('操作成功!');
+                //       handleSearch();
+                //       actionRef.current?.reload?.();
+                //     }
+                //   }}
+                //   title={'确认重试'}
+                // >
+                //   <a>
+                //     <Tooltip title={'重试'} key={'refresh'}>
+                //       <RedoOutlined />
+                //     </Tooltip>
+                //   </a>
+                // </Popconfirm>
+                null}
               </>,
             ]
           : [],
@@ -326,44 +365,69 @@ const Detail = observer(() => {
               <div className={styles.firmwareDetailCard}>
                 <div className={styles.firmwareDetailCardHeader}>
                   <div className={styles.firmwareDetailCardTitle}>
-                    <Badge color={colorMap.get(item.key)} />
+                    <Badge color={colorMap.get(item.key)} style={{ marginRight: 5 }} />
                     {item.name}
                   </div>
                   <div className={styles.firmwareDetailCardRight}>
                     {item.key === 'error' && state.info?.mode?.value === 'push' && (
-                      <Popconfirm
-                        title="确认批量重试"
-                        onConfirm={async () => {
-                          const resp = await service.startTask(params.id, ['failed']);
-                          if (resp.status === 200) {
-                            message.success('操作成功!');
-                            queryFailed();
-                            actionRef.current?.reload?.();
-                          }
+                      // <Popconfirm
+                      //   title="确认批量重试"
+                      //   onConfirm={async () => {
+                      //     const resp = await service.startTask(params.id, ['failed']);
+                      //     if (resp.status === 200) {
+                      //       message.success('操作成功!');
+                      //       queryFailed();
+                      //       actionRef.current?.reload?.();
+                      //     }
+                      //   }}
+                      // >
+                      //   <a>批量重试</a>
+                      // </Popconfirm>
+                      <PermissionButton
+                        key="patch"
+                        type={'link'}
+                        style={{ padding: 0 }}
+                        isPermission={permission.update}
+                        tooltip={{
+                          title: '批量重试',
+                        }}
+                        popConfirm={{
+                          title: '确认批量重试',
+                          onConfirm: async () => {
+                            const resp = await service.startTask(params.id, ['failed']);
+                            if (resp.status === 200) {
+                              message.success('操作成功!');
+                              queryFailed();
+                              actionRef.current?.reload?.();
+                            }
+                          },
                         }}
                       >
-                        <a>批量重试</a>
-                      </Popconfirm>
+                        批量重试
+                      </PermissionButton>
                     )}
-                    <div className={styles.firmwareDetailCardRefresh}>
-                      <img
-                        style={{ width: '100%' }}
-                        src={buttonImg}
-                        onClick={() => {
-                          if (item.key === 'waiting') {
-                            queryWaiting();
-                          } else if (item.key === 'finish') {
-                            querySuccess();
-                          } else if (item.key === 'loading') {
-                            queryProcessing();
-                          } else if (item.key === 'canceled') {
-                            queryCancel();
-                          } else {
-                            queryFailed();
-                          }
-                        }}
-                      />
-                    </div>
+                    <PermissionButton
+                      key="patch1"
+                      style={{ padding: 0, backgroundColor: 'inherit', border: 0 }}
+                      isPermission={permission.update}
+                      onClick={() => {
+                        if (item.key === 'waiting') {
+                          queryWaiting();
+                        } else if (item.key === 'finish') {
+                          querySuccess();
+                        } else if (item.key === 'loading') {
+                          queryProcessing();
+                        } else if (item.key === 'canceled') {
+                          queryCancel();
+                        } else {
+                          queryFailed();
+                        }
+                      }}
+                    >
+                      <div className={styles.firmwareDetailCardRefresh}>
+                        <img style={{ width: '100%' }} src={buttonImg} />
+                      </div>
+                    </PermissionButton>
                   </div>
                 </div>
                 <div

+ 1 - 1
src/pages/device/Firmware/Task/Save/index.tsx

@@ -23,7 +23,7 @@ const Save = (props: Props) => {
   const devices = useRef<DeviceInstance[]>([]);
 
   useEffect(() => {
-    console.log(data);
+    // console.log(data);
     if (data && data.id) {
       setMode(data.mode.value);
     }

+ 29 - 26
src/pages/device/Firmware/Task/index.tsx

@@ -1,7 +1,7 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import ProTable from '@jetlinks/pro-table';
-import { message, Popconfirm, Tooltip } from 'antd';
+import { message, Tooltip } from 'antd';
 import { useRef, useState } from 'react';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import {
@@ -131,7 +131,7 @@ const Task = observer(() => {
           key={'api'}
           type={'link'}
           style={{ padding: 0 }}
-          isPermission={true}
+          isPermission={permission.view}
           tooltip={{
             title: '详情',
           }}
@@ -142,29 +142,39 @@ const Task = observer(() => {
         >
           <AIcon type={'icon-details'} />
         </PermissionButton>,
-        <a
+        <PermissionButton
+          key="link"
+          type={'link'}
+          style={{ padding: 0 }}
+          isPermission={permission.view}
+          tooltip={{
+            title: '查看',
+          }}
           onClick={() => {
             state.visible = true;
             state.current = record;
           }}
-          key="link"
         >
-          <Tooltip title="查看" key={'detail'}>
-            <EyeOutlined />
-          </Tooltip>
-        </a>,
+          <EyeOutlined />
+        </PermissionButton>,
         <UpgradeBtn data={record} actions={actionRef.current} key="btn" />,
-        <a key="delete">
-          <Popconfirm
-            title={
+        <PermissionButton
+          key="delete"
+          type={'link'}
+          style={{ padding: 0 }}
+          isPermission={permission.delete}
+          tooltip={{
+            title: '删除',
+          }}
+          popConfirm={{
+            title:
               record.waiting > 0 || record.processing > 0
                 ? '删除将导致正在进行的任务终止,确定要删除吗?'
                 : intl.formatMessage({
                     id: 'pages.data.option.remove.tips',
                     defaultMessage: '确认删除?',
-                  })
-            }
-            onConfirm={async () => {
+                  }),
+            onConfirm: async () => {
               const resp = await service.deleteTask(record.id);
               if (resp.status === 200) {
                 onlyMessage(
@@ -177,18 +187,11 @@ const Task = observer(() => {
               } else {
                 message.error(resp?.message || '删除失败!');
               }
-            }}
-          >
-            <Tooltip
-              title={intl.formatMessage({
-                id: 'pages.data.option.remove',
-                defaultMessage: '删除',
-              })}
-            >
-              <DeleteOutlined />
-            </Tooltip>
-          </Popconfirm>
-        </a>,
+            },
+          }}
+        >
+          <DeleteOutlined />
+        </PermissionButton>,
       ],
     },
   ];

+ 1 - 1
src/pages/device/Firmware/index.tsx

@@ -126,7 +126,7 @@ const Firmware = observer(() => {
         <PermissionButton
           style={{ padding: 0 }}
           type="link"
-          isPermission={permission.action}
+          isPermission={permission.view}
           key="upgrade"
           onClick={() => {
             //缓存路由参数

+ 17 - 7
src/pages/device/Instance/Detail/Tags/Edit.tsx

@@ -258,18 +258,28 @@ const Edit = (props: Props) => {
           props.close();
         } else {
           const list = (values?.tags || [])
-            .filter((item: any) => item?.key)
+            .filter((item: any) => item?.key && item?.value)
             .map((i: any) => {
               const { dataType, ...extra } = i;
               return { ...extra };
             });
-          const resp = await service.saveTags(InstanceModel.detail?.id || '', list);
-          if (resp.status === 200) {
-            props.refresh();
-            // InstanceModel.detail = { ...InstanceModel.detail, tags: values.tags };
-            onlyMessage('操作成功!');
-            props.close();
+          if (list.length) {
+            // 填值
+            const resp = await service.saveTags(InstanceModel.detail?.id || '', list);
+            if (resp.status === 200) {
+              onlyMessage('操作成功!');
+            }
           }
+          const _list = (values?.tags || []).filter((item: any) => item?.key && !item?.value);
+          if (_list.length) {
+            // 删除值
+            _list.map(async (item: any) => {
+              if (item.id) {
+                await service.delTags(InstanceModel.detail?.id || '', item.id);
+              }
+            });
+          }
+          props.refresh();
         }
       }}
     >

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

@@ -68,6 +68,7 @@ const Tags = () => {
       {visible && (
         <Edit
           refresh={() => {
+            setVisible(false);
             getDetail();
           }}
           close={() => {

+ 8 - 8
src/pages/edge/Resource/Issue/Result.tsx

@@ -24,13 +24,13 @@ const Publish = (props: Props) => {
     const errMessages: any[] = [];
     const _terms = {
       deviceId: (props.list || []).map((item) => item.id),
-      // params: {
-      name: props.data.name,
-      targetId: props.data.targetId,
-      targetType: props.data.targetType,
-      category: props.data.category,
-      metadata: encodeURIComponent(props.data?.metadata || ''),
-      // }
+      params: JSON.stringify({
+        name: props.data.name,
+        targetId: props.data.targetId,
+        targetType: props.data.targetType,
+        category: props.data.category,
+        metadata: encodeURIComponent(props.data?.metadata || ''),
+      }),
     };
     const url = new URLSearchParams();
     Object.keys(_terms).forEach((key) => {
@@ -45,7 +45,7 @@ const Publish = (props: Props) => {
     const source = new EventSourcePolyfill(
       `/${
         SystemConst.API_BASE
-      }/edge/operations/entity-template-save/invoke/_batch?:X_Access_Token=${Token.get()}&${url.toString()}`,
+      }/edge/operations/entity-template-save/invoke/_batch?:X_Access_Token=${Token.get()}&${url}`,
     );
     source.onmessage = (e: any) => {
       const res = JSON.parse(e.data);

+ 8 - 0
src/pages/media/Stream/index.tsx

@@ -194,6 +194,14 @@ const Stream = () => {
                           </PermissionButton>,
                           <PermissionButton
                             isPermission={permission.delete}
+                            tooltip={
+                              item?.state?.value === 'enabled'
+                                ? {
+                                    title: '正常的流媒体服务不能删除',
+                                  }
+                                : undefined
+                            }
+                            disabled={item?.state?.value === 'enabled'}
                             popConfirm={{
                               title: '确认删除',
                               onConfirm: () => {

+ 0 - 18
src/pages/system/Menu/Setting/baseMenu.ts

@@ -1469,24 +1469,6 @@ export default [
                 ],
               },
               {
-                id: 'action',
-                name: '启/禁用',
-                permissions: [
-                  {
-                    permission: 'firmware-manager',
-                    actions: ['query'],
-                  },
-                  {
-                    permission: 'device-instance',
-                    actions: ['query'],
-                  },
-                  {
-                    permission: 'firmware-upgrade-task-manager',
-                    actions: ['query', 'deploy'],
-                  },
-                ],
-              },
-              {
                 id: 'delete',
                 name: '删除',
                 permissions: [