@cqsjjb/jjb-react-admin-component 3.1.4 → 3.2.0-beta.0

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.
@@ -0,0 +1,40 @@
1
+ import * as React from 'react';
2
+
3
+ export interface BMapProps {
4
+ /** 初始经度 默认-116.404 */
5
+ lng?: number;
6
+ /** 初始纬度 默认-39.915 */
7
+ lat?: number;
8
+ /** 标题 默认-百度地图 */
9
+ title?: string;
10
+ /** 地图弹窗宽度 默认-700 */
11
+ width?: number;
12
+ /** 确认事件 返回选择的位置信息 */
13
+ onOk?: (data: {
14
+ // 经度
15
+ lng: number;
16
+ // 纬度
17
+ lat: number;
18
+ // 选择的位置信息对象
19
+ comp?: {
20
+ // 省份
21
+ province: string;
22
+ // 城市
23
+ city: string;
24
+ // 区县
25
+ district: string;
26
+ // 街道
27
+ street: string;
28
+ // 门牌号
29
+ streetNumber: string;
30
+ };
31
+ // 选择的位置详细信息文本
32
+ compText?: string;
33
+ }) => void;
34
+ /** 取消事件 */
35
+ onCancel?: () => void;
36
+ }
37
+
38
+ declare const BMap: React.FC<BMapProps>;
39
+
40
+ export default BMap;
package/BMap/index.js ADDED
@@ -0,0 +1,185 @@
1
+ import React, { useEffect, useRef, useState, useCallback } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Button, Col, message, Modal, Result, Row } from 'antd';
4
+ import './index.less';
5
+ const _B_MAP_SEARCH_ = '_B_MAP_SEARCH_';
6
+ const _B_MAP_DEFAULT_POINT_ = {
7
+ lng: 116.404,
8
+ lat: 39.915
9
+ };
10
+ const BMap = ({
11
+ lng: propLng,
12
+ lat: propLat,
13
+ title,
14
+ width,
15
+ onOk,
16
+ onCancel
17
+ }) => {
18
+ const [lng, setLng] = useState(_B_MAP_DEFAULT_POINT_.lng);
19
+ const [lat, setLat] = useState(_B_MAP_DEFAULT_POINT_.lat);
20
+ const GL = useRef(null);
21
+ const mapRef = useRef(null);
22
+
23
+ /** 初始化地图 */
24
+ useEffect(() => {
25
+ if (typeof window.BMapGL === 'undefined') {
26
+ message.error('未导入百度地图文件,生成地图失败!').then(() => null);
27
+ return;
28
+ }
29
+ const initLng = propLng || _B_MAP_DEFAULT_POINT_.lng;
30
+ const initLat = propLat || _B_MAP_DEFAULT_POINT_.lat;
31
+ setLng(initLng);
32
+ setLat(initLat);
33
+ const point = new window.BMapGL.Point(initLng, initLat);
34
+ const map = new window.BMapGL.Map(GL.current);
35
+ mapRef.current = map;
36
+ map.centerAndZoom(point, 18);
37
+ map.enableScrollWheelZoom(true);
38
+ map.addControl(new window.BMapGL.ScaleControl());
39
+ map.addControl(new window.BMapGL.ZoomControl());
40
+ map.addControl(new window.BMapGL.NavigationControl3D());
41
+ map.addControl(new window.BMapGL.CityListControl({
42
+ anchor: window.BMAP_ANCHOR_TOP_LEFT,
43
+ offset: new window.BMapGL.Size(10, 10),
44
+ onChangeSuccess: e => {
45
+ map.clearOverlays();
46
+ setLng(e.point.lng);
47
+ setLat(e.point.lat);
48
+ const p = new window.BMapGL.Point(e.point.lng, e.point.lat);
49
+ const marker = new window.BMapGL.Marker(p);
50
+ map.addOverlay(marker);
51
+ }
52
+ }));
53
+ const locationControl = new window.BMapGL.LocationControl({
54
+ anchor: window.BMAP_ANCHOR_BOTTOM_LEFT,
55
+ offset: new window.BMapGL.Size(20, 20)
56
+ });
57
+ locationControl.addEventListener('locationError', () => message.error('未知原因,定位失败!'));
58
+ map.addControl(locationControl);
59
+ const marker = new window.BMapGL.Marker(point);
60
+ map.addOverlay(marker);
61
+ map.addEventListener('click', e => {
62
+ map.clearOverlays();
63
+ setLng(e.latlng.lng);
64
+ setLat(e.latlng.lat);
65
+ const p = new window.BMapGL.Point(e.latlng.lng, e.latlng.lat);
66
+ const marker = new window.BMapGL.Marker(p);
67
+ map.addOverlay(marker);
68
+ });
69
+ setTimeout(() => {
70
+ const autoComplete = new window.BMapGL.Autocomplete({
71
+ input: _B_MAP_SEARCH_,
72
+ location: map
73
+ });
74
+ let myValue;
75
+ autoComplete.addEventListener('onconfirm', e => {
76
+ const value = e.item.value;
77
+ myValue = value.province + value.city + value.district + value.street + value.business;
78
+ setPlace();
79
+ });
80
+ function setPlace() {
81
+ const local = new window.BMapGL.LocalSearch(map, {
82
+ onSearchComplete: myFun
83
+ });
84
+ map.clearOverlays();
85
+ function myFun() {
86
+ const pp = local.getResults().getPoi(0).point;
87
+ setLng(pp.lng);
88
+ setLat(pp.lat);
89
+ map.centerAndZoom(pp, 18);
90
+ map.addOverlay(new window.BMapGL.Marker(pp));
91
+ }
92
+ local.search(myValue);
93
+ }
94
+ }, 500);
95
+ }, [propLng, propLat]);
96
+
97
+ /** 重置地图 */
98
+ const onResetMap = useCallback(() => {
99
+ if (!mapRef.current) return;
100
+ const map = mapRef.current;
101
+ map.clearOverlays();
102
+ setLng(_B_MAP_DEFAULT_POINT_.lng);
103
+ setLat(_B_MAP_DEFAULT_POINT_.lat);
104
+ const point = new window.BMapGL.Point(_B_MAP_DEFAULT_POINT_.lng, _B_MAP_DEFAULT_POINT_.lat);
105
+ const marker = new window.BMapGL.Marker(point);
106
+ map.centerAndZoom(_B_MAP_DEFAULT_POINT_, 18);
107
+ map.addOverlay(marker);
108
+ }, []);
109
+
110
+ /** 确认操作 */
111
+ const handleOk = useCallback(() => {
112
+ const map = mapRef.current;
113
+ if (!map) return;
114
+ const point = new window.BMapGL.Point(lng, lat);
115
+ const geocoder = new window.BMapGL.Geocoder();
116
+ geocoder.getLocation(point, (rs = {}) => {
117
+ const comp = rs?.addressComponents;
118
+ onOk && onOk({
119
+ lng,
120
+ lat,
121
+ comp,
122
+ compText: comp && [comp.province, comp.city, comp.district, comp.street, comp.streetNumber].join('') || undefined
123
+ });
124
+ });
125
+ }, [lng, lat, onOk]);
126
+ const hasMapScript = typeof window.BMapGL !== 'undefined';
127
+ return /*#__PURE__*/React.createElement(Modal, {
128
+ open: true,
129
+ destroyOnClose: true,
130
+ title: title,
131
+ width: width,
132
+ footer: hasMapScript && /*#__PURE__*/React.createElement(Row, {
133
+ align: "middle",
134
+ justify: "space-between"
135
+ }, /*#__PURE__*/React.createElement(Col, null, "\u5F53\u524D\u5750\u6807\uFF1A", [lng, lat].join('-')), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Button, {
136
+ ghost: true,
137
+ type: "primary",
138
+ style: {
139
+ marginRight: 12
140
+ },
141
+ onClick: onResetMap
142
+ }, "\u91CD\u7F6E\u5730\u56FE"), /*#__PURE__*/React.createElement(Button, {
143
+ type: "primary",
144
+ onClick: handleOk
145
+ }, "\u786E\u8BA4\u5750\u6807"))),
146
+ maskClosable: false,
147
+ onCancel: () => onCancel && onCancel()
148
+ }, hasMapScript ? /*#__PURE__*/React.createElement("div", {
149
+ style: {
150
+ position: 'relative'
151
+ }
152
+ }, /*#__PURE__*/React.createElement("div", {
153
+ ref: GL,
154
+ style: {
155
+ height: 500,
156
+ userSelect: 'none'
157
+ }
158
+ }), /*#__PURE__*/React.createElement("input", {
159
+ id: _B_MAP_SEARCH_,
160
+ type: "text",
161
+ maxLength: 30,
162
+ placeholder: "\u8BF7\u8F93\u5165\u5173\u952E\u5B57\u67E5\u8BE2"
163
+ })) : /*#__PURE__*/React.createElement(Result, {
164
+ status: "error",
165
+ title: "\u52A0\u8F7D\u5730\u56FE\u5931\u8D25\uFF0C\u7F3A\u5C11\u5FC5\u8981\u7684\u6587\u4EF6\uFF01"
166
+ }));
167
+ };
168
+ BMap.defaultProps = {
169
+ lng: 0,
170
+ lat: 0,
171
+ title: '百度地图',
172
+ width: 700
173
+ };
174
+ BMap.propTypes = {
175
+ lng: PropTypes.number,
176
+ lat: PropTypes.number,
177
+ width: PropTypes.number,
178
+ // 地图宽度
179
+ title: PropTypes.string,
180
+ // 标题
181
+ onOk: PropTypes.func,
182
+ // 确认事件
183
+ onCancel: PropTypes.func // 取消事件
184
+ };
185
+ export default BMap;
@@ -0,0 +1,36 @@
1
+ #_B_MAP_SEARCH_ {
2
+ position: absolute;
3
+ top: 10px;
4
+ right: 10px;
5
+ z-index: 10;
6
+ color: rgb(102 102 102);
7
+ box-shadow: 1px 2px 1px rgb(0 0 0 / 15%);
8
+ border: none;
9
+ height: 32px;
10
+ line-height: 32px;
11
+ width: 300px;
12
+ padding: 0 10px;
13
+ font-size: 12px;
14
+ outline: none;
15
+ border-radius: 3px;
16
+ }
17
+
18
+ .tangram-suggestion-main {
19
+ z-index: 1000;
20
+ margin-top: 6px;
21
+
22
+ .tangram-suggestion {
23
+ border: none;
24
+ box-shadow: 1px 2px 1px rgb(0 0 0 / 15%);
25
+ border-radius: 3px;
26
+ }
27
+ }
28
+
29
+ #selCityWd {
30
+ box-sizing: content-box;
31
+ }
32
+
33
+ .city_content_top {
34
+ box-sizing: content-box;
35
+ }
36
+
@@ -1,73 +1,59 @@
1
- // @ts-ignore
2
1
  import * as React from 'react';
