Procházet zdrojové kódy

fix: 场景联动及其他bug

wzyyy před 2 roky
rodič
revize
059766aec9

+ 2 - 1
src/components/Metadata/ArrayParam/index.tsx

@@ -1,5 +1,5 @@
 import { createSchemaField } from '@formily/react';
-import { Editable, FormItem, FormLayout, Input, NumberPicker, Select } from '@formily/antd';
+import { FormItem, FormLayout, Input, NumberPicker, Select } from '@formily/antd';
 import type { ISchema } from '@formily/json-schema';
 import './index.less';
 import { DataTypeList, DateTypeList, FileTypeList } from '@/pages/device/data';
@@ -7,6 +7,7 @@ import { Store } from 'jetlinks-store';
 import JsonParam from '@/components/Metadata/JsonParam';
 import EnumParam from '@/components/Metadata/EnumParam';
 import BooleanEnum from '@/components/Metadata/BooleanParam';
+import Editable from '../EditTable';
 
 interface Props {
   isFunction?: boolean;

+ 20 - 0
src/components/ProTableCard/CardItems/Scene/index.tsx

@@ -12,6 +12,8 @@ import MyTooltip from './MyTooltip';
 import { handleOptionsLabel } from '@/pages/rule-engine/Scene/Save/terms/paramsItem';
 import { isArray } from 'lodash';
 import TriggerAlarm from '@/pages/rule-engine/Scene/Save/action/TriggerAlarm';
+import { getMenuPathByCode, getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
+import { history } from 'umi';
 
 const imageMap = new Map();
 imageMap.set('timer', require('/public/images/scene/scene-timer.png'));
@@ -425,10 +427,28 @@ const TriggerRender = (data: SceneCardProps) => {
                 if (data.trigger?.device?.selector === 'fixed') {
                   // 自定义
                   //selectorValues
+                  if (!!getMenuPathByCode(MENUS_CODE['device/Instance'])) {
+                    const url = getMenuPathByParams(
+                      MENUS_CODE['device/Instance/Detail'],
+                      data.trigger?.device?.selectorValues[0]?.value,
+                    );
+                    if (url) {
+                      history.replace(url);
+                    }
+                  }
                 } else if (data.trigger?.device?.selector === 'org') {
                   // 组织
                 } else if (data.trigger?.device?.selector === 'all') {
                   // 产品
+                  if (!!getMenuPathByCode(MENUS_CODE['device/Product'])) {
+                    const url = getMenuPathByParams(
+                      MENUS_CODE['device/Product/Detail'],
+                      data.trigger?.device?.productId,
+                    );
+                    if (url) {
+                      history.replace(url);
+                    }
+                  }
                 }
               }
             }}

+ 25 - 25
src/pages/link/AccessConfig/Detail/components/Network/index.tsx

