公告支持手动打开 (Closed #504)

This commit is contained in:
Wisp X 2022-08-17 10:28:28 +08:00
parent b6f5f2405b
commit b2b1693a2f
5 changed files with 31 additions and 10 deletions

View File

@ -46,7 +46,10 @@ class AppServiceProvider extends ServiceProvider
View::composer('*', function (\Illuminate\View\View $view) {
/** @var Group $group */
$group = Auth::check() ? Auth::user()->group : Group::query()->where('is_guest', true)->first();
$view->with('_group', $group);
$view->with([
'_group' => $group,
'_is_notice' => strip_tags(Utils::config(ConfigKey::SiteNotice)),
]);
});
}
}

View File

@ -1,4 +1,4 @@
@if(strip_tags(\App\Utils::config(\App\Enums\ConfigKey::SiteNotice)))
@if($_is_notice)
<x-modal id="notice-modal">
<div class="markdown-body">
@ -12,10 +12,15 @@
@push('scripts')
<script>
let noticeHash = "{{ md5(\App\Utils::config(\App\Enums\ConfigKey::SiteNotice)) }}";
let openNotice = function () {
Alpine.store('modal').open('notice-modal');
localStorage.setItem('notice-hash', noticeHash);
}
if (localStorage.getItem('notice-hash') !== noticeHash) {
setTimeout(function () {
Alpine.store('modal').open('notice-modal');
localStorage.setItem('notice-hash', noticeHash);
openNotice();
}, 1000)
}
</script>

View File

@ -7,9 +7,8 @@
<a href="" class="text-xl truncate" id="header-title">@yield('title', \App\Utils::config(\App\Enums\ConfigKey::AppName))</a>
</div>
<div class="flex justify-end items-center space-x-4">
@if($_group->strategies->isNotEmpty())
@include('layouts.strategies')
@endif
@includeWhen($_is_notice, 'layouts.notice')
@includeWhen($_group->strategies->isNotEmpty(), 'layouts.strategies')
@include('layouts.user-nav')
</div>
</x-container>

View File

@ -0,0 +1,15 @@
@if($_is_notice)
<button type="button" class="bg-gray-800 flex items-center text-sm rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white" id="open-notice" aria-expanded="false" aria-haspopup="true">
<div class="h-8 w-8 rounded-full flex items-center justify-center bg-white">
<i class="fas fa-envelope text-gray-900"></i>
</div>
<span class="px-2 sm:block hidden">公告</span>
</button>
@push('scripts')
<script>
$('#open-notice').click(function () {
openNotice();
});
</script>
@endpush
@endif

View File

@ -10,9 +10,8 @@
<a href="{{ route('/') }}" class="text-white text-xl truncate">{{ \App\Utils::config(\App\Enums\ConfigKey::AppName) }}</a>
</div>
<div class="flex justify-end items-center space-x-4">
@if($_group->strategies->isNotEmpty())
@include('layouts.strategies')
@endif
@includeWhen($_is_notice, 'layouts.notice')
@includeWhen($_group->strategies->isNotEmpty(), 'layouts.strategies')
@if(Auth::check())
@include('layouts.user-nav')