💥 feat(模块): 添加了个很棒的功能

This commit is contained in:
cclu 2025-03-17 17:21:21 +08:00
parent 230cbb8434
commit 1d35b458fa
5 changed files with 125 additions and 65 deletions

View File

@ -1,7 +1,7 @@
import LeftSelectTree from "@/components/leftSelectTree/leftSelectTree"; import LeftSelectTree from "@/components/leftSelectTree/leftSelectTree";
import { handleGetServerpartDDL } from "@/components/leftSelectTree/service"; import { handleGetServerpartDDL } from "@/components/leftSelectTree/service";
import { ActionType, FormInstance, ProCard, ProForm, ProFormList, ProFormSelect, ProFormSwitch, ProFormText, ProFormTextArea, ProTable } from "@ant-design/pro-components"; import { ActionType, FormInstance, ProCard, ProForm, ProFormList, ProFormSelect, ProFormSwitch, ProFormText, ProFormTextArea, ProTable } from "@ant-design/pro-components";
import { Button, Col, message, Modal, Popconfirm, Row, Space, Image } from "antd"; import { Button, Col, message, Modal, Popconfirm, Row, Space, Image, Drawer } from "antd";
import moment from "moment"; import moment from "moment";
import { useRef, useState } from "react"; import { useRef, useState } from "react";
import { connect } from "umi"; import { connect } from "umi";
@ -9,6 +9,7 @@ import { handleAddTemplates, handleDeleteTemplates, handleGetQuestionList, handl
import { handleGetExamineTypeTreeList } from "../index/service"; import { handleGetExamineTypeTreeList } from "../index/service";
import QRCode from 'qrcode'; import QRCode from 'qrcode';
import { base64ToFile } from "@/utils/publicMethods"; import { base64ToFile } from "@/utils/publicMethods";
import RecordDetail from "../record/components/recordDetail";
const examineModal: React.FC<{ currentUser: any }> = (props) => { const examineModal: React.FC<{ currentUser: any }> = (props) => {
@ -29,6 +30,8 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
// 显示新增点位的悬浮框 // 显示新增点位的悬浮框
const [showPlaceModal, setShowPlaceModal] = useState<boolean>(false) const [showPlaceModal, setShowPlaceModal] = useState<boolean>(false)
// 显示详情
const [showDetail, handleShowDetail] = useState<boolean>(false)
// 当前点击选中的问题行 // 当前点击选中的问题行
const [currentRow, setCurrentRow] = useState<any>() const [currentRow, setCurrentRow] = useState<any>()
// 服务区的枚举 // 服务区的枚举
@ -160,7 +163,7 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
align: 'center', align: 'center',
hideInSearch: true, hideInSearch: true,
fixed: "right", fixed: "right",
width: 100, width: 120,
render: (_: any, record: any) => { render: (_: any, record: any) => {
return <Space> return <Space>
<a onClick={() => { <a onClick={() => {
@ -168,6 +171,10 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
setCurrentRow(record) setCurrentRow(record)
setShowPlaceModal(true) setShowPlaceModal(true)
}}></a> }}></a>
<a onClick={() => {
setCurrentRow(record)
handleShowDetail(true)
}}></a>
<Popconfirm <Popconfirm
title={"确认删除?"} title={"确认删除?"}
onConfirm={async () => { onConfirm={async () => {
@ -650,6 +657,20 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
/> />
</Modal> </Modal>
</div> </div>
<Drawer
title={false}
closeIcon={false}
onClose={() => {
handleShowDetail(false)
}}
open={showDetail}
destroyOnClose
width={'60%'}
>
<RecordDetail parentRow={currentRow} show={showDetail} detailType={'modal'} />
</Drawer>
</div > </div >
) )
} }

View File

@ -14,8 +14,9 @@ import './printStyle.css';
type DetailProps = { type DetailProps = {
parentRow: any; // 父级数据 parentRow: any; // 父级数据
show: boolean;// 抽屉是否显示 show: boolean;// 抽屉是否显示
detailType: string; // 详情的类型
} }
const RecordDetail = ({ parentRow, show }: DetailProps) => { const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
const formRef = useRef<FormInstance>(); const formRef = useRef<FormInstance>();
@ -31,11 +32,13 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
const [footerContent, setFooterContent] = useState<string>('') const [footerContent, setFooterContent] = useState<string>('')
const headerRef = useRef<TextAreaRef>(null) const headerRef = useRef<TextAreaRef>(null)
const footerRef = useRef<TextAreaRef>(null) const footerRef = useRef<TextAreaRef>(null)
// 考核分类的对象格式
const [examineObj, setExamineObj] = useState<any>()
const columns: any = [ const columns: any = [
{ {
title: "考核分类", title: "考核分类",
dataIndex: "" dataIndex: "name"
}, },
{ {
title: "考核子类", title: "考核子类",
@ -47,6 +50,21 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
{ {
title: "考核结果", title: "考核结果",
dataIndex: "title", dataIndex: "title",
hideInTable: detailType === 'modal',
render: (_, record) => {
let str: string = ''
if (record.choiceResponse && record?.choiceResponse.length > 0) {
record.choiceResponse.forEach((item: any, index: number) => {
str += `${index > 0 ? '' : ''}答案${index + 1}${item}`
})
}
return str || ""
}
},
{
title: "考核选项",
dataIndex: "title",
hideInTable: detailType !== 'modal',
render: (_, record) => { render: (_, record) => {
let str: string = '' let str: string = ''
if (record.choiceResponse && record?.choiceResponse.length > 0) { if (record.choiceResponse && record?.choiceResponse.length > 0) {
@ -69,7 +87,7 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
let obj = { let obj = {
...parentRow, ...parentRow,
...extendObj, ...extendObj,
placeName: parentRow.template.title, placeName: parentRow.template?.title || '',
submittedAt: moment(parentRow?.submittedAt).format('YYYY-MM-DD HH:mm:ss') submittedAt: moment(parentRow?.submittedAt).format('YYYY-MM-DD HH:mm:ss')
} }
setFormRes(obj) setFormRes(obj)
@ -104,13 +122,18 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
// 把需要打印的数组拿到一层中来 // 把需要打印的数组拿到一层中来
const handleGetTableRes = (list: any) => { const handleGetTableRes = (list: any) => {
console.log('list', list);
let res: any = []; let res: any = [];
if (list && list.length > 0) { if (list && list.length > 0) {
list.forEach((item: any) => { list.forEach((item: any) => {
if (item.question && item.question.length > 0) { if (item.question && item.question.length > 0) {
// 如果当前项有question字段且不为空将其添加到结果数组 // 如果当前项有question字段且不为空将其添加到结果数组
item.question.forEach((questionItem: any) => { item.question.forEach((questionItem: any) => {
res.push(questionItem); res.push({
...questionItem,
parentId: item.parentId ? item.parentId : "-"
});
}); });
} }
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
@ -131,6 +154,7 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
// 深拷贝数据,避免修改原始数据 // 深拷贝数据,避免修改原始数据
const processedData = JSON.parse(JSON.stringify(data)); const processedData = JSON.parse(JSON.stringify(data));
console.log('processedData', processedData);
// 添加分类信息 // 添加分类信息
processedData.forEach((item: any) => { processedData.forEach((item: any) => {
@ -138,9 +162,10 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
if (item.question && item.question.categoryId) { if (item.question && item.question.categoryId) {
// 这里需要根据实际情况获取分类名称 // 这里需要根据实际情况获取分类名称
// 可以从缓存或其他地方获取 // 可以从缓存或其他地方获取
const categoryInfo = getCategoryInfo(item.question.categoryId); // const categoryInfo = getCategoryInfo(item.question.categoryId);
item.categoryName = categoryInfo?.name || ''; item.name = examineObj && item.parentId ? examineObj[item.parentId] : ""
item.parentCategoryName = categoryInfo?.parentName || ''; item.categoryName = item?.question.title || '';
item.parentCategoryName = item?.name || '';
} }
}); });
@ -395,6 +420,9 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
readonly readonly
/> />
</Col> </Col>
{
detailType === 'modal' ? '' :
<>
<Col span={8}> <Col span={8}>
<ProFormText <ProFormText
label={"巡查内容"} label={"巡查内容"}
@ -443,6 +471,8 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
</div> </div>
</ProFormList> </ProFormList>
</Col> </Col>
</>
}
</Row> </Row>
</ProForm> </ProForm>
@ -460,23 +490,28 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
</Button> </Button>
] ]
}} }}
scroll={{ x: "100%", y: 'calc(100vh - 400px)' }}
pagination={false}
options={false} options={false}
request={async () => { request={async () => {
let res = parentRow?.questionResponses || [] let res = detailType === 'modal' ? parentRow?.questionnaireTemplateQuestions
|| [] : parentRow?.questionResponses || []
console.log('res', res); console.log('res', res);
let obj: any = {}
let typeData = await handleGetExamineTypeTreeList({}) let typeData = await handleGetExamineTypeTreeList({})
console.log('typeData', typeData); console.log('typeData', typeData);
if (typeData && typeData.length > 0) { if (typeData && typeData.length > 0) {
typeData.forEach((item: any) => { typeData.forEach((item: any) => {
obj[item.id] = item.name
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
item.children.forEach((subItem: any) => { item.children.forEach((subItem: any) => {
obj[subItem.id] = subItem.name
}) })
} }
}) })
} }
setExamineObj(obj)
let tableData = await handeGetTableData(typeData, res) let tableData = await handeGetTableData(typeData, res)
console.log('tableData', tableData); console.log('tableData', tableData);
@ -487,6 +522,7 @@ const RecordDetail = ({ parentRow, show }: DetailProps) => {
// 处理表格数据,为合并单元格做准备 // 处理表格数据,为合并单元格做准备
let processedData = processTableDataForMerge(tableRes); let processedData = processTableDataForMerge(tableRes);
setTableData(processedData) setTableData(processedData)
if (processedData && processedData.length > 0) { if (processedData && processedData.length > 0) {
return { data: processedData, success: true } return { data: processedData, success: true }
} }

View File

@ -29,13 +29,13 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
title: "统计日期", title: "统计日期",
dataIndex: "staticDate", dataIndex: "staticDate",
hideInTable: true, hideInTable: true,
valueType: "date", valueType: "dateRange",
initialValue: [moment().format('YYYY-MM-DD')], initialValue: [moment().startOf('M'), moment()],
search: { search: {
transform: (value: any) => { transform: (value: any) => {
return { return {
startTime: value, startTime: moment(value[0]).format('YYYY-MM-DD'),
endTime: value endTime: moment(value[1]).format('YYYY-MM-DD')
}; };
}, },
}, },

View File

@ -2,7 +2,7 @@ import request from "@/utils/request"
// 拿到记录 // 拿到记录
export async function handleGetRecordList(params?: any) { export async function handleGetRecordList(params?: any) {
const data = await request.get('/questionnaire-responses', { params }) const data = await request.post('/questionnaire-templates/search', params)
if (data.code === 200) { if (data.code === 200) {
return data.data return data.data
} }

View File

@ -8,6 +8,9 @@ const { UMI_APP_BASEURL } = process.env;
// const instance = axios.create({ baseURL: UMI_APP_BASEURL }); // const instance = axios.create({ baseURL: UMI_APP_BASEURL });
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' }); // const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
// 修改baseURL为完整的API地址确保在生产环境中正确访问 // 修改baseURL为完整的API地址确保在生产环境中正确访问
const instance = axios.create({ baseURL: 'https://es.robot-z.cn' }); const instance = axios.create({ baseURL: 'https://es.robot-z.cn' });