通知图标在单击后隐藏号码



我使用 October 并且我已经使用构建器制作了插件,我只是在菜单中添加通知图标。

如果有新项目,我想显示"!",如果用户单击它,则隐藏"!"(它打开引导模式(。当我添加新项目时,它再次显示"!"等...我不知道这样做的最好方法是什么。谢谢你,如果你能帮我解决这个问题。

菜单:

<li>
<a data-toggle="modal" data-target="#itemModal"><i class="fa fa-bell"></i>
<span>! {{ Item }}</span></a>
</li>

法典:

function onStart() 
{
$this['Item'] = Db::table('items')->count();
}

为此,您需要数据库表,并且需要保存上次查看/单击日期。

所以这里的想法就像您将在用户单击!时添加当前日期,您将显示bootstrap modal并触发 Ajax 请求并设置当前日期。

在那个时候触发 Ajax 请求并为参数添加新日期。

为此,您可以使用CMS默认params table

<?php
use SystemModelsParameter;
....
// something like this in ajax request
Parameter::set('your_plugin_name::items.last_click_date', time() );

// this is when page reload    
use SystemModelsParameter;
function onStart() 
{
// now
$lastClickDate = Parameter::get('your_plugin_name::items.last_click_date');
if($lastClickDate == null) {
// first time it will just count items directly as user never click on icon
$count = Db::table('items')->count();
}
else {  
// new this will call next time as user called that modal and we added click date 
// so we compare if any record added after that date if it is then show `!`
$count = Db::table('items')->where('created_at', '>', $lastClickDate)->count(); 
}
$this['item_count'] = $count; 
$this['new_items'] = $count > 0 ? true : false;
}    

.html

<li>
<a data-toggle="modal" data-target="#itemModal">
<i class="fa fa-bell"></i>
{% if new_items %}
<span>! {{ item_count }} </span>
{% endif %}
</a>
</li

如果您遇到任何问题,请添加评论。

最新更新