From de0f6c43b19761d3a8c352f82bb83c5c844e1d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sat, 7 Jun 2025 12:22:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/hjm/hjmBxLog/model/index.ts | 2 + src/api/hjm/hjmExamLog/index.ts | 1 - src/app.config.ts | 4 +- src/components/Questions.tsx | 42 ++++ src/hjm/bx/bx-add.tsx | 87 +++++++-- src/hjm/bx/bx-list.tsx | 291 ---------------------------- src/hjm/bx/bx.tsx | 190 +++++++++++++++--- src/pages/study/study.tsx | 11 +- src/utils/request.ts | 2 +- 9 files changed, 285 insertions(+), 345 deletions(-) create mode 100644 src/components/Questions.tsx delete mode 100644 src/hjm/bx/bx-list.tsx diff --git a/src/api/hjm/hjmBxLog/model/index.ts b/src/api/hjm/hjmBxLog/model/index.ts index 1948ca4..57ab817 100644 --- a/src/api/hjm/hjmBxLog/model/index.ts +++ b/src/api/hjm/hjmBxLog/model/index.ts @@ -12,6 +12,8 @@ export interface HjmBxLog { accidentType?: string; // 车辆ID carId?: number; + // 车辆编号 + carNo?: string; // 保险图片 image?: string; // 排序(数字越小越靠前) diff --git a/src/api/hjm/hjmExamLog/index.ts b/src/api/hjm/hjmExamLog/index.ts index 63e92bf..56f219d 100644 --- a/src/api/hjm/hjmExamLog/index.ts +++ b/src/api/hjm/hjmExamLog/index.ts @@ -105,7 +105,6 @@ export async function checkMonthTaskCompleted() { const res = await request.get>( '/hjm/hjm-exam-log/checkMonthTaskCompleted' ); - console.log(res,'1231231123123123') if (res.code === 0) { return res.data; } diff --git a/src/app.config.ts b/src/app.config.ts index 2438511..cfcb325 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -47,7 +47,9 @@ export default defineAppConfig({ "video/video", "exam/exam", "bx/bx", - "bx/bx-add" + "bx/bx-add", + // "bx/bx-list", + // "question/detail" ] } // { diff --git a/src/components/Questions.tsx b/src/components/Questions.tsx new file mode 100644 index 0000000..a665bd9 --- /dev/null +++ b/src/components/Questions.tsx @@ -0,0 +1,42 @@ +import {useEffect, useState} from "react"; +import {pageHjmQuestions} from "@/api/hjm/hjmQuestions"; +import {HjmQuestions} from "@/api/hjm/hjmQuestions/model"; + +/** + * 文章终极列表 + * @constructor + */ +const Questions = () => { + const [list, setList] = useState([]) + + const reload = () => { + pageHjmQuestions({}).then(res => { + if (res?.list) { + setList(res?.list) + } + }) + } + + useEffect(() => { + reload() + }, []) + + return ( +
+
+
+ { + list.map((item, index) => { + return ( +
+
{item.question}
+
+ ) + }) + } +
+
+
+ ) +} +export default Questions diff --git a/src/hjm/bx/bx-add.tsx b/src/hjm/bx/bx-add.tsx index 94303ea..ca863e9 100644 --- a/src/hjm/bx/bx-add.tsx +++ b/src/hjm/bx/bx-add.tsx @@ -1,4 +1,4 @@ -import {useEffect, useState} from "react"; +import {useEffect, useState, useCallback} from "react"; import Taro from '@tarojs/taro' import { Image, @@ -22,8 +22,10 @@ function BxAdd() { const [loading, setLoading] = useState(false) const [uploading, setUploading] = useState(false) const [carInfo, setCarInfo] = useState(null) + const [lastClickTime, setLastClickTime] = useState(0) const [formData, setFormData] = useState({ carId: undefined, + accidentType: undefined, image: '', comments: '', status: 0 // 0: 待审核, 1: 已通过, 2: 已驳回 @@ -74,29 +76,75 @@ function BxAdd() { } } - // 拍照上传 - const takePhoto = () => { + // 拍照上传 - 使用 useCallback 防止重复触发 + const takePhoto = useCallback((event?: any) => { + // 阻止事件冒泡 + if (event) { + event.stopPropagation() + event.preventDefault() + } + + // 防抖:防止快速连续点击 + const now = Date.now() + if (now - lastClickTime < 1000) { // 1秒内不允许重复点击 + console.log('点击过于频繁,请稍候...') + return + } + setLastClickTime(now) + + // 防止重复点击 + if (uploading) { + console.log('正在上传中,请稍候...') + Taro.showToast({ + title: '正在上传中...', + icon: 'loading' + }) + return + } + + console.log('开始拍照上传...') + Taro.chooseImage({ count: 1, sizeType: ['compressed'], sourceType: ['camera'], - success: async () => { + success: async (res) => { try { setUploading(true) + console.log('选择图片成功:', res.tempFilePaths[0]) + // 这里应该调用实际的上传接口 - uploadFile().then(data => { - setFormData({ - ...formData, - image: data.url - }) - }); + const uploadResult = await uploadFile() + + setFormData(prev => ({ + ...prev, + image: uploadResult.url || res.tempFilePaths[0] + })) + + Taro.showToast({ + title: '照片上传成功', + icon: 'success' + }) } catch (error) { + console.error('上传失败:', error) + Taro.showToast({ + title: '上传失败,请重试', + icon: 'error' + }) } finally { setUploading(false) } + }, + fail: (error) => { + console.error('选择图片失败:', error) + Taro.showToast({ + title: '选择图片失败', + icon: 'error' + }) + setUploading(false) } }) - } + }, [uploading, lastClickTime]) // 提交表单 const handleSubmit = async () => { @@ -131,7 +179,8 @@ function BxAdd() { // 构建提交数据 const submitData: HjmBxLog = { ...formData, - comments: `事故类型:${accidentType}\n事故描述:${accidentDescription || '无'}` + accidentType: accidentType, + comments: `${accidentDescription || '无'}` } await addHjmBxLog(submitData) @@ -140,9 +189,10 @@ function BxAdd() { title: '报险提交成功', icon: 'success' }) + setTimeout(() => { Taro.navigateBack() - }, 1500) + }, 2000) } catch (error) { console.error('提交失败:', error) @@ -197,7 +247,7 @@ function BxAdd() { 车辆信息 - +
车辆编号: {carInfo.code} @@ -322,6 +372,7 @@ function BxAdd() { )}
diff --git a/src/hjm/bx/bx-list.tsx b/src/hjm/bx/bx-list.tsx deleted file mode 100644 index 27c5cbe..0000000 --- a/src/hjm/bx/bx-list.tsx +++ /dev/null @@ -1,291 +0,0 @@ -import React, {useEffect, useState} from "react"; -import { - InfiniteLoading, - Loading, - Empty, - Button, - Input, - Tag, - Image, - Space, - Cell -} from '@nutui/nutui-react-taro' -import {Search, Calendar, Truck, File} from '@nutui/icons-react-taro' -import Taro from '@tarojs/taro' -import {pageHjmBxLog} from "@/api/hjm/hjmBxLog"; -import {HjmBxLog} from "@/api/hjm/hjmBxLog/model"; - -/** - * 报险记录列表页面 - */ -const BxList: React.FC = () => { - const [list, setList] = useState([]) - const [loading, setLoading] = useState(false) - const [keywords, setKeywords] = useState('') - const [refreshing, setRefreshing] = useState(false) - - // 获取状态显示 - const getStatusDisplay = (status?: number) => { - switch (status) { - case 0: - return {text: '待审核', color: '#faad14', bgColor: '#fffbe6'} - case 1: - return {text: '已通过', color: '#52c41a', bgColor: '#f6ffed'} - case 2: - return {text: '已驳回', color: '#ff4d4f', bgColor: '#fff2f0'} - default: - return {text: '未知', color: '#8c8c8c', bgColor: '#f5f5f5'} - } - } - - const reload = async (showLoading = true) => { - try { - if (showLoading) setLoading(true) - setRefreshing(true) - - const res = await pageHjmBxLog({ - keywords: keywords.trim() || undefined - }) - - setList(res?.list || []) - } catch (error) { - console.error('获取报险记录失败:', error) - Taro.showToast({ - title: '获取报险记录失败', - icon: 'error' - }) - } finally { - setLoading(false) - setRefreshing(false) - } - } - - const onSearch = () => { - reload() - } - - const onKeywordsChange = (value: string) => { - setKeywords(value) - } - - const onAddInsurance = () => { - Taro.navigateTo({ - url: '/hjm/bx/bx-add' - }) - } - - const viewDetail = (item: HjmBxLog) => { - Taro.navigateTo({ - url: `/hjm/bx/bx-detail?id=${item.id}` - }) - } - - useEffect(() => { - reload() - }, []) - - return ( - <> - {/* 搜索栏 */} -
-
- - - -
-
- - {/* 报险记录列表 */} -
- {loading && list.length === 0 ? ( -
- 加载中... -
- ) : list.length === 0 ? ( - - - - ) : ( -
- {list.map((item, index) => { - const statusDisplay = getStatusDisplay(item.status) - - return ( -
viewDetail(item)} - > -
-
-
- - - 报险记录 #{item.id} - -
- - -
- - - 车辆ID:{item.carId} - -
- -
- - - 提交时间:{item.createTime} - -
-
-
- - - {statusDisplay.text} - -
- - {/* 事故照片预览 */} - {item.image && ( -
- -
- )} - - {/* 备注信息 */} - {item.comments && ( -
- {item.comments.length > 50 - ? `${item.comments.substring(0, 50)}...` - : item.comments - } -
- )} -
- ) - })} -
- )} -
- - {/* 浮动添加按钮 */} -
- -
- - ) -} - -export default BxList diff --git a/src/hjm/bx/bx.tsx b/src/hjm/bx/bx.tsx index daaad17..5a7ac74 100644 --- a/src/hjm/bx/bx.tsx +++ b/src/hjm/bx/bx.tsx @@ -1,37 +1,55 @@ -import {useEffect, useState} from "react"; -import {InfiniteLoading, Loading, Empty, Button, Input} from '@nutui/nutui-react-taro' -import {Search, Plus} from '@nutui/icons-react-taro' +import React, {useEffect, useState} from "react"; +import { + Loading, + Empty, + Button, + Input, + Tag, + Image, + Space +} from '@nutui/nutui-react-taro' +import {Search, Calendar, Truck, File} from '@nutui/icons-react-taro' import Taro from '@tarojs/taro' -import {pageHjmCar} from "@/api/hjm/hjmCar"; -import {HjmCar} from "@/api/hjm/hjmCar/model"; -import BestSellers from "./BestSellers"; +import {pageHjmBxLog} from "@/api/hjm/hjmBxLog"; +import {HjmBxLog} from "@/api/hjm/hjmBxLog/model"; /** - * 一键报险 - 车辆列表页面 - * @constructor + * 报险记录列表页面 */ -const InsuranceList = () => { - const [list, setList] = useState([]) +const Bx: React.FC = () => { + const [list, setList] = useState([]) const [loading, setLoading] = useState(false) const [keywords, setKeywords] = useState('') const [refreshing, setRefreshing] = useState(false) + console.log(refreshing) + // 获取状态显示 + const getStatusDisplay = (status?: number) => { + switch (status) { + case 0: + return {text: '待审核', color: '#faad14', bgColor: '#fffbe6'} + case 1: + return {text: '已通过', color: '#52c41a', bgColor: '#f6ffed'} + case 2: + return {text: '已驳回', color: '#ff4d4f', bgColor: '#fff2f0'} + default: + return {text: '未知', color: '#8c8c8c', bgColor: '#f5f5f5'} + } + } const reload = async (showLoading = true) => { try { if (showLoading) setLoading(true) setRefreshing(true) - // 获取车辆列表 - 只获取正常状态的车辆 - const res = await pageHjmCar({ - status: 1, - keywords: keywords.trim() || undefined + const res = await pageHjmBxLog({ + keywords: keywords.trim() }) setList(res?.list || []) } catch (error) { - console.error('获取车辆列表失败:', error) + console.error('获取报险记录失败:', error) Taro.showToast({ - title: '获取车辆列表失败', + title: '获取报险记录失败', icon: 'error' }) } finally { @@ -54,6 +72,12 @@ const InsuranceList = () => { }) } + const viewDetail = (item: HjmBxLog) => { + Taro.navigateTo({ + url: `/hjm/bx/bx-detail?id=${item.id}` + }) + } + useEffect(() => { reload() }, []) @@ -66,6 +90,7 @@ const InsuranceList = () => { top: '20px', left: 0, right: 0, + display: "none", zIndex: 20, padding: '0 16px', backgroundColor: '#f5f5f5' @@ -80,7 +105,7 @@ const InsuranceList = () => { }}> { - {/* 车辆列表 */} + {/* 报险记录列表 */}
{loading && list.length === 0 ? ( @@ -117,19 +142,122 @@ const InsuranceList = () => { 加载中...
) : list.length === 0 ? ( - - ) : ( - {}} - > - reload(false)}/> - +
+ {list.map((item, index) => { + const statusDisplay = getStatusDisplay(item.status) + + return ( +
viewDetail(item)} + > +
+
+
+ + + 报险记录 #{item.id} + +
+ + +
+ + + 车辆编号:{item.carNo} + +
+ +
+ + + 提交时间:{item.createTime} + +
+
+
+ + + {statusDisplay.text} + +
+ + {/* 事故照片预览 */} + {item.image && ( +
+ +
+ )} + + {/* 备注信息 */} + {item.comments && ( +
+ {item.comments.length > 50 + ? `${item.comments.substring(0, 50)}...` + : item.comments + } +
+ )} +
+ ) + })} +
)} @@ -152,11 +280,11 @@ const InsuranceList = () => { boxShadow: '0 4px 12px rgba(0,0,0,0.15)' }} > - + + ) } -export default InsuranceList +export default Bx diff --git a/src/pages/study/study.tsx b/src/pages/study/study.tsx index 8d9d3fb..ed6ffcc 100644 --- a/src/pages/study/study.tsx +++ b/src/pages/study/study.tsx @@ -1,9 +1,10 @@ import {useEffect, useState} from "react"; -import {Image} from '@nutui/nutui-react-taro' -import Taro from '@tarojs/taro' +import {Image} from '@nutui/nutui-react-taro'; +import Taro from '@tarojs/taro'; import {pageCmsArticle} from "@/api/cms/cmsArticle"; import {CmsArticle} from "@/api/cms/cmsArticle/model"; import {checkMonthTaskCompleted} from "@/api/hjm/hjmExamLog"; +import Questions from '@/components/Questions'; /** * 文章终极列表 @@ -17,7 +18,7 @@ const Study = () => { const reload = () => { setLoading(true) checkMonthTaskCompleted().then(res => { - if(res){ + if (res) { setMonthTaskCompleted(true) } pageCmsArticle({categoryId: 4289, status: 0}).then(data => { @@ -47,12 +48,14 @@ const Study = () => { { !monthTaskCompleted && list?.map((item, index) => { return ( -
Taro.navigateTo({url: `/hjm/video/video?id=${item.articleId}`})}> +
Taro.navigateTo({url: `/hjm/video/video?id=${item.articleId}`})}>
) }) } + {list?.length == 0 && }
) } diff --git a/src/utils/request.ts b/src/utils/request.ts index 78d155c..7bbba37 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -4,7 +4,7 @@ import {BaseUrl, TenantId} from "@/utils/config"; let baseUrl = BaseUrl if(process.env.NODE_ENV === 'development'){ - baseUrl = 'http://localhost:9000/api' + // baseUrl = 'http://localhost:9000/api' } export function request(options:any) { const token = Taro.getStorageSync('access_token');