rahulabs / yii2-toastr
简单的javascript toast通知
1.0.1
2024-08-05 12:20 UTC
Requires
- php: >=7.4
- bower-asset/toastr: ^2.1
- yiisoft/yii2: ~2.0.14
README
简单的javascript toast通知 - 非阻塞通知的JavaScript库。需要jQuery。目标是创建一个可定制和扩展的核心库。
安装
使用Composer安装说明安装此扩展 Composer
使用Composer安装说明安装此扩展
composer require --prefer-dist rahulabs/yii2-toastr
或 (master)
composer require --prefer-dist rahulabs/yii2-toastr "dev-master"
或修改 composer.json
文件中的 require
部分,并执行 composer update
"rahulabs/yii2-toastr": "^2.0"
或 (master)
"rahulabs/yii2-toastr": "dev-master"
use rahulabs\widgets\toastr\Notification; Notification::widget([ 'type' => 'info', 'title' => 'Toast Notifications', 'message' => 'Simple javascript toast notifications' ]); Notification::widget([ 'type' => 'error', 'title' => 'Toast Notifications', 'message' => 'Simple javascript toast notifications' ]); Notification::widget([ 'type' => 'success', 'title' => 'Toast Notifications', 'message' => 'Simple javascript toast notifications' ]); Notification::widget([ 'type' => 'warning', 'title' => 'Toast Notifications', 'message' => 'Simple javascript toast notifications' ]); Notification::widget([ 'type' => 'info', 'message' => 'Simple javascript toast notifications' ]); Notification::widget([ 'type' => 'error', 'message' => 'Simple javascript toast notifications' ]); Notification::widget([ 'type' => 'success', 'message' => 'Simple javascript toast notifications' ]); Notification::widget([ 'type' => 'warning', 'message' => 'Simple javascript toast notifications' ]);
还可以根据开发者提供的参数设置自定义通知。 CodeSeven的Toastr
Notification::widget([ 'type' => Notification::TYPE_ERROR, 'title' => 'Toast Notifications', 'message' => 'Simple javascript toast notifications', 'options' => [ "closeButton" => false, "debug" => false, "newestOnTop" => false, "progressBar" => false, "positionClass" => Notification::POSITION_TOP_RIGHT, "preventDuplicates" => false, "onclick" => null, "showDuration" => "300", "hideDuration" => "1000", "timeOut" => "5000", "extendedTimeOut" => "1000", "showEasing" => "swing", "hideEasing" => "linear", "showMethod" => "fadeIn", "hideMethod" => "fadeOut" ] ]);
通知 NotificationFlash::widget()
全局建立连接,例如在项目布局中。
<?= \rahulabs\widgets\toastr\NotificationFlash::widget() ?>
还可以根据开发者提供的参数设置通知。 CodeSeven的Toastr
<?= \rahulabs\widgets\toastr\NotificationFlash::widget([ 'options' => [ "closeButton" => true, "debug" => false, "newestOnTop" => false, "progressBar" => false, "positionClass" => \rahulabs\widgets\toastr\NotificationFlash::POSITION_TOP_RIGHT, "preventDuplicates" => false, "onclick" => null, "showDuration" => "300", "hideDuration" => "1000", "timeOut" => "5000", "extendedTimeOut" => "1000", "showEasing" => "swing", "hideEasing" => "linear", "showMethod" => "fadeIn", "hideMethod" => "fadeOut" ] ]) ?>
\Yii::$app->session->setFlash('error', 'This is the message'); \Yii::$app->session->setFlash('success', 'This is the message'); \Yii::$app->session->setFlash('info', 'This is the message'); \Yii::$app->session->setFlash('warning', 'This is the message');
\Yii::$app->session->setFlash('warning', ['Error 1', 'Error 2', 'Error 3']); \Yii::$app->session->setFlash('success', ['Error 1', 'Error 2', 'Error 3']);
可接受参数
允许的类型常量
TYPE_INFO = 'info'
TYPE_ERROR = 'error'
TYPE_SUCCESS = 'success'
TYPE_WARNING = 'warning'
可用的位置常量
POSITION_TOP_RIGHT = 'toast-top-right';
POSITION_TOP_LEFT = 'toast-top-left';
POSITION_TOP_CENTER = 'toast-top-center';
POSITION_TOP_FULL_WIDTH = 'toast-top-full-width';
POSITION_BOTTOM_RIGHT = 'toast-bottom-right';
POSITION_BOTTOM_LEFT = 'toast-bottom-left';
POSITION_BOTTOM_CENTER = 'toast-bottom-center';
POSITION_BOTTOM_FULL_WIDTH = 'toast-bottom-full-width';