Przeglądaj źródła

fix: bug#4645、4607

xieyonghong 3 lat temu
rodzic
commit
f2711c9da5

+ 17 - 12
src/components/AMapComponent/PathSimplifier/PathNavigator.tsx

@@ -47,21 +47,26 @@ export default (props: PathNavigatorProps) => {
   const createPathNavigator = useCallback(
     (path?: PathSimplifier) => {
       if (path) {
-        PathNavigatorRef.current = path.createPathNavigator(navKey!, {
-          speed: props.speed || 10000,
-          ...omit(extraProps, Object.values(EventMap)),
-        });
+        const pathData = path.getPathData(navKey!);
+        if (pathData?.path && pathData?.path.length) {
+          // 避免path为空数组时,导致创建巡航器异常
 
-        if (PathNavigatorRef.current) {
-          createEvent();
-        }
+          PathNavigatorRef.current = path.createPathNavigator(navKey!, {
+            speed: props.speed || 10000,
+            ...omit(extraProps, Object.values(EventMap)),
+          });
 
-        if (onCreate && PathNavigatorRef.current) {
-          onCreate(PathNavigatorRef.current);
-        }
+          if (PathNavigatorRef.current) {
+            createEvent();
+          }
+
+          if (onCreate && PathNavigatorRef.current) {
+            onCreate(PathNavigatorRef.current);
+          }
 
-        if (props.isAuto !== false) {
-          PathNavigatorRef.current?.start();
+          if (props.isAuto !== false) {
+            PathNavigatorRef.current?.start();
+          }
         }
       }
     },

+ 1 - 0
src/components/AMapComponent/PathSimplifier/index.tsx

@@ -34,6 +34,7 @@ const PathSimplifier = (props: PathSimplifierProps) => {
       }
 
       if (props.pathData) {
+        console.log(props.pathData.map((item) => ({ name: item.name || '路线', path: item.path })));
         pathSimplifierRef.current?.setData(
           props.pathData.map((item) => ({ name: item.name || '路线', path: item.path })),
         );

+ 4 - 2
src/pages/rule-engine/Scene/Save/components/InputUpload/index.tsx

@@ -13,7 +13,7 @@ interface InputUploadProps {
 export default (props: InputUploadProps) => {
   const { onChange } = props;
 
-  const [url, setUrl] = useState(props.value);
+  const [url, setUrl] = useState(props.value || undefined);
   const [loading, setLoading] = useState<boolean>(false);
 
   useEffect(() => {
@@ -28,7 +28,9 @@ export default (props: InputUploadProps) => {
       info.file.url = info.file.response?.result;
       setLoading(false);
       if (onChange) {
-        onChange(info.file.response?.result);
+        const result = info.file.response?.result;
+        setUrl(result);
+        onChange(result);
       }
     }
   };