|
@@ -364,23 +364,31 @@ class FormService implements FormServiceInterface
|
|
|
$total = $query->count();
|
|
|
|
|
|
// 获取分页数据
|
|
|
- $list = $query->select($globalTableFields->pluck('field_name')->toArray())
|
|
|
- ->orderBy('id', 'desc')
|
|
|
- ->offset(($page - 1) * $pageSize)
|
|
|
- ->limit($pageSize)
|
|
|
- ->get();
|
|
|
+ $list = $query->select($globalTableFields->pluck('field_name')->toArray())
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
+ ->offset(($page - 1) * $pageSize)
|
|
|
+ ->limit($pageSize)
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ // 转换字符串数组为实际数组
|
|
|
+ $list->transform(function ($item) use ($globalTableFields) {
|
|
|
+ foreach ($globalTableFields as $field) {
|
|
|
+ $fieldName = $field->field_name;
|
|
|
+ if (isset($item->$fieldName) && is_string($item->$fieldName)) {
|
|
|
+ // 尝试解析JSON格式的字符串
|
|
|
+ $decoded = json_decode($item->$fieldName, true);
|
|
|
+ if (json_last_error() === JSON_ERROR_NONE) {
|
|
|
+ $item->$fieldName = $decoded;
|
|
|
+ }
|
|
|
+ // 如果是简单的逗号分隔字符串,也可以转换为数组
|
|
|
+ elseif (strpos($item->$fieldName, ',') !== false) {
|
|
|
+ $item->$fieldName = array_map('trim', explode(',', $item->$fieldName));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $item;
|
|
|
+ });
|
|
|
|
|
|
- // 处理返回数据,将field_name替换为title
|
|
|
-// $list = $list->map(function($item) use ($globalTableFields) {
|
|
|
-// $newItem = new \stdClass();
|
|
|
-// foreach ($globalTableFields as $field) {
|
|
|
-// $fieldName = $field->field_name;
|
|
|
-// if (isset($item->$fieldName)) {
|
|
|
-// $newItem->{$field->title} = $item->$fieldName;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return $newItem;
|
|
|
-// });
|
|
|
|
|
|
return Result::success([
|
|
|
'tableFields' => $globalTableFields,
|