amirsadjad/simple-list-formatter

简单的列表格式化工具,方便UI开发使用。

dev-main 2022-11-16 20:19 UTC

This package is auto-updated.

Last update: 2024-09-17 12:03:52 UTC


README

简单的列表格式化工具,方便UI开发使用。

这是一个用于根据UI需求格式化数据集合的包。您可以对“laravel collection”、“eloquent collection”和“array”进行格式化。您可以在数据库中为应用中的每一页创建预设,然后将数据和预设传递给外观,获取带有所需列、可排序、可搜索和动态分页的解析结果。您还可以将元数据传递给预设,并将其与结果列表一起传递给UI。

要安装,运行以下命令

composer require amirsadjad/simple-list-formatter

然后通过运行以下命令发布配置文件

php artisan vendor:publish --tag=simple-list-formatter-config

要迁移表,运行以下命令

php artisan migrate

基本用法

use Amirsadjad\SimpleListFormatter\Facades\SimpleList;

// you need to start by using the function Of()
$list = SimpleList::Of($data, $preset);

// you can chain other methods
$list->search($query);
$list->sortBy($columnName, false);
$list->pageNumber($pageNumber);

// you have to run the generate() at the end to parse the data
$list->generate()

要与预设表交互,您可以使用模型类

SimpleListPresets::find($name);

// preset data needs to be formatted like this
$preset = [
  'columns' => [
    'column_name' => [
      'data_type' => 'string',
      'is_sortable' => 'bool',
      'is_searchable' => 'bool',
      'width' => 'int',
      'title' => 'string',
      'metadata' => 'array'
    ],
    ...
    ..
    .
  ],
  'page_size' => 'int',
];

或者您可以使用内置的API: https://www.getpostman.com/collections/64bcf64f6a05fc87cc8b

您可以在以下链接中看到一个如何在该项目中使用此包的示例: https://github.com/Amirsadjad/simple-list-formatter-example