DEV Community

桃花镇童长老
桃花镇童长老

Posted on

china_area

china_area

🏆Introduction and Recommendations

china_area China's regional data, provincial, municipal and county data.

harmony-utils A HarmonyOS tool library with rich features and extremely easy to use, with the help of many practical tools, is committed to helping developers quickly build Hongmeng applications.

harmony-dialog An extremely simple and easy-to-use zero-invasion pop-up window, which can be easily implemented with just one line of code, and can be easily popped up no matter where you are.

🌞Download and install

ohpm i @nutpi/china_area
OpenHarmony ohpm
For more information, please refer to如何安装 OpenHarmony ohpm 包

📚API detailed explanation使用案例

AreaHelper Method Introduction
getAreaStrSync
getAreaStr
Get JSON strings for provinces, cities and counties
getAreaSync
getArea
Get data from provinces, cities and counties
getCityByNameSync
getCityByName
Get the following city according to the provincial name
getDintrictByNameSync
getDintrictByName
Get the following district and county based on the city name

📚Sample code

//获取省市县的JSON字符串
let txtStr = await AreaHelper.getAreaStr();
let areaList = JSONUtil.jsonToArray<AreaEntity>(txtStr);


//获取省市县的数据
let areas = AreaHelper.getAreaSync();


//根据省名获取下面的市
let citys = await AreaHelper.getCityByName("安徽省");


//根据市名获取下面的区县
let list = AreaHelper.getDistrictByNameSync("合肥市");


//配合‘@pura/harmony-dialog’的\nshowTextPickerDialog()方法使用
let data = AreaHelper.getAreaSync();
DialogHelper.showTextPickerDialog({
  title: "请选择",
  range: data,
  onChange: (value: string | string[], index: number | number[]) => {
    LogUtil.error(`value: ${value} --- index: ${index}`);
  },
  onAction: (action: number, dialogId: string, value: string | string[]) => {
    if (action === DialogAction.SURE) {
      DialogHelper.showToast(`已选择:${value}`);
    }
  }
});
Enter fullscreen mode Exit fullscreen mode

🍎Communication and communication 🙏

Any problems found during use can be askedIssueGive us;
Of course, we also welcome you to send us a messagePR

🌏Open Source Protocol

This project is based onApache License 2.0, when copying and borrowing codes, please be sure to indicate the source.

Top comments (0)