Files
device-voice-h5/utils/phone-bind.js
luo 97dec4dc65
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 2m14s
fix: some
2026-10-13 16:11:02 +08:00

32 lines
1.3 KiB
JavaScript

// A customer phone or an old cache does not prove an asset association exists.
export const optionalBoolean = (value) => {
if (value === true || value === 1) return true;
if (value === false || value === 0) return false;
return null;
};
export const getPhoneBindingMode = (customerPhone, assetPhoneBound) => {
if (customerPhone === null || assetPhoneBound === null) return 'unknown';
if (!customerPhone) return assetPhoneBound ? 'customer' : 'customer-asset';
return assetPhoneBound ? 'none' : 'asset';
};
export const getBindingSuccessState = (state, phone, mode) => {
if (mode === 'customer-asset') {
return { customerPhone: phone, assetPhoneBound: true, assetPhoneIsOwn: true, needBindPhone: false };
}
if (mode === 'asset') {
return { assetPhoneBound: true, assetPhoneIsOwn: phone === state.customerPhone, needBindPhone: false };
}
if (mode === 'customer') {
return { customerPhone: phone, assetPhoneIsOwn: null, needBindPhone: false };
}
// Even if the customer phone was unavailable, successful binding of a
// previously unbound asset proves an association now exists, not its owner.
if (state.assetPhoneBound === false) {
return { assetPhoneBound: true, assetPhoneIsOwn: null, needBindPhone: false };
}
// An ambiguous success response does not identify which phone was changed.
return { needBindPhone: false };
};