Compare commits

...

4 Commits

Author SHA1 Message Date
chenjiahan
25155c4465 release: @vant/area-data 1.4.0 2023-01-25 22:40:18 +08:00
neverland
c3d9cbfb1e
feat(Cascader): add useCascaderAreaData method (#11518) 2023-01-25 22:39:27 +08:00
neverland
816acf7886
feat(Locale): add useCurrentLang method (#11517) 2023-01-25 21:01:02 +08:00
neverland
769f16169e
feat(cli): increase document site padding (#11516) 2023-01-25 20:56:10 +08:00
8 changed files with 118 additions and 11 deletions

View File

@ -1,6 +1,6 @@
# Vant Area Data
# Vant China Area Data
中国省市区数据,适用于 Vant Area 组件。
中国省市区数据,适用于 Vant Area 和 Cascader 等组件。
## 安装
@ -17,10 +17,20 @@ pnpm add @vant/area-data
## 使用
在 Vant 的 Area 组件中使用时,直接引用 `areaList` 对象即可:
```ts
import { areaList } from '@vant/area-data';
```
在 Vant 的 Cascader 组件中使用时,请使用 `useCascaderAreaData` 方法:
```ts
import { useCascaderAreaData } from '@vant/area-data';
const cascaderAreaData = useCascaderAreaData();
```
## 数据更新
中国的行政区划每年都会有变动,如果发现省市区数据未及时更新,欢迎提 Pull Request 帮助我们更新。
中国的行政区划每年都会有变动,如果发现省市区数据未及时更新,欢迎提 Pull Request 帮助我们更新。你可以在[「国家统计局 - 全国区划代码」](http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/) 和[「民政部 - 行政区划代码」](https://www.mca.gov.cn/article/sj/xzqh/1980/)上查询到最新数据,请根据官方数据进行核实。

View File

@ -1,6 +1,6 @@
{
"name": "@vant/area-data",
"version": "1.3.2",
"version": "1.4.0",
"description": "Vant 省市区数据",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.mjs",
@ -11,6 +11,7 @@
"require": "./dist/index.cjs.js"
}
},
"sideEffects": false,
"files": [
"dist"
],

View File

@ -1,4 +1,8 @@
export const areaList = {
export const areaList: {
province_list: Record<string, string>;
city_list: Record<string, string>;
county_list: Record<string, string>;
} = {
province_list: {
110000: '北京市',
120000: '天津市',
@ -3886,3 +3890,53 @@ export const areaList = {
820204: '圣方济各堂区',
},
};
type CascaderOption = {
text: string;
value: string;
children?: CascaderOption[];
};
const makeOption = (
text: string,
value: string,
children?: CascaderOption[]
): CascaderOption => ({
text,
value,
children,
});
export function useCascaderAreaData() {
const {
city_list: city,
county_list: county,
province_list: province,
} = areaList;
const provinceMap = new Map<string, CascaderOption>();
Object.keys(province).forEach((code) => {
provinceMap.set(code.slice(0, 2), makeOption(province[code], code, []));
});
const cityMap = new Map<string, CascaderOption>();
Object.keys(city).forEach((code) => {
const option = makeOption(city[code], code, []);
cityMap.set(code.slice(0, 4), option);
const province = provinceMap.get(code.slice(0, 2));
if (province) {
province.children!.push(option);
}
});
Object.keys(county).forEach((code) => {
const city = cityMap.get(code.slice(0, 4));
if (city) {
city.children!.push(makeOption(county[code], code));
}
});
return Array.from(provinceMap.values());
}

View File

@ -14,7 +14,7 @@
--van-doc-green: #07c160;
// sizes
--van-doc-padding: 24px;
--van-doc-padding: 32px;
--van-doc-row-max-width: 1680px;
--van-doc-nav-width: 220px;
--van-doc-border-radius: 20px;

View File

@ -83,8 +83,8 @@ export default {
<style lang="less">
.van-doc-card {
margin-bottom: 24px;
padding: 24px;
margin-bottom: var(--van-doc-padding);
padding: 28px 28px 32px;
background-color: var(--van-doc-background-2);
border-radius: var(--van-doc-border-radius);
overflow: auto;
@ -253,7 +253,7 @@ export default {
}
> ul {
margin: 12px 0;
margin: 16px 0;
}
> ul li,
@ -324,7 +324,7 @@ export default {
padding: 0 0 75px;
.van-doc-markdown-body {
padding: 24px;
padding: var(--van-doc-padding);
overflow: hidden;
h1,
@ -344,7 +344,7 @@ export default {
}
h2 {
margin: 45px 0 20px;
margin: 52px 0 20px;
font-size: 26px;
}
}

View File

@ -79,3 +79,23 @@ Current supported languages:
### Add new language
If you cant find the language you need, please send us a Pull Request to add the new language pack, you can refer to [Add German language pack](https://github.com/vant-ui/vant/pull/7245) PR.
### Get Current Lang
You can get the current language using `useCurrentLang` method.
- **Type:**
```ts
function useCurrentLang(): Ref<string>;
```
- **Example:**
```ts
import { useCurrentLang } from 'vant';
const currentLang = useCurrentLang();
console.log(currentLang.value); // --> 'en-US'
```

View File

@ -77,6 +77,26 @@ Locale.add(messages);
> 在 [这里](https://github.com/vant-ui/vant/tree/main/packages/vant/src/locale/lang) 查看所有的语言包源文件。
### 获取当前语言
你可以通过 `useCurrentLang` 方法来获取当前使用的语言。
- **类型:**
```ts
function useCurrentLang(): Ref<string>;
```
- **示例:**
```ts
import { useCurrentLang } from 'vant';
const currentLang = useCurrentLang();
console.log(currentLang.value); // --> 'zh-CN'
```
## 常见问题
### 找不到所需的语言包?

View File

@ -25,4 +25,6 @@ export const Locale = {
},
};
export const useCurrentLang = () => lang;
export default Locale;