├── 1.x ├── LICENSE.md ├── README.md ├── action-form.md ├── action-grid.md ├── action-show.md ├── action-tree.md ├── action.md ├── assets.md ├── change-log.md ├── custom-authentication.md ├── custom-chart.md ├── custom-navbar.md ├── custom-page.md ├── documentation.md ├── extend.md ├── extension-helpers.md ├── extensions.md ├── function.md ├── helpers.md ├── installation.md ├── introduction.md ├── js.md ├── lazy.md ├── menu.md ├── model-form-callback.md ├── model-form-data.md ├── model-form-field-management.md ├── model-form-fields.md ├── model-form-init.md ├── model-form-layout.md ├── model-form-modal.md ├── model-form-step.md ├── model-form-trans.md ├── model-form-upload.md ├── model-form-validation.md ├── model-form-when.md ├── model-form.md ├── model-grid-actions.md ├── model-grid-column-display.md ├── model-grid-column-filter.md ├── model-grid-column.md ├── model-grid-combination.md ├── model-grid-custom-tools.md ├── model-grid-data.md ├── model-grid-editable.md ├── model-grid-events.md ├── model-grid-export.md ├── model-grid-exporter.md ├── model-grid-filters.md ├── model-grid-header.md ├── model-grid-quick-create.md ├── model-grid-quick-search.md ├── model-grid-relationship.md ├── model-grid-selector.md ├── model-grid-softdelete.md ├── model-grid-trans.md ├── model-grid-tree.md ├── model-grid.md ├── model-json.md ├── model-relationship.md ├── model-repository.md ├── model-show-extend.md ├── model-show-field.md ├── model-show-init.md ├── model-show-relation.md ├── model-show-trans.md ├── model-show.md ├── model-tree.md ├── multi-app.md ├── notice.md ├── permission.md ├── qa.md ├── quick-start.md ├── section.md ├── theme.md ├── trans.md ├── update.md ├── v1-1-0.md ├── v1-2-0.md ├── v1-2-5.md ├── v1-3-0.md ├── v1-3-2.md ├── v1-3-4.md ├── v1-4-0.md ├── v1-4-5.md ├── v1-4-6.md ├── v1-4-7.md ├── v1-4-8.md ├── v1-5-0.md ├── v1-5-2.md ├── v1-5-3.md ├── v1-6-0.md ├── v1-6-5.md ├── v1-7-0.md ├── v1-7-1.md ├── v1-7-3.md ├── v1-7-8.md ├── widgets-alert.md ├── widgets-box.md ├── widgets-charts.md ├── widgets-checkbox.md ├── widgets-data-card.md ├── widgets-dialog-form.md ├── widgets-dropdown.md ├── widgets-form.md ├── widgets-js.md ├── widgets-markdown.md ├── widgets-modal.md ├── widgets-navbar.md ├── widgets-tab.md ├── widgets-table.md └── widgets-tooltip.md ├── 2.x ├── 1-x-upgrade.md ├── LICENSE.md ├── README.md ├── action-form.md ├── action-grid.md ├── action-show.md ├── action-tree.md ├── action.md ├── assets.md ├── beta-change-log.md ├── change-log.md ├── custom-authentication.md ├── custom-chart.md ├── custom-navbar.md ├── custom-page.md ├── documentation.md ├── extend.md ├── extension-dev.md ├── extension-f.md ├── extension-helpers.md ├── extension-theme.md ├── extension-upgrade.md ├── extensions.md ├── function.md ├── helpers.md ├── installation.md ├── introduction.md ├── js.md ├── laravel-octane.md ├── lazy.md ├── menu.md ├── model-form-callback.md ├── model-form-data.md ├── model-form-field-management.md ├── model-form-fields.md ├── model-form-init.md ├── model-form-layout.md ├── model-form-modal.md ├── model-form-step.md ├── model-form-trans.md ├── model-form-upload.md ├── model-form-validation.md ├── model-form-when.md ├── model-form.md ├── model-grid-actions.md ├── model-grid-async.md ├── model-grid-column-display.md ├── model-grid-column-filter.md ├── model-grid-column.md ├── model-grid-combination.md ├── model-grid-custom-tools.md ├── model-grid-data.md ├── model-grid-editable.md ├── model-grid-events.md ├── model-grid-export.md ├── model-grid-exporter.md ├── model-grid-filters.md ├── model-grid-header.md ├── model-grid-quick-create.md ├── model-grid-quick-search.md ├── model-grid-relationship.md ├── model-grid-selector.md ├── model-grid-softdelete.md ├── model-grid-trans.md ├── model-grid-tree.md ├── model-grid.md ├── model-json.md ├── model-relationship.md ├── model-repository.md ├── model-show-extend.md ├── model-show-field.md ├── model-show-init.md ├── model-show-relation.md ├── model-show-trans.md ├── model-show.md ├── model-tree.md ├── multi-app.md ├── notice.md ├── permission.md ├── qa.md ├── quick-start.md ├── response.md ├── section.md ├── theme.md ├── trans.md ├── update.md ├── widgets-alert.md ├── widgets-box.md ├── widgets-charts.md ├── widgets-checkbox.md ├── widgets-data-card.md ├── widgets-dialog-form.md ├── widgets-dropdown.md ├── widgets-form.md ├── widgets-js.md ├── widgets-markdown.md ├── widgets-modal.md ├── widgets-navbar.md ├── widgets-tab.md ├── widgets-table.md └── widgets-tooltip.md ├── README.md └── en-2.x ├── 1-x-upgrade.md ├── LICENSE.md ├── README.md ├── action-form.md ├── action-grid.md ├── action-show.md ├── action-tree.md ├── action.md ├── assets.md ├── beta-change-log.md ├── change-log.md ├── custom-authentication.md ├── custom-chart.md ├── custom-navbar.md ├── custom-page.md ├── documentation.md ├── extend.md ├── extension-dev.md ├── extension-f.md ├── extension-helpers.md ├── extension-theme.md ├── extension-upgrade.md ├── extensions.md ├── function.md ├── helpers.md ├── installation.md ├── introduction.md ├── js.md ├── laravel-octane.md ├── lazy.md ├── menu.md ├── model-form-callback.md ├── model-form-data.md ├── model-form-field-management.md ├── model-form-fields.md ├── model-form-init.md ├── model-form-layout.md ├── model-form-modal.md ├── model-form-step.md ├── model-form-trans.md ├── model-form-upload.md ├── model-form-validation.md ├── model-form-when.md ├── model-form.md ├── model-grid-actions.md ├── model-grid-async.md ├── model-grid-column-display.md ├── model-grid-column-filter.md ├── model-grid-column.md ├── model-grid-combination.md ├── model-grid-custom-tools.md ├── model-grid-data.md ├── model-grid-editable.md ├── model-grid-events.md ├── model-grid-export.md ├── model-grid-exporter.md ├── model-grid-filters.md ├── model-grid-header.md ├── model-grid-quick-create.md ├── model-grid-quick-search.md ├── model-grid-relationship.md ├── model-grid-selector.md ├── model-grid-softdelete.md ├── model-grid-trans.md ├── model-grid-tree.md ├── model-grid.md ├── model-json.md ├── model-relationship.md ├── model-repository.md ├── model-show-extend.md ├── model-show-field.md ├── model-show-init.md ├── model-show-relation.md ├── model-show-trans.md ├── model-show.md ├── model-tree.md ├── multi-app.md ├── notice.md ├── permission.md ├── qa.md ├── quick-start.md ├── response.md ├── section.md ├── theme.md ├── trans.md ├── update.md ├── widgets-alert.md ├── widgets-box.md ├── widgets-charts.md ├── widgets-checkbox.md ├── widgets-data-card.md ├── widgets-dialog-form.md ├── widgets-dropdown.md ├── widgets-form.md ├── widgets-js.md ├── widgets-markdown.md ├── widgets-modal.md ├── widgets-navbar.md ├── widgets-tab.md ├── widgets-table.md └── widgets-tooltip.md /1.x/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jiang Qinghua 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /1.x/README.md: -------------------------------------------------------------------------------- 1 | # dcat-admin 2 | 3 | `Dcat Admin` 是一个基于[Laravel-admin](https://github.com/z-song/laravel-admin)二次开发而成的后台构建工具,只需使用很少的代码即可构建一个漂亮的管理后台。 4 | 5 | >`Dcat Admin` 在[Laravel-admin](https://github.com/z-song/laravel-admin)的基础上精心调整、增加了大量实用的功能接口,并重写了界面样式,以期望能帮助开发者用最简单舒爽的方式快速构建出一个功能完善且漂亮的管理后台。 6 | 7 | 8 | ## 特性 9 | 10 | + 11 | + `model-grid`支持快速构建数据表格 12 | + `model-form`支持快速构建数据表单 13 | + `model-tree`支持快速构建树状数据 14 | + 内置权限系统 15 | + 内置近100种页面组件,其中包含40+种form元素组件,以及支持扩展组件 16 | + 支持`Laravel`的多种模型关系 17 | + `mysql`、`mongodb`、`pgsql`等多数据库支持 18 | + 支持引入第三方前端库 19 | + 数据库和artisan命令行工具的web实现 20 | + 支持自定义图表 21 | + 多种常用web组件 22 | + 支持本地和oss文件上传 23 | 24 | ## Demo 25 | 26 | 打开[demo](),用账号密码`admin/admin`登陆 27 | 28 | ## 环境 29 | + PHP >= 7.1 30 | + Laravel >= 5.5.0 31 | + Fileinfo PHP Extension 32 | 33 | ## 安装 34 | ```sh 35 | composer require dcat/admin 36 | ``` 37 | 38 | 39 | # 依赖 40 | 41 | `dcat-admin` 基于以下组件或者服务: 42 | 43 | + [Laravel](https://laravel.com/) 44 | + [AdminLTE](https://almsaeedstudio.com/) 45 | + [Datetimepicker](http://eonasdan.github.io/bootstrap-datetimepicker/) 46 | + [font-awesome](http://fontawesome.io) 47 | + [moment](http://momentjs.com/) 48 | + [Google map](https://www.google.com/maps) 49 | + [Tencent map](http://lbs.qq.com/) 50 | + [bootstrap-fileinput](https://github.com/kartik-v/bootstrap-fileinput) 51 | + [jquery-pjax](https://github.com/defunkt/jquery-pjax) 52 | + [Nestable](http://dbushell.github.io/Nestable/) 53 | + [toastr](http://codeseven.github.io/toastr/) 54 | + [X-editable](http://github.com/vitalets/x-editable) 55 | + [bootstrap-number-input](https://github.com/wpic/bootstrap-number-input) 56 | + [fontawesome-iconpicker](https://github.com/itsjavi/fontawesome-iconpicker) 57 | 58 | ## 鸣谢 59 | + [Laravel-admin](https://github.com/z-song/laravel-admin) 60 | 61 | ## 交流 62 | 63 | QQ群: 64 | 65 | 66 | ## License 67 | 68 | `dcat-admin` is licensed under [The MIT License (MIT)](zh/LICENSE). 69 | -------------------------------------------------------------------------------- /1.x/action-form.md: -------------------------------------------------------------------------------- 1 | # 数据表单动作 2 | 3 | 运行命令 4 | 5 | ```bash 6 | php artisan admin:action 7 | ``` 8 | 9 | 然后输入 `4` 10 | 11 | ```bash 12 | Which type of action would you like to make?: 13 | [0] default 14 | [1] grid-batch 15 | [2] grid-row 16 | [3] grid-tool 17 | [4] form-tool 18 | [5] show-tool 19 | [6] tree-tool 20 | > 4 # 输入 4 21 | 22 | ``` 23 | 24 | 接着输入 `Action` 类名称,这里需要输入 `大驼峰` 风格的英文字母 25 | 26 | ```bash 27 | 28 | Please enter a name of action class: 29 | > Copy 30 | 31 | ``` 32 | 33 | 类名输入完成之后会出现以下信息让开发者输入类的命名空间,默认的命名空间是 `App\Admin\Actions\Form`,这里使用默认的就行 34 | 35 | ```bash 36 | 37 | Please enter the namespace of action class [App\Admin\Actions\Form]: 38 | > 39 | 40 | ``` 41 | 42 | 最后生成文件如下 43 | 44 | ```php 45 | getKey(); 76 | 77 | return $this->response() 78 | ->success('Processed successfully.') 79 | ->redirect('/'); 80 | } 81 | 82 | /** 83 | * 如果只是a标签跳转,则在这里返回跳转链接即可 84 | * 85 | * @return string|void 86 | */ 87 | protected function href() 88 | { 89 | // 获取主键 90 | $key = $this->getKey(); 91 | 92 | // 获取当前页其他字段 93 | $username = $this->parent->model()->username; 94 | 95 | // return admin_url('auth/users'); 96 | } 97 | 98 | // 如果你想自定义动作按钮的HTML,可以重写此方法 99 | public function html() 100 | { 101 | return parent::html(); 102 | } 103 | 104 | /** 105 | * 确认弹窗信息,如不需要可以删除此方法 106 | * 107 | * @return string|array|void 108 | */ 109 | public function confirm() 110 | { 111 | // return ['Confirm?', 'contents']; 112 | } 113 | 114 | /** 115 | * 权限判断,如不需要可以删除此方法 116 | * 117 | * @param Model|Authenticatable|HasPermissions|null $user 118 | * 119 | * @return bool 120 | */ 121 | protected function authorize($user): bool 122 | { 123 | return true; 124 | } 125 | 126 | /** 127 | * 返回请求接口的参数,如不需要可以删除此方法 128 | * 129 | * @return array 130 | */ 131 | protected function parameters() 132 | { 133 | return []; 134 | } 135 | } 136 | 137 | ``` 138 | 139 | 使用 140 | 141 | ```php 142 | $form->tools(function (Form\Tools $tools) { 143 | $tools->append(new Copy()); 144 | }); 145 | ``` 146 | -------------------------------------------------------------------------------- /1.x/action-show.md: -------------------------------------------------------------------------------- 1 | # 数据详情动作 2 | 3 | 运行命令 4 | 5 | ```bash 6 | php artisan admin:action 7 | ``` 8 | 9 | 然后输入 `5` 10 | 11 | ```bash 12 | Which type of action would you like to make?: 13 | [0] default 14 | [1] grid-batch 15 | [2] grid-row 16 | [3] grid-tool 17 | [4] form-tool 18 | [5] show-tool 19 | [6] tree-tool 20 | > 5 # 输入 5 21 | 22 | ``` 23 | 24 | 接着输入 `Action` 类名称,这里需要输入 `大驼峰` 风格的英文字母 25 | 26 | ```bash 27 | 28 | Please enter a name of action class: 29 | > Copy 30 | 31 | ``` 32 | 33 | 类名输入完成之后会出现以下信息让开发者输入类的命名空间,默认的命名空间是 `App\Admin\Actions\Show`,这里使用默认的就行 34 | 35 | ```bash 36 | 37 | Please enter the namespace of action class [App\Admin\Actions\Show]: 38 | > 39 | 40 | ``` 41 | 42 | 最后生成文件如下 43 | 44 | ```php 45 | getKey(); 76 | 77 | return $this->response() 78 | ->success('Processed successfully.') 79 | ->redirect('/'); 80 | } 81 | 82 | /** 83 | * 如果只是a标签跳转,则在这里返回跳转链接即可 84 | * 85 | * @return string|void 86 | */ 87 | protected function href() 88 | { 89 | // 获取主键 90 | $key = $this->getKey(); 91 | 92 | // 获取当前页其他字段 93 | $username = $this->parent->model()->username; 94 | 95 | // return admin_url('auth/users'); 96 | } 97 | 98 | // 如果你想自定义动作按钮的HTML,可以重写此方法 99 | public function html() 100 | { 101 | return parent::html(); 102 | } 103 | 104 | /** 105 | * 确认弹窗信息,如不需要可以删除此方法 106 | * 107 | * @return string|array|void 108 | */ 109 | public function confirm() 110 | { 111 | // return ['Confirm?', 'contents']; 112 | } 113 | 114 | /** 115 | * 权限判断,如不需要可以删除此方法 116 | * 117 | * @param Model|Authenticatable|HasPermissions|null $user 118 | * 119 | * @return bool 120 | */ 121 | protected function authorize($user): bool 122 | { 123 | return true; 124 | } 125 | 126 | /** 127 | * 返回请求接口的参数,如不需要可以删除此方法 128 | * 129 | * @return array 130 | */ 131 | protected function parameters() 132 | { 133 | return []; 134 | } 135 | } 136 | 137 | ``` 138 | 139 | 使用 140 | 141 | ```php 142 | $show->tools(function (Show\Tools $tools) { 143 | $tools->append(new Copy()); 144 | }); 145 | ``` 146 | -------------------------------------------------------------------------------- /1.x/action-tree.md: -------------------------------------------------------------------------------- 1 | # 模型树动作 2 | 3 | 运行命令 4 | 5 | ```bash 6 | php artisan admin:action 7 | ``` 8 | 9 | 然后输入 `6` 10 | 11 | ```bash 12 | Which type of action would you like to make?: 13 | [0] default 14 | [1] grid-batch 15 | [2] grid-row 16 | [3] grid-tool 17 | [4] form-tool 18 | [5] show-tool 19 | [6] tree-tool 20 | > 6 # 输入 6 21 | 22 | ``` 23 | 24 | 接着输入 `Action` 类名称,这里需要输入 `大驼峰` 风格的英文字母 25 | 26 | ```bash 27 | 28 | Please enter a name of action class: 29 | > Copy 30 | 31 | ``` 32 | 33 | 类名输入完成之后会出现以下信息让开发者输入类的命名空间,默认的命名空间是 `App\Admin\Actions\Tree`,这里使用默认的就行 34 | 35 | ```bash 36 | 37 | Please enter the namespace of action class [App\Admin\Actions\Tree]: 38 | > 39 | 40 | ``` 41 | 42 | 最后生成文件如下 43 | 44 | ```php 45 | response() 75 | ->success('Processed successfully.') 76 | ->redirect('/'); 77 | } 78 | 79 | /** 80 | * 如果只是a标签跳转,则在这里返回跳转链接即可 81 | * 82 | * @return string|void 83 | */ 84 | protected function href() 85 | { 86 | // return admin_url('auth/users'); 87 | } 88 | 89 | // 如果你想自定义动作按钮的HTML,可以重写此方法 90 | public function html() 91 | { 92 | return parent::html(); 93 | } 94 | 95 | /** 96 | * 确认弹窗信息,如不需要可以删除此方法 97 | * 98 | * @return string|array|void 99 | */ 100 | public function confirm() 101 | { 102 | // return ['Confirm?', 'contents']; 103 | } 104 | 105 | /** 106 | * 权限判断,如不需要可以删除此方法 107 | * 108 | * @param Model|Authenticatable|HasPermissions|null $user 109 | * 110 | * @return bool 111 | */ 112 | protected function authorize($user): bool 113 | { 114 | return true; 115 | } 116 | 117 | /** 118 | * 返回请求接口的参数,如不需要可以删除此方法 119 | * 120 | * @return array 121 | */ 122 | protected function parameters() 123 | { 124 | return []; 125 | } 126 | } 127 | 128 | ``` 129 | 130 | 使用 131 | 132 | ```php 133 | $tree->tools(function (Tree\Tools $tools) { 134 | $tools->add(new Copy()); 135 | }); 136 | ``` 137 | -------------------------------------------------------------------------------- /1.x/assets.md: -------------------------------------------------------------------------------- 1 | # 静态资源加载 2 | 3 | `Dcat Admin`修改了`pjax`源码,增加了`js`脚本按需加载的功能,开发者只需在控制器`action`中引入需要用到的`js`组件即可,而无需在项目初始化时引入所有的`js`组件。 4 | 5 | ### 加载js脚本 6 | 7 | `Admin::js`方法可以引入`js`脚本,使用如下: 8 | ```php 9 | class UserController extend Controller 10 | { 11 | public function index() 12 | { 13 | Admin::js('/assets/js/index.js'); 14 | 15 | Admin::js([ 16 | '/assets/js/index2.js' 17 | ]); 18 | } 19 | } 20 | ``` 21 | 22 | ### 加载css脚本 23 | 24 | `Admin::css`方法可以引入`css`脚本,使用如下: 25 | ```php 26 | class UserController extend Controller 27 | { 28 | public function index() 29 | { 30 | Admin::css('/assets/css/index.css'); 31 | 32 | Admin::css([ 33 | '/assets/css/index2.css' 34 | ]); 35 | } 36 | } 37 | ``` 38 | 39 | ### 动态添加js代码 40 | 41 | `Admin::script`方法可以动态添加`js`代码,使用如下: 42 | ```php 43 | public function index() 44 | { 45 | Admin::script( 46 | << 75 | 76 | // 引入js 77 | 78 | ``` 79 | 80 | ### 在模板中添加js代码 81 | 82 | 要在模板中添加的`js`代码需要放在`Dcat.ready`方法内执行,这样才能保证你的`js`代码在所有`js`脚本加载完成之后执行。 83 | 84 | ```html 85 | 90 | ``` 91 | 92 | -------------------------------------------------------------------------------- /1.x/change-log.md: -------------------------------------------------------------------------------- 1 | 2 | 当前最新版本 [v1.7.8](v1-7-8.md) 3 | 4 | - [v1.7.8](v1-7-8.md) 发布时间 `2020/12/22` 5 | - [v1.7.3](v1-7-3.md) 发布时间 `2020/09/09` 6 | - [v1.7.1](v1-7-1.md) 发布时间 `2020/09/02` 7 | - [v1.7.0](v1-7-0.md) 发布时间 `2020/08/23` 8 | - [v1.6.5](v1-6-5.md) 发布时间 `2020/07/28` 9 | - [v1.6.0](v1-6-0.md) 发布时间 `2020/07/12` 10 | - [v1.5.3](v1-5-3.md) 发布时间 `2020/06/28` 11 | - [v1.5.2](v1-5-2.md) 发布时间 `2020/06/21` 12 | - [v1.5.0](v1-5-0.md) 发布时间 `2020/06/14` 13 | - [v1.4.8](v1-4-8.md) 发布时间 `2020/06/03` 14 | - [v1.4.7](v1-4-7.md) 发布时间 `2020/05/29` 15 | - [v1.4.6](v1-4-6.md) 发布时间 `2020/05/27` 16 | - [v1.4.5](v1-4-5.md) 发布时间 `2020/05/23` 17 | - [v1.4.0](v1-4-0.md) 发布时间 `2020/05/17` 18 | - [v1.3.4](v1-3-4.md) 发布时间 `2020/05/12` 19 | - [v1.3.2](v1-3-2.md) 发布时间 `2020/05/08` 20 | - [v1.3.0](v1-3-0.md) 发布时间 `2020-05-06` 21 | - [v1.2.5](v1-2-5.md) 发布时间 `2020-04-30` 22 | - [v1.2.0](v1-2-0.md) 发布时间 `2020-04-24` 23 | - [v1.1.0](v1-1-0.md) 发布时间 `2020-04-20` 24 | -------------------------------------------------------------------------------- /1.x/custom-chart.md: -------------------------------------------------------------------------------- 1 | # 自定义图表 2 | 3 | `dcat-admin 1.5`已经移除了所有的图表组件,如果要在页面中加入图表组件,可以参考下面的流程 4 | 5 | 用`chartjs`举例,首先要下载[chartjs](http://chartjs.org/),放到public目录下面,比如放在`public/vendor/chartjs`目录 6 | 7 | 然后在`app/Admin/bootstrap.php`引入组件: 8 | ```php 9 | use Dcat\Admin\Facades\Admin; 10 | 11 | Admin::js('/vendor/chartjs/dist/Chart.min.js'); 12 | 13 | ``` 14 | 15 | 新建视图文件 `resources/views/admin/charts/bar.blade.php` 16 | 17 | ```php 18 | 19 | 61 | ``` 62 | 63 | 然后就可以在页面的任何地方引入这个图表视图了: 64 | 65 | ```php 66 | public function index() 67 | { 68 | return Admin::content(function (Content $content) { 69 | 70 | $content->header('chart'); 71 | $content->description('.....'); 72 | 73 | $content->body(view('admin.charts.bar')); 74 | }); 75 | } 76 | 77 | ``` 78 | 79 | 按照上面的方式可以引入任意图表库,多图表页面的布局,参考[视图布局](layout.md) -------------------------------------------------------------------------------- /1.x/custom-page.md: -------------------------------------------------------------------------------- 1 | # 自定义页面 2 | 3 | 在`Dcat Admin`中构建自定义页面非常简单,可以参考如下两个例子 4 | 5 | 6 | ### 示例1 7 | 8 | > {tip} `Dcat Admin`构建的是一个单页应用,加载的`JS`脚本只会执行一次,所以初始化操作不能直接放在`JS`脚本中,应该使用`Admin::script`方法载入。 9 | 10 | ```php 11 | script()); 44 | 45 | return view('admin.pages.my-page')->render(); 46 | } 47 | } 48 | ``` 49 | 50 | 视图`admin.pages.my-page`,注意视图代码里面不要包含``和``等标签 51 | ```html 52 |
53 |

自定义页面演示

