@vant/area-data 1.3.2 → 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/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 = {
@@ -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
+ }