This commit is contained in:
2020-02-18 17:52:26 +08:00
parent 4c036db815
commit e7cf4849c9
6 changed files with 87 additions and 20 deletions

View File

@@ -59,23 +59,26 @@ class Config extends Model {
private static function parse($type, $value) {
$data = [];
switch ($type) {
case 'textarea': //解析数组
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
if (strpos($value, ':')) {
foreach ($array as $val) {
$list = explode(':', $val);
if (isset($list[2])) {
$data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1], 'other' => $list[2]];
} else {
$data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1]];
case 'textarea': //解析数组
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
if (strpos($value, ':')) {
foreach ($array as $val) {
$list = explode(':', $val);
if (isset($list[2])) {
$data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1], 'other' => $list[2]];
} else {
$data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1]];
}
}
} else {
foreach ($array as $key => $val) {
$data[] = ['key' => $key, 'value' => $val, 'label' => $val];
}
}
} else {
foreach ($array as $key => $val) {
$data[] = ['key' => $key, 'value' => $val, 'label' => $val];
}
}
break;
break;
default:
return $value;
break;
}
return $data;
}