Sfoglia il codice sorgente

feat: 抽离通用方法、目录结构调整。

lanjianrong 4 anni fa
parent
commit
97452c2d68

+ 0 - 11
src/components/FileModal/api.ts

@@ -1,11 +0,0 @@
-import request from "@/utils/common/request"
-
-/**
- * 根据类型获取附件列表
- * @param dataType - 类型
- * @param dataId - 数据id
- */
-export async function apiGetFileList(dataType: number, dataId: string, pageNo: number, pageSize: number) {
-  const { data } = await request.get('/api/file', { dataType, dataId, pageNo, pageSize })
-  return data
-}

+ 1 - 3
src/components/FileModal/index.tsx

@@ -1,6 +1,6 @@
 import SvgIcon from '@/components/SvgIcon'
-import { apiSaveFileInfo } from '@/pages/Safe/Content/Info/Detail/api'
 import { iFile, iOSSData } from '@/types/file'
+import { apiGetFileList, apiSaveFileInfo, getSignature } from '@/utils/common/api'
 import consts from '@/utils/consts'
 import { dayjsFormat } from '@/utils/util'
 import { InboxOutlined } from '@ant-design/icons'
@@ -10,8 +10,6 @@ import { UploadChangeParam } from 'antd/lib/upload'
 import { UploadFile } from 'antd/lib/upload/interface'
 import React, { useEffect, useState } from 'react'
 import { ZhCloseButton } from '../Button'
-import { getSignature } from '../OssUpload/ali-oss'
-import { apiGetFileList } from './api'
 const { Dragger } = Upload
 interface iFileModalProps {
   dataId: string

+ 0 - 8
src/components/OssUpload/ali-oss.ts

@@ -1,8 +0,0 @@
-import request from "@/utils/common/request"
-
-
-// 获取签名
-export async function getSignature() {
-  const { data } = await request.get('/api/oss/signature')
-  return data
-}

+ 20 - 10
src/components/OssUpload/index.tsx

@@ -1,5 +1,6 @@
 import { ZhCloseButton } from '@/components/Button'
 import { iFile, iOSSData } from '@/types/file'
+import { getSignature } from '@/utils/common/api'
 import consts from '@/utils/consts'
 import { InboxOutlined } from '@ant-design/icons'
 import { Button, message, Modal, Upload } from 'antd'
@@ -7,7 +8,6 @@ import { ModalProps } from 'antd/lib/modal'
 import { UploadChangeParam } from 'antd/lib/upload'
 import { UploadFile } from 'antd/lib/upload/interface'
 import React, { useEffect, useState } from 'react'
-import { getSignature } from './ali-oss'
 const { Dragger } = Upload
 
 interface iUploadModalProps extends ModalProps {
@@ -40,15 +40,19 @@ const UploadModal:React.FC<iUploadModalProps> = (props) => {
     }
     if (status === 'done') {
       // message.success(`${info.file.name} 上传成功!`)
-      setFileList([ ...fileList, ...info.fileList ])
-      const newFileList: iFile[] = info.fileList.map((item: UploadFile) => {
-        return {
-          createTime: new Date(),
-          filepath: item.url,
-          filename: item.name
-        }
-      })
-      setFiles(newFileList)
+      console.log(info)
+      const newFileList = [ ...fileList ]
+      newFileList.push(info.file)
+      setFileList(newFileList)
+      // const newFileList: iFile[] = info.fileList.map((item: UploadFile) => {
+      //   return {
+      //     createTime: new Date(),
+      //     filepath: item.url,
+      //     filename: item.name
+      //   }
+      // })
+      const newFiles = [ ...files, { createTime: new Date(), filepath: info.file.url,filename: info.file.name } ]
+      setFiles(newFiles)
     } else if (status === 'error') {
       message.error(`${info.file.name} 上传失败!`)
     }
@@ -95,6 +99,12 @@ const UploadModal:React.FC<iUploadModalProps> = (props) => {
       initOssData()
       return false
     }
+    console.log(file)
+
+    const reg = new RegExp(consts.UPLOAD_WHITE)
+    if (!reg.test(file.name)) {
+      return false
+    }
     return true
   }
 

+ 1 - 1
src/pages/Contract/Content/Income/components/TableContent/index.tsx

@@ -1,9 +1,9 @@
 import { ZhSubmitButton } from '@/components/Button'
 import OssUploadModal from '@/components/OssUpload'
-import { apiSaveFileInfo } from '@/pages/Safe/Content/Info/Detail/api'
 import { contractStore, tenderStore } from '@/store/mobx'
 import { iIncomeTree } from '@/types/contract'
 import { iFile } from '@/types/file'
+import { apiSaveFileInfo } from '@/utils/common/api'
 import { contractConsts } from '@/utils/common/constStatus'
 import consts from '@/utils/consts'
 import { Button, Input, message, Radio, Table, Tabs } from 'antd'

+ 15 - 10
src/pages/Contract/Content/Income/components/Tabs/File/index.tsx

@@ -1,6 +1,5 @@
-import { apiGetFileList } from '@/components/FileModal/api'
 import { contractStore } from '@/store/mobx'
-import { apiDelFile } from '@/utils/common/api'
+import { apiDelFile, apiGetFileList } from '@/utils/common/api'
 import consts from '@/utils/consts'
 import { dayjsFormat } from '@/utils/util'
 import Table, { ColumnsType } from 'antd/lib/table'
@@ -30,7 +29,7 @@ const File:React.FC<{}> = () => {
       contractStore.shouldUpdate && (contractStore.changeUpdate(''))
     }
   }, [ contractStore.contract.id, contractStore.shouldUpdate ])
