2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
59 lines
1.1 KiB
JavaScript
59 lines
1.1 KiB
JavaScript
export const getExperienceCenterValue = (
|
|
status,
|
|
statusKey,
|
|
storageKey,
|
|
defaultValue = '',
|
|
) => {
|
|
const statusValue = status?.[statusKey];
|
|
if (statusValue !== undefined && statusValue !== null && statusValue !== '') {
|
|
return statusValue;
|
|
}
|
|
|
|
const storageValue = localStorage.getItem(storageKey);
|
|
if (
|
|
storageValue !== null &&
|
|
storageValue !== undefined &&
|
|
storageValue !== ''
|
|
) {
|
|
return storageValue;
|
|
}
|
|
|
|
return defaultValue;
|
|
};
|
|
|
|
export const getExperienceCenterBool = (
|
|
status,
|
|
statusKey,
|
|
storageKey,
|
|
defaultValue = false,
|
|
) => {
|
|
const value = getExperienceCenterValue(
|
|
status,
|
|
statusKey,
|
|
storageKey,
|
|
defaultValue,
|
|
);
|
|
if (typeof value === 'boolean') {
|
|
return value;
|
|
}
|
|
return String(value).toLowerCase() === 'true';
|
|
};
|
|
|
|
export const getExperienceCenterPositiveInt = (
|
|
status,
|
|
statusKey,
|
|
storageKey,
|
|
defaultValue,
|
|
) => {
|
|
const value = parseInt(
|
|
getExperienceCenterValue(
|
|
status,
|
|
statusKey,
|
|
storageKey,
|
|
String(defaultValue),
|
|
),
|
|
10,
|
|
);
|
|
return Number.isFinite(value) && value > 0 ? value : defaultValue;
|
|
};
|