Closed wqp9204 closed 4 months ago
提问前先看看:
https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md
protable colums 动态渲染问题
通过其他页面跳转过来的在路径上写了表的id,然后想在页面protable渲染后 获取表在数据库定义的名称和类型, 动态渲染下列明下,现在的问题是,我跳转到当前页面没有变化,我点了查询他把列明渲染出来。这个怎么改 现在碰到奇怪现象 我跳转过来他没有渲染出来,但是我页面刷新他就能够渲染出来。 而且查询条件也无法渲染
import React, {useEffect, useMemo, useRef, useState} from "react"; import {ActionType, PageContainer, ProColumns, ProTable} from "@ant-design/pro-components"; import {FormattedMessage, useIntl} from "@umijs/max"; import {Button} from "antd"; import {PlusOutlined} from "@ant-design/icons"; import {ResponseCode} from "@/models/Response"; import DangerConfirmModal from "@/components/DangerConfirmModal"; import MdmInstanceModalForm, {MdmInstanceModel} from "@/pages/mdmInstance/components/MdmInstanceModalForm"; import {Access, useAccess} from "@@/plugin-access"; import {deleteInstance, instanceTable} from "@/services/ExtMdmService"; import {history, useSearchParams} from "@@/exports"; import {MdmMainColumnsModel} from "@/pages/mdmMainColumns/components/MdmMainColumnsModalForm"; import {searchMdmMainColumnsList} from "@/services/BaseMdmMainColumnsService"; import {MdmMainColumnsSearchIModel} from "@/models/in/MdmMainColumnsSearchIModel"; const MdmInstance: React.FC = () => { const intl = useIntl(); const access = useAccess(); const [searchParams, setSearchParams] = useSearchParams(); /** * 新增弹框页面 控制状态 */ const [addModalVisible, setAddModalVisible] = useState<boolean>(false); /** * 修改弹框页面 控制状态 */ const [modifyModalVisible, setModifyModalVisible] = useState<boolean>(false); /** * proTable 选中的行的数据 */ const [selectRow, setSelectRow] = useState<MdmInstanceModel>(); /** * proTable 批量选择 选中的行的key列的值 */ const [selectRowKeys, setSelectRowKeys] = useState<[]>([]); /** * proTable的ref */ const actionRef = useRef<ActionType>(); /** * 列表字段内容 */ const tableColumns: ProColumns[] = [ { title: <FormattedMessage id="col.dataId" />, dataIndex: 'dataId', valueType: 'text', ellipsis: true, hideInSearch: true, }, { title: <FormattedMessage id="title.operate" />, valueType: 'option', render: (_, row) => [ <a key="modify" onClick={() => { setSelectRow(row) setModifyModalVisible(true) }}> <FormattedMessage id={access.canMdmInstancePageModify ? "button.modify" : "button.info"} /> </a>, <Access accessible={access.canMdmInstancePageAdd} key="copy"> <a type="text" onClick={() => { const newRow: MdmInstanceModel = {...row} newRow.instanceId = undefined setSelectRow(newRow) setAddModalVisible(true) }} > <FormattedMessage id="button.copy" /> </a> </Access>, <Access accessible={access.canMdmInstancePageModify && !row.instanceFlag} key="copy"> <a key={"instance"} type="text" onClick={() => { instanceTable(row.instanceId).then(res => { if (res.code === ResponseCode.OK) { actionRef.current?.reloadAndRest?.(); return true; } else { return false; } }) }} > <FormattedMessage id="button.instance" /> </a> </Access>, <Access accessible={row.instanceFlag === true} key="copy"> <a key={"instanceData"} type="text" onClick={() => { }} > <FormattedMessage id="button.instanceData" /> </a> </Access>, ] }] const [columns, setColumns] = useState(tableColumns); useEffect(() => { let instanceId = searchParams.get('instanceId'); let mainId = searchParams.get('mainId'); if (instanceId !== null && mainId !== null) { let search: MdmMainColumnsSearchIModel = new MdmMainColumnsSearchIModel(); search.mainId = Number.parseInt(mainId) search.order = "+seq" searchMdmMainColumnsList(search).then(res => { let i = 1; for (let one of res) { tableColumns.splice(i, 0, { title: one.columnName, dataIndex: one.columnId, valueType: 'text', ellipsis: true, }, ) i += 1; } setColumns(tableColumns); }) } else { //跳回实例夜 history.push('/mdmInstance'); } }, []); return ( <> {/*新增*/} <MdmInstanceModalForm accessible={access.canMdmInstancePageAdd} onCancel={(value) => { if (!value) { setAddModalVisible(false) } }} onSubmit={async (values) => { // return await addOneMdmInstance(values).then(res => { // if (res.code === ResponseCode.OK) { // actionRef.current?.reloadAndRest?.(); // return true; // } else { // return false; // } // }) return false }} modalVisible={addModalVisible} values={selectRow || {}} /> {/*修改*/} <MdmInstanceModalForm accessible={access.canMdmInstancePageModify} onCancel={(value) => { if (!value) { setModifyModalVisible(false) } }} onSubmit={async (values) => { // return await modifyOneMdmInstanceWithNull(values).then(res => { // if (res.code === ResponseCode.OK) { // actionRef.current?.reloadAndRest?.(); // return true; // } else { // return false; // } // }) return false }} modalVisible={modifyModalVisible} values={selectRow || {}} /> {/*列表*/} <PageContainer> <ProTable headerTitle={intl.formatMessage({ id: 'title.table' })} search={{labelWidth: "auto"}} scroll={{x: 'max-content'}} pagination={{showQuickJumper: true}} //配置列名和查询条件 columns={columns} //配置返回参数的接口方法 request={async (params = {}, sort) => { // let search: MdmInstanceSearchIModel = new MdmInstanceSearchIModel(); // copy(search, params) // setSearchOrder(search, sort) // return searchMdmInstancePage(search) return [] }} //加新增按钮 toolBarRender={() => [ <Access accessible={access.canMdmInstancePageAdd} key={"add"}> <Button type="primary" onClick={() => { setSelectRow({}) setAddModalVisible(true) }} > <PlusOutlined/> <FormattedMessage id="button.add"/> </Button> </Access>, <DangerConfirmModal key={"batchDelete"} buttonType={"button"} buttonI18nCode={"button.batchDelete"} accessible={access.canMdmInstancePageDelete && selectRowKeys.length > 0} onSubmit={() => { deleteInstance(selectRowKeys).then(res => { if (ResponseCode.OK === res.code) { actionRef.current?.reloadAndRest?.(); } }) }} values={{contentValue: {name: intl.formatMessage({id: "button.batchDelete"})}}}/>, <DangerConfirmModal key={"disable"} buttonType={"button"} buttonI18nCode={"button.disable"} accessible={access.canMdmInstancePageModify && selectRowKeys.length > 0} onSubmit={() => { // modifyListMdmInstanceIgnoreNull({instanceIdList: selectRowKeys, disabled: true}).then(res => { // if (ResponseCode.OK === res.code) { // actionRef.current?.reloadAndRest?.(); // } // }) }} values={{contentValue: {name: intl.formatMessage({id: "button.disable"})}}}/>, <DangerConfirmModal key={"enable"} buttonType={"button"} buttonI18nCode={"button.enable"} accessible={access.canMdmInstancePageModify && selectRowKeys.length > 0} onSubmit={() => { // modifyListMdmInstanceIgnoreNull({instanceIdList: selectRowKeys, disabled: false}).then(res => { // if (ResponseCode.OK === res.code) { // actionRef.current?.reloadAndRest?.(); // } // }) }} values={{contentValue: {name: intl.formatMessage({id: "button.enable"})}}}/> ]} //批量选择的时候 主键字段名称 rowKey={"dataId"} rowSelection={{ onChange: (keys) => { // @ts-ignore setSelectRowKeys(keys) }, }} //column的ref actionRef={actionRef} /> </PageContainer> </> ) } export default MdmInstance;
当前 Issue 未检测到标题,请规范填写,谢谢!
The title of the current issue is not detected, please fill in according to the specifications, thank you!
请大师指点一二。
提问前先看看:
https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md
protable colums 动态渲染问题
通过其他页面跳转过来的在路径上写了表的id,然后想在页面protable渲染后 获取表在数据库定义的名称和类型, 动态渲染下列明下,现在的问题是,我跳转到当前页面没有变化,我点了查询他把列明渲染出来。这个怎么改 现在碰到奇怪现象 我跳转过来他没有渲染出来,但是我页面刷新他就能够渲染出来。 而且查询条件也无法渲染
💻 示例代码
🚑 其他信息