小程序修改
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import Taro from '@tarojs/taro';
|
||||
|
||||
const USER_PHONE_KEY = 'user_phone';
|
||||
|
||||
export function saveUserPhone(phone: string) {
|
||||
const normalized = phone.replace(/\D/g, '').slice(0, 11);
|
||||
if (!/^1[3-9]\d{9}$/.test(normalized)) return;
|
||||
try {
|
||||
Taro.setStorageSync(USER_PHONE_KEY, normalized);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export function getStoredUserPhone(): string {
|
||||
try {
|
||||
const value = Taro.getStorageSync(USER_PHONE_KEY);
|
||||
return typeof value === 'string' ? value : '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user