54 |
55 | 61 | ``` 62 | 63 | 使用 64 | 65 | ```php 66 | public function index(Content $content) 67 | { 68 | return $content->body(new MyPage()); 69 | } 70 | ``` 71 | 72 | 73 | ### 示例2 74 | 75 | 后台的仪表盘页面`/admin`,也可以看做是一个自定义页面,代码实现如下 76 | ```php 77 | public function index(Content $content) 78 | { 79 | return $content 80 | ->header('Dashboard') 81 | ->description('Description...') 82 | ->body(function (Row $row) { 83 | $row->column(6, function (Column $column) { 84 | $column->row(Dashboard::title()); 85 | $column->row(new Examples\Tickets()); 86 | }); 87 | 88 | $row->column(6, function (Column $column) { 89 | $column->row(function (Row $row) { 90 | $row->column(6, new Examples\NewUsers()); 91 | $row->column(6, new Examples\NewDevices()); 92 | }); 93 | 94 | $column->row(new Examples\Sessions()); 95 | $column->row(new Examples\ProductOrders()); 96 | }); 97 | }); 98 | } 99 | ``` 100 | 101 | -------------------------------------------------------------------------------- /1.x/documentation.md: -------------------------------------------------------------------------------- 1 | 2 | - ## 入门 3 | - [简介](introduction.md) 4 | - [安装](installation.md) 5 | - [版本升级](update.md) 6 | - [快速开始](quick-start.md) 7 | - [开发前必读](notice.md) 8 | - [主题与颜色](theme.md) 9 | - [自定义页面](custom-page.md) 10 | - [JS组件](js.md) 11 | - [多应用 (多后台)](multi-app.md) 12 | - [常见问题](qa.md) 13 | - ## 数据表格 14 | - [基本使用](model-grid.md) 15 | - [列的使用和扩展](model-grid-column.md) 16 | - [列的显示和扩展](model-grid-column-display.md) 17 | - [行的使用和扩展](model-grid-actions.md) 18 | - [工具栏](model-grid-custom-tools.md) 19 | - [树状表格](model-grid-tree.md) 20 | - [组合表头](model-grid-combination.md) 21 | - [数据源](model-grid-data.md) 22 | - [关联关系](model-grid-relationship.md) 23 | - [查询过滤](model-grid-filters.md) 24 | - [列过滤器](model-grid-column-filter.md) 25 | - [快捷搜索](model-grid-quick-search.md) 26 | - [规格筛选器](model-grid-selector.md) 27 | - [数据导出](model-grid-export.md) 28 | - [快捷创建](model-grid-quick-create.md) 29 | - [行内编辑](model-grid-editable.md) 30 | - [事件](model-grid-events.md) 31 | - [字段翻译](model-grid-trans.md) 32 | - [头部和脚部](model-grid-header.md) 33 | - [软删除](model-grid-softdelete.md) 34 | - ## 数据表单 35 | - [基本使用](model-form.md) 36 | - [图片/文件上传](model-form-upload.md) 37 | - [字段的使用](model-form-fields.md) 38 | - [字段的管理](model-form-field-management.md) 39 | - [数据源](model-form-data.md) 40 | - [表单弹窗](model-form-modal.md) 41 | - [关联关系](model-relationship.md) 42 | - [JSON表单](model-json.md) 43 | - [字段动态显示](model-form-when.md) 44 | - [表单分步](model-form-step.md) 45 | - [表单验证](model-form-validation.md) 46 | - [事件](model-form-callback.md) 47 | - [表单初始化](model-form-init.md) 48 | - [工具表单](widgets-form.md) 49 | - [表单布局](model-form-layout.md) 50 | - [表单字段翻译](model-form-trans.md) 51 | - ## 数据详情 52 | - [基本使用](model-show.md) 53 | - [字段显示](model-show-field.md) 54 | - [关联关系](model-show-relation.md) 55 | - [显示扩展](model-show-extend.md) 56 | - [初始化](model-show-init.md) 57 | - [字段翻译](model-show-trans.md) 58 | - ## [模型树](model-tree.md) 59 | - ## [数据仓库](model-repository.md) 60 | - ## 动作 61 | - [基本使用](action.md) 62 | - [数据表格](action-grid.md) 63 | - [数据表单](action-form.md) 64 | - [数据详情](action-show.md) 65 | - [模型树](action-tree.md) 66 | - ## [多语言](trans.md) 67 | - ## [开发扩展](extend.md) 68 | - ## 页面组件 69 | - [异步加载](lazy.md) 70 | - [图表](widgets-charts.md) 71 | - [数据统计卡片](widgets-data-card.md) 72 | - [工具表单](widgets-form.md) 73 | - [模态窗(Modal)](widgets-modal.md) 74 | - [下拉菜单](widgets-dropdown.md) 75 | - [单/复选框](widgets-checkbox.md) 76 | - [选项卡](widgets-tab.md) 77 | - [告警框](widgets-alert.md) 78 | - [提示窗(tooltip)](widgets-tooltip.md) 79 | - [Markdown](widgets-markdown.md) 80 | - [卡片](widgets-box.md) 81 | - ## [区块(section)](section.md) 82 | - ## [权限控制](permission.md) 83 | - ## [菜单](menu.md) 84 | - ## [帮助函数](function.md) 85 | - ## [开发工具](helpers.md) 86 | - ## [自定义登陆认证](custom-authentication.md) 87 | - ## [自定义头部导航](custom-navbar.md) 88 | - ## 更新日志 89 | - [v1.7.8](v1-7-8.md) 90 | - [更新日志](change-log.md) -------------------------------------------------------------------------------- /1.x/extension-helpers.md: -------------------------------------------------------------------------------- 1 | # 开发工具 2 | 3 | 在最新的版本中新增了面向开发人员的帮助工具,能在开发中提供帮助提高效率,目前提供`脚手架`,`数据库命令行`和`artisan命令行`三个工具,如果有更好的其它实用工具的想法,欢迎提供建议。 4 | 5 | 安装: 6 | ```php 7 | composer require dcat-admin-ext/helpers 8 | 9 | php artisan admin:import helpers 10 | ``` 11 | 12 | > {tip} 工具的部分功能会在项目中创建或删除文件,可能会出现文件或目录权限的问题,这个问题需要自行解决。 13 | 另外部分数据库和artisan命令无法在web环境下使用。 14 | 15 | ## 脚手架工具 16 | 17 | 脚手架工具能帮你一键生成控制器、模型、迁移文件,并运行迁移文件,访问`http://localhost/admin/helpers/scaffold`打开。 18 | 19 | 其中设置迁移表结构的时候,主键字段是自动生成的不需要填写。 20 | 21 | ![qq20170220-2](https://cloud.githubusercontent.com/assets/1479100/23147949/cbf03e84-f81d-11e6-82b7-d7929c3033a0.png) 22 | 23 | ## 数据库命令行 24 | 25 | 数据库命令行工具的web集成,目前支持`mysql`、`mongodb` 和 `redis`,访问`http://localhost/admin/helpers/terminal/database`打开。 26 | 27 | 在右上角的`select`选择框切换数据库连接,然后在底部的输入框输入对应数据库的查询语句然后回车,就能得到查询结果: 28 | 29 | ![qq20170220-3](https://cloud.githubusercontent.com/assets/1479100/23147951/ce08e5d6-f81d-11e6-8b20-605e8cd06167.png) 30 | 31 | 实用方式和终端上操作数据库是一致的,可以运行所选择数据库的所支持的查询语句。 32 | 33 | ## artisan命令行工具 34 | 35 | `Laravel`的`artisan`命令的web实现,可以在上面运行artisan命令,访问`http://localhost/admin/helpers/terminal/artisan`打开。 36 | 37 | ![qq20170220-1](https://cloud.githubusercontent.com/assets/1479100/23147963/da8a5d30-f81d-11e6-97b9-239eea900ad3.png) 38 | 39 | ## 路由列表 40 | 41 | 这个工具能用用比较直观的展现出系统的所有路由,包括路由的uri、方法和中间件等,还能查询路由。访问`http://localhost/admin/helpers/routes`打开。 42 | 43 | ![helpers_routes](https://user-images.githubusercontent.com/1479100/30899066-e8bdd5ca-a390-11e7-809d-4ceccd0da27f.png) 44 | -------------------------------------------------------------------------------- /1.x/extensions.md: -------------------------------------------------------------------------------- 1 | # 扩展 2 | 3 | | 扩展 | 描述 | dcat-admin 版本 | 4 | | ------------------------------------------------ | ---------------------------------------- |---------------------------------------- | 5 | | [dcat-page](https://github.com/jqhph/dcat-page) | 一个简洁的静态站点构建工具 | * | 6 | | [ueditor](https://github.com/jqhph/dcat-admin-ueditor) | 百度在线编辑器 | * | 7 | | [gank](https://github.com/jqhph/dcat-admin-gank) | 干货集中营 |* | 8 | 9 | 10 | -------------------------------------------------------------------------------- /1.x/function.md: -------------------------------------------------------------------------------- 1 | # 帮助函数 2 | 3 | ### admin_path 4 | 5 | 获取`Dcat Admin`安装的应用路径,默认目录是`app/Admin`: 6 | 7 | ```php 8 | $bootstrap = admin_path('bootstrap.php'); 9 | ``` 10 | 11 | ### admin_url 12 | 13 | 获取`Dcat Admin`应用的路由完整url: 14 | 15 | ```php 16 | // 返回: http://localhost/admin/auth/users 17 | $url = admin_url('auth/users'); 18 | ``` 19 | 20 | ### admin_base_path 21 | 22 | 获取`Dcat Admin`应用的路由路径: 23 | ```php 24 | // 返回: /admin/auth/users 25 | $path = admin_base_path('auth/users'); 26 | ``` 27 | 28 | ### admin_toastr 29 | 30 | 在页面刷新后弹出一个`toastr`提示窗,参数: 31 | 32 | - `$message` 提示窗内容 33 | - `$type` 提示窗类型,默认`success`,支持`success`、`info`、`warning`、`error` 34 | - `$options` toastr配置参数 35 | 36 | ```php 37 | admin_alert('更新成功', 'success'); 38 | ``` 39 | 40 | ### admin_success 41 | 42 | 在页面刷新后在页面顶部显示一个成功消息: 43 | ```php 44 | admin_success('标题', '成功了'); 45 | ``` 46 | 47 | ### admin_error 48 | 49 | 在页面刷新后在页面顶部显示一个错误消息: 50 | ```php 51 | admin_error('标题', '失败了'); 52 | ``` 53 | 54 | ### admin_warning 55 | 56 | 在页面刷新后在页面顶部显示一个警告消息: 57 | ```php 58 | admin_warning('标题', '警告'); 59 | ``` 60 | 61 | ### admin_info 62 | 63 | 在页面刷新后在页面顶部显示一个提示消息: 64 | ```php 65 | admin_info('标题', '内容'); 66 | ``` 67 | 68 | ### admin_asset 69 | 70 | 获取静态资源的完整链接: 71 | 72 | > {tip} 此函数支持别名. 73 | 74 | ```html 75 | // 引入css 76 | 77 | 78 | // 引入js 79 | 80 | ``` 81 | 82 | ### admin_trans_field 83 | 84 | 翻译当前控制器的字段,控制器名称去除`Controller`后缀之后再转化为小写中划线就是语言包的名称,如:控制器名称为`UserProfileController`,则对应的语言包名称为`user-profile.php`。 85 | 86 | > {tip} 如果当前控制器对应的语言包中不存在该字段翻译,则会去公共翻译文件`global.php`中查找。 87 | 88 | ```php 89 | $name = admin_trans_field('name'); 90 | $createdAt = admin_trans_field('created_at'); 91 | ``` 92 | 语言包内容如下: 93 | ```php 94 | return [ 95 | 'fields' => [ 96 | 'name' => '名称', 97 | 'created_at' => '创建时间', 98 | ], 99 | ]; 100 | ``` 101 | 102 | 103 | ### admin_trans_label 104 | 105 | 翻译当前控制器的自定义内容,控制器名称去除`Controller`后缀之后再转化为小写中划线就是语言包的名称,如:控制器名称为`UserProfileController`,则对应的语言包名称为`user-profile.php`。 106 | 107 | > {tip} 如果当前控制器对应的语言包中不存在该字段翻译,则会去公共翻译文件`global.php`中查找。 108 | 109 | ```php 110 | $user = admin_trans_label('User'); 111 | ``` 112 | 语言包内容如下: 113 | ```php 114 | return [ 115 | 'labels' => [ 116 | 'User' => '管理员', 117 | ], 118 | ]; 119 | ``` 120 | 121 | ### admin_trans_option 122 | 123 | 翻译当前控制器的字段选项值,控制器名称去除`Controller`后缀之后再转化为小写中划线就是语言包的名称,如:控制器名称为`UserProfileController`,则对应的语言包名称为`user-profile.php`。 124 | 125 | > {tip} 如果当前控制器对应的语言包中不存在该字段翻译,则会去公共翻译文件`global.php`中查找。 126 | 127 | ```php 128 | $status = admin_trans_option(1, 'status'); 129 | ``` 130 | 语言包内容如下: 131 | ```php 132 | return [ 133 | 'options' => [ 134 | 'status' => [ 135 | 1 => '启用', 136 | 0 => '禁用' 137 | ], 138 | ], 139 | ]; 140 | ``` 141 | 142 | -------------------------------------------------------------------------------- /1.x/helpers.md: -------------------------------------------------------------------------------- 1 | # 开发工具 2 | 3 | `Dcat Admin`提供了一些开发工具以帮助开发者提升开发效率。 4 | 如果需要禁用开发工具,则把配置文件中的`app.debug`或`admin.helpers.enable`的参数值设置为`false`即可。 5 | 6 | 7 | ### 代码生成器 8 | 9 | 代码生成器可以通过界面一键生成增删改查代码,支持根据已有数据表生成增删改查代码,打开浏览器访问`http://localhost:8000/admin/helpers/scaffold`即可使用。 10 | 11 | > {tip} 如果你的开发环境不是`windows`系统,请给整个项目`777`权限,否则可能无法生成文件。 12 | 13 | 14 | ### 扩展包管理 15 | `Dcat Admin`支持可视化管理扩展包,只要通过`composer`安装进来的扩展包都能在管理界面中看到,支持通过界面启用和导入扩展包,打开浏览器访问`http://localhost:8000/admin/helpers/extensions`即可使用。 16 | 17 | ### IDE自动补全 18 | 通过`php artisan admin:ide-helper`命令可以生成IDE自动补全文件,可以生成`Grid`、`Form`、`Show`等功能的IDE自动补全提示文件。 19 | 20 | ### 图标 21 | 访问`http://localhost:8000/admin/helpers/icons`可以查看已支持的图标列表。 22 | 23 | -------------------------------------------------------------------------------- /1.x/installation.md: -------------------------------------------------------------------------------- 1 | # 安装 2 | 3 | 4 | ## 环境 5 | + PHP >= `7.1` 6 | + Laravel `5.5.0` ~ `8.*` 7 | + Fileinfo PHP Extension 8 | 9 | 10 | ## 开始安装 11 | 12 | > {tip} 如果安装过程中出现`composer`下载过慢或安装失败的情况,请运行命令`composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/`把`composer`镜像更换为阿里云镜像。 13 | 14 | 首先需要安装`laravel`,如已安装可以跳过此步骤 15 | ```bash 16 | composer create-project --prefer-dist laravel/laravel 项目名称 7.* 17 | # 或 18 | composer create-project --prefer-dist laravel/laravel 项目名称 19 | ``` 20 | 21 | 安装完`laravel`之后需要修改`.env`文件,设置数据库连接设置正确 22 | 23 | ```dotenv 24 | DB_CONNECTION=mysql 25 | DB_HOST=127.0.0.1 26 | DB_PORT=3306 27 | DB_DATABASE=dcat-admin 28 | DB_USERNAME=root 29 | DB_PASSWORD= 30 | ``` 31 | 32 | 安装`dcat-admin` 33 | 34 | 35 | ``` 36 | cd {项目名称} 37 | 38 | composer require dcat/laravel-admin 39 | ``` 40 | 41 | 然后运行下面的命令来发布资源: 42 | 43 | ``` 44 | php artisan admin:publish 45 | ``` 46 | 47 | 在该命令会生成配置文件`config/admin.php`,可以在里面修改安装的地址、数据库连接、以及表名,建议都是用默认配置不修改。 48 | 49 | 然后运行下面的命令完成安装: 50 | 51 | > {tip} 执行这一步命令可能会报以下错误`Specified key was too long ... 767 bytes`,如果出现这个报错,请在`app/Providers/AppServiceProvider.php`文件的`boot`方法中加上代码`\Schema::defaultStringLength(191);`,然后删除掉数据库中的所有数据表,再重新运行一遍`php artisan admin:install`命令即可。 52 | 53 | ``` 54 | php artisan admin:install 55 | ``` 56 | 57 | 上述步骤操作完成之后就可以配置`web`服务了,**注意需要把`web`目录指向`public`目录**!如果用的是`nginx`,还需要在配置中加上伪静态配置 58 | ```dotenv 59 | location / { 60 | try_files $uri $uri/ /index.php?$query_string; 61 | } 62 | ``` 63 | 64 | 启动服务后,在浏览器打开 `http://localhost/admin`,使用用户名 `admin` 和密码 `admin`登陆。 65 | 66 | 67 | 68 | ## 生成的文件 69 | 70 | 安装完成之后,会在项目目录中生成以下的文件: 71 | 72 | 73 | ### 配置文件 74 | 75 | 安装完成之后,`dcat-admin`所有的配置都在`config/admin.php`文件中。 76 | 77 | 78 | ### 后台项目文件 79 | 安装完成之后,后台的安装目录为`app/Admin`,之后大部分的后台开发编码工作都是在这个目录下进行。 80 | 81 | ``` 82 | app/Admin 83 | ├── Controllers 84 | │   ├── ExampleController.php 85 | │   └── HomeController.php 86 | ├── Metrics 87 | │   └── Examples 88 | │   ├── NewDevices.php 89 | │   ├── NewUsers.php 90 | │   ├── ProductOrders.php 91 | │   ├── Sessions.php 92 | │   ├── Tickets.php 93 | │   └── TotalUsers.php 94 | ├── bootstrap.php 95 | └── routes.php 96 | ``` 97 | 98 | 1. `app/Admin/routes.php`文件用来配置后台路由。 99 | 2. `app/Admin/bootstrap.php` 是`dcat-admin`的启动文件, 使用方法请参考文件里面的注释. 100 | 3. `app/Admin/Controllers`目录用来存放后台控制器文件,该目录下的`HomeController.php`文件是后台首页的显示控制器,`ExampleController.php`为实例文件。 101 | 4. `app/Admin/Metrics/Examples`里面存放的是`数据统计卡片(Metric Card)`的示例代码. 102 | 103 | 104 | ### 静态文件 105 | 106 | 后台所需的前端静态文件在`/public/vendor/dcat-admin`目录下。 107 | 108 | 109 | ### 数据表迁移文件 110 | 对应的数据表迁移文件在`/database/migrations`目录下。 111 | 112 | 113 | ### 语言包 114 | 语言包文件在`/resources/lang`目录下。 115 | 116 | -------------------------------------------------------------------------------- /1.x/introduction.md: -------------------------------------------------------------------------------- 1 | # Dcat Admin 2 | 3 | 4 | `Dcat Admin`是一个基于[laravel-admin](https://www.laravel-admin.org/)二次开发而成的后台系统构建工具,只需极少的代码即可快速构建出一个功能完善的高颜值后台系统。支持页面一键生成CURD代码,内置丰富的后台常用组件,开箱即用,让开发者告别冗杂的HTML代码,对后端开发者非常友好。 5 | 6 |

7 | 8 | 9 | Build Status 10 | 11 | 12 | 13 | 14 | 15 |

