index.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import useModal from '@/components/Modal'
  2. import { PageContainer } from '@ant-design/pro-layout'
  3. import { Button } from 'antd'
  4. import { ColumnsType } from 'antd/lib/table'
  5. import { useRowScript } from './hooks/useRowScript'
  6. import {
  7. ArrowDownOutlined,
  8. ArrowUpOutlined,
  9. DeleteOutlined,
  10. EditOutlined,
  11. FileAddOutlined,
  12. FolderAddOutlined,
  13. SelectOutlined,
  14. FolderOpenFilled,
  15. FileTextOutlined
  16. } from '@ant-design/icons'
  17. import LeftMenu from '../RuleCode/components/LeftMenu'
  18. import ProTable from '@ant-design/pro-table'
  19. import { useEffect, useState } from 'react'
  20. import styles from './index.less'
  21. export enum TemplateMode {
  22. PAPER = 'paper',
  23. UPLOAD = 'upload',
  24. NIL = 'nil'
  25. }
  26. const Inventory = () => {
  27. const [modal, ModalDOM] = useModal()
  28. const [activeKey, setActivekey] = useState<Nullable<string>>(null)
  29. const {
  30. query,
  31. loading,
  32. record,
  33. list = [],
  34. rowClick,
  35. move,
  36. addFolder,
  37. addFile,
  38. editFolder,
  39. deleteFolderOrFile,
  40. moveWithOperation
  41. } = useRowScript(modal, activeKey)
  42. useEffect(() => {
  43. if (activeKey) {
  44. query()
  45. }
  46. }, [activeKey])
  47. const columns: ColumnsType<API.ProfileTemplateItem> = [
  48. {
  49. title: '目录文件名称',
  50. dataIndex: 'name',
  51. width: '50%',
  52. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  53. render: (text, record) => (
  54. <div className="ml-2">
  55. {record.folder ? <FolderOpenFilled /> : <FileTextOutlined />}
  56. <span className="ml-2">{text}</span>
  57. </div>
  58. )
  59. },
  60. {
  61. title: '状态',
  62. dataIndex: 'enable',
  63. align: 'center',
  64. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  65. render: (text, record) => {
  66. if (record.folder) return null
  67. return text ? <span className="text-green">启用</span> : <span className="text-red">停用</span>
  68. }
  69. },
  70. {
  71. title: '是否必填',
  72. dataIndex: 'required',
  73. align: 'center',
  74. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  75. render: (text, record) => {
  76. if (record.folder) return null
  77. return text ? '是' : '否'
  78. }
  79. },
  80. {
  81. title: '资料提供方式',
  82. dataIndex: 'mode',
  83. align: 'center',
  84. render: (mode: TemplateMode, record) => {
  85. if (record.folder) return null
  86. return (
  87. <div className={styles.modeBox}>
  88. {mode.includes(TemplateMode.PAPER) ? (
  89. <span className="border border-hex-91d5ff text-blue bg-hex-e6f7ff rounded-1 px-1 text-sm">
  90. 纸质
  91. </span>
  92. ) : null}
  93. {mode.includes(TemplateMode.UPLOAD) ? (
  94. <span className="border border-hex-9fede5 text-hex-13c2c2 bg-hex-e6fffb rounded-1 px-1 text-sm">
  95. 上传
  96. </span>
  97. ) : null}
  98. </div>
  99. )
  100. }
  101. }
  102. ]
  103. const handleMenuOnChange = (key: string) => {
  104. setActivekey(key)
  105. }
  106. return (
  107. <PageContainer title={false}>
  108. <div className="h-full w-full flex flex-row">
  109. <LeftMenu title="业务列表" onChange={key => handleMenuOnChange(key)} />
  110. <div className="bg-white ml-8 rounded-20px" style={{ width: 'calc(100% - 248px)' }}>
  111. <ProTable
  112. scroll={{ y: document.body.clientHeight - 259 }}
  113. search={false}
  114. rowKey="ID"
  115. headerTitle={
  116. <div className="flex flex-nowrap justify-start items-center">
  117. <div className="children:mx-1 px-1 py-2 ">
  118. <Button
  119. icon={<FolderAddOutlined />}
  120. size="small"
  121. type="primary"
  122. ghost
  123. onClick={() => addFolder()}>
  124. 新建目录
  125. </Button>
  126. <Button
  127. icon={<FileAddOutlined />}
  128. size="small"
  129. type="primary"
  130. ghost
  131. onClick={() => addFile('add')}>
  132. 新建文件
  133. </Button>
  134. <Button
  135. icon={<EditOutlined />}
  136. size="small"
  137. type="primary"
  138. ghost
  139. onClick={() => {
  140. record?.folder && editFolder()
  141. !record?.folder && addFile('update')
  142. }}
  143. disabled={!record}>
  144. 编辑
  145. </Button>
  146. <Button
  147. icon={<DeleteOutlined />}
  148. size="small"
  149. type="primary"
  150. ghost
  151. onClick={deleteFolderOrFile}
  152. disabled={!record}>
  153. 删除
  154. </Button>
  155. <Button
  156. icon={<ArrowUpOutlined />}
  157. size="small"
  158. type="primary"
  159. ghost
  160. disabled={!record?.moveable || record?.position === 'top'}
  161. onClick={() => moveWithOperation('up')}>
  162. 上移
  163. </Button>
  164. <Button
  165. icon={<ArrowDownOutlined />}
  166. size="small"
  167. type="primary"
  168. ghost
  169. disabled={!record?.moveable || record?.position === 'bottom'}
  170. onClick={() => moveWithOperation('down')}>
  171. 下移
  172. </Button>
  173. <Button
  174. icon={<SelectOutlined />}
  175. size="small"
  176. type="primary"
  177. ghost
  178. disabled={!record}
  179. onClick={move}>
  180. 移动至
  181. </Button>
  182. </div>
  183. </div>
  184. }
  185. loading={loading}
  186. columns={columns}
  187. dataSource={list}
  188. pagination={false}
  189. size="small"
  190. bordered
  191. expandable={{ defaultExpandAllRows: true }}
  192. onRow={record => ({
  193. onClick: () => rowClick(record)
  194. })}
  195. rowClassName={row => (row.ID === record?.ID ? 'ant-table-row-selected' : '')}
  196. />
  197. </div>
  198. </div>
  199. {ModalDOM}
  200. </PageContainer>
  201. )
  202. }
  203. export default Inventory