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

@we-weaver/scene-table-list

v0.1.1

Published

快速生成表格场景

Downloads

3

Readme

Weaver table scene

Usage

最少配置项

const tableColumns = [
  {
    prop: 'tempCode',
    label: '模板编号',
  },
  {
    prop: 'tempName',
    label: '模板名称',
    showOverflowTooltip: true,
  },
];

const config = tableScene()('/register-order/list-all-dept', {
  table: tableColumns,
});

进阶配置请求

const config = tableScene()(
  {
    url: '/register-order/list-all-dept',
    name: 'getAnotherListData',
    options: {
      method: 'POST',
      success({ $response, $model }) {
        $model.data = $response;
      },
    },
  },
  {
    table: tableColumns,
  }
);

最简筛选配置

const config = tableScene()('/register-order/list-all-dept', {
  table: tableColumns,
  filter: {
    type: {
      component: 'WeSelect',
      options: [
        { value: '0', label: '男' },
        { value: '1', label: '女' },
      ],
    },
    queryContent: 'WeInput',
    $$placeholder: 'DynamicKeyComponent',
  },
});

完整筛选配置

const config = tableScene()('/register-order/list-all-dept', {
  table: tableColumns,
  filter: [
    {
      prop: 'type',
      component: 'WeSelect',
      options: [
        { value: '0', label: '男' },
        { value: '1', label: '女' },
      ],
      defaultValue: '0',
    },
    {
      prop: '$$placeholder',
      component: 'DynamicKeyComponent',
    },
  ],
});

完整表格主体配置

const config = tableScene()('/register-order/list-all-dept', {
  table: {
    className: 'vve-mb-3',
    data: '${$model.data.getListData.map(i => ({...i, type: i.type + "1"}))}',
    children: tableColumns,
    size: 'medium',
  },
});

分页器配置

const config = tableScene()('/register-order/list-all-dept', {
  // ...
  pagination: {
    // 如果需要替换分页组件可以用这个
    component: 'AnotherPagination',
    // 剩余的配置项会透传到组件上
  },
});

增加 weaver 其它配置,

新增 weaver 配置项会合并入内置的配置中,同名的属性将会被覆盖 在使用 events, actions 等拥有语法糖的配置时,请使用完整的语法进行书写

const config = tableScene()(
  '/register-order/list-all-dept',
  {
    // ...
  },
  {
    events: [
      {
        type: 'created',
        action({ $actions }) {
          $actions.someAction();
        },
      },
    ],
    model: {
      bizParam: {
        someProps: '',
      },
    },
    actions: {
      someAction() {
        console.log('do something');
      },
    },
  }
);

API

tableScene(options?)(requestConfig, layouts, weaverConfig?)

requestConfig

Type: string | RequestConfig

interface RequestConfig {
  // 列表接口地址
  url: string;
  // 列表接口名称, 不填默认名称为 `getListData`
  name?: string;
  // 同 weaver 内置请求实例配置项
  options?: WeaverRequestConfig;
}

layouts

Type: LayoutConfig

interface LayoutConfig {
  // 表格配置项
  table: TableConfig;
  // 筛选配置项
  filter?: FilterConfig | array<FilterConfig>;
  // 分页器配置项
  pagination?: PaginationConfig;
}
filterConfig
 interface FilterConfig {
   // 组件名称,使用时必选先注册
   component: string;
   // 对应的属性名称,如果是动态属性使用`$$placeholder` 作为占位符
   prop: string;
   // 其余所有配置项会透传
   [propName: string]?: any;
 }

options

Type: object

trigger

Type: string

Default: manual

筛选器触发模式

  • manual 手动触发,点击按钮
  • immediate 立即触发,当筛选条件变动时立即触发
  • enter 按 Enter 触发
syncWithURL

Type: boolean

Default: true

筛选参数同步至 URL,并且每次变动地址栏都会触发列表接口动作

例如 http://test.guahao-test.cn?pageNumber=2&pageSize=10&q=test

enablePagination

Type: boolean

Default: true

是否启用分页

enableIndex

Type: boolean

Default: true

是否启用表格首列的索引值展示

功能描述
  1. 筛选器触发模式(手动,自动触发)
{
  // 触发页面重新请求的方式
  // manual 手动触发,点击按钮
  // immediate 立即触发,当筛选条件变动时立即触发
  // enter 按 Enter 触发
  trigger: 'manual';
}

增加三种触发方式(manual,immediate,enter)按回车触发搜索是否需要和手动触发合并?

  1. 筛选参数放置在 URL 请求体中
{
  // 当开关打开时,每次筛选条件触发时(包括分页),筛选条件会同步到地址栏中
  syncWithURL: true;
}
  1. 筛选器组合
  • 极简模式

    const filters = {
      type: {
        component: 'WeSelect',
        options: [
          { value: '0', label: '男' },
          { value: '1', label: '女' },
        ],
      },
      queryContent: 'WeInput',
      $$placeholder: 'DynamicKeyComponent',
    };
    
    // 转换成 weaver 配置
    
    const filters = [
      {
        component: 'WeSelect',
        extend_dataSource: [
          { value: '0', label: '男' },
          { value: '1', label: '女' },
        ],
        props: {
          value: '$model.filters.type',
        },
      },
      {
        component: 'WeInput',
        props: {
          value: '$model.filters.queryContent',
        },
      },
      {
        component: 'DynamicKeyComponent',
        events: [
          {
            type: 'change',
            action({ $args, $weaver, $model }) {
              const [{ key, value }] = $args;
              $weaver.$set($model.filters, key, value);
            },
          },
        ],
      },
    ];
    
    const model = {
      filters: {
        type: '',
        queryContent: '',
      },
    };
  • 完整模式

    const filters = [
      {
        prop: 'type',
        component: 'WeSelect',
        options: [
          { value: '0', label: '男' },
          { value: '1', label: '女' },
        ],
        defaultValue: '0',
      },
      {
        prop: '$$placeholder',
        component: 'DynamicKeyComponent',
      },
    ];
    
    // 转换成 weaver 配置
    
    const filters = [
      {
        component: 'WeSelect',
        extend_dataSource: [
          { value: '0', label: '男' },
          { value: '1', label: '女' },
        ],
        props: {
          value: '$model.filters.type',
          defaultValue: '0',
        },
      },
      {
        component: 'DynamicKeyComponent',
        events: [
          {
            type: 'change',
            action({ $args, $weaver, $model }) {
              const [{ key, value }] = $args;
              $weaver.$set($model.filters, key, value);
            },
          },
        ],
      },
    ];
    
    const model = {
      filters: {
        type: '0',
      },
    };
  1. 分页功能内置(包括分页参数处理,页码与每页数量变动的处理,重置分页参数)
  • 分页参数转换 内置默认分页参数为 pageNumber, pageSize, totalCount, totalPages,可以通过 renameKeys 来转换接口返回的字段
    {
      pagination: {
        renameKeys: {
          page: 'pageNumber',
          size: 'pageSize',
          total: 'totalCount',
          pages: 'totalPages'
        }
      }
    }