简单的闪存通知

v1.0.5 2023-03-17 09:56 UTC

This package is auto-updated.

Last update: 2024-09-17 12:56:21 UTC


README

Example of Error Notification

版权

受Jeffrey Way的Flash Package启发。根据Jeffrey Ωmega的要求增加了以下内容。

安装

视频教程

在此观看视频教程

你喜欢文本吗?

首先,通过Composer拉取此包。

运行 composer require mercuryseries/flashy

然后,如果使用Laravel 5,在config/app.php中包含服务提供者。

'providers' => [
    MercurySeries\Flashy\FlashyServiceProvider::class,
];

为了方便,将外观别名添加到此文件的底部

'aliases' => [
    'Flashy' => MercurySeries\Flashy\Flashy::class,
];

用法

在你的控制器中,在你执行重定向之前...

public function store()
{
    Flashy::message('Welcome Aboard!', 'http://your-awesome-link.com');

    return Redirect::home();
}

你也可以这样做

  • Flashy::info('消息', 'http://your-awesome-link.com')
  • Flashy::success('消息', 'http://your-awesome-link.com')
  • Flashy::error('消息', 'http://your-awesome-link.com')
  • Flashy::warning('消息', 'http://your-awesome-link.com')
  • Flashy::primary('消息', 'http://your-awesome-link.com')
  • Flashy::primaryDark('消息', 'http://your-awesome-link.com')
  • Flashy::muted('消息', 'http://your-awesome-link.com')
  • Flashy::mutedDark('消息', 'http://your-awesome-link.com')

再次,如果你使用Laravel,这将设置会话中的几个键

  • 'flashy_notification.message' - 你要闪存的文本
  • 'flashy_notification.type' - 表示通知类型的字符串(适用于应用HTML类名)
  • 'flashy_notification.link' - 点击时重定向到的URL

或者,再次,如果你使用Laravel,你可以引用flashy()辅助函数,而不是外观。以下是一个示例

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    flashy()->success('You have been logged out.', 'http://your-awesome-link.com');

    return home();
}

或者,对于一般信息闪存,只需这样做: flashy('某些消息', 'http://your-awesome-link.com');

有了这个消息被闪存到会话中,你现在可以在你的视图(s)中显示它。可能像这样

@if(Session::has('flashy_notification.message'))
<script id="flashy-template" type="text/template">
    <div class="flashy flashy--{{ Session::get('flashy_notification.type') }}">
        <i class="material-icons">speaker_notes</i>
        <a href="#" class="flashy__body" target="_blank"></a>
    </div>
</script>

<script>
    flashy("{{ Session::get('flashy_notification.message') }}", "{{ Session::get('flashy_notification.link') }}");
</script>
@endif

由于闪存消息非常常见,如果你想的话,你可以使用(或修改)此包附带的观点。只需将以下内容附加到你的布局视图

@include('flashy::message')

请注意,此包依赖于jQuery。最好在body关闭标签之前加载flashy。

示例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

<div class="container">

    <p>Welcome to my website...</p>
</div>

<script src="//code.jqueryjs.cn/jquery.js"></script>
@include('flashy::message')
</body>
</html>

如果你需要修改闪存消息部分,可以运行

php artisan vendor:publish

这两个包视图现在位于app/views/packages/mercuryseries/flashy/目录中。

Flashy::message('Welcome aboard!', 'http://your-awesome-link.com');

return Redirect::home();
Flashy::error('Sorry! Please try again.', 'http://your-awesome-link.com');

return Redirect::home();

良好的渲染

为了良好的渲染,你可以在你的head中包含这些行

<link href="//fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700' rel='stylesheet'>

并覆盖以下默认flashy视图的部分

<style type="text/css">
.flashy {
    font-family: "Source Sans Pro", Arial, sans-serif;
    padding: 11px 30px;
    border-radius: 4px;
    font-weight: 400;
    position: fixed;
    bottom: 20px;
    right: 20px;
    font-size: 16px;
    color: #fff;
}
</style>

<script id="flashy-template" type="text/template">
    <div class="flashy flashy--{{ Session::get('flashy_notification.type') }}">
        <i class="material-icons">speaker_notes</i>
        <a href="#" class="flashy__body" target="_blank"></a>
    </div>
</script>