npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-crud-kit

v1.0.3

Published

```tsx import { CrudComponent } from "react-crud-kit";

Readme

使用案例

import { CrudComponent } from "react-crud-kit";

import React, { useEffect, useState, useRef } from "react";
import type {
  CrudExposeMethods,
  IBasePagination,
  ICrudOption,
} from "react-crud-kit";
import { Button, Space, Modal } from "antd";
import {
  getActiveList, //获取list接口
  editActive, //编辑接口
  addActive, //新增接口
  removeActive, //删除/批量删除接口
  getActiveDetail, // 获取详情接口
} from "@/api/research";

const TestCrud: React.FC = () => {
  const tableOption: ICrudOption = {
    title: "活动",
    bordered: true,
    showAddButton: true,
    addButtonText: "新增",
    showBatchDeleteButton: true,
    batchDeleteButtonText: "批量删除",
    showEditButton: true,
    showDeleteButton: true,
    showSearch: true,
    searchSpan: 6,
    selection: true,
    checkOrRadio: "checkbox",
    columns: [
      {
        label: "竞赛标题",
        name: "title",
        type: "input",
        form: { show: true, required: true },
        table: { show: true },
        search: { show: true },
      },
      {
        label: "开始时间",
        name: "startTime",
        type: "datePicker",
        props: {
          valueFormat: "YYYY-MM-DD HH:mm:ss",
          format: "YYYY-MM-DD HH:mm:ss",
          showTime: true,
          style: { width: "100%" },
        },

        form: { show: true, required: true },
        table: { show: true },
        search: { show: true },
      },
      {
        label: "结束时间",
        name: "endTime",
        type: "datePicker",
        props: {
          valueFormat: "YYYY-MM-DD HH:mm:ss",
          format: "YYYY-MM-DD HH:mm:ss",
          showTime: true,
          style: { width: "100%" },
        },
        form: { show: true, required: true },
        table: { show: true },
        search: { show: true },
      },
      {
        label: "活动详情",
        name: "content",
        type: "input",
        form: { show: true, required: true },
        table: { show: true },
        search: { show: false },
      },
      {
        label: "活动海报图片",
        name: "pic",
        type: "uploadPicture",
        fileUpload: {
          multiple: false,
          maxCount: 5,
          headers: {
            "Blade-Auth": "bearer " + localStorage.getItem("token"),
            Authorization: "Basic c2FiZXI6c2FiZXJfc2VjcmV0",
          },
          propsHttp: {
            res: "data",
            url: "link",
            name: "originalName",
          },
          action: "/api/blade-resource/oss/endpoint/put-file-attach",
        },

        form: { show: true, required: true },
        table: {
          show: true,
          render: (text: string) => {
            return (
              <img
                src={text}
                alt=""
                style={{ width: "50px", height: "50px" }}
              />
            );
          },
        },
      },
      {
        type: "uploadFile",
        name: "fileList",
        label: "活动文件",
        dataType: "array",
        fileUpload: {
          multiple: true,
          maxCount: 5,
          headers: {
            "Blade-Auth": "bearer " + localStorage.getItem("token"),
            Authorization: "Basic c2FiZXI6c2FiZXJfc2VjcmV0",
          },
          propsHttp: {
            res: "data",
            url: "link",
            name: "originalName",
          },
          action: "/api/blade-resource/oss/endpoint/put-file-attach",
        },

        form: { show: true, required: true },
        table: {
          show: false,
          render: (picList: any[]) => {
            return (
              <>
                {picList?.length > 0 &&
                  picList.map((item, index) => {
                    return (
                      <div key={index}>
                        <a href={item.url} target="_blank">
                          {item.name || item.originalName}
                        </a>
                      </div>
                    );
                  })}
              </>
            );
          },
        },
      },
      {
        label: "活动状态",
        name: "status",
        type: "select",
        options: [
          {
            label: "进行中",
            value: 1,
          },
          {
            label: "已结束",
            value: 2,
          },
        ],
        form: { show: false, required: true },
        table: { show: true },
        search: { show: true },
      },
      {
        label: "参加人数",
        name: "number",
        type: "datePicker",
        form: { show: false, required: true },
        table: { show: true },
        search: { show: false },
      },
      {
        type: "custom",
        name: "actions",
        label: "操作",
        table: {
          show: true,
          isActionColumn: true,
          showEdit: true,
          showDelete: true,
          editButtonType: "primary",
          deleteButtonColor: "danger",
          render: (_, record: any) => {
            return (
              <Space>
                <div
                  onClick={async () => {
                    const res = await getActiveDetail({ id: record.id });
                    crudRef.current?.openEditModal(res);
                  }}
                >
                  <Button type="primary">编辑</Button>
                </div>
                <div onClick={() => deleteUsers([record.id])}>
                  <Button color="danger">删除</Button>
                </div>
              </Space>
            );
          },
        },
      },
    ],
  };

  const crudRef = useRef<CrudExposeMethods>(null);
  const [pagination, setPagination] = useState<IBasePagination>({
    current: 1,
    pageSize: 2,
    total: 0,
    handlePageChange: (current: number, pageSize: number) => {
      setPagination({
        ...pagination,
        current,
        pageSize,
      });
    },
    handleSizeChange: (current: number, pageSize: number) => {
      setPagination({
        ...pagination,
        current,
        pageSize,
      });
    },
  });
  const [loading, setLoading] = useState(false);
  const [listData, setListData] = useState<any[]>([]);

  const fetchActiveList = (data?: any) => {
    setLoading(true);
    getActiveList({
      current: pagination.current,
      size: pagination.pageSize,
      ...data,
    }).then((res) => {
      setListData(res.records || []);
      setPagination({
        ...pagination,
        total: res.total,
      });
      setLoading(false);
    });
  };
  const onSearch = (data: any) => {
    console.log("查询用户列表", data);
    fetchActiveList(data);
  };
  const addUser = (data: any) => {
    console.log("添加用户", data);
    //构造上传信息
    const info = {
      ...data,
      fileList: data.fileList.map((item) => {
        return {
          name: item.name,
          url: item.url,
        };
      }),
      pic: data.pic[0].url,
    };
    addActive(info).then((res) => {
      if (res.code === 200) {
        fetchActiveList();
      }
    });
  };
  const updateUser = (data: any) => {
    console.log("更新用户", data, listData);
    const info = {
      ...data,
      fileList: data.fileList.map((item) => {
        return {
          name: item.name,
          url: item.url,
        };
      }),
      pic: data.pic[0].url,
    };
    editActive(info).then((res) => {
      if (res.code === 200) {
        fetchActiveList();
      }
    });
  };
  const deleteUsers = (ids: number[]) => {
    console.log("删除用户", ids);
    Modal.confirm({
      content: "是否删除已选内容",
      onOk: () => {
        removeActive({ ids: ids.join(",") }).then((res) => {
          if (res.code === 200) {
            fetchActiveList();
          }
        });
      },
    });
  };

  useEffect(() => {
    fetchActiveList();
  }, [pagination.current, pagination.pageSize]);

  return (
    <div>
      <CrudComponent
        pagination={pagination}
        ref={crudRef}
        listData={listData}
        loading={loading}
        option={tableOption}
        onSearch={onSearch}
        onAdd={addUser}
        onUpdate={updateUser}
        onDelete={deleteUsers}
      ></CrudComponent>
    </div>
  );
};
export default TestCrud;