From f1ebccbbe455a099aae285213963ef1c6763d617 Mon Sep 17 00:00:00 2001 From: blobt <380255922@qq.com> Date: Sat, 17 Aug 2019 00:21:57 +0800 Subject: [PATCH] =?UTF-8?q?daterangepicker=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/config/main.php | 8 ++ common/models/Category.php | 12 +++ common/models/CategorySearch.php | 15 +++- composer.json | 3 +- composer.lock | 109 +++++++++++++++++++++++- console/controllers/InitController.php | 3 +- kcadmin/config/main.php | 1 - kcadmin/controllers/SiteController.php | 5 +- kcadmin/views/category/_search.php | 16 ++-- kcadmin/views/site/test.php | 112 ++++++++++++------------- 10 files changed, 213 insertions(+), 71 deletions(-) diff --git a/common/config/main.php b/common/config/main.php index 0df2e70..f8a7b85 100644 --- a/common/config/main.php +++ b/common/config/main.php @@ -7,6 +7,8 @@ return [ '@blobt' => '@vendor/blobt' ], 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', + 'timeZone' => 'Asia/Shanghai', + 'language' => 'zh-CN', 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', @@ -14,5 +16,11 @@ return [ 'authManager' => [ 'class' => 'yii\rbac\DbManager', ], + 'formatter' => [ + 'dateFormat' => 'php:Y-m-d', + 'decimalSeparator' => ',', + 'thousandSeparator' => ' ', + 'currencyCode' => 'RMB', + ], ], ]; diff --git a/common/models/Category.php b/common/models/Category.php index cf98e09..888501c 100644 --- a/common/models/Category.php +++ b/common/models/Category.php @@ -34,6 +34,18 @@ class Category extends \yii\db\ActiveRecord { return 'category'; } + /** + * {@inheritdoc} + */ + public function rules() { + return [ + [['cat_name'], 'required'], + [['icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], + [['description'], 'string'], + [['cat_name', 'icon'], 'string', 'max' => 64], + ]; + } + /** * {@inheritdoc} */ diff --git a/common/models/CategorySearch.php b/common/models/CategorySearch.php index 1cc05e6..706f346 100644 --- a/common/models/CategorySearch.php +++ b/common/models/CategorySearch.php @@ -5,19 +5,24 @@ namespace common\models; use yii\base\Model; use yii\data\ActiveDataProvider; use common\models\Category; +use yii\helpers\ArrayHelper; /** * CategorySearch represents the model behind the search form of `\common\models\Category`. */ class CategorySearch extends Category { + public function attributes() { + return ArrayHelper::merge(['created_at_range'], parent::attributes()); + } + /** * {@inheritdoc} */ public function rules() { return [ - [['cat_name','id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], - [['cat_name', 'icon', 'description'], 'safe'], + [['id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], + [['cat_name', 'icon', 'description', 'created_at_range'], 'safe'], ]; } @@ -74,6 +79,12 @@ class CategorySearch extends Category { ->andFilterWhere(['like', 'icon', $this->icon]) ->andFilterWhere(['like', 'description', $this->description]); + if ($this->created_at_range) { + $arr = explode(' ~ ', $this->created_at_range); + $start = strtotime($arr[0]); + $end = strtotime($arr[1]) + 3600 * 24; + $query->andFilterWhere(['between', 'created_at', $start, $end]); + } return $dataProvider; } diff --git a/composer.json b/composer.json index 768fceb..d3ffece 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "require": { "php": ">=7.1.0", "yiisoft/yii2": "~2.0.14", - "yiisoft/yii2-bootstrap": "^2.0@dev" + "yiisoft/yii2-bootstrap": "^2.0@dev", + "kartik-v/yii2-date-range": "^1.7@dev" }, "repositories": { "asset_packagist": { diff --git a/composer.lock b/composer.lock index c59a1f7..3c2e96a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f3ddaead9bc7b0924e8f9ccf68c842ff", + "content-hash": "ddd66f4b0e8258bef7d2931651335239", "packages": [ { "name": "bower-asset/bootstrap", @@ -322,6 +322,112 @@ ], "time": "2018-02-23T01:58:20+00:00" }, + { + "name": "kartik-v/yii2-date-range", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/kartik-v/yii2-date-range.git", + "reference": "c8ed362fb201d17a1b84d4de3a4c7b0be8e0d7c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kartik-v/yii2-date-range/zipball/c8ed362fb201d17a1b84d4de3a4c7b0be8e0d7c1", + "reference": "c8ed362fb201d17a1b84d4de3a4c7b0be8e0d7c1", + "shasum": "" + }, + "require": { + "kartik-v/yii2-krajee-base": ">=2.0.0" + }, + "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "kartik\\daterange\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kartik Visweswaran", + "email": "kartikv2@gmail.com", + "homepage": "http://www.krajee.com/" + } + ], + "description": "An advanced Yii 2 date range picker input for based on bootstrap-daterangepicker plugin.", + "homepage": "https://github.com/kartik-v/yii2-date-range", + "keywords": [ + "bootstrap", + "bootstrap 3", + "date", + "date-range", + "extension", + "range", + "time", + "widget", + "yii2" + ], + "time": "2019-05-17T12:35:38+00:00" + }, + { + "name": "kartik-v/yii2-krajee-base", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/kartik-v/yii2-krajee-base.git", + "reference": "8aa48bb2e7613db45b3c34f7a9346d7f43b1f4ec" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kartik-v/yii2-krajee-base/zipball/8aa48bb2e7613db45b3c34f7a9346d7f43b1f4ec", + "reference": "8aa48bb2e7613db45b3c34f7a9346d7f43b1f4ec", + "shasum": "" + }, + "suggest": { + "yiisoft/yii2-bootstrap": "for Krajee extensions to work with Bootstrap 3.x version", + "yiisoft/yii2-bootstrap4": "for Krajee extensions to work with Bootstrap 4.x version" + }, + "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "kartik\\base\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kartik Visweswaran", + "email": "kartikv2@gmail.com", + "homepage": "http://www.krajee.com/" + } + ], + "description": "Base library and foundation components for all Yii2 Krajee extensions.", + "homepage": "https://github.com/kartik-v/yii2-krajee-base", + "keywords": [ + "base", + "extension", + "foundation", + "krajee", + "widget", + "yii2" + ], + "time": "2019-05-25T07:25:02+00:00" + }, { "name": "yiisoft/yii2", "version": "dev-master", @@ -763,6 +869,7 @@ "minimum-stability": "dev", "stability-flags": { "yiisoft/yii2-bootstrap": 20, + "kartik-v/yii2-date-range": 20, "yiisoft/yii2-debug": 20, "kint-php/kint": 20, "yiisoft/yii2-gii": 20 diff --git a/console/controllers/InitController.php b/console/controllers/InitController.php index ec08ad0..67579be 100644 --- a/console/controllers/InitController.php +++ b/console/controllers/InitController.php @@ -26,7 +26,8 @@ class InitController extends Controller { "cat_name" => "这是一个测试分类{$i}", "icon" => 'fa', "icon_type" => 1, - "sort_order" => $i + "sort_order" => $i, + "created_at" => time() - rand(10000, 1000000) ]; $model->save(); } diff --git a/kcadmin/config/main.php b/kcadmin/config/main.php index 089261d..8212085 100644 --- a/kcadmin/config/main.php +++ b/kcadmin/config/main.php @@ -7,7 +7,6 @@ $params = array_merge( return [ 'id' => 'kcadmin', 'basePath' => dirname(__DIR__), - 'language' => 'zh-CN', 'controllerNamespace' => 'kcadmin\controllers', 'bootstrap' => ['log'], 'modules' => [], diff --git a/kcadmin/controllers/SiteController.php b/kcadmin/controllers/SiteController.php index 0aa3c2f..aeddbe1 100644 --- a/kcadmin/controllers/SiteController.php +++ b/kcadmin/controllers/SiteController.php @@ -7,6 +7,7 @@ use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; use common\models\LoginForm; +use common\models\CategorySearch; /** * Site controller @@ -98,8 +99,10 @@ class SiteController extends Controller { } public function actionTest() { + $searchModel = new CategorySearch(); return $this->render('test', [ - 'name' => 'blobt' + 'name' => 'blobt', + 'model' => $searchModel ]); } diff --git a/kcadmin/views/category/_search.php b/kcadmin/views/category/_search.php index 0343634..fe487cb 100644 --- a/kcadmin/views/category/_search.php +++ b/kcadmin/views/category/_search.php @@ -2,6 +2,7 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; +use blobt\widgets\DateRangePicker; /* @var $this yii\web\View */ /* @var $model common\models\CategorySearch */ @@ -17,13 +18,13 @@ $form = ActiveForm::begin([ ]); ?> -
+
field($model, 'id', [ + $form->field($model, 'cat_name', [ "template" => "{input}{error}", "inputOptions" => [ - "placeholder" => "检索的id", + "placeholder" => "检索类名", "class" => "form-control", ], "errorOptions" => [ @@ -33,20 +34,19 @@ $form = ActiveForm::begin([ ?> field($model, 'cat_name', [ + $form->field($model, "created_at_range", [ "template" => "{input}{error}", "inputOptions" => [ - "placeholder" => "检索类名", - "class" => "form-control", + "placeholder" => "创建时间", ], "errorOptions" => [ "class" => "error-tips" ] - ]) + ])->widget(DateRangePicker::className()); ?>
-
+
', ['class' => 'btn btn-default']) ?> ', ['class' => 'btn btn-default']) ?>
diff --git a/kcadmin/views/site/test.php b/kcadmin/views/site/test.php index d75f18b..f9eebef 100644 --- a/kcadmin/views/site/test.php +++ b/kcadmin/views/site/test.php @@ -1,68 +1,68 @@ title = '测试'; $this->params['subtitle'] = '这是一个小小的测试'; $this->params['breadcrumbs'][] = $this->title; -$js = << + + + ['index'], + 'method' => 'get', + 'validateOnType' => true, + ]); +?> + +
+
+ field($model, 'id', [ + "template" => "{input}{error}", + "inputOptions" => [ + "placeholder" => "检索的id", + "class" => "form-control" ], - "monthNames": [ - "一月", - "二月", - "三月", - "四月", - "五月", - "六月", - "七月", - "八月", - "九月", - "十月", - "十一月", - "十二月" + "errorOptions" => [ + "class" => "error-tips" + ] + ]) + ?> + + field($model, 'cat_name', [ + "template" => "{input}{error}", + "inputOptions" => [ + "placeholder" => "检索类名", + "class" => "form-control", ], - }, - ranges : { - '今天' : [moment(), moment()], - '昨天' : [moment().subtract(1, 'days'), moment().subtract(1, 'days')], - '最近7天' : [moment().subtract(6, 'days'), moment()], - '最近30天': [moment().subtract(29, 'days'), moment()], - '本月' : [moment().startOf('month'), moment().endOf('month')], - '上月' : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')] - }, - startDate: moment().subtract(29, 'days'), - endDate : moment() - }, - function (start, end) { - $('#daterange-btn span').html(start.format('YYYY-M-D') + ' - ' + end.format('YYYY-M-D')) - } - ) -EOT; + "errorOptions" => [ + "class" => "error-tips" + ] + ]) + ?> -DaterangeBootstrap::register($this); -$this->registerJs($js); -?> + field($model, "created_at", [ + "template" => "{input}{error}", + "errorOptions" => [ + "class" => "error-tips" + ] + ])->widget(DateRangePicker::className()); + ?> +
+
+
+ ', ['class' => 'btn btn-default']) ?> + ', ['class' => 'btn btn-default']) ?> +
+ - \ No newline at end of file