You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileList.js 6.5 KiB

3 年之前
​
​
​
​
​
​
​
​
3 年之前
2 年之前
​
2 年之前
3 月之前
​
3 年之前
​
3 年之前
​
2 年之前
​
2 年之前
3 年之前
3 年之前
​
​
​
3 年之前
3 年之前
3 年之前
​
​
​
​
​
​
3 年之前
3 年之前
​
​
​
​
​
​
​
3 年之前
​
​
​
3 年之前
​
​
​
​
​
​
​
​
​
​
​
3 年之前
3 年之前
3 年之前
​
3 年之前
​
3 年之前
​
3 年之前
​
3 年之前
​
​
3 年之前
​
​
​
​
​
​
​
​
​
​
​
3 月之前
3 年之前
​
​
3 年之前
​
3 年之前
3 年之前
​
​
2 年之前
2 年之前
​
3 年之前
​
​
​
2 年之前
​
3 年之前
​
​
3 年之前
3 年之前
​
​
​
​
​
2 年之前
​
3 年之前
​
​
​
​
​
​
​
​
​
​
​
​
​
3 月之前
3 年之前
​
​
3 年之前
​
​
​
​
​
2 年之前
2 年之前
​
3 年之前
​
​
​
2 年之前
2 年之前
​
3 年之前
​
​
​
​
​
​
3 年之前
​
3 年之前
3 月之前
​
​
​
3 年之前
​
​
3 年之前
​
​
​
​
​
​
​
​
​
​
​
​
​
3 年之前
2 年之前
3 年之前
3 年之前
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // material-ui
  2. import * as React from 'react';
  3. import {
  4. GridActionsCellItem,
  5. } from "@mui/x-data-grid";
  6. import * as Icon from '../utils/IconUtils';
  7. import * as HttpUtils from "../utils/HttpUtils"
  8. import * as UrlUtils from "../utils/ApiPathConst"
  9. import * as DateUtils from "../utils/DateUtils"
  10. import { FiDataGrid } from './FiDataGrid';
  11. import {useTheme} from "@emotion/react";
  12. import {useMediaQuery} from "@mui/material";
  13. import {useIntl} from "react-intl";
  14. import { createDeleteFileColumn } from 'utils/fileListColumns';
  15. import { CONTAINED_PRIMARY_BLUE } from "themes/colorConst";
  16. // ==============================|| EVENT TABLE ||============================== //
  17. export default function FileList({ refType, refId, allowDelete, sx, dateHideable,lang, ...props }) {
  18. const [rows, setRows] = React.useState([]);
  19. const [rowModesModel] = React.useState({});
  20. const theme = useTheme();
  21. const isMdOrLg = useMediaQuery(theme.breakpoints.up('md'));
  22. const intl = useIntl();
  23. const [onDownload, setOnDownload] = React.useState(false);
  24. React.useEffect(() => {
  25. loadData();
  26. }, []);
  27. const onDeleteClick = (fileId, skey, filename) => () => {
  28. HttpUtils.del(
  29. {
  30. url: `${UrlUtils.GET_FILE_DELETE}/${fileId}/${skey}/${encodeURIComponent(filename)}`,
  31. onSuccess: function () {
  32. loadData();
  33. }
  34. }
  35. );
  36. };
  37. const onDownloadClick = (fileId, skey, filename) => () => {
  38. setOnDownload(true)
  39. HttpUtils.fileDownload({
  40. fileId: fileId,
  41. skey: skey,
  42. filename: filename,
  43. onResponse:()=>{
  44. setOnDownload(false)
  45. },
  46. onError:()=>{
  47. setOnDownload(false)
  48. }
  49. });
  50. };
  51. const loadData = () => {
  52. HttpUtils.post(
  53. {
  54. url: UrlUtils.POST_FILE_LIST,
  55. params: {
  56. refType: refType,
  57. refId:refId,
  58. },
  59. onSuccess: function (responseData) {
  60. setRows(responseData.records);
  61. }
  62. }
  63. );
  64. };
  65. const convertToStr = (bytes, decimals) => {
  66. if (bytes == 0) return '0 Bytes';
  67. var dm = decimals || 2,
  68. sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  69. let i = 0;
  70. i = Math.floor(Math.log(bytes) / Math.log(1024));
  71. return parseFloat((bytes / Math.pow(1024, i)).toFixed(dm)) + ' ' + sizes[i];
  72. }
  73. const columns = (dateHideable ?
  74. [
  75. {
  76. field: 'actions',
  77. type: 'actions',
  78. headerName: '',
  79. width: 50,
  80. cellClassName: 'actions',
  81. getActions: (params) => {
  82. return [
  83. <GridActionsCellItem
  84. key="OutSave"
  85. icon={<Icon.Download sx={{ color: CONTAINED_PRIMARY_BLUE }} />}
  86. label="Download"
  87. className="textPrimary"
  88. onClick={onDownloadClick(params.id, params.row.skey, params.row.filename)}
  89. disabled={onDownload}
  90. />]
  91. },
  92. },
  93. {
  94. id: 'filename',
  95. field: 'filename',
  96. headerName: intl.formatMessage({id: 'fileName'}),
  97. width: isMdOrLg ? 'auto' : 400,
  98. flex: isMdOrLg ? 3 : undefined,
  99. },
  100. {
  101. id: 'filesize',
  102. field: 'filesize',
  103. headerName: intl.formatMessage({id: 'fileSize'}),
  104. width: isMdOrLg ? 'auto' : 160,
  105. flex: isMdOrLg ? 1 : undefined,
  106. valueGetter: (params) => {
  107. return convertToStr(params.value);
  108. }
  109. }
  110. ]
  111. :
  112. [
  113. {
  114. id: 'created',
  115. field: 'created',
  116. headerName: lang=="ch"?"日期":'Created',
  117. width: isMdOrLg ? 'auto' : 160,
  118. flex: isMdOrLg ? 1 : undefined,
  119. valueGetter: (params) => {
  120. return DateUtils.datetimeStr(params.value);
  121. }
  122. },
  123. {
  124. field: 'actions',
  125. type: 'actions',
  126. headerName: '',
  127. width: 50,
  128. cellClassName: 'actions',
  129. getActions: (params) => {
  130. return [
  131. <GridActionsCellItem
  132. key="OutSave"
  133. icon={<Icon.Download sx={{ color: CONTAINED_PRIMARY_BLUE }} />}
  134. label="Download"
  135. className="textPrimary"
  136. onClick={onDownloadClick(params.id, params.row.skey, params.row.filename)}
  137. disabled={onDownload}
  138. />]
  139. },
  140. },
  141. {
  142. id: 'filename',
  143. field: 'filename',
  144. headerName: intl.formatMessage({id: 'fileName'}),
  145. width: isMdOrLg ? 'auto' : 400,
  146. flex: isMdOrLg ? 3 : undefined,
  147. },
  148. {
  149. id: 'filesize',
  150. field: 'filesize',
  151. headerName: intl.formatMessage({id: 'fileSize'}),
  152. width: isMdOrLg ? 'auto' : 160,
  153. flex: isMdOrLg ? 1 : undefined,
  154. valueGetter: (params) => {
  155. return convertToStr(params.value);
  156. }
  157. },
  158. ]
  159. );
  160. if (allowDelete) {
  161. columns.push(createDeleteFileColumn(
  162. (id, row) => onDeleteClick(id, row.skey, row.filename),
  163. { icon: Icon.Delete, color: 'primary', width: 100 }
  164. ));
  165. }
  166. return (
  167. <FiDataGrid
  168. {...props}
  169. hideFooterSelectedRowCount={true}
  170. sx={sx}
  171. rows={rows}
  172. columns={columns}
  173. editMode="row"
  174. rowModesModel={rowModesModel}
  175. // initialState={{
  176. // pagination: {
  177. // paginationModel: { page: 0, pageSize: 5 },
  178. // },
  179. // }}
  180. //pageSizeOptions={[5, 10]}
  181. customPageSize={100}
  182. autoHeight={true}
  183. />
  184. );
  185. }