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

This commit is contained in:
cclu 2025-03-19 10:52:42 +08:00
parent 637f0cd1c8
commit 2a2a116a7e
9 changed files with 1027 additions and 336 deletions

View File

@ -0,0 +1,147 @@
import { ConnectState } from "@/models/global";
import { FormInstance, ProForm, ProFormSwitch, ProFormText, ProFormTextArea, ProFormTreeSelect } from "@ant-design/pro-components";
import { useImperativeHandle, useRef } from "react";
import { connect } from "umi";
import { handleGetAddExamineType, handleGetEditExamineType, handleGetExamineTypeTreeList } from "../service";
import { message, Modal } from "antd";
type DetailProps = {
parentRow: any
onRef: any
openAddModal: boolean
currentUser?: any
setOpenAddModal?: any
parentActionRef?: any
setParentRow?: any
afterAdd?: any // 新增完之后 需要调用的方法
}
const AddBigType = ({ parentRow, onRef, openAddModal, currentUser, setOpenAddModal, parentActionRef, setParentRow, afterAdd }: DetailProps) => {
// 弹出框的表单实例
const modalRef = useRef<FormInstance>()
useImperativeHandle(onRef, () => ({
modalRef
}));
return (
<div>
<Modal
title={`${parentRow?.id ? '编辑' : '创建'}分类`}
open={openAddModal}
destroyOnClose
onOk={() => {
modalRef.current?.validateFields().then(async (res) => {
let req = {}
let data = {}
if (parentRow?.id) {
req = {
...parentRow,
parentId: res.parentId,
name: res.name,
description: res.description,
status: res.status,
operator: currentUser?.operator
}
data = await handleGetEditExamineType(req)
} else {
req = {
parentId: res.parentId,
name: res.name,
description: res.description,
sortOrder: "1",
status: res.status,
operator: currentUser?.operator
}
data = await handleGetAddExamineType(req)
}
console.log('req', req);
console.log('data', data);
if (data.code === 200) {
modalRef.current?.resetFields()
message.success(data.message)
setOpenAddModal(false)
if (parentActionRef) {
parentActionRef.current?.reload()
}
if (setParentRow) {
setParentRow(undefined)
}
if (afterAdd) {
afterAdd()
}
} else {
message.error(data.message)
}
})
}}
onCancel={() => {
modalRef.current?.setFieldsValue({})
if (setParentRow) {
setParentRow(undefined)
}
setOpenAddModal(false)
}}
>
<ProForm formRef={modalRef} submitter={false} request={() => {
console.log('parentRow', parentRow);
return { ...parentRow }
}}>
<ProFormTreeSelect
label={"类别层级"}
name={"parentId"}
request={async () => {
const req = {}
const data = await handleGetExamineTypeTreeList(req)
console.log('dsadas', data);
let res = [
{
name: '/',
id: 0,
children: data
}
]
return res
}}
fieldProps={{
treeDefaultExpandedKeys: [0],
fieldNames: {
label: "name",
value: "id"
},
}}
rules={[
{ required: true, message: '请选择类别层级!' }
]}
/>
<ProFormText
label={"类别名称"}
name={"name"}
rules={[
{ required: true, message: '请输入类别名称!' }
]}
/>
<ProFormTextArea
label={"类别注释"}
name={"description"}
/>
<ProFormSwitch
label={"有效状态"}
name={"status"}
initialValue={parentRow?.id ? parentRow.status : true}
/>
</ProForm>
</Modal>
</div>
)
}
export default connect(({ user }: ConnectState) => ({
currentUser: user.data
}))(AddBigType);

View File

@ -7,6 +7,7 @@ import moment from "moment";
import LeftSelectTree from "@/components/leftSelectTree/leftSelectTree";
import { handleGetAddExamineType, handleGetDeleteExamineType, handleGetEditExamineType, handleGetExamineTypeList, handleGetExamineTypeTreeList } from "./service";
import { ProForm, ProFormSwitch, ProFormText, ProFormTextArea, ProFormTreeSelect } from "@ant-design/pro-components";
import AddBigType from "./components/addBigType";
const examineIndex: React.FC<{ currentUser: any }> = (props) => {
@ -190,104 +191,13 @@ const examineIndex: React.FC<{ currentUser: any }> = (props) => {
</div>
</div>
<Modal
title={`${currentRow?.id ? '编辑' : '创建'}分类`}
open={openAddModal}
destroyOnClose
onOk={() => {
modalRef.current?.validateFields().then(async (res) => {
let req = {}
let data = {}
if (currentRow?.id) {
req = {
...currentRow,
parentId: res.parentId,
name: res.name,
description: res.description,
status: res.status,
operator: currentUser?.operator
}
data = await handleGetEditExamineType(req)
} else {
req = {
parentId: res.parentId,
name: res.name,
description: res.description,
sortOrder: "1",
status: res.status,
operator: currentUser?.operator
}
data = await handleGetAddExamineType(req)
}
console.log('req', req);
console.log('data', data);
if (data.code === 200) {
modalRef.current?.resetFields()
message.success(data.message)
setOpenAddModal(false)
actionRef.current?.reload()
setCurrentRow(undefined)
} else {
message.error(data.message)
}
})
}}
onCancel={() => {
modalRef.current?.setFieldsValue({})
setCurrentRow(undefined)
setOpenAddModal(false)
}}
>
<ProForm formRef={modalRef} submitter={false} request={() => {
console.log('currentRow', currentRow);
return { ...currentRow }
}}>
<ProFormTreeSelect
label={"类别层级"}
name={"parentId"}
request={async () => {
const req = {}
const data = await handleGetExamineTypeList(req)
console.log('dsadas', data);
let res = [
{
name: '/',
id: 0,
children: data
}
]
return res
}}
fieldProps={{
treeDefaultExpandedKeys: [0],
fieldNames: {
label: "name",
value: "id"
},
}}
rules={[
{ required: true, message: '请选择类别层级!' }
]}
/>
<ProFormText
label={"类别名称"}
name={"name"}
rules={[
{ required: true, message: '请输入类别名称!' }
]}
/>
<ProFormTextArea
label={"类别注释"}
name={"description"}
/>
<ProFormSwitch
label={"有效状态"}
name={"status"}
initialValue={currentRow?.id ? currentRow.status : true}
/>
</ProForm>
</Modal>
<AddBigType parentRow={currentRow} openAddModal={openAddModal}
setOpenAddModal={setOpenAddModal}
parentActionRef={actionRef}
setParentRow={setCurrentRow} />
</div>
)
}

