@vant/area-data 1.3.1 → 1.4.0

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 ADDED
@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) Youzan
4
+ Copyright (c) Chen Jiahan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Vant Area Data
1
+ # Vant China Area Data
2
2
 
3
- 中国省市区数据,适用于 Vant Area 组件。
3
+ 中国省市区数据,适用于 Vant Area 和 Cascader 等组件。
4
4
 
5
5
  ## 安装
6
6
 
@@ -17,10 +17,20 @@ pnpm add @vant/area-data
17
17
 
18
18
  ## 使用
19
19
 
20
+ 在 Vant 的 Area 组件中使用时,直接引用 `areaList` 对象即可:
21
+
20
22
  ```ts
21
23
  import { areaList } from '@vant/area-data';
22
24
  ```
23
25
 
26
+ 在 Vant 的 Cascader 组件中使用时,请使用 `useCascaderAreaData` 方法:
27
+
28
+ ```ts
29
+ import { useCascaderAreaData } from '@vant/area-data';
30
+
31
+ const cascaderAreaData = useCascaderAreaData();
32
+ ```
33
+
24
34
  ## 数据更新
25
35
 
26
- 中国的行政区划每年都会有变动,如果发现省市区数据未及时更新,欢迎提 Pull Request 帮助我们更新。
36
+ 中国的行政区划每年都会有变动,如果发现省市区数据未及时更新,欢迎提 Pull Request 帮助我们更新。你可以在[「国家统计局 - 全国区划代码」](http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/) 和[「民政部 - 行政区划代码」](https://www.mca.gov.cn/article/sj/xzqh/1980/)上查询到最新数据,请根据官方数据进行核实。
package/dist/index.cjs.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -19,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
20
  // src/index.ts
20
21
  var src_exports = {};
21
22
  __export(src_exports, {
22
- areaList: () => areaList
23
+ areaList: () => areaList,
24
+ useCascaderAreaData: () => useCascaderAreaData
23
25
  });
24
26
  module.exports = __toCommonJS(src_exports);
25
27
  var areaList = {
@@ -1174,10 +1176,10 @@ var areaList = {
1174
1176
  232701: "漠河市",
1175
1177
  232721: "呼玛县",
1176
1178
  232722: "塔河县",
1177
- 232790: "松岭区",
1178
- 232791: "呼中区",
1179
- 232792: "加格达奇区",
1180
- 232793: "新林区",
1179
+ 232761: "加格达奇区",
1180
+ 232762: "松岭区",
1181
+ 232763: "新林区",
1182
+ 232764: "呼中区",
1181
1183
  310101: "黄浦区",
1182
1184
  310104: "徐汇区",
1183
1185
  310105: "长宁区",
@@ -3910,3 +3912,35 @@ var areaList = {
3910
3912
  820204: "圣方济各堂区"
3911
3913
  }
3912
3914
  };
3915
+ var makeOption = (text, value, children) => ({
3916
+ text,
3917
+ value,
3918
+ children
3919
+ });
3920
+ function useCascaderAreaData() {
3921
+ const {
3922
+ city_list: city,
3923
+ county_list: county,
3924
+ province_list: province
3925
+ } = areaList;
3926
+ const provinceMap = /* @__PURE__ */ new Map();
3927
+ Object.keys(province).forEach((code) => {
3928
+ provinceMap.set(code.slice(0, 2), makeOption(province[code], code, []));
3929
+ });
3930
+ const cityMap = /* @__PURE__ */ new Map();
3931
+ Object.keys(city).forEach((code) => {
3932
+ const option = makeOption(city[code], code, []);
3933
+ cityMap.set(code.slice(0, 4), option);
3934
+ const province2 = provinceMap.get(code.slice(0, 2));
3935
+ if (province2) {
3936
+ province2.children.push(option);
3937
+ }
3938
+ });
3939
+ Object.keys(county).forEach((code) => {
3940
+ const city2 = cityMap.get(code.slice(0, 4));
3941
+ if (city2) {
3942
+ city2.children.push(makeOption(county[code], code));
3943
+ }
3944
+ });
3945
+ return Array.from(provinceMap.values());
3946
+ }