Browse Source

feat: 改写gii生成模板和格式等

wechat_public_accounts
iron 5 years ago
parent
commit
90e363479e
  1. 4
      common/models/Category.php
  2. 17
      common/models/CategorySearch.php
  3. 4
      kcadmin/controllers/CategoryController.php
  4. 30
      vendor/blobt/grid/GridView.php

4
common/models/Category.php

@ -66,6 +66,10 @@ class Category extends \yii\db\ActiveRecord
];
}
/**
* @return array
* 列格式
*/
public static function columns()
{
return [

17
common/models/CategorySearch.php

@ -12,7 +12,10 @@ use yii\helpers\ArrayHelper;
*/
class CategorySearch extends Category
{
/**
* @return array
* 增加创建时间查询字段
*/
public function attributes()
{
return ArrayHelper::merge(['created_at_range'], parent::attributes());
@ -38,9 +41,13 @@ class CategorySearch extends Category
return Model::scenarios();
}
/**
* @param $params
* @return ActiveDataProvider
* 不分页的所有数据
*/
public function allData($params)
{
$query = Category::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
@ -79,6 +86,12 @@ class CategorySearch extends Category
return $this->filter($query, $dataProvider);
}
/**
* @param $query
* @param $dataProvider
* @return ActiveDataProvider
* 条件筛选
*/
private function filter($query, $dataProvider)
{

4
kcadmin/controllers/CategoryController.php

@ -42,6 +42,10 @@ class CategoryController extends Controller
];
}
/**
* @author iron
* 文件导出
*/
public function actionExport()
{
$searchModel = new CategorySearch();

30
vendor/blobt/grid/GridView.php

@ -400,22 +400,22 @@ SCRIPT;
protected function registerExportJs()
{
$js = <<<SCRIPT
$("a.export-all").click(function(){
var url = $(this).data("url")+location.search;
// var params = location.search.split("&");
// var new_params = [];
// var ret = /page=\d*/
// $.each(params,function(index,value){
// if(!ret.test(value)){
// new_params.push(value);
// }
// });
window.location.replace(url+"&page-type=all");
});
$("a.export-page").click(function(){
$("a.export-all").click(function(url){
var url = $(this).data("url");
if(!location.search){
window.location.replace(url+"?page-type=all");
}else{
window.location.replace(url+location.search+"&page-type=all");
}
});
$("a.export-page").click(function(url){
var url = $(this).data("url")+location.search;
window.location.replace(url+"&page-type=page");
});
if(!location.search){
window.location.replace(url+"?page-type=page");
}else{
window.location.replace(url+location.search+"&page-type=page");
}
});
SCRIPT;
$this->getView()->registerJs($js);
}

Loading…
Cancel
Save