11
This commit is contained in:
parent
b247ef32a4
commit
acdb0999da
|
@ -111,5 +111,7 @@ export const apiService = {
|
||||||
updateKey: (data: any) => api.put('/appVerify/editKey', data),
|
updateKey: (data: any) => api.put('/appVerify/editKey', data),
|
||||||
deleteKey: (key: any) => api.delete('/appVerify/del/' + key),
|
deleteKey: (key: any) => api.delete('/appVerify/del/' + key),
|
||||||
getExpiredKeys: () => api.get('/appVerify/getExpiredKeyListByOwnerId'),
|
getExpiredKeys: () => api.get('/appVerify/getExpiredKeyListByOwnerId'),
|
||||||
|
getKeyInfo: (keyId: string) => api.get('/appVerify/key/'+keyId),
|
||||||
|
bindKey: (keyId: string) => api.post('/appVerify/claimKey?keyId='+keyId),
|
||||||
// updateKeyExpiration: (keyId: string, expirationTime: string) => api.put('/appVerify/updateKeyExpiration', { keyId, expirationTime }),
|
// updateKeyExpiration: (keyId: string, expirationTime: string) => api.put('/appVerify/updateKeyExpiration', { keyId, expirationTime }),
|
||||||
};
|
};
|
|
@ -34,7 +34,7 @@ type RootStackParamList = {
|
||||||
type NavigationProp = StackNavigationProp<RootStackParamList>;
|
type NavigationProp = StackNavigationProp<RootStackParamList>;
|
||||||
|
|
||||||
const BackIcon = (props: any) => (
|
const BackIcon = (props: any) => (
|
||||||
<Icon {...props} name='arrow-back-outline'/>
|
<Icon {...props} name='arrow-back-outline' />
|
||||||
);
|
);
|
||||||
|
|
||||||
const SnBind = () => {
|
const SnBind = () => {
|
||||||
|
@ -48,7 +48,7 @@ const SnBind = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const BackAction = () => (
|
const BackAction = () => (
|
||||||
<TopNavigationAction icon={BackIcon} onPress={navigateBack}/>
|
<TopNavigationAction icon={BackIcon} onPress={navigateBack} />
|
||||||
);
|
);
|
||||||
|
|
||||||
const togglePopover = () => {
|
const togglePopover = () => {
|
||||||
|
@ -57,15 +57,116 @@ const SnBind = () => {
|
||||||
|
|
||||||
// 处理 keyId 的方法
|
// 处理 keyId 的方法
|
||||||
const handleKeyId = async (keyId: string) => {
|
const handleKeyId = async (keyId: string) => {
|
||||||
const res = await apiService.getUserInfo();
|
try {
|
||||||
|
// 先获取用户信息
|
||||||
|
const userInfoRes = await new Promise((resolve, reject) => {
|
||||||
|
apiService.getUserInfo()
|
||||||
|
.then(res => {
|
||||||
|
if (!res || !res.user) {
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: '获取用户信息失败',
|
||||||
|
});
|
||||||
|
reject(new Error('获取用户信息失败'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(res);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('获取用户信息出错:', error);
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: '获取用户信息失败',
|
||||||
|
});
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
console.log('处理 keyId:', keyId);
|
// 用户信息获取成功后,再获取密钥信息
|
||||||
// TODO: 在这里添加处理 keyId 的逻辑
|
const keyInfoRes = await new Promise((resolve, reject) => {
|
||||||
|
apiService.getKeyInfo(keyId)
|
||||||
|
.then(res => {
|
||||||
|
if (!res || !res.data) {
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: '二维码已过期',
|
||||||
|
});
|
||||||
|
reject(new Error('二维码已过期'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(res);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('获取密钥信息出错:', error);
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: '获取密钥信息失败',
|
||||||
|
});
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 验证手机号匹配
|
||||||
|
const userPhone = userInfoRes.user.phonenumber;
|
||||||
|
const sharePhone = keyInfoRes.data.sharePhone;
|
||||||
|
|
||||||
|
if (!userPhone || !sharePhone) {
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: '手机号信息不完整',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userPhone !== sharePhone) {
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: '您不是分享码的拥有者',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行绑定操作
|
||||||
|
const bindRes = await new Promise((resolve, reject) => {
|
||||||
|
apiService.bindKey(keyId)
|
||||||
|
.then(res => {
|
||||||
|
if (res.code === 200) {
|
||||||
|
Toast.show({
|
||||||
|
type: 'success',
|
||||||
|
text1: '绑定成功',
|
||||||
|
});
|
||||||
|
navigateBack();
|
||||||
|
resolve(res);
|
||||||
|
} else {
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: res.msg || '绑定失败',
|
||||||
|
});
|
||||||
|
reject(new Error(res.msg || '绑定失败'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('绑定密钥出错:', error);
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: '绑定失败',
|
||||||
|
});
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('处理密钥绑定时出错:', error);
|
||||||
|
Toast.show({
|
||||||
|
type: 'error',
|
||||||
|
text1: '操作失败,请稍后重试',
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理扫描结果的方法
|
// 处理扫描结果的方法
|
||||||
const handleScanResult = (data: string) => {
|
const handleScanResult = (data: string) => {
|
||||||
console.log('扫描结果:', data);
|
// console.log('扫描结果:', data);
|
||||||
try {
|
try {
|
||||||
// 检查是否包含 sn
|
// 检查是否包含 sn
|
||||||
const snMatch = data.match(/[?&]sn=([^&]+)/);
|
const snMatch = data.match(/[?&]sn=([^&]+)/);
|
||||||
|
@ -83,7 +184,9 @@ const SnBind = () => {
|
||||||
|
|
||||||
// 检查是否包含 keyId
|
// 检查是否包含 keyId
|
||||||
const keyIdMatch = data.match(/[?&]keyId=([^&]+)/);
|
const keyIdMatch = data.match(/[?&]keyId=([^&]+)/);
|
||||||
|
|
||||||
if (keyIdMatch && keyIdMatch[1]) {
|
if (keyIdMatch && keyIdMatch[1]) {
|
||||||
|
|
||||||
setIsScanning(false);
|
setIsScanning(false);
|
||||||
handleKeyId(keyIdMatch[1]);
|
handleKeyId(keyIdMatch[1]);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user