Config.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ];
  43. return $typeList;
  44. }
  45. public function getValueAttr(string $data)
  46. {
  47. if(!$data){
  48. return $data;
  49. }
  50. //判断data是否是json数据类型
  51. if (str_starts_with($data, '{') && str_ends_with($data, '}')) {
  52. return json_decode($data, true);
  53. }
  54. if(str_starts_with($data, '[') && str_ends_with($data, ']')){
  55. return json_decode($data, true);
  56. }
  57. return $data;
  58. }
  59. public function getExtendAttr(string $data)
  60. {
  61. if(!$data){
  62. return $data;
  63. }
  64. //判断data是否是json数据类型
  65. if (str_starts_with($data, '{') && str_ends_with($data, '}')) {
  66. return json_decode($data, true);
  67. }
  68. if(str_starts_with($data, '[') && str_ends_with($data, ']')){
  69. return json_decode($data, true);
  70. }
  71. return $data;
  72. }
  73. }