* feat: invoice (#2293)

* feat: default voice header

* add i18n

* refactor: 优化代码

* feat: 用户开票

* refactor: 代码优化&&样式联调 (#2384)

* Feat: invoice upload (#2424)

* refactor: 验收问题&&样式调整

* feat: 文件上传

* 小调整

* perf: invoice ui

---------

Co-authored-by: papapatrick <109422393+Patrickill@users.noreply.github.com>
This commit is contained in:
Archer
2024-08-19 17:44:48 +08:00
committed by GitHub
parent 884c2d9553
commit 5fab3734fa
37 changed files with 1093 additions and 31 deletions

View File

@@ -0,0 +1,56 @@
import React, { useRef, useCallback } from 'react';
import { Box } from '@chakra-ui/react';
import { useToast } from '../../../hooks/useToast';
import { useTranslation } from 'next-i18next';
export const useSelectFile = (props?: {
fileType?: string;
multiple?: boolean;
maxCount?: number;
}) => {
const { t } = useTranslation();
const { fileType = '*', multiple = false, maxCount = 10 } = props || {};
const { toast } = useToast();
const SelectFileDom = useRef<HTMLInputElement>(null);
const openSign = useRef<any>();
const File = useCallback(
({ onSelect }: { onSelect: (e: File[], sign?: any) => void }) => (
<Box position={'absolute'} w={0} h={0} overflow={'hidden'}>
<input
ref={SelectFileDom}
type="file"
accept={fileType}
multiple={multiple}
onChange={(e) => {
const files = e.target.files;
if (!files || files?.length === 0) return;
let fileList = Array.from(files);
if (fileList.length > maxCount) {
toast({
status: 'warning',
title: t('file:select_file_amount_limit', { max: maxCount })
});
fileList = fileList.slice(0, maxCount);
}
onSelect(fileList, openSign.current);
e.target.value = '';
}}
/>
</Box>
),
[fileType, maxCount, multiple, toast]
);
const onOpen = useCallback((sign?: any) => {
openSign.current = sign;
SelectFileDom.current && SelectFileDom.current.click();
}, []);
return {
File,
onOpen
};
};