index.tsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2024-08-16 10:02:03
  6. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import { createFromIconfontCN } from '@ant-design/icons';
  10. import { ActionType } from '@ant-design/pro-components';
  11. import { ModalForm, ProFormDatePicker, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  12. import { ProColumns } from '@ant-design/pro-table';
  13. import { Input, message, Popconfirm, DatePicker } from 'antd';
  14. import { useEffect, useRef, useState } from 'react'
  15. import { afterImport, getData, getSpecialImportTable, tableDataImport } from './service';
  16. import FormItem from 'antd/es/form/FormItem';
  17. import './style.less';
  18. import '../../utils/zhongtaiA'
  19. import moment from 'moment';
  20. import 'moment/locale/zh-cn';
  21. import locale from 'antd/es/date-picker/locale/zh_CN';
  22. import { getComputeDate } from '@/pages/Home/service';
  23. import KCIMUpload from '@/components/KCIMUpload';
  24. import KCIMPagecontainer from '@/components/KCIMPageContainer';
  25. import { KCIMTable } from '@/components/KCIMTable';
  26. import { useModel } from '@umijs/max';
  27. const IconFont = createFromIconfontCN({
  28. scriptUrl: '',
  29. });
  30. const currentDate = `${new Date().getFullYear()}-${(new Date().getMonth() + 1).toString().padStart(2, '0')}`;
  31. export default function DicClassfication() {
  32. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  33. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  34. const { initialState, setInitialState } = useModel('@@initialState');
  35. const [currentComputeDate, set_currentComputeDate] = useState<string | undefined>(initialState ? initialState.computeDate : undefined);
  36. const tableRef = useRef<ActionType>();
  37. const columns: ProColumns[] = [
  38. {
  39. title: '所属年月',
  40. dataIndex: 'computeDate',
  41. ellipsis: true
  42. },
  43. {
  44. title: '数据库表名称',
  45. dataIndex: 'tableNameDisplay',
  46. ellipsis: true
  47. },
  48. {
  49. title: '文件名称',
  50. dataIndex: 'fileName',
  51. ellipsis: true,
  52. renderText(text, record, index, action) {
  53. return <a href={record.url} target='_blank'>{record.fileName}</a>
  54. },
  55. },
  56. {
  57. title: '导入时间',
  58. dataIndex: 'createTime',
  59. ellipsis: true
  60. },
  61. {
  62. title: '导入人员',
  63. dataIndex: 'createUserName',
  64. ellipsis: true
  65. },
  66. {
  67. title: '操作',
  68. key: 'option',
  69. width: 120,
  70. valueType: 'option',
  71. render: (_: any, record: any) => {
  72. return [
  73. <Popconfirm
  74. title={`是否${record.importStatus == 1 ? '复原导入' : '撤销导入'}?`}
  75. key="del"
  76. onConfirm={() => afterImportHandle(record)}
  77. >
  78. <a>{record.importStatus == 1 ? '复原导入' : '撤销导入'}</a>
  79. </Popconfirm>
  80. ]
  81. },
  82. },
  83. ];
  84. const afterImportHandle = async (record: any) => {
  85. const { importStatus } = record;
  86. const resp = await afterImport(record.id, importStatus ? 'RECOVERY' : 'CANCEL');
  87. if (resp) {
  88. message.success('操作成功!');
  89. tableRef.current?.reload();
  90. }
  91. }
  92. const getTableData = async (params: any) => {
  93. const { computeDate } = params;
  94. const resp = await getData({ ...params, computeDate: computeDate ? computeDate : currentComputeDate });
  95. if (resp) {
  96. return {
  97. data: resp.list,
  98. success: true,
  99. total: resp.totalCount,
  100. pageSize: resp.pageSize,
  101. totalPage: resp.totalPage,
  102. }
  103. }
  104. return []
  105. }
  106. const importData = () => {
  107. function downloadTemplate(): void {
  108. }
  109. return (
  110. <ModalForm
  111. className='SpecialDataImport-Modal'
  112. width={360}
  113. title={`导入数据`}
  114. trigger={
  115. <span key="3" className='importBtn'>导入</span>
  116. }
  117. submitter={{
  118. render: (props, defaultDoms) => {
  119. const needBtn = defaultDoms.filter((b) => {
  120. return b.key != 'rest'
  121. })
  122. return [
  123. ...needBtn,
  124. ];
  125. },
  126. }}
  127. onFinish={async (values) => {
  128. // console.log({values});
  129. const { importFile: { fileList } } = values;
  130. let formData = new FormData();
  131. formData.append('file', fileList[0].originFileObj);
  132. formData.append('computeDate', values.computeDate);
  133. formData.append('tableName', values.tableName);
  134. const resp = await tableDataImport(formData);
  135. if (resp) {
  136. tableRef.current?.reload();
  137. return true;
  138. }
  139. }}
  140. >
  141. <div className='tip'>本操作为追加导入,会保留已有的数据并将文件的所有记录追加到数据表</div>
  142. <ProFormDatePicker.Month label='所属年月' name='computeDate' width={326} rules={[{ required: true, message: '所属年月不能为空!' }]} />
  143. <ProFormSelect label='数据库表名称' name='tableName' width={326}
  144. request={async () => {
  145. const resp = await getSpecialImportTable();
  146. if (resp) {
  147. return resp.map((a: any) => ({
  148. label: a.name,
  149. value: a.code
  150. }))
  151. }
  152. return []
  153. }}
  154. rules={[{ required: true, message: '数据库表名称不能为空!' }]} />
  155. <FormItem name={'importFile'}>
  156. {currentComputeDate && <KCIMUpload downloadTemplateFile={() => downloadTemplate()} ifShowTip={false} ifShowTemplateDownload={false} />}
  157. </FormItem>
  158. </ModalForm>
  159. )
  160. }
  161. return (
  162. <KCIMPagecontainer className='SpecialDataImport' title={false} >
  163. <div className='toolBar'>
  164. <div className='filter'>
  165. <div className='filterItem'>
  166. {(<div className='search'>
  167. <span>所属年月:</span>
  168. <DatePicker
  169. onChange={(data, dateString) => {
  170. set_tableDataFilterParams({ ...tableDataFilterParams, computeDate: dateString });
  171. setInitialState((s:any)=>({...s,currentComputeDate:dateString}));
  172. }}
  173. picker='month'
  174. locale={locale}
  175. defaultValue={moment(currentComputeDate, 'YYYY-MM')}
  176. format='YYYY-MM' placeholder="选择年月" />
  177. </div>)}
  178. </div>
  179. <div className='filterItem' style={{ marginLeft: 16 }}>
  180. <span className='label'>表名称:</span>
  181. <ProFormSelect
  182. noStyle
  183. allowClear
  184. placeholder="请选择"
  185. style={{ width: 160, marginRight: 16 }}
  186. request={async () => {
  187. const resp = await getSpecialImportTable();
  188. if (resp) {
  189. return resp.map((a: any) => ({
  190. label: a.name,
  191. value: a.code
  192. }))
  193. }
  194. return []
  195. }}
  196. fieldProps={{
  197. onChange(value, option) {
  198. set_tableDataFilterParams({ ...tableDataFilterParams, tableName: value })
  199. },
  200. }}
  201. />
  202. </div>
  203. </div>
  204. <div className='btnGroup'>
  205. {importData()}
  206. </div>
  207. </div>
  208. <div style={{ marginTop: 16 }}>
  209. {currentComputeDate && <KCIMTable scroll={{ y: `calc(100vh - 230px)` }} columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params, sort, filter) => getTableData(params)} />}
  210. </div>
  211. </KCIMPagecontainer>
  212. )
  213. }