From c9a263f8701bea0ad0eaac3d251f9e35cad5aa64 Mon Sep 17 00:00:00 2001 From: 王强 Date: Fri, 23 Feb 2024 15:58:29 +0800 Subject: [PATCH] init --- api.ts | 30 ++++++++++++++++++++++++++++++ components/Filter.tsx | 43 +++++++++++++++++++++++++++++++++++++++++++ components/List.tsx | 46 ++++++++++++++++++++++++++++++++++++++++++++++ components/Modal.tsx | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.tsx | 27 +++++++++++++++++++++++++++ interface.d.ts | 5 +++++ store.ts | 17 +++++++++++++++++ 7 files changed, 232 insertions(+), 0 deletions(-) create mode 100644 api.ts create mode 100644 components/Filter.tsx create mode 100644 components/List.tsx create mode 100644 components/Modal.tsx create mode 100644 index.tsx create mode 100644 interface.d.ts create mode 100644 store.ts diff --git a/api.ts b/api.ts new file mode 100644 index 0000000..76fdf78 --- /dev/null +++ b/api.ts @@ -0,0 +1,30 @@ +import type { http } from "@/typing/http"; +import { ARCHIVES_HOST } from "@/utils/host"; +import request from "@/utils/request"; + +/** + * @description: 分页获取替换name + * @param {替换name.QueryParams} params + * @return {http.PromisePageResp<替换name.ListVO>} + */ +export function get替换nameListApi(params: 替换name.QueryParams): http.PromisePageResp<替换name.ListVO> { + return request.get(`API url`, { params }); +} + +/** + * @description: 保存替换name + * @param {替换name.ListVO} params + * @return {http.PromiseResp} + */ +export function save替换nameApi(params: 替换name.ListVO): http.PromiseResp { + return request.post(`API url`, params); +} + +/** + * @description: 删除替换name + * @param {number} id + * @return {http.PromiseResp} + */ +export function delete替换nameApi(id: number): http.PromiseResp { + return request.get(`API url`, { params: { id } }); +} diff --git a/components/Filter.tsx b/components/Filter.tsx new file mode 100644 index 0000000..b678ebe --- /dev/null +++ b/components/Filter.tsx @@ -0,0 +1,43 @@ +import React from "react"; +import { Button, Row, Input } from "antd"; +import { PlusOutlined } from "@ant-design/icons"; +import { useStore } from "../index"; +import FeeweeFilterOption from "@/pages/notice/components/FeeweeFilterOption"; + +export default function Filter() { + const { pagination, setOpen } = useStore(); + + return ( + +
+ + pagination.setParams({ keyWords: e.target.value })} + onSearch={() => pagination.setParams({ current: 1 }, true)} + /> + +
+ +
+ ); +} diff --git a/components/List.tsx b/components/List.tsx new file mode 100644 index 0000000..f1e7ae1 --- /dev/null +++ b/components/List.tsx @@ -0,0 +1,46 @@ +import React from "react"; +import { Divider, message, Popconfirm, Popover, Table } from "antd"; +import { delete替换nameApi } from "../api"; +import { useStore } from "../index"; + +export default function List() { + const { pagination, setCurrent, setOpen } = useStore(); + + function editItem(item: 替换name.ListVO) { + setCurrent(item); + setOpen(true); + } + + function deleteItem(id: number) { + const hide = message.loading('删除中,请稍后...', 0); + delete替换nameApi(id) + .then((res) => { + hide(); + message.success(res.result); + pagination.setLoading(true); + }) + .catch((error) => { + hide(); + message.error(error.message); + }); + } + + return ( + + + 替换name.ListVO) => ( + <> + 编辑 + + 确定删除?} onConfirm={() => deleteItem(record.id || -1)}> + 删除 + + + )} + /> +
+ ); +} diff --git a/components/Modal.tsx b/components/Modal.tsx new file mode 100644 index 0000000..62e9113 --- /dev/null +++ b/components/Modal.tsx @@ -0,0 +1,64 @@ +import React, { useEffect, useState } from "react"; +import { Form, Input, message, Modal as AntdModal, Spin } from "antd"; +import { save替换nameApi } from "../api"; +import { useStore } from "../index"; + +export default function Modal() { + const { pagination, current, setCurrent, open, setOpen } = useStore(); + const [form] = Form.useForm(); + const [confirmLoading, setConfirmLoading] = useState(false); + + useEffect(() => { + if (open && current) { + form.setFieldsValue(current); + } else { + form.resetFields(); + } + }, [open, current]); + + function onOk(val: any) { + const hide = message.loading('提交中,请稍后...', 0); + setConfirmLoading(true); + const params: 替换name.ListVO = { + ...val, + id: current?.id, + }; + save替换nameApi(params) + .then((res) => { + hide(); + setConfirmLoading(false); + message.success(res.result); + onCancel(); + pagination.setLoading(true); + }) + .catch((error) => { + hide(); + setConfirmLoading(false); + message.error(error.message); + }); + } + + function onCancel() { + setCurrent(undefined); + setOpen(false); + } + + return ( + 替换name`} + open={open} + maskClosable={false} + onOk={form.submit} + confirmLoading={confirmLoading} + onCancel={onCancel} + > + +
+ + + +
+
+
+ ); +} diff --git a/index.tsx b/index.tsx new file mode 100644 index 0000000..24f1519 --- /dev/null +++ b/index.tsx @@ -0,0 +1,27 @@ +import React from "react"; +import { ConfigProvider } from "antd"; +import zhCN from "antd/lib/locale-provider/zh_CN"; +import { PageHeaderWrapper } from "@ant-design/pro-layout"; +import { createStore } from "@/hooks/moz"; +import store from './store'; +import Filter from './components/Filter'; +import List from './components/List'; +import Modal from './components/Modal'; + +export const { Provider, useStore } = createStore(store); + +export default () => <替换name />; + +function 替换name() { + return ( + + + + + + + + + + ); +} diff --git a/interface.d.ts b/interface.d.ts new file mode 100644 index 0000000..5ab3f23 --- /dev/null +++ b/interface.d.ts @@ -0,0 +1,5 @@ +declare namespace 替换name { + interface QueryParams {} + + interface ListVO {} +} diff --git a/store.ts b/store.ts new file mode 100644 index 0000000..22d6f90 --- /dev/null +++ b/store.ts @@ -0,0 +1,17 @@ +import { useState } from 'react'; +import usePagination from "@/hooks/usePagination"; +import { get替换nameListApi } from "./api"; + +export default function useStore() { + const pagination = usePagination(get替换nameListApi); + const [open, setOpen] = useState(false); + const [current, setCurrent] = useState<替换name.ListVO>(); + + return { + pagination, + open, + setOpen, + current, + setCurrent, + }; +} -- libgit2 0.22.2