v4.0.18版本提交
This commit is contained in:
@@ -17,19 +17,25 @@ export function storeStarCount(rating?: number | string | null): number {
|
||||
return Math.min(5, Math.max(1, Math.round(n)));
|
||||
}
|
||||
|
||||
/** 省市区县 + 详细地址 拼接;空则回退占位文案 */
|
||||
export function fullStoreAddress(
|
||||
store: {
|
||||
province?: string | null;
|
||||
cityName?: string | null;
|
||||
city?: string | null;
|
||||
district?: string | null;
|
||||
address?: string | null;
|
||||
},
|
||||
fallback = '地址待完善',
|
||||
): string {
|
||||
const city = store.cityName || store.city || '';
|
||||
const text = `${store.province || ''}${city}${store.district || ''}${store.address || ''}`.trim();
|
||||
export type StoreAddressParts = {
|
||||
province?: string | null;
|
||||
cityName?: string | null;
|
||||
city?: string | null;
|
||||
district?: string | null;
|
||||
address?: string | null;
|
||||
};
|
||||
|
||||
function addressPart(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : '';
|
||||
}
|
||||
|
||||
/** 省 + 市 + 区 + 详细地址原样拼接;详细地址已含省市区时不去重 */
|
||||
export function fullStoreAddress(store: StoreAddressParts, fallback = '地址待完善'): string {
|
||||
const province = addressPart(store.province);
|
||||
const city = addressPart(store.cityName) || addressPart(store.city);
|
||||
const district = addressPart(store.district);
|
||||
const detail = addressPart(store.address);
|
||||
const text = `${province}${city}${district}${detail}`;
|
||||
return text || fallback;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user