@etsoo/smarterp-core 1.1.4 → 1.1.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2004-2025 ETSOO ® (亿速思维 ®), https://etsoo.com, https://etsoo.nz
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
@@ -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 { ApiProvider } from "../src/rq/public/PlaceQueryRQ";
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: ApiProvider.Google
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");
@@ -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
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PublicApi = void 0;
4
4
  const shared_1 = require("@etsoo/shared");
5
- const PlaceQueryRQ_1 = require("./rq/public/PlaceQueryRQ");
6
5
  const appscript_1 = require("@etsoo/appscript");
7
6
  const unitPrefix = "unit";
8
7
  /**
@@ -157,7 +156,7 @@ class PublicApi extends appscript_1.BaseApi {
157
156
  */
158
157
  async queryPlace(rq, payload) {
159
158
  // For simplified Chinese, or CN region, use China map
160
- if (rq.provider === null &&
159
+ if (!rq.provider &&
161
160
  (rq.language === "zh-Hans" ||
162
161
  rq.language === "zh-CN" ||
163
162
  rq.region === "CN")) {
@@ -165,22 +164,25 @@ class PublicApi extends appscript_1.BaseApi {
165
164
  const amapRq = {
166
165
  ...rq,
167
166
  region: undefined,
168
- provider: PlaceQueryRQ_1.ApiProvider.Amap
167
+ provider: appscript_1.MapApiProvider.Amap
169
168
  };
170
169
  const amapResult = await this.api.post("Public/QueryPlace", amapRq, payload);
171
170
  if (amapResult && amapResult.length > 0)
172
- return amapResult;
171
+ return [appscript_1.MapApiProvider.Amap, amapResult];
173
172
  // Baidu
174
173
  const baiduRq = {
175
174
  ...rq,
176
175
  region: undefined,
177
- provider: PlaceQueryRQ_1.ApiProvider.Baidu
176
+ provider: appscript_1.MapApiProvider.Baidu
178
177
  };
179
178
  const baiduResult = await this.api.post("Public/QueryPlace", baiduRq, payload);
180
179
  if (baiduResult && baiduResult.length > 0)
181
- return baiduResult;
180
+ return [appscript_1.MapApiProvider.Baidu, baiduResult];
182
181
  }
183
- return await this.api.post("Public/QueryPlace", rq, payload);
182
+ return [
183
+ rq.provider ?? appscript_1.MapApiProvider.Google,
184
+ await this.api.post("Public/QueryPlace", rq, payload)
185
+ ];
184
186
  }
185
187
  /**
186
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
- return ((0, jsx_runtime_1.jsx)(materialui_1.Tiplist, { fullWidth: fullWidth, getOptionLabel: getOptionLabel, idField: "placeId", label: label, loadData: (keyword, _, maxItems) => keyword
18
- ? app.core.publicApi.queryPlace({
19
- language: app.culture,
20
- query: keyword,
21
- pageSize: maxItems
22
- }, { showLoading: false })
23
- : Promise.resolve([]), name: name, ...rest }));
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,27 +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
- /**
16
- * Google Maps
17
- * 谷歌地图
18
- */
19
- Google = 0,
20
- /**
21
- * Baidu Maps
22
- * 百度地图
23
- */
24
- Baidu = 1,
25
- /**
26
- * Amap
27
- * 高德地图
28
- */
29
- Amap = 2
30
- }
31
10
  /**
32
11
  * Place query request
33
12
  * 地点查询请求
@@ -47,7 +26,7 @@ export type PlaceQueryRQ = {
47
26
  * API provider
48
27
  * 接口供应商
49
28
  */
50
- provider?: ApiProvider;
29
+ provider?: MapApiProvider;
51
30
  /**
52
31
  * Language, like zh-CN
53
32
  * 语言
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiProvider = exports.ApiOutput = void 0;
3
+ exports.ApiOutput = void 0;
4
4
  /**
5
5
  * API output type
6
6
  * API输出类型
@@ -10,25 +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
- /**
20
- * Google Maps
21
- * 谷歌地图
22
- */
23
- ApiProvider[ApiProvider["Google"] = 0] = "Google";
24
- /**
25
- * Baidu Maps
26
- * 百度地图
27
- */
28
- ApiProvider[ApiProvider["Baidu"] = 1] = "Baidu";
29
- /**
30
- * Amap
31
- * 高德地图
32
- */
33
- ApiProvider[ApiProvider["Amap"] = 2] = "Amap";
34
- })(ApiProvider || (exports.ApiProvider = ApiProvider = {}));
@@ -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
@@ -1,6 +1,5 @@
1
1
  import { DataTypes } from "@etsoo/shared";
