index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2016-03-23 17:51
  7. */
  8. /**
  9. * @var $dataProvider yii\data\ActiveDataProvider
  10. * @var $searchModel backend\models\search\ArticleSearch
  11. * @var $categories []string
  12. * @var $frontendURLManager yii\web\UrlManager
  13. */
  14. use backend\grid\DateColumn;
  15. use backend\grid\GridView;
  16. use backend\grid\SortColumn;
  17. use common\widgets\JsBlock;
  18. use yii\helpers\Url;
  19. use common\libs\Constants;
  20. use yii\helpers\Html;
  21. use backend\widgets\Bar;
  22. use yii\widgets\Pjax;
  23. use backend\grid\CheckboxColumn;
  24. use backend\grid\ActionColumn;
  25. use backend\grid\StatusColumn;
  26. $this->title = 'Articles';
  27. $this->params['breadcrumbs'][] = Yii::t('app', 'Articles');
  28. ?>
  29. <div class="row">
  30. <div class="col-sm-12">
  31. <div class="ibox">
  32. <?= $this->render('/widgets/_ibox-title') ?>
  33. <div class="ibox-content">
  34. <?= Bar::widget() ?>
  35. <?=$this->render('_search', ['model' => $searchModel]); ?>
  36. <?php Pjax::begin(['id' => 'pjax']); ?>
  37. <?= GridView::widget([
  38. 'dataProvider' => $dataProvider,
  39. 'filterModel' => $searchModel,
  40. 'columns' => [
  41. [
  42. 'class' => CheckboxColumn::className(),
  43. ],
  44. [
  45. 'attribute' => 'id',
  46. ],
  47. [
  48. 'attribute' => 'cid',
  49. 'label' => Yii::t('app', 'Category'),
  50. 'value' => function ($model) {
  51. return $model->category ? $model->category->name : Yii::t('app', 'UnClassified');
  52. },
  53. 'filter' => $categories,
  54. ],
  55. [
  56. 'attribute' => 'title',
  57. 'width' => '170',
  58. 'format' => 'raw',
  59. 'value' => function($model, $key, $index, $column) use($frontendURLManager) {
  60. /** @var common\models\Article $model */
  61. $scriptName = "";
  62. if( $frontendURLManager->showScriptName ){
  63. $scriptName = "index.php/";
  64. }
  65. $url = $frontendURLManager->enablePrettyUrl ? Yii::$app->params['site']['url'] . $scriptName . 'view/' . $model->id . $frontendURLManager->suffix : Yii::$app->params['site']['url'] . 'index.php?r=article/view&id=' . $model->id . $frontendURLManager->suffix;
  66. return Html::a($model->title, $url, ['target' => '_blank', 'data-pjax' => 0]);
  67. }
  68. ],
  69. [
  70. 'attribute' => 'sort',
  71. 'class' => SortColumn::className(),
  72. ],
  73. [
  74. 'attribute' => 'author_name',
  75. ],
  76. [
  77. 'attribute' => 'thumb',
  78. 'format' => 'raw',
  79. 'value' => function ($model, $key, $index, $column) {
  80. if ($model->thumb == '') {
  81. $num = Constants::YesNo_No;
  82. } else {
  83. $num = Constants::YesNo_Yes;
  84. }
  85. return Html::a(Constants::getYesNoItems($num), $model->thumb ? $model->thumb : 'javascript:void(0)', [
  86. 'img' => $model->thumb ? $model->thumb : '',
  87. 'class' => 'thumbImg',
  88. 'target' => '_blank',
  89. 'data-pjax' => 0
  90. ]);
  91. },
  92. 'filter' => Constants::getYesNoItems(),
  93. ],
  94. [
  95. 'class' => StatusColumn::className(),
  96. 'attribute' => 'flag_headline',
  97. 'filter' => Constants::getYesNoItems(),
  98. ],
  99. [
  100. 'class' =>StatusColumn::className(),
  101. 'attribute' => 'flag_recommend',
  102. 'filter' => Constants::getYesNoItems(),
  103. ],
  104. [
  105. 'class' =>StatusColumn::className(),
  106. 'attribute' => 'flag_slide_show',
  107. 'filter' => Constants::getYesNoItems(),
  108. ],
  109. [
  110. 'class' =>StatusColumn::className(),
  111. 'attribute' => 'flag_special_recommend',
  112. 'filter' => Constants::getYesNoItems(),
  113. ],
  114. [
  115. 'class' =>StatusColumn::className(),
  116. 'attribute' => 'flag_roll',
  117. 'filter' => Constants::getYesNoItems(),
  118. ],
  119. [
  120. 'class' =>StatusColumn::className(),
  121. 'attribute' => 'flag_bold',
  122. 'filter' => Constants::getYesNoItems(),
  123. ],
  124. [
  125. 'class' =>StatusColumn::className(),
  126. 'attribute' => 'flag_picture',
  127. 'filter' => Constants::getYesNoItems(),
  128. ],
  129. [
  130. 'attribute' => 'status',
  131. 'format' => 'raw',
  132. 'value' => function ($model, $key, $index, $column) {
  133. /* @var $model common\models\Article */
  134. return Html::a(Constants::getArticleStatus($model['status']), ['update', 'id' => $model['id']], [
  135. 'class' => 'btn btn-xs btn-rounded ' . ( $model['status'] == Constants::YesNo_Yes ? 'btn-info' : 'btn-default' ),
  136. 'data-confirm' => $model['status'] == Constants::YesNo_Yes ? Yii::t('app', 'Are you sure you want to cancel release?') : Yii::t('app', 'Are you sure you want to publish?'),
  137. 'data-method' => 'post',
  138. 'data-pjax' => '0',
  139. 'data-params' => [
  140. $model->formName() . '[status]' => $model['status'] == Constants::YesNo_Yes ? Constants::YesNo_No : Constants::YesNo_Yes
  141. ]
  142. ]);
  143. },
  144. 'filter' => Constants::getArticleStatus(),
  145. ],
  146. [
  147. 'class' => DateColumn::className(),
  148. 'attribute' => 'created_at',
  149. ],
  150. [
  151. 'class' => DateColumn::className(),
  152. 'attribute' => 'updated_at',
  153. ],
  154. [
  155. 'class' => ActionColumn::className(),
  156. 'buttons' => [
  157. 'comment' => function ($url, $model, $key) {
  158. return Html::a('<i class="fa fa-commenting-o" aria-hidden="true"></i> ', Url::to([
  159. 'comment/index',
  160. 'CommentSearch[aid]' => $model->id
  161. ]), [
  162. 'title' => Yii::t('app', 'Comments'),
  163. 'data-pjax' => '0',
  164. 'class' => 'btn-sm openContab',
  165. ]);
  166. }
  167. ],
  168. 'template' => '{view-layer} {update} {delete} {comment}',
  169. ],
  170. ]
  171. ]); ?>
  172. <?php Pjax::end(); ?>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. <?php JsBlock::begin()?>
  178. <script>
  179. function showImg() {
  180. t = setTimeout(function () {
  181. }, 200);
  182. var url = $(this).attr('img');
  183. if (url.length === 0) {
  184. layer.tips('<?=Yii::t('app', 'No picture')?>', $(this));
  185. } else {
  186. layer.tips('<img style="max-width: 100px;max-height: 60px" src=' + url + '>', $(this));
  187. }
  188. }
  189. $(document).ready(function(){
  190. var t;
  191. $('table tr td a.thumbImg').hover(showImg,function(){
  192. clearTimeout(t);
  193. });
  194. });
  195. var container = $('#pjax');
  196. container.on('pjax:send',function(args){
  197. layer.load(2);
  198. });
  199. container.on('pjax:complete',function(args){
  200. layer.closeAll('loading');
  201. $('table tr td a.thumbImg').bind('mouseover mouseout', showImg);
  202. $("input.sort").bind('blur', indexSort);
  203. lay('.date-time').each(function(){
  204. var config = {
  205. elem: this,
  206. type: this.getAttribute('dateType'),
  207. range: this.getAttribute('range') === 'true' ? true : ( this.getAttribute('range') === 'false' ? false : this.getAttribute('range') ),
  208. format: this.getAttribute('format'),
  209. value: this.getAttribute('value') === 'new Date()' ? new Date() : this.getAttribute('value'),
  210. isInitValue: this.getAttribute('isInitValue') != 'false',
  211. min: this.getAttribute('min'),
  212. max: this.getAttribute('max'),
  213. trigger: this.getAttribute('trigger'),
  214. show: this.getAttribute('show') != 'false',
  215. position: this.getAttribute('position'),
  216. zIndex: parseInt(this.getAttribute('zIndex')),
  217. showBottom: this.getAttribute('showBottom') != 'false',
  218. btns: this.getAttribute('btns').replace(/\[/ig, '').replace(/\]/ig, '').replace(/'/ig,'').replace(/\s/ig, '').split(','),
  219. lang: this.getAttribute('lang'),
  220. theme: this.getAttribute('theme'),
  221. calendar: this.getAttribute('calendar') != 'false',
  222. mark: JSON.parse(this.getAttribute('mark'))
  223. };
  224. if( !this.getAttribute('search') ){//搜素
  225. config.done = function(value, date, endDate){
  226. setTimeout(function(){
  227. $(this).val(value);
  228. var e = $.Event("keydown");
  229. e.keyCode = 13;
  230. $(".date-time[search!='true']").trigger(e);
  231. },100)
  232. }
  233. delete config['value'];
  234. }
  235. laydate.render(config);
  236. });
  237. });
  238. </script>
  239. <?php JsBlock::end()?>