From 52c771c22aa028f5bacfc732a5080f6a3a3aa30a Mon Sep 17 00:00:00 2001 From: tx <2622874537@qq.com> Date: Tue, 31 Dec 2024 11:11:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=AE=E5=8A=A9=E4=B8=AD=E5=BF=83=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/user/HelpCenterPage.tsx | 412 +++++++++++++++++++++++------- 1 file changed, 314 insertions(+), 98 deletions(-) diff --git a/src/views/user/HelpCenterPage.tsx b/src/views/user/HelpCenterPage.tsx index 8b92e5d..fceb6a1 100644 --- a/src/views/user/HelpCenterPage.tsx +++ b/src/views/user/HelpCenterPage.tsx @@ -1,22 +1,50 @@ import React, { useState, useEffect } from 'react'; -import { View, StyleSheet, ScrollView, Image, TouchableOpacity, Alert } from 'react-native'; -import { TopNavigation, TopNavigationAction, Icon, Text, Button } from '@ui-kitten/components'; +import { View, StyleSheet, ScrollView, Image, TouchableOpacity, Alert, Modal, Text, ImageBackground } from 'react-native'; +import { TopNavigation, TopNavigationAction, Icon, Button } from '@ui-kitten/components'; import { apiService } from '../../utils/api'; import { rpx } from '../../utils/rpx'; -const BackIcon = (props) => ( +const BackIcon = (props: any) => ( ); -const HelpCenterPage = ({ navigation }) => { +const HelpCenterPage = ({ navigation }: { navigation: any }) => { const [showQrcode, setShowQrcode] = useState(false); const [phone, setPhone] = useState({ serverWx: '', serverPhone: '' }); const [classifyList, setClassifyList] = useState([]); const [wordlist, setWordlist] = useState([]); const [tabindex, setTabindex] = useState(0); + const [isLoading, setIsLoading] = useState(true); useEffect(() => { - fetchClassifyList(); + const initData = async () => { + try { + setIsLoading(true); + const classifyResponse = await apiService.getClassifyList(); + console.log('分类数据:', classifyResponse); // 添加日志 + + if (classifyResponse?.data?.length > 0) { + setClassifyList(classifyResponse.data); + const firstClassifyId = classifyResponse.data[0].classifyId; + console.log('第一个分类ID:', firstClassifyId); // 添加日志 + + const articleResponse = await apiService.getArticleList(firstClassifyId); + console.log('文章列表数据:', articleResponse); // 添加日志 + + if (articleResponse?.rows) { + setWordlist(articleResponse.rows); + } + } + } catch (error) { + console.error('初始化数据失败:', error); + setClassifyList([]); + setWordlist([]); + } finally { + setIsLoading(false); + } + }; + + initData(); fetchPhone(); }, []); @@ -29,21 +57,30 @@ const HelpCenterPage = ({ navigation }) => { ); const fetchPhone = async () => { - // 模拟获取电话信息 const response = await apiService.getServerPhone(); setPhone(response.data); }; - const fetchClassifyList = async () => { - const response = await apiService.getClassifyList(); - console.log(response,'分类列表'); - setClassifyList(response.data); - fetchArticleList(response.data[0].classifyId); - }; - - const fetchArticleList = async (id) => { - const response = await apiService.getArticleList(id); - setWordlist(response.data.rows); + const fetchArticleList = async (id: string) => { + if (!id) return; + + try { + setIsLoading(true); + console.log('获取文章列表,分类ID:', id); // 添加日志 + const response = await apiService.getArticleList(id); + console.log('获取到的文章列表:', response); // 添加日志 + + if (response?.rows) { + setWordlist(response.rows); + } else { + setWordlist([]); + } + } catch (error) { + console.error('获取文章列表失败:', error); + setWordlist([]); + } finally { + setIsLoading(false); + } }; const showWechat = () => { @@ -54,107 +91,226 @@ const HelpCenterPage = ({ navigation }) => { Alert.alert('拨打电话', `拨打电话: ${phone.serverPhone}`); }; - const changeTab = (index, id) => { + const changeTab = (index: number, id: string) => { setTabindex(index); fetchArticleList(id); }; - const topage = (item) => { + const topage = (item: any) => { navigation.navigate('ArticlePage', { id: item.articleId }); }; - return ( - - - - Hi~有什么可以帮您! - 工作时间: 工作日8:30-11:30 13:30-18:00 - - - - 微信客服 - 为您解答疑惑 - - - - - - - 客服电话 - 欢迎您拨打提问 - - - + const renderWordList = () => { + console.log('当前wordlist数据:', wordlist); // 添加日志 + + if (isLoading) { + return ( + + 加载中... - - - {classifyList.map((item, index) => ( - changeTab(index, item.classifyId)}> - {item.classifyName} - - - ))} - - {wordlist.map((item, index) => ( - topage(item)}> - {item.title} + ); + } + + if (!Array.isArray(wordlist) || wordlist.length === 0) { + return ( + + 暂无数据 + + ); + } + + return ( + + {wordlist.map((item, index) => { + console.log('渲染列表项:', item.title); // 添加日志 + return ( + topage(item)} + > + + {item.title || '无标题'} + - ))} - - {showQrcode && ( - - 微信客服 - - + ); + })} + + ); + }; + + return ( + + + + + + + + Hi~有什么可以帮您! + 工作时间: + 工作日8:30-11:30 13:30-18:00 + + + + + + + + + + 微信客服 + 为您解答疑惑 + + + + + + + + + + + 客服电话 + 欢迎您拨打提问 + + + + + + + + + + {classifyList.map((item, index) => ( + changeTab(index, item.classifyId)} + > + {item.classifyName} + {/* {wordlist[0].title} */} + + + ))} + + + {renderWordList()} + + - )} - - + + + + setShowQrcode(false)} + > + + 微信客服 + + + 保存二维码 + + setShowQrcode(false)} + > + × + + + + + + ); }; const styles = StyleSheet.create({ + wordListWrapper: { + flex: 1, + width: '100%', + }, + background: { + flex: 1, + }, container: { flex: 1, - backgroundColor: '#f5f5f5', + }, + navbar: { + backgroundColor: 'transparent', + height: rpx(90), }, content: { - padding: rpx(16), + paddingLeft: rpx(40), + paddingRight: rpx(64), }, - title: { - fontSize: rpx(36), + helpTime: { + flexDirection: 'row', + justifyContent: 'space-between', + }, + helpTimeLeft: { + marginLeft: rpx(40), + }, + helpTimeLeftTit: { fontWeight: '700', + fontSize: rpx(36), color: '#3D3D3D', - marginBottom: rpx(10), }, - text: { - fontSize: rpx(24), + helpTimeLeftContent: { fontWeight: '400', + fontSize: rpx(24), color: '#3D3D3D', - marginVertical: rpx(8), + }, + helpTimeRight: { + justifyContent: 'center', + }, + helpTimeRightImg: { + width: rpx(168), + height: rpx(154), }, helpBtnBox: { flexDirection: 'row', alignItems: 'center', marginTop: rpx(50), + width: rpx(644), padding: rpx(20), + paddingHorizontal: rpx(38), backgroundColor: '#FFFFFF', - borderRadius: rpx(20), shadowColor: '#000', shadowOffset: { width: 0, height: rpx(6) }, shadowOpacity: 0.08, shadowRadius: rpx(64), + borderRadius: rpx(20), }, helpBtnItem: { flex: 1, flexDirection: 'row', justifyContent: 'space-between', }, + helpBtnItemLeft: {}, helpBtnItemLeftTit: { fontWeight: '700', fontSize: rpx(28), @@ -166,22 +322,24 @@ const styles = StyleSheet.create({ fontSize: rpx(24), color: '#3D3D3D', }, + helpBtnItemRight: {}, helpBtnItemRightImg: { width: rpx(84), height: rpx(84), }, line: { + marginHorizontal: rpx(20), width: rpx(2), height: rpx(128), backgroundColor: '#D8D8D8', - marginHorizontal: rpx(20), }, qscard: { - width: '100%', + width: rpx(680), marginVertical: rpx(40), backgroundColor: '#FFFFFF', borderRadius: rpx(40), padding: rpx(28), + paddingHorizontal: rpx(30), shadowColor: '#2A82E4', shadowOffset: { width: 0, height: rpx(16) }, shadowOpacity: 0.1, @@ -190,67 +348,125 @@ const styles = StyleSheet.create({ cardTop: { flexDirection: 'row', alignItems: 'center', + flexWrap: 'nowrap', }, li: { minWidth: rpx(112), marginRight: rpx(20), }, txt: { + width: rpx(150), fontWeight: '500', fontSize: rpx(28), color: '#3D3D3D', + zIndex: 1, }, botBor: { marginTop: rpx(-20), width: '90%', height: rpx(26), - backgroundColor: '#fff', + backgroundColor: '#FFFFFF', borderRadius: rpx(20), + zIndex: 0, }, botBorActive: { - marginTop: rpx(-20), - width: '90%', - height: rpx(26), backgroundColor: 'rgba(66, 151, 243, 0.55)', - borderRadius: rpx(20), }, - qsLi: { + wordListContainer: { + marginTop: rpx(20), + paddingHorizontal: rpx(20), // 添加水平内边距 + }, + qsLi: { flexDirection: 'row', - justifyContent: 'space-between', alignItems: 'center', + justifyContent: 'space-between', borderBottomWidth: rpx(2), - borderBottomColor: '#D8D8D870', + borderBottomColor: 'rgba(216, 216, 216, 0.44)', paddingVertical: rpx(26), + // 移除 width: '100%' + }, + lastQsLi: { + borderBottomWidth: rpx(2), + borderBottomColor: '#FFFFFF', }, qsLiTxt: { + flex: 1, // 让文本占据剩余空间 fontWeight: '400', fontSize: rpx(28), color: '#3D3D3D', + marginRight: rpx(20), // 改用 marginRight 替代 paddingRight }, icon: { - fontSize: rpx(32), - color: '#3D3D3D', + width: rpx(32), + height: rpx(32), }, - qrcodeContainer: { - position: 'absolute', - top: 0, - left: 0, - right: 0, - bottom: 0, + txtActive: { + color: '#4297F3', + fontWeight: '500', + }, + mask: { + flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.6)', justifyContent: 'center', alignItems: 'center', }, + qrcodeBox: { + width: rpx(600), + backgroundColor: '#FFFFFF', + borderRadius: rpx(20), + padding: rpx(40), + position: 'relative', + }, qrcodeTitle: { fontSize: rpx(32), fontWeight: '500', - color: '#333', + textAlign: 'center', marginBottom: rpx(30), + color: '#333', }, - qrcodeImage: { - width: rpx(200), - height: rpx(200), - marginBottom: rpx(20), + qrcodeImg: { + width: rpx(400), + height: rpx(450), + alignSelf: 'center', + }, + qrcodeBtn: { + width: rpx(400), + height: rpx(80), + backgroundColor: '#4297F3', + borderRadius: rpx(40), + justifyContent: 'center', + alignItems: 'center', + marginTop: rpx(40), + alignSelf: 'center', + }, + qrcodeBtnText: { + color: '#FFFFFF', + fontSize: rpx(28), + }, + closeBtn: { + position: 'absolute', + right: rpx(20), + top: rpx(20), + width: rpx(60), + height: rpx(60), + justifyContent: 'center', + alignItems: 'center', + }, + closeBtnText: { + fontSize: rpx(40), + color: '#999', + }, + loadingText: { + textAlign: 'center', + padding: rpx(20), + color: '#666', + fontSize: rpx(28), + }, + emptyText: { + textAlign: 'center', + padding: rpx(20), + color: '#999', + fontSize: rpx(28), }, });