index.tsx 5.7 KB

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