react-base-client 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-base-client",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "author": "yyc <000000@163.com>",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -4,6 +4,7 @@ import * as HostApp from '../../utils/hostapp';
4
4
  import { AMapType } from './typing.d';
5
5
  // @ts-ignore
6
6
  import LocationIcon from '../../assets/icon/location.svg';
7
+ import ReactDOM from 'react-dom';
7
8
 
8
9
  // @ts-ignore
9
10
  import weiXinIcon from '../../assets/icon/weiXin.svg';
@@ -496,6 +497,64 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
496
497
  });
497
498
  };
498
499
 
500
+ const infoWindowRef = useRef<any>(null);
501
+
502
+ const openInfoWindow = (lng: number, lat: number, content: React.ReactNode) => {
503
+ if (!getAMap || !mapRef.current) return;
504
+ if (infoWindowRef.current) {
505
+ infoWindowRef.current.close();
506
+ infoWindowRef.current = null;
507
+ }
508
+ // 创建内容容器
509
+ const div = document.createElement('div');
510
+ div.style.position = 'relative';
511
+ div.style.minWidth = '200px';
512
+ div.style.minHeight = '120px';
513
+ div.style.padding = '12px 16px 8px 16px';
514
+ div.style.boxSizing = 'border-box';
515
+ div.style.background = '#fff';
516
+ div.style.borderRadius = '8px';
517
+ div.style.maxHeight = '300px';
518
+ div.style.overflowY = 'auto';
519
+
520
+ // 内容区
521
+ const contentDiv = document.createElement('div');
522
+ contentDiv.style.marginTop = '0px';
523
+ div.appendChild(contentDiv);
524
+
525
+ // 渲染 React 组件
526
+ let renderContent: React.ReactElement = <></>;
527
+ if (React.isValidElement(content)) {
528
+ renderContent = content as React.ReactElement;
529
+ } else {
530
+ renderContent = <span>{String(content)}</span>;
531
+ }
532
+ ReactDOM.render(renderContent, contentDiv);
533
+
534
+ // 点击内容关闭
535
+ contentDiv.onclick = () => {
536
+ if (infoWindowRef.current) {
537
+ infoWindowRef.current.close();
538
+ infoWindowRef.current = null;
539
+ }
540
+ };
541
+
542
+ const infoWindow = new getAMap.InfoWindow({
543
+ content: div,
544
+ offset: new getAMap.Pixel(0, -20),
545
+ autoMove: true,
546
+ closeWhenClickMap: true,
547
+ });
548
+ infoWindow.open(mapRef.current, [lng, lat]);
549
+ infoWindowRef.current = infoWindow;
550
+ };
551
+ const closeInfoWindow = () => {
552
+ if (infoWindowRef.current) {
553
+ infoWindowRef.current.close();
554
+ infoWindowRef.current = null;
555
+ }
556
+ };
557
+
499
558
  useEffect(() => {
500
559
  console.log('Map component mounted');
501
560
  let intervalIdRef: NodeJS.Timeout | null = null;
@@ -577,6 +636,8 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
577
636
  useImperativeHandle(ref, () => {
578
637
  return {
579
638
  setZommAndCenterViewNoMap,
639
+ openInfoWindow,
640
+ closeInfoWindow
580
641
  };
581
642
  });
582
643
 
@@ -57,7 +57,7 @@ const XAMap: React.FC<XAMapProps> = (props) => {
57
57
 
58
58
  return (
59
59
  <>
60
- <div
60
+ <div
61
61
  onClick={handleMapClick}
62
62
  style={{
63
63
  padding: '12px',
@@ -67,11 +67,20 @@ const XAMap: React.FC<XAMapProps> = (props) => {
67
67
  cursor: 'pointer',
68
68
  minHeight: '40px',
69
69
  display: 'flex',
70
- alignItems: 'center',
70
+ flexDirection: 'column',
71
+ alignItems: 'flex-start',
71
72
  color: value ? '#000' : '#999'
72
73
  }}
73
74
  >
74
- {value ? '点击查看地图' : placeholder}
75
+ {value && value['设备类型'] ? (
76
+ <>
77
+ <div>设备类型:{value['设备类型'] || '-'}</div>
78
+ <div>地址:{value['地址'] || '-'}</div>
79
+ <div>设备编号:{value['设备编号'] || '-'}</div>
80
+ </>
81
+ ) : (
82
+ <span>{placeholder}</span>
83
+ )}
75
84
  </div>
76
85
 
77
86
  <Popup