@@ -170,31 +170,31 @@ const Network = (props: Props) => {
             description={
               <span>
                 暂无数据
-                {getButtonPermission('link/Type', ['add']) ? (
-                  '请联系管理员进行配置'
-                ) : (
-                  <Button
-                    type="link"
-                    onClick={() => {
-                      const url = getMenuPathByCode(MENUS_CODE['link/Type/Detail']);
-                      const tab: any = window.open(
-                        `${origin}/#${url}?type=${
-                          NetworkTypeMapping.get(props.provider?.id) || ''
-                        }`,
-                      );
-                      tab!.onTabSaveSuccess = (value: any) => {
-                        if (value.status === 200) {
-                          setNetworkCurrent(value.result?.id);
-                          queryNetworkList(props.provider?.id, {
-                            include: networkCurrent || '',
-                          });
-                        }
-                      };
-                    }}
-                  >
-                    去新增
-                  </Button>
-                )}
+                {getButtonPermission('link/Type', ['add'])
+                  ? '请联系管理员进行配置'
+                  : ''
+                    // <Button
+                    //   type="link"
+                    //   onClick={() => {
+                    //     const url = getMenuPathByCode(MENUS_CODE['link/Type/Detail']);
+                    //     const tab: any = window.open(
+                    //       `${origin}/#${url}?type=${
+                    //         NetworkTypeMapping.get(props.provider?.id) || ''
+                    //       }`,
+                    //     );
+                    //     tab!.onTabSaveSuccess = (value: any) => {
+                    //       if (value.status === 200) {
+                    //         setNetworkCurrent(value.result?.id);
+                    //         queryNetworkList(props.provider?.id, {
+                    //           include: networkCurrent || '',
+                    //         });
+                    //       }
+                    //     };
+                    //   }}
+                    // >
+                    //   去新增
+                    // </Button>
+                }
               </span>
             }
           />

+ 21 - 21
src/pages/link/AccessConfig/Detail/components/Protocol/index.tsx

@@ -142,27 +142,27 @@ const Protocol = (props: Props) => {
             description={
               <span>
                 暂无数据
-                {getButtonPermission('link/Protocol', ['add']) ? (
-                  '请联系管理员进行配置'
-                ) : props.view ? (
-                  ''
-                ) : (
-                  <Button
-                    type="link"
-                    onClick={() => {
-                      const url = getMenuPathByCode(MENUS_CODE[`link/Protocol`]);
-                      const tab: any = window.open(`${origin}/#${url}?save=true`);
-                      tab!.onTabSaveSuccess = (resp: any) => {
-                        if (resp.status === 200) {
-                          setProtocolCurrent(resp.result?.id);
-                          queryProtocolList(props.provider?.id);
-                        }
-                      };
-                    }}
-                  >
-                    去新增
-                  </Button>
-                )}
+                {getButtonPermission('link/Protocol', ['add'])
+                  ? '请联系管理员进行配置'
+                  : props.view
+                  ? ''
+                  : ''
+                    // <Button
+                    //   type="link"
+                    //   onClick={() => {
+                    //     const url = getMenuPathByCode(MENUS_CODE[`link/Protocol`]);
+                    //     const tab: any = window.open(`${origin}/#${url}?save=true`);
+                    //     tab!.onTabSaveSuccess = (resp: any) => {
+                    //       if (resp.status === 200) {
+                    //         setProtocolCurrent(resp.result?.id);
+                    //         queryProtocolList(props.provider?.id);
+                    //       }
+                    //     };
+                    //   }}
+                    // >
+                    //   去新增
+                    // </Button>
+                }
               </span>
             }
           />

+ 8 - 8
src/pages/rule-engine/Scene/Save/action/DeviceOutput/actions/TypeModel.tsx

@@ -70,7 +70,7 @@ export default observer((props: Props) => {
         setBuiltInList(filterData);
         if (props.value) {
           const label = optionMap.current.get(props.value);
-          setLabelValue(label?.description);
+          setLabelValue(label?.fullName);
         }
       }
     });
@@ -92,7 +92,6 @@ export default observer((props: Props) => {
 
   useEffect(() => {
     setValue(props.value);
-    // setLabelValue(props.label);
   }, [props.value]);
 
   useEffect(() => {
@@ -212,7 +211,7 @@ export default observer((props: Props) => {
             }}
             onChange={(_: any, timeString: string) => {
               // setDateOpen(false)
-              console.log('timeString', timeString);
+              // console.log('timeString', timeString);
               setValue(timeString);
               setLabelValue(timeString);
               if (props.onChange) {
@@ -254,20 +253,21 @@ export default observer((props: Props) => {
             treeData={builtInList}
             height={300}
             defaultExpandAll
+            defaultSelectedKeys={[props.value]}
             fieldNames={{ title: 'name', key: 'id' }}
             onSelect={(selectedKeys, e) => {
-              // console.log('e.node', e.node);
+              // console.log('e.node', e.node, e);
               if (e.node.metadata) {
                 if (props.onColumns) {
                   props.onColumns(e.node.column);
                 }
               }
               setOpen(false);
-              setLabelValue(e.node.description);
-              DeviceModel.actionName = e.node.description;
+              setLabelValue(e.node.fullName);
+              DeviceModel.actionName = e.node.fullName;
               setValue(selectedKeys[0]);
               if (props.onChange) {
-                props.onChange(selectedKeys[0], source, e.node.description);
+                props.onChange(selectedKeys[0], source, e.node.fullName);
               }
             }}
           />
@@ -323,7 +323,7 @@ export default observer((props: Props) => {
             setObjVisable(false);
           }}
           ok={(param) => {
-            console.log('------', param);
+            // console.log('------', param);
             if (props.onChange) {
               props.onChange(JSON.parse(param));
             }

+ 12 - 7
src/pages/rule-engine/Scene/Save/action/ListItem/FilterCondition.tsx

@@ -188,6 +188,8 @@ export default observer((props: FilterProps) => {
           showLabelKey="fullName"
           isTree={true}
           onChange={(_value, item) => {
+            // console.log('_value-----',_value)
+
             setValue({
               value: undefined,
               source: 'fixed',
@@ -198,11 +200,13 @@ export default observer((props: FilterProps) => {
             const _termTypeOptions: any[] =
               node.termTypes?.map((tItem: any) => ({ title: tItem.name, key: tItem.id })) || [];
             setTtOptions(_termTypeOptions);
-            if (!node.metadata) {
-              columnsRef.current = [node.column];
+            if (node.metadata) {
+              columnsRef.current[0] = node.column;
             } else {
               columnsRef.current = [];
             }
+            console.log('columnsRef.current', columnsRef.current);
+            props.onColumns(columnsRef.current);
             // 默认选中第一个
             let _termTypeValue = undefined;
             if (_termTypeOptions.length) {
@@ -215,6 +219,7 @@ export default observer((props: FilterProps) => {
             }
             ValueRef.current.column = _value!;
             labelCache.current[0] = node.fullName;
+
             valueChange({
               column: _value,
               value: {
@@ -284,7 +289,7 @@ export default observer((props: FilterProps) => {
                 labelCache.current[3] = props.data.type;
 
                 if (v.source === 'upper') {
-                  if (!node.metadata) {
+                  if (node.metadata) {
                     columnsRef.current[1] = node.column;
                   } else {
                     columnsRef.current.splice(1, 1);
@@ -327,7 +332,7 @@ export default observer((props: FilterProps) => {
                 labelCache.current[3] = props.data.type;
 
                 if (v.source === 'upper') {
-                  if (!node.metadata) {
+                  if (node.metadata) {
                     columnsRef.current[2] = node.column;
                   } else {
                     columnsRef.current.splice(2, 1);
@@ -364,15 +369,15 @@ export default observer((props: FilterProps) => {
               setValue({
                 ...v,
               });
-              console.log('node.column-----', node, v);
+              console.log('node.column-----', node);
               if (v.source === 'upper') {
-                if (!node.metadata) {
+                if (node.metadata) {
                   columnsRef.current[1] = node.column;
                 } else {
                   columnsRef.current.splice(1, 1);
                 }
               } else {
-                columnsRef.current = [];
+                columnsRef.current.length = 1;
               }
 
               props.onColumns(columnsRef.current);

+ 4 - 1
src/pages/rule-engine/Scene/Save/action/ListItem/Item.tsx

@@ -409,15 +409,18 @@ export default (props: ItemProps) => {
                   label={props.options?.terms?.[index]}
                   actionColumns={props.options?.otherColumns}
                   onColumnsChange={(columns) => {
-                    console.log('-----', columns);
+                    // console.log('columns-----', columns);
 
                     const filterColumns = new Set(flattenDeep(columns)); // 平铺去重
+                    // console.log('filterColumns-----',filterColumns)
+
                     let newColumns = [...filterColumns.values()];
                     if (optionsRef.current?.otherColumns) {
                       newColumns = [...optionsRef.current.otherColumns, ...newColumns];
                     }
                     optionsRef.current['columns'] = newColumns;
                     optionsRef.current['termsColumns'] = columns;
+                    // console.log('optionsRef.current-----',optionsRef.current)
                     props.onUpdate(cacheValueRef.current, optionsRef.current);
                   }}
                   onAddGroup={() => {

+ 10 - 4
src/pages/rule-engine/Scene/Save/components/Buttons/ParamsDropdown.tsx

@@ -25,12 +25,13 @@ export interface ParamsDropdownProps {
   icon?: ReactNode;
   open?: boolean;
   openChange?: (open: boolean) => void;
+  enumList?: any[];
 }
 
 interface MenusProps {
   value: any;
   options?: any[];
-  onChange: (value: any, lb: any, node) => void;
+  onChange: (value: any, lb: any, node: any) => void;
 }
 
 const Menus = (props: MenusProps) => {
@@ -50,7 +51,7 @@ const Menus = (props: MenusProps) => {
         selectedKeys={value ? [value] : undefined}
         items={props.options}
         onClick={({ key, item }: { key: any; item: any }) => {
-          console.log(item.props);
+          // console.log(item.props);
           const _item = props.options?.find((a) => a.value === item.props.value);
           setValue(key);
           if (_item) {
@@ -91,7 +92,7 @@ export default (props: ParamsDropdownProps) => {
       if (config.name && Array.isArray(_v)) {
         _value = _v[config.name];
       }
-
+      // console.log('type---',type,props.enumList)
       switch (type) {
         case 'int':
         case 'long':
@@ -119,10 +120,15 @@ export default (props: ParamsDropdownProps) => {
             />
           );
         case 'enum':
+          const _enums = props.enumList?.map((item) => ({
+            label: item.name,
+            value: item.id,
+            key: item.id,
+          }));
           return (
             <Menus
               value={_value}
-              options={props.options}
+              options={_enums}
               onChange={(v, l) => {
                 onValueChange(v, l);
                 setOpen(false);

+ 8 - 2
src/pages/rule-engine/Scene/Save/terms/paramsItem.tsx

@@ -127,6 +127,7 @@ const ParamsItem = observer((props: ParamsItemProps) => {
     termType: '',
     value: undefined,
   });
+  const enumRef = useRef<any>([]);
 
   const valueChange = useCallback(
     (_value: any) => {
@@ -182,7 +183,7 @@ const ParamsItem = observer((props: ParamsItemProps) => {
   useEffect(() => {
     setTermType(props.data.termType || '');
     setValue(props.data.value);
-    // console.log(props.data.value,'-----')
+    console.log('props.data-----', props.data);
     setColumn(props.data.column || '');
     // if(props.data.value?.source === 'metric'){
     //   setIsRange(true)
@@ -255,6 +256,10 @@ const ParamsItem = observer((props: ParamsItemProps) => {
           showLabelKey="fullName"
           isTree={true}
           onChange={(_value, item) => {
+            console.log('item.node---', item.node);
+            if (item.node && item.node.dataType === 'enum') {
+              enumRef.current = item.node.options;
+            }
             setValue({
               value: undefined,
               source: 'manual',
@@ -396,8 +401,9 @@ const ParamsItem = observer((props: ParamsItemProps) => {
             placeholder="参数值"
             valueType={valueType}
             value={value}
+            enumList={enumRef.current}
             onChange={(v, lb, item) => {
-              console.log('-----', v, lb, item);
+              // console.log('-----', v, lb, item);
               const _value = { ...v };
               if (item) {
                 _value.metric = item.id;

+ 1 - 1
src/pages/rule-engine/Scene/typings.d.ts

@@ -7,7 +7,7 @@ type Action = {
 
 type Trigger = {
   type: string;
-  device: Record<string, unknown>;
+  device: Record<string, any>;
 };
 
 export enum ParallelEnum {

+ 2 - 0
src/pages/system/Apply/Menu/index.tsx

@@ -73,6 +73,7 @@ const MenuPage = (props: Props) => {
     const res = await service.saveOwnerTree('iot', data.id, datalist);
     if (res?.status === 200) {
       onlyMessage('操作成功');
+      props.close(true);
     }
   };
 
@@ -110,6 +111,7 @@ const MenuPage = (props: Props) => {
         props.close();
       }}
       onOk={() => {
+        // props.close(true)
         const items = filterTree(treeData, [...keys, ...half]);
         if (owner) {
           if (items && items.length !== 0) {

+ 9 - 13
src/pages/system/Apply/Save/index.tsx

@@ -261,10 +261,10 @@ const Save = () => {
               field.selfErrors = '';
             }
           });
-          onFieldReact('apiServer.appId', (field: any) => {
-            const value = (field as Field).value;
-            console.log(value);
-          });
+          // onFieldReact('apiServer.appId', (field: any) => {
+          //   const value = (field as Field).value;
+          //   console.log(value);
+          // });
         },
       }),
     [id],
@@ -1966,14 +1966,6 @@ const Save = () => {
     }
   }, [location]);
 
-  useEffect(() => {
-    const item = form.getValuesIn('provider');
-    // console.log(item, form.getState())
-    // setType(localStorage.getItem('type'))
-
-    console.log(item, form.getState());
-  }, []);
-
   return (
     <PageContainer>
       <Card>
@@ -2015,8 +2007,12 @@ const Save = () => {
       {visible && (
         <MenuPage
           data={detail}
-          close={() => {
+          close={(isOk?: any) => {
             setVisiable(false);
+            if (isOk) {
+              const url = getMenuPathByCode('system/Apply');
+              history.push(url);
+            }
           }}
         />
       )}

+ 1 - 1
src/pages/system/DataSource/Management/DataTable.tsx

@@ -30,7 +30,7 @@ const DataTable = (props: Props) => {
     validateId(value) {
       if (!value) return '';
       const reg = new RegExp('^[0-9a-zA-Z_\\\\-]+$');
-      return reg.exec(value) ? '' : 'ID只能由数字、字母、下划线、中划线组成';
+      return reg.exec(value) ? '' : '名称只能由数字、字母、下划线、中划线组成';
     },
   });