@cqsjjb/jjb-react-admin-component 3.3.0-beta.1 → 3.3.0-beta.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/AMap/README.md ADDED
@@ -0,0 +1,58 @@
1
+ 高德地图组件
2
+
3
+ ## 代码演示
4
+
5
+ ```jsx
6
+ import { useState } from 'react';
7
+ import { Button } from 'antd';
8
+ import AMap from '@cqsjjb/jjb-react-admin-component/AMap';
9
+
10
+ function App() {
11
+ const [ open, setOpen ] = useState(false);
12
+ return (
13
+ <>
14
+ <Button onClick={() => setOpen(true)}>打开地图</Button>
15
+ {open && (
16
+ <AMap
17
+ onOk={data => {
18
+ console.log(data);
19
+ setOpen(false);
20
+ }}
21
+ onCacnel={() => {
22
+ setOpen(false);
23
+ }}
24
+ />
25
+ )}
26
+ </>
27
+ )
28
+ }
29
+ ```
30
+
31
+ ## API
32
+
33
+ | 属性 | 说明 | 类型 | 默认值 |
34
+ |----------|:-----|:---------------------------------------------------------------------------------------------------------:|--------:|
35
+ | lng | 经度 | `number` | 116.404 |
36
+ | lat | 纬度 | `number` | 39.915 |
37
+ | title | 弹窗标题 | `string` | 高德地图 |
38
+ | width | 弹窗宽度 | `number` | 700 |
39
+ | onOk | 确认回调 | (data: { lng: number, lat: number, comp: <span style="color: red">IComp</span>, compText: Text }) => void | - |
40
+ | onCancel | 取消回调 | `() => void` | 700 |
41
+
42
+ ## 确认回调-IComp
43
+
44
+ | 属性 | 说明 | 类型 | 默认值 |
45
+ |--------------|:----|:--------:|----:|
46
+ | province | 省份 | `string` | - |
47
+ | city | 城市 | `string` | - |
48
+ | district | 区县 | `string` | - |
49
+ | street | 街道 | `string` | - |
50
+ | streetNumber | 门牌号 | `string` | - |
51
+
52
+ ## 常见问题
53
+ * 加载地图失败,缺少必要的文件!
54
+
55
+ 请确认应用public/index.html中是否导入高德地图SDK。
56
+ * onOk确认回调compText为undefined
57
+
58
+ 请确认高德地图是否授权Web应用。
@@ -0,0 +1,40 @@
1
+ import * as React from 'react';
2
+
3
+ export interface AMapProps {
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 AMap: React.FC<AMapProps>;
39
+
40
+ export default AMap;
package/AMap/index.js ADDED
@@ -0,0 +1,246 @@
1
+ import React, { useEffect, useRef, useState, useCallback } from 'react';
2
+ import { Button, Col, message, Modal, Result, Row } from 'antd';
3
+ import './index.less';
4
+ const _A_MAP_SEARCH_ = '_A_MAP_SEARCH_';
5
+ const _A_MAP_DEFAULT_POINT_ = {
6
+ lng: 116.397437,
7
+ lat: 39.909148
8
+ };
9
+ const AMap = ({
10
+ lng: propLng,
11
+ lat: propLat,
12
+ title = '高德地图',
13
+ width = 700,
14
+ onOk,
15
+ onCancel
16
+ }) => {
17
+ const [lng, setLng] = useState(_A_MAP_DEFAULT_POINT_.lng);
18
+ const [lat, setLat] = useState(_A_MAP_DEFAULT_POINT_.lat);
19
+ const GL = useRef(null); // 地图容器,沿用你原来的名字
20
+ const mapRef = useRef(null);
21
+ const markerRef = useRef(null);
22
+ const autoRef = useRef(null);
23
+ const placeSearchRef = useRef(null);
24
+ useEffect(() => {
25
+ if (typeof window.AMap === 'undefined') {
26
+ message.error('未导入高德地图文件,生成地图失败!').then(() => null);
27
+ return;
28
+ }
29
+ const initLng = propLng || _A_MAP_DEFAULT_POINT_.lng;
30
+ const initLat = propLat || _A_MAP_DEFAULT_POINT_.lat;
31
+ setLng(initLng);
32
+ setLat(initLat);
33
+
34
+ // 创建地图
35
+ const map = new window.AMap.Map(GL.current, {
36
+ center: [initLng, initLat],
37
+ zoom: 18,
38
+ viewMode: '3D'
39
+ });
40
+ mapRef.current = map;
41
+
42
+ // 通过 plugin 先加载需要的插件(保证控件类存在)
43
+ window.AMap.plugin(['AMap.Scale', 'AMap.ToolBar', 'AMap.Geolocation', 'AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.Geocoder'], () => {
44
+ // 比例尺
45
+ try {
46
+ const scale = new window.AMap.Scale();
47
+ map.addControl(scale);
48
+ } catch (e) {
49
+ // 某些按需构建或旧环境可能报错,容错处理
50
+ // console.warn('AMap.Scale plugin not available', e);
51
+ }
52
+
53
+ // 工具条(放大缩小)
54
+ try {
55
+ map.addControl(new window.AMap.ToolBar({
56
+ position: 'RT'
57
+ }));
58
+ } catch (e) {}
59
+
60
+ // 定位控件
61
+ try {
62
+ const geolocation = new window.AMap.Geolocation({
63
+ position: 'BT',
64
+ offset: new window.AMap.Pixel(20, 20),
65
+ showCircle: false,
66
+ showButton: true
67
+ });
68
+ map.addControl(geolocation);
69
+ geolocation.getCurrentPosition(status => {
70
+ if (status !== 'complete') {
71
+ message.error('未知原因,定位失败!');
72
+ }
73
+ });
74
+ } catch (e) {}
75
+
76
+ // 初始 marker
77
+ markerRef.current = new window.AMap.Marker({
78
+ position: [initLng, initLat],
79
+ map
80
+ });
81
+
82
+ // 自动完成 + 地点搜索
83
+ try {
84
+ placeSearchRef.current = new window.AMap.PlaceSearch({
85
+ map
86
+ });
87
+ autoRef.current = new window.AMap.AutoComplete({
88
+ input: document.getElementById(_A_MAP_SEARCH_)
89
+ });
90
+ autoRef.current.on && autoRef.current.on('select', e => {
91
+ // e.poi 里通常包含 name / location / adcode 等信息
92
+ const name = e?.poi && (e.poi.name || e.poi.address) || e?.info || e?.name;
93
+ // if (!name) return;
94
+ placeSearchRef.current.search(name, (status, result) => {
95
+ if (status === 'complete' && result && result.poiList && result.poiList.pois && result.poiList.pois.length > 0) {
96
+ const poi = result.poiList.pois[0];
97
+ const loc = poi.location || poi.lnglat;
98
+ const foundLng = loc && (loc.lng || Array.isArray(loc) && loc[0]) || null;
99
+ const foundLat = loc && (loc.lat || Array.isArray(loc) && loc[1]) || null;
100
+ if (foundLng != null && foundLat != null) {
101
+ setLng(foundLng);
102
+ setLat(foundLat);
103
+ map.setCenter([foundLng, foundLat]);
104
+ if (markerRef.current) {
105
+ markerRef.current.setPosition([foundLng, foundLat]);
106
+ } else {
107
+ markerRef.current = new window.AMap.Marker({
108
+ position: [foundLng, foundLat],
109
+ map
110
+ });
111
+ }
112
+ }
113
+ }
114
+ });
115
+ });
116
+ } catch (e) {}
117
+
118
+ // 地图点击选点
119
+ map.on && map.on('click', e => {
120
+ const {
121
+ lng: clickLng,
122
+ lat: clickLat
123
+ } = e.lnglat || {};
124
+ if (clickLng == null || clickLat == null) return;
125
+ setLng(clickLng);
126
+ setLat(clickLat);
127
+ if (markerRef.current) {
128
+ markerRef.current.setPosition([clickLng, clickLat]);
129
+ } else {
130
+ markerRef.current = new window.AMap.Marker({
131
+ position: [clickLng, clickLat],
132
+ map
133
+ });
134
+ }
135
+ });
136
+ });
137
+
138
+ // cleanup
139
+ return () => {
140
+ try {
141
+ if (mapRef.current) {
142
+ mapRef.current.destroy();
143
+ mapRef.current = null;
144
+ }
145
+ } catch (e) {}
146
+ markerRef.current = null;
147
+ autoRef.current = null;
148
+ placeSearchRef.current = null;
149
+ };
150
+ }, [propLng, propLat]);
151
+
152
+ /** 重置地图 */
153
+ const onResetMap = useCallback(() => {
154
+ const map = mapRef.current;
155
+ if (!map) return;
156
+ setLng(_A_MAP_DEFAULT_POINT_.lng);
157
+ setLat(_A_MAP_DEFAULT_POINT_.lat);
158
+ map.setCenter([_A_MAP_DEFAULT_POINT_.lng, _A_MAP_DEFAULT_POINT_.lat]);
159
+ if (markerRef.current) {
160
+ markerRef.current.setPosition([_A_MAP_DEFAULT_POINT_.lng, _A_MAP_DEFAULT_POINT_.lat]);
161
+ } else {
162
+ markerRef.current = new window.AMap.Marker({
163
+ position: [_A_MAP_DEFAULT_POINT_.lng, _A_MAP_DEFAULT_POINT_.lat],
164
+ map
165
+ });
166
+ }
167
+ }, []);
168
+
169
+ /** 确认操作(逆地理编码) */
170
+ const handleOk = useCallback(() => {
171
+ if (!mapRef.current) return;
172
+ // 确保 Geocoder 可用
173
+ window.AMap.plugin('AMap.Geocoder', () => {
174
+ try {
175
+ const geocoder = new window.AMap.Geocoder();
176
+ geocoder.getAddress([lng, lat], (status, result) => {
177
+ let comp;
178
+ if (status === 'complete' && result && result.regeocode) {
179
+ comp = result.regeocode.addressComponent;
180
+ }
181
+ onOk && onOk({
182
+ lng,
183
+ lat,
184
+ comp,
185
+ compText: comp && [comp.province, comp.city, comp.district, comp.township, comp.street, comp.streetNumber].filter(Boolean).join('') || undefined
186
+ });
187
+ });
188
+ } catch (e) {
189
+ onOk && onOk({
190
+ lng,
191
+ lat,
192
+ comp: undefined,
193
+ compText: undefined
194
+ });
195
+ }
196
+ });
197
+ }, [lng, lat, onOk]);
198
+ const hasMapScript = typeof window.AMap !== 'undefined';
199
+ return /*#__PURE__*/React.createElement(Modal, {
200
+ open: true,
201
+ destroyOnClose: true,
202
+ title: title,
203
+ width: width,
204
+ footer: hasMapScript && /*#__PURE__*/React.createElement(Row, {
205
+ align: "middle",
206
+ justify: "space-between"
207
+ }, /*#__PURE__*/React.createElement(Col, null, "\u5750\u6807\uFF1A", [lng, lat].join('-')), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Button, {
208
+ ghost: true,
209
+ type: "primary",
210
+ style: {
211
+ marginRight: 12
212
+ },
213
+ onClick: onResetMap
214
+ }, "\u91CD\u7F6E\u5730\u56FE"), /*#__PURE__*/React.createElement(Button, {
215
+ type: "primary",
216
+ onClick: handleOk
217
+ }, "\u786E\u8BA4\u5750\u6807"))),
218
+ maskClosable: false,
219
+ onCancel: () => onCancel && onCancel()
220
+ }, hasMapScript ? /*#__PURE__*/React.createElement("div", {
221
+ style: {
222
+ position: 'relative'
223
+ }
224
+ }, /*#__PURE__*/React.createElement("div", {
225
+ ref: GL,
226
+ style: {
227
+ height: 500,
228
+ userSelect: 'none'
229
+ }
230
+ }), /*#__PURE__*/React.createElement("input", {
231
+ id: _A_MAP_SEARCH_,
232
+ type: "text",
233
+ maxLength: 30,
234
+ placeholder: "\u8BF7\u8F93\u5165\u5173\u952E\u5B57\u67E5\u8BE2",
235
+ style: {
236
+ position: 'absolute',
237
+ top: 10,
238
+ left: 10,
239
+ zIndex: 1000
240
+ }
241
+ })) : /*#__PURE__*/React.createElement(Result, {
242
+ status: "error",
243
+ title: "\u52A0\u8F7D\u5730\u56FE\u5931\u8D25\uFF0C\u7F3A\u5C11\u5FC5\u8981\u7684\u6587\u4EF6\uFF01"
244
+ }));
245
+ };
246
+ export default AMap;
@@ -0,0 +1,35 @@
1
+ #_A_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
+ }
package/BMap/README.md CHANGED
@@ -50,7 +50,7 @@ function App() {
50
50
  | streetNumber | 门牌号 | `string` | - |
51
51
 
52
52
  ## 常见问题
53
- * 未导入百度地图文件,生成地图失败!
53
+ * 加载地图失败,缺少必要的文件!
54
54
 
55
55
  请确认应用public/index.html中是否导入百度地图SDK。
56
56
  * onOk确认回调compText为undefined
package/BMap/index.less CHANGED
@@ -1,36 +1,35 @@
1
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%);
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 {
8
23
  border: none;
9
- height: 32px;
10
- line-height: 32px;
11
- width: 300px;
12
- padding: 0 10px;
13
- font-size: 12px;
14
- outline: none;
24
+ box-shadow: 1px 2px 1px rgb(0 0 0 / 15%);
15
25
  border-radius: 3px;
16
26
  }
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
-
27
+ }
28
+
29
+ #selCityWd {
30
+ box-sizing: content-box;
31
+ }
32
+
33
+ .city_content_top {
34
+ box-sizing: content-box;
35
+ }
@@ -2,8 +2,8 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
2
2
  import React, { useState, useEffect, useCallback, useImperativeHandle, forwardRef } from 'react';
