import React, { useEffect, useRef, useState } from 'react'; import PageContainer from '@/components/PageContainer'; import ProCard from '@/components/ProCard'; import ContentCard from '@/components/ContentCard'; import { ActionType, EditableProTable, ProColumns } from '@ant-design/pro-table'; import ProForm, { ProFormInstance } from '@ant-design/pro-form'; import { isNumber } from 'lodash'; import { Button, Popconfirm, Space, message } from 'antd'; import { getOnlyKey } from '@/utils/utils'; import UserLog from '@/components/UserLog'; import { getProjectComplexity } from '@/services/configManage'; const ProjectComplexity: React.FC = () => { const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]); const actionRef = useRef(); const formRef = useRef();

const fetchList = async () => { const res = await getProjectComplexity({}); console.log(res, 10); if (res.code !== 'BIZ_SUCCESS') return message.error(res.msg); formRef.current?.setFieldsValue({ dataSource: res?.data.map((item: any) => ({ key: getOnlyKey(), ...item })), }); };

useEffect(() => { fetchList(); // const data = [ // { // id: '1', // complexity: 'S', // remark: '基础机新机芯项目', // productType: '智屏', // }, // { // id: '2', // complexity: 'A', // remark: // '1.版本火车;2.基础新机芯片首发区域释放后引入其他区域(如Global释放后北美或者日本上市该机芯);3.Android大版本升级;4.超米信', // productType: '智屏', // }, // { // id: '3', // complexity: 'B', // remark: '基础机新机芯项目', // productType: '智屏', // }, // { // id: '4', // complexity: 'C', // remark: '基础机新机芯项目', // productType: '智屏', // }, // { // id: '5', // complexity: 'D', // remark: '基础机新机芯项目', // productType: '智屏', // }, // ]; // formRef.current?.setFieldsValue({ // dataSource: data.map((item: any) => ({ key: getOnlyKey(), ...item })), // }); }, []);

const columns: ProColumns[] = [ { title: '序号', width: 50, valueType: 'index', align: 'center', renderFormItem: ({ index }) => isNumber(index) && <>{index + 1}</>, }, { title: '复杂度', dataIndex: 'complexity', align: 'center', width: 100, }, { title: '备注', dataIndex: 'comment', align: 'center', valueType: 'textarea', width: 300, }, { title: '产品大类', dataIndex: 'productTopCategory', align: 'center', width: 100, }, { title: '操作', valueType: 'option', width: 120, align: 'center', render: (text, record, , action) => [ <a key="editable" onClick={() => { action?.startEditable?.(record.key); }} > 编辑 , <Popconfirm title="确定删除此行?" key="delete" // onConfirm={async () => { // try { // const { code, msg } = await deleteRoleConfigList({ // id: record.id, // }); // if (code !== 100000) throw new Error(msg); // message.success('删除成功!'); // fetchList(); // } catch (error) {} // }} okText="确定" cancelText="取消" > 删除 , ], }, ]; return ( <ProForm.Item name="dataSource" trigger="onValuesChange" style={{ margin: '0' }}> <EditableProTable rowKey="key" options={false} actionRef={actionRef} cardProps={{ bodyStyle: { padding: 0, }, }} scroll={{ y: 400 }} columns={columns} recordCreatorProps={false} bordered editable={{ type: 'multiple', editableKeys, // onSave: async (, row) => { // const result = { ...row, type: '0' }; // try { // const { code, msg } = row.id // ? await updateRoleConfigList(result) // : await addRoleConfigList(result); // if (code !== 100000) throw new Error(msg); // message.success('保存成功!'); // } catch (error) {} // fetchList();

              // },
              onChange: setEditableRowKeys,
              actionRender: (row, config, defaultDoms) => {
                return [defaultDoms.save, defaultDoms.cancel];
              },
            }}
          />
        </ProForm.Item>
      </ProForm>
      <Space>
        <Button
          type="primary"
          style={{ marginTop: '10px' }}
          onClick={() => {
            actionRef.current?.addEditRecord?.({
              key: getOnlyKey(),
            });
          }}
        >
          新增角色
        </Button>
      </Space>
    </ContentCard>
    <UserLog businessType={'ROLE'} />
  </ProCard>
</PageContainer>

); }; export default ProjectComplexity; 接口调成功之后,会出现一个提示BIZ_SUCCESS,怎么解决内容:根据给出的代码,可以看出接口调用成功后会出现一个提示消息,可以通过以下步骤解决这个问题:

  1. 找到代码中显示提示消息的地方,看看是否有办法控制是否显示该消息。可能是在调用接口成功后直接调用了message.success方法显示消息,可以将其注释掉或者添加条件判断来控制是否显示消息。

  2. 如果无法直接控制是否显示消息,可以尝试在调用接口的地方捕获异常,并在异常处理中阻止消息的显示。例如,在fetchList方法中添加异常捕获,并在异常处理中返回错误信息而不是显示消息。

  3. 另外,如果有必要,还可以查看接口调用的返回数据,看看是否存在其他字段来表示接口调用的结果,例如res.successres.status等,可以根据这些字段来判断接口调用是否成功,并决定是否显示消息。

请根据具体情况尝试上述方法,如果仍然存在问题,请提供更多相关的代码和错误信息以便更详细地帮助解决问题。

项目复杂度管理 - 前端代码示例

原文地址: https://www.cveoy.top/t/topic/qakp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录