@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.
@@ -29983,15 +29983,31 @@ function findParsedRegionConflict(parse, originalAddress) {
29983
29983
  return '';
29984
29984
  }
29985
29985
 
29986
+ /**
29987
+ * 本地识别的省市区全部为空,但输入文本中出现省/市/区/县等行政区划文字时,
29988
+ * 说明本地识别遗漏了行政区划(如姓名前缀把省份顶出匹配窗口),
29989
+ * 也需要调用大模型接口重新识别
29990
+ */
29991
+ function shouldFallbackToAIWhenEmpty(parse, originalAddress) {
29992
+ if (parse.province || parse.city || parse.area) {
29993
+ return false;
29994
+ }
29995
+ var compareText = normalizeAddressForCompare(originalAddress);
29996
+ return /[省市区县]/.test(compareText);
29997
+ }
29998
+
29986
29999
  /**
29987
30000
  * 本地识别错误时,使用原生 fetch 调用大模型接口重新识别
29988
- * GET /v2/project/column/addressBychat?contents={待识别文本}
30001
+ * options.platform == 'plugin'(插件端):POST /project/column/addressBychat,请求体 {content: 待识别文本}
30002
+ * 其他端:GET /v2/project/column/addressBychat?contents={待识别文本}
29989
30003
  * 接口返回 data.content 为大模型识别结果的 JSON 字符串(name/mobile/tel/province/city/area/street/addr)
29990
30004
  * @param {string} address 原始地址字符串
30005
+ * @param {object} [options] 可选配置,platform === 'plugin' 表示插件端
29991
30006
  * @returns {Promise<{aiResult?: object, failMsg?: string}|null>}
29992
30007
  * 成功返回 {aiResult}(content 解析后的对象);失败返回 {failMsg}(接口 msg);不支持 fetch 返回 null
29993
30008
  */
29994
30009
  function parseAddressByChat(address) {
30010
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
29995
30011
  // 小程序等不支持 fetch 的环境直接跳过,保留本地识别结果
29996
30012
  if (typeof fetch !== 'function') {
29997
30013
  console.warn('当前环境不支持 fetch,无法调用大模型地址识别接口');
@@ -30005,10 +30021,21 @@ function parseAddressByChat(address) {
30005
30021
  var isLocal = hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '0.0.0.0' || hostname === '[::1]';
30006
30022
  baseUrl = isLocal ? '/proxyWay' : '';
30007
30023
  }
30008
- var url = baseUrl + '/v2/project/column/addressBychat?contents=' + encodeURIComponent(address);
30009
- return fetch(url, {
30024
+ // 插件端走单独接口:POST /project/column/addressBychat;其他端走 v2 的 GET 接口
30025
+ var isPlugin = options.platform === 'plugin';
30026
+ var url = baseUrl + (isPlugin ? '/project/column/addressBychat' : '/v2/project/column/addressBychat?contents=' + encodeURIComponent(address));
30027
+ var fetchOptions = isPlugin ? {
30028
+ method: 'POST',
30029
+ headers: {
30030
+ 'Content-Type': 'application/json'
30031
+ },
30032
+ body: JSON.stringify({
30033
+ content: address
30034
+ })
30035
+ } : {
30010
30036
  method: 'GET'
30011
- }).then(function (r) {
30037
+ };
30038
+ return fetch(url, fetchOptions).then(function (r) {
30012
30039
  return r.json();
30013
30040
  }).then(function (res) {
30014
30041
  if (res && !res.code && res.data && res.data.content) {
@@ -30068,14 +30095,15 @@ function _addressParse() {
30068
30095
  parseArea(list);
30069
30096
  }
30070
30097
  cleanAddress = preprocessAddress(address);
30071
- parse = parseAddressDetail(cleanAddress, sourceData || {}, address); // 识别完毕后校验:输入文本中有明确的省市区文字,但识别结果与之不一致时,调用大模型接口重新识别
30098
+ parse = parseAddressDetail(cleanAddress, sourceData || {}, address); // 识别完毕后校验:输入文本中有明确的省市区文字,但识别结果与之不一致时,调用大模型接口重新识别;
30099
+ // 省市区识别全为空但输入中出现省市区等行政区划文字时,同样调用大模型接口重新识别
30072
30100
  conflictLevel = findParsedRegionConflict(parse, address);
30073
- if (!conflictLevel) {
30101
+ if (!(conflictLevel || shouldFallbackToAIWhenEmpty(parse, address))) {
30074
30102
  _context.n = 2;
30075
30103
  break;
30076
30104
  }
30077
30105
  _context.n = 1;
30078
- return parseAddressByChat(address);
30106
+ return parseAddressByChat(address, options);
30079
30107
  case 1:
30080
30108
  chatResult = _context.v;
30081
30109
  if (chatResult && chatResult.aiResult) {