feat(hjm/violation): 实现违章记录编辑功能
- 添加编辑模式支持,通过路由参数id判断是否为编辑状态 - 实现获取违章记录详情并填充表单功能 - 区分新增和编辑模式的提交逻辑- 编辑模式下禁用车辆编号输入框- 添加页面间通信机制,支持列表页刷新 - 实现违章记录删除功能 - 更新页面标题根据模式动态显示 - 修改按钮文字根据操作状态显示不同文案 - 调整开发环境API基础URL配置 - 优化请求工具中的本地开发地址配置
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
export const ENV_CONFIG = {
|
export const ENV_CONFIG = {
|
||||||
// 开发环境
|
// 开发环境
|
||||||
development: {
|
development: {
|
||||||
API_BASE_URL: 'https://cms-api.websoft.top/api',
|
API_BASE_URL: 'http://127.0.0.1/api',
|
||||||
APP_NAME: '开发环境',
|
APP_NAME: '开发环境',
|
||||||
DEBUG: 'true',
|
DEBUG: 'true',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export default definePageConfig({
|
export default definePageConfig({
|
||||||
navigationBarTitleText: '添加违章记录'
|
navigationBarTitleText: '违章记录'
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import Taro from '@tarojs/taro'
|
import Taro, {useRouter} from '@tarojs/taro'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
TextArea,
|
TextArea,
|
||||||
Cell,
|
Cell,
|
||||||
Input,
|
Input,
|
||||||
} from '@nutui/nutui-react-taro'
|
} from '@nutui/nutui-react-taro'
|
||||||
import {addHjmViolation} from "@/api/hjm/hjmViolation";
|
import {addHjmViolation, getHjmViolation, updateHjmViolation} from "@/api/hjm/hjmViolation";
|
||||||
import {HjmViolation} from "@/api/hjm/hjmViolation/model";
|
import {HjmViolation} from "@/api/hjm/hjmViolation/model";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加违章记录页面
|
* 添加/编辑违章记录页面
|
||||||
*/
|
*/
|
||||||
function Add() {
|
function Add() {
|
||||||
|
const {params} = useRouter();
|
||||||
const [loading, setLoading] = useState<boolean>(false)
|
const [loading, setLoading] = useState<boolean>(false)
|
||||||
const [lastSubmitTime, setLastSubmitTime] = useState<number>(0) // 最后提交时间
|
const [lastSubmitTime, setLastSubmitTime] = useState<number>(0) // 最后提交时间
|
||||||
|
const [isEditMode, setIsEditMode] = useState<boolean>(false) // 是否为编辑模式
|
||||||
const [formData, setFormData] = useState<HjmViolation>({
|
const [formData, setFormData] = useState<HjmViolation>({
|
||||||
code: '',
|
code: '',
|
||||||
title: '',
|
title: '',
|
||||||
@@ -26,6 +28,28 @@ function Add() {
|
|||||||
// 初始化页面数据
|
// 初始化页面数据
|
||||||
const initPageData = async () => {
|
const initPageData = async () => {
|
||||||
try {
|
try {
|
||||||
|
// 检查是否为编辑模式
|
||||||
|
if (params.id) {
|
||||||
|
setIsEditMode(true)
|
||||||
|
// 获取违章记录详情
|
||||||
|
try {
|
||||||
|
const violation = await getHjmViolation(Number(params.id));
|
||||||
|
if (violation) {
|
||||||
|
setFormData(violation);
|
||||||
|
} else {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '未找到该违章记录',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取违章记录详情失败:', error)
|
||||||
|
Taro.showToast({
|
||||||
|
title: '获取违章记录详情失败',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('初始化失败:', error)
|
console.error('初始化失败:', error)
|
||||||
@@ -36,7 +60,6 @@ function Add() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
// 防止重复提交 - 检查loading状态
|
// 防止重复提交 - 检查loading状态
|
||||||
@@ -76,36 +99,32 @@ function Add() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!formData.money?.trim()) {
|
|
||||||
// Taro.showToast({
|
|
||||||
// title: '请输入处罚金额',
|
|
||||||
// icon: 'none'
|
|
||||||
// })
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (!formData.score?.trim()) {
|
|
||||||
// Taro.showToast({
|
|
||||||
// title: '请输入扣分',
|
|
||||||
// icon: 'none'
|
|
||||||
// })
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isEditMode) {
|
||||||
|
// 编辑模式 - 更新违章记录
|
||||||
|
await updateHjmViolation(formData);
|
||||||
|
Taro.showToast({
|
||||||
|
title: '更新成功',
|
||||||
|
icon: 'success'
|
||||||
|
})
|
||||||
|
// 通知列表页面刷新
|
||||||
|
Taro.eventCenter.trigger('violationListRefresh')
|
||||||
|
} else {
|
||||||
|
// 新增模式 - 添加违章记录
|
||||||
// 构建提交数据
|
// 构建提交数据
|
||||||
const submitData: HjmViolation = {
|
const submitData: HjmViolation = {
|
||||||
...formData,
|
...formData,
|
||||||
status: 0 // 0未处理, 1已处理
|
status: 0 // 0未处理, 1已处理
|
||||||
}
|
}
|
||||||
|
await addHjmViolation(submitData);
|
||||||
addHjmViolation(submitData).then((res) => {
|
|
||||||
console.log(res)
|
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: '提交成功',
|
title: '提交成功',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
})
|
})
|
||||||
|
// 通知列表页面刷新
|
||||||
|
Taro.eventCenter.trigger('violationListRefresh')
|
||||||
// 清空表单
|
// 清空表单
|
||||||
setFormData({
|
setFormData({
|
||||||
code: '',
|
code: '',
|
||||||
@@ -114,14 +133,19 @@ function Add() {
|
|||||||
score: '',
|
score: '',
|
||||||
comments: ''
|
comments: ''
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
Taro.navigateBack()
|
Taro.navigateBack()
|
||||||
}, 2000)
|
}, 2000)
|
||||||
}).finally(() => {
|
} catch (error) {
|
||||||
setLoading(false)
|
Taro.showToast({
|
||||||
|
title: isEditMode ? '更新失败' : '提交失败',
|
||||||
|
icon: 'none'
|
||||||
})
|
})
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -151,7 +175,9 @@ function Add() {
|
|||||||
{/* marginBottom: '12px'*/}
|
{/* marginBottom: '12px'*/}
|
||||||
{/* }}>*/}
|
{/* }}>*/}
|
||||||
{/* <Truck size={18} color="#1890ff"/>*/}
|
{/* <Truck size={18} color="#1890ff"/>*/}
|
||||||
{/* <span style={{fontSize: '16px', fontWeight: 'bold'}}>添加违章记录</span>*/}
|
{/* <span style={{fontSize: '16px', fontWeight: 'bold'}}>*/}
|
||||||
|
{/* {isEditMode ? '编辑违章记录' : '添加违章记录'}*/}
|
||||||
|
{/* </span>*/}
|
||||||
{/* </div>*/}
|
{/* </div>*/}
|
||||||
{/*</div>*/}
|
{/*</div>*/}
|
||||||
|
|
||||||
@@ -167,7 +193,9 @@ function Add() {
|
|||||||
padding: '16px',
|
padding: '16px',
|
||||||
borderBottom: '1px solid #f0f0f0'
|
borderBottom: '1px solid #f0f0f0'
|
||||||
}}>
|
}}>
|
||||||
<span style={{fontSize: '16px', fontWeight: 'bold'}}>违章信息</span>
|
<span style={{fontSize: '16px', fontWeight: 'bold'}}>
|
||||||
|
{isEditMode ? '编辑违章记录' : '添加违章记录'}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<Cell.Group>
|
<Cell.Group>
|
||||||
<Cell title="车辆编号" style={{padding: '12px 16px'}}>
|
<Cell title="车辆编号" style={{padding: '12px 16px'}}>
|
||||||
@@ -176,6 +204,7 @@ function Add() {
|
|||||||
value={formData.code}
|
value={formData.code}
|
||||||
onChange={(value) => setFormData({...formData, code: value})}
|
onChange={(value) => setFormData({...formData, code: value})}
|
||||||
style={{backgroundColor: '#ffffff', borderRadius: '8px'}}
|
style={{backgroundColor: '#ffffff', borderRadius: '8px'}}
|
||||||
|
disabled={isEditMode} // 编辑模式下禁用车辆编号输入
|
||||||
/>
|
/>
|
||||||
</Cell>
|
</Cell>
|
||||||
<Cell title="违章标题" style={{padding: '12px 16px'}}>
|
<Cell title="违章标题" style={{padding: '12px 16px'}}>
|
||||||
@@ -234,7 +263,7 @@ function Add() {
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
>
|
>
|
||||||
{loading ? '提交中...' : '提交违章记录'}
|
{loading ? (isEditMode ? '更新中...' : '提交中...') : (isEditMode ? '更新违章记录' : '提交违章记录')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import {
|
|||||||
Pagination
|
Pagination
|
||||||
} from '@nutui/nutui-react-taro'
|
} from '@nutui/nutui-react-taro'
|
||||||
import {Search, Calendar, Truck, File, AddCircle} from '@nutui/icons-react-taro'
|
import {Search, Calendar, Truck, File, AddCircle} from '@nutui/icons-react-taro'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro, {useDidShow} from '@tarojs/taro'
|
||||||
import {pageHjmViolation} from "@/api/hjm/hjmViolation";
|
import {pageHjmViolation, removeHjmViolation} from "@/api/hjm/hjmViolation";
|
||||||
import {HjmViolation} from "@/api/hjm/hjmViolation/model";
|
import {HjmViolation} from "@/api/hjm/hjmViolation/model";
|
||||||
|
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ const List: React.FC = () => {
|
|||||||
const [page, setPage] = useState<number>(1)
|
const [page, setPage] = useState<number>(1)
|
||||||
const [limit, setLimit] = useState<number>(10)
|
const [limit, setLimit] = useState<number>(10)
|
||||||
const [total, setTotal] = useState<number>(0)
|
const [total, setTotal] = useState<number>(0)
|
||||||
|
const [needRefresh, setNeedRefresh] = useState<boolean>(true)
|
||||||
|
|
||||||
console.log(refreshing)
|
console.log(refreshing)
|
||||||
// 获取状态显示
|
// 获取状态显示
|
||||||
@@ -54,11 +55,11 @@ const List: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const roleCode = Taro.getStorageSync('RoleCode');
|
const roleCode = Taro.getStorageSync('RoleCode');
|
||||||
if(roleCode == 'kuaidi'){
|
if (roleCode == 'kuaidi') {
|
||||||
if(Taro.getStorageSync('OrganizationParentId') == 0){
|
if (Taro.getStorageSync('OrganizationParentId') == 0) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
where.organizationParentId = Taro.getStorageSync('OrganizationId');
|
where.organizationParentId = Taro.getStorageSync('OrganizationId');
|
||||||
}else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
where.organizationId = Taro.getStorageSync('OrganizationId');
|
where.organizationId = Taro.getStorageSync('OrganizationId');
|
||||||
}
|
}
|
||||||
@@ -93,9 +94,30 @@ const List: React.FC = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 页面显示时触发,包括从其他页面返回
|
||||||
|
useDidShow(() => {
|
||||||
|
if (needRefresh) {
|
||||||
|
reload(false);
|
||||||
|
setNeedRefresh(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
reload().then()
|
// 监听刷新事件
|
||||||
}, [page, limit])
|
const handleRefresh = () => {
|
||||||
|
setNeedRefresh(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
Taro.eventCenter.on('violationListRefresh', handleRefresh);
|
||||||
|
|
||||||
|
// 初始加载数据
|
||||||
|
reload().then();
|
||||||
|
|
||||||
|
// 清理事件监听器
|
||||||
|
return () => {
|
||||||
|
Taro.eventCenter.off('violationListRefresh', handleRefresh);
|
||||||
|
};
|
||||||
|
}, [page, limit]);
|
||||||
|
|
||||||
const onPageChange = (current: number) => {
|
const onPageChange = (current: number) => {
|
||||||
setPage(current)
|
setPage(current)
|
||||||
@@ -261,6 +283,34 @@ const List: React.FC = () => {
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{item.userId == Taro.getStorageSync('UserId') && (
|
||||||
|
<div className={'flex justify-end mt-4'}>
|
||||||
|
<Space>
|
||||||
|
<Button type="default" onClick={(event: any) => {
|
||||||
|
event.stopPropagation()
|
||||||
|
Taro.navigateTo({
|
||||||
|
url: `/hjm/violation/add?id=${item.id}`
|
||||||
|
})
|
||||||
|
}}>修改</Button>
|
||||||
|
<Button type="primary" onClick={(event: any) => {
|
||||||
|
event.stopPropagation()
|
||||||
|
removeHjmViolation(item.id).then(() => {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '删除成功',
|
||||||
|
icon: 'success'
|
||||||
|
})
|
||||||
|
// 删除成功后重新加载列表
|
||||||
|
reload(false)
|
||||||
|
}).catch((error) => {
|
||||||
|
Taro.showToast({
|
||||||
|
title: error.message || '删除失败',
|
||||||
|
icon: 'error'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}}>删除</Button>
|
||||||
|
</Space>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
@@ -281,7 +331,7 @@ const List: React.FC = () => {
|
|||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
backgroundColor: '#ff0000',
|
backgroundColor: '#ff0000',
|
||||||
}}>
|
}}>
|
||||||
<AddCircle size={28} color={'#ffffff'} onClick={onAddInsurance} />
|
<AddCircle size={28} color={'#ffffff'} onClick={onAddInsurance}/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {BaseUrl, TenantId} from "@/utils/config";
|
|||||||
let baseUrl = BaseUrl
|
let baseUrl = BaseUrl
|
||||||
|
|
||||||
if(process.env.NODE_ENV === 'development'){
|
if(process.env.NODE_ENV === 'development'){
|
||||||
// baseUrl = 'http://localhost:9000/api'
|
baseUrl = 'http://localhost:9200/api'
|
||||||
}
|
}
|
||||||
export function request<T>(options:any) {
|
export function request<T>(options:any) {
|
||||||
const token = Taro.getStorageSync('access_token');
|
const token = Taro.getStorageSync('access_token');
|
||||||
|
|||||||
Reference in New Issue
Block a user