123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /*
- * @Author: code4eat awesomedema@gmail.com
- * @Date: 2023-03-03 11:30:33
- * @LastEditors: code4eat awesomedema@gmail.com
- * @LastEditTime: 2024-08-16 10:02:03
- * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- import { createFromIconfontCN } from '@ant-design/icons';
- import { ActionType } from '@ant-design/pro-components';
- import { ModalForm, ProFormDatePicker, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
- import { ProColumns } from '@ant-design/pro-table';
- import { Input, message, Popconfirm, DatePicker } from 'antd';
- import { useEffect, useRef, useState } from 'react'
- import { afterImport, getData, getSpecialImportTable, tableDataImport } from './service';
- import FormItem from 'antd/es/form/FormItem';
- import './style.less';
- import '../../utils/zhongtaiA'
- import moment from 'moment';
- import 'moment/locale/zh-cn';
- import locale from 'antd/es/date-picker/locale/zh_CN';
- import { getComputeDate } from '@/pages/Home/service';
- import KCIMUpload from '@/components/KCIMUpload';
- import KCIMPagecontainer from '@/components/KCIMPageContainer';
- import { KCIMTable } from '@/components/KCIMTable';
- import { useModel } from '@umijs/max';
- const IconFont = createFromIconfontCN({
- scriptUrl: '',
- });
- const currentDate = `${new Date().getFullYear()}-${(new Date().getMonth() + 1).toString().padStart(2, '0')}`;
- export default function DicClassfication() {
- const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
- const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
- const { initialState, setInitialState } = useModel('@@initialState');
- const [currentComputeDate, set_currentComputeDate] = useState<string | undefined>(initialState ? initialState.computeDate : undefined);
- const tableRef = useRef<ActionType>();
- const columns: ProColumns[] = [
- {
- title: '所属年月',
- dataIndex: 'computeDate',
- ellipsis: true
- },
- {
- title: '数据库表名称',
- dataIndex: 'tableNameDisplay',
- ellipsis: true
- },
- {
- title: '文件名称',
- dataIndex: 'fileName',
- ellipsis: true,
- renderText(text, record, index, action) {
- return <a href={record.url} target='_blank'>{record.fileName}</a>
- },
- },
- {
- title: '导入时间',
- dataIndex: 'createTime',
- ellipsis: true
- },
- {
- title: '导入人员',
- dataIndex: 'createUserName',
- ellipsis: true
- },
- {
- title: '操作',
- key: 'option',
- width: 120,
- valueType: 'option',
- render: (_: any, record: any) => {
- return [
- <Popconfirm
- title={`是否${record.importStatus == 1 ? '复原导入' : '撤销导入'}?`}
- key="del"
- onConfirm={() => afterImportHandle(record)}
- >
- <a>{record.importStatus == 1 ? '复原导入' : '撤销导入'}</a>
- </Popconfirm>
- ]
- },
- },
- ];
- const afterImportHandle = async (record: any) => {
- const { importStatus } = record;
- const resp = await afterImport(record.id, importStatus ? 'RECOVERY' : 'CANCEL');
- if (resp) {
- message.success('操作成功!');
- tableRef.current?.reload();
- }
- }
- const getTableData = async (params: any) => {
- const { computeDate } = params;
- const resp = await getData({ ...params, computeDate: computeDate ? computeDate : currentComputeDate });
- if (resp) {
- return {
- data: resp.list,
- success: true,
- total: resp.totalCount,
- pageSize: resp.pageSize,
- totalPage: resp.totalPage,
- }
- }
- return []
- }
- const importData = () => {
- function downloadTemplate(): void {
- }
- return (
- <ModalForm
- className='SpecialDataImport-Modal'
- width={360}
- title={`导入数据`}
- trigger={
- <span key="3" className='importBtn'>导入</span>
- }
- submitter={{
- render: (props, defaultDoms) => {
- const needBtn = defaultDoms.filter((b) => {
- return b.key != 'rest'
- })
- return [
- ...needBtn,
- ];
- },
- }}
- onFinish={async (values) => {
- // console.log({values});
- const { importFile: { fileList } } = values;
- let formData = new FormData();
- formData.append('file', fileList[0].originFileObj);
- formData.append('computeDate', values.computeDate);
- formData.append('tableName', values.tableName);
- const resp = await tableDataImport(formData);
- if (resp) {
- tableRef.current?.reload();
- return true;
- }
- }}
- >
- <div className='tip'>本操作为追加导入,会保留已有的数据并将文件的所有记录追加到数据表</div>
- <ProFormDatePicker.Month label='所属年月' name='computeDate' width={326} rules={[{ required: true, message: '所属年月不能为空!' }]} />
- <ProFormSelect label='数据库表名称' name='tableName' width={326}
- request={async () => {
- const resp = await getSpecialImportTable();
- if (resp) {
- return resp.map((a: any) => ({
- label: a.name,
- value: a.code
- }))
- }
- return []
- }}
- rules={[{ required: true, message: '数据库表名称不能为空!' }]} />
- <FormItem name={'importFile'}>
- {currentComputeDate && <KCIMUpload downloadTemplateFile={() => downloadTemplate()} ifShowTip={false} ifShowTemplateDownload={false} />}
- </FormItem>
- </ModalForm>
- )
- }
- return (
- <KCIMPagecontainer className='SpecialDataImport' title={false} >
- <div className='toolBar'>
- <div className='filter'>
- <div className='filterItem'>
- {(<div className='search'>
- <span>所属年月:</span>
- <DatePicker
- onChange={(data, dateString) => {
- set_tableDataFilterParams({ ...tableDataFilterParams, computeDate: dateString });
- setInitialState((s:any)=>({...s,currentComputeDate:dateString}));
- }}
- picker='month'
- locale={locale}
- defaultValue={moment(currentComputeDate, 'YYYY-MM')}
- format='YYYY-MM' placeholder="选择年月" />
- </div>)}
- </div>
- <div className='filterItem' style={{ marginLeft: 16 }}>
- <span className='label'>表名称:</span>
- <ProFormSelect
- noStyle
- allowClear
- placeholder="请选择"
- style={{ width: 160, marginRight: 16 }}
- request={async () => {
- const resp = await getSpecialImportTable();
- if (resp) {
- return resp.map((a: any) => ({
- label: a.name,
- value: a.code
- }))
- }
- return []
- }}
- fieldProps={{
- onChange(value, option) {
- set_tableDataFilterParams({ ...tableDataFilterParams, tableName: value })
- },
- }}
- />
- </div>
- </div>
- <div className='btnGroup'>
- {importData()}
- </div>
- </div>
- <div style={{ marginTop: 16 }}>
- {currentComputeDate && <KCIMTable scroll={{ y: `calc(100vh - 230px)` }} columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params, sort, filter) => getTableData(params)} />}
- </div>
- </KCIMPagecontainer>
- )
- }
|