@vant/area-data 1.3.2 → 1.4.1

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/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
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- areaList: () => areaList
23
+ areaList: () => areaList,
24
+ useCascaderAreaData: () => useCascaderAreaData
24
25
  });
25
26
  module.exports = __toCommonJS(src_exports);
26
27
  var areaList = {
@@ -1646,7 +1647,6 @@ var areaList = {
1646
1647
  360724: "上犹县",
1647
1648
  360725: "崇义县",
1648
1649
  360726: "安远县",
1649
- 360727: "龙南县",
1650
1650
  360728: "定南县",
1651
1651
  360729: "全南县",
1652
1652
  360730: "宁都县",
@@ -1656,6 +1656,7 @@ var areaList = {
1656
1656
  360734: "寻乌县",
1657
1657
  360735: "石城县",
1658
1658
  360781: "瑞金市",
1659
+ 360783: "龙南市",
1659
1660
  360802: "吉州区",
1660
1661
  360803: "青原区",
1661
1662
  360821: "吉安县",
@@ -3911,3 +3912,35 @@ var areaList = {
3911
3912
  820204: "圣方济各堂区"
3912
3913
  }
3913
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
+ }