项目作者: ichynul

项目描述 :
[laravel-admin]增加/修改配置项,管理网站的配置(Add / edit configuration, Manage site configuration)
高级语言: PHP
项目地址: git://github.com/ichynul/configx.git
创建时间: 2018-12-09T08:46:37Z
项目社区:https://github.com/ichynul/configx

开源协议:MIT License

下载


laravel-admin configx

Installation

need to install laravel-admin-ext/config first, see https://github.com/laravel-admin-extensions/config

Then run :

  1. $ composer require ichynul/configx

Then run:

  1. $ php artisan admin:import configx

Add a tabs config in config/admin.php:

  1. 'extensions' => [
  2. 'configx' => [
  3. // Set to `false` if you want to disable this extension
  4. 'enable' => true,
  5. 'tabs' => [
  6. 'base' => '基本设置',
  7. 'shop' => '店铺设置',
  8. 'uplaod' => '上传设置',
  9. 'image' => '' // if tab name is empty, get from trans : trans('admin.configx.tabs.image'); tab名称留空则从翻译中获取
  10. ],
  11. // Whether check group permissions.
  12. //if (!Admin::user()->can('confix.tab.base')) {/*hide base tab*/ } .
  13. 'check_permission' => false,
  14. 'break_when_errors' => false // do not save anything if have errors
  15. ],
  16. ],

Usage

Open http://your-host/admin/configx/edit

Demo

You can click “+” to config tabs :

add an new config key

step 1 Select config type from ['base']

step 2 Select form-element type from ['normal', 'date', 'time', 'datetime', 'image', 'yes_or_no', 'number', 'rate', 'editor', 'radio_group' ,'checkbox_group', 'select']… and so on

step 3 If you selected form-element type is ['radio_group' ,'checkbox_group', 'select'] ,you need inupt [options] :

just text:

  1. text1
  2. text2
  3. ...

and key-text:

  1. key1 : text1
  2. key2 : text2
  3. ...

or load from ulr:

options_url:/api/mydata

If you selected form-element type is textarea , you can config it rows:3 , default is 5.

If you selected form-element type is table, rows / cols is needed :

base.some_key

  1. rows: 4
  2. cols: 4

This wiil build a table like below :

  1. /*
  2. |-------------------------------------------------------------------------------------
  3. | r_label\ c_labe | c_label1 | c_label2 | c_label3 | ⬅Col labels
  4. |-------------------------------------------------------------------------------------
  5. | r_label1 | base.some_key_1_1 | base.some_key_1_2 | base.some_key_1_3 |
  6. |-------------------------------------------------------------------------------------
  7. | r_label2 | base.some_key_2_1 | base.some_key_2_2 | base.some_key_2_3 |
  8. |-------------------------------------------------------------------------------------
  9. | r_label3 | base.some_key_3_1 | base.some_key_3_2 | base.some_key_3_3 |
  10. |-------------------------------------------------------------------------------------
  11. Row labels
  12. You can edit labels as you want.
  13. Each <td> has a key , base.some_key_[0]_[0] to base.some_key_[rows-1]_[cols-1] . (from 0 to length -1 )
  14. So, you can chang a label <td> to input :
  15. |-------------------------------------------------------------------------------------
  16. | r_label\ c_labe | c_label1 | c_label2 | base.some_key_0_3 | ⬅ [c_label3] change to [base.some_key_0_3]
  17. |------------------------------------------------------------------------------------- , we can input here .
  18. | r_label1 | base.some_key_1_1 | base.some_key_1_2 | base.some_key_1_3 | (可以把label 换成输入元素)
  19. |-------------------------------------------------------------------------------------
  20. | r_label2 | base.some_key_2_1 | base.some_key_2_2 | base.some_key_2_3 |
  21. |-------------------------------------------------------------------------------------
  22. | trans.sometext | base.some_key_3_1 | hello world! | base.some_key_3_3 |
  23. |-------------------------------------------------------------------------------------
  24. ↑ ↑
  25. ↑ [base.some_key_3_2] change to [hello world!]
  26. ↑ , we can not input here any more ,
  27. ↑ it wiil just show label text 'hello world!' .
  28. ↑ (也可以把输入元素换成仅显示文字)
  29. get text from trans
  30. trans("admin.configx.base.some_key.sometext")
  31. 显示文字时可以从翻译获取文字,样式 `trans.sometext`
  32. 其中 sometext 为翻译的key
  33. note : if text = key or text = '' ,render as input form element , otherwise just show the text you leave.
  34. //if text is trans.sometext , get from trans : trans("admin.configx.{$tab}.{$tablekey}.{$sometext}")
  35. 总结 : 如果输入的字符串与td默认key一样或输入的字符串为空,这个位置将是一个可输入的表单元素,否则就显示原样你输入的字符串 .
  36. */
  37. Add a lang config in `resources/lang/{zh-CN}/admin.php`
  38. ```php
  39. 'configx' => [
  40. 'new_config_type' => '配置类型',
  41. 'new_config_key' => '配置key',
  42. 'new_config_name' => '配置名称',
  43. 'new_config_element' => '配置表单元素',
  44. 'new_config_help' => '配置help',
  45. 'new_config_options' => '配置扩展项',
  46. 'header' => '网站设置',
  47. 'desc' => '网站设置设置',
  48. 'backup' => '备份',
  49. 'element' => [
  50. 'normal' => '默认',
  51. 'textarea' => '文本域',
  52. 'date' => '日期',
  53. 'time' => '时间',
  54. 'datetime' => '日期时间',
  55. 'password' => '密码',
  56. 'image' => '图片',
  57. 'multiple_image' => '多图',
  58. 'file' => '文件',
  59. 'multiple_file' => '多文件',
  60. 'yes_or_no' => '是或否',
  61. 'editor' => '编辑器',
  62. 'radio_group' => '单选框组',
  63. 'checkbox_group' => '多选框组',
  64. 'number' => '数字',
  65. 'rate' => '比例',
  66. 'select' => '下拉框',
  67. 'tags' => '标签',
  68. 'icon' => '图标',
  69. 'color' => '颜色',
  70. 'table' =>'表格',
  71. 'listbox' => '左右多选框',
  72. 'multiple_select' => '下拉多选',
  73. 'map' => '地图'
  74. ],
  75. ],
  76. 'yes' => '是',
  77. 'no' => '否'

if you need add a new config tab, chang it in config/admin.php.

After add config in the panel, use config($key) to get value you configured.

License


Licensed under The MIT License (MIT).