feat: 初始提交

This commit is contained in:
siujamo
2025-12-25 16:12:01 +08:00
commit faff32475f
77 changed files with 6123 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import { type TreeDataNode } from "antd"
import type { TreeNode } from "@/types/tree"
import type { Department } from "@/types/entity"
export function transformDepartmentData(departments: TreeNode<Department>[]): TreeDataNode[] {
if (!departments || departments.length === 0) {
return []
}
return departments
.sort((a, b) => a.item.sort - b.item.sort)
.map((node) => {
const { item, children } = node
const hasChildren = children && children.length > 0
const treeItem: TreeDataNode = {
key: item.id,
title: item.name,
}
if (hasChildren) {
// Append children
return { ...treeItem, children: transformDepartmentData(children) }
}
return treeItem
})
}
+2
View File
@@ -0,0 +1,2 @@
export * as PhoneNumberUtils from "./phone-number-utils"
export * as DepartmentUtils from "./department-utils"
+28
View File
@@ -0,0 +1,28 @@
import { type CountryCode as RegionAbbreviation, getCountryCallingCode, parsePhoneNumberWithError, PhoneNumber } from "libphonenumber-js"
/**
* Format user's phone number as user's country/region.
*
* @param regionAbbreviation user's region abbreviation
* @param phoneNumber user's phone number
* @return formatted phone number
*/
export function formatInternationalPhoneNumber(regionAbbreviation: string, phoneNumber: string): string {
try {
const _phoneNumber = parsePhoneNumberWithError(phoneNumber, regionAbbreviation as RegionAbbreviation)
if (!_phoneNumber.isValid()) {
console.warn(`Phone number ${_phoneNumber.formatInternational()} is not valid`)
}
return _phoneNumber.formatInternational()
} catch (error) {
console.error("Phone number parsing failed:", error)
const _regionAbbreviation: RegionAbbreviation = regionAbbreviation as RegionAbbreviation
const callingCode = getCountryCallingCode(_regionAbbreviation)
return `+${callingCode} ${phoneNumber}`
}
}
export function getDefaultCountryCode(): RegionAbbreviation {
return import.meta.env.VITE_DEFAULT_REGION_CODE
}