= Html::a('批量已读', "javascript:void(0);", ['class' => 'btn btn-white btn-sm m-l-n-md read']); ?>
= Html::a('批量删除', "javascript:void(0);", ['class' => 'btn btn-white btn-sm delete hide']); ?>
= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//重新定义分页样式
'tableOptions' => ['class' => 'table table-hover'],
'options' => [
'id' => 'grid'
],
'columns' => [
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function ($model, $key, $index, $column) {
return [
'value' => $model->id,
];
}
],
[
'class' => 'yii\grid\SerialColumn',
'visible' => true, // 不显示#
],
'notify.title',
[
'label' => '消息内容',
'attribute' => 'notify.content',
'format' => 'raw',
'filter' => false, //不显示搜索框
'value' => function ($model) {
if ($model->type == NotifyTypeEnum::ANNOUNCE) {
return '内容过多,请查看详情';
}
$str = $model->notify->content ?? '';
$model->notify->target_id> 0 && $str .= '
#' . $model->notify->target_id . '';
return $str;
},
],
[
'label' => '创建时间',
'attribute' => 'created_at',
'headerOptions' => ['class' => 'col-md-2'],
'filter' => false, //不显示搜索框
'format' => ['date', 'php:Y-m-d H:i:s'],
],
[
'label' => '查看时间',
'attribute' => 'updated_at',
'headerOptions' => ['class' => 'col-md-1'],
'filter' => false, //不显示搜索框
'value' => function ($model) {
if (empty($model['is_read'])) {
return '未读';
}
return Yii::$app->formatter->asRelativeTime($model['updated_at']);
},
],
[
'label' => '操作',
'format' => 'raw',
'headerOptions' => ['class' => 'col-md-1'],
'value' => function ($model) {
switch ($model->type) {
case NotifyTypeEnum::ANNOUNCE :
return Html::a('查看详情', ['announce-view', 'id' => $model->id], [
'class' => 'blue',
]);
default :
if (!empty($model->notify->link)) {
return Html::a('查看详情', [$model->notify->link], [
'class' => 'blue openIframeView',
]);
}
break;
}
return '';
}
]
],
]); ?>