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),
|
||||
deleteKey: (key: any) => api.delete('/appVerify/del/' + key),
|
||||
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 }),
|
||||
};
|
|
@ -1,11 +1,11 @@
|
|||
import React, { useState } from 'react';
|
||||
import {
|
||||
View,
|
||||
StyleSheet,
|
||||
TextInput,
|
||||
TouchableWithoutFeedback,
|
||||
Keyboard,
|
||||
Text,
|
||||
import {
|
||||
View,
|
||||
StyleSheet,
|
||||
TextInput,
|
||||
TouchableWithoutFeedback,
|
||||
Keyboard,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
Image,
|
||||
Modal
|
||||
|
@ -34,7 +34,7 @@ type RootStackParamList = {
|
|||
type NavigationProp = StackNavigationProp<RootStackParamList>;
|
||||
|
||||
const BackIcon = (props: any) => (
|
||||
<Icon {...props} name='arrow-back-outline'/>
|
||||
<Icon {...props} name='arrow-back-outline' />
|
||||
);
|
||||
|
||||
const SnBind = () => {
|
||||
|
@ -48,7 +48,7 @@ const SnBind = () => {
|
|||
};
|
||||
|
||||
const BackAction = () => (
|
||||
<TopNavigationAction icon={BackIcon} onPress={navigateBack}/>
|
||||
<TopNavigationAction icon={BackIcon} onPress={navigateBack} />
|
||||
);
|
||||
|
||||
const togglePopover = () => {
|
||||
|
@ -57,15 +57,116 @@ const SnBind = () => {
|
|||
|
||||
// 处理 keyId 的方法
|
||||
const handleKeyId = async (keyId: string) => {
|
||||
const res = await apiService.getUserInfo();
|
||||
|
||||
console.log('处理 keyId:', keyId);
|
||||
// TODO: 在这里添加处理 keyId 的逻辑
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
// 用户信息获取成功后,再获取密钥信息
|
||||
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) => {
|
||||
console.log('扫描结果:', data);
|
||||
// console.log('扫描结果:', data);
|
||||
try {
|
||||
// 检查是否包含 sn
|
||||
const snMatch = data.match(/[?&]sn=([^&]+)/);
|
||||
|
@ -83,7 +184,9 @@ const SnBind = () => {
|
|||
|
||||
// 检查是否包含 keyId
|
||||
const keyIdMatch = data.match(/[?&]keyId=([^&]+)/);
|
||||
|
||||
if (keyIdMatch && keyIdMatch[1]) {
|
||||
|
||||
setIsScanning(false);
|
||||
handleKeyId(keyIdMatch[1]);
|
||||
return;
|
||||
|
@ -114,7 +217,7 @@ const SnBind = () => {
|
|||
|
||||
const handleImagePicker = () => {
|
||||
setPopoverVisible(false);
|
||||
launchImageLibrary({
|
||||
launchImageLibrary({
|
||||
mediaType: 'photo',
|
||||
quality: 1,
|
||||
}, async (response) => {
|
||||
|
@ -125,7 +228,7 @@ const SnBind = () => {
|
|||
} else if (response.assets && response.assets.length > 0) {
|
||||
try {
|
||||
const { uri } = response.assets[0];
|
||||
|
||||
|
||||
// 使用 QRReader 识别图片中的二维码
|
||||
const result = await QRReader.detect({
|
||||
uri: uri
|
||||
|
@ -164,14 +267,14 @@ const SnBind = () => {
|
|||
accessoryLeft={BackAction}
|
||||
style={styles.topNavigation}
|
||||
/>
|
||||
|
||||
|
||||
<View style={styles.contentArea}>
|
||||
{/* 顶部图片 */}
|
||||
<Image
|
||||
source={{ uri: 'https://lxnapi.ccttiot.com/bike/img/static/uVnIDwcwQP7oo12PeYVJ' }}
|
||||
style={styles.topImage}
|
||||
<Image
|
||||
source={{ uri: 'https://lxnapi.ccttiot.com/bike/img/static/uVnIDwcwQP7oo12PeYVJ' }}
|
||||
style={styles.topImage}
|
||||
/>
|
||||
|
||||
|
||||
{/* 输入框和扫码按钮 */}
|
||||
<View style={styles.IptBox}>
|
||||
<TextInput
|
||||
|
@ -183,7 +286,7 @@ const SnBind = () => {
|
|||
<Popover
|
||||
anchor={() => (
|
||||
<TouchableOpacity onPress={togglePopover} style={styles.scanButton}>
|
||||
<Image
|
||||
<Image
|
||||
source={{ uri: 'https://lxnapi.ccttiot.com/bike/img/static/uSPtEFPtKlWIAKNrDtiQ' }}
|
||||
style={styles.scanIcon}
|
||||
/>
|
||||
|
@ -228,8 +331,8 @@ const SnBind = () => {
|
|||
title='扫描二维码'
|
||||
alignment='center'
|
||||
accessoryLeft={() => (
|
||||
<TopNavigationAction
|
||||
icon={BackIcon}
|
||||
<TopNavigationAction
|
||||
icon={BackIcon}
|
||||
onPress={() => setIsScanning(false)}
|
||||
/>
|
||||
)}
|
||||
|
@ -247,7 +350,7 @@ const SnBind = () => {
|
|||
}
|
||||
bottomContent={
|
||||
<View style={styles.bottomContainer}>
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
style={styles.cancelButton}
|
||||
onPress={() => setIsScanning(false)}
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue
Block a user