11 Star 107 Fork 26

我的代码去哪儿了 / curd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

可视化CURD代码生成工具.

源码

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

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

文档

https://doc.zsw.ink

安装

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

在线编辑生成页面

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

$curd = (new \curd\Curd())->props([
    'extComponent' => [
        [
            'label'      => "扩展组件",
            'components' => [
                // 自定义表单组件
                [
                    'component' => [
                        (new Input(['label' => 'Input1', 'name' => 'Input1'])),
                        (new Input(['label' => 'Input2', 'name' => 'Input2']))
                    ],
                    'label'     => '批量插入',
                    'icon'      => "组件"
                ],
            ],
        ]
    ],
]);

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

MIT License Copyright (c) 2020 iszsw Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🔥 CURD代码生成器 可视化生成CURD页面 展开 收起
PHP 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/iszsw/curd.git
git@gitee.com:iszsw/curd.git
iszsw
curd
curd
master

搜索帮助