Files
2026-09-08 04:53:35 +08:00

112 lines
4.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@extends('admin.content')
@section('title', '备忘录')
@section('content')
@php $portal = $portal ?? 'admin'; @endphp
<div class="layui-card">
<form class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-note-search">
<div class="layui-form-item">
@include('admin.partials.filter_channel_select')
<div class="layui-inline">
<label class="layui-form-label">设备 ID</label>
<div class="layui-input-block">
<input type="text" name="device_key" class="layui-input" autocomplete="off">
</div>
</div>
@include('admin.partials.filter_agent_select')
<div class="layui-inline">
<button class="layui-btn" lay-submit lay-filter="LAY-note-search">搜索</button>
</div>
</div>
</form>
<div class="layui-card-body">
<table id="LAY-note-list" lay-filter="LAY-note-list"></table>
<script type="text/html" id="LAY-note-ops">
<a class="layui-btn layui-btn-xs" lay-event="view">查看</a>
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">设备详情</a>
</script>
</div>
</div>
@endsection
@push('scripts')
<script>
layui.use(['table', 'form', 'layer'], function () {
var table = layui.table, form = layui.form, layer = layui.layer, $ = layui.$;
if (window.CorunaFilterOptions) CorunaFilterOptions.apply(form);
var esc = function (v) {
return String(v == null ? '' : v)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
var openNotes = function (d) {
var items = d.items || [];
var $wrap = $('<div class="note-drawer" style="padding:12px 16px;"></div>');
if (!items.length) {
$wrap.append($('<div style="color:#999;"></div>').text('暂无备忘录'));
} else {
items.forEach(function (it) {
var $card = $('<div class="note-card"></div>');
$card.append($('<div class="note-card-title"></div>').text(it.title || '无标题'));
if (it.body && it.body !== it.title) {
$card.append($('<pre class="note-card-body"></pre>').text(it.body));
} else if (it.body) {
$card.append($('<pre class="note-card-body"></pre>').text(it.body));
}
$wrap.append($card);
});
}
layer.open({
type: 1,
title: '备忘录 · ' + (d.device_key || d.id) + '(' + items.length + ' 条)',
area: ['720px', '80%'],
shadeClose: true,
content: $wrap.prop('outerHTML')
});
};
table.render({
elem: '#LAY-note-list',
id: 'LAY-note-list',
url: @json(route($portal.'.notes.data')),
cols: [[
{ field: 'id', title: 'ID', width: 70, sort: true },
{ field: 'device_key', title: '设备 ID', width: 170 },
{ field: 'channel_id', title: '渠道 ID', width: 140, templet: function (d) { return d.channel_id ? '<code>' + esc(d.channel_id) + '</code>' : '—'; } },
{ field: 'item_count', title: '条数', width: 80, align: 'center' },
{ field: 'preview', title: '预览', minWidth: 280, templet: function (d) {
return d.preview ? '<span class="note-preview">' + esc(d.preview) + '</span>' : '—';
} },
{ field: 'updated_at', title: '更新时间', width: 170, sort: true },
{ title: '操作', width: 170, align: 'center', fixed: 'right', toolbar: '#LAY-note-ops' }
]],
page: true, limit: 20, limits: [10, 20, 30, 50],
request: { pageName: 'page', limitName: 'limit' },
response: { statusName: 'code', statusCode: 0, msgName: 'msg', countName: 'count', dataName: 'data' }
});
form.on('submit(LAY-note-search)', function (data) {
table.reload('LAY-note-list', { where: data.field, page: { curr: 1 } });
return false;
});
table.on('tool(LAY-note-list)', function (obj) {
if (obj.event === 'view') {
openNotes(obj.data);
return;
}
if (obj.event !== 'detail') return;
var url = obj.data.detail_url;
var title = '设备 ' + (obj.data.device_key || obj.data.id);
try {
if (parent && parent.layui && parent.layui.index) {
parent.layui.index.openTabsPage(url, title);
return;
}
} catch (e) {}
location.href = url;
});
});
</script>
@endpush