2
- import { ApiProvider } from "./rq/public/PlaceQueryRQ";
3
- import { BaseApi, ProductUnit, RepeatOption } from "@etsoo/appscript";
2
+ import { BaseApi, MapApiProvider, ProductUnit, RepeatOption } from "@etsoo/appscript";
4
3
  const unitPrefix = "unit";
5
4
  /**
6
5
  * Public API
@@ -154,7 +153,7 @@ export class PublicApi extends BaseApi {
154
153
  */
155
154
  async queryPlace(rq, payload) {
156
155
  // For simplified Chinese, or CN region, use China map
157
- if (rq.provider === null &&
156
+ if (!rq.provider &&
158
157
  (rq.language === "zh-Hans" ||
159
158
  rq.language === "zh-CN" ||
160
159
  rq.region === "CN")) {
@@ -162,22 +161,25 @@ export class PublicApi extends BaseApi {
162
161
  const amapRq = {
163
162
  ...rq,
164
163
  region: undefined,
165
- provider: ApiProvider.Amap
164
+ provider: MapApiProvider.Amap
166
165
  };
167
166
  const amapResult = await this.api.post("Public/QueryPlace", amapRq, payload);
168
167
  if (amapResult && amapResult.length > 0)
169
- return amapResult;
168
+ return [MapApiProvider.Amap, amapResult];
170
169
  // Baidu
171
170
  const baiduRq = {
172
171
  ...rq,
173
172
  region: undefined,
174
- provider: ApiProvider.Baidu
173
+ provider: MapApiProvider.Baidu
175
174
  };
176
175
  const baiduResult = await this.api.post("Public/QueryPlace", baiduRq, payload);
177
176
  if (baiduResult && baiduResult.length > 0)
178
- return baiduResult;
177
+ return [MapApiProvider.Baidu, baiduResult];
179
178
  }
180
- return await this.api.post("Public/QueryPlace", rq, payload);
179
+ return [
180
+ rq.provider ?? MapApiProvider.Google,
181
+ await this.api.post("Public/QueryPlace", rq, payload)
182
+ ];
181
183
  }
182
184
  /**
183
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
- return (_jsx(Tiplist, { fullWidth: fullWidth, getOptionLabel: getOptionLabel, idField: "placeId", label: label, loadData: (keyword, _, maxItems) => keyword
15
- ? app.core.publicApi.queryPlace({
16
- language: app.culture,
17
- query: keyword,
18
- pageSize: maxItems
19
- }, { showLoading: false })
20
- : Promise.resolve([]), name: name, ...rest }));
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,27 +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
- /**
16
- * Google Maps
17
- * 谷歌地图
18
- */
19
- Google = 0,
20
- /**
21
- * Baidu Maps
22
- * 百度地图
23
- */
24
- Baidu = 1,
25
- /**
26
- * Amap
27
- * 高德地图
28
- */
29
- Amap = 2
30
- }
31
10
  /**
32
11
  * Place query request
33
12
  * 地点查询请求
@@ -47,7 +26,7 @@ export type PlaceQueryRQ = {
47
26
  * API provider
48
27
  * 接口供应商
49
28
  */
50
- provider?: ApiProvider;
29
+ provider?: MapApiProvider;
51
30
  /**
52
31
  * Language, like zh-CN
53
32
  * 语言
@@ -7,25 +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
- /**
17
- * Google Maps
18
- * 谷歌地图
19
- */
20
- ApiProvider[ApiProvider["Google"] = 0] = "Google";
21
- /**
22
- * Baidu Maps
23
- * 百度地图
24
- */
25
- ApiProvider[ApiProvider["Baidu"] = 1] = "Baidu";
26
- /**
27
- * Amap
28
- * 高德地图
29
- */
30
- ApiProvider[ApiProvider["Amap"] = 2] = "Amap";
31
- })(ApiProvider || (ApiProvider = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/smarterp-core",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "TypeScript APIs for SmartERP Core",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -48,16 +48,16 @@
48
48
  "@types/react": "^19.2.7",
49
49
  "@types/react-dom": "^19.2.3",
50
50
  "@vitejs/plugin-react": "^5.1.2",
51
- "jsdom": "^27.3.0",
51
+ "jsdom": "^27.4.0",
52
52
  "typescript": "^5.9.3",
53
53
  "vitest": "^4.0.16"
54
54
  },
55
55
  "dependencies": {
56
- "@etsoo/appscript": "^1.6.49",
57
- "@etsoo/materialui": "^1.5.92",
58
- "@etsoo/react": "^1.8.65",
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
- "@etsoo/toolpad": "^1.0.42",
60
+ "@etsoo/toolpad": "^1.0.44",
61
61
  "@mui/material": "^7.3.6",
62
62
  "ajv": "^8.17.1",
63
63
  "ajv-formats": "^3.0.1",
package/src/PublicApi.ts CHANGED
@@ -4,7 +4,7 @@ import { PinyinRQ } from "./rq/public/PinyinRQ";
4
4
  import { CreateBarcodeRQ } from "./rq/public/CreateBarcodeRQ";
5
5
  import { CurrencyItem } from "./dto/public/CurrencyItem";
6
6
  import { RegionData } from "./dto/public/RegionData";
7
- import { ApiProvider, PlaceQueryRQ } from "./rq/public/PlaceQueryRQ";
7
+ import { PlaceQueryRQ } from "./rq/public/PlaceQueryRQ";
8
8
  import { PlaceCommon } from "./dto/public/PlaceCommon";
9
9
  import {
10
10
  BaseApi,
@@ -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,10 +193,13 @@ export class PublicApi extends BaseApi {
192
193
  * @param payload Payload
193
194
  * @returns Result
194
195
  */
195
- async queryPlace(rq: PlaceQueryRQ, payload?: IApiPayload<PlaceCommon[]>) {
196
+ async queryPlace(
197
+ rq: PlaceQueryRQ,
198
+ payload?: IApiPayload<PlaceCommon[]>
199
+ ): Promise<[MapApiProvider, PlaceCommon[] | undefined]> {
196
200
  // For simplified Chinese, or CN region, use China map
197
201
  if (
198
- rq.provider === null &&
202
+ !rq.provider &&
199
203
  (rq.language === "zh-Hans" ||
200
204
  rq.language === "zh-CN" ||
201
205
  rq.region === "CN")
@@ -204,7 +208,7 @@ export class PublicApi extends BaseApi {
204
208
  const amapRq: PlaceQueryRQ = {
205
209
  ...rq,
206
210
  region: undefined,
207
- provider: ApiProvider.Amap
211
+ provider: MapApiProvider.Amap
208
212
  };
209
213
 
210
214
  const amapResult = await this.api.post(
@@ -213,13 +217,14 @@ export class PublicApi extends BaseApi {
213
217
  payload
214
218
  );
215
219
 
216
- if (amapResult && amapResult.length > 0) return amapResult;
220
+ if (amapResult && amapResult.length > 0)
221
+ return [MapApiProvider.Amap, amapResult];
217
222
 
218
223
  // Baidu
219
224
  const baiduRq: PlaceQueryRQ = {
220
225
  ...rq,
221
226
  region: undefined,
222
- provider: ApiProvider.Baidu
227
+ provider: MapApiProvider.Baidu
223
228
  };
224
229
 
225
230
  const baiduResult = await this.api.post(
@@ -228,10 +233,14 @@ export class PublicApi extends BaseApi {
228
233
  payload
229
234
  );
230
235
 
231
- if (baiduResult && baiduResult.length > 0) return baiduResult;
236
+ if (baiduResult && baiduResult.length > 0)
237
+ return [MapApiProvider.Baidu, baiduResult];
232
238
  }
233
239
 
234
- return await this.api.post("Public/QueryPlace", rq, payload);
240
+ return [
241
+ rq.provider ?? MapApiProvider.Google,
242
+ await this.api.post("Public/QueryPlace", rq, payload)
243
+ ];
235
244
  }
236
245
 
237
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
- ? app.core.publicApi.queryPlace(
43
- {
44
- language: app.culture,
45
- query: keyword,
46
- pageSize: maxItems
47
- },
48
- { showLoading: false }
49
- )
50
- : Promise.resolve([])
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,30 +9,6 @@ export enum ApiOutput {
9
9
  XML
10
10
  }
11
11
 
12
- /**
13
- * API provider
14
- * 接口供应商
15
- */
16
- export enum ApiProvider {
17
- /**
18
- * Google Maps
19
- * 谷歌地图
20
- */
21
- Google,
22
-
23
- /**
24
- * Baidu Maps
25
- * 百度地图
26
- */
27
- Baidu,
28
-
29
- /**
30
- * Amap
31
- * 高德地图
32
- */
33
- Amap
34
- }
35
-
36
12
  /**
37
13
  * Place query request
38
14
  * 地点查询请求
@@ -54,7 +30,7 @@ export type PlaceQueryRQ = {
54
30
  * API provider
55
31
  * 接口供应商
56
32
  */
57
- provider?: ApiProvider;
33
+ provider?: MapApiProvider;
58
34
 
59
35
  /**
60
36
  * Language, like zh-CN