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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-antd-action-buttons

v0.1.4

Published

基于`ant-design-vue@1`的封装,用于表格行的操作按钮渲染。

Downloads

3

Readme

action-buttons

基于ant-design-vue@1的封装,用于表格行的操作按钮渲染。

效果图

默认效果

最多展示 3 个按钮,其余的自动放到【更多】下拉菜单里面

这里 3 个按钮的概念,是包含【更多】在内的。

再看写法

模板渲染就不写了,跟原来都一样。

export default Vue.extend({
  data() {
    return {
      dataSource: [
        { id: 1, username: '张三', disabled: 1 },
        { id: 2, username: '李四', disabled: 0 },
        { id: 3, username: '王二麻子', disabled: 0 },
      ] as MyData[],
      columns: [
        //
        { title: '#', dataIndex: 'id' },
        { title: '姓名', dataIndex: 'username' },
        {
          title: '状态',
          dataIndex: 'disabled',
          customRender: (value: number) => {
            return value === 0 ? (
              <a-tag color="green">启用</a-tag>
            ) : (
              <a-tag>禁用</a-tag>
            );
          },
        },
        useActionButtons<MyData>({
          align: 'center',
          title: '操作',
          limit: 0,
          showDivider: false,
          buttons: [
            { icon: 'search', text: '查看' },
            { icon: 'edit', text: '编辑' },
            {
              text: '禁用',
              visible: (record) => record.disabled === 0,
            },
            {
              text: '启用',
              visible: (record) => record.disabled === 1,
            },
            {
              icon: 'message',
              text(record, index) {
                return `未读消息(${record.id.toString()})`;
              },
            },
            {
              icon: 'delete',
              text: '删除',
              disabled: (record) => record.disabled === 0,
              click: (record, index) => {
                this.$confirm({
                  content: `确认删除${record.username}吗?`,
                });
              },
            },
          ],
        }),
      ],
    };
  },
});

介绍用法

type useActionButtons = (config: ActionButtonsConfig) => Table.Column;

原理就是通过一个函数,返回了一个带customRender的列的配置。

参数介绍

函数声明

export declare interface ActionButtonsConfig<T> extends Table.Column {
  limit: number;
  showDivider: boolean;
  buttons: Array<ActionButtonsColumnConfig<T>>;
}

| 参数 | 类型 | 描述 | | ----------- | -------------- | ---------------------------------------------------------------------------- | | limit | number | 设置一个数量,超过该数量,则展示【更多】下拉按钮。默认 0,表示按钮将全部展示 | | showDivider | boolean | 是否展示分隔符,默认展示 | | buttons | ButtonConfig[] | 要展示的按钮数组,具体配置看下面介绍 |

ButtonConfig

| 参数 | 类型 | 描述 | | --------- | ----------------------------------- | ------------------------------------------------------ | | text? | string | (record, index) => string | 设置按钮文本,同时支持动态设置,参数为当前行的相关数据 | | icon? | string | 设置按钮图标 | | click | (record, index) => void | 设置按钮点击事件,参数为当前行的相关数据 | | disabled? | (record, index) => boolean | 动态设置按钮是否禁用,参数为当前行的相关数据 | | visible? | (record, index) => boolean | 动态设置按钮是否显示,参数为当前行的相关数据 |

安装

npm i action-buttons

使用

目前没有写任何样式文件,样式有问题的话,需要自行在项目处理。
按钮的根节点设置了一个 class="action-buttons"

直接在页面引入

import { useActionButtons } from 'action-buttons';

然后写到 Table Columns 数组里面对应位置即可。

感谢

感谢阅读,欢迎交流。