Config.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\common\model;
  12. use think\Model;
  13. class Config extends Model{
  14. /**
  15. * 读取配置类型
  16. * @return array
  17. */
  18. public static function getTypeList()
  19. {
  20. $typeList = [
  21. 'text' => __('单行文本'),
  22. 'textarea' => __('多行文本'),
  23. 'password' => __('密码'),
  24. 'editor' => __('富文本'),
  25. 'number' => __('数字'),
  26. 'date' => __('日期'),
  27. 'dateange' => __('日期区间'),
  28. 'time' => __('时间'),
  29. 'timerange' => __('时间区间'),
  30. 'select' => __('下拉列表'),
  31. 'selects' => __('下拉列表(多选)'),
  32. 'image' => __('图片'),
  33. 'images' => __('多张图片'),
  34. 'file' => __('文件'),
  35. 'files' => __('多个文件'),
  36. 'switch' => __('开关'),
  37. 'radio' => __('单项选择'),
  38. 'checkbox' => __('多项选择'),
  39. 'selectpage' => __('关联表'),
  40. 'selectpages' => __('关联表(多选)'),
  41. 'json' => __('JSON'),
  42. 'array' => __('数组,以英文逗号(,)隔开')
  43. ];
  44. return $typeList;
  45. }
  46. public function getValueAttr(string $data)
  47. {
  48. if(!$data){
  49. return $data;
  50. }
  51. //判断data是否是json数据类型
  52. if (str_starts_with($data, '{') && str_ends_with($data, '}')) {
  53. return json_decode($data, true);
  54. }
  55. if(str_starts_with($data, '[') && str_ends_with($data, ']')){
  56. return json_decode($data, true);
  57. }
  58. return $data;
  59. }
  60. public function getExtendAttr(string $data)
  61. {
  62. if(!$data){
  63. return $data;
  64. }
  65. //判断data是否是json数据类型
  66. if (str_starts_with($data, '{') && str_ends_with($data, '}')) {
  67. return json_decode($data, true);
  68. }
  69. if(str_starts_with($data, '[') && str_ends_with($data, ']')){
  70. return json_decode($data, true);
  71. }
  72. return $data;
  73. }
  74. }