-  const initData = async(pageNo: number = 1, pageSize: number = 10) => {
+  const initData = async(pageNo: number = 1, pageSize: number = 7) => {
     const { code = -1, data = [], total = 0 } = await apiGetFileList(consts.DATA_TYPE.CONTRACT, contractStore.contract.id, pageNo, pageSize)
     if (code === consts.RET_CODE.SUCCESS) {
       setData(data)
@@ -48,33 +47,39 @@ const File:React.FC<{}> = () => {
     {
       dataIndex: 'sort',
       // eslint-disable-next-line react/display-name
-      render: (_:any, record: iFileState, idx: number) => <span>{idx+1}</span>
+      render: (_:any, record: iFileState, idx: number) => <span>{idx+1}</span>,
+      width: 5
     },
     {
       title: '名称',
       dataIndex: 'filename',
       // eslint-disable-next-line react/display-name
-      render: (text: string, record: iFileState) => <a href={consts.OSS_PATH.REVIEW + record.filepath} target="_blank" rel="noopener noreferrer">{text}</a>
+      render: (text: string, record: iFileState) => <a href={consts.OSS_PATH.REVIEW + record.filepath} target="_blank" rel="noopener noreferrer">{text}</a>,
+      width: 50
     },
     {
       title: '上传者',
-      dataIndex: 'accountName'
+      dataIndex: 'accountName',
+      width: 10
     },
     {
       title: '上传时间',
       dataIndex: 'createTime',
       // eslint-disable-next-line react/display-name
-      render: (time: string) => <span>{dayjsFormat(time, 'YYYY-MM-DD')}</span>
+      render: (time: string) => <span>{dayjsFormat(time, 'YYYY-MM-DD')}</span>,
+      width: 20
     },
     {
       title: '操作',
       dataIndex: 'opreate',
       // eslint-disable-next-line react/display-name
-      render:(_: string, record: iFileState) =>
-      <div>
+      render:(_: string, record: iFileState) => {
+        return <div>
         <a className="pi-mg-right-5" download href={consts.OSS_PATH.DOWNLOAD + record.filepath}>下载</a>
         <span className="pi-link-red" onClick={() => deleteFile(record.id)}>删除</span>
       </div>
+      },
+      width: 15
     }
   ]
   return (
@@ -86,7 +91,7 @@ const File:React.FC<{}> = () => {
       pagination={{
         hideOnSinglePage: true,
         size: "small",
-        pageSize: consts.PAGE_SIZE,
+        pageSize: 7,
         onChange: (page, pageSize) => initData(page, pageSize),
         total
       }}

+ 2 - 2
src/pages/Quality/Content/Info/Detail/index.tsx

@@ -1,12 +1,12 @@
 import { ZhSubmitButton, ZhUploadButton } from '@/components/Button'
 import DatePicker from '@/components/DatePicker'
-import { apiGetFileList } from '@/components/FileModal/api'
 import Header from '@/components/Header'
 import Slot from '@/components/Header/slot'
 import OssUploadModal from '@/components/OssUpload'
 import SvgIcon from '@/components/SvgIcon'
 import { userStore } from '@/store/mobx'
 import { iFile } from '@/types/file'
+import { apiGetFileList, apiSaveFileInfo } from '@/utils/common/api'
 import consts from '@/utils/consts'
 import { dayjsFormat } from '@/utils/util'
 import { Button, Input, Pagination, Tooltip } from 'antd'
@@ -14,7 +14,7 @@ import locale from 'antd/es/date-picker/locale/zh_CN'
 import dayjs from 'dayjs'
 import React, { useEffect, useState } from 'react'
 import { RouteComponentProps } from 'react-router'
-import { apiGetSafeDetail, apiSaveFileInfo } from './api'
+import { apiGetSafeDetail } from './api'
 import styles from './index.module.scss'
 const { TextArea } = Input
 interface iDetailState {

+ 0 - 12
src/pages/Safe/Content/Info/Detail/api.ts

@@ -1,4 +1,3 @@
-import { iFile } from "@/types/file"
 import request from "@/utils/common/request"
 
 /**
@@ -9,14 +8,3 @@ export async function apiGetSafeDetail(id: string) {
   const { data } = await request.get('/api/safe/detail', { id })
   return data
 }
-
-/**
- *
- * @param fileList - 附件数组
- * @param dataType - 类型
- * @param dataId - 数据id
- */
-export async function apiSaveFileInfo(fileList: iFile[], dataType: number, dataId: string) {
-  const { data } = await request.post('/api/file', { fileList, dataType, dataId })
-  return data
-}

+ 2 - 3
src/pages/Safe/Content/Info/Detail/index.tsx

@@ -1,13 +1,12 @@
 import { ZhSubmitButton, ZhUploadButton } from '@/components/Button'
 import DatePicker from '@/components/DatePicker'
-import { apiGetFileList } from '@/components/FileModal/api'
 import Header from '@/components/Header'
 import Slot from '@/components/Header/slot'
 import OssUploadModal from '@/components/OssUpload'
 import SvgIcon from '@/components/SvgIcon'
 import { userStore } from '@/store/mobx'
 import { iFile } from '@/types/file'
-import { apiDelFile } from '@/utils/common/api'
+import { apiDelFile, apiGetFileList, apiSaveFileInfo } from '@/utils/common/api'
 import consts from '@/utils/consts'
 import { dayjsFormat } from '@/utils/util'
 import { Button, Input, Pagination, Tooltip } from 'antd'
@@ -15,7 +14,7 @@ import locale from 'antd/es/date-picker/locale/zh_CN'
 import dayjs from 'dayjs'
 import React, { useEffect, useState } from 'react'
 import { RouteComponentProps } from 'react-router'
-import { apiGetSafeDetail, apiSaveFileInfo } from './api'
+import { apiGetSafeDetail } from './api'
 import styles from './index.module.scss'
 const { TextArea } = Input
 interface iDetailState {

+ 28 - 0
src/utils/common/api.ts

@@ -1,6 +1,18 @@
+import { iFile } from "@/types/file"
 import request from "./request"
 
 /**
+ * 保存文件信息
+ * @param fileList - 附件数组
+ * @param dataType - 类型
+ * @param dataId - 数据id
+ */
+export async function apiSaveFileInfo(fileList: iFile[], dataType: number, dataId: string) {
+  const { data } = await request.post('/api/file', { fileList, dataType, dataId })
+  return data
+}
+
+/**
  * 删除附件
  * @param id 附件id
  */
@@ -8,3 +20,19 @@ export async function apiDelFile(id:string) {
   const { data } = await request.del('/api/file', { id })
   return data
 }
+
+/**
+ * 根据类型获取附件列表
+ * @param dataType - 类型
+ * @param dataId - 数据id
+ */
+export async function apiGetFileList(dataType: number, dataId: string, pageNo: number, pageSize: number) {
+  const { data } = await request.get('/api/file', { dataType, dataId, pageNo, pageSize })
+  return data
+}
+
+// 获取签名
+export async function getSignature() {
+  const { data } = await request.get('/api/oss/signature')
+  return data
+}

+ 1 - 1
src/utils/consts.ts

@@ -11,7 +11,7 @@ export default {
   RET_CODE: { SUCCESS: 0, FAIL: 1, TOKEN_UNDEFINED: 19, TOKEN_EXPIRED: 1 }, // 接口返回状态码
   RETRY: { COUNT: 3, DELAY: 1000 }, // 请求重试次数/间隙
   RULE: { SAFE: 'safeRule', QUALITY: 'qualityRule', CONTRACT: 'contractRule' }, // 编号规则弹窗常量
-  UPLOAD_WHITE: [ '.json', '.txt','.xls', '.xlsx','.doc', '.docx','.pdf','.ppt', '.pptx','.png', '.jpg', '.jpeg', '.gif', '.bmp', '.cad', '.dwg','.zip', '.rar', '.7z' ], // 上传类型-白名单
+  UPLOAD_WHITE: "(.json|.txt|.xls|.xlsx|.doc|.docx|.pdf|.ppt|.pptx|.png|.jpg|.jpeg|.gif|.bmp|.cad|.dwg|.zip|.rar|.7z)$"  , // 上传类型-白名单
   UPLOAD_LIMIT: 30, // 上传限制30MB
   DATA_TYPE: { RETURN: 1, QUALITY: 2, SAFE: 3, CONTRACT: 4 }, // 附件类型
   PAGE_SIZE: 10, // 默认页数