|
|
@@ -2511,11 +2511,26 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$cat_num = 0;
|
|
|
$row_width = [];
|
|
|
$map = [];
|
|
|
+
|
|
|
+ // 按 column_num 分组并取每组最小 width
|
|
|
+ $col_width = [];
|
|
|
+ foreach ($component as $item) {
|
|
|
+ $col = $item['column_num']-1;
|
|
|
+ if (!isset($grouped[$col]) || $item['width'] < $grouped[$col]['width']) {
|
|
|
+ $column_width[$col] = $item['width'];
|
|
|
+ // $column_width[$col][$item['line_num']-1] = $item['line_num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // $grouped 即为分组后各组 width 最小的记录
|
|
|
+ // return Result::success($column_width);
|
|
|
if(count($component) == $sector_type_info['component_num']){
|
|
|
foreach($component as $key => $val){
|
|
|
if(in_array($val['type'],[23,24])){
|
|
|
$cat_num = $cat_num + 2;
|
|
|
}
|
|
|
+ if(in_array($val['type'],[7,14])){
|
|
|
+ $cat_num = $cat_num + 1;
|
|
|
+ }
|
|
|
if(!isset($map[$val['column_num'] - 1]['col_data']['row_num'])){
|
|
|
$row_num = 1;
|
|
|
$map[$val['column_num'] - 1]['col_data']['row_num'] = $row_num;
|
|
|
@@ -2523,24 +2538,86 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$map[$val['column_num'] - 1]['col_data']['row_num'] = $row_num +1;
|
|
|
}
|
|
|
// 原代码使用 $sector_type['width'] 有误,应该使用 $sector_type_info
|
|
|
- $width = number_format((($val['width'] / $sector_type_info['width']) * 100 - 1.5), 2);
|
|
|
+ // $width = number_format((($val['width'] / $sector_type_info['width']) * 100 - 1.5), 2);
|
|
|
$height = number_format((($val['height'] / $sector_type_info['height']) * 100 - 2.5), 2);
|
|
|
+ $col_width = $column_width[$val['column_num'] - 1];
|
|
|
+
|
|
|
+ $width = number_format((($val['width'] / $col_width) * 100 - 1.5), 2);
|
|
|
+ $col_width = number_format((($col_width / $sector_type_info['width']) * 100 - 1.5), 2);
|
|
|
$row_key = intval($val['line_num'] - 1);
|
|
|
$map[$val['column_num'] - 1]['col_data']['row_data'][$row_key] = [
|
|
|
'row_width' => $width.'%',
|
|
|
'row_height' => $height.'%',
|
|
|
'component_sort' => $val['sort_id'],
|
|
|
];
|
|
|
- $map[$val['column_num'] - 1]['col_data']['col_width'] = $width.'%';
|
|
|
+ $map[$val['column_num'] - 1]['col_data']['col_width'] = $col_width.'%';
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ // 补全缺失的行,确保row_data是连续的索引数组
|
|
|
+ if (!empty($map)) {
|
|
|
+ // 为每一列补全缺失的行
|
|
|
+ for ($col_index = 0; $col_index < count($map); $col_index++) {
|
|
|
+ if (isset($map[$col_index]['col_data']['row_data'])) {
|
|
|
+ $row_data = &$map[$col_index]['col_data']['row_data'];
|
|
|
+
|
|
|
+ // 检查当前行数据是否是连续的索引数组
|
|
|
+ $rows = array_keys($row_data);
|
|
|
+ if (empty($rows)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否存在断连
|
|
|
+ $min_row = min($rows);
|
|
|
+ $max_row = max($rows);
|
|
|
+ $is_continuous = (count($rows) === $max_row - $min_row + 1);
|
|
|
+
|
|
|
+ // 只有当行号不连续时才进行补全
|
|
|
+ if (!$is_continuous || $min_row > 0) {
|
|
|
+ $temp_row_data = [];
|
|
|
+
|
|
|
+ // 遍历从0到最大行号的所有行
|
|
|
+ for ($row_index = 0; $row_index <= $max_row; $row_index++) {
|
|
|
+ if (isset($row_data[$row_index])) {
|
|
|
+ // 保留原有行数据
|
|
|
+ $temp_row_data[$row_index] = $row_data[$row_index];
|
|
|
+ } else {
|
|
|
+ // 补全新行数据
|
|
|
+ $temp_row_data[$row_index] = [
|
|
|
+ 'row_width' => '1%', // 固定为1%
|
|
|
+ 'row_height' => '30.83%', // 默认高度
|
|
|
+ 'component_sort' => null // 补全的行没有component_sort
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 如果不是第一列,尝试从上一列获取高度
|
|
|
+ if ($col_index > 0 && isset($map[$col_index - 1]['col_data']['row_data'][$row_index])) {
|
|
|
+ $temp_row_data[$row_index]['row_height'] = $map[$col_index - 1]['col_data']['row_data'][$row_index]['row_height'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新为连续的索引数组
|
|
|
+ $map[$col_index]['col_data']['row_data'] = array_values($temp_row_data);
|
|
|
+ // 更新row_num
|
|
|
+ $map[$col_index]['col_data']['row_num'] = count($temp_row_data);
|
|
|
+ } elseif (!is_array(reset($row_data))) {
|
|
|
+ // 如果是关联数组但键是连续的,转换为索引数组
|
|
|
+ ksort($row_data);
|
|
|
+ $map[$col_index]['col_data']['row_data'] = array_values($row_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return ['map_json'=>$map ?? [],
|
|
|
- 'component'=>count($component),
|
|
|
- 'row_num'=>$row_num ?? 0,
|
|
|
- 'cat_num'=>$cat_num ?? 0,
|
|
|
- 'component_info'=>$component,];
|
|
|
+ $map_data = [
|
|
|
+ 'map_json'=>$map ?? [],
|
|
|
+ 'component'=>count($component),
|
|
|
+ 'row_num'=>$row_num ?? 0,
|
|
|
+ 'cat_num'=>$cat_num ?? 0,
|
|
|
+ 'component_info'=>$component,
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $map_data;
|
|
|
}
|
|
|
/**
|
|
|
* 通栏版式管理-修改通栏版式
|