diff --git a/.env b/.env index c88bfa87a22755c2d199681a49e018e1e00cc83a..25241b73a372f72529115704bdd0a03940374f54 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -PORT=8080 \ No newline at end of file +PORT=8080 diff --git a/config/proxy.ts b/config/proxy.ts index c18094120b044ce25c315a95a66589a090d1c156..6333b688613ecdcb1f554dfe862797f74fc55426 100644 --- a/config/proxy.ts +++ b/config/proxy.ts @@ -7,23 +7,18 @@ * https://pro.ant.design/docs/deploy */ -const ip = `30.225.24.17` -const port = `8005` +const ip = `127.0.0.1`; +const port = `8005`; -const devTargetUri = `http://${ip}:${port}` +const devTargetUri = `http://${ip}:${port}`; export default { dev: { - '/case/': { + '/api/': { target: devTargetUri, changeOrigin: true, pathRewrite: { '^': '' }, }, - "/module/": { - target: devTargetUri, - changeOrigin: true, - pathRewrite: { '^': '' }, - } }, test: { '/api/': { diff --git a/src/pages/Outline/components/AddModal.tsx b/src/pages/Outline/components/AddModal.tsx index 2e2c2c506d3c89b8fcdbf13a7aea8549ee6f259c..cf29c189d0ed20eef8df66cfa2a6e9928e551dfb 100644 --- a/src/pages/Outline/components/AddModal.tsx +++ b/src/pages/Outline/components/AddModal.tsx @@ -1,42 +1,46 @@ -import React from "react" -import { Modal, Form, Input, Space, Button, message, Upload } from "antd" -import { create, update } from "../services"; +import React from 'react'; +import { Modal, Form, Input, Space, Button, message, Upload } from 'antd'; +import { create, update } from '../services'; import { UploadOutlined } from '@ant-design/icons'; type IProps = { onOk: () => void; onCancel?: () => void; -} +}; type IRefs = { - [k: string]: any -} + [k: string]: any; +}; const AddOutlineModal: React.ForwardRefRenderFunction = (props, ref) => { - const { onOk } = props + const { onOk } = props; + const [form] = Form.useForm(); - const [visible, setVisible] = React.useState(false) - const [loading, setLoading] = React.useState(false) - const [source, setSource] = React.useState(undefined) + const [visible, setVisible] = React.useState(false); + const [loading, setLoading] = React.useState(false); + const [source, setSource] = React.useState(undefined); + const [file, setFile] = React.useState(undefined); React.useImperativeHandle(ref, () => ({ show(_: any) { - setSource(_) - setVisible(true) - form.setFieldsValue(_) - } - })) + setSource(_); + setVisible(true); + form.setFieldsValue(_); + }, + })); - const [form] = Form.useForm() + const on_change = (info: any) => { + setFile(info.file.originFileObj); + }; const handleCancel = () => { - setVisible(false) - setLoading(false) - setSource(undefined) - } + setVisible(false); + setLoading(false); + setSource(undefined); + setFile(undefined); + }; const normFile = (e: any) => { - console.log('Upload event:', e); if (Array.isArray(e)) { return e; } @@ -44,60 +48,71 @@ const AddOutlineModal: React.ForwardRefRenderFunction = (props, r }; const handleOk = async () => { - if (loading) return - - const { code, msg } = source ? await update() : await create() + if (loading) return; + const formData = new FormData(); + formData.append('outline', file); + formData.append('title', form.getFieldValue('title')); + formData.append('remark', form.getFieldValue('remark')); + const { code, msg } = source ? await update(source.id, formData) : await create(formData); if (code !== 200) { - setLoading(true) - message.error(msg) - return + setLoading(true); + message.error(msg); + return; } - setLoading(true) - onOk() - handleCancel() - } + form.resetFields(); + + setLoading(true); + onOk(); + handleCancel(); + }; return ( - + } onCancel={handleCancel} onOk={handleOk} > -
- + + - - - +
+ + + +
- +
- ) -} + ); +}; -export default React.forwardRef(AddOutlineModal) \ No newline at end of file +export default React.forwardRef(AddOutlineModal); diff --git a/src/pages/Outline/index.tsx b/src/pages/Outline/index.tsx index 754e929a327eb1e0c151840d5e2dae492ef2d35a..ec4dfbbbd5a0ec43cd612cdca0569f41ea2d258c 100644 --- a/src/pages/Outline/index.tsx +++ b/src/pages/Outline/index.tsx @@ -1,69 +1,116 @@ -import React from "react" -import { Table, Space, Typography, Row, Button } from "antd" -import { queryTableList } from "./services" -import { useRequest } from "ahooks" -import AddModal from "./components/AddModal" +import React from 'react'; +import { Table, Space, Typography, Row, Button } from 'antd'; +import { queryTableList, deleteOutline, download } from './services'; +import { useRequest } from 'ahooks'; +import AddModal from './components/AddModal'; +import { message } from '_antd@4.19.5@antd'; -const DEFAULT_PAGE_QUERY = { page_size: 20, page_num: 1 } +const DEFAULT_PAGE_QUERY = { page_size: 20, page_num: 1 }; const TestDemand: React.FC = () => { - const [pageQuery, setPageQuery] = React.useState(DEFAULT_PAGE_QUERY) + const [pageQuery, setPageQuery] = React.useState(DEFAULT_PAGE_QUERY); - const { data: dataSource, loading, refresh } = useRequest( - (params = pageQuery) => queryTableList(params), - { refreshDeps: [pageQuery] } - ) + const { + data: dataSource, + loading, + refresh, + } = useRequest((params = pageQuery) => queryTableList(params), { refreshDeps: [pageQuery] }); - const addModalRef = React.useRef(null) as any + const addModalRef = React.useRef(null) as any; const handleAdd = async () => { - addModalRef.current?.show() - } + addModalRef.current?.show(); + }; const handleEdit = async (row: any) => { - addModalRef.current?.show(row) - } + addModalRef.current?.show(row); + }; const handleDelete = async (row: any) => { + const { code, msg } = await deleteOutline(row.id); - } + if (code !== 200) { + message.error(msg); + return; + } + refresh(); + }; - const columns = [{ - title: "标题", - dataIndex: "", - }, { - title: "大纲文件", - dataIndex: "", - }, { - title: "备注", - dataIndex: "", - }, { - title: "创建人", - dataIndex: "", - }, { - title: "创建日期", - dataIndex: "", - }, { - title: "操作", - render(row: any) { - return ( - - handleEdit(row)}> - 编辑 - - handleDelete(row)}> - 删除 - - - ) + const handleDownload = async (row: any) => { + const data = await download(row.id); + const fileContent = row.name.split('.'); + const fileSuffix = fileContent[fileContent.length - 1]; + let fileAppType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + if (fileSuffix === 'doc') { + fileAppType = 'application/msword'; + } else if (fileSuffix == 'pdf') { + fileAppType = 'application/pdf'; + } else if (fileSuffix == 'txt') { + fileAppType = 'text/plain'; + } else { } - }] + const blob = new Blob([data], { + type: fileAppType, + }); + const objectURL = URL.createObjectURL(blob); + const btn = document.createElement('a'); + btn.download = row.name; + btn.href = objectURL; + btn.click(); + URL.revokeObjectURL(objectURL); + message.success('下载成功'); + }; + + const columns = [ + { + title: '标题', + dataIndex: 'title', + }, + { + title: '大纲文件', + dataIndex: 'name', + }, + { + title: '备注', + dataIndex: 'remark', + }, + { + title: '创建人', + dataIndex: 'owner', + }, + { + title: '创建日期', + dataIndex: 'gmt_created', + }, + { + title: '操作', + render(row: any) { + return ( + + handleEdit(row)}> + 编辑 + + handleDelete(row)}> + 删除 + + handleDownload(row)}> + 下载 + + + ); + }, + }, + ]; return ( - + - 测试大纲 - + + 测试大纲 + + { current: pageQuery.page_num, pageSize: pageQuery.page_size, onChange(page_num, page_size) { - setPageQuery({ page_num, page_size }) - } + setPageQuery({ page_num, page_size }); + }, }} /> - + - ) -} + ); +}; -export default TestDemand \ No newline at end of file +export default TestDemand; diff --git a/src/pages/Outline/services.ts b/src/pages/Outline/services.ts index aa6453b4e5469dd815bd6a626d6ded31a307fb6e..151451529fa9440aef3f6f417520dcc64e3713e4 100644 --- a/src/pages/Outline/services.ts +++ b/src/pages/Outline/services.ts @@ -1,13 +1,35 @@ -import { request } from "umi" +import { request } from 'umi'; -export const queryTableList = async () => { - return request(`/api/xxx`) -} +const OUTLINE_API_PREFIX = '/api/outline'; +const OUTLINE_UPLOAD_API = `${OUTLINE_API_PREFIX}/upload`; +const OUTLINE_DOWNLOAD_API = `${OUTLINE_API_PREFIX}/download`; +const OUTLINE_EDIT_API = `${OUTLINE_API_PREFIX}/edit`; +const OUTLINE_QUERY_API = `${OUTLINE_API_PREFIX}/list`; -export const update = async () => { - return request(`/api/xxx`) -} +export const create = async (data: any) => { + return request(OUTLINE_UPLOAD_API, { method: 'post', requestType: 'form', data: data }); +}; -export const create = async () => { - return request(`/api/xxx`) -} \ No newline at end of file +export const download = async (file_id: any) => { + return request(`${OUTLINE_DOWNLOAD_API}/${file_id}`, { method: 'get', responseType: 'blob' }); +}; + +export const queryTableList = async (params: any) => { + return request(OUTLINE_API_PREFIX, { method: 'get', params }); +}; + +export const update = async (file_id: any, data: any) => { + return request(`${OUTLINE_EDIT_API}/${file_id}`, { + method: 'put', + requestType: 'form', + data: data, + }); +}; + +export const deleteOutline = async (file_id: any) => { + return request(`${OUTLINE_API_PREFIX}/${file_id}`, { method: 'delete' }); +}; + +export const query = async (params: any) => { + return request(`${OUTLINE_QUERY_API}`, { method: 'get', params }); +};