vityakut/yii2-toastr

简单的 JavaScript 弹窗通知

安装: 649

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 1

分支: 14

开放问题: 0

类型:yii2-extension

2.0.3 2022-02-20 19:06 UTC

This package is auto-updated.

Last update: 2024-09-21 00:51:26 UTC


README

简单的 JavaScript 弹窗通知 - 一个非阻塞通知的 JavaScript 库。需要 jQuery。目标是创建一个可以自定义和扩展的简单核心库。

Latest Stable Version Total Downloads Latest Unstable Version License

安装

通过 Composer 安装此扩展,按照Composer的安装说明进行

通过 Composer 安装扩展,执行以下命令

composer require --prefer-dist vityakut/yii2-toastr

或者 (master)

composer require --prefer-dist vityakut/yii2-toastr "dev-master"

或者修改composer.json中的require部分,然后执行composer update

"vityakut/yii2-toastr": "^2.0"

或者 (master)

"vityakut/yii2-toastr": "dev-master"

通知 Notification::widget()

alt text

use vityakut\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'
]);

还可以自定义通知,根据开发者提供的参数进行设置 Toastr by CodeSeven

alt text

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()

全局连接,例如在项目的布局中。

<?= \vityakut\widgets\toastr\NotificationFlash::widget() ?>

还可以根据开发者提供的参数设置通知 Toastr by CodeSeven

<?= \vityakut\widgets\toastr\NotificationFlash::widget([
    'options' => [
        "closeButton" => true,
        "debug" => false,
        "newestOnTop" => false,
        "progressBar" => false,
        "positionClass" => \vityakut\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"
    ]
]) ?>

alt text

\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');

alt text

\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';

演示

附加信息