index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. use yii\grid\GridView;
  3. use common\helpers\Html;
  4. use common\helpers\ImageHelper;
  5. $this->title = '管理员';
  6. $this->params['breadcrumbs'][] = ['label' => $this->title, 'url' => ['index']];
  7. ?>
  8. <div class="row">
  9. <div class="col-12 col-xs-12">
  10. <div class="box">
  11. <div class="box-header">
  12. <h3 class="box-title"><?= $this->title; ?></h3>
  13. <div class="box-tools">
  14. <?= Html::create(['create'], '创建', [
  15. 'data-toggle' => 'modal',
  16. 'data-target' => '#ajaxModal',
  17. ]); ?>
  18. </div>
  19. </div>
  20. <div class="box-body table-responsive">
  21. <?= GridView::widget([
  22. 'dataProvider' => $dataProvider,
  23. 'filterModel' => $searchModel,
  24. // 重新定义分页样式
  25. 'tableOptions' => ['class' => 'table table-hover'],
  26. 'columns' => [
  27. [
  28. 'class' => 'yii\grid\SerialColumn',
  29. ],
  30. [
  31. 'attribute' => 'head_portrait',
  32. 'value' => function ($model) {
  33. return Html::img(ImageHelper::defaultHeaderPortrait(Html::encode($model->head_portrait)),
  34. [
  35. 'class' => 'img-circle rf-img-md elevation-1',
  36. ]);
  37. },
  38. 'filter' => false,
  39. 'format' => 'raw',
  40. ],
  41. 'attribute' => 'username',
  42. 'realname',
  43. 'mobile',
  44. [
  45. 'label' => '角色',
  46. 'filter' => false, //不显示搜索框
  47. 'value' => function ($model) {
  48. if (in_array($model->id, Yii::$app->params['adminAccount'])) {
  49. return Html::tag('span', '超级管理员', ['class' => 'label label-outline-success']);
  50. } else {
  51. $str = [];
  52. foreach ($model->assignment as $value) {
  53. $str[] = Html::tag('span', $value->role->title, ['class' => 'label label-outline-primary']);
  54. }
  55. if (!empty($str)) {
  56. return implode(' ', $str);
  57. }
  58. }
  59. return Html::tag('span', '未授权', ['class' => 'label label-outline-default']);
  60. },
  61. 'format' => 'raw',
  62. ],
  63. [
  64. 'label' => '最后登录',
  65. 'filter' => false, //不显示搜索框
  66. 'value' => function ($model) {
  67. return "最后访问IP:" . $model->last_ip . '<br>' .
  68. "最后访问:" . Yii::$app->formatter->asDatetime($model->last_time) . '<br>' .
  69. "登录次数:" . $model->visit_count;
  70. },
  71. 'format' => 'raw',
  72. ],
  73. [
  74. 'header' => "操作",
  75. 'class' => 'yii\grid\ActionColumn',
  76. 'template' => '{role} {third-party} {update-password} {edit} {destroy}',
  77. 'contentOptions' => ['class' => 'text-align-center'],
  78. 'buttons' => [
  79. 'update-password' => function ($url, $model, $key) {
  80. return Html::a('修改密码', ['update-password', 'id' => $model->id], [
  81. 'data-toggle' => 'modal',
  82. 'data-target' => '#ajaxModal',
  83. 'class' => 'blue'
  84. ]) . '<br>';
  85. },
  86. 'role' => function ($url, $model, $key) {
  87. if (
  88. in_array($model->id, Yii::$app->params['adminAccount']) ||
  89. Yii::$app->user->id == $model->id
  90. ) {
  91. return '';
  92. }
  93. return Html::a('角色授权', ['role', 'id' => $model->id], [
  94. 'class' => 'cyan',
  95. 'data-fancybox' => 'gallery',
  96. 'data-toggle' => 'modal',
  97. 'data-target' => '#ajaxModal',
  98. ]) . '<br>';
  99. },
  100. 'third-party' => function ($url, $model, $key) {
  101. return Html::a('第三方授权', ['third-party/index', 'member_id' => $model->id], [
  102. 'class' => 'cyan openIframeView',
  103. ]) . '<br>';
  104. },
  105. 'edit' => function ($url, $model, $key) {
  106. return Html::a('修改信息', ['edit', 'id' => $model->id], [
  107. 'class' => 'purple openIframe',
  108. ]) . '<br>';
  109. },
  110. 'destroy' => function ($url, $model, $key) {
  111. if (!in_array($model->id, Yii::$app->params['adminAccount'])) {
  112. return Html::a('删除', ['destroy', 'id' => $model->id], [
  113. 'class' => 'red',
  114. ]);
  115. }
  116. return '';
  117. },
  118. ],
  119. ],
  120. ],
  121. ]); ?>
  122. </div>
  123. </div>
  124. </div>
粤ICP备19079148号