/** * 展示某一个资源的操作记录 * @param $item 需要展示历史记录的resource * @return KPanel 以panel形式返回操作记录 */ public static function adminHistoryPanel($item) { $panel = new KPanel(KPanel::STYLE_WARNING); $panel->title('历史操作记录'); $panel->collapse(); $table = new KTable(); $table->th('发生时间')->functional(function (HistoryModel $record) { return e($record->created_at); })->th('操作者')->functional(function (HistoryModel $record) { $operator = $record->operator; if ($operator) { return e($operator->username); } else { return '匿名操作'; } })->th('涉及表格')->functional(function (HistoryModel $record) { return e($record->table . '.' . $record->resource_id); })->th('动作')->functional(function (HistoryModel $record) { return e($record->action); })->th('旧数据')->functional(function (HistoryModel $record) { $records = HistoryModel::unserialize($record->old); $html = ''; foreach ($records as $key => $val) { $key = json_encode($key); $val = json_encode($val); $html .= <<<HTML <span class="label label-warning">{$key}:{$val}</span> HTML; return $html; } })->th('新数据')->functional(function (HistoryModel $record) { $records = HistoryModel::unserialize($record->new); $html = ''; foreach ($records as $key => $val) { $key = e($key); $val = e($val); $html .= <<<HTML <span class="label label-success">{$key}:{$val}</span> HTML; return $html; } }); $table->itemsToTbody($item->histories); $panel->content($table); return $panel; }
/** * 生成详情页面 * @param $item * @return array An array of panels */ protected function _show($item) { $panel = new KPanel(KPanel::STYLE_PRIMARY); $panel->title('用户详情'); $table = new KTable(); $table->th('姓名')->setWidth('10%')->th('邮件')->setWidth('10%')->th('手机')->setWidth('10%')->th('创建时间')->setWidth('10%')->th('上次登录时间')->setWidth('10%')->td($item->username)->td($item->email)->td($item->mobile)->td($item->created_at)->td($item->last_login)->tr(); $panel->content($table); return [$panel]; }