@etsoo/smarterp-core 1.1.3 → 1.1.5
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/LICENSE +1 -1
- package/__tests__/PublicApi.ts +8 -4
- package/lib/cjs/PublicApi.d.ts +2 -2
- package/lib/cjs/PublicApi.js +29 -2
- package/lib/cjs/components/public/AddressTiplist.d.ts +9 -1
- package/lib/cjs/components/public/AddressTiplist.js +23 -8
- package/lib/cjs/rq/public/PlaceQueryRQ.d.ts +2 -10
- package/lib/cjs/rq/public/PlaceQueryRQ.js +1 -10
- package/lib/mjs/PublicApi.d.ts +2 -2
- package/lib/mjs/PublicApi.js +30 -3
- package/lib/mjs/components/public/AddressTiplist.d.ts +9 -1
- package/lib/mjs/components/public/AddressTiplist.js +20 -8
- package/lib/mjs/rq/public/PlaceQueryRQ.d.ts +2 -10
- package/lib/mjs/rq/public/PlaceQueryRQ.js +0 -9
- package/package.json +4 -4
- package/src/PublicApi.ts +49 -2
- package/src/components/public/AddressTiplist.tsx +38 -14
- package/src/rq/public/PlaceQueryRQ.ts +2 -11
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2004-
|
|
3
|
+
Copyright (c) 2004-2026 ETSOO ® (亿速思维 ®), https://etsoo.com, https://etsoo.nz
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/__tests__/PublicApi.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isLocalTest, TestApp } from "./app/TestApp";
|
|
2
2
|
import { PublicApi } from "../src/PublicApi";
|
|
3
3
|
import { PinyinFormatType } from "../src/rq/public/PinyinRQ";
|
|
4
|
-
import {
|
|
4
|
+
import { MapApiProvider } from "@etsoo/appscript";
|
|
5
5
|
|
|
6
6
|
const app = new TestApp();
|
|
7
7
|
|
|
@@ -111,7 +111,7 @@ if (isLocalTest) {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
test("Test for CN queryPlace", async () => {
|
|
114
|
-
const result = await api.queryPlace({
|
|
114
|
+
const [provider, result] = await api.queryPlace({
|
|
115
115
|
query: "山东省青岛李沧清溪路88号玫瑰庭院10号楼二单元501室",
|
|
116
116
|
region: "CN"
|
|
117
117
|
});
|
|
@@ -119,6 +119,8 @@ if (isLocalTest) {
|
|
|
119
119
|
expect(result).not.toBeNull();
|
|
120
120
|
if (result == null) return;
|
|
121
121
|
|
|
122
|
+
expect(provider).toBe(MapApiProvider.Amap);
|
|
123
|
+
|
|
122
124
|
const first = result.filter((x) => x.district === "李沧区")[0];
|
|
123
125
|
expect(first.region).toBe("CN");
|
|
124
126
|
expect(first.state).toBe("山东省");
|
|
@@ -129,14 +131,16 @@ if (isLocalTest) {
|
|
|
129
131
|
});
|
|
130
132
|
|
|
131
133
|
test("Test for world queryPlace", async () => {
|
|
132
|
-
const result = await api.queryPlace({
|
|
134
|
+
const [provider, result] = await api.queryPlace({
|
|
133
135
|
query: "14A Cranbrook Place, Glendowie, Auckland 1071",
|
|
134
|
-
provider:
|
|
136
|
+
provider: MapApiProvider.Google
|
|
135
137
|
});
|
|
136
138
|
|
|
137
139
|
expect(result).not.toBeNull();
|
|
138
140
|
if (result == null) return;
|
|
139
141
|
|
|
142
|
+
expect(provider).toBe(MapApiProvider.Google);
|
|
143
|
+
|
|
140
144
|
const first = result[0];
|
|
141
145
|
expect(first.region).toBe("NZ");
|
|
142
146
|
expect(first.state).toBe("Auckland");
|
package/lib/cjs/PublicApi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { CurrencyItem } from "./dto/public/CurrencyItem";
|
|
|
6
6
|
import { RegionData } from "./dto/public/RegionData";
|
|
7
7
|
import { PlaceQueryRQ } from "./rq/public/PlaceQueryRQ";
|
|
8
8
|
import { PlaceCommon } from "./dto/public/PlaceCommon";
|
|
9
|
-
import { BaseApi, CultureItem, Currency, CustomCulture, IApp, ProductUnit, ResultPayload } from "@etsoo/appscript";
|
|
9
|
+
import { BaseApi, CultureItem, Currency, CustomCulture, IApp, MapApiProvider, ProductUnit, ResultPayload } from "@etsoo/appscript";
|
|
10
10
|
import { MemberInvitationDto } from "./dto/public/MemberInvitationDto";
|
|
11
11
|
import { AcceptInvitationRQ } from "./rq/public/AcceptInvitationRQ";
|
|
12
12
|
import { ChinaPinData } from "./dto/public/ChinaPinData";
|
|
@@ -114,7 +114,7 @@ export declare class PublicApi extends BaseApi {
|
|
|
114
114
|
* @param payload Payload
|
|
115
115
|
* @returns Result
|
|
116
116
|
*/
|
|
117
|
-
queryPlace(rq: PlaceQueryRQ, payload?: IApiPayload<PlaceCommon[]>): Promise<PlaceCommon[] | undefined>;
|
|
117
|
+
queryPlace(rq: PlaceQueryRQ, payload?: IApiPayload<PlaceCommon[]>): Promise<[MapApiProvider, PlaceCommon[] | undefined]>;
|
|
118
118
|
/**
|
|
119
119
|
* Read member invitation
|
|
120
120
|
* @param id Id
|
package/lib/cjs/PublicApi.js
CHANGED
|
@@ -154,8 +154,35 @@ class PublicApi extends appscript_1.BaseApi {
|
|
|
154
154
|
* @param payload Payload
|
|
155
155
|
* @returns Result
|
|
156
156
|
*/
|
|
157
|
-
queryPlace(rq, payload) {
|
|
158
|
-
|
|
157
|
+
async queryPlace(rq, payload) {
|
|
158
|
+
// For simplified Chinese, or CN region, use China map
|
|
159
|
+
if (rq.provider === null &&
|
|
160
|
+
(rq.language === "zh-Hans" ||
|
|
161
|
+
rq.language === "zh-CN" ||
|
|
162
|
+
rq.region === "CN")) {
|
|
163
|
+
// Amap first
|
|
164
|
+
const amapRq = {
|
|
165
|
+
...rq,
|
|
166
|
+
region: undefined,
|
|
167
|
+
provider: appscript_1.MapApiProvider.Amap
|
|
168
|
+
};
|
|
169
|
+
const amapResult = await this.api.post("Public/QueryPlace", amapRq, payload);
|
|
170
|
+
if (amapResult && amapResult.length > 0)
|
|
171
|
+
return [appscript_1.MapApiProvider.Amap, amapResult];
|
|
172
|
+
// Baidu
|
|
173
|
+
const baiduRq = {
|
|
174
|
+
...rq,
|
|
175
|
+
region: undefined,
|
|
176
|
+
provider: appscript_1.MapApiProvider.Baidu
|
|
177
|
+
};
|
|
178
|
+
const baiduResult = await this.api.post("Public/QueryPlace", baiduRq, payload);
|
|
179
|
+
if (baiduResult && baiduResult.length > 0)
|
|
180
|
+
return [appscript_1.MapApiProvider.Baidu, baiduResult];
|
|
181
|
+
}
|
|
182
|
+
return [
|
|
183
|
+
rq.provider ?? appscript_1.MapApiProvider.Google,
|
|
184
|
+
await this.api.post("Public/QueryPlace", rq, payload)
|
|
185
|
+
];
|
|
159
186
|
}
|
|
160
187
|
/**
|
|
161
188
|
* Read member invitation
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { TiplistProps } from "@etsoo/materialui";
|
|
2
2
|
import { PlaceCommon } from "../../dto/public/PlaceCommon";
|
|
3
|
+
import { MapApiProvider } from "@etsoo/appscript";
|
|
3
4
|
/**
|
|
4
5
|
* Address tiplist component props
|
|
5
6
|
*/
|
|
6
|
-
export type AddressTiplistProps = Omit<TiplistProps<PlaceCommon, "placeId">, "idField" | "loadData" | "name" | "label"> & Partial<Pick<TiplistProps<PlaceCommon, "placeId">, "name" | "label">> & {
|
|
7
|
+
export type AddressTiplistProps = Omit<TiplistProps<PlaceCommon, "placeId">, "idField" | "loadData" | "name" | "label" | "onValueChange"> & Partial<Pick<TiplistProps<PlaceCommon, "placeId">, "name" | "label">> & {
|
|
8
|
+
/**
|
|
9
|
+
* Value change handler
|
|
10
|
+
* @param value New value
|
|
11
|
+
* @param provider Map API provider
|
|
12
|
+
*/
|
|
13
|
+
onValueChange?: (value: PlaceCommon | null, provider: MapApiProvider) => void;
|
|
14
|
+
};
|
|
7
15
|
/**
|
|
8
16
|
* Address tiplist component
|
|
9
17
|
* @param props Properties
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.AddressTiplist = AddressTiplist;
|
|
4
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
8
|
const materialui_1 = require("@etsoo/materialui");
|
|
6
9
|
const ICoreServiceApp_1 = require("../../ICoreServiceApp");
|
|
10
|
+
const react_1 = __importDefault(require("react"));
|
|
11
|
+
const appscript_1 = require("@etsoo/appscript");
|
|
7
12
|
/**
|
|
8
13
|
* Address tiplist component
|
|
9
14
|
* @param props Properties
|
|
@@ -13,12 +18,22 @@ function AddressTiplist(props) {
|
|
|
13
18
|
// App
|
|
14
19
|
const app = (0, ICoreServiceApp_1.useRequiredAppContext)();
|
|
15
20
|
// Destruct
|
|
16
|
-
const { fullWidth = true, getOptionLabel = (option) => `${option.name} - ${option.formattedAddress} (${option.postalCode})`, name = "address", label = app.get("address") ?? "Address", maxItems = 10, ...rest } = props;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const { fullWidth = true, getOptionLabel = (option) => `${option.name} - ${option.formattedAddress} (${option.postalCode})`, name = "address", label = app.get("address") ?? "Address", maxItems = 10, onValueChange, ...rest } = props;
|
|
22
|
+
// Provider
|
|
23
|
+
const providerRef = react_1.default.useRef(appscript_1.MapApiProvider.Google);
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)(materialui_1.Tiplist, { fullWidth: fullWidth, getOptionLabel: getOptionLabel, idField: "placeId", label: label, loadData: async (keyword, _, maxItems) => {
|
|
25
|
+
if (keyword && keyword.length > 2) {
|
|
26
|
+
const [provider, results] = await app.core.publicApi.queryPlace({
|
|
27
|
+
language: app.culture,
|
|
28
|
+
query: keyword,
|
|
29
|
+
pageSize: maxItems
|
|
30
|
+
}, { showLoading: false });
|
|
31
|
+
// Save provider
|
|
32
|
+
providerRef.current = provider;
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
}, name: name, onValueChange: (value) => onValueChange?.(value, providerRef.current), ...rest }));
|
|
24
39
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaceLocation } from "@etsoo/appscript";
|
|
1
|
+
import { MapApiProvider, PlaceLocation } from "@etsoo/appscript";
|
|
2
2
|
/**
|
|
3
3
|
* API output type
|
|
4
4
|
* API输出类型
|
|
@@ -7,14 +7,6 @@ export declare enum ApiOutput {
|
|
|
7
7
|
JSON = 0,
|
|
8
8
|
XML = 1
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* API provider
|
|
12
|
-
* 接口供应商
|
|
13
|
-
*/
|
|
14
|
-
export declare enum ApiProvider {
|
|
15
|
-
Google = 0,
|
|
16
|
-
Baidu = 1
|
|
17
|
-
}
|
|
18
10
|
/**
|
|
19
11
|
* Place query request
|
|
20
12
|
* 地点查询请求
|
|
@@ -34,7 +26,7 @@ export type PlaceQueryRQ = {
|
|
|
34
26
|
* API provider
|
|
35
27
|
* 接口供应商
|
|
36
28
|
*/
|
|
37
|
-
provider?:
|
|
29
|
+
provider?: MapApiProvider;
|
|
38
30
|
/**
|
|
39
31
|
* Language, like zh-CN
|
|
40
32
|
* 语言
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ApiOutput = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* API output type
|
|
6
6
|
* API输出类型
|
|
@@ -10,12 +10,3 @@ var ApiOutput;
|
|
|
10
10
|
ApiOutput[ApiOutput["JSON"] = 0] = "JSON";
|
|
11
11
|
ApiOutput[ApiOutput["XML"] = 1] = "XML";
|
|
12
12
|
})(ApiOutput || (exports.ApiOutput = ApiOutput = {}));
|
|
13
|
-
/**
|
|
14
|
-
* API provider
|
|
15
|
-
* 接口供应商
|
|
16
|
-
*/
|
|
17
|
-
var ApiProvider;
|
|
18
|
-
(function (ApiProvider) {
|
|
19
|
-
ApiProvider[ApiProvider["Google"] = 0] = "Google";
|
|
20
|
-
ApiProvider[ApiProvider["Baidu"] = 1] = "Baidu";
|
|
21
|
-
})(ApiProvider || (exports.ApiProvider = ApiProvider = {}));
|
package/lib/mjs/PublicApi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { CurrencyItem } from "./dto/public/CurrencyItem";
|
|
|
6
6
|
import { RegionData } from "./dto/public/RegionData";
|
|
7
7
|
import { PlaceQueryRQ } from "./rq/public/PlaceQueryRQ";
|
|
8
8
|
import { PlaceCommon } from "./dto/public/PlaceCommon";
|
|
9
|
-
import { BaseApi, CultureItem, Currency, CustomCulture, IApp, ProductUnit, ResultPayload } from "@etsoo/appscript";
|
|
9
|
+
import { BaseApi, CultureItem, Currency, CustomCulture, IApp, MapApiProvider, ProductUnit, ResultPayload } from "@etsoo/appscript";
|
|
10
10
|
import { MemberInvitationDto } from "./dto/public/MemberInvitationDto";
|
|
11
11
|
import { AcceptInvitationRQ } from "./rq/public/AcceptInvitationRQ";
|
|
12
12
|
import { ChinaPinData } from "./dto/public/ChinaPinData";
|
|
@@ -114,7 +114,7 @@ export declare class PublicApi extends BaseApi {
|
|
|
114
114
|
* @param payload Payload
|
|
115
115
|
* @returns Result
|
|
116
116
|
*/
|
|
117
|
-
queryPlace(rq: PlaceQueryRQ, payload?: IApiPayload<PlaceCommon[]>): Promise<PlaceCommon[] | undefined>;
|
|
117
|
+
queryPlace(rq: PlaceQueryRQ, payload?: IApiPayload<PlaceCommon[]>): Promise<[MapApiProvider, PlaceCommon[] | undefined]>;
|
|
118
118
|
/**
|
|
119
119
|
* Read member invitation
|
|
120
120
|
* @param id Id
|
package/lib/mjs/PublicApi.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataTypes } from "@etsoo/shared";
|
|
2
|
-
import { BaseApi, ProductUnit, RepeatOption } from "@etsoo/appscript";
|
|
2
|
+
import { BaseApi, MapApiProvider, ProductUnit, RepeatOption } from "@etsoo/appscript";
|
|
3
3
|
const unitPrefix = "unit";
|
|
4
4
|
/**
|
|
5
5
|
* Public API
|
|
@@ -151,8 +151,35 @@ export class PublicApi extends BaseApi {
|
|
|
151
151
|
* @param payload Payload
|
|
152
152
|
* @returns Result
|
|
153
153
|
*/
|
|
154
|
-
queryPlace(rq, payload) {
|
|
155
|
-
|
|
154
|
+
async queryPlace(rq, payload) {
|
|
155
|
+
// For simplified Chinese, or CN region, use China map
|
|
156
|
+
if (rq.provider === null &&
|
|
157
|
+
(rq.language === "zh-Hans" ||
|
|
158
|
+
rq.language === "zh-CN" ||
|
|
159
|
+
rq.region === "CN")) {
|
|
160
|
+
// Amap first
|
|
161
|
+
const amapRq = {
|
|
162
|
+
...rq,
|
|
163
|
+
region: undefined,
|
|
164
|
+
provider: MapApiProvider.Amap
|
|
165
|
+
};
|
|
166
|
+
const amapResult = await this.api.post("Public/QueryPlace", amapRq, payload);
|
|
167
|
+
if (amapResult && amapResult.length > 0)
|
|
168
|
+
return [MapApiProvider.Amap, amapResult];
|
|
169
|
+
// Baidu
|
|
170
|
+
const baiduRq = {
|
|
171
|
+
...rq,
|
|
172
|
+
region: undefined,
|
|
173
|
+
provider: MapApiProvider.Baidu
|
|
174
|
+
};
|
|
175
|
+
const baiduResult = await this.api.post("Public/QueryPlace", baiduRq, payload);
|
|
176
|
+
if (baiduResult && baiduResult.length > 0)
|
|
177
|
+
return [MapApiProvider.Baidu, baiduResult];
|
|
178
|
+
}
|
|
179
|
+
return [
|
|
180
|
+
rq.provider ?? MapApiProvider.Google,
|
|
181
|
+
await this.api.post("Public/QueryPlace", rq, payload)
|
|
182
|
+
];
|
|
156
183
|
}
|
|
157
184
|
/**
|
|
158
185
|
* Read member invitation
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { TiplistProps } from "@etsoo/materialui";
|
|
2
2
|
import { PlaceCommon } from "../../dto/public/PlaceCommon";
|
|
3
|
+
import { MapApiProvider } from "@etsoo/appscript";
|
|
3
4
|
/**
|
|
4
5
|
* Address tiplist component props
|
|
5
6
|
*/
|
|
6
|
-
export type AddressTiplistProps = Omit<TiplistProps<PlaceCommon, "placeId">, "idField" | "loadData" | "name" | "label"> & Partial<Pick<TiplistProps<PlaceCommon, "placeId">, "name" | "label">> & {
|
|
7
|
+
export type AddressTiplistProps = Omit<TiplistProps<PlaceCommon, "placeId">, "idField" | "loadData" | "name" | "label" | "onValueChange"> & Partial<Pick<TiplistProps<PlaceCommon, "placeId">, "name" | "label">> & {
|
|
8
|
+
/**
|
|
9
|
+
* Value change handler
|
|
10
|
+
* @param value New value
|
|
11
|
+
* @param provider Map API provider
|
|
12
|
+
*/
|
|
13
|
+
onValueChange?: (value: PlaceCommon | null, provider: MapApiProvider) => void;
|
|
14
|
+
};
|
|
7
15
|
/**
|
|
8
16
|
* Address tiplist component
|
|
9
17
|
* @param props Properties
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Tiplist } from "@etsoo/materialui";
|
|
3
3
|
import { useRequiredAppContext } from "../../ICoreServiceApp";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { MapApiProvider } from "@etsoo/appscript";
|
|
4
6
|
/**
|
|
5
7
|
* Address tiplist component
|
|
6
8
|
* @param props Properties
|
|
@@ -10,12 +12,22 @@ export function AddressTiplist(props) {
|
|
|
10
12
|
// App
|
|
11
13
|
const app = useRequiredAppContext();
|
|
12
14
|
// Destruct
|
|
13
|
-
const { fullWidth = true, getOptionLabel = (option) => `${option.name} - ${option.formattedAddress} (${option.postalCode})`, name = "address", label = app.get("address") ?? "Address", maxItems = 10, ...rest } = props;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const { fullWidth = true, getOptionLabel = (option) => `${option.name} - ${option.formattedAddress} (${option.postalCode})`, name = "address", label = app.get("address") ?? "Address", maxItems = 10, onValueChange, ...rest } = props;
|
|
16
|
+
// Provider
|
|
17
|
+
const providerRef = React.useRef(MapApiProvider.Google);
|
|
18
|
+
return (_jsx(Tiplist, { fullWidth: fullWidth, getOptionLabel: getOptionLabel, idField: "placeId", label: label, loadData: async (keyword, _, maxItems) => {
|
|
19
|
+
if (keyword && keyword.length > 2) {
|
|
20
|
+
const [provider, results] = await app.core.publicApi.queryPlace({
|
|
21
|
+
language: app.culture,
|
|
22
|
+
query: keyword,
|
|
23
|
+
pageSize: maxItems
|
|
24
|
+
}, { showLoading: false });
|
|
25
|
+
// Save provider
|
|
26
|
+
providerRef.current = provider;
|
|
27
|
+
return results;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
}, name: name, onValueChange: (value) => onValueChange?.(value, providerRef.current), ...rest }));
|
|
21
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaceLocation } from "@etsoo/appscript";
|
|
1
|
+
import { MapApiProvider, PlaceLocation } from "@etsoo/appscript";
|
|
2
2
|
/**
|
|
3
3
|
* API output type
|
|
4
4
|
* API输出类型
|
|
@@ -7,14 +7,6 @@ export declare enum ApiOutput {
|
|
|
7
7
|
JSON = 0,
|
|
8
8
|
XML = 1
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* API provider
|
|
12
|
-
* 接口供应商
|
|
13
|
-
*/
|
|
14
|
-
export declare enum ApiProvider {
|
|
15
|
-
Google = 0,
|
|
16
|
-
Baidu = 1
|
|
17
|
-
}
|
|
18
10
|
/**
|
|
19
11
|
* Place query request
|
|
20
12
|
* 地点查询请求
|
|
@@ -34,7 +26,7 @@ export type PlaceQueryRQ = {
|
|
|
34
26
|
* API provider
|
|
35
27
|
* 接口供应商
|
|
36
28
|
*/
|
|
37
|
-
provider?:
|
|
29
|
+
provider?: MapApiProvider;
|
|
38
30
|
/**
|
|
39
31
|
* Language, like zh-CN
|
|
40
32
|
* 语言
|
|
@@ -7,12 +7,3 @@ export var ApiOutput;
|
|
|
7
7
|
ApiOutput[ApiOutput["JSON"] = 0] = "JSON";
|
|
8
8
|
ApiOutput[ApiOutput["XML"] = 1] = "XML";
|
|
9
9
|
})(ApiOutput || (ApiOutput = {}));
|
|
10
|
-
/**
|
|
11
|
-
* API provider
|
|
12
|
-
* 接口供应商
|
|
13
|
-
*/
|
|
14
|
-
export var ApiProvider;
|
|
15
|
-
(function (ApiProvider) {
|
|
16
|
-
ApiProvider[ApiProvider["Google"] = 0] = "Google";
|
|
17
|
-
ApiProvider[ApiProvider["Baidu"] = 1] = "Baidu";
|
|
18
|
-
})(ApiProvider || (ApiProvider = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/smarterp-core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "TypeScript APIs for SmartERP Core",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"vitest": "^4.0.16"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@etsoo/appscript": "^1.6.
|
|
57
|
-
"@etsoo/materialui": "^1.5.
|
|
58
|
-
"@etsoo/react": "^1.8.
|
|
56
|
+
"@etsoo/appscript": "^1.6.50",
|
|
57
|
+
"@etsoo/materialui": "^1.5.93",
|
|
58
|
+
"@etsoo/react": "^1.8.66",
|
|
59
59
|
"@etsoo/shared": "^1.2.80",
|
|
60
60
|
"@etsoo/toolpad": "^1.0.42",
|
|
61
61
|
"@mui/material": "^7.3.6",
|
package/src/PublicApi.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
Currency,
|
|
13
13
|
CustomCulture,
|
|
14
14
|
IApp,
|
|
15
|
+
MapApiProvider,
|
|
15
16
|
ProductUnit,
|
|
16
17
|
RepeatOption,
|
|
17
18
|
ResultPayload
|
|
@@ -192,8 +193,54 @@ export class PublicApi extends BaseApi {
|
|
|
192
193
|
* @param payload Payload
|
|
193
194
|
* @returns Result
|
|
194
195
|
*/
|
|
195
|
-
queryPlace(
|
|
196
|
-
|
|
196
|
+
async queryPlace(
|
|
197
|
+
rq: PlaceQueryRQ,
|
|
198
|
+
payload?: IApiPayload<PlaceCommon[]>
|
|
199
|
+
): Promise<[MapApiProvider, PlaceCommon[] | undefined]> {
|
|
200
|
+
// For simplified Chinese, or CN region, use China map
|
|
201
|
+
if (
|
|
202
|
+
rq.provider === null &&
|
|
203
|
+
(rq.language === "zh-Hans" ||
|
|
204
|
+
rq.language === "zh-CN" ||
|
|
205
|
+
rq.region === "CN")
|
|
206
|
+
) {
|
|
207
|
+
// Amap first
|
|
208
|
+
const amapRq: PlaceQueryRQ = {
|
|
209
|
+
...rq,
|
|
210
|
+
region: undefined,
|
|
211
|
+
provider: MapApiProvider.Amap
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const amapResult = await this.api.post(
|
|
215
|
+
"Public/QueryPlace",
|
|
216
|
+
amapRq,
|
|
217
|
+
payload
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
if (amapResult && amapResult.length > 0)
|
|
221
|
+
return [MapApiProvider.Amap, amapResult];
|
|
222
|
+
|
|
223
|
+
// Baidu
|
|
224
|
+
const baiduRq: PlaceQueryRQ = {
|
|
225
|
+
...rq,
|
|
226
|
+
region: undefined,
|
|
227
|
+
provider: MapApiProvider.Baidu
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const baiduResult = await this.api.post(
|
|
231
|
+
"Public/QueryPlace",
|
|
232
|
+
baiduRq,
|
|
233
|
+
payload
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
if (baiduResult && baiduResult.length > 0)
|
|
237
|
+
return [MapApiProvider.Baidu, baiduResult];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return [
|
|
241
|
+
rq.provider ?? MapApiProvider.Google,
|
|
242
|
+
await this.api.post("Public/QueryPlace", rq, payload)
|
|
243
|
+
];
|
|
197
244
|
}
|
|
198
245
|
|
|
199
246
|
/**
|
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import { Tiplist, TiplistProps } from "@etsoo/materialui";
|
|
2
2
|
import { useRequiredAppContext } from "../../ICoreServiceApp";
|
|
3
3
|
import { PlaceCommon } from "../../dto/public/PlaceCommon";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { MapApiProvider } from "@etsoo/appscript";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Address tiplist component props
|
|
7
9
|
*/
|
|
8
10
|
export type AddressTiplistProps = Omit<
|
|
9
11
|
TiplistProps<PlaceCommon, "placeId">,
|
|
10
|
-
"idField" | "loadData" | "name" | "label"
|
|
12
|
+
"idField" | "loadData" | "name" | "label" | "onValueChange"
|
|
11
13
|
> &
|
|
12
|
-
Partial<Pick<TiplistProps<PlaceCommon, "placeId">, "name" | "label">> & {
|
|
14
|
+
Partial<Pick<TiplistProps<PlaceCommon, "placeId">, "name" | "label">> & {
|
|
15
|
+
/**
|
|
16
|
+
* Value change handler
|
|
17
|
+
* @param value New value
|
|
18
|
+
* @param provider Map API provider
|
|
19
|
+
*/
|
|
20
|
+
onValueChange?: (
|
|
21
|
+
value: PlaceCommon | null,
|
|
22
|
+
provider: MapApiProvider
|
|
23
|
+
) => void;
|
|
24
|
+
};
|
|
13
25
|
|
|
14
26
|
/**
|
|
15
27
|
* Address tiplist component
|
|
@@ -28,28 +40,40 @@ export function AddressTiplist(props: AddressTiplistProps) {
|
|
|
28
40
|
name = "address",
|
|
29
41
|
label = app.get("address") ?? "Address",
|
|
30
42
|
maxItems = 10,
|
|
43
|
+
onValueChange,
|
|
31
44
|
...rest
|
|
32
45
|
} = props;
|
|
33
46
|
|
|
47
|
+
// Provider
|
|
48
|
+
const providerRef = React.useRef<MapApiProvider>(MapApiProvider.Google);
|
|
49
|
+
|
|
34
50
|
return (
|
|
35
51
|
<Tiplist<PlaceCommon>
|
|
36
52
|
fullWidth={fullWidth}
|
|
37
53
|
getOptionLabel={getOptionLabel}
|
|
38
54
|
idField="placeId"
|
|
39
55
|
label={label}
|
|
40
|
-
loadData={(keyword, _, maxItems) =>
|
|
41
|
-
keyword
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
loadData={async (keyword, _, maxItems) => {
|
|
57
|
+
if (keyword && keyword.length > 2) {
|
|
58
|
+
const [provider, results] = await app.core.publicApi.queryPlace(
|
|
59
|
+
{
|
|
60
|
+
language: app.culture,
|
|
61
|
+
query: keyword,
|
|
62
|
+
pageSize: maxItems
|
|
63
|
+
},
|
|
64
|
+
{ showLoading: false }
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Save provider
|
|
68
|
+
providerRef.current = provider;
|
|
69
|
+
|
|
70
|
+
return results;
|
|
71
|
+
} else {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
}}
|
|
52
75
|
name={name}
|
|
76
|
+
onValueChange={(value) => onValueChange?.(value, providerRef.current)}
|
|
53
77
|
{...rest}
|
|
54
78
|
/>
|
|
55
79
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaceLocation } from "@etsoo/appscript";
|
|
1
|
+
import { MapApiProvider, PlaceLocation } from "@etsoo/appscript";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* API output type
|
|
@@ -9,15 +9,6 @@ export enum ApiOutput {
|
|
|
9
9
|
XML
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* API provider
|
|
14
|
-
* 接口供应商
|
|
15
|
-
*/
|
|
16
|
-
export enum ApiProvider {
|
|
17
|
-
Google,
|
|
18
|
-
Baidu
|
|
19
|
-
}
|
|
20
|
-
|
|
21
12
|
/**
|
|
22
13
|
* Place query request
|
|
23
14
|
* 地点查询请求
|
|
@@ -39,7 +30,7 @@ export type PlaceQueryRQ = {
|
|
|
39
30
|
* API provider
|
|
40
31
|
* 接口供应商
|
|
41
32
|
*/
|
|
42
|
-
provider?:
|
|
33
|
+
provider?: MapApiProvider;
|
|
43
34
|
|
|
44
35
|
/**
|
|
45
36
|
* Language, like zh-CN
|