16 | 17 | ### 技术栈 18 | 19 | - [Laravel](https://laravel.com/) 20 | - [AdminLTE3](https://github.com/ColorlibHQ/AdminLTE) 21 | - [Bootstrap4](https://getbootstrap.net/) 22 | - jQuery3 23 | 24 | 25 | ### 特性 26 | 27 | - 简洁优雅、灵活可扩展的API 28 | - 用户管理 29 | - RBAC权限管理,支持无限极权限节点 30 | - 菜单管理 31 | - 使用pjax构建无刷新页面,支持**按需加载**静态资源,可以无限扩展组件而不影响整体性能 32 | - 松耦合的页面构建与数据操作设计,可轻松切换数据源 33 | - 自定义页面 34 | - 自定义主题配色 35 | - 多主题切换功能,内置多种主题色 36 | - 可轻松构建无菜单栏的独立页面(如可用于构建弹窗选择器等功能) 37 | - 插件功能 38 | - 可视化代码生成器,可根据数据表一键生成增删改查页面 39 | - 数据表格构建工具,内置丰富的表格常用功能(如组合表头、数据导出、搜索、快捷创建、批量操作等) 40 | - 树状表格功能构建工具,支持分页和点击加载 41 | - 数据表单构建工具,内置丰富的表单类型,支持表单异步提交 42 | - 分步表单构建工具 43 | - 弹窗表单构建工具 44 | - 数据详情页构建工具 45 | - 无限层级树状页面构建工具,支持用拖拽的方式实现数据的层级、排序等操作 46 | - 内置丰富的常用页面组件(如图表、数据统计卡片、下拉菜单、Tab卡片、提示工具等) 47 | - `Section`功能(类似`Wordpress`的`Filter`和`blade`模板的`section`标签) 48 | - 异步文件上传表单,支持分块多线程上传 49 | - 多应用(多后台) 50 | - 插件市场,只需在管理页面轻轻点击鼠标即可完成插件的安装、更新和卸载等操作(`暂未实现`) 51 | 52 | 53 | 54 | 55 | ### 与Laravel Admin的异同 56 | 57 | `Dcat Admin`是基于`Laravel Admin`二次开发而成的后台构建工具,整体风格与`Laravel Admin`一脉相承,只是在功能细节上做了大量的调整。 58 | 59 | 60 | 调整: 61 | - 采用[AdminLTE3](https://github.com/ColorlibHQ/AdminLTE)(`bootstrap4`+`jQuery3`)构建前端页面 62 | - 使用`PJAX`构建无刷新页面,并且支持前端资源按需加载,开发者无需再担心安装组件过多会影响页面加载速度 63 | - 采用松耦合的页面构建与数据操作设计,构建页面不再需要关心数据操作接口的具体实现 64 | - 调整了表单提交方式,改为`ajax`提交 65 | - 调整了代码生成器,支持根据已有数据表一键生成增删改查页面 66 | - 调整了多语言翻译功能,使用更简单 67 | - 调整了权限功能,支持分层级以及排序 68 | - 调整了扩展系统,支持页面管理 69 | - ... 70 | 71 | 新增: 72 | - 新增多主题切换功能 73 | - 新增表单弹窗功能,仅需增加数行代码就可以构建一个非Iframe表单弹窗 74 | - 新增快速构建无菜单栏页面功能 75 | - 新增弹窗选择器表单,可以在弹窗中选择表格数据 76 | - 新增AJAX提交表单,以及表单前端验证功能 77 | - 新增文件异步上传组件,支持分块上传、批量上传、上传进度条等 78 | - 新增表格过滤器右侧滑动面板布局 79 | - 新增表格字段值过滤功能 80 | - 新增分步表单 81 | - 新增`section`功能(与`wordpress`的`add_filter`功能类似) 82 | - 新增树形表格功能,可分页显示大批量的层级结构数据 83 | - 新增双表头表格功能,仅需增加数行代码即可构建出双表头表格 84 | - 新增了多种实用的页面组件,如图表、下拉菜单、markdown、checkbox等等 85 | - 新增`Tree`表单 86 | - 新增通过数组添加菜单的功能,支持绑定权限和角色 87 | - 新增通过数组添加菜单功能 88 | - 新增菜单缓存功能 89 | - ... 90 | 91 | ### 交流 92 | 93 | **QQ群** 704661955 94 | 95 | **扩展开发者QQ群** 679738409 96 | 97 | ### 加入我们 98 | 99 | 如果您对这个项目感兴趣,非常欢迎加入项目开发团队,参与这个项目的功能维护与开发。欢迎任何形式的贡献(包括但不限于以下): 100 | 101 | * 贡献代码 102 | * 完善文档 103 | * 撰写教程 104 | * 完善注释 105 | * ... 106 | -------------------------------------------------------------------------------- /1.x/menu.md: -------------------------------------------------------------------------------- 1 | # 菜单 2 | 3 | `Dcat Admin`的菜单是保存在数据表`admin_menu`上的,开发者可以在后台菜单管理页面对菜单进行管理。 4 | 5 | ### 菜单权限 6 | 每个菜单都可以与权限或角色进行绑定,如果不设置则为公共菜单,所有账号都能看到。 7 | 8 | 通过`admin.menu.bind_permission`配置参数可以设置是否允许绑定权限。 9 | > {tip} 默认一个菜单最多能绑定一个权限和一个角色。 10 | 11 | ### 菜单翻译 12 | 在您的语言文件的menu_titles索引中追加菜单标题。 例如“工作单位”标题: 13 | 14 | 在`resources/lang/{当前语言}/admin.php`中 15 | ```php 16 | ... 17 | 'menu_titles' => [ 18 | 'work_units' => 'Unidades de trabajo' 19 | ], 20 | ``` 21 | 22 | ### 菜单缓存 23 | 通过`admin.menu.cache.enable`配置参数可以开启或关闭菜单缓存,建议开启。 24 | 25 | ### 通过Menu::add接口动态添加菜单 26 | `Dcat Admin`还提供了通过数组的方式在代码中即时添加菜单。 27 | 28 | 在`app\Admin\bootstrap.php`中添加如下代码: 29 | ```php 30 | add([ 36 | [ 37 | 'id' => '1', // 此id只要保证当前的数组中是唯一的即可 38 | 'title' => '测试菜单', 39 | 'icon' => 'fa-file-text-o', 40 | 'uri' => '', 41 | 'parent_id' => 0, 42 | 'permission_id' => 'test', // 与权限绑定 43 | 'roles' => 'test-roles', // 与角色绑定 44 | ], 45 | [ 46 | 'id' => '2', // 此id只要保证当前的数组中是唯一的即可 47 | 'title' => '测试菜单2', 48 | 'icon' => 'fa-file-text-o', 49 | 'uri' => 'test-menu2', 50 | 'parent_id' => '1', 51 | ], 52 | ]); 53 | }); 54 | 55 | ``` 56 | 57 | ### 为何没有权限的菜单不会自动隐藏? 58 | 59 | 这个问题是因为你没有给菜单绑定权限或者角色,给你想要无权不显示的菜单绑定权限或者角色即可。 60 | 61 | 62 | -------------------------------------------------------------------------------- /1.x/model-form-data.md: -------------------------------------------------------------------------------- 1 | # 表单数据源 2 | 3 | ## 模型与数据仓库 4 | 5 | 6 | 数据仓库(`Repository`)是一个可以提供特定接口对数据进行读写操作的类,通过数据仓库的引入,可以让页面的构建不再关心数据读写功能的具体实现,开发者只需要实现特定的操作接口即可轻松切换数据源。关于数据仓库的详细用法请参考文档[数据仓库](model-repository.md)。 7 | 8 | 9 | ## 数据来自模型 10 | 11 | > {tip} 如果你的数据来自`Model`,那么你也可以直接使用`Model`实例,底层会自动把`Model`转化为数据仓库实例。 12 | 13 | 14 | 15 | 当数据源支持模型时,只需创建一个非常简单的`Repository`类既可: 16 | 17 | 18 | ```php 19 | getKeyName(), 'name', 'title', 'created_at']; 35 | } 36 | } 37 | ``` 38 | 使用: 39 | ```php 40 | use App\Admin\Repositories\Movie; 41 | 42 | $form = new Form(new Movie); 43 | 44 | ... 45 | ``` 46 | 47 | ## 数据来自外部API 48 | 49 | 下面以`豆瓣电影`的API为例子,来展示`Repository`的表单数据读写操作相关接口的用法: 50 | 51 | ```php 52 | builder()->getResourceId(); 71 | 72 | $data = file_get_contents("http://api.douban.com/v2/movie/subject/$id"); 73 | 74 | return json_decode($data, true); 75 | } 76 | 77 | // 这个方法用于在修改数据前查询原记录 78 | // 如果使用了文件上传表单,当文件发生变更时会根据这个原始记录自动删除旧文件 79 | // 如果不需要此数据返回空数组即可 80 | public function getDataWhenUpdating(Form $form): array 81 | { 82 | // 获取id 83 | $id = $form->builder()->getResourceId(); 84 | 85 | return []; 86 | } 87 | 88 | // 修改操作 89 | // 返回一个bool类型的数据 90 | public function update(Form $form) 91 | { 92 | // 获取id 93 | $id = $form->builder()->getResourceId(); 94 | 95 | // 获取要修改的数据 96 | $attributes = $form->updates(); 97 | 98 | // TODO 99 | // 这里写你的修改逻辑 100 | 101 | return true; 102 | } 103 | 104 | // 这个方法用于在修改数据前查询原始数据 105 | // 如果使用了文件上传表单,会根据这个数据自动删除文件 106 | // 如果不需要此数据返回空数组即可 107 | public function getDataWhenDeleting(Form $form): array 108 | { 109 | $id = $form->builder()->getResourceId(); 110 | 111 | $id = explode(',', $id); 112 | 113 | // $data = file_get_contents("http://api.douban.com/v2/movie/subject/$id"); 114 | // 115 | // return json_decode($data, true); 116 | 117 | return []; 118 | } 119 | 120 | // 删除数据 121 | // $deletingData 是由 getDataWhenDeleting 方法返回的数据 122 | public function destroy(Form $form, array $deletingData) 123 | { 124 | // 注意这里的id可能是多个 125 | $id = $form->builder()->getResourceId(); 126 | 127 | // 当使用批量删除功能时,这里的id是用“,”隔开的字符串 128 | $id = explode(',', $id); 129 | 130 | // TODO 131 | // var_dump($id, $deletingData); 132 | 133 | return true; 134 | } 135 | 136 | } 137 | ``` 138 | 139 | 140 | -------------------------------------------------------------------------------- /1.x/model-form-init.md: -------------------------------------------------------------------------------- 1 | # 表单初始化 2 | 3 | 通过`Form::resolving`方法设置的回调函数会在`Dcat\Admin\Form`类被实例化时触发; 4 | 5 | 通过`Form::composing`方法设置的回调函数会在`render()`方法被调用时(渲染页面时)触发; 6 | 7 | 开发者可以在这两个事件中改变`Form`的一些设置或行为,比如需要禁用掉某些操作,可以在`app/Admin/bootstrap.php`加入下面的代码: 8 | 9 | ```php 10 | use Dcat\Admin\Form; 11 | 12 | Form::resolving(function (Form $form) { 13 | 14 | $form->disableEditingCheck(); 15 | 16 | $form->disableCreatingCheck(); 17 | 18 | $form->disableViewCheck(); 19 | 20 | $form->tools(function (Form\Tools $tools) { 21 | $tools->disableDelete(); 22 | $tools->disableView(); 23 | $tools->disableList(); 24 | }); 25 | 26 | }); 27 | ``` 28 | 这样就不用在每一个控制器的代码中来设置了。 29 | 30 | 如果全局设置后,要在其中某一个表单中开启设置,比如开启显示`继续编辑`的checkbox,在对应的实例上调用`$form->disableEditingCheck(false);`就可以了 -------------------------------------------------------------------------------- /1.x/model-form-trans.md: -------------------------------------------------------------------------------- 1 | # 表单字段翻译 2 | 3 | 数据表单表单中所有使用到字段的地方都会自动读取语言包中的翻译。 4 | 5 | > {tip} 语言包的详细使用方法请参考[多语言](trans.md)。 6 | 7 | ### 语言包名称 8 | 语言包名称需要与控制器名相对应,假如控制器名`UserProfileController`,则对应的语言包为`resources/lang/{当前语言}/user-profile.php`(需要转化为小写中划线风格)。 9 | 10 | 11 | ### 示例 12 | 现在假设语言包`resources/lang/zh-CN/user-profile.php`内容如下: 13 | ```php 14 | return [ 15 | 'fields' => [ 16 | 'name' => '名称', 17 | 'age' => '年龄', 18 | 'class' => '班级', 19 | ], 20 | ]; 21 | ``` 22 | 23 | 控制器`UserProfileController`中设置的`Form`字段会自动读取以上翻译: 24 | ```php 25 | // 不设置labael会自动读取语言包翻译 26 | $form->display('id'); 27 | $form->text('name'); 28 | $form->text('age'); 29 | $form->text('class'); 30 | ``` 31 | 32 | ### 公共翻译 33 | 当`admin_trans_field`函数找不到当前控制器中对指定字段的翻译时,会去`global.php`中查找。如果某些字段是很多数据表中都有的,可以把这些翻译写在`resources/lang/{当前语言}/global.php`文件中。 34 | ```php 35 | return [ 36 | // 常用的字段放在 global.php 中可以所有控制器共用。 37 | 'fields' => [ 38 | 'id' => 'ID', 39 | 'created_at' => '创建时间', 40 | 'updated_at' => '更新时间', 41 | ], 42 | ]; 43 | ``` 44 | 45 | -------------------------------------------------------------------------------- /1.x/model-form-when.md: -------------------------------------------------------------------------------- 1 | # 表单字段动态显示 2 | 3 | > {tip} Since `v1.6.0` 此功能在[工具表单](widgets-form.md)中一样有效 4 | 5 | 表单字段动态显示是指,在选择表单项的指定的选项时,联动显示其他的表单项。 6 | 7 | 8 | 9 | 10 | 11 | 12 | 目前支持的表单联动的组件有: 13 | 14 | - `select` 15 | - `multipleSelect` 16 | - `radio` 17 | - `checkbox` 18 | 19 | ## 使用方法 20 | 21 | 可以将上面的组件分为单选和多选两种类型,其中`select`、`radio`为单选组件,其它为多选组件 22 | 23 | ### 单选组件 24 | 25 | 下面的例子中,选择不同的国籍类型,将会切换选择不同的联动表单项: 26 | 27 | ```php 28 | $form->radio('radio') 29 | ->when([1, 4], function (Form $form) { 30 | // 值为1和4时显示文本框 31 | $form->text('text1'); 32 | $form->text('text2'); 33 | $form->text('text3'); 34 | }) 35 | ->when(2, function (Form $form) { 36 | $form->editor('editor'); 37 | }) 38 | ->when(3, function (Form $form) { 39 | $form->image('image'); 40 | }) 41 | ->options([ 42 | 1 => '显示文本框', 43 | 2 => '显示编辑器', 44 | 3 => '显示文件上传', 45 | 4 => '还是显示文本框', 46 | ]) 47 | ->default(1); 48 | ``` 49 | 50 | 上例中,方法`when(1, $callback)`等效于`when('=', 1, $callback)`, 如果用操作符`=`,则可以省略这个参数 51 | 52 | 同时也支持这些操作符,`=`、`>`、`>=`、`<`、`<=`、`!=`使用方法如下: 53 | 54 | ```php 55 | $form->radio('check') 56 | ->when('>', 1, function () { 57 | 58 | })->when('>=', 2, function () { 59 | 60 | }); 61 | ``` 62 | 63 | `select` 组件的使用方法和`radio`是一样的。 64 | 65 | ### 多选组件 66 | 67 | 多选组件支持两个操作符:`in`、`notIn` 68 | 69 | ```php 70 | $form->checkbox('nationality', '国籍') 71 | ->options([ 72 | 1 => '中国', 73 | 2 => '外国', 74 | ])->when([1, 2], function (Form $form) { 75 | 76 | $form->text('name', '姓名'); 77 | $form->text('idcard', '身份证'); 78 | 79 | })->when('notIn', 2, function (Form $form) { 80 | 81 | $form->text('name', '姓名'); 82 | $form->text('passport', '护照'); 83 | 84 | }); 85 | ``` 86 | 87 | `multipleSelect`组件的使用方法和`checkbox`是一样的。 88 | 89 | 90 | ### 布局 91 | 92 | 表单动态显示功能支持结合`column`以及`tab`布局功能一起使用,用法如下 93 | 94 | 95 | `tab`布局 96 | ```php 97 | $form->tab('Radio', function (Form $form) { 98 | $form->display('title')->value('单选框动态展示'); 99 | 100 | $form->radio('radio') 101 | ->when([1, 4], function (Form $form) { 102 | $form->text('text1'); 103 | $form->text('text2'); 104 | }) 105 | ->when(2, function (Form $form) { 106 | $form->editor('editor'); 107 | }) 108 | ->options($this->options) 109 | ->default(1); 110 | }); 111 | ``` 112 | 113 | `column`布局 114 | ```php 115 | $form->column(6, function (Form $form) { 116 | $form->radio('radio') 117 | ->when([1, 4], function (Form $form) { 118 | $form->text('text1'); 119 | $form->text('text2'); 120 | }) 121 | ->when(2, function (Form $form) { 122 | $form->editor('editor'); 123 | }) 124 | ->options($this->options) 125 | ->default(1); 126 | }); 127 | ``` -------------------------------------------------------------------------------- /1.x/model-grid-combination.md: -------------------------------------------------------------------------------- 1 | # 组合表头 2 | 3 | 通过 `Grid::combine` 方法可以很方便的把任意两个以上的字段组合成一级表头 4 | 5 | 6 | 7 | 8 | 9 | 示例 10 | 11 | ```php 12 | protected function grid() 13 | { 14 | return Grid::make(new Report(), function (Grid $grid) { 15 | // 第一个参数为一级表头字段名称,第二个字段为二级表头字段名称,二级表头字段最少设置两个 16 | $grid->combine('avgCost', ['avgMonthCost', 'avgQuarterCost', 'avgYearCost']); 17 | 18 | // 启用RWD-Table-Patterns插件 19 | $grid->combine('avgVist', ['avgMonthVist', 'avgQuarterVist', 'avgYearVist'])->responsive(); 20 | 21 | // 启用RWD-Table-Patterns插件并设置样式 22 | $grid->combine('top', ['topCost', 'topVist', 'topIncr'])->responsive()->style('color:#1867c0'); 23 | 24 | $grid->content->limit(50)->responsive(); 25 | $grid->cost->sortable()->responsive(); 26 | $grid->avgMonthCost->responsive(); 27 | $grid->avgQuarterCost->responsive()->setHeaderAttributes(['style' => 'color:#5b69bc']); 28 | $grid->avgYearCost->responsive(); 29 | $grid->avgMonthVist->responsive(); 30 | $grid->avgQuarterVist->responsive(); 31 | $grid->avgYearVist->responsive(); 32 | $grid->incrs->hide(); 33 | $grid->avgVists->hide(); 34 | $grid->topCost->responsive(); 35 | $grid->topVist->responsive(); 36 | $grid->topIncr->responsive(); 37 | $grid->date->sortable()->responsive(); 38 | }); 39 | } 40 | ``` 41 | 42 | -------------------------------------------------------------------------------- /1.x/model-grid-events.md: -------------------------------------------------------------------------------- 1 | # 数据表格事件 2 | 3 | ### 初始化 4 | 5 | 6 | 通过 `Grid::resolving` 方法可以监听表格初始化事件。 7 | 8 | 9 | 开发者可以在这两个事件中改变 `Grid` 的一些设置或行为,比如需要禁用掉某些操作,可以在 `app/Admin/bootstrap.php` 加入下面的代码: 10 | 11 | ```php 12 | use Dcat\Admin\Grid; 13 | 14 | Grid::resolving(function (Grid $grid) { 15 | $grid->disableActions(); 16 | 17 | $grid->disablePagination(); 18 | 19 | $grid->disableCreateButton(); 20 | 21 | $grid->disableFilter(); 22 | 23 | $grid->disableRowSelector(); 24 | 25 | $grid->disableTools(); 26 | 27 | $grid->disableExport(); 28 | }); 29 | 30 | 31 | // 只需要监听一次 32 | Grid::resolving(function (Grid $grid) { 33 | ... 34 | }, true); 35 | ``` 36 | 这样就不用在每一个控制器的代码中来设置了。 37 | 38 | 如果全局设置后,要在其中某一个表格中开启设置,比如开启显示操作列,在对应的实例上调用 `$grid->disableActions(false);` 就可以了 39 | 40 | 41 | ### 构建 42 | 43 | 通过 `Grid::composing` 方法可以监听表格被调用事件。 44 | 45 | ```php 46 | Grid::composing(function (Grid $grid) { 47 | ... 48 | }); 49 | 50 | // 只需要监听一次 51 | Grid::composing(function (Grid $grid) { 52 | ... 53 | }, true); 54 | ``` 55 | 56 | ### fetching回调 57 | 58 | 通过 `Grid::fetching` 方法可以监听表格获取数据之前事件,此事件在 `composing` 事件之后触发。 59 | 60 | ```php 61 | 62 | $grid = new Grid(...); 63 | 64 | $grid->fetching(function () { 65 | ... 66 | }); 67 | 68 | 69 | // 可以在 composing 事件中使用 70 | Grid::composing(function (Grid $grid) { 71 | $grid->fetching(function (Grid $grid) { 72 | ... 73 | }); 74 | }); 75 | ``` 76 | 77 | ### rows回调 78 | 79 | 通过 `Grid::rows` 方法可以监听表格获取数据之后事件。 80 | 81 | ```php 82 | use Dcat\Admin\Grid\Row; 83 | use Illuminate\Support\Collection; 84 | 85 | $grid->rows(function (Collection $rows) { 86 | /** 87 | * 获取第一行数据 88 | * 89 | * @var Row $firstRow 90 | */ 91 | $firstRow = $rows->first(); 92 | 93 | if ($firstRow) { 94 | // 获取第一行的 id 95 | $id = $firstRow->id; 96 | // 转化为数组 97 | $row = $firstRow->toArray(); 98 | } 99 | }); 100 | ``` 101 | 102 | ### collection回调 103 | 104 | 这个方法和`display`回调不同的是,它可以批量修改数据, 参考下面实例中的几个使用场景: 105 | 106 | ```php 107 | use Illuminate\Support\Collection; 108 | 109 | $grid->model()->collection(function (Collection $collection) { 110 | 111 | // 1. 可以给每一列加字段,类似上面display回调的作用 112 | $collection->transform(function ($item) { 113 | $item['full_name'] = $item['first_name'] . ' ' . $item['last_name']; 114 | 115 | return $item; 116 | }); 117 | 118 | // 2. 给表格加一个序号列 119 | $collection->transform(function ($item, $index) { 120 | $item['number'] = $index; 121 | 122 | return $item; 123 | }); 124 | 125 | // 3. 从外部接口获取数据填充到模型集合中 126 | $ids = $collection->pluck('id'); 127 | $data = getDataFromApi($ids); 128 | $collection->transform(function ($item, $index) use ($data) { 129 | $item['column_name'] = $data[$index]; 130 | 131 | return $item; 132 | }); 133 | 134 | // 最后一定要返回集合对象 135 | return $collection; 136 | }); 137 | ``` 138 | 139 | `$collection`表示当前这一个表格数据的模型集合, 你可以根据你的需要来读取或者修改它的数据。 140 | 141 | 142 | -------------------------------------------------------------------------------- /1.x/model-grid-export.md: -------------------------------------------------------------------------------- 1 | # 数据导出 2 | 3 | 系统默认使用Easy Excel作为导出工具,支持导出 `csv`、 `xlsx` 和 `ods` 等格式文件。 4 | 5 | 6 | 使用前必须先安装Easy Excel: 7 | 8 | ```bash 9 | composer require dcat/easy-excel 10 | ``` 11 | 12 | > {tip} 默认不开启导出功能。 13 | 14 | ### 启用导出功能 15 | 启用或禁用导出功能 16 | ```php 17 | $grid->export(); 18 | ``` 19 | 20 | 禁用 `导出所有` 选项 21 | ```php 22 | $grid->export()->disableExportAll(); 23 | ``` 24 | 25 | 禁用 `导出选中行` 选项 26 | ```php 27 | $grid->export()->disableExportSelectedRow(); 28 | ``` 29 | 30 | 禁用 `导出当前页` 选项 31 | ```php 32 | $grid->export()->disableExportCurrentPage(); 33 | ``` 34 | 35 | ### 导出文件类型 36 | 37 | > {tip} 默认导出 `xlsx` 格式文件。 38 | 39 | ```php 40 | // csv 41 | $grid->export()->csv(); 42 | 43 | // xlsx 44 | $grid->export()->xlsx(); 45 | 46 | // ods 47 | $grid->export()->ods(); 48 | ``` 49 | 50 | ### 设置列标题 51 | 52 | > {tip} 如果设置了标题,那么导出的文件的**列数**与标题的**列数**相同,且列的**排序**也相同。 53 | 54 | ```php 55 | // 只导出 id, name和email 三列数据 56 | $titles = ['id' => 'ID', 'name' => '名称', 'email' => '邮箱']; 57 | 58 | $grid->export($titles); 59 | 60 | // 也可以这么使用 61 | $grid->export()->titles($titles); 62 | ``` 63 | 64 | ### 处理导出数据 65 | 66 | ```php 67 | $grid->export()->rows(function (array $rows) { 68 | foreach ($rows as $index => &$row) { 69 | $row['name'] = $row['first_name'].' '.$row['last_name']; 70 | } 71 | 72 | return $rows; 73 | }); 74 | ``` 75 | 76 | ### 设置导出文件名 77 | 78 | ```php 79 | $grid->export()->filename('管理员数据'); 80 | ``` 81 | 82 | 83 | ## 扩展导出功能 84 | 85 | 如果系统内置的导出功能不了自己的需求,可以按照下面的步骤来自定义导出功能 86 | 87 | 本示例用[Laravel-Excel](https://github.com/Maatwebsite/Laravel-Excel)作为excel操作库,当然也可以使用任何其他excel库 88 | 89 | 首先安装好它: 90 | 91 | ```shell 92 | composer require maatwebsite/excel:~2.1.0 93 | 94 | php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" 95 | ``` 96 | 97 | 然后新建自定义导出类,比如`app/Admin/Extensions/ExcelExpoter.php`: 98 | ```php 99 | sheet('Sheetname', function($sheet) { 113 | 114 | // 最多导出10W条数据 115 | // 必须设置maxSize,当否则选择导出所有选项时只能导出默认的20条数据。 116 | $maxSize = 10000; 117 | 118 | // 这段逻辑是从表格数据中取出需要导出的字段 119 | $rows = collect($this->buildData(1, $maxSize))->map(function ($item) { 120 | return array_only($item, ['id', 'title', 'content', 'rate', 'keywords']); 121 | }); 122 | 123 | $sheet->rows($rows); 124 | 125 | }); 126 | 127 | })->export('xls'); 128 | } 129 | } 130 | ``` 131 | 132 | 然后在`model-grid`中使用这个导出类: 133 | ```php 134 | 135 | use App\Admin\Extensions\ExcelExpoter; 136 | 137 | $grid->export(new ExcelExpoter()); 138 | ``` 139 | 140 | 有关更多`Laravel-Excel`的使用方法,参考[laravel-excel/docs](http://www.maatwebsite.nl/laravel-excel/docs) -------------------------------------------------------------------------------- /1.x/model-grid-exporter.md: -------------------------------------------------------------------------------- 1 | # 自定义导出 2 | 3 | dcat-admin的数据表格默认支持导出csv文件, 4 | 5 | ```php 6 | getTable().'.csv'; 17 | 18 | $data = $this->getData(); 19 | 20 | $output = ''; 21 | 22 | $headers = [ 23 | 'Content-Encoding' => 'UTF-8', 24 | 'Content-Type' => 'text/csv;charset=UTF-8', 25 | 'Content-Disposition' => "attachment; filename=\"$filename\"", 26 | ]; 27 | 28 | response(rtrim($output, "\n"), 200, $headers)->send(); 29 | 30 | exit; 31 | } 32 | } 33 | ``` -------------------------------------------------------------------------------- /1.x/model-grid-header.md: -------------------------------------------------------------------------------- 1 | # 头部和脚部 2 | 3 | 数据表格支持往头部和脚部两个区块填入你想要的内容 4 | 5 | ```php 6 | $grid->header(function ($collection) { 7 | return 'header'; 8 | }); 9 | 10 | $grid->footer(function ($collection) { 11 | return 'footer'; 12 | }); 13 | ``` 14 | 15 | 其中闭包函数的参数`$collection`为`Illuminate\Support\Collection`类实例,是当前页表格数据,下面是两个不同场景的使用举例 16 | 17 | ## 头部 18 | 19 | ```php 20 | $grid->header(function ($collection) use ($grid) { 21 | $query = Model::query(); 22 | 23 | // 拿到表格筛选 where 条件数组进行遍历 24 | $grid->model()->getQueries()->unique()->each(function ($value) use (&$query) { 25 | if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) { 26 | return; 27 | } 28 | 29 | $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []); 30 | }); 31 | 32 | // 查出统计数据 33 | $data = $query->get(); 34 | 35 | // 自定义组件 36 | return new Card($data); 37 | }); 38 | ``` 39 | 40 | 自定义头部展示的组件实现 41 | ```php 42 | data = $data; 61 | } 62 | 63 | public function script() 64 | { 65 | return <<script()); 80 | 81 | return view('...', ['data' => $this->data])->render(); 82 | } 83 | } 84 | ``` 85 | 86 | 87 | ## 脚部 88 | 89 | 一个比较常见的场景是在数据表格的脚部显示统计信息,比如在订单表格的脚部加入收入统计,可以参考下面的代码实现: 90 | 91 | ```php 92 | $grid->footer(function ($collection) use ($grid) { 93 | $query = Model::query(); 94 | 95 | // 拿到表格筛选 where 条件数组进行遍历 96 | $grid->model()->getQueries()->unique()->each(function ($value) use (&$query) { 97 | if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) { 98 | return; 99 | } 100 | 101 | $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []); 102 | }); 103 | 104 | // 查出统计数据 105 | $data = $query->get(); 106 | 107 | return "
总收入 : $data
"; 108 | }); 109 | ``` 110 | 111 | 如果有比较复杂的脚部需要显示,也可以使用视图对象或者封装成一个类来实现。 -------------------------------------------------------------------------------- /1.x/model-grid-selector.md: -------------------------------------------------------------------------------- 1 | # 表格规格筛选器 2 | 3 | 4 | 这个功能用来构建类似淘宝或京东商品的规格选择。 5 | 6 | 7 | 8 | 9 | 10 | 11 | ### 基本使用 12 | 13 | 14 | > {tip} `select`和`selectOne`方法的第二个参数为选择器`label`, 可以省略,如果省略的话将会自动使用翻译文件的翻译. 15 | 16 | 17 | 如下代码所示,假设`brand`字段的4个取值分别对应4个品牌,下面的方式会构建出`brand`的规格选择器 18 | 19 | ```php 20 | use Dcat\Admin\Grid; 21 | 22 | $grid->selector(function (Grid\Tools\Selector $selector) { 23 | $selector->select('brand', '品牌', [ 24 | 1 => '华为', 25 | 2 => '小米', 26 | 3 => 'OPPO', 27 | 4 => 'vivo', 28 | ]); 29 | }); 30 | ``` 31 | 32 | `select`方法默认是多选的,在页面上点击每一个选项的右边的加号,这个字段的查询会增加一个查询选项,如果字段筛选只允许选择一项,使用`selectOne`方法 33 | 34 | ```php 35 | $selector->selectOne('brand', '品牌', [ 36 | 1 => '华为', 37 | 2 => '小米', 38 | 3 => 'OPPO', 39 | 4 => 'vivo', 40 | ]); 41 | ``` 42 | 43 | ### 关联关系字段查询 44 | 45 | > {tip} Since `v1.7.0` 46 | 47 | 如果安装了 [dcat/laravel-wherehasin](https://github.com/jqhph/laravel-wherehasin),则会优先使用`whereHasIn`方法进行查询操作 48 | 49 | ```php 50 | use Dcat\Admin\Grid; 51 | 52 | $grid->selector(function (Grid\Tools\Selector $selector) { 53 | $selector->select('brand.id', '品牌', [ 54 | 1 => '华为', 55 | 2 => '小米', 56 | 3 => 'OPPO', 57 | 4 => 'vivo', 58 | ]); 59 | }); 60 | ``` 61 | 62 | 63 | ### 自定义查询 64 | 上面的方式会使用在选择器上选定的值,作为查询条件进行查询,但是有些情况需要更灵活的控制查询方式,那么可以使用下面的方式自定义查询: 65 | 66 | ```php 67 | $selector->select('price', '价格', ['0-999', '1000-1999', '2000-2999'], function ($query, $value) { 68 | $between = [ 69 | [0, 999], 70 | [1000, 1999], 71 | [2000, 2999], 72 | ]; 73 | 74 | $value = current($value); 75 | 76 | $query->whereBetween('price', $between[$value]); 77 | }); 78 | ``` 79 | 80 | 如上所示,传入一个匿名函数作为第四个参数,价格字段price选择之后,将会使用匿名函数中的逻辑进行数据查询,这样你可以定义任意的查询方式。 81 | -------------------------------------------------------------------------------- /1.x/model-grid-trans.md: -------------------------------------------------------------------------------- 1 | # 表格字段翻译 2 | 3 | 数据表格中所有使用到字段的地方都会自动读取语言包中的翻译。 4 | 5 | > {tip} 语言包的详细使用方法请参考[多语言](trans.md)。 6 | 7 | ### 语言包名称 8 | 语言包名称需要与控制器名相对应,假如控制器名`UserProfileController`,则对应的语言包为`resources/lang/{当前语言}/user-profile.php`(需要转化为小写中划线风格)。 9 | 10 | 11 | ### 示例 12 | 现在假设语言包`resources/lang/zh-CN/user-profile.php`内容如下: 13 | ```php 14 | return [ 15 | 'fields' => [ 16 | 'name' => '名称', 17 | 'age' => '年龄', 18 | 'class' => '班级', 19 | ], 20 | ]; 21 | ``` 22 | 23 | 控制器`UserProfileController`中设置的`Grid`字段会自动读取以上翻译: 24 | ```php 25 | // 不设置labael会自动读取语言包翻译 26 | $grid->id(); 27 | $grid->name; 28 | $grid->age; 29 | $grid->class; 30 | 31 | $grid->filter(function ($filter) { 32 | $filter->gt('age'); 33 | }); 34 | 35 | // 上面代码等同于 36 | $grid->name('名称'); 37 | $grid->age('年龄'); 38 | 39 | // 也可这样使用 40 | $grid->id(admin_trans_field('id')); 41 | $grid->name(admin_trans_field('name')); 42 | $grid->age(admin_trans_field('age')); 43 | 44 | ``` 45 | 46 | ### 公共翻译 47 | 当`admin_trans_field`函数找不到当前控制器中对指定字段的翻译时,会去`global.php`中查找。如果某些字段是很多数据表中都有的,可以把这些翻译写在`resources/lang/{当前语言}/global.php`文件中。 48 | ```php 49 | return [ 50 | // 常用的字段放在 global.php 中可以所有控制器共用。 51 | 'fields' => [ 52 | 'id' => 'ID', 53 | 'created_at' => '创建时间', 54 | 'updated_at' => '更新时间', 55 | ], 56 | ]; 57 | ``` 58 | 59 | -------------------------------------------------------------------------------- /1.x/model-json.md: -------------------------------------------------------------------------------- 1 | # JSON格式字段处理 2 | 3 | `dcat-admin`的表单提供了下面几个组件来处理`JSON`格式的字段,方便用来处理`JOSN`格式的对象、一维数组、二维数组等对象。 4 | 5 | 6 | ## 键值对象 (keyValue) 7 | 8 | ![]({{public}}/assets/img/screenshots/key-value.png) 9 | 10 | 如果你的字段存储的是不固定`键`的`{"field":"value"}`格式,可以用`keyValue`组件: 11 | 12 | ```php 13 | $form->keyValue('column_name'); 14 | 15 | // 设置校验规则 16 | $form->keyValue('column_name')->rules('required|min:5'); 17 | ``` 18 | 19 | ## 固定键值对象 (embeds) 20 | 21 | ![]({{public}}/assets/img/screenshots/embeds.png) 22 | 23 | 用于处理`mysql`的`JSON`类型字段数据或者`mongodb`的`object`类型数据,也可以将多个`field`的数据值以`JSON`字符串的形式存储在`mysql`的字符串类型字段中 24 | 25 | 适用于有固定键值的`JSON`类型字段 26 | 27 | ```php 28 | $form->embeds('column_name', function ($form) { 29 | 30 | $form->text('key1')->required(); 31 | $form->email('key2')->required(); 32 | $form->datetime('key3'); 33 | 34 | $form->dateRange('key4', 'key5', '范围')->rules('required'); 35 | })->saving(funtion ($v) { 36 | // 转化为json格式存储 37 | return json_encode($v); 38 | }); 39 | 40 | // 自定义标题 41 | $form->embeds('column_name', '字段标题', function ($form) { 42 | ... 43 | }); 44 | ``` 45 | 46 | 回调函数里面构建表单元素的方法调用和外面是一样的。 47 | 48 | ## 一维数组 (list) 49 | 50 | ![]({{public}}/assets/img/screenshots/form-list.png) 51 | 52 | 如果你的字段是用来存储`["foo", "Bar"]`格式的一维数组, 可以使用`list`组件: 53 | 54 | ```php 55 | $form->list('column_name'); 56 | 57 | // 设置校验规则 58 | $form->list('column_name')->rules('required|min:5'); 59 | 60 | // 设置最大和最小元素个数 61 | $form->list('column_name')->max(10)->min(5); 62 | ``` 63 | 64 | ## 二维数组 (table) 65 | 66 | ![]({{public}}/assets/img/screenshots/form-table.png) 67 | 68 | 如果某一个字段存储的是`json`格式的二维数组,可以使用`table`表单组件来实现快速的编辑: 69 | 70 | ```php 71 | $form->table('column_name', function ($table) { 72 | $table->text('key'); 73 | $table->text('value'); 74 | $table->textarea('desc'); 75 | })->saving(function ($v) { 76 | return json_encode($v); 77 | }); 78 | ``` 79 | 80 | 这个组件类似于`hasMany`组件,不过是用来处理单个字段的情况,适用于简单的二维数据。 81 | 82 | 83 | ## 二维数组 (array) 84 | 85 | > {tip} Since `v1.7.0` 86 | 87 | ![]({{public}}/assets/img/screenshots/has-many.png) 88 | 89 | 如果某一个字段存储的是`json`格式的二维数组,并且字段比较多,可以使用`array`表单组件来实现快速的编辑: 90 | 91 | ```php 92 | $form->array('column_name', function ($table) { 93 | $table->text('key'); 94 | $table->text('value'); 95 | $table->textarea('desc'); 96 | })->saveAsJson(); 97 | ``` 98 | -------------------------------------------------------------------------------- /1.x/model-show-extend.md: -------------------------------------------------------------------------------- 1 | # 详情字段显示扩展 2 | 3 | 这个功能用来扩展详情字段显示, 在内置的显示方法不满足需求的情况下,可以使用这个功能来实现 4 | 5 | 首先定义扩展类: 6 | 7 | ```php 8 | value); 23 | } 24 | } 25 | ``` 26 | 然后在`app/Admin/bootstrap.php`中注册扩展类 27 | 28 | ```php 29 | use Dcat\Admin\Show\Field; 30 | use App\Admin\Extensions\Show\UnSerialize; 31 | 32 | Field::extend('unserialize', UnSerialize::class); 33 | ``` 34 | 然后在控制器中使用这个扩展 35 | 36 | ```php 37 | $show->column()->unserialize('xxx'); 38 | ``` 39 | 传入unserialize()方法的参数会按顺序传入UnSerialize::render()方法中。 40 | 41 | 在父类`Dcat\Admin\Show\AbstractField`中可以看到几个常用的属性 42 | 43 | ```php 44 | /** 45 | * Field value. 46 | * 47 | * @var mixed 48 | */ 49 | protected $value; 50 | 51 | /** 52 | * Current field model. 53 | * 54 | * @var Fluent 55 | */ 56 | protected $model; 57 | 58 | /** 59 | * If this field show with a border. 60 | * 61 | * @var bool 62 | */ 63 | public $border = true; 64 | 65 | /** 66 | * If this field show escaped contents. 67 | * 68 | * @var bool 69 | */ 70 | public $escape = true; 71 | ``` 72 | 其中`$value`和`$model`分别是当前字段值和当前详情内容的数据,在`render()`方法中可以用来获取你想要的数据。 73 | 74 | `$border`用来控制当前显示内容是否需要外边框,`$escape`分别用来设置当前显示内容要不要HTML转义。 -------------------------------------------------------------------------------- /1.x/model-show-init.md: -------------------------------------------------------------------------------- 1 | # 数据详情初始化 2 | 3 | 通过`Show::resolving`方法设置的回调函数会在`Dcat\Admin\Show`类被实例化时触发; 4 | 5 | 通过`Show::composing`方法设置的回调函数会在`render()`方法被调用时触发; 6 | 7 | 开发者可以在这两个事件中改变`Show`的一些设置或行为,比如需要禁用掉某些操作,可以在`app/Admin/bootstrap.php`加入下面的代码: 8 | 9 | ```php 10 | use Dcat\Admin\Show; 11 | 12 | Show::resolving(function (Show $show) { 13 | 14 | $show->showQuickEdit(); 15 | 16 | }); 17 | ``` 18 | -------------------------------------------------------------------------------- /1.x/model-show-trans.md: -------------------------------------------------------------------------------- 1 | # 数据详情字段翻译 2 | 3 | 与数据表格字段翻译的使用基本一致,可参考[数据表格字段翻译](model-grid-trans.md)。 -------------------------------------------------------------------------------- /1.x/model-tree.md: -------------------------------------------------------------------------------- 1 | # 模型树 2 | 3 | 这个功能可以实现一个树状组件,可以用拖拽的方式实现数据的层级、排序等操作,下面是基本的用法。 4 | 5 | 6 | 7 | 8 | 9 | ## 表结构和模型 10 | 要使用`model-tree`,要遵守约定的表结构: 11 | 12 | > {tip} `parent_id`字段一定要默认为`0`!!! 13 | 14 | ```sql 15 | CREATE TABLE `demo_categories` ( 16 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 17 | `parent_id` int(11) NOT NULL DEFAULT '0', 18 | `order` int(11) NOT NULL DEFAULT '0', 19 | `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL, 20 | `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 21 | `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 22 | PRIMARY KEY (`id`) 23 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci 24 | ``` 25 | 上面的表格结构里面有三个必要的字段`parent_id`、`order`、`title`,其它字段没有要求。 26 | 27 | 对应的模型为`app/Models/Category.php`: 28 | ```php 29 | {tip} 为了便于阅读,这里不再展示 `Repository` 代码。 46 | 47 | ```php 48 | header('树状模型') 90 | ->body(function (Row $row) { 91 | $tree = new Tree(new Category); 92 | 93 | $row->column(12, $tree); 94 | }); 95 | } 96 | } 97 | ``` 98 | 可以通过下面的方式来修改行数据的显示: 99 | ```php 100 | $tree = new Tree(new Category); 101 | 102 | $tree->branch(function ($branch) { 103 | $src = config('admin.upload.host') . '/' . $branch['logo'] ; 104 | $logo = ""; 105 | 106 | return "{$branch['id']} - {$branch['title']} $logo"; 107 | }); 108 | ``` 109 | 在回调函数中返回的字符串类型数据,就是在树状组件中的每一行的显示内容,`$branch`参数是当前行的数据数组。 110 | 111 | 如果要修改模型的查询,用下面的方式 112 | ```php 113 | $tree->query(function ($model) { 114 | return $model->where('type', 1); 115 | }); 116 | ``` 117 | 118 | ## 自定义工具栏按钮 119 | 120 | 请参考文档[模型树动作](action-tree.md) 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /1.x/update.md: -------------------------------------------------------------------------------- 1 | # 版本升级须知 2 | 3 | 4 | ### 说明 5 | 6 | `Dcat Admin`的版本发行将会参考主流`web框架`的发行策略,尽量降低版本升级带来的影响,小版本和补丁**决不**包含非兼容性更改;同时我们也将会提供更新日志,详细说明新版本的改动以及可能造成的影响。 7 | 8 | 9 | 10 | 11 | 12 | ### 升级命令 13 | 升级命令 14 | ```bash 15 | composer update dcat/laravel-admin 16 | ``` 17 | 18 | 升级成功之后一般需要重新发布语言包、配置文件、前端静态资源等文件,然后清理浏览器缓存 19 | ```bash 20 | php artisan admin:publish --force 21 | ``` 22 | 23 | 只更新语言包 24 | ```bash 25 | php artisan admin:publish --force --lang 26 | ``` 27 | 28 | 只更新配置文件 29 | ```bash 30 | php artisan admin:publish --force --config 31 | ``` 32 | 33 | 34 | 只更新前端静态资源 35 | ```bash 36 | php artisan admin:publish --force --assets 37 | ``` 38 | 39 | 只更新数据库迁徙文件(这个一般不需要更新) 40 | ```bash 41 | php artisan admin:publish --force --migrations 42 | ``` -------------------------------------------------------------------------------- /1.x/v1-1-0.md: -------------------------------------------------------------------------------- 1 | # v1.1.0更新日志 2 | 3 | 4 | **发布时间** `2020-04-20` 5 | 6 | 功能新增以及优化部分 7 | 8 | - 集成`TinyMCE`作为内置编辑器,并支持图片上传功能 9 | - 增加绿色主题配色 10 | - 数据表格快捷搜索增加`auto`方法,允许禁用自动提交功能 11 | - 优化背景色以及表格边框颜色,加深对比度 12 | - 登陆页面优化 13 | - 模型树字段名称设置功能简化 14 | - 优化菜单栏样式 15 | - 增加切换或刷新页面时移除模态窗遮罩层功能 16 | - 表单页面禁用`perfectScrollbar`滚动条美化插件 17 | - 表单`Field`增加`resolving`和`composing`事件支持 18 | 19 | `Bug`修复部分 20 | 21 | - 修复`action`确认弹窗设置空字符串或去除弹窗方法报错问题 22 | - 修复`Show\Field::view`方法会转义`HTML`实体问题 23 | - 修复编辑页面聚焦输入框时按回车键会触发删除确认弹窗问题 24 | - 修复 `Laravel5.5`兼容问题 25 | - 修复`switchGroup`没有颜色默认值问题 26 | 27 | 28 | 29 | 30 | ### v1.0.1 31 | 32 | - 修复数据表格筛选器`selectOne`方法筛选报错问题 33 | - 文件/图片上传表单自定义上传接口时关联文件删除相关功能 34 | - 优化图片上传表单样式 35 | - 优化菜单栏样式 36 | 37 | -------------------------------------------------------------------------------- /1.x/v1-2-5.md: -------------------------------------------------------------------------------- 1 | # v1.2.5更新日志 2 | 3 | **发布时间** `2020-04-30` 4 | 5 | #### 功能新增以及优化部分 6 | 7 | **1.从服务器删除文件时增加确认弹窗** 8 | 9 | 最近收到一些同学的反馈,图片删除操作太危险,容易造成误删的情况,因此这个版本中我们加上了删除文件时需要点击确认弹窗的功能 10 | 11 | 12 | ![](https://cdn.learnku.com/uploads/images/202004/30/38389/VQTvmDch4u.png!large) 13 | 14 | 15 | 如果你不想让用户从服务器删除文件,可以使用`disableRemove`方法,这样用户就只能替换文件而不能直接删除 16 | 17 | > 这个方法在旧版本中也能使用,但有部分同学没发现这个用法,所以这里说明一下 18 | 19 | ```php 20 | $form->image('my_img')->disableRemove(); 21 | ``` 22 | 23 | **2.`Grid\Column::prepand`、`Grid\Column::append`方法增加支持闭包类型参数** 24 | 25 | ```php 26 | $grid->email->prepend(function ($value, $original) { 27 | // $value 是当前字段值 28 | // $original 是当前字段从数据库中查询出来的原始值 29 | 30 | // 获取其他字段值 31 | $username = $this->username; 32 | 33 | return "[{$username}]"; 34 | }); 35 | ``` 36 | 37 | **3.增加`Grid\Column::dot`方法** 38 | 39 | 通过`dot`方法可以在列文字前面加上一个带颜色的圆点 40 | 41 | ```php 42 | use Dcat\Admin\Admin; 43 | 44 | $grid->state 45 | ->using([1 => '未处理', 2 => '已处理', ...]) 46 | ->dot( 47 | [ 48 | 1 => 'primary', 49 | 2 => 'danger', 50 | 3 => 'success', 51 | 4 => Admin::color()->info(), 52 | ], 53 | 'primary' // 默认颜色 54 | ); 55 | ``` 56 | 效果 57 | 58 | ![]({{public}}/assets/img/screenshots/grid-column-dot.png) 59 | 60 | 61 | **4.`Show\Field::prepand`、`Show\Field::append`方法支持闭包类型参数** 62 | 63 | **5.`Show\Field::dot`方法** 64 | 65 | **6.调整表格过滤器`panel`布局方式的间距** 66 | 67 | **7.数据表格`quickSearch`移除重置按钮,适配低版本浏览器** 68 | 69 | **8.代码生成器生成的模型自动兼容`Laravel7`的时间格式显示异常问题** 70 | 71 | **9.优化`EloquentRepository`的删除功能** 72 | 73 | **10.`Show\Field::image`支持显示多图** 74 | 75 | #### Bug修复部分 76 | 77 | 1. 修复数据表格`quickSearch`的`orWhere`查询污染默认条件问题 78 | 2. 修复`Form::number`字段编辑页面默认值不为`0`问题 79 | 3. 修复`select2`下拉选框不兼容`editor-md`组件问题 80 | 4. 修复`Form::table`表单下`select2`下拉选框`remoteOptions`功能编辑选中异常问题 81 | 5. 修复树状表格编辑后跳转回列表时`url`参数异常问题 82 | 6. 修复文件上传字段名称为`file`时编辑异常问题 83 | 7. 修复单文件上传成功文件数量提示异常问题 -------------------------------------------------------------------------------- /1.x/v1-3-0.md: -------------------------------------------------------------------------------- 1 | # v1.3.0更新日志 2 | 3 | **发布时间** `2020-05-06` 4 | 5 | #### 功能新增以及优化部分 6 | 7 | **1.新增主题配色** 8 | 9 | 新增主题配色`blue-dark`,效果如下 10 | 11 | 12 | 13 | 14 | **2.自定义主题配色** 15 | 16 | 这个版本开放了自定义主题配色的功能,开发者通过`admin:minify`命令就可以随意自定义主题配色,非常简单方便,具体使用请参照文档[自定义主题配色](theme.md#custom)。 17 | 18 | **3.优化表格过滤器滑动面板收起功能** 19 | 20 | 之前收到用户反馈过滤器的滑动面板收起操作不太方便,所以在这个版本中我们增加了点击页面任意位置可以收起滑动面板的功能。 21 | 22 | 23 | 24 | 25 | 26 | **4.php7.4支持** 27 | 28 | **5.增加多图/文件上传表单排序功能** 29 | 30 | 使用 31 | ```php 32 | $form->multipleImage('images')->sortable(); 33 | ``` 34 | 35 | **5.时间日期插件多语言支持** 36 | 37 | **6.select2插件简体中文支持** 38 | 39 | **7.增加`select`表单`placeholder`设置** 40 | 41 | **8.增加`selectResource`表单`placeholder`设置** 42 | 43 | **9.美化`tab`样式** 44 | 45 | **10.调整删除确认弹窗提示信息** 46 | 47 | 48 | #### BUG修复部分 49 | 50 | - 修复同个页面无法显示多个富文本编辑器问题 [#63](https://github.com/jqhph/dcat-admin/issues/63) 51 | - 修复代码生成器在设置了表前缀之后无法读取表信息问题 52 | - 修复`Form::table`字段在不保存为`json`字符串的情况下报错问题[#59](https://github.com/jqhph/dcat-admin/issues/63) 53 | - 修复数据详情`Show`无法显示关联模型字段值问题 54 | - 修复弹窗表单重复提示失败信息问题 55 | 56 | -------------------------------------------------------------------------------- /1.x/v1-3-2.md: -------------------------------------------------------------------------------- 1 | # v1.3.2更新日志 2 | 3 | 这个版本主要是`BUG`修复版本,发布时间 `2020/05/08` 4 | 5 | ## BUG修复部分 6 | 7 | - 修复菜单绑定角色以及权限后不显示问题 8 | - 修复`select`表单会默认选中`key`为`0`的选项问题 9 | - 修复`select`表单联动编辑页面不会自动选中子表单选项问题 10 | - 修复`Displayers\Button`报错问题 11 | - 修复数据表格使用字段排序`sortable`后无法导出全部数据问题 [#77](https://github.com/jqhph/dcat-admin/issues/77) 12 | - 修复`qrcode`使用问题 [#80](https://github.com/jqhph/dcat-admin/issues/80) 13 | - 修复`full page`页面出现`pjax`跳转问题 14 | 15 | ## 功能优化部分 16 | 17 | - 增加台湾省繁体字 18 | - 富文本编辑器`Editor`增加默认参数`convert_urls=false` 19 | - `tree`删除确认弹窗显示`ID` 20 | - 移除菜单管理和权限管理的页面跳转编辑按钮 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /1.x/v1-3-4.md: -------------------------------------------------------------------------------- 1 | # v1.3.2更新日志 2 | 3 | 发布时间 `2020/05/12` 4 | 5 | ## 功能优化部分 6 | 7 | **1.优化表单多列布局功能,优化表单间距,使整体更加协调** 8 | 9 | ```php 10 | $form->row(function (Form\Row $row) { 11 | $form->width(4)->text('username')->required(); 12 | $form->width(3)->text('title'); 13 | ... 14 | }); 15 | 16 | $form->row(function (Form\Row $row) { 17 | ... 18 | }); 19 | 20 | ... 21 | ``` 22 | 效果 23 | ![](https://cdn.learnku.com/uploads/images/202005/12/38389/LuigrONAja.png!large) 24 | 25 | 26 | 27 | **2.增加数据详情Show多列布局功能** 28 | ```php 29 | $show->row(function (Show\Row $show) { 30 | $show->width(3)->id; 31 | $show->width(3)->name; 32 | $show->width(5)->email; 33 | }); 34 | 35 | $show->row(function (Show\Row $show) { 36 | $show->width(5)->email_verified_at; 37 | $show->created_at; 38 | $show->updated_at; 39 | }); 40 | 41 | $show->row(function (Show\Row $show) { 42 | $show->width(3)->field('profile.first_name'); 43 | $show->field('profile.last_name'); 44 | $show->width(3)->field('profile.postcode'); 45 | }); 46 | ``` 47 | 效果 48 | ![](https://cdn.learnku.com/uploads/images/202005/12/38389/4net12VyoJ.png!large) 49 | 50 | **3.增加HasMany一对多表单对文件上传表单的支持** 51 | ```php 52 | $form->hasMany('paintings', function (Form\NestedForm $form) { 53 | $form->text('title'); 54 | $form->file('attachment'); 55 | $form->image('image'); 56 | }); 57 | ``` 58 | 59 | 60 | **4.增加一对一表单对文件上传表单的支持** 61 | 62 | ```php 63 | $form->image('profile.avatar'); 64 | ``` 65 | 66 | **5.Content和Color增加Macroable支持** 67 | 在你的`app\Admin\bootstrap.php`中加入以下代码 68 | ```php 69 | Content::macro('getView', function () { 70 | return $this->view; 71 | }); 72 | ``` 73 | 使用 74 | ```php 75 | $view = $content->getView(); 76 | ``` 77 | 78 | **6.登录页面错误信息显示文件布局优化** 79 | 80 | ## BUG修复部分 81 | 82 | - 修复`selectResource`表单弹窗内部无法使用快捷搜索功能问题 83 | - 修复`HasMany`无法把字段保存为空问题 84 | - 修复`Form::currency`字段保存字段值异常问题 [#98](https://github.com/jqhph/dcat-admin/issues/98) 85 | - 修复`select`表单`loads`编辑页面选中子表单选项问题 [#99](https://github.com/jqhph/dcat-admin/issues/99) 86 | - 修复`Form`编辑页面`builder`闭包内无法获取到表单值问题 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /1.x/v1-4-0.md: -------------------------------------------------------------------------------- 1 | # v1.4.0 更新日志 2 | 3 | 发布时间 `2020/05/17` 4 | 5 | ## 功能新增及优化部分 6 | 7 | **1. 新增多应用(多后台)功能** 8 | 9 | 运行命令生成新应用 10 | ```php 11 | // NewAdmin 为应用名称 12 | php artisan admin:app NewAdmin 13 | ``` 14 | 运行成功后你的项目中会新增一个新的应用目录 `app/NewAdmin`,以及新的配置文件 `config/new-admin.php`。 15 | 16 | 启用新应用,打开配置文件`config/admin.php`写入 17 | ```php 18 | return [ 19 | ... 20 | 21 | 'multi_app' => [ 22 | // 与新应用的配置文件名称一致 23 | // 设置为true启用,false则是停用 24 | 'new-admin' => true, 25 | ], 26 | ]; 27 | ``` 28 | 然后就可以打开浏览器访问这个新应用了 `http://localhost:8000/new-admin`,更改路由前缀以及详细内容请参考文档[多应用](https://learnku.com/docs/dcat-admin/1.x/multi-application-multi-background/8475)。 29 | 30 | **2. 新增行内编辑功能** 31 | 32 | 此功能由小伙伴[@youxx](https://github.com/youyingxiang)贡献 33 | ```php 34 | $grid->column('title')->editable(); 35 | 36 | // 编辑成功后刷新页面 37 | $grid->column('nickname')->editable(true); 38 | ``` 39 | 40 | 效果 41 | 42 | 43 | 44 | 45 | 46 | 47 | **3. 新增数据表格列使用action方法** 48 | 49 | 此功能由小伙伴[@lilashih](https://github.com/lilashih)贡献 50 | ```php 51 | $grid->column('star')->action(Star::class); 52 | ``` 53 | 详细用法请参考文档[列的显示 - action](model-grid-column-display.md#action) 54 | 55 | **4. RowSelector::titleColumn支持设置关联模型字段** 56 | 57 | ```php 58 | $grid->rowSelector()->titleColumn('users.nickname'); 59 | ``` 60 | 61 | **5. 表格工具栏允许设置自定义按钮在右边显示** 62 | 63 | ```php 64 | $grid->tools("..."); 65 | ``` 66 | 67 | **6. 新增快捷创建设置提交地址方法** 68 | 69 | 此功能由小伙伴[@youxx](https://github.com/youyingxiang)贡献 70 | ```php 71 | $grid->quickCreate(function (Grid\Tools\QuickCreate $create) { 72 | $create->action('auth/users'); 73 | $create->method('GET'); 74 | 75 | $create->text('username')->required(); 76 | ... 77 | }); 78 | ``` 79 | 80 | **7. 优化数据表格limit方法** 81 | 82 | 增加按钮点击可展开完整内容 83 | ```php 84 | // 最多显示50个字符 85 | $grid->column('content')->limit(50); 86 | ``` 87 | 88 | 效果 89 | 90 | 91 | 92 | 93 | 94 | 95 | **8. hasMany表单table模式样式优化** 96 | 97 | **9. 默认隐藏li 圆点** 98 | 99 | 100 | 101 | 102 | ## BUG修复部分 103 | - 修复一对多`HasMany`表单编辑情况下有几率报错问题 [#108](https://github.com/jqhph/dcat-admin/issues/108) 104 | - 修复表单Image字段使用`macro`方法无效问题 105 | - 修复表格点击列展开功能会增加行间距问题 106 | - 修复DialogTree同个字段下无法显示不同节点问题 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /1.x/v1-4-5.md: -------------------------------------------------------------------------------- 1 | # v1.4.5 更新日志 2 | 3 | 发布时间 `2020/05/23` 4 | 5 | ## 功能新增及优化部分 6 | 7 | **1. 新增切换数据表格工具栏按钮样式功能** 8 | 9 | 并且在这个版本中,会默认使用`outline`样式,用法 10 | ```php 11 | $grid->toolsWithOutline(); 12 | 13 | // 禁止 14 | $grid->toolsWithOutline(false); 15 | ``` 16 | 17 | 18 | 19 | 20 | 21 | 如果你希望某个按钮不使用`outline`模式,可以在按钮的`class`属性中加上`disable-outline` 22 | ```php 23 | $grid->tools('测试按钮'); 24 | ``` 25 | 26 | 27 | **2. 新增表格使用鼠标右键显示行操作菜单功能** 28 | 29 | 用法 30 | ```php 31 | use Dcat\Admin\Grid\Displayers\ContextMenuActions; 32 | 33 | $grid->setActionClass(ContextMenuActions::class); 34 | ``` 35 | 36 | 如果需要全局修改,可以更改配置参数`admin.grid.grid_action_class`的值为`Dcat\Admin\Grid\Displayers\ContextMenuActions` 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | **3. 优化dropdown下拉菜单显示定位功能** 45 | 46 | **4. 优化`Grid::withBorder`方法,允许禁用表格的边框模式** 47 | ```php 48 | // 传false可以禁用边框模式 49 | $grid->withBorder(false); 50 | ``` 51 | 52 | 53 | **5. 优化UI样式** 54 | 55 | **6. 优化快捷编辑弹窗标题** 56 | 57 | **7. 优化静态资源压缩命令,防止中断命令可能造成主题颜色异常问题** 58 | 59 | ## BUG修复部分 60 | 61 | - 修复表格行内编辑无法保存纯数字问题 62 | - 修复模型树数据表中包含`path`字段时,二级节点不可编辑问题[#140](https://github.com/jqhph/dcat-admin/issues/140) -------------------------------------------------------------------------------- /1.x/v1-4-6.md: -------------------------------------------------------------------------------- 1 | # v1.4.6 更新日志 2 | 3 | 这个版本主要是 BUG 修复版本,发布时间 `2020/05/27` 4 | 5 | ## 更新内容 6 | 7 | BUG修复部分 8 | 9 | - 修复`linux`系统下上传超过`5M`大小的文件报错问题 10 | - 修复`Form::block`布局无法正常显示编辑数据问题[#156](https://github.com/jqhph/dcat-admin/issues/156) 11 | - 修复数据表单弹窗重复刷新页面问题 12 | - 修复`Form::selectResource`表单无法设置默认值问题 13 | 14 | 功能优化部分 15 | 16 | - `ContextMenuActions`操作列宽度优化 17 | - 移除已废弃的配置参数以及多余前端组件 18 | -------------------------------------------------------------------------------- /1.x/v1-4-7.md: -------------------------------------------------------------------------------- 1 | 2 | # v1.4.7 更新日志 3 | 4 | 发布时间 `2020/05/29` 5 | 6 | ## 更新内容 7 | 8 | BUG修复部分 9 | 10 | - 修复表格开启了`responsive`功能后点击全选`checkbox`无法取消单个`checkbox`问题 11 | - 修复`markdown`编辑器转义中括号问题 12 | - 修复`Form::date`时间日期表单显示定位异常问题 13 | 14 | 15 | 功能优化部分 16 | 17 | - 使用表格过滤器滑动面板布局时,搜索后只在第一页默认展开滑动面板 18 | - 优化黑色菜单 19 | - 移除单元测试文件夹中的chromedriver 20 | 21 | -------------------------------------------------------------------------------- /1.x/v1-4-8.md: -------------------------------------------------------------------------------- 1 | # v1.4.8 更新日志 2 | 3 | 发布时间 `2020/06/03` 4 | 5 | ## 更新内容 6 | 7 | 8 | **功能优化部分** 9 | 10 | 1.优化权限配置表单 11 | 12 | 这个版本改进了权限配置表单绑定`HTTP路径`的功能,用户可以直接选择类似`auth/roles*`这样格式的路径,这样就能匹配所有以`auth/roles`开头的路由。 13 | 14 | 2.表单关联模型兼容驼峰风格命名 15 | 16 | ```php 17 | protected function form() 18 | { 19 | // 这里关联模型方法的名称是 userProfile 20 | return Form::make(Model::with('userProfile'), function () { 21 | $form->text('username')->rules('required'); 22 | 23 | ... 24 | 25 | // 这里的名称需要改为下划线风格命名 26 | $form->text('user_profile.first_name'); 27 | $form->text('user_profile.last_name'); 28 | 29 | ... 30 | }); 31 | } 32 | 33 | ``` 34 | 35 | 3.增加表格行内编辑功能对一对一关联模型表单的支持 36 | 37 | 用法如下 38 | ```php 39 | $grid->column('profile.address')->editable(); 40 | 41 | $grid->column('profile.status')->select([1 => '状态1', 2 => '状态2']); 42 | 43 | $grid->column('profile.is_new')->switch(); 44 | ``` 45 | 46 | 4.`Action::makeSelector`方法优化 47 | 48 | 49 | 50 | **BUG修复部分** 51 | 52 | - 修复数据表格开启`responsive`之后最后一行无法显示完整下拉菜单问题[#175](https://github.com/jqhph/dcat-admin/issues/175) 53 | - 修复弹窗选择器表单会把空值转化为`0`问题 54 | 55 | -------------------------------------------------------------------------------- /1.x/v1-5-2.md: -------------------------------------------------------------------------------- 1 | 2 | # v1.5.2 更新日志 3 | 4 | 发布时间 `2020/06/21` 5 | 6 | > {tip} 本次版本没有包含不兼容改动,适合所有用户升级。 7 | 8 | 9 | ### 功能优化部分 10 | 11 | #### 1.增加文件表单自动上传功能 12 | 13 | 开启这个功能之后选择完文件会立即自动上传,页面将不再显示`上传`按钮,使用方法如下 14 | 15 | ```php 16 | $form->file('file')->autoUpload(); 17 | 18 | $form->image('img')->autoUpload(); 19 | ``` 20 | 21 | #### 2.优化`JSON`格式表单 22 | 23 | 1.`list`表单,用于保存一维数组的`JSON`格式字符串到数据库 24 | 25 | ```php 26 | $form->list('column_name'); 27 | ``` 28 | 29 | 30 | 31 | 32 | 33 | 2.`keyValue`表单,用于保存键值对数组的`json`格式字符串到数据库 34 | 35 | ```php 36 | $form->keyValue('column_name'); 37 | ``` 38 | 39 | 40 | 41 | 42 | 43 | 更多`JSON`表单组件用法请参考文档[JSON表单](model-json.md)。 44 | 45 | 46 | #### 3.表格增加`addTableClass`方法 47 | 48 | 通过`addTableClass`可以给表格的`table`添加`css`样式 49 | 50 | ```php 51 | $grid->addTableClass(['class1', 'class2']); 52 | ``` 53 | 54 | #### 4.表格过滤器增加`view`方法 55 | 56 | 通过`view`可以自定义表格的过滤器的视图文件,从而更改过滤器布局 57 | 58 | ```php 59 | $grid->filter(function ($filter) { 60 | $filter->view('xxx'); 61 | }); 62 | ``` 63 | 64 | #### 5.表格工具栏样式优化 65 | 66 | 表格工具栏浮动清除 [#239](https://github.com/jqhph/dcat-admin/issues/239) 67 | 68 | 69 | 70 | 71 | #### 6.Text表单自定义图标 72 | 73 | ```php 74 | $form->text('column_name')->prepend('feather icon-edit'); 75 | ``` 76 | 77 | #### 7.样式细节优化 78 | 79 | 优化了表格边框模式、规格筛选器等等样式细节 80 | 81 | 82 | ### BUG修复部分 83 | 84 | 85 | 1. 修复表格存在多个`expand`情况下异步加载功能异常问题 86 | 2. 修复表格`label`无法设置`16`进制颜色值问题 87 | 3. 修复`editor`清空编辑器内容后`required`验证规则无效问题 [#226](https://github.com/jqhph/dcat-admin/issues/226) 88 | 4. 修复多后台不兼容路由缓存的问题 89 | 5. 修复`hasMany`以及`table`表单下无法使用`select`表单联动功能问题 [#237](https://github.com/jqhph/dcat-admin/issues/237) 90 | 6. 修复注册扩展路由不兼容多后台功能问题 [#235](https://github.com/jqhph/dcat-admin/issues/235) 91 | 7. 修复文件上传表单移除页面上验证错误信息异常问题 [#240](https://github.com/jqhph/dcat-admin/issues/240) 92 | -------------------------------------------------------------------------------- /1.x/v1-5-3.md: -------------------------------------------------------------------------------- 1 | 2 | # v1.5.3 更新日志 3 | 4 | 发布时间 `2020/06/28` 5 | 6 | > {tip} 本次版本没有包含不兼容改动,适合所有用户升级。 7 | 8 | 9 | ### 功能优化部分 10 | 11 | #### 1.完善禁用权限系统功能 12 | 13 | 把`admin.auth.enable`配置参数的值设置为`false`可以完全禁用内置的权限系统。 14 | 15 | #### 2.优化深色模式切换按钮手机页面显示 16 | 17 | [#255](https://github.com/jqhph/dcat-admin/issues/255) 18 | 19 | 20 | #### 3.表单row布局间距优化 21 | 22 | 23 | #### 4.增加range表单 24 | 25 | 在这个版本中增加了`range`表单用于设置一个范围值 26 | 27 | ```php 28 | $form->range('start_column', 'end_column', '范围'); 29 | ``` 30 | 31 | #### 5.优化widget table 32 | 33 | 34 | #### 6.优化自定义主题配色功能 35 | 36 | 37 | ### 7.允许`copyable`使用`display`设置的值 38 | [#253](https://github.com/jqhph/dcat-admin/issues/253) 39 | 40 | 41 | ### BUG修复部分 42 | 43 | 1. 修复文件上传表单`disableAutoSave`方法不生效问题 44 | 2. 修复`list`表单`max`和`min`验证规则无效问题 45 | 3. 修复`rate`表单验证规则错误问题 46 | 4. 修复开启自动上传后批量上传多图只会上传两个图片问题 [#262](https://github.com/jqhph/dcat-admin/issues/262) 47 | 5. 修复删除功能模型会与与`cast`产生冲突问题 [#258](https://github.com/jqhph/dcat-admin/issues/258) 48 | 6. 修复`selectResource`选项过多时样式异常问题 49 | 7. 修复`editable`行内编辑可以复制HTML文本内容问题 50 | 8. 修复`hasMany`以及`table`表单无法使用多个`switch`表单问题 51 | -------------------------------------------------------------------------------- /1.x/v1-7-1.md: -------------------------------------------------------------------------------- 1 | 2 | # v1.7.1 更新日志 3 | 4 | 发布时间 `2020/09/02` 5 | 6 | > {tip} 本次版本没有包含不兼容改动,适合所有用户升级。 7 | 8 | ## 升级方法 9 | 10 | ```bash 11 | composer update dcat/laravel-admin 12 | ``` 13 | 14 | 本次版本需要重新发布**静态资源**以及**语言包**,然后按`Ctrl`+`F5`**清除浏览器缓存**! 15 | ```bash 16 | php artisan admin:publish --assets --force 17 | php artisan admin:publish --lang --force 18 | ``` 19 | 20 | ## 功能优化部分 21 | 22 | #### 1. 优化表单默认值设置功能,允许在编辑页使用 23 | 24 | 表单`default`方法默认在编辑页不生效,如果需要在编辑页也设置默认值,则需要把第二个参数设置为`true` 25 | 26 | ```php 27 | $form->text('xxx')->default('默认值', true); 28 | ``` 29 | 30 | #### 2. 表格显示部分功能增加HTML转义功能 31 | 32 | 表格 `copyable`、`limit`、`editable` 等字段显示增加HTML转义功能,防止XSS攻击 33 | 34 | 35 | #### 3. 快捷搜索优化 36 | 37 | 快捷搜索闭包查询会自动包裹在括号内 38 | 39 | #### 4. 单文件上传表单默认值可以设置字符串 40 | 41 | ```php 42 | $form->image('test')->default('xxx/xxx.jpg'); 43 | ``` 44 | 45 | #### 6. select联动load支持 multipleSelect 46 | 47 | 此功能由小伙伴[@youyingxiang](https://github.com/youyingxiang)贡献,[#508](https://github.com/jqhph/dcat-admin/pull/508) 48 | 49 | #### 7. 增加 Form\Field::replaceOptions 方法 50 | 51 | 用于替换默认的`options`属性 52 | 53 | ```php 54 | $form->editor(...)->replaceOptions(['xxx' => 'xxx']); 55 | ``` 56 | 57 | #### 8. 优化`ajax`代码,无需附带`_token`参数 58 | 59 | 从这个版本开始,编写`ajax`提交代码时无需附带`_token`参数 60 | 61 | ```php 62 | Admin::script( 63 | <<html(...)`方法报错问题 80 | 3. 修复表格无数据时导出报错问题 81 | 4. 修复同个页面多个表格情况下快捷搜索冲突问题 82 | 5. 修复弹窗编辑无法弹出颜色选择器问题 [#462](https://github.com/jqhph/dcat-admin/issues/462) 83 | 6. 修复表格选择器无法显示下拉菜单表单问题 [#474](https://github.com/jqhph/dcat-admin/issues/474) 84 | 7. 修复表单弹窗使用分列布局时报`419`错误问题 [482](https://github.com/jqhph/dcat-admin/issues/482) 85 | 8. 修复创建页面使用tab布局时会显示`id`以及`created_at`等`display`类型字段问题 86 | -------------------------------------------------------------------------------- /1.x/v1-7-3.md: -------------------------------------------------------------------------------- 1 | # v1.7.3 更新日志 2 | 3 | 发布时间 `2020/09/09` 4 | 5 | > {tip} 本次版本没有包含不兼容改动,适合所有用户升级。 6 | 7 | 8 | ## 更新内容 9 | 10 | 1. 支持Laravel8.0 11 | 2. 修复 Grid Column Editable 行内编辑字段值为空时不出现保存按钮问题 12 | 3. 修复 selectTable 多选时显示异常问题[#524](https://github.com/jqhph/dcat-admin/issues/524) 13 | 4. 修复工具表单地图表单提交时表单值被忽略问题[#525](https://github.com/jqhph/dcat-admin/issues/525) 14 | 5. 修复工具表单使用分列布局报错问题 15 | 16 | -------------------------------------------------------------------------------- /1.x/v1-7-8.md: -------------------------------------------------------------------------------- 1 | # v1.7.8 更新日志 2 | 3 | 发布时间 `2020/12/22` 4 | 5 | > {tip} 本次版本没有包含不兼容改动,适合所有用户升级。 6 | 7 | 8 | ### 功能改进 9 | 10 | **1.支持php8.0** 11 | 12 | **2.增加表单右上角提示窗展示字段验证错误信息** 13 | 14 | 此功能默认开启,可以通过`validationErrorToastr`方法禁用 15 | 16 | ```php 17 | $form->validationErrorToastr(false); 18 | ``` 19 | 20 | **3.样式细节优化** 21 | 22 | ### BUG修复 23 | 24 | 1. 修复更换图片时有时无法删除图片,报其他表单域必填的错误 [#736](https://github.com/jqhph/dcat-admin/issues/736) 25 | 2. 修复更新数据失败但是依然翻译成更新成功的问题 26 | 3. 修复 selectTable 没有滚动条,数据量多提交按钮无法点击问题 [#477](https://github.com/jqhph/dcat-admin/issues/477) 27 | -------------------------------------------------------------------------------- /1.x/widgets-alert.md: -------------------------------------------------------------------------------- 1 | # 警告框 2 | 3 | ### Alert 4 | 基本用法 5 | 6 | ```php 7 | success(); 15 | $alert->danger(); 16 | $alert->info(); 17 | $alert->warning(); 18 | 19 | // 图标 20 | $alert->icon('feather icon-x'); 21 | 22 | // 可移除按钮 23 | $alert->removable(); 24 | ``` 25 | 效果 26 | 27 | 28 | 29 | 30 | ### Callout 31 | 32 | ```php 33 | light(); 41 | $callout->primary(); 42 | 43 | // 可移除按钮 44 | $callout->removable(); 45 | ``` 46 | 47 | 效果 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /1.x/widgets-box.md: -------------------------------------------------------------------------------- 1 | # 卡片 2 | 3 | ## Card 4 | 5 | ```php 6 | padding('0 15px 0 12px'); 18 | 19 | // 设置工具按钮 20 | $card->tool(''); 21 | 22 | // 设置底部内容 23 | $card->footer(view('...')); 24 | ``` 25 | 26 | ## Box 27 | 28 | ```php 29 | padding('0 15px 0 12px'); 38 | 39 | // 设置工具按钮 40 | $box->tool(''); 41 | 42 | // 设置收缩按钮 43 | $box->collapsable(); 44 | 45 | // 设置移除按钮 46 | $box->removable(); 47 | ``` -------------------------------------------------------------------------------- /1.x/widgets-checkbox.md: -------------------------------------------------------------------------------- 1 | # 单/复选框 2 | 3 | ## 单选框 4 | 5 | 通过 `Dcat\Admin\Widgets\Radio`类可以很方便地快速构建单选框表单。 6 | 7 | ### 基本使用 8 | 9 | ```php 10 | '未处理', 18 | 2 => '已处理', 19 | 3 => '已拒绝', 20 | ]; 21 | 22 | $radio = Radio::make($name, $options)->check(1); // 选中第一个选项 23 | ``` 24 | 25 | 效果 26 | 27 | 28 | 29 | 30 | 31 | ### 显示在同一行 (inline) 32 | 33 | ```php 34 | '未处理', 40 | 2 => '已处理', 41 | 3 => '已拒绝', 42 | ]; 43 | 44 | $radio = Radio::make($name, $options)->check(1)->inline(); 45 | ``` 46 | 效果 47 | 48 | 49 | 50 | 51 | 52 | ### 设置禁选的选项 (disable) 53 | 54 | 55 | ```php 56 | '未处理', 62 | 2 => '已处理', 63 | 3 => '已拒绝', 64 | ]; 65 | 66 | $radio = Radio::make($name, $options)->inline()->disable([2, 3]); 67 | ``` 68 | 效果 69 | 70 | 71 | 72 | 73 | 74 | ### 设置样式 (style) 75 | 76 | 通过`style`方法可以设置单选框的样式,支持`primary`、`info`、`success`、`danger`。 77 | 78 | ### 设置尺寸 79 | 80 | 单选框支持3中尺寸,使用方法如下 81 | 82 | 83 | `small`设置为小尺寸 84 | ```php 85 | $radio->small(); 86 | ``` 87 | 88 | `large`设置为大尺寸 89 | ```php 90 | $radio->large(); 91 | ``` 92 | 93 | 94 | ## 复选框 95 | 96 | 通过 `Dcat\Admin\Widgets\Checkbox`类可以很方便地快速构建复选框表单,并且复选框类是属于`Radio`的子类,因此用法与`Radio`类基本一致。 97 | 98 | ### 基本用法 99 | 100 | ```php 101 | '唱', 109 | 2 => '跳', 110 | 3 => 'RAP', 111 | 4 => '打篮球', 112 | ]; 113 | 114 | $checkbox = Checkbox::make($name, $options) 115 | ->inline() 116 | ->check([1, 2]); // 这里允许传递数组,默认选中多个选项 117 | ``` 118 | 119 | 效果 120 | 121 | 122 | 123 | 124 | 125 | ### 全选 126 | 127 | 通过`checkAll`方法可以选中全部选项。 128 | 129 | ```php 130 | '唱', 138 | 2 => '跳', 139 | 3 => 'RAP', 140 | 4 => '打篮球', 141 | ]; 142 | 143 | $checkbox = Checkbox::make($name, $options) 144 | ->inline() 145 | ->checkAll(); // 全部选中 146 | ``` 147 | 148 | `checkAll`方法也允许全选的同时排除指定选项。 149 | 150 | ```php 151 | $checkbox = Checkbox::make($name, $options) 152 | ->inline() 153 | ->checkAll([1, 3]); // 全部选中,但是排除key为1和3的选项 154 | ``` 155 | 156 | ### 更多用法 157 | 158 | 更多用法与`Radio`的用法一直,这里不再赘述。 159 | 160 | -------------------------------------------------------------------------------- /1.x/widgets-dialog-form.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/1.x/widgets-dialog-form.md -------------------------------------------------------------------------------- /1.x/widgets-js.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/1.x/widgets-js.md -------------------------------------------------------------------------------- /1.x/widgets-markdown.md: -------------------------------------------------------------------------------- 1 | # Markdown 2 | 3 | 基本用法 4 | 5 | ```php 6 | body(Card::make( 17 | Markdown::make('你的markdown本文内容') 18 | )); 19 | } 20 | } 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /1.x/widgets-modal.md: -------------------------------------------------------------------------------- 1 | # 模态窗 (Modal) 2 | 3 | > {tip} Since `v1.7.0` 4 | 5 | 基本使用 6 | 7 | ```php 8 | use Dcat\Admin\Widgets\Modal; 9 | 10 | $modal = Modal::make() 11 | ->lg() 12 | ->title('标题') 13 | ->body(view(...)) 14 | ->button(''); 15 | 16 | return view(..., ['modal' => $modal]); 17 | ``` 18 | 19 | ## 功能 20 | 21 | ### 标题 (title) 22 | 23 | 设置弹窗标题 24 | 25 | ```php 26 | $modal->title('标题'); 27 | ``` 28 | 29 | ### 内容 (body) 30 | 31 | 设置弹窗内容,此方法接受一个参数,允许传入`string`、`Cloure`、`Illuminate\Contracts\Support\Renderable`以及`Dcat\Admin\Contracts\LazyRenderable`类型值 32 | 33 | ```php 34 | // 传入字符串 35 | $modal->body('字符串'); 36 | 37 | // 传入闭包,注意闭包必须返回字符串类型值或空值 38 | $modal->body(function () { 39 | return view(...)->render(); 40 | }); 41 | 42 | // 传入 Renderable 43 | use Dcat\Admin\Widgets\ 44 | 45 | $modal->body(view(...)); 46 | $modal->body(Card::make()); 47 | 48 | // 传入 LazyRenderable 49 | $modal->body(PostTable::make()); 50 | ``` 51 | 52 | ### 底部内容 (footer) 53 | 设置弹窗底部内容,此方法接受一个参数,允许传入`string`、`Cloure`、`Illuminate\Contracts\Support\Renderable`以及`Dcat\Admin\Contracts\LazyRenderable`类型值,用法同上 54 | 55 | ```php 56 | $modal->footer('字符串'); 57 | 58 | $modal->footer(view(...)); 59 | ``` 60 | 61 | ### 尺寸 62 | 63 | 默认 `500px` 64 | 65 | ```php 66 | // 800px 67 | $modal->lg(); 68 | 69 | // 1140px 70 | $modal->xl(); 71 | ``` 72 | 73 | ### 按钮 (button) 74 | 75 | 设置按钮 76 | 77 | ### 事件监听 78 | 79 | 支持事件 80 | 81 | - `onShow` 弹窗显示事件 82 | - `onShown` 弹窗已显示事件 83 | - `onHide` 弹窗隐藏事件 84 | - `onHidden` 弹窗已隐藏事件 85 | 86 | 用法示例 87 | 88 | ```php 89 | use Dcat\Admin\Admin; 90 | 91 | $modal->onShow( 92 | <<onHide( 98 | << 107 | ## 表单弹窗 108 | 109 | 参考文档 [工具表单 - 弹窗](widgets-form.md#modal) 110 | 111 | -------------------------------------------------------------------------------- /1.x/widgets-navbar.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/1.x/widgets-navbar.md -------------------------------------------------------------------------------- /1.x/widgets-tab.md: -------------------------------------------------------------------------------- 1 | # 选项卡 2 | 3 | 通过`Dcat\Admin\Widgets\Tab`方法可以快速构建`tab`选项卡。 4 | 5 | ### 基本用法 6 | 7 | ```php 8 | add('选项卡1', view('...'), true); 16 | $tab->add('选项2', 'html'); 17 | // 添加选项卡链接 18 | $tab->addLink('跳转链接', 'http://xxx'); 19 | 20 | return $content->body($tab->withCard()); 21 | ``` 22 | 23 | ### 切换显示模式 24 | 25 | ```php 26 | // 主题色 27 | $tab = Tab::make()->theme(); 28 | ``` 29 | 30 | ### 垂直 (vertical) 31 | 32 | 通过`vertical`方法可以让选项卡标题栏呈垂直排列。 33 | 34 | ```php 35 | add('选项卡1', view('...')); 42 | $tab->add('选项2', 'html'); 43 | 44 | return $content->body($tab->withCard()->vertical()); 45 | ``` 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /1.x/widgets-table.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/1.x/widgets-table.md -------------------------------------------------------------------------------- /1.x/widgets-tooltip.md: -------------------------------------------------------------------------------- 1 | # 提示窗 2 | 3 | 基本用法 4 | 5 | ```php 6 | title('我是提示信息'); 17 | 18 | return $content->body(new Card( 19 | << 21 | 22 | 23 | HTML 24 | )); 25 | } 26 | } 27 | ``` 28 | 效果 29 | 30 | 31 | -------------------------------------------------------------------------------- /2.x/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jiang Qinghua 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /2.x/README.md: -------------------------------------------------------------------------------- 1 | # dcat-admin 2 | 3 | `Dcat Admin` is a backend builder based on [Laravel-admin](https://github.com/z-song/laravel-admin) that allows you to build a beautiful backend with very little code. 4 | 5 | >`Dcat Admin` is based on [Laravel-admin](https://github.com/z-song/laravel-admin) and has been rewritten with a lot of useful features and interfaces to help you build a beautiful and functional backend in a simple and comfortable way 6 | 7 | 8 | ## Features 9 | 10 | + `model-grid` support for fast data table construction 11 | + `model-form` support for rapid data form building 12 | + `model-tree` support for fast tree construction 13 | + Built-in permission system 14 | + Nearly 100 built-in page components, including 40+ form element components, and support for extension components 15 | + Multiple model relationships for `Laravel` support 16 | + Multi-database support for `mysql`, `mongodb`, `pgsql`, etc. 17 | + Support for the introduction of third-party front-end libraries 18 | + web implementation of database and artisan command-line tools 19 | + Support for custom charts 20 | + multiple common web components 21 | + Support for local and oss file uploads 22 | 23 | ## Demo 24 | 25 | Open [demo](),and login with `admin/admin`. 26 | 27 | ## Requirements 28 | + PHP >= 7.1 29 | + Laravel >= 5.5.0 30 | + Fileinfo PHP Extension 31 | 32 | ## Installation 33 | ```sh 34 | composer require dcat/admin 35 | ``` 36 | 37 | 38 | # Dependencies 39 | 40 | `dcat-admin` is based on the following components or services: 41 | 42 | + [Laravel](https://laravel.com/) 43 | + [AdminLTE](https://almsaeedstudio.com/) 44 | + [Datetimepicker](http://eonasdan.github.io/bootstrap-datetimepicker/) 45 | + [font-awesome](http://fontawesome.io) 46 | + [moment](http://momentjs.com/) 47 | + [Google map](https://www.google.com/maps) 48 | + [Tencent map](http://lbs.qq.com/) 49 | + [bootstrap-fileinput](https://github.com/kartik-v/bootstrap-fileinput) 50 | + [jquery-pjax](https://github.com/defunkt/jquery-pjax) 51 | + [Nestable](http://dbushell.github.io/Nestable/) 52 | + [toastr](http://codeseven.github.io/toastr/) 53 | + [X-editable](http://github.com/vitalets/x-editable) 54 | + [bootstrap-number-input](https://github.com/wpic/bootstrap-number-input) 55 | + [fontawesome-iconpicker](https://github.com/itsjavi/fontawesome-iconpicker) 56 | 57 | ## Thanks 58 | + [Laravel-admin](https://github.com/z-song/laravel-admin) 59 | 60 | ## Contact 61 | 62 | QQ Group: 63 | 64 | 65 | ## License 66 | 67 | `dcat-admin` is licensed under [The MIT License (MIT)](en/LICENSE). 68 | -------------------------------------------------------------------------------- /2.x/action-form.md: -------------------------------------------------------------------------------- 1 | # 数据表单动作 2 | 3 | 运行命令 4 | 5 | ```bash 6 | php artisan admin:action 7 | ``` 8 | 9 | 然后输入 `4` 10 | 11 | ```bash 12 | Which type of action would you like to make?: 13 | [0] default 14 | [1] grid-batch 15 | [2] grid-row 16 | [3] grid-tool 17 | [4] form-tool 18 | [5] show-tool 19 | [6] tree-tool 20 | > 4 # 输入 4 21 | 22 | ``` 23 | 24 | 接着输入 `Action` 类名称,这里需要输入 `大驼峰` 风格的英文字母 25 | 26 | ```bash 27 | 28 | Please enter a name of action class: 29 | > Copy 30 | 31 | ``` 32 | 33 | 类名输入完成之后会出现以下信息让开发者输入类的命名空间,默认的命名空间是 `App\Admin\Actions\Form`,这里使用默认的就行 34 | 35 | ```bash 36 | 37 | Please enter the namespace of action class [App\Admin\Actions\Form]: 38 | > 39 | 40 | ``` 41 | 42 | 最后生成文件如下 43 | 44 | ```php 45 | getKey(); 76 | 77 | return $this->response() 78 | ->success('Processed successfully.') 79 | ->redirect('/'); 80 | } 81 | 82 | /** 83 | * 如果只是a标签跳转,则在这里返回跳转链接即可 84 | * 85 | * @return string|void 86 | */ 87 | protected function href() 88 | { 89 | // 获取主键 90 | $key = $this->getKey(); 91 | 92 | // 获取当前页其他字段 93 | $username = $this->parent->model()->username; 94 | 95 | // return admin_url('auth/users'); 96 | } 97 | 98 | // 如果你想自定义动作按钮的HTML,可以重写此方法 99 | public function html() 100 | { 101 | return parent::html(); 102 | } 103 | 104 | /** 105 | * 确认弹窗信息,如不需要可以删除此方法 106 | * 107 | * @return string|array|void 108 | */ 109 | public function confirm() 110 | { 111 | // return ['Confirm?', 'contents']; 112 | } 113 | 114 | /** 115 | * 权限判断,如不需要可以删除此方法 116 | * 117 | * @param Model|Authenticatable|HasPermissions|null $user 118 | * 119 | * @return bool 120 | */ 121 | protected function authorize($user): bool 122 | { 123 | return true; 124 | } 125 | 126 | /** 127 | * 返回请求接口的参数,如不需要可以删除此方法 128 | * 129 | * @return array 130 | */ 131 | protected function parameters() 132 | { 133 | return []; 134 | } 135 | } 136 | 137 | ``` 138 | 139 | 使用 140 | 141 | ```php 142 | $form->tools(function (Form\Tools $tools) { 143 | $tools->append(new Copy()); 144 | }); 145 | ``` 146 | -------------------------------------------------------------------------------- /2.x/action-show.md: -------------------------------------------------------------------------------- 1 | # 数据详情动作 2 | 3 | 运行命令 4 | 5 | ```bash 6 | php artisan admin:action 7 | ``` 8 | 9 | 然后输入 `5` 10 | 11 | ```bash 12 | Which type of action would you like to make?: 13 | [0] default 14 | [1] grid-batch 15 | [2] grid-row 16 | [3] grid-tool 17 | [4] form-tool 18 | [5] show-tool 19 | [6] tree-tool 20 | > 5 # 输入 5 21 | 22 | ``` 23 | 24 | 接着输入 `Action` 类名称,这里需要输入 `大驼峰` 风格的英文字母 25 | 26 | ```bash 27 | 28 | Please enter a name of action class: 29 | > Copy 30 | 31 | ``` 32 | 33 | 类名输入完成之后会出现以下信息让开发者输入类的命名空间,默认的命名空间是 `App\Admin\Actions\Show`,这里使用默认的就行 34 | 35 | ```bash 36 | 37 | Please enter the namespace of action class [App\Admin\Actions\Show]: 38 | > 39 | 40 | ``` 41 | 42 | 最后生成文件如下 43 | 44 | ```php 45 | getKey(); 76 | 77 | return $this->response() 78 | ->success('Processed successfully.') 79 | ->redirect('/'); 80 | } 81 | 82 | /** 83 | * 如果只是a标签跳转,则在这里返回跳转链接即可 84 | * 85 | * @return string|void 86 | */ 87 | protected function href() 88 | { 89 | // 获取主键 90 | $key = $this->getKey(); 91 | 92 | // 获取当前页其他字段 93 | $username = $this->parent->model()->username; 94 | 95 | // return admin_url('auth/users'); 96 | } 97 | 98 | // 如果你想自定义动作按钮的HTML,可以重写此方法 99 | public function html() 100 | { 101 | return parent::html(); 102 | } 103 | 104 | /** 105 | * 确认弹窗信息,如不需要可以删除此方法 106 | * 107 | * @return string|array|void 108 | */ 109 | public function confirm() 110 | { 111 | // return ['Confirm?', 'contents']; 112 | } 113 | 114 | /** 115 | * 权限判断,如不需要可以删除此方法 116 | * 117 | * @param Model|Authenticatable|HasPermissions|null $user 118 | * 119 | * @return bool 120 | */ 121 | protected function authorize($user): bool 122 | { 123 | return true; 124 | } 125 | 126 | /** 127 | * 返回请求接口的参数,如不需要可以删除此方法 128 | * 129 | * @return array 130 | */ 131 | protected function parameters() 132 | { 133 | return []; 134 | } 135 | } 136 | 137 | ``` 138 | 139 | 使用 140 | 141 | ```php 142 | $show->tools(function (Show\Tools $tools) { 143 | $tools->append(new Copy()); 144 | }); 145 | ``` 146 | -------------------------------------------------------------------------------- /2.x/change-log.md: -------------------------------------------------------------------------------- 1 | 2 | 当前最新版本 [v2.0.0-beta](v2-0-0-beta.md) 3 | 4 | -------------------------------------------------------------------------------- /2.x/custom-chart.md: -------------------------------------------------------------------------------- 1 | # 自定义图表 2 | 3 | `dcat-admin 1.5`已经移除了所有的图表组件,如果要在页面中加入图表组件,可以参考下面的流程 4 | 5 | 用`chartjs`举例,首先要下载[chartjs](http://chartjs.org/),放到public目录下面,比如放在`public/vendor/chartjs`目录 6 | 7 | 然后在`app/Admin/bootstrap.php`引入组件: 8 | ```php 9 | use Dcat\Admin\Facades\Admin; 10 | 11 | Admin::js('/vendor/chartjs/dist/Chart.min.js'); 12 | 13 | ``` 14 | 15 | 新建视图文件 `resources/views/admin/charts/bar.blade.php` 16 | 17 | ```php 18 | 19 | 61 | ``` 62 | 63 | 然后就可以在页面的任何地方引入这个图表视图了: 64 | 65 | ```php 66 | public function index() 67 | { 68 | return Admin::content(function (Content $content) { 69 | 70 | $content->header('chart'); 71 | $content->description('.....'); 72 | 73 | $content->body(view('admin.charts.bar')); 74 | }); 75 | } 76 | 77 | ``` 78 | 79 | 按照上面的方式可以引入任意图表库,多图表页面的布局,参考[视图布局](layout.md) -------------------------------------------------------------------------------- /2.x/custom-page.md: -------------------------------------------------------------------------------- 1 | # 视图与自定义页面 2 | 3 | ## 视图 4 | 5 | 6 | 在`Dcat Admin`中我们可以用`admin_view`函数渲染视图,这个功能借鉴了`vue`的设计思想,可以把`HTML`、`CSS`和`JS`代码写在同一个模板文件中,让代码分层更清晰更简洁易读,如 7 | 8 | ```html 9 |
...
10 | 11 | 16 | 17 | 20 | ``` 21 | 22 | 在`php`中渲染这个视图 23 | ```php 24 | public function index(Content $content) 25 | { 26 | return $content->body(admin_view('...')); 27 | } 28 | ``` 29 | 30 | #### 示例解析 31 | 32 | 上面示例中的代码,其实相当于下面的代码 33 | 34 | ```html 35 |
...
36 | ``` 37 | 38 | ```php 39 | public function index(Content $content) 40 | { 41 | admin_require_assets(['@test1', '@test2']); 42 | 43 | admin_style('.my-class { 44 | color: blue; 45 | }'); 46 | 47 | admin_script( 48 | <<body(view('...')); 56 | } 57 | ``` 58 | 59 | 很显然,使用`admin_view`渲染视图会让你的代码更简洁易读,关于`Dcat.init`以及`script`标签中的`init`和`require`属性的用法,请参考文档[静态资源](assets.md)以及[动态监听元素生成 (init)](js.md#init)章节。 60 | 61 | ## 自定义页面 62 | 63 | 在`Dcat Admin`中构建自定义页面非常简单,可以参考如下两个例子 64 | 65 | 66 | ### 示例1 67 | 68 | > {tip} `Dcat Admin`构建的是一个单页应用,加载的`JS`脚本只会执行一次,所以初始化操作不能直接放在`JS`脚本中,应该使用`Admin::script`方法载入。 69 | 70 | ```php 71 | `和``等标签 87 | ```html 88 |
89 |

自定义页面演示

90 |
91 | 92 | 96 | {!! admin_js(['xxx/js/page.min.js']) !!} 97 | {!! admin_css(['xxx/js/page.min.css']) !!} 98 | 99 | 107 | ``` 108 | 109 | 使用 110 | 111 | ```php 112 | public function index(Content $content) 113 | { 114 | return $content->body(new MyPage()); 115 | } 116 | ``` 117 | 118 | 119 | ### 示例2 120 | 121 | 后台的仪表盘页面`/admin`,也可以看做是一个自定义页面,代码实现如下 122 | ```php 123 | public function index(Content $content) 124 | { 125 | return $content 126 | ->header('Dashboard') 127 | ->description('Description...') 128 | ->body(function (Row $row) { 129 | $row->column(6, function (Column $column) { 130 | $column->row(Dashboard::title()); 131 | $column->row(new Examples\Tickets()); 132 | }); 133 | 134 | $row->column(6, function (Column $column) { 135 | $column->row(function (Row $row) { 136 | $row->column(6, new Examples\NewUsers()); 137 | $row->column(6, new Examples\NewDevices()); 138 | }); 139 | 140 | $column->row(new Examples\Sessions()); 141 | $column->row(new Examples\ProductOrders()); 142 | }); 143 | }); 144 | } 145 | ``` 146 | 147 | -------------------------------------------------------------------------------- /2.x/documentation.md: -------------------------------------------------------------------------------- 1 | 2 | - ## 入门 3 | - [简介](introduction.md) 4 | - [安装](installation.md) 5 | - [v1.x升级指南](1-x-upgrade.md) 6 | - [版本升级](update.md) 7 | - [快速开始](quick-start.md) 8 | - [开发前必读](notice.md) 9 | - [静态资源](assets.md) 10 | - [主题与颜色](theme.md) 11 | - [视图与自定义页面](custom-page.md) 12 | - [JS组件](js.md) 13 | - [多应用 (多后台)](multi-app.md) 14 | - [Laravel Octane](laravel-octane.md) 15 | - [常见问题](qa.md) 16 | - ## 数据表格 17 | - [基本使用](model-grid.md) 18 | - [列的使用和扩展](model-grid-column.md) 19 | - [列的显示和扩展](model-grid-column-display.md) 20 | - [行的使用和扩展](model-grid-actions.md) 21 | - [工具栏](model-grid-custom-tools.md) 22 | - [树状表格](model-grid-tree.md) 23 | - [组合表头](model-grid-combination.md) 24 | - [数据源](model-grid-data.md) 25 | - [关联关系](model-grid-relationship.md) 26 | - [查询过滤](model-grid-filters.md) 27 | - [列过滤器](model-grid-column-filter.md) 28 | - [快捷搜索](model-grid-quick-search.md) 29 | - [规格筛选器](model-grid-selector.md) 30 | - [数据导出](model-grid-export.md) 31 | - [快捷创建](model-grid-quick-create.md) 32 | - [行内编辑](model-grid-editable.md) 33 | - [事件](model-grid-events.md) 34 | - [字段翻译](model-grid-trans.md) 35 | - [头部和脚部](model-grid-header.md) 36 | - [软删除](model-grid-softdelete.md) 37 | - [异步渲染](model-grid-softdelete.md) 38 | - ## 数据表单 39 | - [基本使用](model-form.md) 40 | - [图片/文件上传](model-form-upload.md) 41 | - [字段使用](model-form-fields.md) 42 | - [字段扩展](model-form-field-management.md) 43 | - [数据源](model-form-data.md) 44 | - [表单弹窗](model-form-modal.md) 45 | - [关联关系](model-relationship.md) 46 | - [JSON表单](model-json.md) 47 | - [字段动态显示](model-form-when.md) 48 | - [表单分步](model-form-step.md) 49 | - [表单验证](model-form-validation.md) 50 | - [事件](model-form-callback.md) 51 | - [表单初始化](model-form-init.md) 52 | - [工具表单](widgets-form.md) 53 | - [表单布局](model-form-layout.md) 54 | - [表单字段翻译](model-form-trans.md) 55 | - ## 数据详情 56 | - [基本使用](model-show.md) 57 | - [字段显示](model-show-field.md) 58 | - [关联关系](model-show-relation.md) 59 | - [显示扩展](model-show-extend.md) 60 | - [初始化](model-show-init.md) 61 | - [字段翻译](model-show-trans.md) 62 | - ## [模型树](model-tree.md) 63 | - ## [数据仓库](model-repository.md) 64 | - ## 动作 65 | - [基本使用](action.md) 66 | - [数据表格](action-grid.md) 67 | - [数据表单](action-form.md) 68 | - [数据详情](action-show.md) 69 | - [模型树](action-tree.md) 70 | - ## [多语言](trans.md) 71 | - ## 扩展 72 | - [扩展基本使用](extension-f.md) 73 | - [开发扩展](extension-dev.md) 74 | - [开发主题](extension-theme.md) 75 | - ## 页面组件 76 | - [异步加载](lazy.md) 77 | - [图表](widgets-charts.md) 78 | - [数据统计卡片](widgets-data-card.md) 79 | - [工具表单](widgets-form.md) 80 | - [模态窗(Modal)](widgets-modal.md) 81 | - [下拉菜单](widgets-dropdown.md) 82 | - [单/复选框](widgets-checkbox.md) 83 | - [选项卡](widgets-tab.md) 84 | - [告警框](widgets-alert.md) 85 | - [提示窗(tooltip)](widgets-tooltip.md) 86 | - [Markdown](widgets-markdown.md) 87 | - [卡片](widgets-box.md) 88 | - ## [区块(section)](section.md) 89 | - ## [动作以及表单响应](response.md) 90 | - ## [权限控制](permission.md) 91 | - ## [菜单](menu.md) 92 | - ## [帮助函数](function.md) 93 | - ## [开发工具](helpers.md) 94 | - ## [自定义登陆认证](custom-authentication.md) 95 | - ## [自定义头部导航](custom-navbar.md) 96 | - ## 更新日志 97 | - [BETA版本更新日志](beta-change-log.md) -------------------------------------------------------------------------------- /2.x/extension-helpers.md: -------------------------------------------------------------------------------- 1 | # 开发工具 2 | 3 | 在最新的版本中新增了面向开发人员的帮助工具,能在开发中提供帮助提高效率,目前提供`脚手架`,`数据库命令行`和`artisan命令行`三个工具,如果有更好的其它实用工具的想法,欢迎提供建议。 4 | 5 | 安装: 6 | ```php 7 | composer require dcat-admin-ext/helpers 8 | 9 | php artisan admin:import helpers 10 | ``` 11 | 12 | > {tip} 工具的部分功能会在项目中创建或删除文件,可能会出现文件或目录权限的问题,这个问题需要自行解决。 13 | 另外部分数据库和artisan命令无法在web环境下使用。 14 | 15 | ## 脚手架工具 16 | 17 | 脚手架工具能帮你一键生成控制器、模型、迁移文件,并运行迁移文件,访问`http://localhost/admin/helpers/scaffold`打开。 18 | 19 | 其中设置迁移表结构的时候,主键字段是自动生成的不需要填写。 20 | 21 | ![qq20170220-2](https://cloud.githubusercontent.com/assets/1479100/23147949/cbf03e84-f81d-11e6-82b7-d7929c3033a0.png) 22 | 23 | ## 数据库命令行 24 | 25 | 数据库命令行工具的web集成,目前支持`mysql`、`mongodb` 和 `redis`,访问`http://localhost/admin/helpers/terminal/database`打开。 26 | 27 | 在右上角的`select`选择框切换数据库连接,然后在底部的输入框输入对应数据库的查询语句然后回车,就能得到查询结果: 28 | 29 | ![qq20170220-3](https://cloud.githubusercontent.com/assets/1479100/23147951/ce08e5d6-f81d-11e6-8b20-605e8cd06167.png) 30 | 31 | 实用方式和终端上操作数据库是一致的,可以运行所选择数据库的所支持的查询语句。 32 | 33 | ## artisan命令行工具 34 | 35 | `Laravel`的`artisan`命令的web实现,可以在上面运行artisan命令,访问`http://localhost/admin/helpers/terminal/artisan`打开。 36 | 37 | ![qq20170220-1](https://cloud.githubusercontent.com/assets/1479100/23147963/da8a5d30-f81d-11e6-97b9-239eea900ad3.png) 38 | 39 | ## 路由列表 40 | 41 | 这个工具能用用比较直观的展现出系统的所有路由,包括路由的uri、方法和中间件等,还能查询路由。访问`http://localhost/admin/helpers/routes`打开。 42 | 43 | ![helpers_routes](https://user-images.githubusercontent.com/1479100/30899066-e8bdd5ca-a390-11e7-809d-4ceccd0da27f.png) 44 | -------------------------------------------------------------------------------- /2.x/extension-theme.md: -------------------------------------------------------------------------------- 1 | # 主题开发 2 | 3 | -------------------------------------------------------------------------------- /2.x/extension-upgrade.md: -------------------------------------------------------------------------------- 1 | # 扩展版本与升级 -------------------------------------------------------------------------------- /2.x/extensions.md: -------------------------------------------------------------------------------- 1 | # 扩展 2 | 3 | | 扩展 | 描述 | dcat-admin 版本 | 4 | | ------------------------------------------------ | ---------------------------------------- |---------------------------------------- | 5 | | [dcat-page](https://github.com/jqhph/dcat-page) | 一个简洁的静态站点构建工具 | * | 6 | | [ueditor](https://github.com/jqhph/dcat-admin-ueditor) | 百度在线编辑器 | * | 7 | | [gank](https://github.com/jqhph/dcat-admin-gank) | 干货集中营 |* | 8 | 9 | 10 | -------------------------------------------------------------------------------- /2.x/helpers.md: -------------------------------------------------------------------------------- 1 | # 开发工具 2 | 3 | `Dcat Admin`提供了一些开发工具以帮助开发者提升开发效率。 4 | 如果需要禁用开发工具,则把配置文件中的`app.debug`或`admin.helpers.enable`的参数值设置为`false`即可。 5 | 6 | 7 | ### 代码生成器 8 | 9 | 代码生成器可以通过界面一键生成增删改查代码,支持根据已有数据表生成增删改查代码,打开浏览器访问`http://localhost:8000/admin/helpers/scaffold`即可使用。 10 | 11 | > {tip} 如果你的开发环境不是`windows`系统,请给整个项目`777`权限,否则可能无法生成文件。 12 | 13 | 14 | ### 扩展包管理 15 | `Dcat Admin`支持可视化管理扩展包,只要通过`composer`安装进来的扩展包都能在管理界面中看到,支持通过界面启用和导入扩展包,打开浏览器访问`http://localhost:8000/admin/helpers/extensions`即可使用。 16 | 17 | ### IDE自动补全 18 | 通过`php artisan admin:ide-helper`命令可以生成IDE自动补全文件,可以生成`Grid`、`Form`、`Show`等功能的IDE自动补全提示文件。 19 | 20 | ### 图标 21 | 访问`http://localhost:8000/admin/helpers/icons`可以查看已支持的图标列表。 22 | 23 | -------------------------------------------------------------------------------- /2.x/installation.md: -------------------------------------------------------------------------------- 1 | # 安装 2 | 3 | 4 | ## 环境 5 | + PHP >= `7.1` 6 | + Laravel `5.5.0` ~ `9.*` 7 | + Fileinfo PHP Extension 8 | 9 | 10 | ## 开始安装 11 | 12 | > {tip} 如果安装过程中出现`composer`下载过慢或安装失败的情况,请运行命令`composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/`把`composer`镜像更换为阿里云镜像。 13 | 14 | 首先需要安装`laravel`,如已安装可以跳过此步骤 15 | ```bash 16 | composer create-project --prefer-dist laravel/laravel 项目名称 7.* 17 | # 或 18 | composer create-project --prefer-dist laravel/laravel 项目名称 19 | ``` 20 | 21 | 安装完`laravel`之后需要修改`.env`文件,设置数据库连接设置正确 22 | 23 | ```dotenv 24 | DB_CONNECTION=mysql 25 | DB_HOST=127.0.0.1 26 | DB_PORT=3306 27 | DB_DATABASE=dcat-admin 28 | DB_USERNAME=root 29 | DB_PASSWORD= 30 | ``` 31 | 32 | 安装`dcat-admin` 33 | 34 | 35 | ``` 36 | cd {项目名称} 37 | 38 | composer require dcat/laravel-admin:"2.*" -vvv 39 | ``` 40 | 41 | 然后运行下面的命令来发布资源: 42 | 43 | ``` 44 | php artisan admin:publish 45 | ``` 46 | 47 | 在该命令会生成配置文件`config/admin.php`,可以在里面修改安装的地址、数据库连接、以及表名,建议都是用默认配置不修改。 48 | 49 | 然后运行下面的命令完成安装: 50 | 51 | > {tip} 执行这一步命令可能会报以下错误`Specified key was too long ... 767 bytes`,如果出现这个报错,请在`app/Providers/AppServiceProvider.php`文件的`boot`方法中加上代码`\Schema::defaultStringLength(191);`,然后删除掉数据库中的所有数据表,再重新运行一遍`php artisan admin:install`命令即可。 52 | 53 | ``` 54 | php artisan admin:install 55 | ``` 56 | 57 | 上述步骤操作完成之后就可以配置`web`服务了,**注意需要把`web`目录指向`public`目录**!如果用的是`nginx`,还需要在配置中加上伪静态配置 58 | ```dotenv 59 | location / { 60 | try_files $uri $uri/ /index.php?$query_string; 61 | } 62 | ``` 63 | 64 | 启动服务后,在浏览器打开 `http://localhost/admin`,使用用户名 `admin` 和密码 `admin`登陆。 65 | 66 | 67 | 68 | ## 生成的文件 69 | 70 | 安装完成之后,会在项目目录中生成以下的文件: 71 | 72 | 73 | ### 配置文件 74 | 75 | 安装完成之后,`dcat-admin`所有的配置都在`config/admin.php`文件中。 76 | 77 | 78 | ### 后台项目文件 79 | 安装完成之后,后台的安装目录为`app/Admin`,之后大部分的后台开发编码工作都是在这个目录下进行。 80 | 81 | ``` 82 | app/Admin 83 | ├── Controllers 84 | │   ├── AuthController.php 85 | │   └── HomeController.php 86 | ├── Metrics 87 | │   └── Examples 88 | │   ├── NewDevices.php 89 | │   ├── NewUsers.php 90 | │   ├── ProductOrders.php 91 | │   ├── Sessions.php 92 | │   ├── Tickets.php 93 | │   └── TotalUsers.php 94 | ├── bootstrap.php 95 | └── routes.php 96 | ``` 97 | 98 | 1. `app/Admin/routes.php`文件用来配置后台路由。 99 | 2. `app/Admin/bootstrap.php` 是`dcat-admin`的启动文件, 使用方法请参考文件里面的注释. 100 | 3. `app/Admin/Controllers`目录用来存放后台控制器文件,该目录下的`HomeController.php`文件是后台首页的显示控制器,`AuthController.php`为后台管理员登录鉴权控制器。 101 | 4. `app/Admin/Metrics/Examples`里面存放的是`数据统计卡片(Metric Card)`的示例代码. 102 | 103 | 104 | ### 静态文件 105 | 106 | 后台所需的前端静态文件在`/public/vendor/dcat-admin`目录下。 107 | 108 | 109 | ### 数据表迁移文件 110 | 对应的数据表迁移文件在`/database/migrations`目录下。 111 | 112 | 113 | ### 语言包 114 | 语言包文件在`/resources/lang`目录下。 115 | 116 | -------------------------------------------------------------------------------- /2.x/introduction.md: -------------------------------------------------------------------------------- 1 | # Dcat Admin 2 | 3 | 4 | `Dcat Admin`是一个基于[laravel-admin](https://www.laravel-admin.org/)二次开发而成的后台系统构建工具,只需极少的代码即可快速构建出一个功能完善的高颜值后台系统。支持页面一键生成CURD代码,内置丰富的后台常用组件,开箱即用,让开发者告别冗杂的HTML代码,对后端开发者非常友好。 5 | 6 |

7 | 8 | 9 | Build Status 10 | 11 | 12 | 13 | 14 | 15 |

16 | 17 | ### 技术栈 18 | 19 | - [Laravel](https://laravel.com/) 20 | - [AdminLTE3](https://github.com/ColorlibHQ/AdminLTE) 21 | - [Bootstrap4](https://getbootstrap.net/) 22 | - jQuery3 23 | 24 | 25 | ### 特性 26 | 27 | - 简洁优雅、灵活可扩展的API 28 | - 用户管理 29 | - RBAC权限管理,支持无限级权限节点 30 | - 菜单管理 31 | - 使用pjax构建无刷新页面,支持**按需加载**静态资源,可以无限扩展组件而不影响整体性能 32 | - 松耦合的页面构建与数据操作设计,可轻松切换数据源 33 | - 自定义页面 34 | - 自定义主题配色 35 | - 多主题切换功能,内置多种主题色 36 | - 可轻松构建无菜单栏的独立页面(如可用于构建弹窗选择器等功能) 37 | - 插件功能 38 | - 可视化代码生成器,可根据数据表一键生成增删改查页面 39 | - 数据表格构建工具,内置丰富的表格常用功能(如组合表头、数据导出、搜索、快捷创建、批量操作等) 40 | - 树状表格功能构建工具,支持分页和点击加载 41 | - 数据表单构建工具,内置丰富的表单类型,支持表单异步提交 42 | - 分步表单构建工具 43 | - 弹窗表单构建工具 44 | - 数据详情页构建工具 45 | - 无限层级树状页面构建工具,支持用拖拽的方式实现数据的层级、排序等操作 46 | - 内置丰富的常用页面组件(如图表、数据统计卡片、下拉菜单、Tab卡片、提示工具等) 47 | - `Section`功能(类似`Wordpress`的`Filter`和`blade`模板的`section`标签) 48 | - 异步文件上传表单,支持分块多线程上传 49 | - 多应用(多后台) 50 | - 插件市场,只需在管理页面轻轻点击鼠标即可完成插件的安装、更新和卸载等操作(`暂未实现`) 51 | 52 | 53 | 54 | ### 交流 55 | 56 | **QQ群** 704661955 57 | 58 | **扩展开发者QQ群** 679738409 59 | 60 | ### 加入我们 61 | 62 | 如果您对这个项目感兴趣,非常欢迎加入项目开发团队,参与这个项目的功能维护与开发。欢迎任何形式的贡献(包括但不限于以下): 63 | 64 | * 贡献代码 65 | * 完善文档 66 | * 撰写教程 67 | * 完善注释 68 | * ... 69 | -------------------------------------------------------------------------------- /2.x/laravel-octane.md: -------------------------------------------------------------------------------- 1 | # Laravel Octane 2 | 3 | [Laravel Octane](https://github.com/laravel/octane) 是一个基于 `Swoole/RoadRunner` 驱动的可以提升 `Laravel` 框架性能的项目,安装后可以大幅提升`Laravel`项目的性能。 4 | 5 | `Dcat Admin`兼容了`Laravel Octane`环境,只需在配置文件`config/octane.php`中加入如下配置即可: 6 | 7 | ```php 8 | 9 | 'listeners' => [ 10 | ..., 11 | 12 | RequestReceived::class => [ 13 | ...Octane::prepareApplicationForNextOperation(), 14 | ...Octane::prepareApplicationForNextRequest(), 15 | 16 | // 开启对 Dcat Admin 的支持 17 | Dcat\Admin\Octane\Listeners\FlushAdminState::class, 18 | ], 19 | 20 | ... 21 | ], 22 | ``` 23 | 24 | > [Laravel Octane](https://github.com/laravel/octane)目前仍处于`beta`版本阶段,关于[Laravel Octane](https://github.com/laravel/octane)的安装与更多介绍请前往文档 https://github.com/laravel/octane 查看。 25 | 26 | -------------------------------------------------------------------------------- /2.x/menu.md: -------------------------------------------------------------------------------- 1 | # 菜单 2 | 3 | `Dcat Admin`的菜单是保存在数据表`admin_menu`上的,开发者可以在后台菜单管理页面对菜单进行管理。 4 | 5 | ### 菜单权限 6 | 每个菜单都可以与权限或角色进行绑定,如果不设置则为公共菜单,所有账号都能看到。 7 | 8 | 通过`admin.menu.bind_permission`配置参数可以设置是否允许绑定权限。 9 | > {tip} 默认一个菜单最多能绑定一个权限和一个角色。 10 | 11 | ### 菜单翻译 12 | 在您的语言文件的menu_titles索引中追加菜单标题。 例如“工作单位”标题: 13 | 14 | 在`resources/lang/{当前语言}/admin.php`中 15 | ```php 16 | ... 17 | 'menu_titles' => [ 18 | 'work_units' => 'Unidades de trabajo' 19 | ], 20 | ``` 21 | 22 | ### 菜单缓存 23 | 通过`admin.menu.cache.enable`配置参数可以开启或关闭菜单缓存,建议开启。 24 | 25 | ### 通过Menu::add接口动态添加菜单 26 | `Dcat Admin`还提供了通过数组的方式在代码中即时添加菜单。 27 | 28 | 在`app\Admin\bootstrap.php`中添加如下代码: 29 | ```php 30 | add([ 36 | [ 37 | 'id' => '1', // 此id只要保证当前的数组中是唯一的即可 38 | 'title' => '测试菜单', 39 | 'icon' => 'fa-file-text-o', 40 | 'uri' => '', 41 | 'parent_id' => 0, 42 | 'permission_id' => 'test', // 与权限绑定 43 | 'roles' => 'test-roles', // 与角色绑定 44 | ], 45 | [ 46 | 'id' => '2', // 此id只要保证当前的数组中是唯一的即可 47 | 'title' => '测试菜单2', 48 | 'icon' => 'fa-file-text-o', 49 | 'uri' => 'test-menu2', 50 | 'parent_id' => '1', 51 | ], 52 | ]); 53 | }); 54 | 55 | ``` 56 | 57 | ### 为何没有权限的菜单不会自动隐藏? 58 | 59 | 这个问题是因为你没有给菜单绑定权限或者角色,给你想要无权不显示的菜单绑定权限或者角色即可。 60 | 61 | 62 | -------------------------------------------------------------------------------- /2.x/model-form-data.md: -------------------------------------------------------------------------------- 1 | # 表单数据源 2 | 3 | ## 模型与数据仓库 4 | 5 | 6 | 数据仓库(`Repository`)是一个可以提供特定接口对数据进行读写操作的类,通过数据仓库的引入,可以让页面的构建不再关心数据读写功能的具体实现,开发者只需要实现特定的操作接口即可轻松切换数据源。关于数据仓库的详细用法请参考文档[数据仓库](model-repository.md)。 7 | 8 | 9 | ## 数据来自模型 10 | 11 | > {tip} 如果你的数据来自`Model`,那么你也可以直接使用`Model`实例,底层会自动把`Model`转化为数据仓库实例。 12 | 13 | 14 | 15 | 当数据源支持模型时,只需创建一个非常简单的`Repository`类既可: 16 | 17 | 18 | ```php 19 | getKeyName(), 'name', 'title', 'created_at']; 35 | } 36 | } 37 | ``` 38 | 使用: 39 | ```php 40 | use App\Admin\Repositories\Movie; 41 | 42 | $form = new Form(new Movie); 43 | 44 | ... 45 | ``` 46 | 47 | ## 数据来自外部API 48 | 49 | 下面以`豆瓣电影`的API为例子,来展示`Repository`的表单数据读写操作相关接口的用法: 50 | 51 | ```php 52 | builder()->getResourceId(); 71 | 72 | $data = file_get_contents("http://api.douban.com/v2/movie/subject/$id"); 73 | 74 | return json_decode($data, true); 75 | } 76 | 77 | // 这个方法用于在修改数据前查询原记录 78 | // 如果使用了文件上传表单,当文件发生变更时会根据这个原始记录自动删除旧文件 79 | // 如果不需要此数据返回空数组即可 80 | public function updating(Form $form) 81 | { 82 | // 获取id 83 | $id = $form->builder()->getResourceId(); 84 | 85 | return []; 86 | } 87 | 88 | // 修改操作 89 | // 返回一个bool类型的数据 90 | public function update(Form $form) 91 | { 92 | // 获取id 93 | $id = $form->builder()->getResourceId(); 94 | 95 | // 获取要修改的数据 96 | $attributes = $form->updates(); 97 | 98 | // TODO 99 | // 这里写你的修改逻辑 100 | 101 | return true; 102 | } 103 | 104 | // 这个方法用于在修改数据前查询原始数据 105 | // 如果使用了文件上传表单,会根据这个数据自动删除文件 106 | // 如果不需要此数据返回空数组即可 107 | public function deleting(Form $form) 108 | { 109 | $id = $form->builder()->getResourceId(); 110 | 111 | $id = explode(',', $id); 112 | 113 | // $data = file_get_contents("http://api.douban.com/v2/movie/subject/$id"); 114 | // 115 | // return json_decode($data, true); 116 | 117 | return []; 118 | } 119 | 120 | // 删除数据 121 | // $deletingData 是由 getDataWhenDeleting 方法返回的数据 122 | public function destroy(Form $form, $deletingData) 123 | { 124 | // 注意这里的id可能是多个 125 | $id = $form->builder()->getResourceId(); 126 | 127 | // 当使用批量删除功能时,这里的id是用“,”隔开的字符串 128 | $id = explode(',', $id); 129 | 130 | // TODO 131 | // var_dump($id, $deletingData); 132 | 133 | return true; 134 | } 135 | 136 | } 137 | ``` 138 | 139 | 140 | -------------------------------------------------------------------------------- /2.x/model-form-init.md: -------------------------------------------------------------------------------- 1 | # 表单初始化 2 | 3 | 通过`Form::resolving`方法设置的回调函数会在`Dcat\Admin\Form`类被实例化时触发; 4 | 5 | 通过`Form::composing`方法设置的回调函数会在`render()`方法被调用时(渲染页面时)触发; 6 | 7 | 开发者可以在这两个事件中改变`Form`的一些设置或行为,比如需要禁用掉某些操作,可以在`app/Admin/bootstrap.php`加入下面的代码: 8 | 9 | ```php 10 | use Dcat\Admin\Form; 11 | 12 | Form::resolving(function (Form $form) { 13 | 14 | $form->disableEditingCheck(); 15 | 16 | $form->disableCreatingCheck(); 17 | 18 | $form->disableViewCheck(); 19 | 20 | $form->tools(function (Form\Tools $tools) { 21 | $tools->disableDelete(); 22 | $tools->disableView(); 23 | $tools->disableList(); 24 | }); 25 | 26 | }); 27 | ``` 28 | 这样就不用在每一个控制器的代码中来设置了。 29 | 30 | 如果全局设置后,要在其中某一个表单中开启设置,比如开启显示`继续编辑`的checkbox,在对应的实例上调用`$form->disableEditingCheck(false);`就可以了 -------------------------------------------------------------------------------- /2.x/model-form-trans.md: -------------------------------------------------------------------------------- 1 | # 表单字段翻译 2 | 3 | 数据表单表单中所有使用到字段的地方都会自动读取语言包中的翻译。 4 | 5 | > {tip} 语言包的详细使用方法请参考[多语言](trans.md)。 6 | 7 | ### 语言包名称 8 | 语言包名称需要与控制器名相对应,假如控制器名`UserProfileController`,则对应的语言包为`resources/lang/{当前语言}/user-profile.php`(需要转化为小写中划线风格)。 9 | 10 | 11 | 如果想要更改语言包的名称,可以通过下面两种方式进行更改 12 | 13 | 方式1 14 | ```php 15 | use Dcat\Admin\Http\Controllers\AdminController; 16 | 17 | class UserController extends AdminController 18 | { 19 | /** 20 | * 指定翻译文件名称 21 | * 22 | * @var string 23 | */ 24 | protected $translation = 'user1'; 25 | 26 | ... 27 | } 28 | ``` 29 | 30 | 方式2 31 | ```php 32 | use Dcat\Admin\Admin; 33 | 34 | Admin::translation('user1'); 35 | ``` 36 | 37 | 38 | ### 示例 39 | 现在假设语言包`resources/lang/zh_CN/user-profile.php`内容如下: 40 | ```php 41 | return [ 42 | 'fields' => [ 43 | 'name' => '名称', 44 | 'age' => '年龄', 45 | 'class' => '班级', 46 | ], 47 | ]; 48 | ``` 49 | 50 | 控制器`UserProfileController`中设置的`Form`字段会自动读取以上翻译: 51 | ```php 52 | // 不设置labael会自动读取语言包翻译 53 | $form->display('id'); 54 | $form->text('name'); 55 | $form->text('age'); 56 | $form->text('class'); 57 | ``` 58 | 59 | ### 公共翻译 60 | 当`admin_trans_field`函数找不到当前控制器中对指定字段的翻译时,会去`global.php`中查找。如果某些字段是很多数据表中都有的,可以把这些翻译写在`resources/lang/{当前语言}/global.php`文件中。 61 | ```php 62 | return [ 63 | // 常用的字段放在 global.php 中可以所有控制器共用。 64 | 'fields' => [ 65 | 'id' => 'ID', 66 | 'created_at' => '创建时间', 67 | 'updated_at' => '更新时间', 68 | ], 69 | ]; 70 | ``` 71 | 72 | -------------------------------------------------------------------------------- /2.x/model-grid-async.md: -------------------------------------------------------------------------------- 1 | # 表格异步渲染 2 | 3 | 当页面的表格展示的数据特别多(列多行多),并且加载的组件也较多时,可能会出现卡顿的现象,此时可以使用表格异步渲染功能,可以有效地减轻页面卡顿的情况: 4 | 5 | 6 | ```php 7 | // 启用表格异步渲染功能 8 | $grid->async(); 9 | 10 | // 禁用 11 | $grid->async(false); 12 | 13 | // 判断是否是异步渲染请求 14 | if ($grid->isAsyncRequest()) { 15 | ... 16 | } 17 | ``` 18 | 19 | > 需要注意的是,如果页面没有出现明显的卡顿现象,则无需启用此功能。并且如果页面中存在多个数据表格,那么也无法使用此功能。 20 | 21 | 开启此功能之后,表格**工具栏**(`toolbar`)以下的位置都会采用异步的方式进行渲染,换句话说,**工具栏**(`toolbar`)以及以上的位置只会刷新一次!在实际编码过程中需要注意有无特殊影响。 22 | -------------------------------------------------------------------------------- /2.x/model-grid-combination.md: -------------------------------------------------------------------------------- 1 | # 组合表头 2 | 3 | 通过 `Grid::combine` 方法可以很方便的把任意两个以上的字段组合成一级表头 4 | 5 | 6 | 7 | 8 | 9 | 示例 10 | 11 | ```php 12 | protected function grid() 13 | { 14 | return Grid::make(new Report(), function (Grid $grid) { 15 | // 第一个参数为一级表头字段名称,第二个字段为二级表头字段名称,二级表头字段最少设置两个 16 | $grid->combine('avgCost', ['avgMonthCost', 'avgQuarterCost', 'avgYearCost']); 17 | 18 | $grid->combine('avgVist', ['avgMonthVist', 'avgQuarterVist', 'avgYearVist']); 19 | 20 | // 设置样式 21 | $grid->combine('top', ['topCost', 'topVist', 'topIncr'])->style('color:#1867c0'); 22 | 23 | $grid->column('content')->limit(50); 24 | $grid->column('cost')->sortable(); 25 | $grid->column('avgMonthCost'); 26 | $grid->column('avgQuarterCost')->setHeaderAttributes(['style' => 'color:#5b69bc']); 27 | $grid->column('avgYearCost'); 28 | $grid->column('avgMonthVist'); 29 | $grid->column('avgQuarterVist'); 30 | $grid->column('avgYearVist'); 31 | $grid->column('incrs'); 32 | $grid->column('avgVists'); 33 | $grid->column('topCost'); 34 | $grid->column('topVist'); 35 | $grid->column('topIncr'); 36 | $grid->column('date')->sortable(); 37 | }); 38 | } 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /2.x/model-grid-events.md: -------------------------------------------------------------------------------- 1 | # 数据表格事件 2 | 3 | ### 初始化 4 | 5 | 6 | 通过 `Grid::resolving` 方法可以监听表格初始化事件。 7 | 8 | 9 | 开发者可以在这两个事件中改变 `Grid` 的一些设置或行为,比如需要禁用掉某些操作,可以在 `app/Admin/bootstrap.php` 加入下面的代码: 10 | 11 | ```php 12 | use Dcat\Admin\Grid; 13 | 14 | Grid::resolving(function (Grid $grid) { 15 | $grid->disableActions(); 16 | 17 | $grid->disablePagination(); 18 | 19 | $grid->disableCreateButton(); 20 | 21 | $grid->disableFilter(); 22 | 23 | $grid->disableRowSelector(); 24 | 25 | $grid->disableToolbar(); 26 | }); 27 | 28 | 29 | // 只需要监听一次 30 | Grid::resolving(function (Grid $grid) { 31 | ... 32 | }, true); 33 | ``` 34 | 这样就不用在每一个控制器的代码中来设置了。 35 | 36 | 如果全局设置后,要在其中某一个表格中开启设置,比如开启显示操作列,在对应的实例上调用 `$grid->disableActions(false);` 就可以了 37 | 38 | 39 | ### 构建 40 | 41 | 通过 `Grid::composing` 方法可以监听表格被调用事件。 42 | 43 | ```php 44 | Grid::composing(function (Grid $grid) { 45 | ... 46 | }); 47 | 48 | // 只需要监听一次 49 | Grid::composing(function (Grid $grid) { 50 | ... 51 | }, true); 52 | ``` 53 | 54 | ### Fetching 55 | 56 | 监听表格获取数据之前事件,此事件在 `composing` 事件之后触发。 57 | 58 | ```php 59 | $grid->listen(Grid\Events\Fetching::class, function ($grid) { 60 | 61 | }); 62 | 63 | 64 | // 可以在 composing 事件中使用 65 | Grid::composing(function (Grid $grid) { 66 | $grid->listen(Grid\Events\Fetching::class, function ($grid) { 67 | 68 | }); 69 | }); 70 | ``` 71 | 72 | ### Fetched 73 | 74 | 监听表格获取数据之后事件,通过监听此事件可以批量修改数据, 参考下面实例 75 | 76 | ```php 77 | $grid->listen(Grid\Events\Fetched::class, function ($grid, Collection $rows) { 78 | // $collection 当前这一个表格数据的模型集合, 你可以根据你的需要来读取或者修改它的数据。 79 | 80 | $rows->transform(function ($row) { 81 | // 更改行数据 82 | $row['name'] = $row['first_name'].' '.$row['last_name']; 83 | 84 | return $row; 85 | }); 86 | }); 87 | ``` 88 | 89 | ### ApplyFilter 90 | 91 | 监听表格过滤器搜索事件,此事件只有在过滤器有搜索条件时才会触发 92 | 93 | ```php 94 | $grid->listen(Grid\Events\ApplyFilter::class, function ($grid, array $conditions) { 95 | // $conditions 当前过滤器生成的搜索条件数组 96 | 97 | dd('表格过滤器', $conditions); 98 | }); 99 | ``` 100 | 101 | 102 | ### ApplyQuickSearch 103 | 104 | 监听表格快捷搜索事件,此事件只有在快捷搜索输入框有值时才会触发 105 | 106 | ```php 107 | $grid->listen(Grid\Events\ApplyQuickSearch::class, function ($grid, $input) { 108 | // $input 搜索关键字 109 | 110 | dd('表格快捷搜索', $input); 111 | }); 112 | ``` 113 | 114 | ### ApplySelector 115 | 116 | 监听表格规格筛选器事件,此事件只有在规格筛选器选中选项时才会触发 117 | 118 | ```php 119 | $grid->listen(Grid\Events\ApplySelector::class, function ($grid, array $input) { 120 | // $input 筛选器选中的选项数组 121 | 122 | dd('表格规格筛选器', $input); 123 | }); 124 | ``` 125 | 126 | 127 | 128 | ### rows回调 129 | 130 | 通过 `Grid::rows` 方法可以监听表格获取数据之后事件。 131 | 132 | ```php 133 | use Dcat\Admin\Grid\Row; 134 | use Illuminate\Support\Collection; 135 | 136 | $grid->rows(function (Collection $rows) { 137 | /** 138 | * 获取第一行数据 139 | * 140 | * @var Row $firstRow 141 | */ 142 | $firstRow = $rows->first(); 143 | 144 | // 设置 tr html属性 145 | $firstRow->setAttributes(['name' => '....']); 146 | 147 | if ($firstRow) { 148 | // 获取第一行的 id 149 | $id = $firstRow->id; 150 | // 转化为数组 151 | $row = $firstRow->toArray(); 152 | } 153 | }); 154 | ``` 155 | 156 | 157 | -------------------------------------------------------------------------------- /2.x/model-grid-export.md: -------------------------------------------------------------------------------- 1 | # 数据导出 2 | 3 | 系统默认使用Easy Excel作为导出工具,支持导出 `csv`、 `xlsx` 和 `ods` 等格式文件。 4 | 5 | 6 | 使用前必须先安装Easy Excel: 7 | 8 | ```bash 9 | composer require dcat/easy-excel 10 | ``` 11 | 12 | > {tip} 默认不开启导出功能。 13 | 14 | ### 启用导出功能 15 | 启用或禁用导出功能 16 | ```php 17 | $grid->export(); 18 | ``` 19 | 20 | 禁用 `导出所有` 选项 21 | ```php 22 | $grid->export()->disableExportAll(); 23 | ``` 24 | 25 | 禁用 `导出选中行` 选项 26 | ```php 27 | $grid->export()->disableExportSelectedRow(); 28 | ``` 29 | 30 | 禁用 `导出当前页` 选项 31 | ```php 32 | $grid->export()->disableExportCurrentPage(); 33 | ``` 34 | 35 | ### 导出文件类型 36 | 37 | > {tip} 默认导出 `xlsx` 格式文件。 38 | 39 | ```php 40 | // csv 41 | $grid->export()->csv(); 42 | 43 | // xlsx 44 | $grid->export()->xlsx(); 45 | 46 | // ods 47 | $grid->export()->ods(); 48 | ``` 49 | 50 | ### 设置列标题 51 | 52 | > {tip} 如果设置了标题,那么导出的文件的**列数**与标题的**列数**相同,且列的**排序**也相同。 53 | 54 | ```php 55 | // 只导出 id, name和email 三列数据 56 | $titles = ['id' => 'ID', 'name' => '名称', 'email' => '邮箱']; 57 | 58 | $grid->export($titles); 59 | 60 | // 也可以这么使用 61 | $grid->export()->titles($titles); 62 | ``` 63 | 64 | ### 处理导出数据 65 | 66 | ```php 67 | $grid->export()->rows(function (array $rows) { 68 | foreach ($rows as $index => &$row) { 69 | $row['name'] = $row['first_name'].' '.$row['last_name']; 70 | } 71 | 72 | return $rows; 73 | }); 74 | ``` 75 | 76 | ### 设置导出文件名 77 | 78 | ```php 79 | $grid->export()->filename('管理员数据'); 80 | ``` 81 | 82 | 83 | ## 扩展导出功能 84 | 85 | 如果系统内置的导出功能不了自己的需求,可以按照下面的步骤来自定义导出功能 86 | 87 | 本示例用[Laravel-Excel](https://github.com/Maatwebsite/Laravel-Excel)作为excel操作库,当然也可以使用任何其他excel库 88 | 89 | 首先安装好它: 90 | 91 | ```shell 92 | composer require maatwebsite/excel:~2.1.0 93 | 94 | php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" 95 | ``` 96 | 97 | 然后新建自定义导出类,比如`app/Admin/Extensions/ExcelExpoter.php`: 98 | ```php 99 | sheet('Sheetname', function($sheet) { 113 | 114 | // 最多导出10W条数据 115 | // 必须设置maxSize,当否则选择导出所有选项时只能导出默认的20条数据。 116 | $maxSize = 10000; 117 | 118 | // 这段逻辑是从表格数据中取出需要导出的字段 119 | $rows = collect($this->buildData(1, $maxSize))->map(function ($item) { 120 | return array_only($item, ['id', 'title', 'content', 'rate', 'keywords']); 121 | }); 122 | 123 | $sheet->rows($rows); 124 | 125 | }); 126 | 127 | })->export('xls'); 128 | } 129 | } 130 | ``` 131 | 132 | 然后在`model-grid`中使用这个导出类: 133 | ```php 134 | 135 | use App\Admin\Extensions\ExcelExpoter; 136 | 137 | $grid->export(new ExcelExpoter()); 138 | ``` 139 | 140 | 有关更多`Laravel-Excel`的使用方法,参考[laravel-excel/docs](http://www.maatwebsite.nl/laravel-excel/docs) -------------------------------------------------------------------------------- /2.x/model-grid-exporter.md: -------------------------------------------------------------------------------- 1 | # 自定义导出 2 | 3 | dcat-admin的数据表格默认支持导出csv文件, 4 | 5 | ```php 6 | getTable().'.csv'; 17 | 18 | $data = $this->getData(); 19 | 20 | $output = ''; 21 | 22 | $headers = [ 23 | 'Content-Encoding' => 'UTF-8', 24 | 'Content-Type' => 'text/csv;charset=UTF-8', 25 | 'Content-Disposition' => "attachment; filename=\"$filename\"", 26 | ]; 27 | 28 | response(rtrim($output, "\n"), 200, $headers)->send(); 29 | 30 | exit; 31 | } 32 | } 33 | ``` -------------------------------------------------------------------------------- /2.x/model-grid-header.md: -------------------------------------------------------------------------------- 1 | # 头部和脚部 2 | 3 | 数据表格支持往头部和脚部两个区块填入你想要的内容 4 | 5 | ```php 6 | $grid->header(function ($collection) { 7 | return 'header'; 8 | }); 9 | 10 | $grid->footer(function ($collection) { 11 | return 'footer'; 12 | }); 13 | ``` 14 | 15 | 其中闭包函数的参数`$collection`为`Illuminate\Support\Collection`类实例,是当前页表格数据,下面是两个不同场景的使用举例 16 | 17 | ## 头部 18 | 19 | ```php 20 | $grid->header(function ($collection) use ($grid) { 21 | $query = Model::query(); 22 | 23 | // 拿到表格筛选 where 条件数组进行遍历 24 | $grid->model()->getQueries()->unique()->each(function ($value) use (&$query) { 25 | if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) { 26 | return; 27 | } 28 | 29 | $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []); 30 | }); 31 | 32 | // 查出统计数据 33 | $data = $query->get(); 34 | 35 | // 自定义组件 36 | return new Card($data); 37 | }); 38 | ``` 39 | 40 | 自定义头部展示的组件实现 41 | ```php 42 | data = $data; 61 | } 62 | 63 | public function script() 64 | { 65 | return <<script()); 80 | 81 | return view('...', ['data' => $this->data])->render(); 82 | } 83 | } 84 | ``` 85 | 86 | 87 | ## 脚部 88 | 89 | 一个比较常见的场景是在数据表格的脚部显示统计信息,比如在订单表格的脚部加入收入统计,可以参考下面的代码实现: 90 | 91 | ```php 92 | $grid->footer(function ($collection) use ($grid) { 93 | $query = Model::query(); 94 | 95 | // 拿到表格筛选 where 条件数组进行遍历 96 | $grid->model()->getQueries()->unique()->each(function ($value) use (&$query) { 97 | if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) { 98 | return; 99 | } 100 | 101 | $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []); 102 | }); 103 | 104 | // 查出统计数据 105 | $data = $query->get(); 106 | 107 | return "
总收入 : $data
"; 108 | }); 109 | ``` 110 | 111 | 如果有比较复杂的脚部需要显示,也可以使用视图对象或者封装成一个类来实现。 -------------------------------------------------------------------------------- /2.x/model-grid-selector.md: -------------------------------------------------------------------------------- 1 | # 表格规格筛选器 2 | 3 | 4 | 这个功能用来构建类似淘宝或京东商品的规格选择。 5 | 6 | 7 | 8 | 9 | 10 | 11 | ### 基本使用 12 | 13 | 14 | > {tip} `select`和`selectOne`方法的第二个参数为选择器`label`, 可以省略,如果省略的话将会自动使用翻译文件的翻译. 15 | 16 | 17 | 如下代码所示,假设`brand`字段的4个取值分别对应4个品牌,下面的方式会构建出`brand`的规格选择器 18 | 19 | ```php 20 | use Dcat\Admin\Grid; 21 | 22 | $grid->selector(function (Grid\Tools\Selector $selector) { 23 | $selector->select('brand', '品牌', [ 24 | 1 => '华为', 25 | 2 => '小米', 26 | 3 => 'OPPO', 27 | 4 => 'vivo', 28 | ]); 29 | }); 30 | ``` 31 | 32 | `select`方法默认是多选的,在页面上点击每一个选项的右边的加号,这个字段的查询会增加一个查询选项,如果字段筛选只允许选择一项,使用`selectOne`方法 33 | 34 | ```php 35 | $selector->selectOne('brand', '品牌', [ 36 | 1 => '华为', 37 | 2 => '小米', 38 | 3 => 'OPPO', 39 | 4 => 'vivo', 40 | ]); 41 | ``` 42 | 43 | ### 关联关系字段查询 44 | 45 | 如果安装了 [dcat/laravel-wherehasin](https://github.com/jqhph/laravel-wherehasin),则会优先使用`whereHasIn`方法进行查询操作 46 | 47 | ```php 48 | use Dcat\Admin\Grid; 49 | 50 | $grid->selector(function (Grid\Tools\Selector $selector) { 51 | $selector->select('brand.id', '品牌', [ 52 | 1 => '华为', 53 | 2 => '小米', 54 | 3 => 'OPPO', 55 | 4 => 'vivo', 56 | ]); 57 | }); 58 | ``` 59 | 60 | 61 | ### 自定义查询 62 | 上面的方式会使用在选择器上选定的值,作为查询条件进行查询,但是有些情况需要更灵活的控制查询方式,那么可以使用下面的方式自定义查询: 63 | 64 | ```php 65 | $selector->select('price', '价格', ['0-999', '1000-1999', '2000-2999'], function ($query, $value) { 66 | $between = [ 67 | [0, 999], 68 | [1000, 1999], 69 | [2000, 2999], 70 | ]; 71 | 72 | $value = current($value); 73 | 74 | $query->whereBetween('price', $between[$value]); 75 | }); 76 | ``` 77 | 78 | 如上所示,传入一个匿名函数作为第四个参数,价格字段price选择之后,将会使用匿名函数中的逻辑进行数据查询,这样你可以定义任意的查询方式。 79 | -------------------------------------------------------------------------------- /2.x/model-grid-trans.md: -------------------------------------------------------------------------------- 1 | # 表格字段翻译 2 | 3 | 数据表格中所有使用到字段的地方都会自动读取语言包中的翻译。 4 | 5 | > {tip} 语言包的详细使用方法请参考[多语言](trans.md)。 6 | 7 | ### 语言包名称 8 | 语言包名称需要与控制器名相对应,假如控制器名`UserProfileController`,则对应的语言包为`resources/lang/{当前语言}/user-profile.php`(需要转化为小写中划线风格)。 9 | 10 | 如果想要更改语言包的名称,可以通过下面两种方式进行更改 11 | 12 | 方式1 13 | ```php 14 | use Dcat\Admin\Http\Controllers\AdminController; 15 | 16 | class UserController extends AdminController 17 | { 18 | /** 19 | * 指定翻译文件名称 20 | * 21 | * @var string 22 | */ 23 | protected $translation = 'user1'; 24 | 25 | ... 26 | } 27 | ``` 28 | 29 | 方式2 30 | ```php 31 | use Dcat\Admin\Admin; 32 | 33 | Admin::translation('user1'); 34 | ``` 35 | 36 | 37 | 38 | 39 | ### 示例 40 | 现在假设语言包`resources/lang/zh_CN/user-profile.php`内容如下: 41 | ```php 42 | return [ 43 | 'fields' => [ 44 | 'name' => '名称', 45 | 'age' => '年龄', 46 | 'class' => '班级', 47 | ], 48 | ]; 49 | ``` 50 | 51 | 控制器`UserProfileController`中设置的`Grid`字段会自动读取以上翻译: 52 | ```php 53 | // 不设置labael会自动读取语言包翻译 54 | $grid->id(); 55 | $grid->name; 56 | $grid->age; 57 | $grid->class; 58 | 59 | $grid->filter(function ($filter) { 60 | $filter->gt('age'); 61 | }); 62 | 63 | // 上面代码等同于 64 | $grid->name('名称'); 65 | $grid->age('年龄'); 66 | 67 | // 也可这样使用 68 | $grid->id(admin_trans_field('id')); 69 | $grid->name(admin_trans_field('name')); 70 | $grid->age(admin_trans_field('age')); 71 | 72 | ``` 73 | 74 | ### 公共翻译 75 | 当`admin_trans_field`函数找不到当前控制器中对指定字段的翻译时,会去`global.php`中查找。如果某些字段是很多数据表中都有的,可以把这些翻译写在`resources/lang/{当前语言}/global.php`文件中。 76 | ```php 77 | return [ 78 | // 常用的字段放在 global.php 中可以所有控制器共用。 79 | 'fields' => [ 80 | 'id' => 'ID', 81 | 'created_at' => '创建时间', 82 | 'updated_at' => '更新时间', 83 | ], 84 | ]; 85 | ``` 86 | 87 | -------------------------------------------------------------------------------- /2.x/model-json.md: -------------------------------------------------------------------------------- 1 | # JSON格式字段处理 2 | 3 | `dcat-admin`的表单提供了下面几个组件来处理`JSON`格式的字段,方便用来处理`JOSN`格式的对象、一维数组、二维数组等对象。 4 | 5 | 6 | ## 键值对象 (keyValue) 7 | 8 | ![]({{public}}/assets/img/screenshots/key-value.png) 9 | 10 | 如果你的字段存储的是不固定`键`的`{"field":"value"}`格式,可以用`keyValue`组件: 11 | 12 | ```php 13 | $form->keyValue('column_name'); 14 | 15 | // 设置校验规则 16 | $form->keyValue('column_name')->rules('required|min:5'); 17 | ``` 18 | 19 | 自定义键名以及键值标题翻译 20 | 21 | ```php 22 | $form->keyValue(...)->setKeyLabel('键名')->setValueLabel('键值'); 23 | ``` 24 | 25 | ## 固定键值对象 (embeds) 26 | 27 | ![]({{public}}/assets/img/screenshots/embeds.png) 28 | 29 | 用于处理`mysql`的`JSON`类型字段数据或者`mongodb`的`object`类型数据,也可以将多个`field`的数据值以`JSON`字符串的形式存储在`mysql`的字符串类型字段中 30 | 31 | 适用于有固定键值的`JSON`类型字段 32 | 33 | ```php 34 | $form->embeds('column_name', function ($form) { 35 | 36 | $form->text('key1')->required(); 37 | $form->email('key2')->required(); 38 | $form->datetime('key3'); 39 | 40 | $form->dateRange('key4', 'key5', '范围')->rules('required'); 41 | })->saving(funtion ($v) { 42 | // 转化为json格式存储 43 | return json_encode($v); 44 | }); 45 | 46 | // 自定义标题 47 | $form->embeds('column_name', '字段标题', function ($form) { 48 | ... 49 | }); 50 | ``` 51 | 52 | 回调函数里面构建表单元素的方法调用和外面是一样的。 53 | 54 | ## 一维数组 (list) 55 | 56 | ![]({{public}}/assets/img/screenshots/form-list.png) 57 | 58 | 如果你的字段是用来存储`["foo", "Bar"]`格式的一维数组, 可以使用`list`组件: 59 | 60 | ```php 61 | $form->list('column_name'); 62 | 63 | // 设置校验规则 64 | $form->list('column_name')->rules('required|min:5'); 65 | 66 | // 设置最大和最小元素个数 67 | $form->list('column_name')->max(10)->min(5); 68 | ``` 69 | 70 | ## 二维数组 (table) 71 | 72 | ![]({{public}}/assets/img/screenshots/form-table.png) 73 | 74 | 如果某一个字段存储的是`json`格式的二维数组,可以使用`table`表单组件来实现快速的编辑: 75 | 76 | ```php 77 | $form->table('column_name', function ($table) { 78 | $table->text('key'); 79 | $table->text('value'); 80 | $table->textarea('desc'); 81 | })->saving(function ($v) { 82 | return json_encode($v); 83 | }); 84 | ``` 85 | 86 | 这个组件类似于`hasMany`组件,不过是用来处理单个字段的情况,适用于简单的二维数据。 87 | 88 | 89 | ## 二维数组 (array) 90 | 91 | ![]({{public}}/assets/img/screenshots/has-many.png) 92 | 93 | 如果某一个字段存储的是`json`格式的二维数组,并且字段比较多,可以使用`array`表单组件来实现快速的编辑: 94 | 95 | ```php 96 | $form->array('column_name', function ($table) { 97 | $table->text('key'); 98 | $table->text('value'); 99 | $table->textarea('desc'); 100 | })->saveAsJson(); 101 | ``` 102 | -------------------------------------------------------------------------------- /2.x/model-show-extend.md: -------------------------------------------------------------------------------- 1 | # 详情字段显示扩展 2 | 3 | 这个功能用来扩展详情字段显示, 在内置的显示方法不满足需求的情况下,可以使用这个功能来实现 4 | 5 | 首先定义扩展类: 6 | 7 | ```php 8 | value); 23 | } 24 | } 25 | ``` 26 | 然后在`app/Admin/bootstrap.php`中注册扩展类 27 | 28 | ```php 29 | use Dcat\Admin\Show\Field; 30 | use App\Admin\Extensions\Show\UnSerialize; 31 | 32 | Field::extend('unserialize', UnSerialize::class); 33 | ``` 34 | 然后在控制器中使用这个扩展 35 | 36 | ```php 37 | $show->column()->unserialize('xxx'); 38 | ``` 39 | 传入unserialize()方法的参数会按顺序传入UnSerialize::render()方法中。 40 | 41 | 在父类`Dcat\Admin\Show\AbstractField`中可以看到几个常用的属性 42 | 43 | ```php 44 | /** 45 | * Field value. 46 | * 47 | * @var mixed 48 | */ 49 | protected $value; 50 | 51 | /** 52 | * Current field model. 53 | * 54 | * @var Fluent 55 | */ 56 | protected $model; 57 | 58 | /** 59 | * If this field show with a border. 60 | * 61 | * @var bool 62 | */ 63 | public $border = true; 64 | 65 | /** 66 | * If this field show escaped contents. 67 | * 68 | * @var bool 69 | */ 70 | public $escape = true; 71 | ``` 72 | 其中`$value`和`$model`分别是当前字段值和当前详情内容的数据,在`render()`方法中可以用来获取你想要的数据。 73 | 74 | `$border`用来控制当前显示内容是否需要外边框,`$escape`分别用来设置当前显示内容要不要HTML转义。 -------------------------------------------------------------------------------- /2.x/model-show-init.md: -------------------------------------------------------------------------------- 1 | # 数据详情初始化 2 | 3 | 通过`Show::resolving`方法设置的回调函数会在`Dcat\Admin\Show`类被实例化时触发; 4 | 5 | 通过`Show::composing`方法设置的回调函数会在`render()`方法被调用时触发; 6 | 7 | 开发者可以在这两个事件中改变`Show`的一些设置或行为,比如需要禁用掉某些操作,可以在`app/Admin/bootstrap.php`加入下面的代码: 8 | 9 | ```php 10 | use Dcat\Admin\Show; 11 | 12 | Show::resolving(function (Show $show) { 13 | 14 | $show->showQuickEdit(); 15 | 16 | }); 17 | ``` 18 | -------------------------------------------------------------------------------- /2.x/model-show-trans.md: -------------------------------------------------------------------------------- 1 | # 数据详情字段翻译 2 | 3 | 与数据表格字段翻译的使用基本一致,可参考[数据表格字段翻译](model-grid-trans.md)。 -------------------------------------------------------------------------------- /2.x/model-show.md: -------------------------------------------------------------------------------- 1 | # 数据详情基本使用 2 | 3 | `Dcat\Admin\Show`用来显示数据详情,先来个例子,数据库中有posts表: 4 | 5 | ```sql 6 | CREATE TABLE `posts` ( 7 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 8 | `author_id` int(10) unsigned NOT NULL , 9 | `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 10 | `content` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 11 | `rate` int(255) COLLATE utf8_unicode_ci NOT NULL, 12 | `release_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', 13 | `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', 14 | `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', 15 | PRIMARY KEY (`id`) 16 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 17 | ``` 18 | 对应的数据模型为`App\Models\Post`,数据仓库为`App\Admin\Repositories\Post`,下面的代码可以显示posts表的数据详情: 19 | 20 | 21 | ```php 22 | header('Post') 37 | ->description('详情') 38 | ->body(Show::make($id, new Post(), function (Show $show) { 39 | $show->id('ID'); 40 | $show->title('标题'); 41 | $show->content('内容'); 42 | $show->rate(); 43 | $show->created_at(); 44 | $show->updated_at(); 45 | $show->release_at(); 46 | })); 47 | } 48 | } 49 | ``` 50 | 51 | ## 基本使用方法 52 | 53 | ### HTML内容转义 54 | 为了防止XSS攻击, 默认输出的内容都会使用HTML转义,如果你不想转义输出`HTML`,可以调用`unescape`方法: 55 | 56 | ```php 57 | $show->avatar()->unescape()->as(function ($avatar) { 58 | 59 | return ""; 60 | 61 | }); 62 | ``` 63 | 64 | ### 设置字段宽度 65 | 字段宽度默认值为“3”,可以设置1-12之间的数字。 66 | 67 | ```php 68 | $show->created_at->width(4); 69 | ``` 70 | 71 | ### 修改面板的样式和标题 72 | ```php 73 | $show->panel() 74 | ->style('danger') 75 | ->title('post基本信息...'); 76 | ``` 77 | style的取值可以是primary、info、danger、warning、default 78 | 79 | ### 面板工具设置 80 | 面板右上角默认有三个按钮编辑、删除、列表,可以分别用下面的方式关掉它们: 81 | 82 | ```php 83 | $show->panel() 84 | ->tools(function ($tools) { 85 | $tools->disableEdit(); 86 | $tools->disableList(); 87 | $tools->disableDelete(); 88 | // 显示快捷编辑按钮 89 | $tools->showQuickEdit(); 90 | }); 91 | ``` 92 | 93 | #### 自定义复杂工具按钮 94 | 95 | 请参考文档[数据详情动作](action-show.md) 96 | 97 | 98 | ### 多列布局 99 | 100 | 使用 101 | 102 | ```php 103 | $show->row(function (Show\Row $show) { 104 | $show->width(3)->id; 105 | $show->width(3)->name; 106 | $show->width(5)->email; 107 | }); 108 | 109 | $show->row(function (Show\Row $show) { 110 | $show->width(5)->email_verified_at; 111 | $show->created_at; 112 | $show->updated_at; 113 | }); 114 | 115 | $show->row(function (Show\Row $show) { 116 | $show->width(3)->field('profile.first_name'); 117 | $show->field('profile.last_name'); 118 | $show->width(3)->field('profile.postcode'); 119 | }); 120 | ``` 121 | 122 | 效果 123 | 124 | 125 | -------------------------------------------------------------------------------- /2.x/response.md: -------------------------------------------------------------------------------- 1 | # 动作以及表单响应 2 | 3 | [动作](action.md)、[数据表单](model-form.md)以及[工具表单](widgets-form.md)的响应方法都是同一套方法。 4 | 5 | 在类中可以通过 `$this->response()` 获取到 `Dcat\Admin\Http\JsonResponse`对象并响应数据到前端 6 | 7 | ```php 8 | return $this->response()->success('成功!'); 9 | 10 | // 等同于 11 | use Dcat\Admin\Admin; 12 | use Dcat\Admin\Http\JsonResponse; 13 | 14 | return JsonResponse::make()->success('成功!'); 15 | 16 | return Admin::make()->success('成功!'); 17 | ``` 18 | 19 | 如果是在控制器中使用,需要加上`send`方法 20 | 21 | ```php 22 | public function index() 23 | { 24 | return JsonResponse::make()->success('成功!')->send(); 25 | } 26 | ``` 27 | 28 | 29 | ### 功能 30 | 下面介绍一下 `JsonResponse` 的主要用法 31 | 32 | 33 | #### 展示成功信息 34 | 35 | 此方法接收一个`string`类型参数 36 | 37 | ```php 38 | $this->response()->success('成功!'); 39 | ``` 40 | 41 | #### 展示错误信息 42 | 43 | 此方法接收一个`string`类型参数 44 | 45 | ```php 46 | $this->response()->error('出错了!'); 47 | ``` 48 | 49 | #### 展示警告信息 50 | 51 | 此方法接收一个`string`类型参数 52 | 53 | ```php 54 | $this->response()->warning('警告'); 55 | ``` 56 | 57 | #### 跳转 58 | 59 | 此方法接收一个`string`类型参数,可以与`success`、`error`、`warning`等方法同时使用 60 | 61 | ```php 62 | $this->response()->redirect('auth/users'); 63 | ``` 64 | 65 | #### 跳转 (location) 66 | 67 | `1`秒后自动跳转(非局部刷新),此方法接收一个`string`类型参数 68 | 69 | ```php 70 | $this->response()->success('操作成功')->location('auth/users'); 71 | ``` 72 | 73 | 如果不传参则刷新当前页面 74 | 75 | ```php 76 | $this->response()->success('操作成功')->location(); 77 | ``` 78 | 79 | #### 刷新当前页面 80 | 81 | 此方法可以与`success`、`error`、`warning`等方法同时使用 82 | 83 | ```php 84 | $this->response()->success('xxx')->refresh(); 85 | ``` 86 | 87 | #### 下载 88 | 89 | 此方法接收一个`string`类型参数 90 | 91 | ```php 92 | $this->response()->download('auth/users?_export_=1'); 93 | ``` 94 | 95 | #### 展示确认弹窗 96 | 97 | ```php 98 | // 成功 99 | $this->response()->alert(true)->success('...')->detail('详细内容'); 100 | 101 | // 错误 102 | $this->response()->alert(true)->error('...')->detail('详细内容'); 103 | 104 | // 警告 105 | $this->response()->alert(true)->warning('...')->detail('详细内容'); 106 | 107 | // 提示 108 | $this->response()->alert(true)->info('...')->detail('详细内容'); 109 | ``` 110 | 111 | #### 返回HTML 112 | 113 | 此方法可接收一个`string`、`Renderable`、`Htmlable`类型参数,可以与`success`、`error`、`warning`等方法同时使用 114 | 115 | > {tip} 响应的`HTML`字符默认会被置入动作按钮元素上,如果需要自己控制,则覆写[handleHtmlResponse](#handleHtmlResponse)方法即可。 116 | 117 | ```php 118 | $this->response()->html('a标签'); 119 | 120 | $this->response()->html(view('...')); 121 | ``` 122 | 123 | #### 执行JS代码 124 | 125 | 此方法接收一个`string`类型参数,可以与`success`、`error`、`warning`等方法同时使用 126 | 127 | ```php 128 | $this->response()->script( 129 | <<response()->success(...)->ifRefresh($condition); 142 | $this->response()->success(...)->ifLocation($condition, 'auth/users'); 143 | 144 | // $condition 也可以是闭包 145 | $this->response()->success(...)->ifRefresh(function () { 146 | return true; 147 | }); 148 | ``` 149 | 150 | -------------------------------------------------------------------------------- /2.x/update.md: -------------------------------------------------------------------------------- 1 | # 版本升级须知 2 | 3 | 4 | ### 说明 5 | 6 | `Dcat Admin`的版本发行将会参考主流`web框架`的发行策略,尽量降低版本升级带来的影响,小版本和补丁**决不**包含非兼容性更改;同时我们也将会提供更新日志,详细说明新版本的改动以及可能造成的影响。 7 | 8 | 9 | 10 | 11 | ### 升级命令 12 | 升级命令 13 | ```bash 14 | composer update dcat/laravel-admin 15 | ``` 16 | 17 | 升级成功之后需要运行 `admin:update` 命令进行重新发布语言包、配置文件、前端静态资源等文件,然后**清理浏览器缓存** 18 | 19 | ```bash 20 | # 发布 语言包、配置文件、前端静态资源、数据迁移文件等 21 | php artisan admin:update 22 | ``` 23 | 24 | 运行 `admin:update`,相当于运行 25 | 26 | ``` 27 | php artisan admin:publish --assets --migrations --lang --force 28 | php artisan migrate 29 | ``` 30 | 31 | #### 发布文件命令 32 | 33 | > 运行 `admin:update` 后一般不需要运行 `admin:publish` 命令 34 | 35 | ```bash 36 | php artisan admin:publish --force 37 | ``` 38 | 39 | 只更新语言包 40 | ```bash 41 | php artisan admin:publish --force --lang 42 | ``` 43 | 44 | 只更新配置文件 45 | ```bash 46 | php artisan admin:publish --force --config 47 | ``` 48 | 49 | 50 | 只更新前端静态资源 51 | ```bash 52 | php artisan admin:publish --force --assets 53 | ``` 54 | 55 | 只更新数据库迁徙文件(这个一般不需要更新) 56 | ```bash 57 | php artisan admin:publish --force --migrations 58 | ``` -------------------------------------------------------------------------------- /2.x/widgets-alert.md: -------------------------------------------------------------------------------- 1 | # 警告框 2 | 3 | ### Alert 4 | 基本用法 5 | 6 | ```php 7 | success(); 15 | $alert->danger(); 16 | $alert->info(); 17 | $alert->warning(); 18 | 19 | // 图标 20 | $alert->icon('feather icon-x'); 21 | 22 | // 可移除按钮 23 | $alert->removable(); 24 | ``` 25 | 效果 26 | 27 | 28 | 29 | 30 | ### Callout 31 | 32 | ```php 33 | light(); 41 | $callout->primary(); 42 | 43 | // 可移除按钮 44 | $callout->removable(); 45 | ``` 46 | 47 | 效果 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /2.x/widgets-box.md: -------------------------------------------------------------------------------- 1 | # 卡片 2 | 3 | ## Card 4 | 5 | ```php 6 | padding('0 15px 0 12px'); 18 | 19 | // 设置工具按钮 20 | $card->tool(''); 21 | 22 | // 设置底部内容 23 | $card->footer(view('...')); 24 | ``` 25 | 26 | ## Box 27 | 28 | ```php 29 | padding('0 15px 0 12px'); 38 | 39 | // 设置工具按钮 40 | $box->tool(''); 41 | 42 | // 设置收缩按钮 43 | $box->collapsable(); 44 | 45 | // 设置移除按钮 46 | $box->removable(); 47 | ``` -------------------------------------------------------------------------------- /2.x/widgets-checkbox.md: -------------------------------------------------------------------------------- 1 | # 单/复选框 2 | 3 | ## 单选框 4 | 5 | 通过 `Dcat\Admin\Widgets\Radio`类可以很方便地快速构建单选框表单。 6 | 7 | ### 基本使用 8 | 9 | ```php 10 | '未处理', 18 | 2 => '已处理', 19 | 3 => '已拒绝', 20 | ]; 21 | 22 | $radio = Radio::make($name, $options)->check(1); // 选中第一个选项 23 | ``` 24 | 25 | 效果 26 | 27 | 28 | 29 | 30 | 31 | ### 显示在同一行 (inline) 32 | 33 | ```php 34 | '未处理', 40 | 2 => '已处理', 41 | 3 => '已拒绝', 42 | ]; 43 | 44 | $radio = Radio::make($name, $options)->check(1)->inline(); 45 | ``` 46 | 效果 47 | 48 | 49 | 50 | 51 | 52 | ### 设置禁选的选项 (disable) 53 | 54 | 55 | ```php 56 | '未处理', 62 | 2 => '已处理', 63 | 3 => '已拒绝', 64 | ]; 65 | 66 | $radio = Radio::make($name, $options)->inline()->disable([2, 3]); 67 | ``` 68 | 效果 69 | 70 | 71 | 72 | 73 | 74 | ### 设置样式 (style) 75 | 76 | 通过`style`方法可以设置单选框的样式,支持`primary`、`info`、`success`、`danger`。 77 | 78 | ### 设置尺寸 79 | 80 | 单选框支持3中尺寸,使用方法如下 81 | 82 | 83 | `small`设置为小尺寸 84 | ```php 85 | $radio->small(); 86 | ``` 87 | 88 | `large`设置为大尺寸 89 | ```php 90 | $radio->large(); 91 | ``` 92 | 93 | 94 | ## 复选框 95 | 96 | 通过 `Dcat\Admin\Widgets\Checkbox`类可以很方便地快速构建复选框表单,并且复选框类是属于`Radio`的子类,因此用法与`Radio`类基本一致。 97 | 98 | ### 基本用法 99 | 100 | ```php 101 | '唱', 109 | 2 => '跳', 110 | 3 => 'RAP', 111 | 4 => '打篮球', 112 | ]; 113 | 114 | $checkbox = Checkbox::make($name, $options) 115 | ->inline() 116 | ->check([1, 2]); // 这里允许传递数组,默认选中多个选项 117 | ``` 118 | 119 | 效果 120 | 121 | 122 | 123 | 124 | 125 | ### 全选 126 | 127 | 通过`checkAll`方法可以选中全部选项。 128 | 129 | ```php 130 | '唱', 138 | 2 => '跳', 139 | 3 => 'RAP', 140 | 4 => '打篮球', 141 | ]; 142 | 143 | $checkbox = Checkbox::make($name, $options) 144 | ->inline() 145 | ->checkAll(); // 全部选中 146 | ``` 147 | 148 | `checkAll`方法也允许全选的同时排除指定选项。 149 | 150 | ```php 151 | $checkbox = Checkbox::make($name, $options) 152 | ->inline() 153 | ->checkAll([1, 3]); // 全部选中,但是排除key为1和3的选项 154 | ``` 155 | 156 | ### 更多用法 157 | 158 | 更多用法与`Radio`的用法一直,这里不再赘述。 159 | 160 | -------------------------------------------------------------------------------- /2.x/widgets-dialog-form.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/2.x/widgets-dialog-form.md -------------------------------------------------------------------------------- /2.x/widgets-js.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/2.x/widgets-js.md -------------------------------------------------------------------------------- /2.x/widgets-markdown.md: -------------------------------------------------------------------------------- 1 | # Markdown 2 | 3 | 基本用法 4 | 5 | ```php 6 | body(Card::make( 17 | Markdown::make('你的markdown本文内容') 18 | )); 19 | } 20 | } 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /2.x/widgets-modal.md: -------------------------------------------------------------------------------- 1 | # 模态窗 (Modal) 2 | 3 | 基本使用 4 | 5 | ```php 6 | use Dcat\Admin\Widgets\Modal; 7 | 8 | $modal = Modal::make() 9 | ->lg() 10 | ->title('标题') 11 | ->body(view(...)) 12 | ->button(''); 13 | 14 | return view(..., ['modal' => $modal]); 15 | ``` 16 | 17 | ## 功能 18 | 19 | ### 标题 (title) 20 | 21 | 设置弹窗标题 22 | 23 | ```php 24 | $modal->title('标题'); 25 | ``` 26 | 27 | ### 内容 (body) 28 | 29 | 设置弹窗内容,此方法接受一个参数,允许传入`string`、`Cloure`、`Illuminate\Contracts\Support\Renderable`以及`Dcat\Admin\Contracts\LazyRenderable`类型值 30 | 31 | ```php 32 | // 传入字符串 33 | $modal->body('字符串'); 34 | 35 | // 传入闭包,注意闭包必须返回字符串类型值或空值 36 | $modal->body(function () { 37 | return view(...)->render(); 38 | }); 39 | 40 | // 传入 Renderable 41 | use Dcat\Admin\Widgets\ 42 | 43 | $modal->body(view(...)); 44 | $modal->body(Card::make()); 45 | 46 | // 传入 LazyRenderable 47 | $modal->body(PostTable::make()); 48 | ``` 49 | 50 | ### 底部内容 (footer) 51 | 设置弹窗底部内容,此方法接受一个参数,允许传入`string`、`Cloure`、`Illuminate\Contracts\Support\Renderable`以及`Dcat\Admin\Contracts\LazyRenderable`类型值,用法同上 52 | 53 | ```php 54 | $modal->footer('字符串'); 55 | 56 | $modal->footer(view(...)); 57 | ``` 58 | 59 | ### 尺寸 60 | 61 | 默认 `500px` 62 | 63 | ```php 64 | // 800px 65 | $modal->lg(); 66 | 67 | // 1140px 68 | $modal->xl(); 69 | ``` 70 | 71 | ### 按钮 (button) 72 | 73 | 设置按钮 74 | 75 | ### 事件监听 76 | 77 | 支持事件 78 | 79 | - `onShow` 弹窗显示事件 80 | - `onShown` 弹窗已显示事件 81 | - `onHide` 弹窗隐藏事件 82 | - `onHidden` 弹窗已隐藏事件 83 | 84 | 用法示例 85 | 86 | ```php 87 | use Dcat\Admin\Admin; 88 | 89 | $modal->onShow( 90 | <<onHide( 96 | <<xl() 109 | ->centered() // 设置弹窗垂直居中 110 | ->title(...) 111 | ->body(...); 112 | ``` 113 | 114 | ### 内容可滚动 (scrollable) 115 | 116 | 设置弹窗内容可滚动 117 | 118 | ```php 119 | $modal = Modal::make() 120 | ->xl() 121 | ->scrollable() // 设置弹窗内容可滚动 122 | ->title(...) 123 | ->body(...); 124 | ``` 125 | 126 | 127 | ## 表单弹窗 128 | 129 | 参考文档 [工具表单 - 弹窗](widgets-form.md#modal) 130 | 131 | -------------------------------------------------------------------------------- /2.x/widgets-navbar.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/2.x/widgets-navbar.md -------------------------------------------------------------------------------- /2.x/widgets-tab.md: -------------------------------------------------------------------------------- 1 | # 选项卡 2 | 3 | 通过`Dcat\Admin\Widgets\Tab`方法可以快速构建`tab`选项卡。 4 | 5 | ### 基本用法 6 | 7 | ```php 8 | add('选项卡1', view('...'), true); 16 | $tab->add('选项2', 'html'); 17 | // 添加选项卡链接 18 | $tab->addLink('跳转链接', 'http://xxx'); 19 | 20 | return $content->body($tab->withCard()); 21 | ``` 22 | 23 | ### 切换显示模式 24 | 25 | ```php 26 | // 主题色 27 | $tab = Tab::make()->theme(); 28 | ``` 29 | 30 | ### 垂直 (vertical) 31 | 32 | 通过`vertical`方法可以让选项卡标题栏呈垂直排列。 33 | 34 | ```php 35 | add('选项卡1', view('...')); 42 | $tab->add('选项2', 'html'); 43 | 44 | return $content->body($tab->withCard()->vertical()); 45 | ``` 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /2.x/widgets-table.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/2.x/widgets-table.md -------------------------------------------------------------------------------- /2.x/widgets-tooltip.md: -------------------------------------------------------------------------------- 1 | # 提示窗 2 | 3 | 基本用法 4 | 5 | ```php 6 | title('我是提示信息'); 17 | 18 | return $content->body(new Card( 19 | << 21 | 22 | 23 | HTML 24 | )); 25 | } 26 | } 27 | ``` 28 | 效果 29 | 30 | 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 |
6 |

Dcat Admin is based on laravel-admin. It allows you to quickly build a fully functional backend system of high value with very little code. Built with a wealth of common back-end components, out of the box, allowing developers to say goodbye to redundant HTML code, very back-end developer-friendly.

7 | 8 |

9 | learnku文档 | 10 | Homepage | 11 | Demo | 12 | Demo Source Code | 13 | Extensions 14 |

15 | 16 | Dcat Admin Docs 17 | -------------------------------------------------------------------------------- /en-2.x/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jiang Qinghua 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /en-2.x/README.md: -------------------------------------------------------------------------------- 1 | # dcat-admin 2 | 3 | `Dcat Admin` is a backend builder based on [Laravel-admin](https://github.com/z-song/laravel-admin) that allows you to build a beautiful backend with very little code. 4 | 5 | >`Dcat Admin` is based on [Laravel-admin](https://github.com/z-song/laravel-admin) and has been rewritten with a lot of useful features and interfaces to help you build a beautiful and functional backend in a simple and comfortable way 6 | 7 | 8 | ## Features 9 | 10 | + `model-grid` support for fast data table construction 11 | + `model-form` support for rapid data form building 12 | + `model-tree` support for fast tree construction 13 | + Built-in permission system 14 | + Nearly 100 built-in page components, including 40+ form element components, and support for extension components 15 | + Multiple model relationships for `Laravel` support 16 | + Multi-database support for `mysql`, `mongodb`, `pgsql`, etc. 17 | + Support for the introduction of third-party front-end libraries 18 | + web implementation of database and artisan command-line tools 19 | + Support for custom charts 20 | + multiple common web components 21 | + Support for local and oss file uploads 22 | 23 | ## Demo 24 | 25 | Open [demo](),and login with `admin/admin`. 26 | 27 | ## Requirements 28 | + PHP >= 7.1 29 | + Laravel >= 5.5.0 30 | + Fileinfo PHP Extension 31 | 32 | ## Installation 33 | ```sh 34 | composer require dcat/admin 35 | ``` 36 | 37 | 38 | # Dependencies 39 | 40 | `dcat-admin` is based on the following components or services: 41 | 42 | + [Laravel](https://laravel.com/) 43 | + [AdminLTE](https://almsaeedstudio.com/) 44 | + [Datetimepicker](http://eonasdan.github.io/bootstrap-datetimepicker/) 45 | + [font-awesome](http://fontawesome.io) 46 | + [moment](http://momentjs.com/) 47 | + [Google map](https://www.google.com/maps) 48 | + [Tencent map](http://lbs.qq.com/) 49 | + [bootstrap-fileinput](https://github.com/kartik-v/bootstrap-fileinput) 50 | + [jquery-pjax](https://github.com/defunkt/jquery-pjax) 51 | + [Nestable](http://dbushell.github.io/Nestable/) 52 | + [toastr](http://codeseven.github.io/toastr/) 53 | + [X-editable](http://github.com/vitalets/x-editable) 54 | + [bootstrap-number-input](https://github.com/wpic/bootstrap-number-input) 55 | + [fontawesome-iconpicker](https://github.com/itsjavi/fontawesome-iconpicker) 56 | 57 | ## Thanks 58 | + [Laravel-admin](https://github.com/z-song/laravel-admin) 59 | 60 | ## Contact 61 | 62 | QQ Group: 63 | 64 | 65 | ## License 66 | 67 | `dcat-admin` is licensed under [The MIT License (MIT)](en/LICENSE). 68 | -------------------------------------------------------------------------------- /en-2.x/change-log.md: -------------------------------------------------------------------------------- 1 | 2 | Current latest version [v2.0.0-beta](v2-0-0-beta.md) 3 | -------------------------------------------------------------------------------- /en-2.x/custom-chart.md: -------------------------------------------------------------------------------- 1 | # Custom charts 2 | 3 | `dcat-admin 1.5` has removed all chart components, if you want to add a chart component to your page, you can refer to the following procedure 4 | 5 | To use `chartjs` as an example, first download [chartjs](http://chartjs.org/) and put it in the public directory, for example, in `public/vendor/chartjs`. 6 | 7 | Then include the component in `app/Admin/bootstrap.php'. 8 | ```php 9 | use Dcat\Admin\Facades\Admin; 10 | 11 | Admin::js('/vendor/chartjs/dist/Chart.min.js'); 12 | 13 | ``` 14 | 15 | New view file `resources/views/admin/charts/bar.blade.php` 16 | 17 | ```php 18 | 19 | 61 | ``` 62 | 63 | You can then include this chart view anywhere on the page: 64 | 65 | ```php 66 | public function index() 67 | { 68 | return Admin::content(function (Content $content) { 69 | 70 | $content->header('chart'); 71 | $content->description('.....'); 72 | 73 | $content->body(view('admin.charts.bar')); 74 | }); 75 | } 76 | 77 | ``` 78 | 79 | Any chart library can be introduced in the above way, see [view layout](layout.md) for multi-chart page layout -------------------------------------------------------------------------------- /en-2.x/extension-helpers.md: -------------------------------------------------------------------------------- 1 | # Development tools 2 | 3 | In the latest version of the new developer-oriented help tools have been added to provide help in development to improve efficiency, currently provides `scaffolding`, `database command line` and `artisan command line` three tools, if there are better ideas for other utilities, welcome to provide suggestions. 4 | 5 | Installation: 6 | ```bash 7 | composer require dcat-admin-ext/helpers 8 | 9 | php artisan admin:import helpers 10 | ``` 11 | 12 | > {tip} Some of the functions of the tool will create or delete files in the project, and there may be issues with file or directory permissions, which will need to be resolved on your own. 13 | Also some of the database and artisan commands are not available in a web environment. 14 | 15 | 16 | ## Scaffolding Tools 17 | 18 | The scaffolding tool helps you to generate controller, model, migration file in one click, and run the migration file, visit `http://localhost/admin/helpers/scaffold` to open it. 19 | 20 | In which the primary key field is automatically generated without filling when setting the migration table structure. 21 | 22 | ![qq20170220-2](https://cloud.githubusercontent.com/assets/1479100/23147949/cbf03e84-f81d-11e6-82b7-d7929c3033a0.png) 23 | 24 | ## Database command line 25 | 26 | Database command-line tool for web integration, currently supports `mysql`, `mongodb` and `redis`, visit `http://localhost/admin/helpers/terminal/database` to open. 27 | 28 | In the upper right corner of the `select` selection box to switch the database connection, and then at the bottom of the input box enter the corresponding database query statement and then enter, you can get the results of the query: `mysql`, `mongodb` and `redis`. 29 | 30 | ![qq20170220-3](https://cloud.githubusercontent.com/assets/1479100/23147951/ce08e5d6-f81d-11e6-8b20-605e8cd06167.png) 31 | 32 | The utility is identical to the database manipulation on the terminal, allowing you to run the supported queries for the selected database. 33 | 34 | ## artisan command line tool 35 | 36 | A web implementation of the `artisan` command for `Laravel` can be opened by running the artisan command on it and visiting `http://localhost/admin/helpers/terminal/artisan`. 37 | 38 | ![qq20170220-1](https://cloud.githubusercontent.com/assets/1479100/23147963/da8a5d30-f81d-11e6-97b9-239eea900ad3.png) 39 | 40 | 41 | ## Routing list 42 | 43 | This tool can be used to visually display all the routes in the system, including the route uri, methods and middleware, as well as querying routes. Visit `http://localhost/admin/helpers/routes` to open. 44 | 45 | ![helpers_routes](https://user-images.githubusercontent.com/1479100/30899066-e8bdd5ca-a390-11e7-809d-4ceccd0da27f.png) 46 | -------------------------------------------------------------------------------- /en-2.x/extension-theme.md: -------------------------------------------------------------------------------- 1 | # Theme development 2 | 3 | -------------------------------------------------------------------------------- /en-2.x/extension-upgrade.md: -------------------------------------------------------------------------------- 1 | # Extensions and upgrades -------------------------------------------------------------------------------- /en-2.x/extensions.md: -------------------------------------------------------------------------------- 1 | # Extensions 2 | 3 | | extensions | description | dcat-admin version | dcat-admin version 4 | ------------------------------------------------ | ---------------------------------------- | ----------------------------------- ----- 5 | | [dcat-page](https://github.com/jqhph/dcat-page) | A simple static site builder | * | | [dcat-page](https://github.com/jqhph/dcat-page) 6 | | The [editor](https://github.com/jqhph/dcat-admin-ueditor) | Baidu Online Editor | * | [edit](https://github.com/jqhph/dcat-admin-ueditor) 7 | | [gank](https://github.com/jqhph/dcat-admin-gank) | Trunk Camp |* | | [gank](https://github.com/jqhph/dcat-admin-gank) 8 | 9 | 10 | -------------------------------------------------------------------------------- /en-2.x/helpers.md: -------------------------------------------------------------------------------- 1 | # Development tools 2 | 3 | `Dcat Admin` provides a number of development tools to help developers improve development efficiency. 4 | If you need to disable the development tools, just set `app.debug` or `admin.helpers.enable` to `false` in the configuration file. 5 | 6 | 7 | ### Code generators 8 | 9 | The code generator can generate add, delete, redact, and check codes from the interface with one click. It supports generating add, delete, redact, and check codes from existing data tables. 10 | 11 | > If your development environment is not `windows`, please give `777` permission to the whole project, otherwise you may not be able to generate the file. 12 | 13 | 14 | ### Extension package management 15 | `Dcat Admin` supports visual management of extensions. As long as the extensions installed through `composer` can be seen in the management interface, the extensions can be enabled and imported through the interface, open the browser and visit `http://localhost:8000/admin/helpers/extensions` to use it. 16 | 17 | ### IDE autocomplete 18 | The `php artisan admin:ide-helper` command can generate IDE autocomplete files, which can generate hints for `Grid`, `Form`, `Show` and other functions. 19 | 20 | ### Icon 21 | Visit `http://localhost:8000/admin/helpers/icons` for a list of supported icons. 22 | 23 | -------------------------------------------------------------------------------- /en-2.x/laravel-octane.md: -------------------------------------------------------------------------------- 1 | # Laravel Octane 2 | 3 | [Laravel Octane](https://github.com/laravel/octane) is a project based on `Swoole/RoadRunner` driver that can improve the performance of `Laravel` framework, after installation it can significantly improve the performance of `Laravel` projects. 4 | 5 | `Dcat Admin` is compatible with the `Laravel Octane` environment, just add the following configuration to the configuration file `config/octane.php`. 6 | 7 | ```php 8 | 9 | 'listeners' => [ 10 | ... , 11 | 12 | RequestReceived::class => [ 13 | ... .Octane::prepareApplicationForNextOperation(), 14 | ... .Octane::prepareApplicationForNextRequest(), 15 | 16 | // Enable support for Dcat Admin 17 | Dcat\Admin\Octane\Listeners\FlushAdminState::class, 18 | class], 19 | 20 | ... 21 | ], 22 | ``` 23 | 24 | > [Laravel Octane](https://github.com/laravel/octane) is still in `beta` phase, for installation and more information about [Laravel Octane](https://github.com/laravel/octane) Please go to the documentation at https://github.com/laravel/octane for more information. 25 | 26 | -------------------------------------------------------------------------------- /en-2.x/menu.md: -------------------------------------------------------------------------------- 1 | # Menu 2 | 3 | The menus of `Dcat Admin` are stored on the datasheet `admin_menu` and can be managed in the background menu management page. 4 | 5 | ### Menu Permissions 6 | Each menu can be tied to a permission or role, or if not set it will be a public menu, visible to all accounts. 7 | 8 | 9 | The `admin.menu.bind_permission` configuration parameter allows you to set whether or not to allow bind permissions. 10 | > {tip} By default, a menu can bind up to one permission and one role. 11 | 12 | ### Menu translation 13 | Append the menu TITLE to the menu_titles index of your language file. For example, the "Workplace" TITLE: 14 | 15 | In `resources/lang/{current language}/admin.php` 16 | ```php 17 | ... 18 | 'menu_titles' => [ 19 | 'work_units' => 'Unidades de trabajo' 20 | ], 21 | ``` 22 | 23 | ### Menu cache 24 | The menu cache can be turned on or off through the `admin.menu.cache.enable` configuration parameter, it is recommended to turn it on. 25 | 26 | ### Add menu dynamically through Menu::add interface 27 | `Dcat Admin` also provides the ability to instantly add menus to the code by means of arrays. 28 | 29 | Add the following code to `app\Admin\bootstrap.php`: 30 | ```php 31 | add([ 37 | [ 38 | 'id' => '1', // This id just needs to be unique in the current array. 39 | 'title' => 'Test Menu', 40 | 'icon' => 'fa-file-text-o', 41 | 'uri' => '', 42 | 'parent_id' => 0, 43 | 'permission_id' => 'test', // Binding to permissions 44 | 'roles' => 'test-roles', // Binding to roles 45 | ], 46 | [ 47 | 'id' => '2', // This id just needs to be unique in the current array. 48 | 'title' => 'Test Menu 2', 49 | 'icon' => 'fa-file-text-o', 50 | 'uri' => 'test-menu2', 51 | 'parent_id' => '1', 52 | ], 53 | ]); 54 | }); 55 | 56 | ``` 57 | 58 | ### Why don't menus with no permissions automatically hide? 59 | 60 | This problem is because you don't bind permissions or roles to menus, just bind permissions or roles to menus that you want to show without permissions. 61 | 62 | 63 | -------------------------------------------------------------------------------- /en-2.x/model-form-init.md: -------------------------------------------------------------------------------- 1 | # Form initialization 2 | 3 | The callback function set by the `Form::resolving` method is triggered when the `Dcat\Admin\Form` class is instantiated. 4 | 5 | The callback function set by the `Form::composing` method is triggered when the `render()` method is called (when the page is rendered). 6 | 7 | Developers can change some of the settings or behavior of `Form` in these two events, for example, if they need to disable certain actions, they can add the following code to `app/Admin/bootstrap.php`. 8 | 9 | ```php 10 | use Dcat\Admin\Form; 11 | 12 | Form::resolving(function (Form $form) { 13 | 14 | $form->disableEditingCheck(); 15 | 16 | $form->disableCreatingCheck(); 17 | 18 | $form->disableViewCheck(); 19 | 20 | $form->tools(function (Form\Tools $tools) { 21 | $tools->disableDelete(); 22 | $tools->disableView(); 23 | $tools->disableList(); 24 | }); 25 | 26 | }); 27 | ``` 28 | This way you don't have to set it in the code of each controller. 29 | 30 | If you want to enable the setting in one of the forms after the global setting, for example, enable the checkbox that shows `Continue Editing`, call `$form->disableEditingCheck(false);` on the corresponding instance! -------------------------------------------------------------------------------- /en-2.x/model-form-trans.md: -------------------------------------------------------------------------------- 1 | # Form field translation 2 | 3 | All the places in the data form form where the fields are used will automatically read the translations from the language pack. 4 | 5 | > {tip} See [Multilingual](trans.md) for details on how to use the language package. 6 | 7 | ### Language package name 8 | If the controller is `UserProfileController`, the corresponding language package is `resources/lang/{current language}/user-profile.php` (needs to be converted to lower case strikethrough style). 9 | 10 | 11 | If you want to change the name of the language pack, you can do so in the following two ways 12 | 13 | Method 1 14 | ```php 15 | use Dcat\Admin\Http\Controllers\AdminController; 16 | 17 | class UserController extends AdminController 18 | { 19 | /** 20 | * Specify the translation file name 21 | * 22 | * @var string 23 | */ 24 | protected $translation = 'user1'; 25 | 26 | ... 27 | } 28 | ``` 29 | 30 | Method 2 31 | ```php 32 | use Dcat\Admin\Admin; 33 | 34 | Admin::translation('user1'); 35 | ``` 36 | 37 | 38 | ### Example 39 | Now suppose that the language package `resources/lang/zh_CN/user-profile.php` contains the following: 40 | ```php 41 | return [ 42 | 'fields' => [ 43 | 'name' => '名称', 44 | 'age' => '年龄', 45 | 'class' => '班级', 46 | ], 47 | ]; 48 | ``` 49 | 50 | The `Form` field set in the controller `UserProfileController` will automatically read the above translation: 51 | ```php 52 | // If you don't set labels, language package translations are used automatically 53 | $form->display('id'); 54 | $form->text('name'); 55 | $form->text('age'); 56 | $form->text('class'); 57 | ``` 58 | 59 | ### Public interpretation 60 | When the `admin_trans_field` function can't find the translation of a given field in the current controller, it looks for it in `global.php`. If some fields are present in many data tables, you can write those translations in the `resources/lang/{current language}/global.php` file. 61 | ```php 62 | return [ 63 | // Commonly used fields are placed in global.php and can be used by all controllers 64 | 'fields' => [ 65 | 'id' => 'ID', 66 | 'created_at' => '创建时间', 67 | 'updated_at' => '更新时间', 68 | ], 69 | ]; 70 | ``` 71 | 72 | -------------------------------------------------------------------------------- /en-2.x/model-grid-async.md: -------------------------------------------------------------------------------- 1 | # Asynchronous rendering of tables 2 | 3 | When the table on the page displays a particularly large amount of data (many columns and rows) and loads more components, there may be a lagging phenomenon, which can be effectively mitigated by using the table asynchronous rendering feature. 4 | 5 | 6 | ```php 7 | // Enable asynchronous rendering of tables 8 | $grid->async(); 9 | 10 | // Disable 11 | $grid->async(false); 12 | 13 | // Determine if the request is an asynchronous rendering request 14 | if ($grid->isAsyncRequest()) { 15 | ... 16 | } 17 | ``` 18 | 19 | > Note that there is no need to enable this feature if the page is not significantly stuttering. And if there are multiple data tables on the page, then this feature is also not available. 20 | 21 | When this feature is enabled, the table **toolbar** (`toolbar`) and below will be rendered asynchronously, in other words, the **toolbar** (`toolbar`) and above will only be refreshed once! You need to pay attention to any special effects during the actual coding process. 22 | -------------------------------------------------------------------------------- /en-2.x/model-grid-combination.md: -------------------------------------------------------------------------------- 1 | # Combination headers 2 | 3 | The `Grid::combine` method makes it easy to combine any two or more fields into a first-level table header. 4 | 5 | 6 | 7 | 8 | 9 | Example 10 | 11 | ```php 12 | protected function grid() 13 | { 14 | return Grid::make(new Report(), function (Grid $grid) { 15 | // The first parameter is the primary table header field name, the second field is the secondary table header field name, the secondary table header field is set to at least two 16 | $grid->combine('avgCost', ['avgMonthCost', 'avgQuarterCost', 'avgYearCost']); 17 | 18 | $grid->combine('avgVist', ['avgMonthVist', 'avgQuarterVist', 'avgYearVist']); 19 | 20 | // Set the style 21 | $grid->combine('top', ['topCost', 'topVist', 'topIncr'])->style('color:#1867c0'); 22 | 23 | $grid->column('content')->limit(50); 24 | $grid->column('cost')->sortable(); 25 | $grid->column('avgMonthCost'); 26 | $grid->column('avgQuarterCost')->setHeaderAttributes(['style' => 'color:#5b69bc']); 27 | $grid->column('avgYearCost'); 28 | $grid->column('avgMonthVist'); 29 | $grid->column('avgQuarterVist'); 30 | $grid->column('avgYearVist'); 31 | $grid->column('incrs'); 32 | $grid->column('avgVists'); 33 | $grid->column('topCost'); 34 | $grid->column('topVist'); 35 | $grid->column('topIncr'); 36 | $grid->column('date')->sortable(); 37 | 38 | }); 39 | } 40 | ``` 41 | 42 | -------------------------------------------------------------------------------- /en-2.x/model-grid-exporter.md: -------------------------------------------------------------------------------- 1 | # Custom export 2 | 3 | The dcat-admin data form supports exporting csv files by default. 4 | 5 | ```php 6 | getTable().'.csv'; 17 | 18 | $data = $this->getData(); 19 | 20 | $output = ''; 21 | 22 | $headers = [ 23 | 'Content-Encoding' => 'UTF-8', 24 | 'Content-Type' => 'text/csv;charset=UTF-8', 25 | 'Content-Disposition' => "attachment; filename=\"$filename\"", 26 | ]; 27 | 28 | response(rtrim($output, "\n"), 200, $headers)->send(); 29 | 30 | exit; 31 | } 32 | } 33 | ``` -------------------------------------------------------------------------------- /en-2.x/model-grid-header.md: -------------------------------------------------------------------------------- 1 | # Head and feet 2 | 3 | The data table supports filling the head and foot blocks as you wish. 4 | 5 | ```php 6 | $grid->header(function ($collection) { 7 | return 'header'; 8 | }); 9 | 10 | $grid->footer(function ($collection) { 11 | return 'footer'; 12 | }); 13 | ``` 14 | 15 | The parameter `$collection` of the closure function is `Illuminate\Support\Collection` class instance, which is the current page table data, the following is an example of the use of two different scenarios 16 | 17 | ## Head 18 | 19 | ```php 20 | $grid->header(function ($collection) use ($grid) { 21 | $query = Model::query(); 22 | 23 | // Get the table filter where the conditional array is traversed. 24 | $grid->model()->getQueries()->unique()->each(function ($value) use (&$query) { 25 | if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) { 26 | return; 27 | } 28 | 29 | $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []); 30 | }); 31 | 32 | // Identify statistical data 33 | $data = $query->get(); 34 | 35 | // Custom component 36 | return new Card($data); 37 | }); 38 | ``` 39 | 40 | Component implementation for custom header display 41 | ```php 42 | data = $data; 61 | } 62 | 63 | public function script() 64 | { 65 | return <<script()); 80 | 81 | return view('...', ['data' => $this->data])->render(); 82 | } 83 | } 84 | ``` 85 | 86 | 87 | ## Footer 88 | 89 | A more common scenario is to display statistics in the footer of a data form, such as adding revenue statistics to the footer of an order form, which can be implemented with the following code. 90 | 91 | ```php 92 | $grid->footer(function ($collection) use ($grid) { 93 | $query = Model::query(); 94 | 95 | // Get the table to filter the where condition array for iterations 96 | $grid->model()->getQueries()->unique()->each(function ($value) use (&$query) { 97 | if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) { 98 | return; 99 | } 100 | 101 | $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []); 102 | }); 103 | 104 | // Identifying statistics 105 | $data = $query->get(); 106 | 107 | return "
gross income : $data
"; 108 | }); 109 | ``` 110 | 111 | If there is a more complex footer that needs to be displayed, you can also use a view object or wrap it into a class. -------------------------------------------------------------------------------- /en-2.x/model-grid-selector.md: -------------------------------------------------------------------------------- 1 | # Filter for table specifications 2 | 3 | 4 | This feature is used to build a selection of specifications similar to Taobao or Jingdong products. 5 | 6 | 7 | 8 | 9 | 10 | 11 | ### Basic use 12 | 13 | 14 | > {tip} The second argument of `select` and `selectOne` method is selector `label`, which can be omitted, if omitted the translation of the translation file will be used automatically. 15 | 16 | 17 | As shown in the following code, assuming that the four values of the `brand` field correspond to four brands, the following way will build the specification selector of `brand`. 18 | 19 | ```php 20 | use Dcat\Admin\Grid; 21 | 22 | $grid->selector(function (Grid\Tools\Selector $selector) { 23 | $selector->select('brand', 'brands', [ 24 | 1 => 'Huawei', 25 | 2 => 'millet', 26 | 3 => 'OPPO', 27 | 4 => 'vivo', 28 | ]); 29 | }); 30 | ``` 31 | 32 | `select` method is multiple choice by default, click on the page to the right of each option of the plus sign, the query will add a query option for this field, if the field filter allows only one selection, use the `selectOne` method 33 | 34 | ```php 35 | $selector->selectOne('brand', 'brand', [ 36 | 1 => 'Huawei', 37 | 2 => 'millet', 38 | 3 => 'OPPO', 39 | 4 => 'vivo', 40 | ]); 41 | ``` 42 | 43 | ### Relational field lookup 44 | 45 | If [dcat/laravel-wherehasin](https://github.com/jqhph/laravel-wherehasin) is installed, the `whereHasIn` method is used preferentially for queries. 46 | 47 | ```php 48 | use Dcat\Admin\Grid; 49 | 50 | $grid->selector(function (Grid\Tools\Selector $selector) { 51 | $selector->select('brand.id', 'brands', [ 52 | 1 => 'Huawei', 53 | 2 => 'millet', 54 | 3 => 'OPPO', 55 | 4 => 'vivo', 56 | ]); 57 | }); 58 | ``` 59 | 60 | 61 | ### Custom queries 62 | The above method will use the value selected on the selector as the query condition, but in some cases where more flexible control over the query is needed, the query can be customized using the following method: 63 | 64 | ```php 65 | $selector->select('price', '价格', ['0-999', '1000-1999', '2000-2999'], function ($query, $value) { 66 | $between = [ 67 | [0, 999], 68 | [1000, 1999], 69 | [2000, 2999], 70 | ]; 71 | 72 | $value = current($value); 73 | 74 | $query->whereBetween('price', $between[$value]); 75 | }); 76 | ``` 77 | 78 | As shown above, an anonymous function is passed in as the fourth argument. Once price is selected, the logic in the anonymous function will be used to query the data, so that you can define any kind of query. 79 | -------------------------------------------------------------------------------- /en-2.x/model-grid-trans.md: -------------------------------------------------------------------------------- 1 | # Table field translation 2 | 3 | All the places in the data table where the fields are used will automatically read the translations from the language pack. 4 | 5 | > {tip} See [Multilingual](trans.md) for details on how to use the language package. 6 | 7 | ### Language package name 8 | If the controller is `UserProfileController`, the corresponding language package is `resources/lang/{current language}/user-profile.php` (needs to be converted to lower case strikethrough style). 9 | 10 | If you want to change the name of the language pack, you can do so in the following two ways 11 | 12 | Method 1 13 | ```php 14 | use Dcat\Admin\Http\Controllers\AdminController; 15 | 16 | class UserController extends AdminController 17 | { 18 | /** 19 | * Specify the name of the translation file 20 | * 21 | * @var string 22 | */ 23 | protected $translation = 'user1'; 24 | 25 | ... 26 | } 27 | ``` 28 | 29 | Method 2 30 | ```php 31 | use Dcat\Admin\Admin; 32 | 33 | Admin::translation('user1'); 34 | ``` 35 | 36 | 37 | 38 | 39 | ### Example 40 | Now suppose that the language package `resources/lang/zh_CN/user-profile.php` contains the following: 41 | ```php 42 | return [ 43 | 'fields' => [ 44 | 'name' => '名称', 45 | 'age' => '年龄', 46 | 'class' => '班级', 47 | ], 48 | ]; 49 | ``` 50 | 51 | The `Grid' field set in the controller `UserProfileController` will automatically read the above translation: 52 | ```php 53 | // Don't set labael to read translations automatically. 54 | $grid->id(); 55 | $grid->name; 56 | $grid->age; 57 | $grid->class; 58 | 59 | $grid->filter(function ($filter) { 60 | $filter->gt('age'); 61 | }); 62 | 63 | // The above code is equivalent to 64 | $grid->name('名称'); 65 | $grid->age('年龄'); 66 | 67 | // Can also be used like this 68 | $grid->id(admin_trans_field('id')); 69 | $grid->name(admin_trans_field('name')); 70 | $grid->age(admin_trans_field('age')); 71 | 72 | ``` 73 | 74 | ### Public interpretation 75 | When the `admin_trans_field` function can't find the translation of a given field in the current controller, it looks for it in `global.php`. If some fields are present in many data tables, you can write those translations in the `resources/lang/{current language}/global.php` file. 76 | ```php 77 | return [ 78 | // Commonly used fields are placed in global.php and can be used by all controllers. 79 | 'fields' => [ 80 | 'id' => 'ID', 81 | 'created_at' => '创建时间', 82 | 'updated_at' => '更新时间', 83 | ], 84 | ]; 85 | ``` 86 | 87 | -------------------------------------------------------------------------------- /en-2.x/model-json.md: -------------------------------------------------------------------------------- 1 | # JSON format field handling 2 | 3 | The `dcat-admin` form provides the following components to handle `JSON` formatted fields, which are convenient for handling `JOSN` formatted objects, 1D arrays, 2D arrays, etc. 4 | 5 | 6 | ## KeyValue object (keyValue) 7 | 8 | ![]({{public}}/assets/img/screenshots/key-value.png) 9 | 10 | If your field stores a variable `key` in the `{"field": "value"}` format, you can use the `keyValue` component: 11 | 12 | ```php 13 | $form->keyValue('column_name'); 14 | 15 | // Set the validation rule 16 | $form->keyValue('column_name')->rules('required|min:5'); 17 | ``` 18 | 19 | Custom key names and translations of key titles 20 | 21 | ```php 22 | $form->keyValue(...) ->setKeyLabel('KeyName')->setValueLabel('KeyValue'); 23 | ``` 24 | 25 | ## Fixed key-value objects (embeds) 26 | 27 | ![]({{public}}/assets/img/screenshots/embeds.png) 28 | 29 | Used to process `mysql`'s `JSON` type field data or `mongodb`'s `object` type data, or store multiple `field` data values as `JSON` strings in `mysql`'s string type fields. 30 | 31 | Applies to fields of type `JSON` with a fixed key value 32 | 33 | ```php 34 | $form->embeds('column_name', function ($form) { 35 | 36 | $form->text('key1')->required(); 37 | $form->email('key2')->required(); 38 | $form->datetime('key3'); 39 | 40 | $form->dateRange('key4', 'key5', 'scope')->rules('required'); 41 | })->saving(funtion ($v) { 42 | // Converted to json format for storage 43 | return json_encode($v); 44 | }); 45 | 46 | // Custom TITLE 47 | $form->embeds('column_name', 'Field TITLE', function ($form) { 48 | ... 49 | }); 50 | ``` 51 | 52 | The method calls for building form elements inside the callback function are the same as outside. 53 | 54 | ## one-dimensional array (list) 55 | 56 | ![]({{public}}/assets/img/screenshots/form-list.png) 57 | 58 | If your field is used to store a one-dimensional array of `["foo", "Bar"]` format, you can use the `list` component: 59 | 60 | ```php 61 | $form->list('column_name'); 62 | 63 | // Setting the validation rule 64 | $form->list('column_name')->rules('required|min:5'); 65 | 66 | // Set the maximum and minimum number of elements 67 | $form->list('column_name')->max(10)->min(5); 68 | ``` 69 | 70 | ## Two-dimensional array (table) 71 | 72 | ![]({{public}}/assets/img/screenshots/form-table.png) 73 | 74 | If a field stores a two-dimensional array in `json` format, the `table` form component can be used for fast editing: 75 | 76 | ```php 77 | $form->table('column_name', function ($table) { 78 | $table->text('key'); 79 | $table->text('value'); 80 | $table->textarea('desc'); 81 | })->saving(function ($v) { 82 | return json_encode($v); 83 | }); 84 | ``` 85 | 86 | This component is similar to the `hasMany` component, but is used to handle the case of a single field, for simple two-dimensional data. 87 | 88 | 89 | ## Two-dimensional arrays (array) 90 | 91 | ![]({{public}}/assets/img/screenshots/has-many.png) 92 | 93 | If a field stores a two-dimensional array in `json` format, and there are more fields, you can use the `array` form component for fast editing: 94 | 95 | ```php 96 | $form->array('column_name', function ($table) { 97 | $table->text('key'); 98 | $table->text('value'); 99 | $table->textarea('desc'); 100 | })->saveAsJson(); 101 | ``` 102 | -------------------------------------------------------------------------------- /en-2.x/model-show-extend.md: -------------------------------------------------------------------------------- 1 | # Detail field display expansion 2 | 3 | This feature is used to extend the detail field display, in cases where the built-in display method is not sufficient. 4 | 5 | First define the extension class: 6 | 7 | ```php 8 | value); 23 | } 24 | } 25 | ``` 26 | Then register the extension class in `app/Admin/bootstrap.php` 27 | 28 | ```php 29 | use Dcat\Admin\Show\Field; 30 | use App\Admin\Extensions\Show\UnSerialize; 31 | 32 | Field::extend('unserialize', UnSerialize::class); 33 | ``` 34 | Then use this extension in the controller 35 | 36 | ```php 37 | $show->column()->unserialize('xxx'); 38 | ``` 39 | Parameters passed into the unserialize() method are passed sequentially into the UnSerialize::render() method. 40 | 41 | Several common attributes can be found in the parent class `Dcat\Admin\Show\AbstractField` 42 | 43 | ```php 44 | /** 45 | * Field value. 46 | * 47 | * @var mixed 48 | */ 49 | protected $value; 50 | 51 | /** 52 | * Current field model. 53 | * 54 | * @var Fluent 55 | */ 56 | protected $model; 57 | 58 | /** 59 | * If this field show with a border. 60 | * 61 | * @var bool 62 | */ 63 | public $border = true; 64 | 65 | /** 66 | * If this field show escaped contents. 67 | * 68 | * @var bool 69 | */ 70 | public $escape = true; 71 | ``` 72 | Where `$value` and `$model` are the current field value and the current details of the data, in the `render()` method can be used to get the data you want. 73 | 74 | `$border` is used to control whether the current display needs a border, `$escape` is used to set the current display to not HTML escape. -------------------------------------------------------------------------------- /en-2.x/model-show-init.md: -------------------------------------------------------------------------------- 1 | # Data detail initialization 2 | 3 | The callback function set through the `Show::resolving` method is triggered when the `Dcat\Admin\Show` class is instantiated. 4 | 5 | The callback function set by the `Show::composing` method is triggered when the `render()` method is called. 6 | 7 | Developers can change some of the settings or behavior of `Show` in these two events, for example, if they need to disable certain actions, they can add the following code to `app/Admin/bootstrap.php`. 8 | 9 | ```php 10 | use Dcat\Admin\Show; 11 | 12 | Show::resolving(function (Show $show) { 13 | 14 | $show->showQuickEdit(); 15 | 16 | }); 17 | ``` 18 | -------------------------------------------------------------------------------- /en-2.x/model-show-trans.md: -------------------------------------------------------------------------------- 1 | # Data detail field translation 2 | 3 | The use of data table field translations is essentially the same as the use of data table field translations, see [data table field translations] (model-grid-trans.md). -------------------------------------------------------------------------------- /en-2.x/update.md: -------------------------------------------------------------------------------- 1 | # Version upgrade instructions 2 | 3 | 4 | ### Description 5 | 6 | The release of `Dcat Admin` will take into account the release strategy of the mainstream `web framework` to minimize the impact of version upgrades, minor versions and patches **never** contain non-compatibility changes; we will also provide an update log detailing the changes and possible impact of the new version. 7 | 8 | 9 | 10 | 11 | ### Upgrade command 12 | upgrade command 13 | ```bash 14 | composer update dcat/laravel-admin 15 | ``` 16 | 17 | After successful upgrade, you need to run ``admin:update`` to republish the language pack, configuration files, front-end static resources and other files, and then **clean the browser cache** 18 | 19 | ```bash 20 | # Publish language packs, configuration files, front-end static resources, data migration files, etc. 21 | php artisan admin:update 22 | ``` 23 | 24 | Running ``admin:update`` is equivalent to running 25 | 26 | ```bash 27 | php artisan admin:publish --assets --migrations --lang --force 28 | php artisan migrate 29 | ``` 30 | 31 | #### publish file command 32 | 33 | > After running ``admin:update`'' you don't usually need to run the ``admin:publish`'' command 34 | 35 | ```bash 36 | php artisan admin:publish --force 37 | ``` 38 | 39 | Only language pack updates 40 | ```bash 41 | php artisan admin:publish --force --lang 42 | ``` 43 | 44 | Update Configuration Files Only 45 | ```bash 46 | php artisan admin:publish --force --config 47 | ``` 48 | 49 | 50 | Only front-end static resources are updated 51 | ```bash 52 | php artisan admin:publish --force --assets 53 | ``` 54 | 55 | Update only the database migration file (this generally does not need to be updated) 56 | ```bash 57 | php artisan admin:publish --force --migrations 58 | ``` -------------------------------------------------------------------------------- /en-2.x/widgets-alert.md: -------------------------------------------------------------------------------- 1 | # Warning boxes 2 | 3 | ### Alert 4 | Basic Usage 5 | 6 | ```php 7 | success(); 15 | $alert->danger(); 16 | $alert->info(); 17 | $alert->warning(); 18 | 19 | // icon 20 | $alert->icon('feather icon-x'); 21 | 22 | // Removable buttons 23 | $alert->removable(); 24 | ``` 25 | result 26 | 27 | 28 | 29 | 30 | ### Callout 31 | 32 | ```php 33 | light(); 41 | $callout->primary(); 42 | 43 | // Removable buttons 44 | $callout->removable(); 45 | ``` 46 | 47 | result 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /en-2.x/widgets-box.md: -------------------------------------------------------------------------------- 1 | # Cards 2 | 3 | ## Card 4 | 5 | ```php 6 | padding('0 15px 0 12px'); 18 | 19 | // Set tool buttons 20 | $card->tool(''); 21 | 22 | // Set footer content 23 | $card->footer(view('...')); 24 | ``` 25 | 26 | ## Box 27 | 28 | ```php 29 | padding('0 15px 0 12px'); 38 | 39 | // Set tool buttons 40 | $box->tool(''); 41 | 42 | // Setting the shrink button 43 | $box->collapsable(); 44 | 45 | // Set the remove button 46 | $box->removable(); 47 | ``` -------------------------------------------------------------------------------- /en-2.x/widgets-dialog-form.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/en-2.x/widgets-dialog-form.md -------------------------------------------------------------------------------- /en-2.x/widgets-js.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/en-2.x/widgets-js.md -------------------------------------------------------------------------------- /en-2.x/widgets-markdown.md: -------------------------------------------------------------------------------- 1 | # Markdown 2 | 3 | Basic Usage 4 | 5 | ```php 6 | body(Card::make( 17 | Markdown::make('The content of your markdown article') 18 | )); 19 | } 20 | } 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /en-2.x/widgets-modal.md: -------------------------------------------------------------------------------- 1 | # Modal windows (Modal) 2 | 3 | Basic use 4 | 5 | 6 | ```php 7 | use Dcat\Admin\Widgets\Modal; 8 | 9 | $modal = Modal::make() 10 | ->lg() 11 | ->title('TITLE') 12 | ->body(view(...)) 13 | ->button(''); 14 | 15 | return view(..., ['modal' => $modal]); 16 | ``` 17 | 18 | ## Functionality 19 | 20 | ### TITLE (title) 21 | 22 | Set pop-up window TITLE 23 | 24 | ```php 25 | $modal->title('TITLE'); 26 | ``` 27 | 28 | ### content (body) 29 | 30 | Set popup contents, this method accepts a parameter that allows incoming values of type `string`, `Closure`, `Illuminate\Contracts\Support\Renderable` and `Dcat\Admin\Contracts\LazyRenderable`. 31 | 32 | ```php 33 | // pass a string 34 | $modal->body('字符串'); 35 | 36 | // pass a closure, note that the closure must return a string type value or a null value 37 | $modal->body(function () { 38 | return view(...)->render(); 39 | }); 40 | 41 | // Passing in Renderable 42 | use Dcat\Admin\Widgets\ 43 | 44 | $modal->body(view(...)); 45 | $modal->body(Card::make()); 46 | 47 | // Passing in LazyRenderable 48 | $modal->body(PostTable::make()); 49 | ``` 50 | 51 | ### Bottom content (footer) 52 | Set the content at the bottom of the popup window, this method accepts a parameter that allows the passing of `string`, `Closure`, `Illuminate\Contracts\Support\Renderable` and `Dcat\Admin\Contracts\LazyRenderable` type values, Usage as above. 53 | 54 | ```php 55 | $modal->footer('字符串'); 56 | 57 | $modal->footer(view(...)); 58 | ``` 59 | 60 | ### size 61 | 62 | Default `500px` 63 | 64 | ```php 65 | // 800px 66 | $modal->lg(); 67 | 68 | // 1140px 69 | $modal->xl(); 70 | ``` 71 | 72 | ### Buttons (button) 73 | 74 | Set button 75 | 76 | ### Event listening 77 | 78 | Supported Events 79 | 80 | - `onShow` Popup Show Event 81 | - `onShown` Pop-up window shows event 82 | - `onHide` Popup hide event 83 | - `onHidden` Pop-ups with hidden event 84 | 85 | UsageExample 86 | ```php 87 | use Dcat\Admin\Admin; 88 | 89 | $modal->onShow( 90 | <<onHide( 96 | <<xl() 109 | ->centered() // Set the pop-up window to be vertically centered 110 | ->title(...) 111 | ->body(...); 112 | ``` 113 | 114 | ### Scrollable content (scrollable) 115 | 116 | Set the content of the pop-up window to be scrollable 117 | 118 | ```php 119 | $modal = Modal::make() 120 | ->xl() 121 | ->scrollable() // Set the content of the pop-up window to be scrollable 122 | ->title(...) 123 | ->body(...); 124 | ``` 125 | 126 | 127 | 128 | 129 | ## Form pop-up 130 | 131 | Reference [tools-form - popups](widgets-form.md#modal) 132 | 133 | -------------------------------------------------------------------------------- /en-2.x/widgets-navbar.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/en-2.x/widgets-navbar.md -------------------------------------------------------------------------------- /en-2.x/widgets-tab.md: -------------------------------------------------------------------------------- 1 | # Tabs 2 | 3 | The `tab` tab can be quickly constructed using the `Dcat\Admin\Widgets\Tab` method. 4 | 5 | ### Basic Usage 6 | 7 | ```php 8 | add('Tab 1', view('...'), true); 16 | $tab->add('Option 2', 'html'); 17 | // Adding tab links 18 | $tab->addLink('skip link', 'http://xxx'); 19 | 20 | return $content->body($tab->withCard()); 21 | ``` 22 | 23 | ### Switching display mode 24 | 25 | ```php 26 | // theme color 27 | $tab = Tab::make()->theme(); 28 | ``` 29 | 30 | ### vertically (vertical) 31 | 32 | The `vertical` method allows the tab TITLE column to be aligned vertically. 33 | 34 | ```php 35 | add('Tab 1', view('...')); 42 | $tab->add('Option 2', 'html'); 43 | 44 | return $content->body($tab->withCard()->vertical()); 45 | ``` 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /en-2.x/widgets-table.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcat-admin/docs/cb535380935eacc722a190ca90735f3ea5c3afd6/en-2.x/widgets-table.md -------------------------------------------------------------------------------- /en-2.x/widgets-tooltip.md: -------------------------------------------------------------------------------- 1 | # Tooltips 2 | Basic Usage 3 | 4 | ```php 5 | title('I'm the info'); 16 | 17 | return $content->body(new Card( 18 | << 20 | 21 | 22 | HTML 23 | )); 24 | } 25 | } 26 | ``` 27 | result 28 | 29 | 30 | --------------------------------------------------------------------------------