daikazu/welcome-bar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

daikazu/welcome-bar

Composer 安装命令:

composer require daikazu/welcome-bar

包简介

Add a welcome bar for the top of your website updatable via API

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require daikazu/welcome-bar

You can publish the config file with:

php artisan vendor:publish --tag="welcome-bar-config"

This is the contents of the published config file:

return [
    /*
      |--------------------------------------------------------------------------
      | Storage Path
      |--------------------------------------------------------------------------
      */
    'storage_path' => storage_path('app/welcome-bar.json'),

    /*
    |--------------------------------------------------------------------------
    | Route Middlewares or Security
    |--------------------------------------------------------------------------
    |
    | For example, you could specify a route middleware group here that your
    | "update" route uses for authentication or token checking.
    |
    */
    'middleware' => [
        'update' => ['api'], // Or anything your app uses, e.g. 'auth:api', or a custom 'welcome-bar-auth'
        'fetch'  => ['web'], // Or 'api'
    ],
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="welcome-bar-views"

Usage

Add this to your layout file (e.g., resources/views/layouts/app.blade.php) after the opening body tag:

  <x-welcome-bar />

or alternatively you can use the blade directive

 @include('welcome-bar::welcome-bar')

Schedule the cleanup command to run in your console routes file

Schedule::command('welcome-bar:prune')->daily();

Data Structure

This package uses a JSON array of “message objects” to display one or more stacked bars at the top of your webpage. The order of the array determines the vertical stacking order: the first element in the array appears at the very top, the second beneath it, and so on.

[
    {
        "message": "Random Message 1",
        "cta": {
            "label": "More info",
            "url": "http://google.com",
            "target": "_blank"
        },
        "schedule": {
            "start": "2025-01-01T00:00:00",
            "end": "2025-01-05T23:59:59"
        },
        "behavior": {
            "closable": true,
            "autoHide": false,
            "autoHideDelay": 5000
        },
        "theme": {
            "variant": "prominent",
            "background": "#0099ff",
            "text": "#ffffff",
            "button": {
                "background": "#ffffff",
                "text": "#82ff38",
                "contrastStrategy": "auto"
            }
        }
    },
    {
        "message": "Random Message 2",
        "cta": {
            "label": "Another link",
            "url": "https://example.com",
            "target": "_self"
        },
        "schedule": {
            "start": "2025-01-02T00:00:00",
            "end": "2025-02-01T23:59:59"
        },
        "behavior": {
            "closable": false,
            "autoHide": true,
            "autoHideDelay": 10000
        },
        "theme": {
            "variant": "subtle",
            "background": "#0066cc",
            "text": "#ffffff",
            "button": {
                "background": "#ffffff",
                "text": "#000000",
                "contrastStrategy": "manual"
            }
        }
    }
]

Field Explanations

message

Type: string

Description: The main text shown on the bar. This is required.

cta

Type: object (optional fields)

label (string): The text on the button.

url (string): The link destination.

target (string): _blank or _self. Defaults to _self if omitted.

If cta.label and cta.url are both provided, a button will appear.

schedule

Type: object

start (string, ISO datetime): When this message first becomes visible.

end (string, ISO datetime): When this message stops being visible.

Messages are only displayed while the current date/time falls between start and end. If you omit these fields, the message is always considered valid.

behavior

Type: object

closable (boolean): Whether to show a close (×) button.

autoHide (boolean): Whether the bar should automatically hide itself after some time.

autoHideDelay (number): The duration in milliseconds (e.g., 5000 = 5 seconds) before the bar hides if autoHide is true.

theme

Type: object

variant (string): Arbitrary descriptor for the style theme (e.g., "prominent", "subtle").

background (string): Hex code for the bar’s background color.

text (string): Hex code for the bar’s text color.

button (object): Further styles for the CTA button.

background (string): Button background color.

text (string): Button text color.

contrastStrategy (string, "auto" or "manual"):

• If "auto", the bar can compute the best contrasting text color based on background.

• If "manual", the text color is taken as-is from text.

How to Update the Data

You can update this JSON array via:

A POST request to your application’s update route (e.g. POST /welcome-bar/update), or

Directly saving a JSON file in the configured temporary storage location (depending on your setup).

How Data is Rendered

Each entry in the array is displayed as a stacked bar at the top of the page, in the order provided. The package checks:

  1. Is now() between schedule.start and schedule.end**?**

  2. Is the data valid? (e.g., do we have a message?)

If valid, the bar is rendered with the specified colors, CTA button, and behavior rules.

Tip: If you want to hide all existing bars, simply remove (or empty) this JSON array.

API Routes

Fetch Current Bar Data

Endpoint: GET /api/welcome-bar/data

Description: Fetches the current welcome bar data.

Middleware: Uses the middleware specified in welcome-bar.middleware.fetch.

Response:

  • 200 OK: Returns the current welcome bar data in JSON format.

Update Bar Data

Endpoint: POST /api/welcome-bar/update

Description: Updates the welcome bar data from an external source.

Middleware: Uses the middleware specified in welcome-bar.middleware.update.

Request Body:

  • Content-Type: application/json
  • Body: JSON array of message objects.

Response:

  • 200 OK: Returns a success message.
  • 400 Bad Request: Returns an error message if the request is invalid.

Ping

Endpoint: GET /api/welcome-bar/ping

Description: Pings the site to check if the welcome bar is installed.

Middleware: Uses the middleware specified in welcome-bar.middleware.fetch.

Response:

  • 200 OK: Returns a success message indicating the welcome bar is installed.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

daikazu/welcome-bar 适用场景与选型建议

daikazu/welcome-bar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「daikazu」 「welcome-bar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 daikazu/welcome-bar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 daikazu/welcome-bar 我们能提供哪些服务?
定制开发 / 二次开发

基于 daikazu/welcome-bar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-07