Giter Site home page Giter Site logo

curd's Introduction

可视化CURD代码生成工具.

源码

gitee地址:https://gitee.com/iszsw/curd

github地址:https://github.com/iszsw/curd

文档

https://doc.zsw.ink

演示

https://demo.curd.zsw.ink/

安装

# 运行环境要求 PHP8+
composer require iszsw/curd

在线编辑生成页面

curd作为surface的自定义组件,完全遵循surface的开发规范,因此,你可以直接在surface中调用curd组件,无需任何配置,直接使用即可。

// 演示地址完整代码
<?php

use curd\Curd;
use surface\components\Input;
use surface\components\Number;
use surface\components\Upload;
use surface\components\TableColumn;

// 预定义的列
$tableColumns = [
    (new TableColumn())->props(['label' => '用户名', 'prop' => 'username']),
    (new TableColumn())->props(['label' => '年龄', 'prop' => 'age']),
    (new TableColumn())->props(['label' => '手机号', 'prop' => 'phone']),
    (new TableColumn())->props(['label' => '邮箱', 'prop' => 'email']),
    (new TableColumn())->props(['label' => '头像', 'prop' => 'avatar']),
    (new TableColumn())->props(['label' => '注册时间', 'prop' => 'create_time']),
];
$formColumns = [
    (new Input(["label" => "用户名", "name" => "username"]))->rules(['required' => true, 'message' => '请输入用户名']),
    (new Number(["label" => "年龄", "name" => "age"])),
    (new Input(["label" => "手机号", "name" => "phone"])),
    (new Input(["label" => "邮箱", "name" => "email"])),
    (new Upload(["label" => "头像", "name" => "avatar"])),
];

// curd组件
$curd = (new Curd())->props([
    'extComponent' => [
        [
            'label'      => "扩展组件",
            'components' => [
                [
                    'component' => [
                        (new Input(['label' => 'Input1', 'name' => '第一项'])),
                        (new Input(['label' => 'Input2', 'name' => '第二项']))
                    ],
                    'label'     => '批量插入',
                    'icon'      => "组件"
                ],
            ],
        ]
    ],
    "default-form" => [
        'options' => new \stdClass(),
        'columns' => $formColumns,
    ],
    "default-table" => [
        'options' => [
            "request" => [
                "url" => ""
            ]
        ],
        'columns' => $tableColumns,
    ]
]);

// 渲染页面
echo $curd->view();

222a7427e2be6c9a942.png 1117cdbd92582b91ebd.png QQ202403251635191c1fb503a8cc3af6.png

根据数据库源生成默认配置

调用 Curd::withDbSource(\PDO $pdo, string $database, string $tableName = '') 方法,指定数据库源,生成默认配置。

下面提供一个ThinkPHP在页面上选择数据库源的示例:

// 从参数中获取表名
$table = $this->request->get('table', '');

$curd = (new \curd\Curd())->props([
    'extComponent' => [
        [
            'label'      => "扩展组件",
            'components' => [
                [
                    'component' => [
                        (new Input(['label' => 'Input1', 'name' => 'Input1'])),
                        (new Input(['label' => 'Input2', 'name' => 'Input2']))
                    ],
                    'label'     => '批量插入',
                    'icon'      => "组件"
                ],
            ],
        ]
    ],
])
// Tp框架获取Pdo连接:Db::connect()->connect()
->withDbSource(Db::connect()->connect(), '数据库名', $table);

$surface = new Surface();

// 下面代码提供一个下拉选择框浮动到页面上,选中表名之后生成默认配置
$surface->addStyle(
"<style>
.table-list{
    position: fixed;
    top: 10px;
    right: 510px;
    z-index: 99;
    width: 200px;
}
</style>");

$tableNames = [];
foreach (Db::query("SHOW TABLES") as $info) {
    $name = $info['Tables_in_surface'];
    $tableNames[$name] = $name;
}
$surface->append((new Select())->props([
    'class' => "table-list",
    'filterable' => true,
    'model-value' => new Vmodel("cur_table_name", $table),
    'model-value' => $table,
    // 将选中的表名同步到url刷新页面
    'onChange' => Functions::create(<<<JS
let url = window.location.href
let paramName = 'table'
let pattern = new RegExp('(' + paramName + '=).*?(&|$)');
if (url.search(pattern)>=0) {
    url = url.replace(pattern,'$1' + name + '$2');
} else {
    url += (url.indexOf('?')>0 ? '&' : '?') + paramName + '=' + name;
}
window.location.href = url;
JS, ['name'])
])->options($tableNames));
$surface->append($curd);

return $surface->view();

image4aa85ece7f21ff1f.png

curd's People

Contributors

iszsw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

curd's Issues

缺少完善的文档

文档缺失,
配置里只有路由前缀,
生成菜单后的地址一般是什么样?如何访问 只能看demo才知道是curd/page/index?_table=z_user,生成菜单感觉有歧义,只是生成路由映射吧,所有的数据表配置保存在配置里,不透明。
然后上传改了之后上传报错403
去看源码suface 才知道要返回

echo json_encode(
    [
        'code' => 0,
        'msg'  => 'success',
        'data' => [
            'url'  => 'http://q1.qlogo.cn/g?b=qq&nk=191587'.rand(100, 999).'&s=640',
        ],
    ], JSON_UNESCAPED_UNICODE
);

这种格式,
相当于上传后的字段只能存路径,像一般cms是上传后插入附件表md5 去重,返回id,展示用id获取路径的。

curd如何使用可编辑开关?

数据库表在tinyint字段下应该如何配置,定义开关修改键值为0或者1?
直接采用默认设置无法修改数据

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.