From 8a6f0fcffe9ce91446de3e98e93dfc639038e682 Mon Sep 17 00:00:00 2001 From: tx <2622874537@qq.com> Date: Tue, 31 Dec 2024 10:14:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 14 ++ package.json | 1 + src/navigation/HomeStack.tsx | 8 + src/navigation/types.tsx | 1 + src/utils/api.ts | 29 ++- src/views/ProfileScreen.jsx | 2 +- src/views/device/deviceDetailSet.tsx | 297 ++++++++++++++++++++------- src/views/user/HelpCenterPage.tsx | 257 +++++++++++++++++++++++ yarn.lock | 10 +- 9 files changed, 543 insertions(+), 76 deletions(-) create mode 100644 src/views/user/HelpCenterPage.tsx diff --git a/package-lock.json b/package-lock.json index 03b5073..2a41ee6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,6 +43,7 @@ "react-native-svg": "^15.10.1", "react-native-toast-message": "^2.2.1", "react-native-view-shot": "^4.0.0", + "react-native-webview": "^13.12.5", "react-native-wheel-picker-android": "^2.0.6", "rn-fetch-blob": "^0.12.0", "rn-qr-generator": "^1.4.3", @@ -14701,6 +14702,19 @@ "react-native": "*" } }, + "node_modules/react-native-webview": { + "version": "13.12.5", + "resolved": "https://registry.npmmirror.com/react-native-webview/-/react-native-webview-13.12.5.tgz", + "integrity": "sha512-INOKPom4dFyzkbxbkuQNfeRG9/iYnyRDzrDkJeyvSWgJAW2IDdJkWFJBS2v0RxIL4gqLgHkiIZDOfiLaNnw83Q==", + "dependencies": { + "escape-string-regexp": "^4.0.0", + "invariant": "2.2.4" + }, + "peerDependencies": { + "react": "*", + "react-native": "*" + } + }, "node_modules/react-native-wheel-picker-android": { "version": "2.0.6", "resolved": "https://registry.npmmirror.com/react-native-wheel-picker-android/-/react-native-wheel-picker-android-2.0.6.tgz", diff --git a/package.json b/package.json index 8cf5310..0097845 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "react-native-svg": "^15.10.1", "react-native-toast-message": "^2.2.1", "react-native-view-shot": "^4.0.0", + "react-native-webview": "^13.12.5", "react-native-wheel-picker-android": "^2.0.6", "rn-fetch-blob": "^0.12.0", "rn-qr-generator": "^1.4.3", diff --git a/src/navigation/HomeStack.tsx b/src/navigation/HomeStack.tsx index 5ecfdf3..447cb42 100644 --- a/src/navigation/HomeStack.tsx +++ b/src/navigation/HomeStack.tsx @@ -18,6 +18,7 @@ import TestBule from '../views/device/test_bule'; import ShareDetailScreen from '../views/device/KeyDetail'; import ExpiredKeysScreen from '../views/device/ExpiredKeysScreen'; import deviceDetailSet from '../views/device/deviceDetailSet'; +import HelpCenterPage from '../views/user/HelpCenterPage'; const Stack = createStackNavigator(); const createScreenOptions = (title: string): StackNavigationOptions => { @@ -81,6 +82,13 @@ export default function HomeStackNavigator({ navigation, route }: Props) { headerShown: false, }} /> + api.post('/appCodeLogin', { phone, phoneCode, uuid }), - + // 密码登录 passwordLogin: (username: string, password: string) => api.post('/appLogin', { username, password }), register: (username: string, password: string, code: string, uuid: string) => api.post('/register', { username, password, code, uuid }), - + // 重置密码 resetPassword: (phone: string, newPassword: string, phoneCode: string, uuid: string) => api.post('/forgotPassword', { phone, newPassword, phoneCode, uuid }), + // 获取用户信息 getUserInfo: () => api.get('/getInfo'), - + // 获取设备信息 getDeviceInfo: (sn: string) => api.get('/appVerify/getDeviceBySn', { params: { sn } }), + // 绑定设备 bindSn: (sn: string) => api.post('/appVerify/userBandDevice?sn=' + sn), + // 获取设备列表 getDeviceList: () => api.get('/appVerify/getDeviceListByMerchantToken'), toggleDefault: (sn: string) => api.put(`/appVerify/toggleDefault?sn=${sn}`), + // 响铃 ring: (sn: string) => api.post(`/app/device/ring?sn=${sn}`), + // 解锁 unlocking: (sn: string) => api.post(`/appVerify/admin/unlocking?sn=${sn}`), + // 锁车 lock: (sn: string) => api.post(`/appVerify/admin/lock?sn=${sn}`), + // 获取钥匙列表 getKeyListByOwnerId: () => api.get('/appVerify/getKeyListByOwnerId'), + // 添加钥匙 addKey: (data: any) => api.post('/appVerify/addKey', data), + // 更新钥匙 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), + // 更新设备 updateDevice: ( data: any) => api.put('/appVerify/device/edit', data), + // 解绑设备 untieDevice: (deviceId: string) => api.post('/appVerify/untie/'+deviceId), + // 获取七牛云token getQiniuToken: () => api.get('/common/qiniu/uploadInfo'), + // 获取车型 getModelList: () => api.get('/appVerify/modelList'), + // 获取帮助中心分类 + getClassifyList: () => api.get('/app/classify/list'), + // 获取帮助中心文章列表 + getArticleList: (classifyId: string) => api.get('/app/article/list?classifyId=' + classifyId), + // 获取客服电话 + getServerPhone: () => api.get('/app/getServerPhone'), // updateKeyExpiration: (keyId: string, expirationTime: string) => api.put('/appVerify/updateKeyExpiration', { keyId, expirationTime }), }; \ No newline at end of file diff --git a/src/views/ProfileScreen.jsx b/src/views/ProfileScreen.jsx index 0d81b93..a75b4d9 100644 --- a/src/views/ProfileScreen.jsx +++ b/src/views/ProfileScreen.jsx @@ -101,7 +101,7 @@ const ProfileScreen = () => { navigation.navigate('HelpCenter')} + onPress={() => navigation.navigate('HelpCenterPage')} > { const [brandList, setBrandList] = useState([]); const [modelList, setModelList] = useState([]); const [modelModalVisible, setModelModalVisible] = useState(false); - const [previewImage, setPreviewImage] = useState(null); const upload = async () => { try { const result = await uploadImageService.uploadImage(); - if (result) { - const response = await apiService.updateDevice({ - sn: deviceInfo.sn, - pricture: result + + if (!result || !Array.isArray(result) || result.length === 0) { + Toast.show({ + type: 'error', + text1: '上传失败', + text2: '请重试', + }); + return; + } + + const imageUrl = result[0]; // 从数组中提取 URL + + const response = await apiService.updateDevice({ + sn: deviceInfo.sn, + pricture: imageUrl + }); + + if (response.code == 200) { + setDeviceInfo(prevInfo => ({ + ...prevInfo, + pricture: imageUrl + })); + setModalVisible(false); + Toast.show({ + type: 'success', + text1: '修改成功', + }); + fetchDeviceInfo(); + } else { + Toast.show({ + type: 'error', + text1: response.msg || '修改失败', }); - - if (response.code === 200) { - setDeviceInfo(prevInfo => ({ - ...prevInfo, - pricture: result - })); - Toast.show({ - type: 'success', - text1: '图片上传成功', - }); - fetchDeviceInfo(); - } else { - Toast.show({ - type: 'error', - text1: response.msg || '图片上传失败', - }); - } } } catch (error) { - console.error('Upload failed:', error); + console.error('Update failed:', error); Toast.show({ type: 'error', - text1: '上传失败', + text1: '更新失败', text2: '请检查网络连接', }); } @@ -142,7 +152,7 @@ const deviceDetailSet = () => { } const response = await apiService.getDeviceInfo(sn); - if (response.code === 200 && response.data) { + if (response.code == 200 && response.data) { setDeviceInfo(response.data); } else { Toast.show({ @@ -177,9 +187,6 @@ const deviceDetailSet = () => { const models = modelData.filter(item => item.brandName === brand).map(item => item.model); setModelList(models); setSelectedModelIndex(new IndexPath(0)); - const initialModel = models[0]; - const initialImageUrl = getImageUrl(brand, initialModel); - setPreviewImage(initialImageUrl); }; const getImageUrl = (brand, model) => { @@ -187,6 +194,41 @@ const deviceDetailSet = () => { return selectedModel ? selectedModel.picture : null; }; + const updateDeviceImage = async (brand, model) => { + const imageUrl = getImageUrl(brand, model); + if (imageUrl && deviceInfo?.sn) { + try { + const response = await apiService.updateDevice({ + sn: deviceInfo.sn, + pricture: imageUrl + }); + console.log(response,'图片上传'); + if (response.code == 200) { + setDeviceInfo(prevInfo => ({ + ...prevInfo, + pricture: imageUrl + })); + Toast.show({ + type: 'success', + text1: '图片更新成功', + }); + } else { + Toast.show({ + type: 'error', + text1: response.msg || '图片更新失败', + }); + } + } catch (error) { + console.error('图片更新失败:', error); + Toast.show({ + type: 'error', + text1: '图片更新失败', + text2: '请检查网络连接', + }); + } + } + }; + const handleBrandChange = (index) => { setSelectedBrandIndex(index); const brand = brandList[index.row]; @@ -195,50 +237,12 @@ const deviceDetailSet = () => { const handleModelChange = (index) => { setSelectedModelIndex(index); - const model = modelList[index.row]; - const brand = brandList[selectedBrandIndex.row]; - const imageUrl = getImageUrl(brand, model); - setPreviewImage(imageUrl); }; - const handleModelSelection = async () => { - if (!selectedBrandIndex || !selectedModelIndex) return; - + const handleModelSelection = () => { const brand = brandList[selectedBrandIndex.row]; const model = modelList[selectedModelIndex.row]; - const imageUrl = getImageUrl(brand, model); - - try { - const response = await apiService.updateDevice({ - sn: deviceInfo.sn, - pricture: imageUrl - }); - - if (response.code === 200) { - setDeviceInfo(prevInfo => ({ - ...prevInfo, - pricture: imageUrl - })); - Toast.show({ - type: 'success', - text1: '车辆信息更新成功', - }); - fetchDeviceInfo(); - } else { - Toast.show({ - type: 'error', - text1: response.msg || '车辆信息更新失败', - }); - } - } catch (error) { - console.error('Update failed:', error); - Toast.show({ - type: 'error', - text1: '更新失败', - text2: '请检查网络连接', - }); - } - + updateDeviceImage(brand, model); setModelModalVisible(false); }; @@ -258,6 +262,93 @@ const deviceDetailSet = () => { /> ); + const handleEdit = (type: 'remark' | 'fullVoltage' | 'vehicleNum' | 'lowVoltage' | 'fullEndurance') => { + let title = ''; + let value = ''; + + switch (type) { + case 'remark': + title = '修改备注'; + value = deviceInfo?.remark || ''; + break; + case 'fullVoltage': + title = '修改满电电压'; + value = deviceInfo?.fullVoltage || ''; + break; + case 'vehicleNum': + title = '修改车牌号'; + value = deviceInfo?.vehicleNum || ''; + break; + case 'lowVoltage': + title = '修改亏电电压'; + value = deviceInfo?.lowVoltage || ''; + break; + case 'fullEndurance': + title = '修改满电续航'; + value = deviceInfo?.fullEndurance || ''; + break; + } + + setCurrentEdit({ title, value, type }); + setModalVisible(true); + }; + + const handleSubmit = async (value: string) => { + if (!currentEdit || !deviceInfo?.sn) return; + + try { + const response = await apiService.updateDevice({ + sn: deviceInfo.sn, + [currentEdit.type]: value + }); + + if (response.code === 200) { + setDeviceInfo(prevInfo => ({ + ...prevInfo, + [currentEdit.type]: value + })); + setModalVisible(false); + Toast.show({ + type: 'success', + text1: '修改成功', + }); + fetchDeviceInfo(); + } else { + Toast.show({ + type: 'error', + text1: response.msg || '修改失败', + }); + } + } catch (error) { + console.error('Update failed:', error); + Toast.show({ + type: 'error', + text1: '更新失败', + text2: '请检查网络连接', + }); + } + }; + + const handleUnbind = () => { + apiService.untieDevice(deviceInfo.deviceId).then((res) => { + if (res.code == 200) { + Toast.show({ + type: 'success', + text1: '解绑成功', + }); + navigation.goBack(); + } + }); + }; + + if (isLoading) { + return ( + + + + ); + } + return ( { scrollEventThrottle={16} nestedScrollEnabled={true} > + + - + 上传图片 @@ -290,7 +383,69 @@ const deviceDetailSet = () => { - {/* ... existing info items ... */} + + + 备注 + handleEdit('remark')} + > + {deviceInfo?.remark || '未设置'} + + + + + + 满电电压 + handleEdit('fullVoltage')} + > + {deviceInfo?.fullVoltage || '未设置'} + + + + + 亏电电压 + handleEdit('lowVoltage')} + > + {deviceInfo?.lowVoltage || '未设置'} + + + + + 满电续航 + handleEdit('fullEndurance')} + > + {deviceInfo?.fullEndurance || '未设置'} + + + + + 车牌号 + handleEdit('vehicleNum')} + > + {deviceInfo?.vehicleNum || '未设置'} + + + + + 蓝牙设置 + navigation.navigate('DeviceSet')} + > + 去设置 + + + + @@ -318,7 +473,7 @@ const deviceDetailSet = () => { 选择车型