@bytenew/bn-applet-ui 1.1.75 → 1.1.77
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/dist/bn-applet-ui.umd.js
CHANGED
|
@@ -30001,15 +30001,31 @@ function findParsedRegionConflict(parse, originalAddress) {
|
|
|
30001
30001
|
return '';
|
|
30002
30002
|
}
|
|
30003
30003
|
|
|
30004
|
+
/**
|
|
30005
|
+
* 本地识别的省市区全部为空,但输入文本中出现省/市/区/县等行政区划文字时,
|
|
30006
|
+
* 说明本地识别遗漏了行政区划(如姓名前缀把省份顶出匹配窗口),
|
|
30007
|
+
* 也需要调用大模型接口重新识别
|
|
30008
|
+
*/
|
|
30009
|
+
function shouldFallbackToAIWhenEmpty(parse, originalAddress) {
|
|
30010
|
+
if (parse.province || parse.city || parse.area) {
|
|
30011
|
+
return false;
|
|
30012
|
+
}
|
|
30013
|
+
var compareText = normalizeAddressForCompare(originalAddress);
|
|
30014
|
+
return /[省市区县]/.test(compareText);
|
|
30015
|
+
}
|
|
30016
|
+
|
|
30004
30017
|
/**
|
|
30005
30018
|
* 本地识别错误时,使用原生 fetch 调用大模型接口重新识别
|
|
30006
|
-
*
|
|
30019
|
+
* options.platform == 'plugin'(插件端):POST /project/column/addressBychat,请求体 {content: 待识别文本}
|
|
30020
|
+
* 其他端:GET /v2/project/column/addressBychat?contents={待识别文本}
|
|
30007
30021
|
* 接口返回 data.content 为大模型识别结果的 JSON 字符串(name/mobile/tel/province/city/area/street/addr)
|
|
30008
30022
|
* @param {string} address 原始地址字符串
|
|
30023
|
+
* @param {object} [options] 可选配置,platform === 'plugin' 表示插件端
|
|
30009
30024
|
* @returns {Promise<{aiResult?: object, failMsg?: string}|null>}
|
|
30010
30025
|
* 成功返回 {aiResult}(content 解析后的对象);失败返回 {failMsg}(接口 msg);不支持 fetch 返回 null
|
|
30011
30026
|
*/
|
|
30012
30027
|
function parseAddressByChat(address) {
|
|
30028
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30013
30029
|
// 小程序等不支持 fetch 的环境直接跳过,保留本地识别结果
|
|
30014
30030
|
if (typeof fetch !== 'function') {
|
|
30015
30031
|
console.warn('当前环境不支持 fetch,无法调用大模型地址识别接口');
|
|
@@ -30023,10 +30039,21 @@ function parseAddressByChat(address) {
|
|
|
30023
30039
|
var isLocal = hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '0.0.0.0' || hostname === '[::1]';
|
|
30024
30040
|
baseUrl = isLocal ? '/proxyWay' : '';
|
|
30025
30041
|
}
|
|
30026
|
-
|
|
30027
|
-
|
|
30042
|
+
// 插件端走单独接口:POST /project/column/addressBychat;其他端走 v2 的 GET 接口
|
|
30043
|
+
var isPlugin = options.platform === 'plugin';
|
|
30044
|
+
var url = baseUrl + (isPlugin ? '/project/column/addressBychat' : '/v2/project/column/addressBychat?contents=' + encodeURIComponent(address));
|
|
30045
|
+
var fetchOptions = isPlugin ? {
|
|
30046
|
+
method: 'POST',
|
|
30047
|
+
headers: {
|
|
30048
|
+
'Content-Type': 'application/json'
|
|
30049
|
+
},
|
|
30050
|
+
body: JSON.stringify({
|
|
30051
|
+
content: address
|
|
30052
|
+
})
|
|
30053
|
+
} : {
|
|
30028
30054
|
method: 'GET'
|
|
30029
|
-
}
|
|
30055
|
+
};
|
|
30056
|
+
return fetch(url, fetchOptions).then(function (r) {
|
|
30030
30057
|
return r.json();
|
|
30031
30058
|
}).then(function (res) {
|
|
30032
30059
|
if (res && !res.code && res.data && res.data.content) {
|
|
@@ -30086,14 +30113,15 @@ function _addressParse() {
|
|
|
30086
30113
|
parseArea(list);
|
|
30087
30114
|
}
|
|
30088
30115
|
cleanAddress = preprocessAddress(address);
|
|
30089
|
-
parse = parseAddressDetail(cleanAddress, sourceData || {}, address); //
|
|
30116
|
+
parse = parseAddressDetail(cleanAddress, sourceData || {}, address); // 识别完毕后校验:输入文本中有明确的省市区文字,但识别结果与之不一致时,调用大模型接口重新识别;
|
|
30117
|
+
// 省市区识别全为空但输入中出现省市区等行政区划文字时,同样调用大模型接口重新识别
|
|
30090
30118
|
conflictLevel = findParsedRegionConflict(parse, address);
|
|
30091
|
-
if (!conflictLevel) {
|
|
30119
|
+
if (!(conflictLevel || shouldFallbackToAIWhenEmpty(parse, address))) {
|
|
30092
30120
|
_context.n = 2;
|
|
30093
30121
|
break;
|
|
30094
30122
|
}
|
|
30095
30123
|
_context.n = 1;
|
|
30096
|
-
return parseAddressByChat(address);
|
|
30124
|
+
return parseAddressByChat(address, options);
|
|
30097
30125
|
case 1:
|
|
30098
30126
|
chatResult = _context.v;
|
|
30099
30127
|
if (chatResult && chatResult.aiResult) {
|