浏览代码

fix(dueros): dueros

lind 3 年之前
父节点
当前提交
1bac0be20b

+ 3 - 2
src/components/ProTableCard/CardItems/duerOs.tsx

@@ -17,14 +17,15 @@ export default (props: DuerOSProps) => {
   return (
     <TableCard
       actions={props.action}
-      detail={props.detail}
+      // detail={props.detail}
+      showStatus={false}
       // status={props.state?.value}
       // statusText={props.state?.text}
       // statusNames={{
       //   enabled: StatusColorEnum.success,
       //   disabled: StatusColorEnum.error,
       // }}
-      // showMask={false}
+      showMask={false}
     >
       <div className={'pro-table-card-item'}>
         <div className={'card-item-avatar'}>

+ 31 - 0
src/pages/Northbound/DuerOS/Detail/Doc.tsx

@@ -0,0 +1,31 @@
+const Doc = () => {
+  return (
+    <div className="doc">
+      <div className="url">
+        小度智能家居开放平台:
+        <a href="https://dueros.baidu.com/dbp/bot/index#/iotopenplatform">
+          https://dueros.baidu.com/dbp/bot/index#/iotopenplatform
+        </a>
+      </div>
+      <h1>1. 概述</h1>
+      <div>
+        DuerOS支持家居场景下的云端控制,该页面主要将平台的产品与DuerOS支持语音控制的产品进行映射,以到达小度平台控制本平台设备的目的。
+      </div>
+      <h1>2. 操作步骤</h1>
+      <div>
+        <h2>1、在百度小度技能平台创建技能,并授权。完成物联网平台与dueros的关联。</h2>
+        <h2>2、登录物联网平台,进行平台内产品与dueros产品的数据映射。</h2>
+        <h2>
+          3、智能家居用户通过物联网平台中的用户,登录小度APP,获取平台内当前用户的所属设备。获取后即可进行语音控制。
+        </h2>
+      </div>
+      <h1>3. 配置说明</h1>
+      <div>
+        <h2>
+          1、“设备类型”为dueros平台拟定的标准规范,设备类型将决定【动作映射】中“动作”的下拉选项,以及【属性映射】中“Dueros属性”的下拉选项
+        </h2>
+      </div>
+    </div>
+  );
+};
+export default Doc;

+ 46 - 28
src/pages/Northbound/DuerOS/Detail/index.tsx

@@ -1,7 +1,7 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import { createSchemaField } from '@formily/react';
 import { ISchema } from '@formily/json-schema';
-import { Card, Col, Row } from 'antd';
+import { Card, Col, message, Row } from 'antd';
 import {
   ArrayCollapse,
   ArrayTable,
@@ -15,10 +15,12 @@ import {
 } from '@formily/antd';
 import { PermissionButton } from '@/components';
 import { useMemo } from 'react';
-import { createForm, Field, onFieldReact, onFieldValueChange } from '@formily/core';
+import { createForm, Field, onFieldReact, onFieldValueChange, onFormInit } from '@formily/core';
 import { useAsyncDataSource } from '@/utils/util';
 import { service } from '..';
 import { Store } from 'jetlinks-store';
+import { useParams } from 'umi';
+import Doc from '@/pages/Northbound/DuerOS/Detail/Doc';
 
 const Save = () => {
   const SchemaField = createSchemaField({
@@ -33,6 +35,8 @@ const Save = () => {
     },
   });
 
+  const { id } = useParams<{ id: string }>();
+
   const getProduct = () =>
     service.getProduct().then((resp) => {
       Store.set('product-list', resp.result);
@@ -71,7 +75,7 @@ const Save = () => {
           columnGap: 24,
         },
         properties: {
-          product: {
+          id: {
             title: '产品',
             'x-decorator-props': {
               gridSpan: 1,
@@ -93,7 +97,7 @@ const Save = () => {
             'x-reactions': '{{useAsyncDataSource(getProduct)}}',
             required: true,
           },
-          deviceType: {
+          applianceType: {
             title: '设备类型',
             'x-decorator-props': {
               gridSpan: 1,
@@ -275,7 +279,7 @@ const Save = () => {
                             },
                           },
                         },
-                        function: {
+                        inputs: {
                           title: '参数列表',
                           type: 'array',
                           'x-component': 'ArrayTable',
@@ -408,6 +412,7 @@ const Save = () => {
                       label: 'name',
                       value: 'id',
                     },
+                    mode: 'tags',
                   },
                 },
               },
@@ -429,35 +434,39 @@ const Save = () => {
     },
   };
 
-  const handleSave = () => {};
-
-  const findProductMetadata = (id: string) => {
-    if (!id) return;
+  const findProductMetadata = (_id: string) => {
+    if (!_id) return;
     const _productList = Store.get('product-list');
-    const _product = _productList.find((item: any) => item.id === id);
-    return _product.metadata && JSON.parse(_product.metadata || '{}');
+    const _product = _productList?.find((item: any) => item.id === _id);
+    return _product?.metadata && JSON.parse(_product.metadata || '{}');
   };
 
-  const findDeviceType = (id: string) => {
-    if (!id) return;
+  const findapplianceType = (_id: string) => {
+    if (!_id) return;
     const _productTypes = Store.get('product-types');
-    return _productTypes.find((item: any) => item.id === id);
+    return _productTypes?.find((item: any) => item.id === _id);
   };
   const form = useMemo(
     () =>
       createForm({
         validateFirst: true,
         effects() {
+          onFormInit(async (form1) => {
+            await getTypes();
+            await getProduct();
+            const resp = await service.detail(id);
+            form1.setInitialValues(resp.result);
+          });
           onFieldReact('actionMappings.*.layout.action', (field) => {
-            const productType = field.query('deviceType').value();
-            (field as Field).setDataSource(findDeviceType(productType)?.actions);
+            const productType = field.query('applianceType').value();
+            (field as Field).setDataSource(findapplianceType(productType)?.actions);
           });
           onFieldReact('actionMappings.*.layout.command.message.properties', (field) => {
-            const product = field.query('product').value();
+            const product = field.query('id').value();
             (field as Field).setDataSource(findProductMetadata(product)?.properties);
           });
           onFieldReact('actionMappings.*.layout.command.message.functionId', (field) => {
-            const product = field.query('product').value();
+            const product = field.query('id').value();
             (field as Field).setDataSource(findProductMetadata(product)?.functions);
           });
           onFieldValueChange(
@@ -465,7 +474,7 @@ const Save = () => {
             (field, form1) => {
               const functionId = field.value;
               if (!functionId) return;
-              const product = field.query('product').value();
+              const product = field.query('id').value();
               const _functionList = findProductMetadata(product)?.functions;
               const _function =
                 _functionList && _functionList.find((item: any) => item.id === functionId);
@@ -477,35 +486,44 @@ const Save = () => {
               });
             },
           );
-          onFieldReact('propertyMappings.*.layout.target', (field) => {
-            const productType = field.query('deviceType').value();
-            (field as Field).setDataSource(findDeviceType(productType)?.properties);
-          });
           onFieldReact('propertyMappings.*.layout.source', (field) => {
-            const product = field.query('product').value();
+            const productType = field.query('applianceType').value();
+            (field as Field).setDataSource(findapplianceType(productType)?.properties);
+          });
+          onFieldReact('propertyMappings.*.layout.target', (field) => {
+            const product = field.query('id').value();
             (field as Field).setDataSource(findProductMetadata(product)?.properties);
           });
         },
       }),
     [],
   );
+
+  const handleSave = async () => {
+    const data: any = await form.submit();
+    await service.savePatch(data);
+    message.success('保存成功!');
+    history.back();
+  };
   return (
-    <PageContainer>
+    <PageContainer className={'page-title-show'}>
       <Card>
         <Row>
-          <Col span={10}>
+          <Col span={12}>
             <Form layout="vertical" form={form}>
               <SchemaField schema={schema} scope={{ useAsyncDataSource, getTypes, getProduct }} />
               <FormButtonGroup.Sticky>
                 <FormButtonGroup.FormItem>
-                  <PermissionButton type="primary" onClick={handleSave}>
+                  <PermissionButton isPermission={true} type="primary" onClick={handleSave}>
                     保存
                   </PermissionButton>
                 </FormButtonGroup.FormItem>
               </FormButtonGroup.Sticky>
             </Form>
           </Col>
-          <Col span={12} push={2}></Col>
+          <Col span={10} push={2}>
+            <Doc />
+          </Col>
         </Row>
       </Card>
     </PageContainer>

+ 11 - 51
src/pages/Northbound/DuerOS/index.tsx

@@ -3,15 +3,9 @@ import SearchComponent from '@/components/SearchComponent';
 import { useRef, useState } from 'react';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { PermissionButton, ProTableCard } from '@/components';
-import {
-  DeleteOutlined,
-  EditOutlined,
-  PlayCircleOutlined,
-  PlusOutlined,
-  StopOutlined,
-} from '@ant-design/icons';
+import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
 import { useIntl } from '@@/plugin-locale/localeExports';
-import { Space } from 'antd';
+import { message, Space } from 'antd';
 import { DuerOSItem } from '@/pages/Northbound/DuerOS/types';
 import DuerOSCard from '@/components/ProTableCard/CardItems/duerOs';
 import { history } from '@@/core/history';
@@ -42,7 +36,9 @@ export default () => {
               }
             : undefined
         }
-        onClick={() => {}}
+        onClick={() => {
+          history.push(getMenuPathByParams(MENUS_CODE['Northbound/DuerOS/Detail'], record.id));
+        }}
       >
         <EditOutlined />
         {type !== 'table' &&
@@ -52,53 +48,20 @@ export default () => {
           })}
       </PermissionButton>,
       <PermissionButton
-        key={'started'}
-        type={'link'}
-        style={{ padding: 0 }}
-        isPermission={permission.action}
-        popConfirm={{
-          title: intl.formatMessage({
-            id: `pages.data.option.${
-              record.state.value === 'started' ? 'disabled' : 'enabled'
-            }.tips`,
-            defaultMessage: '确认禁用?',
-          }),
-          onConfirm: async () => {},
-        }}
-        tooltip={
-          type === 'table'
-            ? {
-                title: intl.formatMessage({
-                  id: `pages.data.option.${
-                    record.state.value === 'started' ? 'disabled' : 'enabled'
-                  }`,
-                  defaultMessage: '启用',
-                }),
-              }
-            : undefined
-        }
-      >
-        {record.state.value === 'started' ? <StopOutlined /> : <PlayCircleOutlined />}
-        {type !== 'table' &&
-          intl.formatMessage({
-            id: `pages.data.option.${record.state.value === 'started' ? 'disabled' : 'enabled'}`,
-            defaultMessage: record.state.value === 'started' ? '禁用' : '启用',
-          })}
-      </PermissionButton>,
-      <PermissionButton
         key={'delete'}
         type={'link'}
         style={{ padding: 0 }}
         isPermission={permission.delete}
-        disabled={record.state.value === 'started'}
         popConfirm={{
           title: '确认删除?',
-          disabled: record.state.value === 'started',
-          onConfirm: () => {},
+          onConfirm: async () => {
+            await service.remove(record.id);
+            message.success('删除成功!');
+            actionRef.current?.reload();
+          },
         }}
         tooltip={{
-          title:
-            record.state.value === 'started' ? <span>请先禁用,再删除</span> : <span>删除</span>,
+          title: '删除',
         }}
       >
         <DeleteOutlined />
@@ -173,9 +136,6 @@ export default () => {
             <PermissionButton
               isPermission={true}
               onClick={() => {
-                // setCurrent(undefined);
-                // setVisible(true);
-                // state.current = record;
                 history.push(getMenuPathByParams(MENUS_CODE['Northbound/DuerOS/Detail']));
               }}
               key="button"