View File

@ -3,13 +3,15 @@ import { handleGetServerpartDDL } from "@/components/leftSelectTree/service";
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, Drawer } from "antd";
import moment from "moment";
import { useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { connect } from "umi";
import { handleAddTemplates, handleDeleteTemplates, handleGetQuestionList, handleGetTemplatesList, handleUpdateTemplates, handleUploadFile } from "./service";
import { handleGetExamineTypeTreeList } from "../index/service";
import QRCode from 'qrcode';
import { base64ToFile } from "@/utils/publicMethods";
import RecordDetail from "../record/components/recordDetail";
import AddBigType from "../index/components/addBigType";
import AddQuestion from "../question/components/addQuestion";
const examineModal: React.FC<{ currentUser: any }> = (props) => {
@ -56,6 +58,12 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
createdAt: { show: false },
operator: { show: false },
})
// 显示新增大类的抽屉
const [openAddBigType, setOpenAddBigType] = useState<boolean>(false)
// 显示 新增问题的抽屉
const [openAddQuestion, setOpenAddQuestion] = useState<boolean>(false)
// 拿到protable的问题分类
const [bigTypeList, setBigTypeList] = useState<any>()
const columns: any = [
{
@ -171,10 +179,10 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
setCurrentRow(record)
setShowPlaceModal(true)
}}></a>
<a onClick={() => {
{/* <a onClick={() => {
setCurrentRow(record)
handleShowDetail(true)
}}></a>
}}></a> */}
<Popconfirm
title={"确认删除?"}
onConfirm={async () => {
@ -196,25 +204,26 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
dataIndex: "id",
hideInTable: true,
valueType: 'treeSelect',
request: async () => {
const data = await handleGetExamineTypeTreeList()
console.log('data', data);
return data && data.length > 0 ? data.map(item => ({
title: item.name,
value: item.id,
children: item.children?.map((child: any) => ({
title: child.name,
value: child.id,
children: child.children || []
})) || []
})) : []
},
// request: async () => {
// const data = await handleGetExamineTypeTreeList()
// console.log('data', data);
// return data && data.length > 0 ? data.map(item => ({
// title: item.name,
// value: item.id,
// children: item.children?.map((child: any) => ({
// title: child.name,
// value: child.id,
// children: child.children || []
// })) || []
// })) : []
// },
fieldProps: {
multiple: false,
treeDefaultExpandAll: true,
showSearch: true,
treeNodeFilterProp: 'title',
placeholder: '请选择问题分类'
placeholder: '请选择问题分类',
options: bigTypeList
}
},
{
@ -252,6 +261,29 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
}
}
// 新增完类型之后的刷新
const handleReloadSearchList = async () => {
modalActionRef.current?.reload();
fetchTreeData()
}
const fetchTreeData = async () => {
const data = await handleGetExamineTypeTreeList();
const formattedData = data?.length ? data.map(item => ({
title: item.name,
value: item.id,
children: item.children?.map(child => ({
title: child.name,
value: child.id,
children: child.children || []
})) || []
})) : [];
setBigTypeList(formattedData);
};
useEffect(() => {
fetchTreeData()
}, [])
return (
<div style={{ backgroundColor: '#fff', display: 'flex' }}>
{/* <LeftSelectTree setSelectedId={setSelectedId} setCollapsible={setCollapsible} collapsible={collapsible} currentUser={currentUser} /> */}
@ -276,7 +308,6 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
search={{ span: 6 }}
request={async () => {
const req: any = {
}
const data = await handleGetTemplatesList()
if (data && data.length > 0) {
@ -654,6 +685,21 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
setSelectedQuestionId(selectedRowKeys)
}
}}
toolbar={{
actions: [
<Button type="primary" onClick={(e) => {
setOpenAddBigType(true)
}}>
</Button>,
<Button type="primary" onClick={(e) => {
setOpenAddQuestion(true)
}}>
</Button>
]
}}
/>
</Modal>
</div>
@ -671,6 +717,13 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
>
<RecordDetail parentRow={currentRow} show={showDetail} detailType={'modal'} />
</Drawer>
<AddBigType openAddModal={openAddBigType} setOpenAddModal={setOpenAddBigType} afterAdd={handleReloadSearchList} />
<AddQuestion showQuestionModal={openAddQuestion} setShowQuestionModal={setOpenAddQuestion} afterAdd={handleReloadSearchList} />
</div >
)
}

View File

@ -0,0 +1,246 @@
import { ConnectState } from "@/models/global";
import { FormInstance, ProForm, ProFormDigit, ProFormList, ProFormRadio, ProFormSwitch, ProFormText, ProFormTextArea, ProFormTreeSelect } from "@ant-design/pro-components";
import { useImperativeHandle, useRef, useState } from "react";
import { connect } from "umi";
import { Col, message, Modal, Row } from "antd";
import { handleGetExamineTypeList, handleGetExamineTypeTreeList } from "../../index/service";
import { handleAddQuestion, handleEditQuestion } from "../service";
type DetailProps = {
parentRow: any
onRef: any
currentUser?: any
showQuestionModal: boolean
setShowQuestionModal?: any
parentActionRef?: any
setCurrentRow?: any
afterAdd?: any
}
const addQuestion = ({ parentRow, onRef, currentUser, showQuestionModal, setShowQuestionModal, parentActionRef, setCurrentRow, afterAdd }: DetailProps) => {
// 弹出框的表单实例
const modalRef = useRef<FormInstance>()
const [categoryIdObj, setCategoryIdObj] = useState<any>()
useImperativeHandle(onRef, () => ({
modalRef,
categoryIdObj
}));
return (
<div>
<Modal
width={800}
title={`${parentRow?.id ? '编辑' : '创建'}问题`}
open={showQuestionModal}
destroyOnClose
onOk={() => {
modalRef.current?.validateFields().then(async (res) => {
let req = {}
let data = {}
if (parentRow?.id) {
req = {
...parentRow,
categoryId: res.categoryId,// 题目id
type: `${res.selectType === 1 ? 'radio' : 'checked'}_choice`,// 题目类型
title: res.title,// 问题内容
required: res.required,// 是否必填
options: res.options,
status: res.status,
operator: currentUser?.operator,
description: `${res.categoryId && categoryIdObj ? categoryIdObj[res.categoryId] : ''}`
}
data = await handleEditQuestion(req)
} else {
req = {
categoryId: res.categoryId,// 题目id
type: `${res.selectType === 1 ? 'radio' : 'checked'}_choice`,// 题目类型
title: res.title,// 问题内容
required: res.required,// 是否必填
options: res.options,
sortOrder: 1,
status: res.status,
operator: currentUser?.operator,
defaultScore: 0,
images: [],
description: `${res.categoryId && categoryIdObj ? categoryIdObj[res.categoryId] : ''}`
}
data = await handleAddQuestion(req)
}
console.log('datadsadsa', data);
if (data.code === 200) {
if (modalRef) {
modalRef.current?.resetFields()
}
message.success(data.message)
setShowQuestionModal(false)
if (parentActionRef) {
parentActionRef.current?.reload()
}
if (setCurrentRow) {
setCurrentRow(undefined)
}
if (afterAdd) {
afterAdd()
}
} else {
message.error(data.message)
}
})
}}
onCancel={() => {
if (modalRef) {
modalRef.current?.resetFields()
}
setShowQuestionModal(false)
if (setCurrentRow) {
setCurrentRow(undefined)
}
}}
>
<ProForm formRef={modalRef} submitter={false} request={() => {
console.log('currentRow', parentRow);
return {
...parentRow,
selectType: parentRow.type.split('_')[0] === 'checked' ? 2 : 1
}
}}>
<Row gutter={8}>
<Col span={12}>
<ProFormTreeSelect
label={"问题分类"}
name={"categoryId"}
rules={[
{ required: true, message: '请选择问题分类!' }
]}
request={async () => {
const req = {}
const data = await handleGetExamineTypeTreeList(req)
console.log('dsadas', data);
let res = [
{
name: '/',
id: 0,
children: data
}
]
let obj: any = {}
const labelList = await handleGetExamineTypeList()
if (labelList && labelList.length > 0) {
labelList.forEach((item) => {
obj[item.id] = item.name
})
}
setCategoryIdObj(obj)
return data
}}
fieldProps={{
treeDefaultExpandedKeys: [0],
fieldNames: {
label: "name",
value: "id"
},
showSearch: true,
filterTreeNode: (input, treeNode) => {
return (treeNode?.name ?? '').toLowerCase().indexOf(input.toLowerCase()) >= 0;
},
treeNodeFilterProp: 'name'
}}
/>
</Col>
<Col span={12}>
<ProFormText
label={"问题内容"}
name={"title"}
rules={[
{ required: true, message: '请输入问题!' }
]}
/>
</Col>
<Col span={6}>
<ProFormSwitch
label={"是否必填"}
name={"required"}
initialValue={parentRow?.id ? parentRow.required : true}
/>
</Col>
<Col span={6}>
<ProFormSwitch
label={"有效状态"}
name={"status"}
initialValue={parentRow?.id ? parentRow.status : true}
/>
</Col>
<Col span={6}>
<ProFormRadio.Group
label={"题目类型"}
name={"selectType"}
fieldProps={{
options: [{ label: "单选", value: 1 }, { label: "多选", value: 2 }],
}}
initialValue={1}
/>
</Col>
<Col span={24}>
<ProFormList
name="options"
label="选项内容"
initialValue={[]}
creatorButtonProps={{
position: 'bottom',
creatorButtonText: '添加选项'
}}
copyIconProps={false}
style={{ width: '100%' }}
itemContainerStyle={{ width: '100%' }}
itemRender={({ listDom, action }, { record, index }) => (
<div style={{ width: '100%', display: 'flex', alignItems: 'flex-start', marginBottom: '10px' }}>
<div style={{ flex: 1, width: '100%' }}>{listDom}</div>
<div style={{ marginLeft: '8px', marginTop: '30px' }}>{action}</div>
</div>
)}
>
<Row gutter={6} style={{ width: '100%', margin: 0 }}>
<Col span={16}>
<ProFormTextArea
name="text"
label="选项"
fieldProps={{
style: { width: '100%' }
}}
/>
</Col>
<Col span={8}>
<ProFormDigit
name="mark"
label="分值"
fieldProps={{
style: { width: '100%' },
defaultValue: 0
}}
/>
</Col>
</Row>
</ProFormList>
</Col>
</Row>
</ProForm>
</Modal>
</div>
)
}
export default connect(({ user }: ConnectState) => ({
currentUser: user.data
}))(addQuestion);

View File

@ -6,12 +6,15 @@ import { connect } from "umi";
import { handleAddQuestion, handleDeleteQuestion, handleEditQuestion, handleGetQuestionList } from "./service";
import { handleGetExamineTypeList, handleGetExamineTypeTreeList } from "../index/service";
import moment from "moment";
import AddQuestion from "./components/addQuestion";
const examineQuestion: React.FC<{ currentUser: any }> = (props) => {
const { currentUser } = props
const actionRef = useRef<ActionType>();
const formRef = useRef<FormInstance>();
const addQuestionRef = useRef<any>()
// 显示新增问题的悬浮框
const [showQuestionModal, setShowQuestionModal] = useState<boolean>(false)
// 当前点击选中的问题行
@ -27,6 +30,11 @@ const examineQuestion: React.FC<{ currentUser: any }> = (props) => {
const columns: any = [
{
title: "问题内容",
dataIndex: "title",
hideInTable: true,
},
{
title: <div style={{ textAlign: 'center' }}></div>,
dataIndex: "description",
@ -191,196 +199,14 @@ const examineQuestion: React.FC<{ currentUser: any }> = (props) => {
/>
</div>
<Modal
width={800}
title={`${currentRow?.id ? '编辑' : '创建'}问题`}
open={showQuestionModal}
destroyOnClose
onOk={() => {
modalRef.current?.validateFields().then(async (res) => {
let req = {}
let data = {}
if (currentRow?.id) {
req = {
...currentRow,
categoryId: res.categoryId,// 题目id
type: `${res.selectType === 1 ? 'radio' : 'checked'}_choice`,// 题目类型
title: res.title,// 问题内容
required: res.required,// 是否必填
options: res.options,
status: res.status,
operator: currentUser?.operator,
description: `${res.categoryId ? categoryIdObj[res.categoryId] : ''}`
}
data = await handleEditQuestion(req)
} else {
req = {
categoryId: res.categoryId,// 题目id
type: `${res.selectType === 1 ? 'radio' : 'checked'}_choice`,// 题目类型
title: res.title,// 问题内容
required: res.required,// 是否必填
options: res.options,
sortOrder: 1,
status: res.status,
operator: currentUser?.operator,
defaultScore: 0,
images: [],
description: `${res.categoryId ? categoryIdObj[res.categoryId] : ''}`
}
data = await handleAddQuestion(req)
}
console.log('datadsadsa', data);
if (data.code === 200) {
modalRef.current?.resetFields()
message.success(data.message)
setShowQuestionModal(false)
actionRef.current?.reload()
setCurrentRow(undefined)
} else {
message.error(data.message)
}
})
}}
onCancel={() => {
modalRef.current?.resetFields()
setShowQuestionModal(false)
setCurrentRow(undefined)
}}
>
<ProForm formRef={modalRef} submitter={false} request={() => {
console.log('currentRow', currentRow);
return {
...currentRow,
selectType: currentRow.type.split('_')[0] === 'checked' ? 2 : 1
}
}}>
<Row gutter={8}>
<Col span={12}>
<ProFormTreeSelect
label={"问题分类"}
name={"categoryId"}
rules={[
{ required: true, message: '请选择问题分类!' }
]}
request={async () => {
<AddQuestion onRef={addQuestionRef} parentRow={currentRow}
showQuestionModal={showQuestionModal}
setShowQuestionModal={setShowQuestionModal}
parentActionRef={actionRef}
setCurrentRow={setCurrentRow}
/>
const req = {}
const data = await handleGetExamineTypeTreeList(req)
console.log('dsadas', data);
let res = [
{
name: '/',
id: 0,
children: data
}
]
let obj: any = {}
const labelList = await handleGetExamineTypeList()
if (labelList && labelList.length > 0) {
labelList.forEach((item) => {
obj[item.id] = item.name
})
}
setCategoryIdObj(obj)
return res
}}
fieldProps={{
treeDefaultExpandedKeys: [0],
fieldNames: {
label: "name",
value: "id"
},
showSearch: true,
filterTreeNode: (input, treeNode) => {
return (treeNode?.name ?? '').toLowerCase().indexOf(input.toLowerCase()) >= 0;
},
treeNodeFilterProp: 'name'
}}
/>
</Col>
<Col span={12}>
<ProFormText
label={"问题内容"}
name={"title"}
rules={[
{ required: true, message: '请输入问题!' }
]}
/>
</Col>
<Col span={6}>
<ProFormSwitch
label={"是否必填"}
name={"required"}
initialValue={currentRow?.id ? currentRow.required : true}
/>
</Col>
<Col span={6}>
<ProFormSwitch
label={"有效状态"}
name={"status"}
initialValue={currentRow?.id ? currentRow.status : true}
/>
</Col>
<Col span={6}>
<ProFormRadio.Group
label={"题目类型"}
name={"selectType"}
fieldProps={{
options: [{ label: "单选", value: 1 }, { label: "多选", value: 2 }],
}}
initialValue={1}
/>
</Col>
<Col span={24}>
<ProFormList
name="options"
label="选项内容"
initialValue={[]}
creatorButtonProps={{
position: 'bottom',
creatorButtonText: '添加选项'
}}
copyIconProps={false}
style={{ width: '100%' }}
itemContainerStyle={{ width: '100%' }}
itemRender={({ listDom, action }, { record, index }) => (
<div style={{ width: '100%', display: 'flex', alignItems: 'flex-start', marginBottom: '10px' }}>
<div style={{ flex: 1, width: '100%' }}>{listDom}</div>
<div style={{ marginLeft: '8px', marginTop: '30px' }}>{action}</div>
</div>
)}
>
<Row gutter={6} style={{ width: '100%', margin: 0 }}>
<Col span={16}>
<ProFormTextArea
name="text"
label="选项"
fieldProps={{
style: { width: '100%' }
}}
/>
</Col>
<Col span={8}>
<ProFormDigit
name="mark"
label="分值"
fieldProps={{
style: { width: '100%' },
defaultValue: 0
}}
/>
</Col>
</Row>
</ProFormList>
</Col>
</Row>
</ProForm>
</Modal>
</div >
)
}

View File

@ -1,27 +1,36 @@
import { ConnectState } from "@/models/global";
import { ActionType, ProTable } from "@ant-design/pro-components";
import ProForm, { FormInstance, ProFormList, ProFormText } from "@ant-design/pro-form";
import ProForm, { FormInstance, ProFormList, ProFormSelect, ProFormText, ProFormTextArea, ProFormUploadButton } from "@ant-design/pro-form";
import { Col, Row, Image, Button, Input, Modal } from "antd";
import moment from "moment";
import { useEffect, useRef, useState } from "react";
import { useEffect, useImperativeHandle, useRef, useState } from "react";
import { connect } from "umi";
import { handleGetExamineTypeTreeList } from "../../index/service";
import session from "@/utils/session";
import { TextAreaRef } from "antd/lib/input/TextArea";
import './printStyle.css';
import { handleGetDealerList, handleUploadFile } from "../service";
type DetailProps = {
parentRow: any; // 父级数据
show: boolean;// 抽屉是否显示
detailType: string; // 详情的类型
currentUser: any
onRef?: any
showError: boolean;// 是不是处理异常
}
const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
const RecordDetail = ({ parentRow, show, detailType, currentUser, onRef, showError }: DetailProps) => {
const formRef = useRef<FormInstance>();
console.log('currentUser', currentUser);
const actionRef = useRef<ActionType>();
const tableFormRef = useRef<FormInstance>();
const errorStatusFormRef = useRef<FormInstance>();
const errorStatusFormReflast = useRef<FormInstance>();
// 表格数据
const [proTableData, setTableData] = useState<any>([])
@ -34,6 +43,10 @@ const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
const footerRef = useRef<TextAreaRef>(null)
// 考核分类的对象格式
const [examineObj, setExamineObj] = useState<any>()
// 文件列表
const [fileList, setFileList] = useState<any>()
// 选人的列表数据
const [selectPersonList, setSelectPersonList] = useState<any>()
const columns: any = [
{
@ -90,6 +103,8 @@ const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
placeName: parentRow.template?.title || '',
submittedAt: moment(parentRow?.submittedAt).format('YYYY-MM-DD HH:mm:ss')
}
console.log('formRes', obj);
setFormRes(obj)
formRef.current?.setFieldsValue(obj)
}
@ -334,11 +349,11 @@ const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
<div></div>
</div>
<div style="width:100%;display:flex;align-items: center;justify-content: space-between;">
<div></div>
<div>${parentRow?.title || '-'}</div>
<div>${formRes?.uploadResult || '-'}</div>
<div>${formRes?.placeName || '-'}</div>
</div>
<div style="width:100%;display:flex;align-items: center;justify-content: space-between;">
<div>${parentRow?.operator || '-'}</div>
<div>${parentRow?.userName || '-'}</div>
<div>${parentRow?.createdAt ? moment(parentRow?.createdAt).format('YYYY-MM-DD HH:mm:ss') : '-'}</div>
</div>
`
@ -366,42 +381,65 @@ const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
if (record._categoryMerged) {
// 如果已合并,不显示单元格
} else {
printContent += `<td ${record._categoryRowSpan && record._categoryRowSpan > 1 ? `rowspan="${record._categoryRowSpan}"` : ''}>${record.parentName || ''}</td>`;
printContent += `<td style="width: 100px" ${record._categoryRowSpan && record._categoryRowSpan > 1 ? `rowspan="${record._categoryRowSpan}"` : ''}>${record.parentName || ''}</td>`;
}
// 考核子类列 - 处理合并单元格
if (record._subCategoryMerged) {
// 如果已合并,不显示单元格
} else {
printContent += `<td ${record._subCategoryRowSpan && record._subCategoryRowSpan > 1 ? `rowspan="${record._subCategoryRowSpan}"` : ''}>${record.question?.title || ''}</td>`;
printContent += `<td style="width: 100px" ${record._subCategoryRowSpan && record._subCategoryRowSpan > 1 ? `rowspan="${record._subCategoryRowSpan}"` : ''}>${record.question?.title || ''}</td>`;
}
// 考核结果列
let resultStr = '';
if (record.choiceResponse && record.choiceResponse.length > 0) {
record.choiceResponse.forEach((item: any, index: number) => {
resultStr += `${index > 0 ? '' : ''}答案${index + 1}${item}`;
resultStr += `${index > 0 ? '' : ''}结果${index + 1}${item}`;
});
}
printContent += `<td>${resultStr || ''}</td>`;
printContent += `<td style="text-align:left">${resultStr || ''}</td>`;
printContent += '</tr>';
});
// if (parentRow?.situation !== 1) {
// 加一个页脚
// printContent += `
// <table>
// <tbody>
// <tr>
// <td>巡检人员</td>
// <td></td>
// <td>巡检时间</td>
// <td></td>
// </tr>
// </tbody>
// </table>
// `
printContent += `
<table>
<tbody>
${formRes.errorStatus >= 1 ? `<tr>
<td style="width: 100px"></td>
<td>${formRes.suggestPerson.STAFF_NAME || '-'}</td>
<td style="width: 100px"></td>
<td>${formRes.suggestTime || '-'}</td>
</tr>
<tr>
<td style="width: 100px"></td>
<td colspan="3">${formRes.suggestion || '-'}</td>
</tr>`: ""
}
${formRes.errorStatus === 2 ? `
<tr>
<td style="width: 100px"></td>
<td>${formRes.person.STAFF_NAME || '-'}</td>
<td style="width: 100px"></td>
<td>${formRes.feedbackTime || '-'}</td>
</tr>
<tr>
<td style="width: 100px"></td>
<td colspan="3">${formRes.feedbackContent || '-'}</td>
</tr>
`:
""
}
</tbody>
</table>
`
// }
@ -442,6 +480,14 @@ const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
}
};
useImperativeHandle(onRef, () => ({
errorStatusFormRef,
errorStatusFormReflast,
formRes,
selectPersonList,
fileList
}));
return (
<div>
<ProForm
@ -520,6 +566,143 @@ const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
</Row>
</ProForm>
{
showError && formRes && formRes.errorStatus >= 0 ?
<ProForm
formRef={errorStatusFormRef}
submitter={false}
layout={'horizontal'}
request={() => {
console.log('formRes', formRes);
return {
...formRes,
personIndex: formRes.person.STAFF_ID
}
}}
>
<Row gutter={8}>
<Col span={8}>
<ProFormSelect
label={"异常处理人"}
name={"personIndex"}
request={async () => {
const req = {
SERVERPART_ID: formRes.serverPartId,
PROVINCE_CODE: currentUser.provinceCode,
}
const data = await handleGetDealerList(req)
console.log('data', data)
let res = data.Data.List
setSelectPersonList(res)
return res
}}
rules={[
{ required: true, message: "请选择处理人" }
]}
fieldProps={{
fieldNames: {
"label": "STAFF_NAME",
"value": "STAFF_ID"
}
}}
disabled={formRes.errorStatus > 0}
/>
</Col>
<Col span={8}>
<ProFormTextArea
label={"整改意见"}
name={"suggestion"}
rules={[
{ required: true, message: "请输入整改意见" }
]}
disabled={formRes.errorStatus > 0}
/>
</Col>
</Row>
</ProForm> : ""
}
{
showError && formRes && formRes.errorStatus >= 1 ?
<ProForm
formRef={errorStatusFormReflast}
submitter={false}
layout={'horizontal'}
request={() => {
console.log('formRes', formRes);
let list: any = []
if (formRes.feedbackImgList && formRes.feedbackImgList.length > 0) {
formRes.feedbackImgList.forEach((item: string, index: number) => {
list.push({
uid: '',
name: `image${index}.png`,
status: 'done',
url: item,
})
})
}
setFileList(list)
return {
...formRes,
}
}}
>
<Row gutter={8}>
<Col span={8}>
<ProFormUploadButton
label={"反馈图片"}
listType="picture-card"
name={"feedbackImgList"}
fileList={fileList}
rules={[{
required: true,
message: "请上传反馈图片"
}]}
disabled={formRes.errorStatus > 1}
fieldProps={{
customRequest: async (info: any) => {
console.log('info', info);
const formData = new FormData();
formData.append('file', info.file, typeof info.file !== 'string' ? info.file?.name : '');
const data = await handleUploadFile(formData)
console.log('data', data);
let url = `https://es.robot-z.cn/${data.data.path}`
let file = JSON.parse(JSON.stringify(fileList))
file.push({
uid: '',
name: `${data.data.filename}.png`,
status: 'done',
url: url,
})
setFileList(file)
},
onChange: (info: any) => {
if (info.file.status === 'removed') {
console.log('info', info);
setFileList(info.fileList)
}
}
}}
/>
</Col>
<Col span={8}>
<ProFormTextArea
label={"反馈内容"}
name={"feedbackContent"}
rules={[
{ required: true, message: "请输入反馈内容" }
]}
disabled={formRes.errorStatus > 1}
/>
</Col>
</Row>
</ProForm> : ""
}
<ProTable
actionRef={actionRef}
formRef={tableFormRef}
@ -629,7 +812,7 @@ const RecordDetail = ({ parentRow, show, detailType }: DetailProps) => {
{/* 移除打印设置弹窗 */}
</div>
</div >
)
}

View File

@ -2,7 +2,7 @@ import { ConnectState } from "@/models/global";
import { ActionType, FormInstance, ProTable } from "@ant-design/pro-components";
import { useRef, useState } from "react";
import { connect } from "umi";
import { handleDeleteRecord, handleGetRecordList } from "./service";
import { handleDeleteRecord, handleGetRecordList, handleUpdateExtend } from "./service";
import moment from "moment";
import { Button, Drawer, Image, message, Popconfirm, Space } from "antd";
import { handleGetServerpartDDL } from "@/components/leftSelectTree/service";
@ -13,6 +13,7 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
const actionRef = useRef<ActionType>();
const formRef = useRef<FormInstance>();
const recordDetailRef = useRef<any>()
// 显示的附件数据
const [showImgList, setShowImgList] = useState<string[]>([])
// 预览图片
@ -23,6 +24,8 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
const [currentRow, setCurrentRow] = useState<any>()
// 显示详情抽屉
const [showDetail, setShowDetail] = useState<boolean>(false)
// 判断是否点了出现的是异常处理的抽屉
const [showAbnormal, setShowAbnormal] = useState<boolean>(false)
const columns: any = [
{
@ -58,6 +61,17 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
return data
}
},
{
title: "巡查类型",
dataIndex: "inspectionType",
hideInTable: true,
valueType: "select",
valueEnum: {
"1": '异常',
"0": "正常"
}
},
{
title: <div style={{ textAlign: 'center' }}></div>,
dataIndex: "serverPartName",
@ -78,6 +92,18 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
return record?.template.title ? record?.template.title : "-"
}
},
{
title: <div style={{ textAlign: 'center' }}></div>,
dataIndex: "placeName",
hideInSearch: true,
width: 100,
align: 'center',
ellipsis: true,
render: (_, record) => {
let res: any = record.extend ? JSON.parse(record.extend) : "-"
return <span style={{ color: res.situation === 1 ? "red" : "" }}>{res.situation === 1 ? '异常' : res.situation === 0 ? '正常' : ''}</span>
}
},
{
title: <div style={{ textAlign: 'center' }}></div>,
dataIndex: "uploadResult",
@ -130,6 +156,26 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
ellipsis: true,
align: 'center',
},
{
title: <div style={{ textAlign: 'center' }}></div>,
dataIndex: "errorStatus",
hideInSearch: true,
width: 100,
ellipsis: true,
align: 'center',
render: (_, record) => {
let res: any = record.extend ? JSON.parse(record.extend) : "-"
return <span style={{ color: res.errorStatus === 0 ? "red" : res.errorStatus === 1 ? "#1677ff" : "" }}>{
res.errorStatus === 0
? "待处理"
: res.errorStatus === 1
? "处理中"
: res.errorStatus === 2
? "已处理"
: "-"
}</span>
}
},
{
title: <div style={{ textAlign: 'center' }}></div>,
dataIndex: "placeName",
@ -153,15 +199,33 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
align: 'center',
fixed: "right",
hideInSearch: true,
width: 100,
width: 150,
render: (_: any, record: any) => {
let res: any = record.extend ? JSON.parse(record.extend) : "-"
return <Space>
<a onClick={() => {
setCurrentRow(record)
{
res.situation === 1 ?
<a onClick={
() => {
setCurrentRow({
...record,
...res
})
setShowAbnormal(true)
setShowDetail(true)
}
}></a> : ""
}
< a onClick={() => {
setCurrentRow({
...record,
...res
})
setShowDetail(true)
}}>
</a>
</a >
<Popconfirm
title={"确认删除?"}
onConfirm={async () => {
@ -171,7 +235,7 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
<a></a>
</Popconfirm>
</Space>
</Space >
}
}
]
@ -211,7 +275,12 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
const req: any = {
startTime: params?.startTime ? `${params?.startTime}T00:00:00` : "",
endTime: params?.endTime ? `${params?.endTime}T23:59:59` : "",
serverPartId: params?.serverPartId ? params?.serverPartId : ""
serverPartId: params?.serverPartId ? params?.serverPartId : undefined,
extend: params?.inspectionType ? [{
key: "situation",
value: params?.inspectionType
}] : undefined
}
console.log('req', req);
const data = await handleGetRecordList(req)
@ -258,12 +327,92 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
closeIcon={false}
onClose={() => {
setShowDetail(false)
setShowAbnormal(false)
}}
open={showDetail}
destroyOnClose
width={'60%'}
footer={showAbnormal && currentRow?.errorStatus !== 2 ? <div style={{ width: "100%", boxSizing: 'border-box', padding: "0 24px", display: 'flex', justifyContent: 'flex-end' }}>
<Button type="primary" onClick={() => {
if (recordDetailRef.current?.formRes.errorStatus === 0) {
recordDetailRef.current?.errorStatusFormRef.current?.validateFields().then(async (res: any) => {
console.log('res', res);
let extendObj = JSON.parse(recordDetailRef.current?.formRes.extend)
let personObj: any = {}
let personList: any = recordDetailRef.current?.selectPersonList
if (personList && personList.length > 0) {
personList.forEach((item: any) => {
if (item.STAFF_ID === res.personIndex) {
personObj = item
}
})
}
const req = {
...extendObj,
person: personObj,
errorStatus: 1,
suggestion: res.suggestion,
suggestTime: moment().format('YYYY-MM-DD'), // 选处理人的时间
suggestPerson: {
STAFF_NAME: currentUser.adminName,
STAFF_ID: currentUser.id,
MEMBERSHIP_NAME: currentUser.adminName,
MEMBERSHIP_ID: currentUser.id,
},
};
const data = await handleUpdateExtend(recordDetailRef.current?.formRes.id, { extend: JSON.stringify(req) })
if (data.code === 200) {
message.success('提交成功')
setShowDetail(false)
setShowAbnormal(false)
actionRef.current?.reload()
setCurrentRow(undefined)
} else {
message.error(data.message)
}
})
}
if (recordDetailRef.current?.formRes.errorStatus === 1) {
recordDetailRef.current?.errorStatusFormReflast.current?.validateFields().then(async (res: any) => {
console.log('res', res);
let extendObj = JSON.parse(recordDetailRef.current?.formRes.extend)
let fileList: any = []
if (recordDetailRef.current?.fileList && recordDetailRef.current?.fileList.length > 0) {
recordDetailRef.current?.fileList.forEach((item: any) => {
fileList.push(item.url)
})
}
const req = {
...extendObj,
feedbackImgList: fileList,
feedbackContent: res.feedbackContent,
feedbackTime: moment().format('YYYY-MM-DD HH:mm:ss'), // 反馈时间
errorStatus: 2,
};
const data = await handleUpdateExtend(recordDetailRef.current?.formRes.id, { extend: JSON.stringify(req) })
if (data.code === 200) {
message.success('提交成功')
setShowDetail(false)
setShowAbnormal(false)
actionRef.current?.reload()
setCurrentRow(undefined)
} else {
message.error(data.message)
}
})
}
}}></Button>
</div> : false}
>
<RecordDetail parentRow={currentRow} show={showDetail} />
<RecordDetail onRef={recordDetailRef} parentRow={currentRow} show={showDetail} showError={showAbnormal} />
</Drawer>
</div>
)

View File

@ -1,8 +1,9 @@
import request from "@/utils/request"
import requestMap from '@/utils/requestMap'
// 拿到记录
export async function handleGetRecordList(params?: any) {
const data = await request.post('/questionnaire-templates/search/many', params)
const data = await request.post('/questionnaire-responses/search/many', params)
if (data.code === 200) {
return data.data
}
@ -17,5 +18,23 @@ export async function handleDeleteRecord(params?: any) {
}
// 拿到处理人列表
export async function handleGetDealerList(params?: any) {
const data = await requestMap.get(`handler_ajax.ashx?SERVERPART_ID=${params?.SERVERPART_ID}&PROVINCE_CODE=${params?.PROVINCE_CODE}&action_type=GetDealerList`)
return data
}
// 删除记录
export async function handleUpdateExtend(id: any, params?: any) {
const data = await request.post(`questionnaire-responses/${id}/extend`, params)
return data
}
// 上传图片
export async function handleUploadFile(params?: any) {
const data = await request.post(`/oss/upload`, params)
return data
}

158
src/utils/requestMap.ts Normal file
View File

@ -0,0 +1,158 @@
import axios from 'axios';
import { getDvaApp } from 'umi';
import { notification } from 'antd';
import type { AxiosRequestHeaders } from 'axios/index';
import CryptoJS from "crypto-js";
const { UMI_APP_BASEURL } = process.env;
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
// 修改baseURL为完整的API地址确保在生产环境中正确访问
const instance = axios.create({ baseURL: 'https://mp.eshangtech.com/Coop.Merchant/Handler/' });
instance.interceptors.request.use(
(config) => {
// 对data数据进行加密
// if (config.data) {
// config.data = preprocessData(JSON.stringify(config.data)); // 调用预处理函数
// }
console.log('config', config);
const isUpload = config.url?.includes("/oss/upload");
config.headers = {
...config.headers,
Authorization: `Bearer ${localStorage.getItem('Authorization') || ''}`,
"Content-Type": "text/plain; charset=utf-8",
} as AxiosRequestHeaders;
return config;
},
(error) => Promise.reject(error),
);
instance.interceptors.response.use(
//状态码为2xx的时候执行
(response) => {
const { data } = response;
if (data.code !== 200) {
// notification.error({
// message: data.message,
// });
}
const timestamp = getFormattedDate()
return data
},
//状态码不是2xx的时候执行
(error) => {
const { response } = error;
if (response && response.status === 401) {
// // 清除本地存储的token
// localStorage.removeItem('Authorization');
// // 重定向到登录页
// window.location.href = '/user/login';
// notification.error({
// message: response?.data?.message || '请求失败',
// description: error.message
// });
} else {
// notification.error({
// message: response?.data?.message || '请求失败',
// description: error.message
// });
}
return Promise.reject({
code: response?.status || 500,
message: response?.data?.message || '请求失败'
});
},
);
// 加密
const encryptAESECB = (data: string, key: string) => {
// const cipher = CryptoJS.createCipheriv('aes-128-ecb', key, null); // ECB 模式不需要 IV
const newKey = CryptoJS.enc.Utf8.parse(key); // 密钥必须是 16 字节
const cipher = CryptoJS.AES.encrypt(data, newKey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
let encrypted = cipher.ciphertext.toString(CryptoJS.enc.Hex);
// let encrypted = cipher.update(data, 'utf8', 'hex');
// encrypted += cipher.final('hex');
return encrypted;
}
// 解密
const decryptAESECB = (data: string, key: string) => {
// const decipher = CryptoJS.createDecipheriv('aes-128-ecb', key, null);
// let decrypted = decipher.update(data, 'hex', 'utf8');
// decrypted += decipher.final('utf8');
const newKey = CryptoJS.enc.Utf8.parse(key);
const encryptedData = CryptoJS.enc.Hex.parse(data);
// 解密操作
const decrypted = CryptoJS.AES.decrypt({ ciphertext: encryptedData }, newKey, {
mode: CryptoJS.mode.ECB, // ECB 模式
padding: CryptoJS.pad.Pkcs7 // PKCS7 填充方式
});
// 将解密后的结果转为 UTF-8 字符串
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
return decryptedText;
}
// md5 签名
const md5 = (key: string, data: string, timestamp: string) => {
const text = "s" + key + data + timestamp;
return CryptoJS.MD5(text).toString(CryptoJS.enc.Hex);
}
// 生成签名戳
const getFormattedDate = () => {
const date = new Date();
const year = date.getFullYear(); // 获取年份 (yyyy)
const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份 (MM)
const day = String(date.getDate()).padStart(2, '0'); // 获取日期 (dd)
const hours = String(date.getHours()).padStart(2, '0'); // 获取小时 (HH)
return `es0${year}${month}${day}${hours}0es`; // 拼接成 yyyyMMddHH 格式
}
// 加密方法
const preprocessData = (data: string) => {
console.log('data', data);
// YYYYMMDD
let timestamp = getFormattedDate()
console.log('timestamp', timestamp);
// 秒为单位的时间戳
let timeSecond = parseInt((new Date().getTime() / 1000).toString())
console.log('timeSecond', timeSecond);
// 数据的加密
let encryptionData = encryptAESECB(data, timestamp)
console.log('encryptionData', encryptionData);
// md5签名方法
let md5Data = md5(timestamp, encryptionData, timestamp)
console.log('md5Data', md5Data);
let res = {
data: encryptionData,
timestamp: timeSecond,
sign: md5Data
}
console.log('res', res);
return res
}
export default instance;