3
3
  import { Table, Row, Col, Form } from 'antd';
4
4
  import { isEqual } from 'lodash';
5
- import SearchForm from '../SearchForm';
6
- import ProTable from '../Table';
5
+ import SearchForm from '@cqsjjb/jjb-react-admin-component/SearchForm';
6
+ import ProTable from '@cqsjjb/jjb-react-admin-component/Table';
7
7
 
8
8
  /**
9
9
  * @component ListDataContainer
@@ -53,11 +53,10 @@ const ListDataContainer = /*#__PURE__*/forwardRef(({
53
53
  searchFormConfig = [],
54
54
  rowKey = 'id',
55
55
  initialPagination = {
56
- current: 1,
56
+ pageIndex: 1,
57
57
  pageSize: 10,
58
58
  showSizeChanger: true,
59
- showQuickJumper: true,
60
- showTotal: total => `共 ${total} 条记录`
59
+ showQuickJumper: true
61
60
  },
62
61
  tableProps = {},
63
62
  proTable = false
@@ -85,7 +84,7 @@ const ListDataContainer = /*#__PURE__*/forwardRef(({
85
84
 
86
85
  // 2. 构造基础参数:分页参数 + 表单参数
87
86
  const baseParams = {
88
- page: pagination.current,
87
+ pageIndex: pagination.pageIndex,
89
88
  pageSize: pagination.pageSize,
90
89
  ...formValues
91
90
  };
@@ -98,8 +97,8 @@ const ListDataContainer = /*#__PURE__*/forwardRef(({
98
97
 
99
98
  // 4. 发起请求
100
99
  const response = await fetchDataApi(requestParams);
101
- setTableData(response.data.list || []);
102
- setTotalCount(response.data.total || 0);
100
+ setTableData(response.data || []);
101
+ setTotalCount(response.totalCount || 0);
103
102
  } catch (error) {
104
103
  console.error('列表数据请求失败:', error);
105
104
  setTableData([]);
@@ -118,9 +117,12 @@ const ListDataContainer = /*#__PURE__*/forwardRef(({
118
117
  // 搜索时重置到第一页,并用表单值覆盖(values会合并到baseParams中)
119
118
  setPagination(prev => ({
120
119
  ...prev,
121
- current: 1
120
+ pageIndex: 1
122
121
  }));
123
- loadDataSource(values);
122
+ loadDataSource({
123
+ ...values,
124
+ pageIndex: 1
125
+ });
124
126
  };
125
127
  const handleReset = () => {
126
128
  // 清空表单
@@ -133,17 +135,20 @@ const ListDataContainer = /*#__PURE__*/forwardRef(({
133
135
  loadDataSource();
134
136
  };
135
137
  const handlePaginationChange = newPagination => {
138
+ console.warn("ssssssssssss", newPagination);
136
139
  // 更新分页后,用新分页参数查询
137
- setPagination(newPagination);
140
+ setPagination({
141
+ ...newPagination,
142
+ pageIndex: newPagination.current
143
+ });
144
+ loadDataSource({
145
+ pageIndex: newPagination.current,
146
+ pageSize: newPagination.pageSize
147
+ });
138
148
  };
139
-
140
- // 分页变化时自动重新加载
141
149
  useEffect(() => {
142
- // 避免初始加载时重复调用,判断两个对象是否相等
143
- if (!isEqual(pagination, initialPagination)) {
144
- loadDataSource();
145
- }
146
- }, [pagination, loadDataSource]);
150
+ loadDataSource();
151
+ }, []);
147
152
  const generateFormItems = () => {
148
153
  return searchFormConfig.map((item, index) => {
149
154
  const {
@@ -193,6 +198,7 @@ const ListDataContainer = /*#__PURE__*/forwardRef(({
193
198
  loading: loading,
194
199
  pagination: {
195
200
  ...pagination,
201
+ current: pagination.pageIndex,
196
202
  total: totalCount
197
203
  },
198
204
  onChange: handlePaginationChange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cqsjjb/jjb-react-admin-component",
3
- "version": "3.3.0-beta.1",
3
+ "version": "3.3.0-beta.3",
4
4
  "description": "jjb-react-admin-组件库@new",
5
5
  "main": "index.js",
6
6
  "author": "jjb-front-team",