|
@@ -5,9 +5,8 @@ import AAbtn from '@/pages/ZcomPage/AAbtn'
|
|
|
import UpBtn, { UpBtnMethods } from '@/pages/ZcomPage/UpBtn'
|
|
import UpBtn, { UpBtnMethods } from '@/pages/ZcomPage/UpBtn'
|
|
|
import MyTable from '@/components/MyTable'
|
|
import MyTable from '@/components/MyTable'
|
|
|
import { downloadFileByUrl } from '@/utils/history'
|
|
import { downloadFileByUrl } from '@/utils/history'
|
|
|
-import http, { baseUrlTemp, envFlag } from '@/utils/http'
|
|
|
|
|
|
|
+import http from '@/utils/http'
|
|
|
import dayjs from 'dayjs'
|
|
import dayjs from 'dayjs'
|
|
|
-import { getTokenInfo } from '@/utils/storage'
|
|
|
|
|
import { MessageFu } from '@/utils/message'
|
|
import { MessageFu } from '@/utils/message'
|
|
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
@@ -45,15 +44,6 @@ type DetailQueryType = {
|
|
|
type DetailModalMode = 'view' | 'uploadResult'
|
|
type DetailModalMode = 'view' | 'uploadResult'
|
|
|
|
|
|
|
|
const emptyTxt = '(空)'
|
|
const emptyTxt = '(空)'
|
|
|
-const requestBaseURL = envFlag ? '/api/' : `${baseUrlTemp}/api/`
|
|
|
|
|
-const detailApiCandidates = [
|
|
|
|
|
- 'cms/importLedger/detailPage',
|
|
|
|
|
- 'cms/importLedger/detailList',
|
|
|
|
|
- 'cms/importLedger/resultPage',
|
|
|
|
|
- 'cms/importLedger/checkPage',
|
|
|
|
|
- 'cms/importLedger/checkResultPage',
|
|
|
|
|
- 'cms/importLedger/pageDetail'
|
|
|
|
|
-]
|
|
|
|
|
const templateMenuItems = [
|
|
const templateMenuItems = [
|
|
|
{
|
|
{
|
|
|
key: 'one_pu_template',
|
|
key: 'one_pu_template',
|
|
@@ -66,6 +56,18 @@ const templateMenuItems = [
|
|
|
fileUrl: './myData/xlsx/博物馆文物藏品总账模板.xlsx'
|
|
fileUrl: './myData/xlsx/博物馆文物藏品总账模板.xlsx'
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
|
|
+const uploadMenuItems = [
|
|
|
|
|
+ {
|
|
|
|
|
+ key: 'upload_excel_1',
|
|
|
|
|
+ label: '一普文物信息',
|
|
|
|
|
+ url: 'cms/importLedger/uploadExcel'
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ key: 'upload_excel_2',
|
|
|
|
|
+ label: '博物馆文物藏品总账',
|
|
|
|
|
+ url: 'cms/importLedger/uploadExcel2'
|
|
|
|
|
+ }
|
|
|
|
|
+]
|
|
|
const pickValue = (item: any, keys: string[], defaultValue: any = emptyTxt) => {
|
|
const pickValue = (item: any, keys: string[], defaultValue: any = emptyTxt) => {
|
|
|
for (const key of keys) {
|
|
for (const key of keys) {
|
|
|
const value = item?.[key]
|
|
const value = item?.[key]
|
|
@@ -214,54 +216,11 @@ const filterInlineDetails = (list: ImportDetailType[], query: DetailQueryType) =
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const buildDetailPayload = (record: ImportRecordType, query: DetailQueryType) => {
|
|
|
|
|
- const keyword = query.keyword.trim()
|
|
|
|
|
- const result = query.result
|
|
|
|
|
-
|
|
|
|
|
- return {
|
|
|
|
|
- id: record.id,
|
|
|
|
|
- importId: record.id,
|
|
|
|
|
- batchId: record.id,
|
|
|
|
|
- logId: record.id,
|
|
|
|
|
- pageNum: query.pageNum,
|
|
|
|
|
- pageSize: query.pageSize,
|
|
|
|
|
- keyword,
|
|
|
|
|
- keyWord: keyword,
|
|
|
|
|
- searchText: keyword,
|
|
|
|
|
- searchKey: keyword,
|
|
|
|
|
- nameOrNum: keyword,
|
|
|
|
|
- result,
|
|
|
|
|
- status: result,
|
|
|
|
|
- checkResult: result,
|
|
|
|
|
- validateResult: result
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const silentPost = async (url: string, data: any) => {
|
|
|
|
|
- const { token } = getTokenInfo()
|
|
|
|
|
- try {
|
|
|
|
|
- const response = await fetch(`${requestBaseURL}${url}`, {
|
|
|
|
|
- method: 'POST',
|
|
|
|
|
- headers: {
|
|
|
|
|
- 'Content-Type': 'application/json',
|
|
|
|
|
- ...(token ? { token } : {})
|
|
|
|
|
- },
|
|
|
|
|
- body: JSON.stringify(data)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- if (!response.ok) return null
|
|
|
|
|
- const result = await response.json().catch(() => null)
|
|
|
|
|
- if (!result || result.code !== 0) return null
|
|
|
|
|
- return result
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- return null
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
function ImportData({ closeFu }: Props) {
|
|
function ImportData({ closeFu }: Props) {
|
|
|
const uploadBtnRef = useRef<UpBtnMethods>(null)
|
|
const uploadBtnRef = useRef<UpBtnMethods>(null)
|
|
|
- const detailApiPathRef = useRef('')
|
|
|
|
|
|
|
+ const uploadBtnRef2 = useRef<UpBtnMethods>(null)
|
|
|
const reuploadPendingRef = useRef(false)
|
|
const reuploadPendingRef = useRef(false)
|
|
|
|
|
+ const lastUploadMenuKeyRef = useRef(uploadMenuItems[0].key)
|
|
|
|
|
|
|
|
const [formData, setFormData] = useState({ pageNum: 1, pageSize: 10 })
|
|
const [formData, setFormData] = useState({ pageNum: 1, pageSize: 10 })
|
|
|
const [tableInfo, setTableInfo] = useState({ list: [] as ImportRecordType[], total: 0 })
|
|
const [tableInfo, setTableInfo] = useState({ list: [] as ImportRecordType[], total: 0 })
|
|
@@ -313,7 +272,6 @@ function ImportData({ closeFu }: Props) {
|
|
|
}, [getListFu])
|
|
}, [getListFu])
|
|
|
|
|
|
|
|
const openDetailModal = useCallback((item: ImportRecordType, mode: DetailModalMode = 'view') => {
|
|
const openDetailModal = useCallback((item: ImportRecordType, mode: DetailModalMode = 'view') => {
|
|
|
- detailApiPathRef.current = ''
|
|
|
|
|
setDetailModalMode(mode)
|
|
setDetailModalMode(mode)
|
|
|
setActionLoading('')
|
|
setActionLoading('')
|
|
|
setDetailInput({ keyword: '', result: '' })
|
|
setDetailInput({ keyword: '', result: '' })
|
|
@@ -357,7 +315,8 @@ function ImportData({ closeFu }: Props) {
|
|
|
const getDetailListFu = useCallback(async () => {
|
|
const getDetailListFu = useCallback(async () => {
|
|
|
if (!detailInfo) return
|
|
if (!detailInfo) return
|
|
|
|
|
|
|
|
- const inlineList = getInlineDetailList(detailInfo.raw)
|
|
|
|
|
|
|
+ const inlineSource = detailModalMode === 'uploadResult' ? uploadResultData || detailInfo.raw : detailInfo.raw
|
|
|
|
|
+ const inlineList = getInlineDetailList(inlineSource)
|
|
|
if (inlineList.length) {
|
|
if (inlineList.length) {
|
|
|
const normalizedList = inlineList.map((item: any, index: number) =>
|
|
const normalizedList = inlineList.map((item: any, index: number) =>
|
|
|
normalizeDetail(item, index)
|
|
normalizeDetail(item, index)
|
|
@@ -370,6 +329,11 @@ function ImportData({ closeFu }: Props) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (detailModalMode === 'uploadResult') {
|
|
|
|
|
+ setDetailTableInfo({ list: [], total: 0 })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
setDetailLoading(true)
|
|
setDetailLoading(true)
|
|
|
try {
|
|
try {
|
|
|
if (detailModalMode === 'view') {
|
|
if (detailModalMode === 'view') {
|
|
@@ -385,36 +349,11 @@ function ImportData({ closeFu }: Props) {
|
|
|
list: filteredList,
|
|
list: filteredList,
|
|
|
total: filteredList.length
|
|
total: filteredList.length
|
|
|
})
|
|
})
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const payload = buildDetailPayload(detailInfo, detailQuery)
|
|
|
|
|
- const tryPaths = detailApiPathRef.current
|
|
|
|
|
- ? [detailApiPathRef.current]
|
|
|
|
|
- : [...detailApiCandidates]
|
|
|
|
|
-
|
|
|
|
|
- for (const path of tryPaths) {
|
|
|
|
|
- const res = await silentPost(path, payload)
|
|
|
|
|
- if (res?.data) {
|
|
|
|
|
- detailApiPathRef.current = path
|
|
|
|
|
- const records = getInlineDetailList(res.data).map((item: any, index: number) =>
|
|
|
|
|
- normalizeDetail(item, index)
|
|
|
|
|
- )
|
|
|
|
|
- const filteredList = filterInlineDetails(records, detailQuery)
|
|
|
|
|
-
|
|
|
|
|
- setDetailTableInfo({
|
|
|
|
|
- list: filteredList,
|
|
|
|
|
- total: filteredList.length
|
|
|
|
|
- })
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- setDetailTableInfo({ list: [], total: 0 })
|
|
|
|
|
} finally {
|
|
} finally {
|
|
|
setDetailLoading(false)
|
|
setDetailLoading(false)
|
|
|
}
|
|
}
|
|
|
- }, [detailInfo, detailModalMode, detailQuery])
|
|
|
|
|
|
|
+ }, [detailInfo, detailModalMode, detailQuery, uploadResultData])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
getDetailListFu()
|
|
getDetailListFu()
|
|
@@ -435,11 +374,20 @@ function ImportData({ closeFu }: Props) {
|
|
|
closeDetailModal()
|
|
closeDetailModal()
|
|
|
}, [closeDetailModal])
|
|
}, [closeDetailModal])
|
|
|
|
|
|
|
|
- const reuploadFu = useCallback(() => {
|
|
|
|
|
- reuploadPendingRef.current = true
|
|
|
|
|
|
|
+ const openUploadPickerByKey = useCallback((key: string) => {
|
|
|
|
|
+ lastUploadMenuKeyRef.current = key
|
|
|
|
|
+ if (key === uploadMenuItems[1].key) {
|
|
|
|
|
+ uploadBtnRef2.current?.openPicker()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
uploadBtnRef.current?.openPicker()
|
|
uploadBtnRef.current?.openPicker()
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
+ const reuploadFu = useCallback(() => {
|
|
|
|
|
+ reuploadPendingRef.current = true
|
|
|
|
|
+ openUploadPickerByKey(lastUploadMenuKeyRef.current)
|
|
|
|
|
+ }, [openUploadPickerByKey])
|
|
|
|
|
+
|
|
|
const importSuccessData = useCallback(async () => {
|
|
const importSuccessData = useCallback(async () => {
|
|
|
if (!detailInfo || !uploadResultData) return
|
|
if (!detailInfo || !uploadResultData) return
|
|
|
if (Number(detailInfo.successCount || 0) <= 0) {
|
|
if (Number(detailInfo.successCount || 0) <= 0) {
|
|
@@ -500,15 +448,42 @@ function ImportData({ closeFu }: Props) {
|
|
|
<AAbtn txt={1} onClick={() => undefined} tit='下载模板' />
|
|
<AAbtn txt={1} onClick={() => undefined} tit='下载模板' />
|
|
|
</div>
|
|
</div>
|
|
|
</Dropdown>
|
|
</Dropdown>
|
|
|
- <UpBtn
|
|
|
|
|
- ref={uploadBtnRef}
|
|
|
|
|
- tit='上传藏品数据'
|
|
|
|
|
- url='cms/importLedger/uploadExcel'
|
|
|
|
|
- width={140}
|
|
|
|
|
- backFu={getListFu}
|
|
|
|
|
- onFileSelected={handleUploadFileSelected}
|
|
|
|
|
- onSuccess={handleUploadSuccess}
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ <Dropdown
|
|
|
|
|
+ trigger={['click']}
|
|
|
|
|
+ placement='bottomCenter'
|
|
|
|
|
+ overlayClassName={styles.A1ImportTemplateMenu}
|
|
|
|
|
+ menu={{
|
|
|
|
|
+ items: uploadMenuItems.map(item => ({
|
|
|
|
|
+ key: item.key,
|
|
|
|
|
+ label: item.label
|
|
|
|
|
+ })),
|
|
|
|
|
+ onClick: ({ key }) => openUploadPickerByKey(key)
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <AAbtn txt={1} onClick={() => undefined} tit='上传藏品数据' width={140} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Dropdown>
|
|
|
|
|
+ <div style={{ display: 'none' }}>
|
|
|
|
|
+ <UpBtn
|
|
|
|
|
+ ref={uploadBtnRef}
|
|
|
|
|
+ tit='上传藏品数据'
|
|
|
|
|
+ url={uploadMenuItems[0].url}
|
|
|
|
|
+ width={140}
|
|
|
|
|
+ backFu={getListFu}
|
|
|
|
|
+ onFileSelected={handleUploadFileSelected}
|
|
|
|
|
+ onSuccess={handleUploadSuccess}
|
|
|
|
|
+ />
|
|
|
|
|
+ <UpBtn
|
|
|
|
|
+ ref={uploadBtnRef2}
|
|
|
|
|
+ tit='上传藏品数据'
|
|
|
|
|
+ url={uploadMenuItems[1].url}
|
|
|
|
|
+ width={140}
|
|
|
|
|
+ backFu={getListFu}
|
|
|
|
|
+ onFileSelected={handleUploadFileSelected}
|
|
|
|
|
+ onSuccess={handleUploadSuccess}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|