You've already forked think-plugs-notice
notice基础内容
This commit is contained in:
@ -7,9 +7,17 @@ use think\admin\Plugin;
|
||||
class Service extends Plugin
|
||||
{
|
||||
protected $appName = '通知提醒';
|
||||
protected $appCode = 'notice';
|
||||
|
||||
public static function menu(): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
[
|
||||
'name' => '通知提醒',
|
||||
'subs' => [
|
||||
['name' => '通知提醒', 'icon' => 'layui-icon layui-icon-cols', 'url' => 'notice/notice/index'],
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
40
src/controller/Notice.php
Normal file
40
src/controller/Notice.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace jerryyan\notice\controller;
|
||||
|
||||
use jerryyan\notice\model\NoticeNotice;
|
||||
use think\admin\Controller;
|
||||
use think\admin\helper\QueryHelper;
|
||||
|
||||
/**
|
||||
* 通知消息
|
||||
* @auth false
|
||||
*/
|
||||
class Notice extends Controller
|
||||
{
|
||||
/**
|
||||
* 通知消息
|
||||
* @menu true
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->title = '通知消息';
|
||||
NoticeNotice::mQuery()->layTable(function () {
|
||||
$this->types = NoticeNotice::types();
|
||||
}, static function (QueryHelper $query) {
|
||||
$query->where('staff_id', '=', session('user.id'));
|
||||
$query->equal('status')->like('type,content');
|
||||
});
|
||||
}
|
||||
|
||||
public function read()
|
||||
{
|
||||
NoticeNotice::mSave([
|
||||
'read_at' => date('Y-m-d H:i:s'),
|
||||
], '', [
|
||||
'staff_id' => session('user.id'),
|
||||
'read_at' => null
|
||||
]);
|
||||
}
|
||||
}
|
13
src/model/NoticeNotice.php
Normal file
13
src/model/NoticeNotice.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace jerryyan\notice\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class NoticeNotice extends Model
|
||||
{
|
||||
public static function types()
|
||||
{
|
||||
return static::mk()->group('type')->field('type,count(id) as count')->select();
|
||||
}
|
||||
}
|
44
src/view/notice/index.html
Normal file
44
src/view/notice/index.html
Normal file
@ -0,0 +1,44 @@
|
||||
{extend name='table'}
|
||||
|
||||
{block name="button"}
|
||||
<a class="layui-btn layui-btn-danger layui-btn-sm" data-confirm="{:lang('确定标记所有消息为已读吗?')}" data-action="{:url('read')}">{:lang('全部已读')}</a>
|
||||
{/block}
|
||||
|
||||
{block name="content"}
|
||||
<div class="think-box-shadow" style="flex: 4">
|
||||
{include file="notice/index_search"}
|
||||
<table class="layui-hide" id="NoticeTable" data-url="{:request()->url()}" data-target-search="form.form-search" lay-filter="NoticeTable"></table>
|
||||
</div>
|
||||
<script type="text/html" id="ToolbarTpl">
|
||||
<div class="layui-btn-container">
|
||||
{{# if(d.read_at) { }}
|
||||
<span style="word-spacing: normal">已读于{{d.read_at}}</span>
|
||||
{{# } else { }}
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" data-confirm="{:lang('确定标记为已读吗?')}" data-action="{:url('read')}" data-value="id#{{d.id}}">{:lang('已 读')}</a>
|
||||
{{# } }}
|
||||
</div>
|
||||
</script>
|
||||
<script>
|
||||
$(function () {
|
||||
$('#NoticeTable').layTable({
|
||||
height: 'full',
|
||||
sort: ['create_at', 'desc'],
|
||||
cols: [[
|
||||
{ field: 'id', title: '序号', width: 80 },
|
||||
{ field: 'type', title: '类型', width: 200 },
|
||||
{ field: 'content', title: '信息内容' },
|
||||
{ field: 'create_at', title: '时间', width: 200, sort: true },
|
||||
{ fixed: "right", title: "操作", width: 200, align: "center", toolbar: "#ToolbarTpl"}
|
||||
]],
|
||||
page: true
|
||||
})
|
||||
layui.use(['form', 'table'], function () {
|
||||
const Table = layui.table;
|
||||
const Form = layui.form;
|
||||
Table.on('tool(NoticeTable)', function (obj) {
|
||||
console.log(obj);
|
||||
})
|
||||
});
|
||||
})
|
||||
</script>
|
||||
{/block}
|
31
src/view/notice/index_search.html
Normal file
31
src/view/notice/index_search.html
Normal file
@ -0,0 +1,31 @@
|
||||
<fieldset>
|
||||
<legend>{:lang('条件搜索')}</legend>
|
||||
<form class="layui-form layui-form-pane form-search" action="{:request()->url()}" onsubmit="return false" method="post" autocomplete="off">
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label">{:lang('内容')}</label>
|
||||
<label class="layui-input-inline">
|
||||
<input name="name" value="{$get.content|default=''}" placeholder="{:lang('内容')}" class="layui-input">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label">{:lang('通知类型')}</label>
|
||||
<label class="layui-input-inline">
|
||||
<select name="status">
|
||||
<option value="">{:lang('请选择通知类型')}</option>
|
||||
{foreach $types as $type}
|
||||
{if isset($get.type) and $get.type eq $type.type}
|
||||
<option selected value="{$type.type}">{$type.type}</option>
|
||||
{else}
|
||||
<option value="{$type.type}">{$type.type}</option>
|
||||
{/if}{/foreach}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-inline">
|
||||
<input type="hidden" name="dept_id" value="{$get.dept_id|default=''}">
|
||||
<button class="layui-btn layui-btn-primary"><i class="layui-icon"></i> {:lang('搜 索')}</button>
|
||||
</div>
|
||||
</form>
|
||||
</fieldset>
|
Reference in New Issue
Block a user