Преглед изворни кода

fix: 修复场景联动无法显示功能列表问题

xieyonghong пре 3 година
родитељ
комит
21f710203e

+ 5 - 1
src/pages/rule-engine/Scene/Save/action/device/functionCall.tsx

@@ -16,6 +16,7 @@ interface FunctionCallProps {
   functionData: any[];
   value?: any;
   onChange?: (data: any) => void;
+  name?: string;
 }
 
 export default (props: FunctionCallProps) => {
@@ -24,6 +25,9 @@ export default (props: FunctionCallProps) => {
 
   useEffect(() => {
     setEditableRowKeys(props.functionData.map((d) => d.id));
+    formRef.current?.setFieldsValue({
+      table: props.functionData,
+    });
   }, [props.functionData]);
 
   useEffect(() => {
@@ -126,7 +130,7 @@ export default (props: FunctionCallProps) => {
   return (
     <ProForm<{ table: FunctionTableDataType[] }>
       formRef={formRef}
-      name={'proForm'}
+      name={props.name || 'proForm'}
       submitter={false}
       onValuesChange={() => {
         const values = formRef.current?.getFieldsValue();

+ 10 - 9
src/pages/rule-engine/Scene/Save/components/TimingTrigger/index.tsx

@@ -64,6 +64,8 @@ export default (props: TimingTrigger) => {
         when: [],
         period: {
           unit: 'seconds',
+          from: moment(new Date()).format('HH:mm:ss'),
+          to: moment(new Date()).format('HH:mm:ss'),
         },
       });
     } else {
@@ -81,8 +83,8 @@ export default (props: TimingTrigger) => {
           ...omit(data, 'once'),
           mod: key,
           period: {
-            from: undefined,
-            to: undefined,
+            from: moment(new Date()).format('HH:mm:ss'),
+            to: moment(new Date()).format('HH:mm:ss'),
             unit: 'seconds',
           },
         });
@@ -91,7 +93,7 @@ export default (props: TimingTrigger) => {
           ...omit(data, 'period'),
           mod: key,
           once: {
-            time: undefined,
+            time: moment(new Date()).format('HH:mm:ss'),
           },
         });
       }
@@ -190,11 +192,10 @@ export default (props: TimingTrigger) => {
               {data.mod === PeriodModEnum.period ? (
                 <TimePicker.RangePicker
                   format={'HH:mm:ss'}
-                  value={
-                    data.period?.from
-                      ? [moment(data.period?.from, 'HH:mm:ss'), moment(data.period?.to, 'hh:mm:ss')]
-                      : [moment(new Date(), 'HH:mm:ss'), moment(new Date(), 'HH:mm:ss')]
-                  }
+                  value={[
+                    moment(data.period?.from, 'HH:mm:ss'),
+                    moment(data.period?.to, 'hh:mm:ss'),
+                  ]}
                   onChange={(_, dateString) => {
                     onChange({
                       ...data,
@@ -209,7 +210,7 @@ export default (props: TimingTrigger) => {
               ) : (
                 <TimePicker
                   format={'HH:mm:ss'}
-                  value={moment(data.once?.time || new Date(), 'HH:mm:ss')}
+                  value={moment(data.once?.time, 'HH:mm:ss')}
                   onChange={(_, dateString) => {
                     onChange({
                       ...data,

+ 3 - 0
src/pages/rule-engine/Scene/Save/index.tsx

@@ -24,6 +24,7 @@ import { service } from '../index';
 import './index.less';
 import { model } from '@formily/reactive';
 import type { FormModelType } from '@/pages/rule-engine/Scene/typings';
+import moment from 'moment';
 
 type ShakeLimitType = {
   enabled: boolean;
@@ -296,6 +297,8 @@ export default () => {
                   when: [],
                   period: {
                     unit: 'seconds',
+                    from: moment(new Date()).format('HH:mm:ss'),
+                    to: moment(new Date()).format('HH:mm:ss'),
                   },
                 }}
               >

+ 23 - 1
src/pages/rule-engine/Scene/Save/trigger/index.tsx

@@ -12,6 +12,7 @@ import { observer } from '@formily/reactive-react';
 import OrgTreeSelect from './OrgTreeSelect';
 import { FormModel } from '../index';
 import AllDevice from '@/pages/rule-engine/Scene/Save/action/device/AllDevice';
+import moment from 'moment';
 
 interface TriggerProps {
   value?: any;
@@ -305,6 +306,8 @@ export default observer((props: TriggerProps) => {
             when: [],
             period: {
               unit: 'seconds',
+              from: moment(new Date()).format('HH:mm:ss'),
+              to: moment(new Date()).format('HH:mm:ss'),
             },
           }}
         >
@@ -331,6 +334,25 @@ export default observer((props: TriggerProps) => {
                   filterOption={(input: string, option: any) =>
                     option.name.toLowerCase().indexOf(input.toLowerCase()) >= 0
                   }
+                  onSelect={(_: any, fcItem: any) => {
+                    if (fcItem) {
+                      const _properties = fcItem.valueType
+                        ? fcItem.valueType.properties
+                        : fcItem.inputs;
+                      const array = [];
+                      for (const datum of _properties) {
+                        array.push({
+                          id: datum.id,
+                          name: datum.name,
+                          type: datum.valueType ? datum.valueType.type : '-',
+                          format: datum.valueType ? datum.valueType.format : undefined,
+                          options: datum.valueType ? datum.valueType.elements : undefined,
+                          value: undefined,
+                        });
+                      }
+                      setFunctionItem(array);
+                    }
+                  }}
                 />
               </Form.Item>
             </Col>
@@ -339,7 +361,7 @@ export default observer((props: TriggerProps) => {
             </Col>
             <Col span={24}>
               <Form.Item name={['trigger', 'device', 'operation', 'functionParameters']}>
-                <FunctionCall functionData={functionItem} />
+                <FunctionCall functionData={functionItem} name={'functionForm'} />
               </Form.Item>
             </Col>
           </Row>

+ 13 - 7
src/pages/system/Platforms/index.tsx

@@ -20,6 +20,7 @@ export default () => {
   const [param, setParam] = useState({});
   const [saveVisible, setSaveVisible] = useState(false);
   const [passwordVisible, setPasswordVisible] = useState(false);
+  const [editData, setEditData] = useState<ActionType | undefined>(undefined);
 
   const { permission } = PermissionButton.usePermission('system/Platforms');
 
@@ -58,22 +59,21 @@ export default () => {
             status={record.value}
             text={record.text}
             statusNames={{
-              started: StatusColorEnum.processing,
+              enabled: StatusColorEnum.processing,
               disable: StatusColorEnum.error,
-              notActive: StatusColorEnum.warning,
             }}
           />
         ) : (
           ''
         ),
       valueEnum: {
-        disable: {
+        disabled: {
           text: '禁用',
-          status: 'offline',
+          status: 'disabled',
         },
-        started: {
+        enabled: {
           text: '正常',
-          status: 'started',
+          status: 'enabled',
         },
       },
     },
@@ -105,7 +105,10 @@ export default () => {
               defaultMessage: '编辑',
             }),
           }}
-          onClick={() => {}}
+          onClick={() => {
+            setSaveVisible(true);
+            setEditData(record);
+          }}
         >
           <EditOutlined />
         </PermissionButton>,
@@ -187,6 +190,7 @@ export default () => {
         params={param}
         columns={columns}
         actionRef={actionRef}
+        request={(params: any) => service.query(params)}
         headerTitle={
           <PermissionButton
             key="button"
@@ -206,8 +210,10 @@ export default () => {
       />
       <SaveModal
         visible={saveVisible}
+        data={editData}
         onCancel={() => {
           setSaveVisible(false);
+          setEditData(undefined);
         }}
         onReload={() => {
           actionRef.current?.reload();

+ 31 - 7
src/pages/system/Platforms/save.tsx

@@ -14,7 +14,7 @@ import {
   TreeSelect,
 } from '@formily/antd';
 import { message, Modal } from 'antd';
-import React, { useMemo, useState } from 'react';
+import React, { useCallback, useMemo, useState } from 'react';
 import * as ICONS from '@ant-design/icons';
 import { PlusOutlined } from '@ant-design/icons';
 import type { ISchema } from '@formily/json-schema';
@@ -77,7 +77,9 @@ export default (props: SaveProps) => {
     () =>
       createForm({
         validateFirst: true,
-        initialValues: props.data || { oath2: true, id: randomString() },
+        initialValues: props.data
+          ? { ...props.data, confirm_password: props.data.password }
+          : { enableOAuth2: true, id: randomString() },
       }),
     [props.data],
   );
@@ -184,7 +186,9 @@ export default (props: SaveProps) => {
             'x-component': 'Password',
             'x-component-props': {
               placeholder: '请输入密码',
+              checkStrength: true,
             },
+            'x-visible': !props.data,
             'x-decorator-props': {
               gridSpan: 1,
             },
@@ -201,8 +205,26 @@ export default (props: SaveProps) => {
             ],
             'x-validator': [
               {
-                max: 64,
-                message: '最多可输入64个字符',
+                triggerType: 'onBlur',
+                validator: (value: string) => {
+                  return new Promise((resolve) => {
+                    service
+                      .validateField('password', value)
+                      .then((resp) => {
+                        if (resp.status === 200) {
+                          if (resp.result.passed) {
+                            resolve('');
+                          } else {
+                            resolve(resp.result.reason);
+                          }
+                        }
+                        resolve('');
+                      })
+                      .catch(() => {
+                        return '验证失败!';
+                      });
+                  });
+                },
               },
               {
                 required: true,
@@ -218,7 +240,9 @@ export default (props: SaveProps) => {
             'x-component': 'Password',
             'x-component-props': {
               placeholder: '请再次输入密码',
+              checkStrength: true,
             },
+            'x-visible': !props.data,
             'x-decorator-props': {
               gridSpan: 1,
             },
@@ -379,13 +403,13 @@ export default (props: SaveProps) => {
     }
   };
 
-  const saveData = async () => {
+  const saveData = useCallback(async () => {
     // setLoading(true)
     const data: any = await form.submit();
     console.log(data);
     if (data) {
       setLoading(true);
-      const resp = data.id ? await service.update(data) : await service.save(data);
+      const resp: any = props.data ? await service.update(data) : await service.save(data);
       setLoading(false);
       if (resp.status === 200) {
         if (props.onReload) {
@@ -395,7 +419,7 @@ export default (props: SaveProps) => {
         message.success('操作成功');
       }
     }
-  };
+  }, [props.data]);
 
   return (
     <Modal

+ 11 - 0
src/pages/system/Platforms/service.ts

@@ -8,6 +8,17 @@ class Service extends BaseService<platformsType> {
       method: 'GET',
       params,
     });
+
+  /**
+   * 密码校验
+   * @param type
+   * @param name
+   */
+  validateField = (type: 'username' | 'password', name: string) =>
+    request(`/${SystemConst.API_BASE}/user/${type}/_validate`, {
+      method: 'POST',
+      data: name,
+    });
 }
 
 export default Service;