@@ -34,16 +34,31 @@ public function index()
34
34
$ table ->cols ->filter (fn ($ col ) => empty ($ col ->hide_in_search ))->column ('data_index ' ),
35
35
['filter ' , 'sorter ' ]
36
36
), 'get ' );
37
+
37
38
$ total = $ this ->model ->withSearch (array_keys ($ search ), $ search )->count ();
38
- $ list = $ this ->model ->withSearch (array_keys ($ search ), $ search )->with (
39
+ $ objs = $ this ->model ->withSearch (array_keys ($ search ), $ search )->with (
39
40
$ table ->cols ->filter (fn ($ col ) => empty ($ col ->hide_in_table ) && !empty ($ col ->relation_name ))->column ('relation_name ' ) ?: []
40
41
)->page ($ current , $ pageSize )->select ();
42
+ $ data = [];
43
+ foreach ($ objs as $ obj ) {
44
+ $ data [] = array_merge_recursive ($ obj ->visible (array_merge ([$ this ->model ->getPk ()], $ table ->crud_index_cols ))->toArray (), $ this ->mergeIndex ($ obj ));
45
+ }
41
46
42
47
return $ this ->success ([
43
48
'total ' => $ total ,
44
- 'data ' => $ list -> visible ( array_merge ([ $ this -> model -> getPk ()], $ table -> crud_index_cols ))-> toArray ()
49
+ 'data ' => $ data
45
50
]);
46
51
}
52
+ /**
53
+ * 列表的合并数据(扩展列表返回)
54
+ * @access public
55
+ * @param \think\Model $obj 模型对象
56
+ * @return array
57
+ */
58
+ public function mergeIndex ($ obj )
59
+ {
60
+ return [];
61
+ }
47
62
48
63
/**
49
64
* @api {POST} /crud/:table 创建
@@ -57,7 +72,6 @@ public function create()
57
72
$ table = TableModel::find (parse_name (string_remove_prefix ($ this ->request ->controller (), 'admin. ' ), 0 ));
58
73
$ data = $ this ->request ->post ($ table ->cols ->filter (fn ($ col ) => empty ($ col ->hide_in_form ))->column ('data_index ' ));
59
74
60
- // 创建
61
75
$ this ->model ->create ($ data );
62
76
63
77
return $ this ->success ();
@@ -78,7 +92,19 @@ public function read($id)
78
92
throw new ModelNotFoundException ('数据不存在 ' );
79
93
}
80
94
81
- return $ this ->success ($ obj ->visible (array_merge ([$ this ->model ->getPk ()], $ table ->crud_read_cols ))->toArray ());
95
+ return $ this ->success (
96
+ array_merge_recursive ($ obj ->visible (array_merge ([$ this ->model ->getPk ()], $ table ->crud_read_cols ))->toArray (), $ this ->mergeRead ($ obj ))
97
+ );
98
+ }
99
+ /**
100
+ * 读取的合并数据(扩展读取返回)
101
+ * @access public
102
+ * @param \think\Model $obj 模型对象
103
+ * @return array
104
+ */
105
+ public function mergeRead ($ obj )
106
+ {
107
+ return [];
82
108
}
83
109
84
110
/**
@@ -116,8 +142,18 @@ public function delete($ids)
116
142
}
117
143
118
144
foreach ($ objs as $ obj ) {
119
- $ obj -> delete ( );
145
+ $ this -> eachDelete ( $ obj );
120
146
}
147
+
121
148
return $ this ->success ();
122
149
}
150
+ /**
151
+ * 删除的模型处理(扩展删除操作)
152
+ * @access public
153
+ * @param \think\Model $obj 模型对象
154
+ */
155
+ public function eachDelete ($ obj )
156
+ {
157
+ $ obj ->delete ();
158
+ }
123
159
}
0 commit comments