3
- // @ts-ignore
4
- import { Moment } from 'moment';
5
- // @ts-ignore
6
- import { DefaultOptionType, FieldNamesType } from 'antd/es/cascader';
7
- import { ComponentProps } from '../types';
2
+ import { Dayjs } from 'dayjs';
3
+ import {
4
+ Input as OriginInput,
5
+ Select as OriginSelect,
6
+ Cascader as OriginCascader,
7
+ DatePicker as OriginDatePicker,
8
+ TreeSelect as OriginTreeSelect,
9
+ } from 'antd';
8
10
 
9
- interface BaseProps<T> extends ComponentProps {
10
- // 输入内容
11
- value?: T;
12
- // 标签
11
+ /** 公共扩展 props */
12
+ interface ExtraProps<T> {
13
+ /** 标签文本 */
13
14
  label?: string;
14
- // 标签宽度
15
+ /** 标签宽度 (Col span) */
15
16
  labelSpan?: number;
16
- // 内容清空
17
- allowClear?: boolean;
18
- // 占位符
19
- placeholder?: string;
20
- // 输出事件
17
+ /** 自定义样式 */
18
+ style?: React.CSSProperties;
19
+ /** 受控值 */
20
+ value?: T;
21
+ /** 值变化回调 */
21
22
  onChange?: (value: T) => void;
22
23
  }
23
24
 
24
- interface InputProps<T> extends BaseProps<T> {
25
- // 文本长度
26
- maxLength?: number;
27
- }
25
+ /** 包装后的类型工具 */
26
+ type WithExtraProps<C, T = any> = React.FC<
27
+ React.ComponentProps<C> & ExtraProps<T>
28
+ >;
28
29
 
29
- interface SelectProps<T> extends BaseProps<T> {
30
- // 设置 Select 的模式为多选或标签
31
- mode?: 'multiple' | 'tags';
32
- // 最多显示多少个tag
33
- maxTagCount?: number;
34
- }
30
+ declare const ControlWrapper: {
31
+ /** 输入框 */
32
+ Input: WithExtraProps<typeof OriginInput, string | number>;
35
33
 
36
- interface CascaderProps<T> extends BaseProps<T> {
37
- // 可选项数据源
38
- options?: DefaultOptionType[];
39
- // 支持多选节点
40
- multiple?: boolean;
41
- // 自定义 options 中 label value children 的字段
42
- fieldNames?: FieldNamesType;
43
- // 最多显示多少个tag
44
- maxTagCount?: number;
45
- // 定义选中项回填的方式
46
- showCheckedStrategy?: 'SHOW_CHILD' | 'SHOW_PARENT';
47
- }
34
+ /** 下拉选择 */
35
+ Select: WithExtraProps<typeof OriginSelect, string | number>;
48
36
 
49
- interface DatePickerProps<T> {
50
- // 标签
51
- label?: string;
52
- // 输入
53
- value?: T;
54
- // 格式日期
55
- format?: string;
56
- // 输出事件
57
- onChange?: (value: T) => void;
58
- }
37
+ /** 级联选择 */
38
+ Cascader: WithExtraProps<typeof OriginCascader, (string | number)[]>;
59
39
 
60
- declare const ControlWrapper: {
61
- // 输入
62
- Input: React.FC<InputProps<string | number>>;
63
- // 选择
64
- Select: React.FC<SelectProps<string | number>>;
65
- // 级联选择
66
- Cascader: React.FC<CascaderProps<string[] | number[]>>;
67
- // 日期选择
68
- DatePicker: React.FC<DatePickerProps<Moment>> & {
69
- // 日期范围选择
70
- RangePicker: React.FC<DatePickerProps<Moment[]>>
40
+ /** 树形选择 */
41
+ TreeSelect: WithExtraProps<typeof OriginTreeSelect, string | number>;
42
+
43
+ /** 日期选择 */
44
+ DatePicker: WithExtraProps<typeof OriginDatePicker, Dayjs> & {
45
+ /** 时间选择 */
46
+ TimePicker: WithExtraProps<typeof OriginDatePicker.TimePicker, Dayjs>;
47
+ /** 日期范围选择 */
48
+ RangePicker: WithExtraProps<typeof OriginDatePicker.RangePicker, Dayjs[]>;
49
+ /** 周选择 */
50
+ WeekPicker: WithExtraProps<typeof OriginDatePicker.WeekPicker, Dayjs>;
51
+ /** 月选择 */
52
+ MonthPicker: WithExtraProps<typeof OriginDatePicker.MonthPicker, Dayjs>;
53
+ /** 季度选择 */
54
+ QuarterPicker: WithExtraProps<typeof OriginDatePicker.QuarterPicker, Dayjs>;
55
+ /** 年选择 */
56
+ YearPicker: WithExtraProps<typeof OriginDatePicker.YearPicker, Dayjs>;
71
57
  };
72
58
  };
73
59