@bytenew/bn-applet-ui 1.1.40 → 1.1.41

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.
@@ -21651,7 +21651,7 @@ var CITY_SUFFIX_KEYS = ['布依族苗族自治州', '苗族侗族自治州', '
21651
21651
  var INVALID_AREA_NAMES = ['其他', '其它区', '其他区'];
21652
21652
 
21653
21653
  /**
21654
- * 去掉地址片段开头的市/州等后缀
21654
+ * 去掉地址片段开头的市/州等后缀(仅用于城市简称匹配后的剩余文本)
21655
21655
  */
21656
21656
  function stripLeadingCitySuffix(text) {
21657
21657
  var result = text;
@@ -21665,6 +21665,19 @@ function stripLeadingCitySuffix(text) {
21665
21665
  return result;
21666
21666
  }
21667
21667
 
21668
+ /**
21669
+ * 城市简称匹配后去掉后缀;「市中区」「市南区」等区名开头的「市」不能误删
21670
+ */
21671
+ function stripLeadingCitySuffixAfterShortMatch(text) {
21672
+ if (!text || text.indexOf('市') !== 0) {
21673
+ return text;
21674
+ }
21675
+ if (/^市[中南东西]/.test(text)) {
21676
+ return text;
21677
+ }
21678
+ return stripLeadingCitySuffix(text);
21679
+ }
21680
+
21668
21681
  /**
21669
21682
  * 同名区对应多个城市时,根据地址中是否出现城市名进行消歧
21670
21683
  */
@@ -21708,41 +21721,59 @@ function pickCityByContext(address, areaName, areaData) {
21708
21721
 
21709
21722
  /**
21710
21723
  * 在文本中匹配城市,返回最早出现的城市
21724
+ * 优先匹配完整城市名(如「乐山市」),避免误删「市中区」等区名前缀
21711
21725
  */
21712
21726
  function matchCityInText(text, cities) {
21713
- var matchedCity = null;
21714
- var matchIdx = -1;
21715
- var matchedLength = 0;
21727
+ var best = null;
21716
21728
  for (var i = 0; i < cities.length; i++) {
21717
21729
  var city = cities[i];
21718
21730
  var cityName = city.name;
21719
21731
  var idx = text.indexOf(cityName);
21720
21732
  if (idx > -1 && idx < 15) {
21721
- if (matchIdx === -1 || idx < matchIdx || idx === matchIdx && cityName.length > matchedLength) {
21722
- matchedCity = city;
21723
- matchIdx = idx;
21724
- matchedLength = cityName.length;
21725
- }
21726
- }
21727
- var cityShort = cityName.replace('市', '').replace('地区', '');
21728
- if (cityShort !== cityName && cityShort.length >= 2) {
21729
- var shortIdx = text.indexOf(cityShort);
21730
- if (shortIdx > -1 && shortIdx < 15) {
21731
- if (matchIdx === -1 || shortIdx < matchIdx || shortIdx === matchIdx && cityShort.length > matchedLength) {
21732
- matchedCity = city;
21733
- matchIdx = shortIdx;
21734
- matchedLength = cityShort.length;
21735
- }
21733
+ if (!best || idx < best.idx || idx === best.idx && cityName.length > best.token.length) {
21734
+ best = {
21735
+ city: city,
21736
+ idx: idx,
21737
+ token: cityName,
21738
+ type: 'full'
21739
+ };
21736
21740
  }
21737
21741
  }
21738
21742
  }
21739
- if (!matchedCity) {
21743
+ if (best && best.type === 'full') {
21744
+ return {
21745
+ city: best.city,
21746
+ afterCity: text.substring(best.idx + best.token.length)
21747
+ };
21748
+ }
21749
+ for (var _i = 0; _i < cities.length; _i++) {
21750
+ var _city = cities[_i];
21751
+ var _cityName = _city.name;
21752
+ var cityShort = _cityName.replace('市', '').replace('地区', '');
21753
+ if (cityShort === _cityName || cityShort.length < 2) {
21754
+ continue;
21755
+ }
21756
+ var _idx = text.indexOf(cityShort);
21757
+ if (_idx > -1 && _idx < 15) {
21758
+ if (!best || _idx < best.idx || _idx === best.idx && cityShort.length > best.token.length) {
21759
+ best = {
21760
+ city: _city,
21761
+ idx: _idx,
21762
+ token: cityShort,
21763
+ type: 'short'
21764
+ };
21765
+ }
21766
+ }
21767
+ }
21768
+ if (!best) {
21740
21769
  return null;
21741
21770
  }
21742
- var afterCity = text.substring(matchIdx + matchedLength);
21743
- afterCity = stripLeadingCitySuffix(afterCity);
21771
+ var afterCity = text.substring(best.idx + best.token.length);
21772
+ if (best.type === 'short') {
21773
+ afterCity = stripLeadingCitySuffixAfterShortMatch(afterCity);
21774
+ }
21744
21775
  return {
21745
- city: matchedCity,
21776
+ city: best.city,
21746
21777
  afterCity: afterCity
21747
21778
  };
21748
21779
  }
@@ -22018,7 +22049,7 @@ function detail_parse_forward(address, sourceData) {
22018
22049
 
22019
22050
  // 先尝试快速匹配
22020
22051
  var _loop = function _loop() {
22021
- var pattern = _provPatterns[_i];
22052
+ var pattern = _provPatterns[_i2];
22022
22053
  if (remaining.startsWith(pattern.pattern)) {
22023
22054
  // 在 defaultData 中找到对应的省份数据
22024
22055
  var found = defaultData.find(function (p) {
@@ -22036,7 +22067,7 @@ function detail_parse_forward(address, sourceData) {
22036
22067
  }
22037
22068
  }
22038
22069
  };
22039
- for (var _i = 0, _provPatterns = provPatterns; _i < _provPatterns.length; _i++) {
22070
+ for (var _i2 = 0, _provPatterns = provPatterns; _i2 < _provPatterns.length; _i2++) {
22040
22071
  if (_loop()) break;
22041
22072
  }
22042
22073
 
@@ -22113,19 +22144,19 @@ function detail_parse_forward(address, sourceData) {
22113
22144
 
22114
22145
  // 收集所有 area,同名区优先选择地址中出现对应城市名的
22115
22146
  var allAreas = [];
22116
- for (var _i2 = 0; _i2 < matchedProvince.city.length; _i2++) {
22117
- var city = matchedProvince.city[_i2];
22147
+ for (var _i3 = 0; _i3 < matchedProvince.city.length; _i3++) {
22148
+ var city = matchedProvince.city[_i3];
22118
22149
  if (city.area && city.area.length > 0) {
22119
22150
  for (var j = 0; j < city.area.length; j++) {
22120
22151
  var areaName = city.area[j];
22121
22152
  if (areaName && INVALID_AREA_NAMES.indexOf(areaName) === -1 && areaName.length >= 2) {
22122
- var _idx = remaining.indexOf(areaName);
22123
- if (_idx > -1 && _idx < 15) {
22153
+ var _idx2 = remaining.indexOf(areaName);
22154
+ if (_idx2 > -1 && _idx2 < 15) {
22124
22155
  allAreas.push({
22125
22156
  areaName: areaName,
22126
22157
  cityName: city.name,
22127
22158
  cityData: city,
22128
- index: _idx
22159
+ index: _idx2
22129
22160
  });
22130
22161
  }
22131
22162
  }
@@ -22170,8 +22201,8 @@ function detail_parse_forward(address, sourceData) {
22170
22201
  }).sort(function (a, b) {
22171
22202
  return b.length - a.length;
22172
22203
  });
22173
- for (var _i3 = 0; _i3 < sortedStreets.length; _i3++) {
22174
- var streetName = sortedStreets[_i3];
22204
+ for (var _i4 = 0; _i4 < sortedStreets.length; _i4++) {
22205
+ var streetName = sortedStreets[_i4];
22175
22206
  var streetIdx = _afterArea.indexOf(streetName);
22176
22207
  if (streetIdx > -1 && streetIdx < 8) {
22177
22208
  parse.street = streetName;